# town_map.h

Go to the documentation of this file.

    00001 /* $Id: town_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 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
    00148 static inline byte GetHouseAnimationFrame(TileIndex t)
    00149 {
    00150   assert(IsTileType(t, MP_HOUSE));
    00151   return GB(_m[t].m6, 2, 6) | (GB(_m[t].m3, 5, 1) << 6);
    00152 }
    00153
    00160 static inline void SetHouseAnimationFrame(TileIndex t, byte frame)
    00161 {
    00162   assert(IsTileType(t, MP_HOUSE));
    00163   SB(_m[t].m6, 2, 6, GB(frame, 0, 6));
    00164   SB(_m[t].m3, 5, 1, GB(frame, 6, 1));
    00165 }
    00166
    00172 static inline bool IsHouseCompleted(TileIndex t)
    00173 {
    00174   assert(IsTileType(t, MP_HOUSE));
    00175   return HasBit(_m[t].m3, 7);
    00176 }
    00177
    00183 static inline void SetHouseCompleted(TileIndex t, bool status)
    00184 {
    00185   assert(IsTileType(t, MP_HOUSE));
    00186   SB(_m[t].m3, 7, 1, !!status);
    00187 }
    00188
    00199 static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
    00200 {
    00201   assert(IsTileType(t, MP_CLEAR));
    00202
    00203   SetTileType(t, MP_HOUSE);
    00204   _m[t].m1 = random_bits;
    00205   _m[t].m2 = tid;
    00206   _m[t].m3 = 0;
    00207   SetHouseType(t, type);
    00208   SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
    00209   _m[t].m5 = IsHouseCompleted(t) ? 0 : (stage << 3 | counter);
    00210   SetHouseAnimationFrame(t, 0);
    00211   _me[t].m7 = HouseSpec::Get(type)->processing_time;
    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   }
    00270 }
    00271
    00278 static inline void ResetHouseAge(TileIndex t)
    00279 {
    00280   assert(IsTileType(t, MP_HOUSE) && IsHouseCompleted(t));
    00281   _m[t].m5 = 0;
    00282 }
    00283
    00289 static inline void IncrementHouseAge(TileIndex t)
    00290 {
    00291   assert(IsTileType(t, MP_HOUSE));
    00292   if (IsHouseCompleted(t) && _m[t].m5 < 0xFF) _m[t].m5++;
    00293 }
    00294
    00301 static inline Year GetHouseAge(TileIndex t)
    00302 {
    00303   assert(IsTileType(t, MP_HOUSE));
    00304   return IsHouseCompleted(t) ? _m[t].m5 : 0;
    00305 }
    00306
    00314 static inline void SetHouseRandomBits(TileIndex t, byte random)
    00315 {
    00316   assert(IsTileType(t, MP_HOUSE));
    00317   _m[t].m1 = random;
    00318 }
    00319
    00327 static inline byte GetHouseRandomBits(TileIndex t)
    00328 {
    00329   assert(IsTileType(t, MP_HOUSE));
    00330   return _m[t].m1;
    00331 }
    00332
    00340 static inline void SetHouseTriggers(TileIndex t, byte triggers)
    00341 {
    00342   assert(IsTileType(t, MP_HOUSE));
    00343   SB(_m[t].m3, 0, 5, triggers);
    00344 }
    00345
    00353 static inline byte GetHouseTriggers(TileIndex t)
    00354 {
    00355   assert(IsTileType(t, MP_HOUSE));
    00356   return GB(_m[t].m3, 0, 5);
    00357 }
    00358
    00365 static inline byte GetHouseProcessingTime(TileIndex t)
    00366 {
    00367   assert(IsTileType(t, MP_HOUSE));
    00368   return _me[t].m7;
    00369 }
    00370
    00377 static inline void SetHouseProcessingTime(TileIndex t, byte time)
    00378 {
    00379   assert(IsTileType(t, MP_HOUSE));
    00380   _me[t].m7 = time;
    00381 }
    00382
    00388 static inline void DecHouseProcessingTime(TileIndex t)
    00389 {
    00390   assert(IsTileType(t, MP_HOUSE));
    00391   _me[t].m7--;
    00392 }
    00393
    00394 #endif /* TOWN_MAP_H */