# unmovable_map.h

Go to the documentation of this file.

    00001 /* $Id: unmovable_map.h 15392 2009-02-07 02:38:32Z belugas $ */
    00002
    00005 #ifndef UNMOVABLE_MAP_H
    00006 #define UNMOVABLE_MAP_H
    00007
    00008 #include "core/bitmath_func.hpp"
    00009 #include "tile_map.h"
    00010
    00012 enum UnmovableType {
    00013   UNMOVABLE_TRANSMITTER = 0,
    00014   UNMOVABLE_LIGHTHOUSE  = 1,
    00015   UNMOVABLE_STATUE      = 2,
    00016   UNMOVABLE_OWNED_LAND  = 3,
    00017   UNMOVABLE_HQ          = 4,
    00018   UNMOVABLE_MAX,
    00019 };
    00020
    00027 static inline UnmovableType GetUnmovableType(TileIndex t)
    00028 {
    00029   assert(IsTileType(t, MP_UNMOVABLE));
    00030   return (UnmovableType)_m[t].m5;
    00031 }
    00032
    00038 static inline bool IsTransmitterTile(TileIndex t)
    00039 {
    00040   return IsTileType(t, MP_UNMOVABLE) && GetUnmovableType(t) == UNMOVABLE_TRANSMITTER;
    00041 }
    00042
    00049 static inline bool IsOwnedLand(TileIndex t)
    00050 {
    00051   assert(IsTileType(t, MP_UNMOVABLE));
    00052   return GetUnmovableType(t) == UNMOVABLE_OWNED_LAND;
    00053 }
    00054
    00060 static inline bool IsOwnedLandTile(TileIndex t)
    00061 {
    00062   return IsTileType(t, MP_UNMOVABLE) && IsOwnedLand(t);
    00063 }
    00064
    00071 static inline bool IsCompanyHQ(TileIndex t)
    00072 {
    00073   assert(IsTileType(t, MP_UNMOVABLE));
    00074   return _m[t].m5 == UNMOVABLE_HQ;
    00075 }
    00076
    00083 static inline bool IsStatue(TileIndex t)
    00084 {
    00085   assert(IsTileType(t, MP_UNMOVABLE));
    00086   return GetUnmovableType(t) == UNMOVABLE_STATUE;
    00087 }
    00088
    00094 static inline bool IsStatueTile(TileIndex t)
    00095 {
    00096   return IsTileType(t, MP_UNMOVABLE) && IsStatue(t);
    00097 }
    00098
    00105 static inline TownID GetStatueTownID(TileIndex t)
    00106 {
    00107   assert(IsStatueTile(t));
    00108   return _m[t].m2;
    00109 }
    00110
    00117 static inline byte GetCompanyHQSize(TileIndex t)
    00118 {
    00119   assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    00120   return GB(_m[t].m3, 2, 3);
    00121 }
    00122
    00129 static inline void SetCompanyHQSize(TileIndex t, uint8 size)
    00130 {
    00131   assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    00132   SB(_m[t].m3, 2, 3, size);
    00133 }
    00134
    00142 static inline byte GetCompanyHQSection(TileIndex t)
    00143 {
    00144   assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    00145   return GB(_m[t].m3, 0, 2);
    00146 }
    00147
    00154 static inline void SetCompanyHQSection(TileIndex t, uint8 section)
    00155 {
    00156   assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    00157   SB(_m[t].m3, 0, 2, section);
    00158 }
    00159
    00167 static inline void EnlargeCompanyHQ(TileIndex t, byte size)
    00168 {
    00169   assert(GetCompanyHQSection(t) == 0);
    00170   assert(size <= 4);
    00171   if (size <= GetCompanyHQSize(t)) return;
    00172
    00173   SetCompanyHQSize(t                   , size);
    00174   SetCompanyHQSize(t + TileDiffXY(0, 1), size);
    00175   SetCompanyHQSize(t + TileDiffXY(1, 0), size);
    00176   SetCompanyHQSize(t + TileDiffXY(1, 1), size);
    00177 }
    00178
    00179
    00187 static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o)
    00188 {
    00189   SetTileType(t, MP_UNMOVABLE);
    00190   SetTileOwner(t, o);
    00191   _m[t].m2 = 0;
    00192   _m[t].m3 = 0;
    00193   _m[t].m4 = 0;
    00194   _m[t].m5 = u;
    00195 }
    00196
    00197
    00202 static inline void MakeTransmitter(TileIndex t)
    00203 {
    00204   MakeUnmovable(t, UNMOVABLE_TRANSMITTER, OWNER_NONE);
    00205 }
    00206
    00211 static inline void MakeLighthouse(TileIndex t)
    00212 {
    00213   MakeUnmovable(t, UNMOVABLE_LIGHTHOUSE, OWNER_NONE);
    00214 }
    00215
    00222 static inline void MakeStatue(TileIndex t, Owner o, TownID town_id)
    00223 {
    00224   MakeUnmovable(t, UNMOVABLE_STATUE, o);
    00225   _m[t].m2 = town_id;
    00226 }
    00227
    00233 static inline void MakeOwnedLand(TileIndex t, Owner o)
    00234 {
    00235   MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o);
    00236 }
    00237
    00244 static inline void MakeUnmovableHQHelper(TileIndex t, uint8 section, Owner o)
    00245 {
    00246   MakeUnmovable(t, UNMOVABLE_HQ, o);
    00247   SetCompanyHQSection(t, section);
    00248 }
    00249
    00255 static inline void MakeCompanyHQ(TileIndex t, Owner o)
    00256 {
    00257   MakeUnmovableHQHelper(t                   , 0, o);
    00258   MakeUnmovableHQHelper(t + TileDiffXY(0, 1), 1, o);
    00259   MakeUnmovableHQHelper(t + TileDiffXY(1, 0), 2, o);
    00260   MakeUnmovableHQHelper(t + TileDiffXY(1, 1), 3, o);
    00261 }
    00262
    00263 #endif /* UNMOVABLE_MAP_H */