src/industry_cmd.cpp
changeset 7760 d10e2e25cd5f
parent 7758 17ad53748c7b
child 7799 72e48b8cf207
equal deleted inserted replaced
7759:eb8f1b5b2883 7760:d10e2e25cd5f
  1580  * @param p2 unused
  1580  * @param p2 unused
  1581  * @return index of the newly create industry, or CMD_ERROR if it failed
  1581  * @return index of the newly create industry, or CMD_ERROR if it failed
  1582  */
  1582  */
  1583 CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1583 CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
  1584 {
  1584 {
  1585 	int num;
       
  1586 	const IndustryTileTable * const *itt;
       
  1587 	const IndustrySpec *indspec;
  1585 	const IndustrySpec *indspec;
  1588 
  1586 
  1589 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
  1587 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
  1590 
  1588 
  1591 	indspec = GetIndustrySpec(p1);
  1589 	indspec = GetIndustrySpec(p1);
  1606 			/* Prospecting has a chance to fail, however we cannot guarantee that something can
  1604 			/* Prospecting has a chance to fail, however we cannot guarantee that something can
  1607 			 * be built on the map, so the chance gets lower when the map is fuller, but there
  1605 			 * be built on the map, so the chance gets lower when the map is fuller, but there
  1608 			 * is nothing we can really do about that. */
  1606 			 * is nothing we can really do about that. */
  1609 			if (Random() <= indspec->prospecting_chance) {
  1607 			if (Random() <= indspec->prospecting_chance) {
  1610 				for (int i = 0; i < 5000; i++) {
  1608 				for (int i = 0; i < 5000; i++) {
  1611 					uint tilespec_index = RandomRange(indspec->num_table);
  1609 					const Industry *ind = CreateNewIndustryHelper(RandomTile(), p1, flags, indspec, RandomRange(indspec->num_table));
  1612 					const Industry *ind = CreateNewIndustryHelper(RandomTile(), p1, flags, indspec, tilespec_index);
       
  1613 					if (ind != NULL) {
  1610 					if (ind != NULL) {
  1614 						SetDParam(0, indspec->name);
  1611 						SetDParam(0, indspec->name);
  1615 						if (indspec->new_industry_text > STR_LAST_STRINGID) {
  1612 						if (indspec->new_industry_text > STR_LAST_STRINGID) {
  1616 							SetDParam(1, STR_TOWN);
  1613 							SetDParam(1, STR_TOWN);
  1617 							SetDParam(2, ind->town->index);
  1614 							SetDParam(2, ind->town->index);
  1624 					}
  1621 					}
  1625 				}
  1622 				}
  1626 			}
  1623 			}
  1627 		}
  1624 		}
  1628 	} else {
  1625 	} else {
  1629 		num = indspec->num_table;
  1626 		int count = indspec->num_table;
  1630 		itt = indspec->table;
  1627 		const IndustryTileTable * const *itt = indspec->table;
       
  1628 		int num = RandomRange(count);
  1631 
  1629 
  1632 		_error_message = STR_0239_SITE_UNSUITABLE;
  1630 		_error_message = STR_0239_SITE_UNSUITABLE;
  1633 		do {
  1631 		do {
  1634 			if (--num < 0) return CMD_ERROR;
  1632 			if (--count < 0) return CMD_ERROR;
       
  1633 			if (--num < 0) num = indspec->num_table - 1;
  1635 		} while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1));
  1634 		} while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1));
  1636 
  1635 
  1637 		if (CreateNewIndustryHelper(tile, p1, flags, indspec, num) == NULL) return CMD_ERROR;
  1636 		if (CreateNewIndustryHelper(tile, p1, flags, indspec, num) == NULL) return CMD_ERROR;
  1638 	}
  1637 	}
  1639 
  1638