summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-26 19:51:49 +0000
committertruelight <truelight@openttd.org>2006-08-26 19:51:49 +0000
commitb7fcce091eba6ab8603f7ae10d8952c26015baf7 (patch)
tree6ea2d59fac96e685c5333e8f358b59b50f7f67a4
parentb3cf0189a3163781fb661e9b1431b5c381d18c80 (diff)
downloadopenttd-b7fcce091eba6ab8603f7ae10d8952c26015baf7.tar.xz
(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.
-rw-r--r--industry.h8
-rw-r--r--industry_cmd.c71
2 files changed, 43 insertions, 36 deletions
diff --git a/industry.h b/industry.h
index e4cbaa628..d654e0735 100644
--- a/industry.h
+++ b/industry.h
@@ -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)
diff --git a/industry_cmd.c b/industry_cmd.c
index 43397b47d..1fd1124be 100644
--- 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 @@ 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)