summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2006-04-10 21:00:56 +0000
committerbelugas <belugas@openttd.org>2006-04-10 21:00:56 +0000
commitf1da549c10f8e2d2207f1b6325a86b0210a28b5e (patch)
treee2a2356f833bf455ac95d036ad577eb097f20f49
parentb0ee09fd1d82f1e28cd061e978c30dda3ae103e0 (diff)
downloadopenttd-f1da549c10f8e2d2207f1b6325a86b0210a28b5e.tar.xz
(svn r4350) CodeChange : Add and use accessors [G|S]etIndustrype. Define and use IndustryGfx type instead of uint
-rw-r--r--industry.h6
-rw-r--r--industry_cmd.c48
-rw-r--r--industry_map.h51
-rw-r--r--smallmap_gui.c2
4 files changed, 90 insertions, 17 deletions
diff --git a/industry.h b/industry.h
index 7f3d216b9..e2841ed36 100644
--- a/industry.h
+++ b/industry.h
@@ -82,11 +82,11 @@ enum {
IT_FARM = 9,
IT_COPPER_MINE = 10,
IT_OIL_WELL = 11,
- IT_BANK = 12,
+ IT_BANK_TEMP = 12,
IT_FOOD_PROCESS = 13,
IT_PAPER_MILL = 14,
IT_GOLD_MINE = 15,
- IT_BANK_2 = 16,
+ IT_BANK_TROPIC_ARCTIC = 16,
IT_DIAMOND_MINE = 17,
IT_IRON_MINE = 18,
IT_FRUIT_PLANTATION = 19,
@@ -107,6 +107,8 @@ enum {
IT_BUBBLE_GENERATOR = 34,
IT_TOFFEE_QUARRY = 35,
IT_SUGAR_MINE = 36,
+ IT_END,
+ IT_INVALID = 255,
};
typedef enum IndustryLifeTypes {
diff --git a/industry_cmd.c b/industry_cmd.c
index 31d16699e..bc85e0fb6 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -75,7 +75,7 @@ typedef struct DrawIndustrySpec4Struct {
typedef struct IndustryTileTable {
TileIndexDiffC ti;
- byte gfx;
+ IndustryGfx gfx;
} IndustryTileTable;
typedef struct IndustrySpec {
@@ -93,7 +93,7 @@ typedef struct IndustrySpec {
-static const IndustryType _industry_close_mode[37] = {
+static const IndustryType _industry_close_mode[IT_END] = {
/* COAL_MINE */ INDUSTRYLIFE_PRODUCTION,
/* POWER_STATION */ INDUSTRYLIFE_NOT_CLOSABLE,
/* SAWMILL */ INDUSTRYLIFE_CLOSABLE,
@@ -133,7 +133,7 @@ static const IndustryType _industry_close_mode[37] = {
/* SUGAR_MINE */ INDUSTRYLIFE_PRODUCTION
};
-static const StringID _industry_prod_up_strings[] = {
+static const StringID _industry_prod_up_strings[IT_END] = {
STR_4836_NEW_COAL_SEAM_FOUND_AT,
STR_4835_INCREASES_PRODUCTION,
STR_4835_INCREASES_PRODUCTION,
@@ -173,7 +173,7 @@ static const StringID _industry_prod_up_strings[] = {
STR_4835_INCREASES_PRODUCTION,
};
-static const StringID _industry_prod_down_strings[] = {
+static const StringID _industry_prod_down_strings[IT_END] = {
STR_4839_PRODUCTION_DOWN_BY_50,
STR_4839_PRODUCTION_DOWN_BY_50,
STR_4839_PRODUCTION_DOWN_BY_50,
@@ -213,7 +213,7 @@ static const StringID _industry_prod_down_strings[] = {
STR_4839_PRODUCTION_DOWN_BY_50,
};
-static const StringID _industry_close_strings[] = {
+static const StringID _industry_close_strings[IT_END] = {
STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
STR_4832_ANNOUNCES_IMMINENT_CLOSURE,
STR_4833_SUPPLY_PROBLEMS_CAUSE_TO,
@@ -253,6 +253,31 @@ static const StringID _industry_close_strings[] = {
STR_4832_ANNOUNCES_IMMINENT_CLOSURE
};
+/**
+ * Retrieve the type for this industry. Although it is accessed by a tile,
+ * it will return the general type of industry, and not the sprite index
+ * as would do GetIndustryGfx.
+ * The same information can be accessed by looking at Industry->type
+ * @param tile that is queried
+ * @pre IsTileType(tile, MP_INDUSTRY)
+ * @return general type for this industry, as defined in industry.h
+ **/
+IndustryType GetIndustryType(TileIndex tile)
+{
+ IndustryGfx this_type = GetIndustryGfx(tile);
+ IndustryType iloop;
+
+ assert(IsTileType(tile, MP_INDUSTRY));
+
+ for (iloop = IT_COAL_MINE; iloop < IT_END; iloop += 1) {
+ if IS_INT_INSIDE(this_type, industry_gfx_Solver[iloop].MinGfx,
+ industry_gfx_Solver[iloop].MaxGfx) {
+ return iloop;
+ }
+ }
+
+ return IT_INVALID; //we have not found equivalent, whatever the reason
+}
static void IndustryDrawSugarMine(const TileInfo *ti)
{
@@ -393,7 +418,6 @@ static void DrawTile_Industry(TileInfo *ti)
}
}
-
static uint GetSlopeZ_Industry(const TileInfo* ti)
{
return ti->z + (ti->tileh == 0 ? 0 : 8);
@@ -406,7 +430,7 @@ static uint GetSlopeTileh_Industry(TileIndex tile, uint tileh)
static void GetAcceptedCargo_Industry(TileIndex tile, AcceptedCargo ac)
{
- uint gfx = GetIndustryGfx(tile);
+ IndustryGfx gfx = GetIndustryGfx(tile);
CargoID a;
a = _industry_section_accepts_1[gfx];
@@ -596,7 +620,7 @@ static void AnimateTile_Industry(TileIndex tile)
case 148: case 149: case 150: case 151:
case 152: case 153: case 154: case 155:
if ((_tick_counter & 3) == 0) {
- uint gfx = GetIndustryGfx(tile);
+ IndustryGfx gfx = GetIndustryGfx(tile);
gfx = (gfx < 155) ? gfx + 1 : 148;
SetIndustryGfx(tile, gfx);
@@ -607,7 +631,7 @@ static void AnimateTile_Industry(TileIndex tile)
case 30: case 31: case 32:
if ((_tick_counter & 7) == 0) {
bool b = CHANCE16(1,7);
- uint gfx = GetIndustryGfx(tile);
+ IndustryGfx gfx = GetIndustryGfx(tile);
m = GB(_m[tile].m1, 0, 2) + 1;
if (m == 4 && (m = 0, ++gfx) == 32 + 1 && (gfx = 30, b)) {
@@ -745,7 +769,7 @@ static void TileLoopIndustry_BubbleGenerator(TileIndex tile)
static void TileLoop_Industry(TileIndex tile)
{
- uint newgfx;
+ IndustryGfx newgfx;
if (!IsIndustryCompleted(tile)) {
MakeIndustryTileBigger(tile);
@@ -1328,12 +1352,12 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable*
if (bits & 8 && (t & (2 + 4))) return false;
}
- if (type == IT_BANK) {
+ if (type == IT_BANK_TEMP) {
if (!IsTileType(cur_tile, MP_HOUSE) || t->population < 1200) {
_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
return false;
}
- } else if (type == IT_BANK_2) {
+ } else if (type == IT_BANK_TROPIC_ARCTIC) {
if (!IsTileType(cur_tile, MP_HOUSE)) {
_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS;
return false;
diff --git a/industry_map.h b/industry_map.h
index 55c4c3875..a734d792b 100644
--- a/industry_map.h
+++ b/industry_map.h
@@ -9,6 +9,7 @@
#include "macros.h"
#include "tile.h"
+typedef uint IndustryGfx;
static inline uint GetIndustryIndex(TileIndex t)
{
@@ -27,6 +28,8 @@ static inline bool IsIndustryCompleted(TileIndex t)
return HASBIT(_m[t].m1, 7);
}
+IndustryType GetIndustryType(TileIndex tile);
+
/**
* Set if the industry that owns the tile as under construction or not
* @param tile the tile to query
@@ -63,13 +66,13 @@ static inline void SetIndustryConstructionStage(TileIndex tile, byte value)
SB(_m[tile].m1, 0, 2, value);
}
-static inline uint GetIndustryGfx(TileIndex t)
+static inline IndustryGfx GetIndustryGfx(TileIndex t)
{
assert(IsTileType(t, MP_INDUSTRY));
return _m[t].m5;
}
-static inline void SetIndustryGfx(TileIndex t, uint gfx)
+static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
{
assert(IsTileType(t, MP_INDUSTRY));
_m[t].m5 = gfx;
@@ -123,4 +126,48 @@ static inline void ResetIndustryConstructionStage(TileIndex tile)
_m[tile].m1 = 0;
}
+typedef struct IndustryTypeSolver {
+ IndustryGfx MinGfx;
+ IndustryGfx MaxGfx;
+ } IndustryTypeSolver;
+
+static const IndustryTypeSolver industry_gfx_Solver [IT_END] = {
+ { 0, 6}, //IT_COAL_MINE
+ { 7, 10}, //IT_POWER_STATION,
+ { 11, 15}, //IT_SAWMILL,
+ { 16, 17}, //IT_FOREST,
+ { 18, 23}, //IT_OIL_REFINERY,
+ { 24, 28}, //IT_OIL_RIG,
+ { 29, 31}, //IT_OIL_WELL,
+ { 32, 38}, //IT_FARM,
+ { 39, 42}, //IT_FACTORY,
+ { 43, 46}, //IT_PRINTING_WORKS,
+ { 47, 51}, //IT_COPPER_MINE,
+ { 52, 57}, //IT_STEEL_MILL,
+ { 58, 59}, //IT_BANK_TEMP,
+ { 60, 63}, //IT_FOOD_PROCESS,
+ { 64, 71}, //IT_PAPER_MILL,
+ { 72, 88}, //IT_GOLD_MINE,
+ { 89, 90}, //IT_BANK_TROPIC_ARCTIC,
+ { 91, 99}, //IT_DIAMOND_MINE,
+ {100, 115}, //IT_IRON_MINE,
+ {116, 116}, //IT_FRUIT_PLANTATION,
+ {117, 117}, //IT_RUBBER_PLANTATION,
+ {118, 119}, //IT_WATER_SUPPLY,
+ {120, 120}, //IT_WATER_TOWER,
+ {121, 124}, //IT_FACTORY_2,
+ {125, 128}, //IT_LUMBER_MILL,
+ {129, 130}, //IT_COTTON_CANDY,
+ {131, 134}, //IT_CANDY_FACTORY or sweet factory
+ {135, 136}, //IT_BATTERY_FARM,
+ {137, 137}, //IT_COLA_WELLS,
+ {138, 141}, //IT_TOY_SHOP,
+ {142, 147}, //IT_TOY_FACTORY,
+ {148, 155}, //IT_PLASTIC_FOUNTAINS,
+ {156, 159}, //IT_FIZZY_DRINK_FACTORY,
+ {160, 163}, //IT_BUBBLE_GENERATOR,
+ {164, 166}, //IT_TOFFEE_QUARRY,
+ {167, 174} //IT_SUGAR_MINE,
+};
+
#endif /* INDUSTRY_MAP_H */
diff --git a/smallmap_gui.c b/smallmap_gui.c
index 360b89fdb..ee4378756 100644
--- a/smallmap_gui.c
+++ b/smallmap_gui.c
@@ -490,7 +490,7 @@ static inline uint32 GetSmallMapVegetationPixels(TileIndex tile)
break;
case MP_INDUSTRY:
- bits = IS_BYTE_INSIDE(GetIndustryGfx(tile), 0x10, 0x12) ? MKCOLOR(0xD0D0D0D0) : MKCOLOR(0xB5B5B5B5);
+ bits = GetIndustryType(tile) == IT_FOREST ? MKCOLOR(0xD0D0D0D0) : MKCOLOR(0xB5B5B5B5);
break;
case MP_TREES: