# unmovable_map.h

Go to the documentation of this file.

    00001 /* $Id$ */
    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 UNMOVABLE_MAP_H
    00013 #define UNMOVABLE_MAP_H
    00014
    00015 #include "core/bitmath_func.hpp"
    00016 #include "tile_map.h"
    00017
    00019 enum UnmovableType {
    00020   UNMOVABLE_TRANSMITTER = 0,
    00021   UNMOVABLE_LIGHTHOUSE  = 1,
    00022   UNMOVABLE_STATUE      = 2,
    00023   UNMOVABLE_OWNED_LAND  = 3,
    00024   UNMOVABLE_HQ          = 4,
    00025   UNMOVABLE_MAX,
    00026 };
    00027
    00034 static inline UnmovableType GetUnmovableType(TileIndex t)
    00035 {
    00036   assert(IsTileType(t, MP_UNMOVABLE));
    00037   return (UnmovableType)_m[t].m5;
    00038 }
    00039
    00045 static inline bool IsTransmitterTile(TileIndex t)
    00046 {
    00047   return IsTileType(t, MP_UNMOVABLE) && GetUnmovableType(t) == UNMOVABLE_TRANSMITTER;
    00048 }
    00049
    00056 static inline bool IsOwnedLand(TileIndex t)
    00057 {
    00058   assert(IsTileType(t, MP_UNMOVABLE));
    00059   return GetUnmovableType(t) == UNMOVABLE_OWNED_LAND;
    00060 }
    00061
    00067 static inline bool IsOwnedLandTile(TileIndex t)
    00068 {
    00069   return IsTileType(t, MP_UNMOVABLE) && IsOwnedLand(t);
    00070 }
    00071
    00078 static inline bool IsCompanyHQ(TileIndex t)
    00079 {
    00080   assert(IsTileType(t, MP_UNMOVABLE));
    00081   return _m[t].m5 == UNMOVABLE_HQ;
    00082 }
    00083
    00090 static inline bool IsStatue(TileIndex t)
    00091 {
    00092   assert(IsTileType(t, MP_UNMOVABLE));
    00093   return GetUnmovableType(t) == UNMOVABLE_STATUE;
    00094 }
    00095
    00101 static inline bool IsStatueTile(TileIndex t)
    00102 {
    00103   return IsTileType(t, MP_UNMOVABLE) && IsStatue(t);
    00104 }
    00105
    00112 static inline TownID GetStatueTownID(TileIndex t)
    00113 {
    00114   assert(IsStatueTile(t));
    00115   return _m[t].m2;
    00116 }
    00117
    00124 static inline byte GetCompanyHQSize(TileIndex t)
    00125 {
    00126   assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    00127   return GB(_m[t].m3, 2, 3);
    00128 }
    00129
    00136 static inline void SetCompanyHQSize(TileIndex t, uint8 size)
    00137 {
    00138   assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    00139   SB(_m[t].m3, 2, 3, size);
    00140 }
    00141
    00149 static inline byte GetCompanyHQSection(TileIndex t)
    00150 {
    00151   assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    00152   return GB(_m[t].m3, 0, 2);
    00153 }
    00154
    00161 static inline void SetCompanyHQSection(TileIndex t, uint8 section)
    00162 {
    00163   assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    00164   SB(_m[t].m3, 0, 2, section);
    00165 }
    00166
    00174 static inline void EnlargeCompanyHQ(TileIndex t, byte size)
    00175 {
    00176   assert(GetCompanyHQSection(t) == 0);
    00177   assert(size <= 4);
    00178   if (size <= GetCompanyHQSize(t)) return;
    00179
    00180   SetCompanyHQSize(t,                    size);
    00181   SetCompanyHQSize(t + TileDiffXY(0, 1), size);
    00182   SetCompanyHQSize(t + TileDiffXY(1, 0), size);
    00183   SetCompanyHQSize(t + TileDiffXY(1, 1), size);
    00184 }
    00185
    00186
    00194 static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o)
    00195 {
    00196   SetTileType(t, MP_UNMOVABLE);
    00197   SetTileOwner(t, o);
    00198   _m[t].m2 = 0;
    00199   _m[t].m3 = 0;
    00200   _m[t].m4 = 0;
    00201   _m[t].m5 = u;
    00202   SB(_m[t].m6, 2, 4, 0);
    00203   _me[t].m7 = 0;
    00204 }
    00205
    00206
    00211 static inline void MakeTransmitter(TileIndex t)
    00212 {
    00213   MakeUnmovable(t, UNMOVABLE_TRANSMITTER, OWNER_NONE);
    00214 }
    00215
    00220 static inline void MakeLighthouse(TileIndex t)
    00221 {
    00222   MakeUnmovable(t, UNMOVABLE_LIGHTHOUSE, OWNER_NONE);
    00223 }
    00224
    00231 static inline void MakeStatue(TileIndex t, Owner o, TownID town_id)
    00232 {
    00233   MakeUnmovable(t, UNMOVABLE_STATUE, o);
    00234   _m[t].m2 = town_id;
    00235 }
    00236
    00242 static inline void MakeOwnedLand(TileIndex t, Owner o)
    00243 {
    00244   MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o);
    00245 }
    00246
    00253 static inline void MakeUnmovableHQHelper(TileIndex t, uint8 section, Owner o)
    00254 {
    00255   MakeUnmovable(t, UNMOVABLE_HQ, o);
    00256   SetCompanyHQSection(t, section);
    00257 }
    00258
    00264 static inline void MakeCompanyHQ(TileIndex t, Owner o)
    00265 {
    00266   MakeUnmovableHQHelper(t,                    0, o);
    00267   MakeUnmovableHQHelper(t + TileDiffXY(0, 1), 1, o);
    00268   MakeUnmovableHQHelper(t + TileDiffXY(1, 0), 2, o);
    00269   MakeUnmovableHQHelper(t + TileDiffXY(1, 1), 3, o);
    00270 }
    00271
    00272 #endif /* UNMOVABLE_MAP_H */