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 "town_type.h"
00017 #include "house.h"
00018
00025 static inline TownID GetTownIndex(TileIndex t)
00026 {
00027 assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
00028 return _m[t].m2;
00029 }
00030
00037 static inline void SetTownIndex(TileIndex t, TownID index)
00038 {
00039 assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
00040 _m[t].m2 = index;
00041 }
00042
00050 static inline HouseID GetCleanHouseType(TileIndex t)
00051 {
00052 assert(IsTileType(t, MP_HOUSE));
00053 return _m[t].m4 | (GB(_m[t].m3, 6, 1) << 8);
00054 }
00055
00062 static inline HouseID GetHouseType(TileIndex t)
00063 {
00064 return GetTranslatedHouseID(GetCleanHouseType(t));
00065 }
00066
00073 static inline void SetHouseType(TileIndex t, HouseID house_id)
00074 {
00075 assert(IsTileType(t, MP_HOUSE));
00076 _m[t].m4 = GB(house_id, 0, 8);
00077 SB(_m[t].m3, 6, 1, GB(house_id, 8, 1));
00078 }
00079
00085 static inline bool LiftHasDestination(TileIndex t)
00086 {
00087 return HasBit(_me[t].m7, 0);
00088 }
00089
00096 static inline void SetLiftDestination(TileIndex t, byte dest)
00097 {
00098 SetBit(_me[t].m7, 0);
00099 SB(_me[t].m7, 1, 3, dest);
00100 }
00101
00107 static inline byte GetLiftDestination(TileIndex t)
00108 {
00109 return GB(_me[t].m7, 1, 3);
00110 }
00111
00118 static inline void HaltLift(TileIndex t)
00119 {
00120 SB(_me[t].m7, 0, 4, 0);
00121 }
00122
00128 static inline byte GetLiftPosition(TileIndex t)
00129 {
00130 return GB(_m[t].m6, 2, 6);
00131 }
00132
00138 static inline void SetLiftPosition(TileIndex t, byte pos)
00139 {
00140 SB(_m[t].m6, 2, 6, pos);
00141 }
00142
00149 static inline byte GetHouseAnimationFrame(TileIndex t)
00150 {
00151 assert(IsTileType(t, MP_HOUSE));
00152 return GB(_m[t].m6, 2, 6) | (GB(_m[t].m3, 5, 1) << 6);
00153 }
00154
00161 static inline void SetHouseAnimationFrame(TileIndex t, byte frame)
00162 {
00163 assert(IsTileType(t, MP_HOUSE));
00164 SB(_m[t].m6, 2, 6, GB(frame, 0, 6));
00165 SB(_m[t].m3, 5, 1, GB(frame, 6, 1));
00166 }
00167
00173 static inline bool IsHouseCompleted(TileIndex t)
00174 {
00175 assert(IsTileType(t, MP_HOUSE));
00176 return HasBit(_m[t].m3, 7);
00177 }
00178
00184 static inline void SetHouseCompleted(TileIndex t, bool status)
00185 {
00186 assert(IsTileType(t, MP_HOUSE));
00187 SB(_m[t].m3, 7, 1, !!status);
00188 }
00189
00200 static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
00201 {
00202 assert(IsTileType(t, MP_CLEAR));
00203
00204 SetTileType(t, MP_HOUSE);
00205 _m[t].m1 = random_bits;
00206 _m[t].m2 = tid;
00207 _m[t].m3 = 0;
00208 SetHouseType(t, type);
00209 SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
00210 _m[t].m5 = IsHouseCompleted(t) ? 0 : (stage << 3 | counter);
00211 SetHouseAnimationFrame(t, 0);
00212 _me[t].m7 = HouseSpec::Get(type)->processing_time;
00213 }
00214
00236 static inline byte GetHouseBuildingStage(TileIndex t)
00237 {
00238 assert(IsTileType(t, MP_HOUSE));
00239 return IsHouseCompleted(t) ? (byte)TOWN_HOUSE_COMPLETED : GB(_m[t].m5, 3, 2);
00240 }
00241
00248 static inline byte GetHouseConstructionTick(TileIndex t)
00249 {
00250 assert(IsTileType(t, MP_HOUSE));
00251 return IsHouseCompleted(t) ? 0 : GB(_m[t].m5, 0, 3);
00252 }
00253
00261 static inline void IncHouseConstructionTick(TileIndex t)
00262 {
00263 assert(IsTileType(t, MP_HOUSE));
00264 AB(_m[t].m5, 0, 5, 1);
00265
00266 if (GB(_m[t].m5, 3, 2) == TOWN_HOUSE_COMPLETED) {
00267
00268
00269 SetHouseCompleted(t, true);
00270 }
00271 }
00272
00279 static inline void ResetHouseAge(TileIndex t)
00280 {
00281 assert(IsTileType(t, MP_HOUSE) && IsHouseCompleted(t));
00282 _m[t].m5 = 0;
00283 }
00284
00290 static inline void IncrementHouseAge(TileIndex t)
00291 {
00292 assert(IsTileType(t, MP_HOUSE));
00293 if (IsHouseCompleted(t) && _m[t].m5 < 0xFF) _m[t].m5++;
00294 }
00295
00302 static inline Year GetHouseAge(TileIndex t)
00303 {
00304 assert(IsTileType(t, MP_HOUSE));
00305 return IsHouseCompleted(t) ? _m[t].m5 : 0;
00306 }
00307
00315 static inline void SetHouseRandomBits(TileIndex t, byte random)
00316 {
00317 assert(IsTileType(t, MP_HOUSE));
00318 _m[t].m1 = random;
00319 }
00320
00328 static inline byte GetHouseRandomBits(TileIndex t)
00329 {
00330 assert(IsTileType(t, MP_HOUSE));
00331 return _m[t].m1;
00332 }
00333
00341 static inline void SetHouseTriggers(TileIndex t, byte triggers)
00342 {
00343 assert(IsTileType(t, MP_HOUSE));
00344 SB(_m[t].m3, 0, 5, triggers);
00345 }
00346
00354 static inline byte GetHouseTriggers(TileIndex t)
00355 {
00356 assert(IsTileType(t, MP_HOUSE));
00357 return GB(_m[t].m3, 0, 5);
00358 }
00359
00366 static inline byte GetHouseProcessingTime(TileIndex t)
00367 {
00368 assert(IsTileType(t, MP_HOUSE));
00369 return _me[t].m7;
00370 }
00371
00378 static inline void SetHouseProcessingTime(TileIndex t, byte time)
00379 {
00380 assert(IsTileType(t, MP_HOUSE));
00381 _me[t].m7 = time;
00382 }
00383
00389 static inline void DecHouseProcessingTime(TileIndex t)
00390 {
00391 assert(IsTileType(t, MP_HOUSE));
00392 _me[t].m7--;
00393 }
00394
00395 #endif