summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2006-04-10 15:09:56 +0000
committerbelugas <belugas@openttd.org>2006-04-10 15:09:56 +0000
commit43101bd2d114423e1b61bcfdf82ef64f8349a147 (patch)
treeb5d0374e10871b67150591e288f8b0ba183dc582
parent24f871debad5aa218c2a22bf40c16689ffe21b7b (diff)
downloadopenttd-43101bd2d114423e1b61bcfdf82ef64f8349a147.tar.xz
(svn r4346) CodeChange : Add and Use Accessors to Industry's Stage and Counter construction. Removed last direct map access from Disaster_cmd.c as well. Based on work from Rubidium in tfc_newmap
-rw-r--r--disaster_cmd.c2
-rw-r--r--industry_cmd.c27
-rw-r--r--industry_map.h82
3 files changed, 97 insertions, 14 deletions
diff --git a/disaster_cmd.c b/disaster_cmd.c
index b11afbb63..da4c3e766 100644
--- a/disaster_cmd.c
+++ b/disaster_cmd.c
@@ -339,7 +339,7 @@ static void DestructIndustry(Industry *i)
for (tile = 0; tile != MapSize(); tile++) {
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == i->index) {
- _m[tile].m1 = 0;
+ ResetIndustryConstructionStage(tile);
MarkTileDirtyByTile(tile);
}
}
diff --git a/industry_cmd.c b/industry_cmd.c
index 411ee918b..d5223c43e 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -356,7 +356,7 @@ static void DrawTile_Industry(TileInfo *ti)
ormod = GENERAL_SPRITE_COLOR(ind->color_map);
/* Retrieve pointer to the draw industry tile struct */
- dits = &_industry_draw_tile_data[GetIndustryGfx(ti->tile) << 2 | GB(_m[ti->tile].m1, 0, 2)];
+ dits = &_industry_draw_tile_data[GetIndustryGfx(ti->tile) << 2 | GetIndustryConstructionStage(ti->tile)];
image = dits->sprite_1;
if (image & PALETTE_MODIFIER_COLOR && (image & PALETTE_SPRITE_MASK) == 0)
@@ -485,7 +485,8 @@ static void TransportIndustryGoods(TileIndex tile)
uint newgfx = _industry_produce_section[GetIndustryGfx(tile)];
if (newgfx != 0xFF) {
- _m[tile].m1 = 0x80;
+ ResetIndustryConstructionStage(tile);
+ SetIndustryCompleted(tile, true);
SetIndustryGfx(tile, newgfx);
MarkTileDirtyByTile(tile);
}
@@ -678,18 +679,22 @@ static void CreateIndustryEffectSmoke(TileIndex tile)
CreateEffectVehicle(x + 15, y + 14, z + 59 + (tileh != 0 ? 8 : 0), EV_CHIMNEY_SMOKE);
}
-static void MakeIndustryTileBigger(TileIndex tile, byte size)
+static void MakeIndustryTileBigger(TileIndex tile)
{
- byte b = (byte)((size + (1<<2)) & (3<<2));
+ byte cnt = GetIndustryConstructionCounter(tile) + 1;
+ byte stage;
- if (b != 0) {
- _m[tile].m1 = b | (size & 3);
+ if (cnt != 4) {
+ SetIndustryConstructionCounter(tile, cnt);
return;
}
- size = (size + 1) & 3;
- if (size == 3) size |= 0x80;
- _m[tile].m1 = size | b;
+ stage = GetIndustryConstructionStage(tile) + 1;
+ SetIndustryConstructionCounter(tile, 0);
+ SetIndustryConstructionStage(tile, stage);
+ if (stage == 3) {
+ SetIndustryCompleted(tile, true);
+ }
MarkTileDirtyByTile(tile);
@@ -748,7 +753,7 @@ static void TileLoop_Industry(TileIndex tile)
uint newgfx;
if (!IsIndustryCompleted(tile)) {
- MakeIndustryTileBigger(tile, _m[tile].m1);
+ MakeIndustryTileBigger(tile);
return;
}
@@ -758,7 +763,7 @@ static void TileLoop_Industry(TileIndex tile)
newgfx = _industry_section_animation_next[GetIndustryGfx(tile)];
if (newgfx != 255) {
- _m[tile].m1 = 0;
+ ResetIndustryConstructionStage(tile);
SetIndustryGfx(tile, newgfx);
MarkTileDirtyByTile(tile);
return;
diff --git a/industry_map.h b/industry_map.h
index 3726b619c..55c4c3875 100644
--- a/industry_map.h
+++ b/industry_map.h
@@ -1,5 +1,10 @@
/* $Id$ */
+/** @file industry_map.h Accessors for industries */
+
+#ifndef INDUSTRY_MAP_H
+#define INDUSTRY_MAP_H
+
#include "industry.h"
#include "macros.h"
#include "tile.h"
@@ -16,13 +21,47 @@ static inline Industry* GetIndustryByTile(TileIndex t)
return GetIndustry(GetIndustryIndex(t));
}
-
static inline bool IsIndustryCompleted(TileIndex t)
{
assert(IsTileType(t, MP_INDUSTRY));
return HASBIT(_m[t].m1, 7);
}
+/**
+ * Set if the industry that owns the tile as under construction or not
+ * @param tile the tile to query
+ * @param isCompleted whether it is completed or not
+ * @pre IsTileType(tile, MP_INDUSTRY)
+ */
+static inline void SetIndustryCompleted(TileIndex tile, bool isCompleted)
+{
+ assert(IsTileType(tile, MP_INDUSTRY));
+ SB(_m[tile].m1, 7, 1, isCompleted ? 1 :0);
+}
+
+/**
+ * Returns the industry construction stage of the specified tile
+ * @param tile the tile to query
+ * @pre IsTileType(tile, MP_INDUSTRY)
+ * @return the construction stage
+ */
+static inline byte GetIndustryConstructionStage(TileIndex tile)
+{
+ assert(IsTileType(tile, MP_INDUSTRY));
+ return GB(_m[tile].m1, 0, 2);
+}
+
+/**
+ * Sets the industry construction stage of the specified tile
+ * @param tile the tile to query
+ * @param value the new construction stage
+ * @pre IsTileType(tile, MP_INDUSTRY)
+ */
+static inline void SetIndustryConstructionStage(TileIndex tile, byte value)
+{
+ assert(IsTileType(tile, MP_INDUSTRY));
+ SB(_m[tile].m1, 0, 2, value);
+}
static inline uint GetIndustryGfx(TileIndex t)
{
@@ -36,7 +75,6 @@ static inline void SetIndustryGfx(TileIndex t, uint gfx)
_m[t].m5 = gfx;
}
-
static inline void MakeIndustry(TileIndex t, uint index, uint gfx)
{
SetTileType(t, MP_INDUSTRY);
@@ -46,3 +84,43 @@ static inline void MakeIndustry(TileIndex t, uint index, uint gfx)
_m[t].m4 = 0;
_m[t].m5 = gfx;
}
+
+/**
+ * Returns this indutry tile's construction counter value
+ * @param tile the tile to query
+ * @pre IsTileType(tile, MP_INDUSTRY)
+ * @return the construction counter
+ */
+static inline byte GetIndustryConstructionCounter(TileIndex tile)
+{
+ assert(IsTileType(tile, MP_INDUSTRY));
+ return GB(_m[tile].m1, 2, 2);
+}
+
+/**
+ * Sets this indutry tile's construction counter value
+ * @param tile the tile to query
+ * @param value the new value for the construction counter
+ * @pre IsTileType(tile, MP_INDUSTRY)
+ */
+static inline void SetIndustryConstructionCounter(TileIndex tile, byte value)
+{
+ assert(IsTileType(tile, MP_INDUSTRY));
+ SB(_m[tile].m1, 2, 2, value);
+}
+
+/**
+ * Reset the construction stage counter of the industry,
+ * as well as the completion bit.
+ * In fact, it is the same as restarting construction frmo ground up
+ * @param tile the tile to query
+ * @param generating_world whether generating a world or not
+ * @pre IsTileType(tile, MP_INDUSTRY)
+ */
+static inline void ResetIndustryConstructionStage(TileIndex tile)
+{
+ assert(IsTileType(tile, MP_INDUSTRY));
+ _m[tile].m1 = 0;
+}
+
+#endif /* INDUSTRY_MAP_H */