src/industry_cmd.cpp
changeset 7757 6335bd827212
parent 7725 e3892b38aa14
child 7758 69238219f5d2
equal deleted inserted replaced
7756:47e4498a0119 7757:6335bd827212
    66 
    66 
    67 	memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs));
    67 	memset(&_industry_tile_specs, 0, sizeof(_industry_tile_specs));
    68 	memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs));
    68 	memcpy(&_industry_tile_specs, &_origin_industry_tile_specs, sizeof(_origin_industry_tile_specs));
    69 }
    69 }
    70 
    70 
       
    71 void ResetIndustryCreationProbility(IndustryType type)
       
    72 {
       
    73 	assert(type < INVALID_INDUSTRYTYPE);
       
    74 	_industry_specs[type].appear_creation[_opt.landscape] = 0;
       
    75 }
       
    76 
    71 /**
    77 /**
    72  * Called if a new block is added to the industry-pool
    78  * Called if a new block is added to the industry-pool
    73  */
    79  */
    74 static void IndustryPoolNewBlock(uint start_item)
    80 static void IndustryPoolNewBlock(uint start_item)
    75 {
    81 {
  1664 	uint8 chance;
  1670 	uint8 chance;
  1665 	IndustryType it;
  1671 	IndustryType it;
  1666 	const IndustrySpec *ind_spc;
  1672 	const IndustrySpec *ind_spc;
  1667 
  1673 
  1668 	/* Find the total amount of industries */
  1674 	/* Find the total amount of industries */
  1669 	for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) {
  1675 	if (_opt.diff.number_industries > 0) {
  1670 
  1676 		for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) {
  1671 		ind_spc = GetIndustrySpec(it);
  1677 
  1672 		if (ind_spc->enabled) {
  1678 			ind_spc = GetIndustrySpec(it);
       
  1679 
       
  1680 			if (!CheckIfCallBackAllowsAvailability(it, IACT_MAPGENERATION)) {
       
  1681 				ResetIndustryCreationProbility(it);
       
  1682 			}
       
  1683 
  1673 			chance = ind_spc->appear_creation[_opt.landscape];
  1684 			chance = ind_spc->appear_creation[_opt.landscape];
  1674 			if (chance > 0) {
  1685 			if (ind_spc->enabled) && chance > 0 {
  1675 				/* once the chance of appearance is determind, it have to be scaled by
  1686 				/* once the chance of appearance is determind, it have to be scaled by
  1676 				 * the difficulty level. The "chance" in question is more an index into
  1687 				 * the difficulty level. The "chance" in question is more an index into
  1677 				 * the _numof_industry_table,in fact */
  1688 				 * the _numof_industry_table,in fact */
  1678 				int num = _numof_industry_table[_opt.diff.number_industries][chance];
  1689 				int num = (chance < 11) ? chance : _numof_industry_table[_opt.diff.number_industries][chance];
  1679 
  1690 
  1680 				/* These are always placed next to the coastline, so we scale by the perimeter instead. */
  1691 				/* These are always placed next to the coastline, so we scale by the perimeter instead. */
  1681 				num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
  1692 				num = (ind_spc->check_proc == CHECK_REFINERY || ind_spc->check_proc == CHECK_OIL_RIG) ? ScaleByMapSize1D(num) : ScaleByMapSize(num);
  1682 				i += num;
  1693 				i += num;
  1683 			}
  1694 			}
  1684 		}
  1695 		}
  1685 	}
  1696 	}
  1686 
  1697 
  1687 	SetGeneratingWorldProgress(GWP_INDUSTRY, i);
  1698 	SetGeneratingWorldProgress(GWP_INDUSTRY, i);
  1688 
  1699 
  1689 	for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) {
  1700 	if (_opt.diff.number_industries > 0) {
  1690 		/* Once the number of industries has been determined, let's really create them.
  1701 		for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) {
  1691 		 * The test for chance allows us to try create industries that are available only
  1702 			/* Once the number of industries has been determined, let's really create them.
  1692 		 * for this landscape.
  1703 			 * The test for chance allows us to try create industries that are available only
  1693 		 * @todo :  Do we really have to pass chance as un-scaled value, since we've already
  1704 			 * for this landscape.
  1694 		 *          processed that scaling above? No, don't think so.  Will find a way. */
  1705 			 * @todo :  Do we really have to pass chance as un-scaled value, since we've already
  1695 		ind_spc = GetIndustrySpec(it);
  1706 			 *          processed that scaling above? No, don't think so.  Will find a way. */
  1696 		if (ind_spc->enabled) {
  1707 			ind_spc = GetIndustrySpec(it);
  1697 			chance = ind_spc->appear_creation[_opt.landscape];
  1708 			if (ind_spc->enabled) {
  1698 			if (chance > 0) PlaceInitialIndustry(it, chance);
  1709 				chance = ind_spc->appear_creation[_opt.landscape];
  1699 		}
  1710 				if (chance > 0) PlaceInitialIndustry(it, chance);
  1700 	};
  1711 			}
       
  1712 		}
       
  1713 	}
  1701 }
  1714 }
  1702 
  1715 
  1703 /* Change industry production or do closure */
  1716 /* Change industry production or do closure */
  1704 static void ExtChangeIndustryProduction(Industry *i)
  1717 static void ExtChangeIndustryProduction(Industry *i)
  1705 {
  1718 {
  1822 
  1835 
  1823 	/* Generate a list of all possible industries that can be built. */
  1836 	/* Generate a list of all possible industries that can be built. */
  1824 	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
  1837 	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
  1825 		byte chance = GetIndustrySpec(j)->appear_ingame[_opt.landscape];
  1838 		byte chance = GetIndustrySpec(j)->appear_ingame[_opt.landscape];
  1826 
  1839 
  1827 		/* if appearing chance for this landscape is above 0, this industry can be chosen */
  1840 		/* If there is no Callback CBID_INDUSTRY_AVAILABLE or if this one did anot failed,
  1828 		if (chance != 0) {
  1841 		 * and if appearing chance for this landscape is above 0, this industry can be chosen */
       
  1842 		if (CheckIfCallBackAllowsAvailability(j, IACT_RANDOMCREATION) && chance != 0) {
  1829 			probability_max += chance;
  1843 			probability_max += chance;
  1830 			/* adds the result for this industry */
  1844 			/* adds the result for this industry */
  1831 			cumulative_probs[num].ind = j;
  1845 			cumulative_probs[num].ind = j;
  1832 			cumulative_probs[num++].prob = probability_max;
  1846 			cumulative_probs[num++].prob = probability_max;
  1833 		}
  1847 		}