00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef TOWN_MAP_H
00013 #define TOWN_MAP_H
00014
00015 #include "road_map.h"
00016 #include "house.h"
00017
00024 static inline TownID GetTownIndex(TileIndex t)
00025 {
00026 assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
00027 return _m[t].m2;
00028 }
00029
00036 static inline void SetTownIndex(TileIndex t, TownID index)
00037 {
00038 assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
00039 _m[t].m2 = index;
00040 }
00041
00049 static inline HouseID GetCleanHouseType(TileIndex t)
00050 {
00051 assert(IsTileType(t, MP_HOUSE));
00052 return _m[t].m4 | (GB(_m[t].m3, 6, 1) << 8);
00053 }
00054
00061 static inline HouseID GetHouseType(TileIndex t)
00062 {
00063 return GetTranslatedHouseID(GetCleanHouseType(t));
00064 }
00065
00072 static inline void SetHouseType(TileIndex t, HouseID house_id)
00073 {
00074 assert(IsTileType(t, MP_HOUSE));
00075 _m[t].m4 = GB(house_id, 0, 8);
00076 SB(_m[t].m3, 6, 1, GB(house_id, 8, 1));
00077 }
00078
00084 static inline bool LiftHasDestination(TileIndex t)
00085 {
00086 return HasBit(_me[t].m7, 0);
00087 }
00088
00095 static inline void SetLiftDestination(TileIndex t, byte dest)
00096 {
00097 SetBit(_me[t].m7, 0);
00098 SB(_me[t].m7, 1, 3, dest);
00099 }
00100
00106 static inline byte GetLiftDestination(TileIndex t)
00107 {
00108 return GB(_me[t].m7, 1, 3);
00109 }
00110
00117 static inline void HaltLift(TileIndex t)
00118 {
00119 SB(_me[t].m7, 0, 4, 0);
00120 }
00121
00127 static inline byte GetLiftPosition(TileIndex t)
00128 {
00129 return GB(_m[t].m6, 2, 6);
00130 }
00131
00137 static inline void SetLiftPosition(TileIndex t, byte pos)
00138 {
00139 SB(_m[t].m6, 2, 6, pos);
00140 }
00141
00147 static inline bool IsHouseCompleted(TileIndex t)
00148 {
00149 assert(IsTileType(t, MP_HOUSE));
00150 return HasBit(_m[t].m3, 7);
00151 }
00152
00158 static inline void SetHouseCompleted(TileIndex t, bool status)
00159 {
00160 assert(IsTileType(t, MP_HOUSE));
00161 SB(_m[t].m3, 7, 1, !!status);
00162 }
00163
00185 static inline byte GetHouseBuildingStage(TileIndex t)
00186 {
00187 assert(IsTileType(t, MP_HOUSE));
00188 return IsHouseCompleted(t) ? (byte)TOWN_HOUSE_COMPLETED : GB(_m[t].m5, 3, 2);
00189 }
00190
00197 static inline byte GetHouseConstructionTick(TileIndex t)
00198 {
00199 assert(IsTileType(t, MP_HOUSE));
00200 return IsHouseCompleted(t) ? 0 : GB(_m[t].m5, 0, 3);
00201 }
00202
00210 static inline void IncHouseConstructionTick(TileIndex t)
00211 {
00212 assert(IsTileType(t, MP_HOUSE));
00213 AB(_m[t].m5, 0, 5, 1);
00214
00215 if (GB(_m[t].m5, 3, 2) == TOWN_HOUSE_COMPLETED) {
00216
00217
00218 SetHouseCompleted(t, true);
00219 }
00220 }
00221
00228 static inline void ResetHouseAge(TileIndex t)
00229 {
00230 assert(IsTileType(t, MP_HOUSE) && IsHouseCompleted(t));
00231 _m[t].m5 = 0;
00232 }
00233
00239 static inline void IncrementHouseAge(TileIndex t)
00240 {
00241 assert(IsTileType(t, MP_HOUSE));
00242 if (IsHouseCompleted(t) && _m[t].m5 < 0xFF) _m[t].m5++;
00243 }
00244
00251 static inline Year GetHouseAge(TileIndex t)
00252 {
00253 assert(IsTileType(t, MP_HOUSE));
00254 return IsHouseCompleted(t) ? _m[t].m5 : 0;
00255 }
00256
00264 static inline void SetHouseRandomBits(TileIndex t, byte random)
00265 {
00266 assert(IsTileType(t, MP_HOUSE));
00267 _m[t].m1 = random;
00268 }
00269
00277 static inline byte GetHouseRandomBits(TileIndex t)
00278 {
00279 assert(IsTileType(t, MP_HOUSE));
00280 return _m[t].m1;
00281 }
00282
00290 static inline void SetHouseTriggers(TileIndex t, byte triggers)
00291 {
00292 assert(IsTileType(t, MP_HOUSE));
00293 SB(_m[t].m3, 0, 5, triggers);
00294 }
00295
00303 static inline byte GetHouseTriggers(TileIndex t)
00304 {
00305 assert(IsTileType(t, MP_HOUSE));
00306 return GB(_m[t].m3, 0, 5);
00307 }
00308
00315 static inline byte GetHouseProcessingTime(TileIndex t)
00316 {
00317 assert(IsTileType(t, MP_HOUSE));
00318 return GB(_m[t].m6, 2, 6);
00319 }
00320
00327 static inline void SetHouseProcessingTime(TileIndex t, byte time)
00328 {
00329 assert(IsTileType(t, MP_HOUSE));
00330 SB(_m[t].m6, 2, 6, time);
00331 }
00332
00338 static inline void DecHouseProcessingTime(TileIndex t)
00339 {
00340 assert(IsTileType(t, MP_HOUSE));
00341 _m[t].m6 -= 1 << 2;
00342 }
00343
00354 static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
00355 {
00356 assert(IsTileType(t, MP_CLEAR));
00357
00358 SetTileType(t, MP_HOUSE);
00359 _m[t].m1 = random_bits;
00360 _m[t].m2 = tid;
00361 _m[t].m3 = 0;
00362 SetHouseType(t, type);
00363 SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
00364 _m[t].m5 = IsHouseCompleted(t) ? 0 : (stage << 3 | counter);
00365 SetAnimationFrame(t, 0);
00366 SetHouseProcessingTime(t, HouseSpec::Get(type)->processing_time);
00367 }
00368
00369 #endif