Mercurial > hg > openttd
changeset 4403:50936d5e527b draft
(svn r6156) -Codechange: DeleteIndustry removes an industry from the pool
-Codechange: DestroyIndustry is called by DeleteIndustry to remove all things where a industry depends on.
Last 2 changes to prepare for new pool system. Not pretty now, will be soon.
author | truelight <truelight@openttd.org> |
---|---|
date | Sat, 26 Aug 2006 19:51:49 +0000 |
parents | 254c2ba8dac5 |
children | 9caa4ef62d05 |
files | industry.h industry_cmd.c |
diffstat | 2 files changed, 43 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/industry.h +++ b/industry.h @@ -131,6 +131,14 @@ return GetIndustry(index); } +void DestroyIndustry(Industry *i); + +static inline void DeleteIndustry(Industry *i) +{ + DestroyIndustry(i); + i->xy = 0; +} + #define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1 < GetIndustryPoolSize()) ? GetIndustry(i->index + 1) : NULL) if (IsValidIndustry(i)) #define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
--- a/industry_cmd.c +++ b/industry_cmd.c @@ -25,6 +25,13 @@ #include "genworld.h" #include "date.h" +void ShowIndustryViewWindow(int industry); +void BuildOilRig(TileIndex tile); +void DeleteOilRig(TileIndex tile); + +static byte _industry_sound_ctr; +static TileIndex _industry_sound_tile; + enum { /* Max industries: 64000 (8 * 8000) */ INDUSTRY_POOL_BLOCK_SIZE_BITS = 3, /* In bits, so (1 << 3) == 8 */ @@ -46,13 +53,6 @@ /* Initialize the industry-pool */ MemoryPool _industry_pool = { "Industry", INDUSTRY_POOL_MAX_BLOCKS, INDUSTRY_POOL_BLOCK_SIZE_BITS, sizeof(Industry), &IndustryPoolNewBlock, NULL, 0, 0, NULL }; -static byte _industry_sound_ctr; -static TileIndex _industry_sound_tile; - -void ShowIndustryViewWindow(int industry); -void BuildOilRig(TileIndex tile); -void DeleteOilRig(TileIndex tile); - static const IndustryType _industry_close_mode[IT_END] = { /* COAL_MINE */ INDUSTRYLIFE_PRODUCTION, /* POWER_STATION */ INDUSTRYLIFE_NOT_CLOSABLE, @@ -132,6 +132,34 @@ return &_industry_specs[thistype]; } +void DestroyIndustry(Industry *i) +{ + BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy); + if (IsTileType(tile_cur, MP_INDUSTRY)) { + if (GetIndustryIndex(tile_cur) == i->index) { + DoClearSquare(tile_cur); + } + } else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { + DeleteOilRig(tile_cur); + } + END_TILE_LOOP(tile_cur, i->width, i->height, i->xy); + + if (i->type == IT_FARM || i->type == IT_FARM_2) { + /* Remove the farmland and convert it to regular tiles over time. */ + BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) { + if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) && + GetIndustryIndexOfField(tile_cur) == i->index) { + SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY); + } + } END_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiff(21, 21)) + } + + _industry_sort_dirty = true; + DeleteSubsidyWithIndustry(i->index); + DeleteWindowById(WC_INDUSTRY_VIEW, i->index); + InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); +} + static void IndustryDrawSugarMine(const TileInfo *ti) { const DrawIndustrySpec1Struct *d; @@ -743,35 +771,6 @@ /* not used */ } -void DeleteIndustry(Industry *i) -{ - BEGIN_TILE_LOOP(tile_cur, i->width, i->height, i->xy); - if (IsTileType(tile_cur, MP_INDUSTRY)) { - if (GetIndustryIndex(tile_cur) == i->index) { - DoClearSquare(tile_cur); - } - } else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { - DeleteOilRig(tile_cur); - } - END_TILE_LOOP(tile_cur, i->width, i->height, i->xy); - - if (i->type == IT_FARM || i->type == IT_FARM_2) { - /* Remove the farmland and convert it to regular tiles over time. */ - BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) { - if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) && - GetIndustryIndexOfField(tile_cur) == i->index) { - SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY); - } - } END_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiff(21, 21)) - } - - i->xy = 0; - _industry_sort_dirty = true; - DeleteSubsidyWithIndustry(i->index); - DeleteWindowById(WC_INDUSTRY_VIEW, i->index); - InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0); -} - static const byte _plantfarmfield_type[] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}; static bool IsBadFarmFieldTile(TileIndex tile)