src/industry_cmd.cpp
branchgamebalance
changeset 9910 0b2aebc8283e
parent 9909 dce9a6923bb7
child 9911 0b8b245a2391
equal deleted inserted replaced
9909:dce9a6923bb7 9910:0b2aebc8283e
    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 	}
    76 
    76 
    77 	return IT_INVALID;  //we have not found equivalent, whatever the reason
    77 	return IT_INVALID;  //we have not found equivalent, whatever the reason
    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.
   494 
   494 
   495 	case GFX_OILWELL_ANIMATED_1:
   495 	case GFX_OILWELL_ANIMATED_1:
   496 	case GFX_OILWELL_ANIMATED_2:
   496 	case GFX_OILWELL_ANIMATED_2:
   497 	case GFX_OILWELL_ANIMATED_3:
   497 	case GFX_OILWELL_ANIMATED_3:
   498 		if ((_tick_counter & 7) == 0) {
   498 		if ((_tick_counter & 7) == 0) {
   499 			bool b = CHANCE16(1,7);
   499 			bool b = CHANCE16(1, 7);
   500 			IndustryGfx gfx = GetIndustryGfx(tile);
   500 			IndustryGfx gfx = GetIndustryGfx(tile);
   501 
   501 
   502 			m = GetIndustryAnimationState(tile) + 1;
   502 			m = GetIndustryAnimationState(tile) + 1;
   503 			if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
   503 			if (m == 4 && (m = 0, ++gfx) == GFX_OILWELL_ANIMATED_3 + 1 && (gfx = GFX_OILWELL_ANIMATED_1, b)) {
   504 				SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED);
   504 				SetIndustryGfx(tile, GFX_OILWELL_NOT_ANIMATED);
   703 			DeleteAnimatedTile(tile);
   703 			DeleteAnimatedTile(tile);
   704 		}
   704 		}
   705 		break;
   705 		break;
   706 
   706 
   707 	case GFX_POWERPLANT_SPARKS:
   707 	case GFX_POWERPLANT_SPARKS:
   708 		if (CHANCE16(1,3)) {
   708 		if (CHANCE16(1, 3)) {
   709 			SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile);
   709 			SndPlayTileFx(SND_0C_ELECTRIC_SPARK, tile);
   710 			AddAnimatedTile(tile);
   710 			AddAnimatedTile(tile);
   711 		}
   711 		}
   712 		break;
   712 		break;
   713 
   713 
   962 	uint32 r;
   962 	uint32 r;
   963 	uint num;
   963 	uint num;
   964 
   964 
   965 	/* play a sound? */
   965 	/* play a sound? */
   966 	if ((i->counter & 0x3F) == 0) {
   966 	if ((i->counter & 0x3F) == 0) {
   967 		if (CHANCE16R(1,14,r) && (num=_industry_sounds[i->type][0]) != 0) {
   967 		if (CHANCE16R(1, 14, r) && (num = _industry_sounds[i->type][0]) != 0) {
   968 			SndPlayTileFx(
   968 			SndPlayTileFx(
   969 				(SoundFx)(_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16)),
   969 				(SoundFx)(_industry_sounds[i->type][1] + (((r >> 16) * num) >> 16)),
   970 				i->xy);
   970 				i->xy);
   971 		}
   971 		}
   972 	}
   972 	}
  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. */
  1666 					SetDParam(2, mag);
  1666 					SetDParam(2, mag);
  1667 					SetDParam(0, GetCargo(i->produced_cargo[j])->name);
  1667 					SetDParam(0, GetCargo(i->produced_cargo[j])->name);
  1668 					SetDParam(1, i->index);
  1668 					SetDParam(1, i->index);
  1669 					AddNewsItem(
  1669 					AddNewsItem(
  1670 						percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
  1670 						percent >= 0 ? STR_INDUSTRY_PROD_GOUP : STR_INDUSTRY_PROD_GODOWN,
  1671 						NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
  1671 						NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_ECONOMY, 0),
  1672 						i->xy + TileDiffXY(1, 1), 0
  1672 						i->xy + TileDiffXY(1, 1), 0
  1673 					);
  1673 					);
  1674 				}
  1674 				}
  1675 			}
  1675 			}
  1676 			break;
  1676 			break;
  1680 	if (closeit) {
  1680 	if (closeit) {
  1681 		i->prod_level = 0;
  1681 		i->prod_level = 0;
  1682 		SetDParam(0, i->index);
  1682 		SetDParam(0, i->index);
  1683 		AddNewsItem(
  1683 		AddNewsItem(
  1684 			indspec->closure_text,
  1684 			indspec->closure_text,
  1685 			NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_OPENCLOSE, 0),
  1685 			NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0),
  1686 			i->xy + TileDiffXY(1, 1), 0
  1686 			i->xy + TileDiffXY(1, 1), 0
  1687 		);
  1687 		);
  1688 	}
  1688 	}
  1689 }
  1689 }
  1690 
  1690 
  1696 
  1696 
  1697 	if (i->produced_cargo[0] != CT_INVALID) {
  1697 	if (i->produced_cargo[0] != CT_INVALID) {
  1698 		pct = 0;
  1698 		pct = 0;
  1699 		if (i->last_mo_production[0] != 0) {
  1699 		if (i->last_mo_production[0] != 0) {
  1700 			i->last_prod_year = _cur_year;
  1700 			i->last_prod_year = _cur_year;
  1701 			pct = min(i->last_mo_transported[0] * 256 / i->last_mo_production[0],255);
  1701 			pct = min(i->last_mo_transported[0] * 256 / i->last_mo_production[0], 255);
  1702 		}
  1702 		}
  1703 		i->pct_transported[0] = pct;
  1703 		i->pct_transported[0] = pct;
  1704 
  1704 
  1705 		i->total_production[0] = i->last_mo_production[0];
  1705 		i->total_production[0] = i->last_mo_production[0];
  1706 		i->last_mo_production[0] = 0;
  1706 		i->last_mo_production[0] = 0;
  1712 
  1712 
  1713 	if (i->produced_cargo[1] != CT_INVALID) {
  1713 	if (i->produced_cargo[1] != CT_INVALID) {
  1714 		pct = 0;
  1714 		pct = 0;
  1715 		if (i->last_mo_production[1] != 0) {
  1715 		if (i->last_mo_production[1] != 0) {
  1716 			i->last_prod_year = _cur_year;
  1716 			i->last_prod_year = _cur_year;
  1717 			pct = min(i->last_mo_transported[1] * 256 / i->last_mo_production[1],255);
  1717 			pct = min(i->last_mo_transported[1] * 256 / i->last_mo_production[1], 255);
  1718 		}
  1718 		}
  1719 		i->pct_transported[1] = pct;
  1719 		i->pct_transported[1] = pct;
  1720 
  1720 
  1721 		i->total_production[1] = i->last_mo_production[1];
  1721 		i->total_production[1] = i->last_mo_production[1];
  1722 		i->last_mo_production[1] = 0;
  1722 		i->last_mo_production[1] = 0;
  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);
  1789 	}
  1789 	}
  1790 
  1790 
  1791 	SetDParam(0, ind_spc->name);
  1791 	SetDParam(0, ind_spc->name);
  1792 	SetDParam(1, ind->town->index);
  1792 	SetDParam(1, ind->town->index);
  1793 	AddNewsItem(ind_spc->new_industry_text,
  1793 	AddNewsItem(ind_spc->new_industry_text,
  1794 		NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_OPENCLOSE, 0), ind->xy, 0);
  1794 		NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0), ind->xy, 0);
  1795 }
  1795 }
  1796 
  1796 
  1797 static void ChangeIndustryProduction(Industry *i)
  1797 static void ChangeIndustryProduction(Industry *i)
  1798 {
  1798 {
  1799 	bool only_decrease = false;
  1799 	bool only_decrease = false;
  1808 		case INDUSTRYLIFE_PRODUCTION:
  1808 		case INDUSTRYLIFE_PRODUCTION:
  1809 			/* decrease or increase */
  1809 			/* decrease or increase */
  1810 			if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE)
  1810 			if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE)
  1811 				only_decrease = true;
  1811 				only_decrease = true;
  1812 
  1812 
  1813 			if (only_decrease || CHANCE16(1,3)) {
  1813 			if (only_decrease || CHANCE16(1, 3)) {
  1814 				/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
  1814 				/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
  1815 				if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1,3)) {
  1815 				if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1, 3)) {
  1816 					/* Increase production */
  1816 					/* Increase production */
  1817 					if (i->prod_level != 0x80) {
  1817 					if (i->prod_level != 0x80) {
  1818 						byte b;
  1818 						byte b;
  1819 
  1819 
  1820 						i->prod_level <<= 1;
  1820 						i->prod_level <<= 1;
  1847 			}
  1847 			}
  1848 			break;
  1848 			break;
  1849 
  1849 
  1850 		case INDUSTRYLIFE_CLOSABLE:
  1850 		case INDUSTRYLIFE_CLOSABLE:
  1851 			/* maybe close */
  1851 			/* maybe close */
  1852 			if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1,2)) {
  1852 			if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1, 2)) {
  1853 				i->prod_level = 0;
  1853 				i->prod_level = 0;
  1854 				str = indspec->closure_text;
  1854 				str = indspec->closure_text;
  1855 			}
  1855 			}
  1856 			break;
  1856 			break;
  1857 	}
  1857 	}
  1858 
  1858 
  1859 	if (str != STR_NULL) {
  1859 	if (str != STR_NULL) {
  1860 		SetDParam(0, i->index);
  1860 		SetDParam(0, i->index);
  1861 		AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, str == indspec->closure_text ? NT_OPENCLOSE : NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0);
  1861 		AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, str == indspec->closure_text ? NT_OPENCLOSE : NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0);
  1862 	}
  1862 	}
  1863 }
  1863 }
  1864 
  1864 
  1865 void IndustryMonthlyLoop()
  1865 void IndustryMonthlyLoop()
  1866 {
  1866 {