mirror of https://github.com/OpenTTD/OpenTTD.git
(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.
This commit is contained in:
parent
b3cf0189a3
commit
b7fcce091e
|
@ -131,6 +131,14 @@ static inline Industry *GetRandomIndustry(void)
|
|||
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)
|
||||
|
||||
|
|
|
@ -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 @@ static void IndustryPoolNewBlock(uint start_item)
|
|||
/* 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 @@ const IndustrySpec *GetIndustrySpec(IndustryType thistype)
|
|||
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 @@ static void ChangeTileOwner_Industry(TileIndex tile, PlayerID old_player, Player
|
|||
/* 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)
|
||||
|
|
Loading…
Reference in New Issue