# industry_map.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #ifndef INDUSTRY_MAP_H
    00013 #define INDUSTRY_MAP_H
    00014
    00015 #include "industrytype.h"
    00016 #include "tile_map.h"
    00017 #include "water_map.h"
    00018
    00019
    00025 enum {
    00026   GFX_COAL_MINE_TOWER_NOT_ANIMATED   =   0,
    00027   GFX_COAL_MINE_TOWER_ANIMATED       =   1,
    00028   GFX_POWERPLANT_CHIMNEY             =   8,
    00029   GFX_POWERPLANT_SPARKS              =  10,
    00030   GFX_OILRIG_1                       =  24,
    00031   GFX_OILRIG_2                       =  25,
    00032   GFX_OILRIG_3                       =  26,
    00033   GFX_OILRIG_4                       =  27,
    00034   GFX_OILRIG_5                       =  28,
    00035   GFX_OILWELL_NOT_ANIMATED           =  29,
    00036   GFX_OILWELL_ANIMATED_1             =  30,
    00037   GFX_OILWELL_ANIMATED_2             =  31,
    00038   GFX_OILWELL_ANIMATED_3             =  32,
    00039   GFX_COPPER_MINE_TOWER_NOT_ANIMATED =  47,
    00040   GFX_COPPER_MINE_TOWER_ANIMATED     =  48,
    00041   GFX_COPPER_MINE_CHIMNEY            =  49,
    00042   GFX_GOLD_MINE_TOWER_NOT_ANIMATED   =  79,
    00043   GFX_GOLD_MINE_TOWER_ANIMATED       =  88,
    00044   GFX_TOY_FACTORY                    = 143,
    00045   GFX_PLASTIC_FOUNTAIN_ANIMATED_1    = 148,
    00046   GFX_PLASTIC_FOUNTAIN_ANIMATED_2    = 149,
    00047   GFX_PLASTIC_FOUNTAIN_ANIMATED_3    = 150,
    00048   GFX_PLASTIC_FOUNTAIN_ANIMATED_4    = 151,
    00049   GFX_PLASTIC_FOUNTAIN_ANIMATED_5    = 152,
    00050   GFX_PLASTIC_FOUNTAIN_ANIMATED_6    = 153,
    00051   GFX_PLASTIC_FOUNTAIN_ANIMATED_7    = 154,
    00052   GFX_PLASTIC_FOUNTAIN_ANIMATED_8    = 155,
    00053   GFX_BUBBLE_GENERATOR               = 161,
    00054   GFX_BUBBLE_CATCHER                 = 162,
    00055   GFX_TOFFEE_QUARY                   = 165,
    00056   GFX_SUGAR_MINE_SIEVE               = 174,
    00057   GFX_WATERTILE_SPECIALCHECK         = 255,
    00058 };
    00059
    00066 static inline IndustryID GetIndustryIndex(TileIndex t)
    00067 {
    00068   assert(IsTileType(t, MP_INDUSTRY));
    00069   return _m[t].m2;
    00070 }
    00071
    00078 static inline bool IsIndustryCompleted(TileIndex t)
    00079 {
    00080   assert(IsTileType(t, MP_INDUSTRY));
    00081   return HasBit(_m[t].m1, 7);
    00082 }
    00083
    00084 IndustryType GetIndustryType(TileIndex tile);
    00085
    00092 static inline void SetIndustryCompleted(TileIndex tile, bool isCompleted)
    00093 {
    00094   assert(IsTileType(tile, MP_INDUSTRY));
    00095   SB(_m[tile].m1, 7, 1, isCompleted ? 1 :0);
    00096 }
    00097
    00104 static inline byte GetIndustryConstructionStage(TileIndex tile)
    00105 {
    00106   assert(IsTileType(tile, MP_INDUSTRY));
    00107   return IsIndustryCompleted(tile) ? (byte)INDUSTRY_COMPLETED : GB(_m[tile].m1, 0, 2);
    00108 }
    00109
    00116 static inline void SetIndustryConstructionStage(TileIndex tile, byte value)
    00117 {
    00118   assert(IsTileType(tile, MP_INDUSTRY));
    00119   SB(_m[tile].m1, 0, 2, value);
    00120 }
    00121
    00129 static inline IndustryGfx GetCleanIndustryGfx(TileIndex t)
    00130 {
    00131   assert(IsTileType(t, MP_INDUSTRY));
    00132   return _m[t].m5 | (GB(_m[t].m6, 2, 1) << 8);
    00133 }
    00134
    00141 static inline IndustryGfx GetIndustryGfx(TileIndex t)
    00142 {
    00143   assert(IsTileType(t, MP_INDUSTRY));
    00144   return GetTranslatedIndustryTileID(GetCleanIndustryGfx(t));
    00145 }
    00146
    00153 static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
    00154 {
    00155   assert(IsTileType(t, MP_INDUSTRY));
    00156   _m[t].m5 = GB(gfx, 0, 8);
    00157   SB(_m[t].m6, 2, 1, GB(gfx, 8, 1));
    00158 }
    00159
    00165 static inline bool IsIndustryTileOnWater(TileIndex t)
    00166 {
    00167   assert(IsTileType(t, MP_INDUSTRY));
    00168   return (GetWaterClass(t) != WATER_CLASS_INVALID);
    00169 }
    00170
    00177 static inline byte GetIndustryConstructionCounter(TileIndex tile)
    00178 {
    00179   assert(IsTileType(tile, MP_INDUSTRY));
    00180   return GB(_m[tile].m1, 2, 2);
    00181 }
    00182
    00189 static inline void SetIndustryConstructionCounter(TileIndex tile, byte value)
    00190 {
    00191   assert(IsTileType(tile, MP_INDUSTRY));
    00192   SB(_m[tile].m1, 2, 2, value);
    00193 }
    00194
    00202 static inline void ResetIndustryConstructionStage(TileIndex tile)
    00203 {
    00204   assert(IsTileType(tile, MP_INDUSTRY));
    00205   SB(_m[tile].m1, 0, 4, 0);
    00206   SB(_m[tile].m1, 7, 1, 0);
    00207 }
    00208
    00214 static inline byte GetIndustryAnimationLoop(TileIndex tile)
    00215 {
    00216   assert(IsTileType(tile, MP_INDUSTRY));
    00217   return _m[tile].m4;
    00218 }
    00219
    00226 static inline void SetIndustryAnimationLoop(TileIndex tile, byte count)
    00227 {
    00228   assert(IsTileType(tile, MP_INDUSTRY));
    00229   _m[tile].m4 = count;
    00230 }
    00231
    00237 static inline byte GetIndustryAnimationState(TileIndex tile)
    00238 {
    00239   assert(IsTileType(tile, MP_INDUSTRY));
    00240   return _m[tile].m3;
    00241 }
    00242
    00249 static inline void SetIndustryAnimationState(TileIndex tile, byte state)
    00250 {
    00251   assert(IsTileType(tile, MP_INDUSTRY));
    00252   _m[tile].m3 = state;
    00253 }
    00254
    00262 static inline byte GetIndustryRandomBits(TileIndex tile)
    00263 {
    00264   assert(IsTileType(tile, MP_INDUSTRY));
    00265   return _me[tile].m7;
    00266 }
    00267
    00275 static inline void SetIndustryRandomBits(TileIndex tile, byte bits)
    00276 {
    00277   assert(IsTileType(tile, MP_INDUSTRY));
    00278   _me[tile].m7 = bits;
    00279 }
    00280
    00288 static inline byte GetIndustryTriggers(TileIndex tile)
    00289 {
    00290   assert(IsTileType(tile, MP_INDUSTRY));
    00291   return GB(_m[tile].m6, 3, 3);
    00292 }
    00293
    00294
    00302 static inline void SetIndustryTriggers(TileIndex tile, byte triggers)
    00303 {
    00304   assert(IsTileType(tile, MP_INDUSTRY));
    00305   SB(_m[tile].m6, 3, 3, triggers);
    00306 }
    00307
    00316 static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
    00317 {
    00318   SetTileType(t, MP_INDUSTRY);
    00319   _m[t].m1 = 0;
    00320   _m[t].m2 = index;
    00321   _m[t].m3 = 0;
    00322   _m[t].m4 = 0;
    00323   SetIndustryGfx(t, gfx); // m5, part of m6
    00324   SetIndustryTriggers(t, 0); // rest of m6
    00325   SetIndustryRandomBits(t, random); // m7
    00326   SetWaterClass(t, wc);
    00327 }
    00328
    00329 #endif /* INDUSTRY_MAP_H */