src/industry_cmd.cpp
changeset 6989 43b359b4cb86
parent 6987 b0f13039bda2
child 7015 af363e4290ab
equal deleted inserted replaced
6988:76eba6a9cc6f 6989:43b359b4cb86
    65 	IndustryGfx this_type = GetIndustryGfx(tile);
    65 	IndustryGfx this_type = GetIndustryGfx(tile);
    66 	IndustryType iloop;
    66 	IndustryType iloop;
    67 
    67 
    68 	assert(IsTileType(tile, MP_INDUSTRY));
    68 	assert(IsTileType(tile, MP_INDUSTRY));
    69 
    69 
    70 	for (iloop = IT_COAL_MINE; iloop < IT_END; iloop += 1) {
    70 	for (iloop = IT_COAL_MINE; iloop < NUM_INDUSTRYTYPES; iloop += 1) {
    71 		if (IS_BYTE_INSIDE(this_type, industry_gfx_Solver[iloop].MinGfx,
    71 		if (IS_BYTE_INSIDE(this_type, industry_gfx_Solver[iloop].MinGfx,
    72 				industry_gfx_Solver[iloop].MaxGfx + 1)) {
    72 				industry_gfx_Solver[iloop].MaxGfx + 1)) {
    73 			return iloop;
    73 			return iloop;
    74 		}
    74 		}
    75 	}
    75 	}
    80 /**
    80 /**
    81  * Accessor for array _industry_specs.
    81  * Accessor for array _industry_specs.
    82  * This will ensure at once : proper access and
    82  * This will ensure at once : proper access and
    83  * not allowing modifications of it.
    83  * not allowing modifications of it.
    84  * @param thistype of industry (which is the index in _industry_specs)
    84  * @param thistype of industry (which is the index in _industry_specs)
    85  * @pre thistype < IT_END
    85  * @pre thistype < NUM_INDUSTRYTYPES
    86  * @return a pointer to the corresponding industry spec
    86  * @return a pointer to the corresponding industry spec
    87  **/
    87  **/
    88 const IndustrySpec *GetIndustrySpec(IndustryType thistype)
    88 const IndustrySpec *GetIndustrySpec(IndustryType thistype)
    89 {
    89 {
    90 	assert(thistype < IT_END);
    90 	assert(thistype < NUM_INDUSTRYTYPES);
    91 	return &_industry_specs[thistype];
    91 	return &_industry_specs[thistype];
    92 }
    92 }
    93 
    93 
    94 /**
    94 /**
    95  * Accessor for array _industry_tile_specs.
    95  * Accessor for array _industry_tile_specs.
  1588 	uint8 chance;
  1588 	uint8 chance;
  1589 	IndustryType it;
  1589 	IndustryType it;
  1590 	const IndustrySpec *ind_spc;
  1590 	const IndustrySpec *ind_spc;
  1591 
  1591 
  1592 	/* Find the total amount of industries */
  1592 	/* Find the total amount of industries */
  1593 	for (it = IT_COAL_MINE; it < IT_END; it++) {
  1593 	for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) {
  1594 		int num;
  1594 		int num;
  1595 
  1595 
  1596 		ind_spc = GetIndustrySpec(it);
  1596 		ind_spc = GetIndustrySpec(it);
  1597 		chance = ind_spc->appear_creation[_opt.landscape];
  1597 		chance = ind_spc->appear_creation[_opt.landscape];
  1598 
  1598 
  1608 		}
  1608 		}
  1609 	}
  1609 	}
  1610 
  1610 
  1611 	SetGeneratingWorldProgress(GWP_INDUSTRY, i);
  1611 	SetGeneratingWorldProgress(GWP_INDUSTRY, i);
  1612 
  1612 
  1613 	for (it = IT_COAL_MINE; it < IT_END; it++) {
  1613 	for (it = IT_COAL_MINE; it < NUM_INDUSTRYTYPES; it++) {
  1614 		/* Once the number of industries has been determined, let's really create them.
  1614 		/* Once the number of industries has been determined, let's really create them.
  1615 		 * The test for chance allows us to try create industries that are available only
  1615 		 * The test for chance allows us to try create industries that are available only
  1616 		 * for this landscape.
  1616 		 * for this landscape.
  1617 		 * @todo :  Do we really have to pass chance as un-scaled value, since we've already
  1617 		 * @todo :  Do we really have to pass chance as un-scaled value, since we've already
  1618 		 *          processed that scaling above? No, don't think so.  Will find a way. */
  1618 		 *          processed that scaling above? No, don't think so.  Will find a way. */
  1750 {
  1750 {
  1751 	Industry *ind;               //will receive the industry's creation pointer
  1751 	Industry *ind;               //will receive the industry's creation pointer
  1752 	IndustryType rndtype, j;     // Loop controlers
  1752 	IndustryType rndtype, j;     // Loop controlers
  1753 	const IndustrySpec *ind_spc;
  1753 	const IndustrySpec *ind_spc;
  1754 	uint num = 0;
  1754 	uint num = 0;
  1755 	ProbabilityHelper cumulative_probs[IT_END]; // probability collector
  1755 	ProbabilityHelper cumulative_probs[NUM_INDUSTRYTYPES]; // probability collector
  1756 	uint16 probability_max = 0;
  1756 	uint16 probability_max = 0;
  1757 
  1757 
  1758 	/* Generate a list of all possible industries that can be built. */
  1758 	/* Generate a list of all possible industries that can be built. */
  1759 	for (j = 0; j < IT_END; j++) {
  1759 	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
  1760 		byte chance = GetIndustrySpec(j)->appear_ingame[_opt.landscape];
  1760 		byte chance = GetIndustrySpec(j)->appear_ingame[_opt.landscape];
  1761 
  1761 
  1762 		/* if appearing chance for this landscape is above 0, this industry can be chosen */
  1762 		/* if appearing chance for this landscape is above 0, this industry can be chosen */
  1763 		if (chance != 0) {
  1763 		if (chance != 0) {
  1764 			probability_max += chance;
  1764 			probability_max += chance;
  1768 		}
  1768 		}
  1769 	}
  1769 	}
  1770 
  1770 
  1771 	/* Find a random type, with maximum being what has been evaluate above*/
  1771 	/* Find a random type, with maximum being what has been evaluate above*/
  1772 	rndtype = RandomRange(probability_max);
  1772 	rndtype = RandomRange(probability_max);
  1773 	for (j = 0; j < IT_END; j++) {
  1773 	for (j = 0; j < NUM_INDUSTRYTYPES; j++) {
  1774 		/* and choose the index of the industry that matches as close as possible this random type */
  1774 		/* and choose the index of the industry that matches as close as possible this random type */
  1775 		if (cumulative_probs[j].prob >= rndtype) break;
  1775 		if (cumulative_probs[j].prob >= rndtype) break;
  1776 	}
  1776 	}
  1777 
  1777 
  1778 	ind_spc = GetIndustrySpec(cumulative_probs[j].ind);
  1778 	ind_spc = GetIndustrySpec(cumulative_probs[j].ind);