src/industry_map.h
changeset 5726 8f399788f6c9
parent 5687 a6f0e780d714
child 6285 187e3ef04cc9
equal deleted inserted replaced
5725:8ad0e96437e0 5726:8f399788f6c9
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file industry_map.h Accessors for industries */
       
     4 
       
     5 #ifndef INDUSTRY_MAP_H
       
     6 #define INDUSTRY_MAP_H
       
     7 
       
     8 #include "industry.h"
       
     9 #include "macros.h"
       
    10 #include "tile.h"
       
    11 
       
    12 
       
    13 
       
    14 /**
       
    15  * The following enums are indices used to know what to draw for this industry tile.
       
    16  * They all are pointing toward array _industry_draw_tile_data, in table/industry_land.h
       
    17  * How to calculate the correct position ? GFXid << 2 | IndustryStage (0 to 3)
       
    18  */
       
    19 enum {
       
    20 	GFX_COAL_MINE_TOWER_NOT_ANIMATED   =   0,
       
    21 	GFX_COAL_MINE_TOWER_ANIMATED       =   1,
       
    22 	GFX_POWERPLANT_CHIMNEY             =   8,
       
    23 	GFX_POWERPLANT_SPARKS              =  10,
       
    24 	GFX_OILRIG_1                       =  24,
       
    25 	GFX_OILRIG_2                       =  25,
       
    26 	GFX_OILRIG_3                       =  26,
       
    27 	GFX_OILRIG_4                       =  27,
       
    28 	GFX_OILRIG_5                       =  28,
       
    29 	GFX_OILWELL_NOT_ANIMATED           =  29,
       
    30 	GFX_OILWELL_ANIMATED_1             =  30,
       
    31 	GFX_OILWELL_ANIMATED_2             =  31,
       
    32 	GFX_OILWELL_ANIMATED_3             =  32,
       
    33 	GFX_COPPER_MINE_TOWER_NOT_ANIMATED =  47,
       
    34 	GFX_COPPER_MINE_TOWER_ANIMATED     =  48,
       
    35 	GFX_COPPER_MINE_CHIMNEY            =  49,
       
    36 	GFX_GOLD_MINE_TOWER_NOT_ANIMATED   =  79,
       
    37 	GFX_GOLD_MINE_TOWER_ANIMATED       =  88,
       
    38 	GFX_TOY_FACTORY                    = 143,
       
    39 	GFX_PLASTIC_FOUNTAIN_ANIMATED_1    = 148,
       
    40 	GFX_PLASTIC_FOUNTAIN_ANIMATED_2    = 149,
       
    41 	GFX_PLASTIC_FOUNTAIN_ANIMATED_3    = 150,
       
    42 	GFX_PLASTIC_FOUNTAIN_ANIMATED_4    = 151,
       
    43 	GFX_PLASTIC_FOUNTAIN_ANIMATED_5    = 152,
       
    44 	GFX_PLASTIC_FOUNTAIN_ANIMATED_6    = 153,
       
    45 	GFX_PLASTIC_FOUNTAIN_ANIMATED_7    = 154,
       
    46 	GFX_PLASTIC_FOUNTAIN_ANIMATED_8    = 155,
       
    47 	GFX_BUBBLE_GENERATOR               = 161,
       
    48 	GFX_BUBBLE_CATCHER                 = 162,
       
    49 	GFX_TOFFEE_QUARY                   = 165,
       
    50 	GFX_SUGAR_MINE_SIEVE               = 174,
       
    51 	NUM_INDUSTRY_GFXES                 = 175,
       
    52 };
       
    53 
       
    54 static inline IndustryID GetIndustryIndex(TileIndex t)
       
    55 {
       
    56 	assert(IsTileType(t, MP_INDUSTRY));
       
    57 	return _m[t].m2;
       
    58 }
       
    59 
       
    60 static inline Industry* GetIndustryByTile(TileIndex t)
       
    61 {
       
    62 	return GetIndustry(GetIndustryIndex(t));
       
    63 }
       
    64 
       
    65 static inline bool IsIndustryCompleted(TileIndex t)
       
    66 {
       
    67 	assert(IsTileType(t, MP_INDUSTRY));
       
    68 	return HASBIT(_m[t].m1, 7);
       
    69 }
       
    70 
       
    71 IndustryType GetIndustryType(TileIndex tile);
       
    72 
       
    73 /**
       
    74  * Set if the industry that owns the tile as under construction or not
       
    75  * @param tile the tile to query
       
    76  * @param isCompleted whether it is completed or not
       
    77  * @pre IsTileType(tile, MP_INDUSTRY)
       
    78  */
       
    79 static inline void SetIndustryCompleted(TileIndex tile, bool isCompleted)
       
    80 {
       
    81 	assert(IsTileType(tile, MP_INDUSTRY));
       
    82 	SB(_m[tile].m1, 7, 1, isCompleted ? 1 :0);
       
    83 }
       
    84 
       
    85 /**
       
    86  * Returns the industry construction stage of the specified tile
       
    87  * @param tile the tile to query
       
    88  * @pre IsTileType(tile, MP_INDUSTRY)
       
    89  * @return the construction stage
       
    90  */
       
    91 static inline byte GetIndustryConstructionStage(TileIndex tile)
       
    92 {
       
    93 	assert(IsTileType(tile, MP_INDUSTRY));
       
    94 	return GB(_m[tile].m1, 0, 2);
       
    95 }
       
    96 
       
    97 /**
       
    98  * Sets the industry construction stage of the specified tile
       
    99  * @param tile the tile to query
       
   100  * @param value the new construction stage
       
   101  * @pre IsTileType(tile, MP_INDUSTRY)
       
   102  */
       
   103 static inline void SetIndustryConstructionStage(TileIndex tile, byte value)
       
   104 {
       
   105 	assert(IsTileType(tile, MP_INDUSTRY));
       
   106 	SB(_m[tile].m1, 0, 2, value);
       
   107 }
       
   108 
       
   109 static inline IndustryGfx GetIndustryGfx(TileIndex t)
       
   110 {
       
   111 	assert(IsTileType(t, MP_INDUSTRY));
       
   112 	return _m[t].m5;
       
   113 }
       
   114 
       
   115 static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
       
   116 {
       
   117 	assert(IsTileType(t, MP_INDUSTRY));
       
   118 	_m[t].m5 = gfx;
       
   119 }
       
   120 
       
   121 static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx)
       
   122 {
       
   123 	SetTileType(t, MP_INDUSTRY);
       
   124 	_m[t].m1 = 0;
       
   125 	_m[t].m2 = index;
       
   126 	_m[t].m3 = 0;
       
   127 	_m[t].m4 = 0;
       
   128 	_m[t].m5 = gfx;
       
   129 }
       
   130 
       
   131 /**
       
   132  * Returns this indutry tile's construction counter value
       
   133  * @param tile the tile to query
       
   134  * @pre IsTileType(tile, MP_INDUSTRY)
       
   135  * @return the construction counter
       
   136  */
       
   137 static inline byte GetIndustryConstructionCounter(TileIndex tile)
       
   138 {
       
   139 	assert(IsTileType(tile, MP_INDUSTRY));
       
   140 	return GB(_m[tile].m1, 2, 2);
       
   141 }
       
   142 
       
   143 /**
       
   144  * Sets this indutry tile's construction counter value
       
   145  * @param tile the tile to query
       
   146  * @param value the new value for the construction counter
       
   147  * @pre IsTileType(tile, MP_INDUSTRY)
       
   148  */
       
   149 static inline void SetIndustryConstructionCounter(TileIndex tile, byte value)
       
   150 {
       
   151 	assert(IsTileType(tile, MP_INDUSTRY));
       
   152 	SB(_m[tile].m1, 2, 2, value);
       
   153 }
       
   154 
       
   155 /**
       
   156  * Reset the construction stage counter of the industry,
       
   157  * as well as the completion bit.
       
   158  * In fact, it is the same as restarting construction frmo ground up
       
   159  * @param tile the tile to query
       
   160  * @param generating_world whether generating a world or not
       
   161  * @pre IsTileType(tile, MP_INDUSTRY)
       
   162  */
       
   163 static inline void ResetIndustryConstructionStage(TileIndex tile)
       
   164 {
       
   165 	assert(IsTileType(tile, MP_INDUSTRY));
       
   166 	_m[tile].m1 = 0;
       
   167 }
       
   168 
       
   169 typedef struct IndustryTypeSolver {
       
   170 	IndustryGfx MinGfx;
       
   171 	IndustryGfx MaxGfx;
       
   172 } IndustryTypeSolver;
       
   173 
       
   174 static const IndustryTypeSolver industry_gfx_Solver [IT_END] = {
       
   175 	{  0,   6}, //IT_COAL_MINE
       
   176 	{  7,  10}, //IT_POWER_STATION,
       
   177 	{ 11,  15}, //IT_SAWMILL,
       
   178 	{ 16,  17}, //IT_FOREST,
       
   179 	{ 18,  23}, //IT_OIL_REFINERY,
       
   180 	{ 24,  28}, //IT_OIL_RIG,
       
   181 	{ 29,  31}, //IT_OIL_WELL,
       
   182 	{ 32,  38}, //IT_FARM,
       
   183 	{ 39,  42}, //IT_FACTORY,
       
   184 	{ 43,  46}, //IT_PRINTING_WORKS,
       
   185 	{ 47,  51}, //IT_COPPER_MINE,
       
   186 	{ 52,  57}, //IT_STEEL_MILL,
       
   187 	{ 58,  59}, //IT_BANK_TEMP,
       
   188 	{ 60,  63}, //IT_FOOD_PROCESS,
       
   189 	{ 64,  71}, //IT_PAPER_MILL,
       
   190 	{ 72,  88}, //IT_GOLD_MINE,
       
   191 	{ 89,  90}, //IT_BANK_TROPIC_ARCTIC,
       
   192 	{ 91,  99}, //IT_DIAMOND_MINE,
       
   193 	{100, 115}, //IT_IRON_MINE,
       
   194 	{116, 116}, //IT_FRUIT_PLANTATION,
       
   195 	{117, 117}, //IT_RUBBER_PLANTATION,
       
   196 	{118, 119}, //IT_WATER_SUPPLY,
       
   197 	{120, 120}, //IT_WATER_TOWER,
       
   198 	{121, 124}, //IT_FACTORY_2,
       
   199 	{125, 128}, //IT_LUMBER_MILL,
       
   200 	{129, 130}, //IT_COTTON_CANDY,
       
   201 	{131, 134}, //IT_CANDY_FACTORY or sweet factory
       
   202 	{135, 136}, //IT_BATTERY_FARM,
       
   203 	{137, 137}, //IT_COLA_WELLS,
       
   204 	{138, 141}, //IT_TOY_SHOP,
       
   205 	{142, 147}, //IT_TOY_FACTORY,
       
   206 	{148, 155}, //IT_PLASTIC_FOUNTAINS,
       
   207 	{156, 159}, //IT_FIZZY_DRINK_FACTORY,
       
   208 	{160, 163}, //IT_BUBBLE_GENERATOR,
       
   209 	{164, 166}, //IT_TOFFEE_QUARRY,
       
   210 	{167, 174}  //IT_SUGAR_MINE,
       
   211 };
       
   212 
       
   213 /**
       
   214  * Get the animation loop number
       
   215  * @param tile the tile to get the animation loop number of
       
   216  * @pre IsTileType(tile, MP_INDUSTRY)
       
   217  */
       
   218 static inline byte GetIndustryAnimationLoop(TileIndex tile)
       
   219 {
       
   220 	assert(IsTileType(tile, MP_INDUSTRY));
       
   221 	return _m[tile].m4;
       
   222 }
       
   223 
       
   224 /**
       
   225  * Set the animation loop number
       
   226  * @param tile the tile to set the animation loop number of
       
   227  * @param count the new animation frame number
       
   228  * @pre IsTileType(tile, MP_INDUSTRY)
       
   229  */
       
   230 static inline void SetIndustryAnimationLoop(TileIndex tile, byte count)
       
   231 {
       
   232 	assert(IsTileType(tile, MP_INDUSTRY));
       
   233 	_m[tile].m4 = count;
       
   234 }
       
   235 
       
   236 /**
       
   237  * Get the animation state
       
   238  * @param tile the tile to get the animation state of
       
   239  * @pre IsTileType(tile, MP_INDUSTRY)
       
   240  */
       
   241 static inline byte GetIndustryAnimationState(TileIndex tile)
       
   242 {
       
   243 	assert(IsTileType(tile, MP_INDUSTRY));
       
   244 	return _m[tile].m3;
       
   245 }
       
   246 
       
   247 /**
       
   248  * Set the animation state
       
   249  * @param tile the tile to set the animation state of
       
   250  * @param count the new animation state
       
   251  * @pre IsTileType(tile, MP_INDUSTRY)
       
   252  */
       
   253 static inline void SetIndustryAnimationState(TileIndex tile, byte state)
       
   254 {
       
   255 	assert(IsTileType(tile, MP_INDUSTRY));
       
   256 	_m[tile].m3 = state;
       
   257 }
       
   258 
       
   259 #endif /* INDUSTRY_MAP_H */