src/industry_cmd.cpp
branchgamebalance
changeset 9895 7bd07f43b0e3
parent 6527 f584ab6d87f8
child 9903 dc85aaa556ae
equal deleted inserted replaced
9894:70d78ac95d6c 9895:7bd07f43b0e3
   231 
   231 
   232 	/* Pointer to industry */
   232 	/* Pointer to industry */
   233 	ind = GetIndustryByTile(ti->tile);
   233 	ind = GetIndustryByTile(ti->tile);
   234 
   234 
   235 	/* Retrieve pointer to the draw industry tile struct */
   235 	/* Retrieve pointer to the draw industry tile struct */
   236 	dits = &_industry_draw_tile_data[gfx << 2 | (_industry_section_draw_animation_state[gfx] ?
   236 	dits = &_industry_draw_tile_data[gfx << 2 | (GetIndustryTileSpec(gfx)->anim_state ?
   237 			GetIndustryAnimationState(ti->tile) & 3 :
   237 			GetIndustryAnimationState(ti->tile) & 3 :
   238 			GetIndustryConstructionStage(ti->tile))];
   238 			GetIndustryConstructionStage(ti->tile))];
   239 
   239 
   240 	image = dits->ground.sprite;
   240 	image = dits->ground.sprite;
   241 	if (HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->ground.pal == PAL_NONE) {
   241 	if (HASBIT(image, PALETTE_MODIFIER_COLOR) && dits->ground.pal == PAL_NONE) {
   355 		i->last_mo_production[0] += cw;
   355 		i->last_mo_production[0] += cw;
   356 
   356 
   357 		am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
   357 		am = MoveGoodsToStation(i->xy, i->width, i->height, i->produced_cargo[0], cw);
   358 		i->last_mo_transported[0] += am;
   358 		i->last_mo_transported[0] += am;
   359 		if (am != 0) {
   359 		if (am != 0) {
   360 			uint newgfx = _industry_produce_section[GetIndustryGfx(tile)];
   360 			uint newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_production;
   361 
   361 
   362 			if (newgfx != 0xFF) {
   362 			if (newgfx != INDUTILE_NOANIM) {
   363 				ResetIndustryConstructionStage(tile);
   363 				ResetIndustryConstructionStage(tile);
   364 				SetIndustryCompleted(tile, true);
   364 				SetIndustryCompleted(tile, true);
   365 				SetIndustryGfx(tile, newgfx);
   365 				SetIndustryGfx(tile, newgfx);
   366 				MarkTileDirtyByTile(tile);
   366 				MarkTileDirtyByTile(tile);
   367 			}
   367 			}
   643 
   643 
   644 	if (_game_mode == GM_EDITOR) return;
   644 	if (_game_mode == GM_EDITOR) return;
   645 
   645 
   646 	TransportIndustryGoods(tile);
   646 	TransportIndustryGoods(tile);
   647 
   647 
   648 	newgfx = _industry_section_animation_next[GetIndustryGfx(tile)];
   648 	newgfx = GetIndustryTileSpec(GetIndustryGfx(tile))->anim_next;
   649 	if (newgfx != 255) {
   649 	if (newgfx != INDUTILE_NOANIM) {
   650 		ResetIndustryConstructionStage(tile);
   650 		ResetIndustryConstructionStage(tile);
   651 		SetIndustryGfx(tile, newgfx);
   651 		SetIndustryGfx(tile, newgfx);
   652 		MarkTileDirtyByTile(tile);
   652 		MarkTileDirtyByTile(tile);
   653 		return;
   653 		return;
   654 	}
   654 	}
   983 			ChopLumberMillTrees(i);
   983 			ChopLumberMillTrees(i);
   984 		}
   984 		}
   985 	}
   985 	}
   986 }
   986 }
   987 
   987 
   988 void OnTick_Industry(void)
   988 void OnTick_Industry()
   989 {
   989 {
   990 	Industry *i;
   990 	Industry *i;
   991 
   991 
   992 	if (_industry_sound_ctr != 0) {
   992 	if (_industry_sound_ctr != 0) {
   993 		_industry_sound_ctr++;
   993 		_industry_sound_ctr++;
  1353 		}
  1353 		}
  1354 	}
  1354 	}
  1355 	return true;
  1355 	return true;
  1356 }
  1356 }
  1357 
  1357 
  1358 static Industry *AllocateIndustry(void)
  1358 static Industry *AllocateIndustry()
  1359 {
  1359 {
  1360 	Industry *i;
  1360 	Industry *i;
  1361 
  1361 
  1362 	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
  1362 	/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
  1363 	 * TODO - This is just a temporary stage, this will be removed. */
  1363 	 * TODO - This is just a temporary stage, this will be removed. */
  1580 
  1580 
  1581 		_current_player = old_player;
  1581 		_current_player = old_player;
  1582 	}
  1582 	}
  1583 }
  1583 }
  1584 
  1584 
  1585 void GenerateIndustries(void)
  1585 void GenerateIndustries()
  1586 {
  1586 {
  1587 	const byte *b;
  1587 	const byte *b;
  1588 	uint i = 0;
  1588 	uint i = 0;
  1589 
  1589 
  1590 	/* Find the total amount of industries */
  1590 	/* Find the total amount of industries */
  1668 	if (closeit) {
  1668 	if (closeit) {
  1669 		i->prod_level = 0;
  1669 		i->prod_level = 0;
  1670 		SetDParam(0, i->index);
  1670 		SetDParam(0, i->index);
  1671 		AddNewsItem(
  1671 		AddNewsItem(
  1672 			indspec->closure_text,
  1672 			indspec->closure_text,
  1673 			NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0),
  1673 			NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_OPENCLOSE, 0),
  1674 			i->xy + TileDiffXY(1, 1), 0
  1674 			i->xy + TileDiffXY(1, 1), 0
  1675 		);
  1675 		);
  1676 	}
  1676 	}
  1677 }
  1677 }
  1678 
  1678 
  1729 	{30, 30, 30, 36, 36, 31, 31, 31, 27, 27, 27, 28, 28, 28, 26, 26, 26, 34, 34, 34, 35, 35, 35, 29, 29, 29, 32, 32, 32, 33, 33, 33},
  1729 	{30, 30, 30, 36, 36, 31, 31, 31, 27, 27, 27, 28, 28, 28, 26, 26, 26, 34, 34, 34, 35, 35, 35, 29, 29, 29, 32, 32, 32, 33, 33, 33},
  1730 };
  1730 };
  1731 
  1731 
  1732 static void MaybeNewIndustry(uint32 r)
  1732 static void MaybeNewIndustry(uint32 r)
  1733 {
  1733 {
  1734 	int type;
  1734 	int type =_new_industry_rand[_opt.landscape][GB(r, 16, 5)];
  1735 	int j;
  1735 	int j;
  1736 	Industry *i;
  1736 	Industry *i;
  1737 
  1737 	const IndustrySpec *ind_spc = GetIndustrySpec(type);;
  1738 	type = _new_industry_rand[_opt.landscape][GB(r, 16, 5)];
       
  1739 
  1738 
  1740 	if (type == IT_OIL_WELL && _cur_year > 1950) return;
  1739 	if (type == IT_OIL_WELL && _cur_year > 1950) return;
  1741 	if (type == IT_OIL_RIG  && _cur_year < 1960) return;
  1740 	if (type == IT_OIL_RIG  && _cur_year < 1960) return;
  1742 
  1741 
  1743 	j = 2000;
  1742 	j = 2000;
  1745 		i = CreateNewIndustry(RandomTile(), type);
  1744 		i = CreateNewIndustry(RandomTile(), type);
  1746 		if (i != NULL) break;
  1745 		if (i != NULL) break;
  1747 		if (--j == 0) return;
  1746 		if (--j == 0) return;
  1748 	}
  1747 	}
  1749 
  1748 
  1750 	SetDParam(0, GetIndustrySpec(type)->name);
  1749 	SetDParam(0, ind_spc->name);
  1751 	SetDParam(1, i->town->index);
  1750 	SetDParam(1, i->town->index);
  1752 	AddNewsItem(
  1751 	AddNewsItem(ind_spc->new_industry_text,
  1753 		(type != IT_FOREST && type != IT_FRUIT_PLANTATION && type != IT_RUBBER_PLANTATION && type != IT_COTTON_CANDY) ?
  1752 		NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_OPENCLOSE, 0), i->xy, 0);
  1754 			STR_482D_NEW_UNDER_CONSTRUCTION : STR_482E_NEW_BEING_PLANTED_NEAR,
       
  1755 		NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY,0), i->xy, 0
       
  1756 	);
       
  1757 }
  1753 }
  1758 
  1754 
  1759 static void ChangeIndustryProduction(Industry *i)
  1755 static void ChangeIndustryProduction(Industry *i)
  1760 {
  1756 {
  1761 	bool only_decrease = false;
  1757 	bool only_decrease = false;
  1818 			break;
  1814 			break;
  1819 	}
  1815 	}
  1820 
  1816 
  1821 	if (str != STR_NULL) {
  1817 	if (str != STR_NULL) {
  1822 		SetDParam(0, i->index);
  1818 		SetDParam(0, i->index);
  1823 		AddNewsItem(str, NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_TILE, NT_ECONOMY, 0), i->xy + TileDiffXY(1, 1), 0);
  1819 		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);
  1824 	}
  1820 	}
  1825 }
  1821 }
  1826 
  1822 
  1827 void IndustryMonthlyLoop(void)
  1823 void IndustryMonthlyLoop()
  1828 {
  1824 {
  1829 	Industry *i;
  1825 	Industry *i;
  1830 	PlayerID old_player = _current_player;
  1826 	PlayerID old_player = _current_player;
  1831 	_current_player = OWNER_NONE;
  1827 	_current_player = OWNER_NONE;
  1832 
  1828 
  1848 	_industry_sort_dirty = true;
  1844 	_industry_sort_dirty = true;
  1849 	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
  1845 	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
  1850 }
  1846 }
  1851 
  1847 
  1852 
  1848 
  1853 void InitializeIndustries(void)
  1849 void InitializeIndustries()
  1854 {
  1850 {
  1855 	CleanPool(&_Industry_pool);
  1851 	CleanPool(&_Industry_pool);
  1856 	AddBlockToPool(&_Industry_pool);
  1852 	AddBlockToPool(&_Industry_pool);
  1857 
  1853 
  1858 	_total_industries = 0;
  1854 	_total_industries = 0;
  1906 	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
  1902 	SLE_CONDNULL(32, 2, SL_MAX_VERSION),
  1907 
  1903 
  1908 	SLE_END()
  1904 	SLE_END()
  1909 };
  1905 };
  1910 
  1906 
  1911 static void Save_INDY(void)
  1907 static void Save_INDY()
  1912 {
  1908 {
  1913 	Industry *ind;
  1909 	Industry *ind;
  1914 
  1910 
  1915 	/* Write the vehicles */
  1911 	/* Write the vehicles */
  1916 	FOR_ALL_INDUSTRIES(ind) {
  1912 	FOR_ALL_INDUSTRIES(ind) {
  1917 		SlSetArrayIndex(ind->index);
  1913 		SlSetArrayIndex(ind->index);
  1918 		SlObject(ind, _industry_desc);
  1914 		SlObject(ind, _industry_desc);
  1919 	}
  1915 	}
  1920 }
  1916 }
  1921 
  1917 
  1922 static void Load_INDY(void)
  1918 static void Load_INDY()
  1923 {
  1919 {
  1924 	int index;
  1920 	int index;
  1925 
  1921 
  1926 	_total_industries = 0;
  1922 	_total_industries = 0;
  1927 
  1923