src/industry_cmd.cpp
changeset 6987 b0f13039bda2
parent 6964 737c8b546ca5
child 6989 43b359b4cb86
equal deleted inserted replaced
6986:168d3add1f13 6987:b0f13039bda2
    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 < IT_END; 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
   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 	}
  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;
  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 {