# unmovable_map.h

Go to the documentation of this file.

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