00001
00002
00005 #ifndef TOWN_MAP_H
00006 #define TOWN_MAP_H
00007
00008 #include "town.h"
00009 #include "tile_map.h"
00010
00017 static inline TownID GetTownIndex(TileIndex t)
00018 {
00019 assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_ROAD));
00020 return _m[t].m2;
00021 }
00022
00030 static inline void SetTownIndex(TileIndex t, TownID index)
00031 {
00032 assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_ROAD));
00033 _m[t].m2 = index;
00034 }
00035
00041 static inline Town *GetTownByTile(TileIndex t)
00042 {
00043 return GetTown(GetTownIndex(t));
00044 }
00045
00054 static inline HouseID GetHouseType(TileIndex t)
00055 {
00056 assert(IsTileType(t, MP_HOUSE));
00057 return _m[t].m4 | (GB(_m[t].m3, 6, 1) << 8);
00058 }
00059
00066 static inline void SetHouseType(TileIndex t, HouseID house_id)
00067 {
00068 assert(IsTileType(t, MP_HOUSE));
00069 _m[t].m4 = GB(house_id, 0, 8);
00070 SB(_m[t].m3, 6, 1, GB(house_id, 8, 1));
00071 }
00072
00078 static inline bool LiftHasDestination(TileIndex t)
00079 {
00080 return HasBit(_me[t].m7, 0);
00081 }
00082
00089 static inline void SetLiftDestination(TileIndex t, byte dest)
00090 {
00091 SetBit(_me[t].m7, 0);
00092 SB(_me[t].m7, 1, 3, dest);
00093 }
00094
00100 static inline byte GetLiftDestination(TileIndex t)
00101 {
00102 return GB(_me[t].m7, 1, 3);
00103 }
00104
00111 static inline void HaltLift(TileIndex t)
00112 {
00113 SB(_me[t].m7, 0, 4, 0);
00114 }
00115
00121 static inline byte GetLiftPosition(TileIndex t)
00122 {
00123 return GB(_m[t].m6, 2, 6);
00124 }
00125
00131 static inline void SetLiftPosition(TileIndex t, byte pos)
00132 {
00133 SB(_m[t].m6, 2, 6, pos);
00134 }
00135
00142 static inline byte GetHouseAnimationFrame(TileIndex t)
00143 {
00144 assert(IsTileType(t, MP_HOUSE));
00145 return GB(_m[t].m6, 2, 6) | (GB(_m[t].m3, 5, 1) << 6);
00146 }
00147
00154 static inline void SetHouseAnimationFrame(TileIndex t, byte frame)
00155 {
00156 assert(IsTileType(t, MP_HOUSE));
00157 SB(_m[t].m6, 2, 6, GB(frame, 0, 6));
00158 SB(_m[t].m3, 5, 1, GB(frame, 6, 1));
00159 }
00160
00166 static inline bool IsHouseCompleted(TileIndex t)
00167 {
00168 assert(IsTileType(t, MP_HOUSE));
00169 return HasBit(_m[t].m3, 7);
00170 }
00171
00177 static inline void SetHouseCompleted(TileIndex t, bool status)
00178 {
00179 assert(IsTileType(t, MP_HOUSE));
00180 SB(_m[t].m3, 7, 1, !!status);
00181 }
00182
00193 static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
00194 {
00195 assert(IsTileType(t, MP_CLEAR));
00196
00197 SetTileType(t, MP_HOUSE);
00198 _m[t].m1 = random_bits;
00199 _m[t].m2 = tid;
00200 _m[t].m3 = 0;
00201 SetHouseType(t, type);
00202 SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
00203 _m[t].m5 = IsHouseCompleted(t) ? 0 : (stage << 3 | counter);
00204 SetHouseAnimationFrame(t, 0);
00205 _me[t].m7 = GetHouseSpecs(type)->processing_time;
00206 }
00207
00229 static inline byte GetHouseBuildingStage(TileIndex t)
00230 {
00231 assert(IsTileType(t, MP_HOUSE));
00232 return IsHouseCompleted(t) ? (byte)TOWN_HOUSE_COMPLETED : GB(_m[t].m5, 3, 2);
00233 }
00234
00241 static inline byte GetHouseConstructionTick(TileIndex t)
00242 {
00243 assert(IsTileType(t, MP_HOUSE));
00244 return IsHouseCompleted(t) ? 0 : GB(_m[t].m5, 0, 3);
00245 }
00246
00254 static inline void IncHouseConstructionTick(TileIndex t)
00255 {
00256 assert(IsTileType(t, MP_HOUSE));
00257 AB(_m[t].m5, 0, 5, 1);
00258
00259 if (GB(_m[t].m5, 3, 2) == TOWN_HOUSE_COMPLETED) {
00260
00261
00262 SetHouseCompleted(t, true);
00263 }
00264 }
00265
00272 static inline void ResetHouseAge(TileIndex t)
00273 {
00274 assert(IsTileType(t, MP_HOUSE) && IsHouseCompleted(t));
00275 _m[t].m5 = 0;
00276 }
00277
00283 static inline void IncrementHouseAge(TileIndex t)
00284 {
00285 assert(IsTileType(t, MP_HOUSE));
00286 if (IsHouseCompleted(t) && _m[t].m5 < 0xFF) _m[t].m5++;
00287 }
00288
00295 static inline Year GetHouseAge(TileIndex t)
00296 {
00297 assert(IsTileType(t, MP_HOUSE));
00298 return IsHouseCompleted(t) ? _m[t].m5 : 0;
00299 }
00300
00308 static inline void SetHouseRandomBits(TileIndex t, byte random)
00309 {
00310 assert(IsTileType(t, MP_HOUSE));
00311 _m[t].m1 = random;
00312 }
00313
00321 static inline byte GetHouseRandomBits(TileIndex t)
00322 {
00323 assert(IsTileType(t, MP_HOUSE));
00324 return _m[t].m1;
00325 }
00326
00334 static inline void SetHouseTriggers(TileIndex t, byte triggers)
00335 {
00336 assert(IsTileType(t, MP_HOUSE));
00337 SB(_m[t].m3, 0, 5, triggers);
00338 }
00339
00347 static inline byte GetHouseTriggers(TileIndex t)
00348 {
00349 assert(IsTileType(t, MP_HOUSE));
00350 return GB(_m[t].m3, 0, 5);
00351 }
00352
00359 static inline byte GetHouseProcessingTime(TileIndex t)
00360 {
00361 assert(IsTileType(t, MP_HOUSE));
00362 return _me[t].m7;
00363 }
00364
00371 static inline void SetHouseProcessingTime(TileIndex t, byte time)
00372 {
00373 assert(IsTileType(t, MP_HOUSE));
00374 _me[t].m7 = time;
00375 }
00376
00382 static inline void DecHouseProcessingTime(TileIndex t)
00383 {
00384 assert(IsTileType(t, MP_HOUSE));
00385 _me[t].m7--;
00386 }
00387
00388 #endif