industry_map.h

Go to the documentation of this file.
00001 /* $Id: industry_map.h 18809 2010-01-15 16:41:15Z rubidium $ */
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 "water_map.h"
00017 
00018 
00024 enum {
00025   GFX_COAL_MINE_TOWER_NOT_ANIMATED   =   0,
00026   GFX_COAL_MINE_TOWER_ANIMATED       =   1,
00027   GFX_POWERPLANT_CHIMNEY             =   8,
00028   GFX_POWERPLANT_SPARKS              =  10,
00029   GFX_OILRIG_1                       =  24,
00030   GFX_OILRIG_2                       =  25,
00031   GFX_OILRIG_3                       =  26,
00032   GFX_OILRIG_4                       =  27,
00033   GFX_OILRIG_5                       =  28,
00034   GFX_OILWELL_NOT_ANIMATED           =  29,
00035   GFX_OILWELL_ANIMATED_1             =  30,
00036   GFX_OILWELL_ANIMATED_2             =  31,
00037   GFX_OILWELL_ANIMATED_3             =  32,
00038   GFX_COPPER_MINE_TOWER_NOT_ANIMATED =  47,
00039   GFX_COPPER_MINE_TOWER_ANIMATED     =  48,
00040   GFX_COPPER_MINE_CHIMNEY            =  49,
00041   GFX_GOLD_MINE_TOWER_NOT_ANIMATED   =  79,
00042   GFX_GOLD_MINE_TOWER_ANIMATED       =  88,
00043   GFX_TOY_FACTORY                    = 143,
00044   GFX_PLASTIC_FOUNTAIN_ANIMATED_1    = 148,
00045   GFX_PLASTIC_FOUNTAIN_ANIMATED_2    = 149,
00046   GFX_PLASTIC_FOUNTAIN_ANIMATED_3    = 150,
00047   GFX_PLASTIC_FOUNTAIN_ANIMATED_4    = 151,
00048   GFX_PLASTIC_FOUNTAIN_ANIMATED_5    = 152,
00049   GFX_PLASTIC_FOUNTAIN_ANIMATED_6    = 153,
00050   GFX_PLASTIC_FOUNTAIN_ANIMATED_7    = 154,
00051   GFX_PLASTIC_FOUNTAIN_ANIMATED_8    = 155,
00052   GFX_BUBBLE_GENERATOR               = 161,
00053   GFX_BUBBLE_CATCHER                 = 162,
00054   GFX_TOFFEE_QUARY                   = 165,
00055   GFX_SUGAR_MINE_SIEVE               = 174,
00056   GFX_WATERTILE_SPECIALCHECK         = 255,  
00057 };
00058 
00065 static inline IndustryID GetIndustryIndex(TileIndex t)
00066 {
00067   assert(IsTileType(t, MP_INDUSTRY));
00068   return _m[t].m2;
00069 }
00070 
00077 static inline bool IsIndustryCompleted(TileIndex t)
00078 {
00079   assert(IsTileType(t, MP_INDUSTRY));
00080   return HasBit(_m[t].m1, 7);
00081 }
00082 
00083 IndustryType GetIndustryType(TileIndex tile);
00084 
00091 static inline void SetIndustryCompleted(TileIndex tile, bool isCompleted)
00092 {
00093   assert(IsTileType(tile, MP_INDUSTRY));
00094   SB(_m[tile].m1, 7, 1, isCompleted ? 1 :0);
00095 }
00096 
00103 static inline byte GetIndustryConstructionStage(TileIndex tile)
00104 {
00105   assert(IsTileType(tile, MP_INDUSTRY));
00106   return IsIndustryCompleted(tile) ? (byte)INDUSTRY_COMPLETED : GB(_m[tile].m1, 0, 2);
00107 }
00108 
00115 static inline void SetIndustryConstructionStage(TileIndex tile, byte value)
00116 {
00117   assert(IsTileType(tile, MP_INDUSTRY));
00118   SB(_m[tile].m1, 0, 2, value);
00119 }
00120 
00128 static inline IndustryGfx GetCleanIndustryGfx(TileIndex t)
00129 {
00130   assert(IsTileType(t, MP_INDUSTRY));
00131   return _m[t].m5 | (GB(_m[t].m6, 2, 1) << 8);
00132 }
00133 
00140 static inline IndustryGfx GetIndustryGfx(TileIndex t)
00141 {
00142   assert(IsTileType(t, MP_INDUSTRY));
00143   return GetTranslatedIndustryTileID(GetCleanIndustryGfx(t));
00144 }
00145 
00152 static inline void SetIndustryGfx(TileIndex t, IndustryGfx gfx)
00153 {
00154   assert(IsTileType(t, MP_INDUSTRY));
00155   _m[t].m5 = GB(gfx, 0, 8);
00156   SB(_m[t].m6, 2, 1, GB(gfx, 8, 1));
00157 }
00158 
00164 static inline bool IsIndustryTileOnWater(TileIndex t)
00165 {
00166   assert(IsTileType(t, MP_INDUSTRY));
00167   return (GetWaterClass(t) != WATER_CLASS_INVALID);
00168 }
00169 
00176 static inline byte GetIndustryConstructionCounter(TileIndex tile)
00177 {
00178   assert(IsTileType(tile, MP_INDUSTRY));
00179   return GB(_m[tile].m1, 2, 2);
00180 }
00181 
00188 static inline void SetIndustryConstructionCounter(TileIndex tile, byte value)
00189 {
00190   assert(IsTileType(tile, MP_INDUSTRY));
00191   SB(_m[tile].m1, 2, 2, value);
00192 }
00193 
00201 static inline void ResetIndustryConstructionStage(TileIndex tile)
00202 {
00203   assert(IsTileType(tile, MP_INDUSTRY));
00204   SB(_m[tile].m1, 0, 4, 0);
00205   SB(_m[tile].m1, 7, 1, 0);
00206 }
00207 
00213 static inline byte GetIndustryAnimationLoop(TileIndex tile)
00214 {
00215   assert(IsTileType(tile, MP_INDUSTRY));
00216   return _m[tile].m4;
00217 }
00218 
00225 static inline void SetIndustryAnimationLoop(TileIndex tile, byte count)
00226 {
00227   assert(IsTileType(tile, MP_INDUSTRY));
00228   _m[tile].m4 = count;
00229 }
00230 
00236 static inline byte GetIndustryAnimationState(TileIndex tile)
00237 {
00238   assert(IsTileType(tile, MP_INDUSTRY));
00239   return _m[tile].m3;
00240 }
00241 
00248 static inline void SetIndustryAnimationState(TileIndex tile, byte state)
00249 {
00250   assert(IsTileType(tile, MP_INDUSTRY));
00251   _m[tile].m3 = state;
00252 }
00253 
00261 static inline byte GetIndustryRandomBits(TileIndex tile)
00262 {
00263   assert(IsTileType(tile, MP_INDUSTRY));
00264   return _me[tile].m7;
00265 }
00266 
00274 static inline void SetIndustryRandomBits(TileIndex tile, byte bits)
00275 {
00276   assert(IsTileType(tile, MP_INDUSTRY));
00277   _me[tile].m7 = bits;
00278 }
00279 
00287 static inline byte GetIndustryTriggers(TileIndex tile)
00288 {
00289   assert(IsTileType(tile, MP_INDUSTRY));
00290   return GB(_m[tile].m6, 3, 3);
00291 }
00292 
00293 
00301 static inline void SetIndustryTriggers(TileIndex tile, byte triggers)
00302 {
00303   assert(IsTileType(tile, MP_INDUSTRY));
00304   SB(_m[tile].m6, 3, 3, triggers);
00305 }
00306 
00315 static inline void MakeIndustry(TileIndex t, IndustryID index, IndustryGfx gfx, uint8 random, WaterClass wc)
00316 {
00317   SetTileType(t, MP_INDUSTRY);
00318   _m[t].m1 = 0;
00319   _m[t].m2 = index;
00320   _m[t].m3 = 0;
00321   _m[t].m4 = 0;
00322   SetIndustryGfx(t, gfx); // m5, part of m6
00323   SetIndustryTriggers(t, 0); // rest of m6
00324   SetIndustryRandomBits(t, random); // m7
00325   SetWaterClass(t, wc);
00326 }
00327 
00328 #endif /* INDUSTRY_MAP_H */

Generated on Sat Jun 5 21:52:05 2010 for OpenTTD by  doxygen 1.6.1