town_map.h

Go to the documentation of this file.
00001 /* $Id: town_map.h 12347 2008-03-06 14:21:10Z frosch $ */
00002 
00005 #ifndef TOWN_MAP_H
00006 #define TOWN_MAP_H
00007 
00008 #include "town.h"
00009 #include "date_func.h"
00010 #include "tile_map.h"
00011 #include "functions.h"
00012 
00019 static inline TownID GetTownIndex(TileIndex t)
00020 {
00021   assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_ROAD)); // XXX incomplete
00022   return _m[t].m2;
00023 }
00024 
00032 static inline void SetTownIndex(TileIndex t, TownID index)
00033 {
00034   assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_ROAD));
00035   _m[t].m2 = index;
00036 }
00037 
00043 static inline Town *GetTownByTile(TileIndex t)
00044 {
00045   return GetTown(GetTownIndex(t));
00046 }
00047 
00056 static inline HouseID GetHouseType(TileIndex t)
00057 {
00058   assert(IsTileType(t, MP_HOUSE));
00059   return _m[t].m4 | (GB(_m[t].m3, 6, 1) << 8);
00060 }
00061 
00068 static inline void SetHouseType(TileIndex t, HouseID house_id)
00069 {
00070   assert(IsTileType(t, MP_HOUSE));
00071   _m[t].m4 = GB(house_id, 0, 8);
00072   SB(_m[t].m3, 6, 1, GB(house_id, 8, 1));
00073 }
00074 
00080 static inline bool LiftHasDestination(TileIndex t)
00081 {
00082   return HasBit(_me[t].m7, 0);
00083 }
00084 
00091 static inline void SetLiftDestination(TileIndex t, byte dest)
00092 {
00093   SetBit(_me[t].m7, 0);
00094   SB(_me[t].m7, 1, 3, dest);
00095 }
00096 
00102 static inline byte GetLiftDestination(TileIndex t)
00103 {
00104   return GB(_me[t].m7, 1, 3);
00105 }
00106 
00113 static inline void HaltLift(TileIndex t)
00114 {
00115   SB(_me[t].m7, 0, 4, 0);
00116   DeleteAnimatedTile(t);
00117 }
00118 
00124 static inline byte GetLiftPosition(TileIndex t)
00125 {
00126   return GB(_m[t].m6, 2, 6);
00127 }
00128 
00134 static inline void SetLiftPosition(TileIndex t, byte pos)
00135 {
00136   SB(_m[t].m6, 2, 6, pos);
00137 }
00138 
00145 static inline byte GetHouseAnimationFrame(TileIndex t)
00146 {
00147   assert(IsTileType(t, MP_HOUSE));
00148   return GB(_m[t].m6, 2, 6) | (GB(_m[t].m3, 5, 1) << 6);
00149 }
00150 
00157 static inline void SetHouseAnimationFrame(TileIndex t, byte frame)
00158 {
00159   assert(IsTileType(t, MP_HOUSE));
00160   SB(_m[t].m6, 2, 6, GB(frame, 0, 6));
00161   SB(_m[t].m3, 5, 1, GB(frame, 6, 1));
00162 }
00163 
00169 static inline bool IsHouseCompleted(TileIndex t)
00170 {
00171   assert(IsTileType(t, MP_HOUSE));
00172   return HasBit(_m[t].m3, 7);
00173 }
00174 
00180 static inline void SetHouseCompleted(TileIndex t, bool status)
00181 {
00182   assert(IsTileType(t, MP_HOUSE));
00183   SB(_m[t].m3, 7, 1, !!status);
00184 }
00185 
00196 static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
00197 {
00198   assert(IsTileType(t, MP_CLEAR));
00199 
00200   SetTileType(t, MP_HOUSE);
00201   _m[t].m1 = random_bits;
00202   _m[t].m2 = tid;
00203   _m[t].m3 = 0;
00204   SetHouseType(t, type);
00205   SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
00206   _m[t].m5 = IsHouseCompleted(t) ? 0 : (stage << 3 | counter);
00207   SetHouseAnimationFrame(t, 0);
00208   _me[t].m7 = GetHouseSpecs(type)->processing_time;
00209 
00210   if (GetHouseSpecs(type)->building_flags & BUILDING_IS_ANIMATED) AddAnimatedTile(t);
00211   MarkTileDirtyByTile(t);
00212 }
00213 
00235 static inline byte GetHouseBuildingStage(TileIndex t)
00236 {
00237   assert(IsTileType(t, MP_HOUSE));
00238   return IsHouseCompleted(t) ? (byte)TOWN_HOUSE_COMPLETED : GB(_m[t].m5, 3, 2);
00239 }
00240 
00247 static inline byte GetHouseConstructionTick(TileIndex t)
00248 {
00249   assert(IsTileType(t, MP_HOUSE));
00250   return IsHouseCompleted(t) ? 0 : GB(_m[t].m5, 0, 3);
00251 }
00252 
00260 static inline void IncHouseConstructionTick(TileIndex t)
00261 {
00262   assert(IsTileType(t, MP_HOUSE));
00263   AB(_m[t].m5, 0, 5, 1);
00264 
00265   if (GB(_m[t].m5, 3, 2) == TOWN_HOUSE_COMPLETED) {
00266     /* House is now completed.
00267      * Store the year of construction as well, for newgrf house purpose */
00268     SetHouseCompleted(t, true);
00269     _m[t].m5 = Clamp(_cur_year - ORIGINAL_BASE_YEAR, 0, 0xFF);
00270   }
00271 }
00272 
00279 static inline Year GetHouseConstructionYear(TileIndex t)
00280 {
00281   assert(IsTileType(t, MP_HOUSE));
00282   return IsHouseCompleted(t) ? _m[t].m5 + ORIGINAL_BASE_YEAR : 0;
00283 }
00284 
00292 static inline void SetHouseRandomBits(TileIndex t, byte random)
00293 {
00294   assert(IsTileType(t, MP_HOUSE));
00295   _m[t].m1 = random;
00296 }
00297 
00305 static inline byte GetHouseRandomBits(TileIndex t)
00306 {
00307   assert(IsTileType(t, MP_HOUSE));
00308   return _m[t].m1;
00309 }
00310 
00318 static inline void SetHouseTriggers(TileIndex t, byte triggers)
00319 {
00320   assert(IsTileType(t, MP_HOUSE));
00321   SB(_m[t].m3, 0, 5, triggers);
00322 }
00323 
00331 static inline byte GetHouseTriggers(TileIndex t)
00332 {
00333   assert(IsTileType(t, MP_HOUSE));
00334   return GB(_m[t].m3, 0, 5);
00335 }
00336 
00343 static inline byte GetHouseProcessingTime(TileIndex t)
00344 {
00345   assert(IsTileType(t, MP_HOUSE));
00346   return _me[t].m7;
00347 }
00348 
00355 static inline void SetHouseProcessingTime(TileIndex t, byte time)
00356 {
00357   assert(IsTileType(t, MP_HOUSE));
00358   _me[t].m7 = time;
00359 }
00360 
00366 static inline void DecHouseProcessingTime(TileIndex t)
00367 {
00368   assert(IsTileType(t, MP_HOUSE));
00369   _me[t].m7--;
00370 }
00371 
00372 #endif /* TOWN_MAP_H */

Generated on Wed Oct 1 17:03:24 2008 for openttd by  doxygen 1.5.6