# unmovable_map.h

Go to the documentation of this file.

    00001 /* $Id: unmovable_map.h 11773 2008-01-07 00:45:05Z rubidium $ */
    00002
    00005 #ifndef UNMOVABLE_MAP_H
    00006 #define UNMOVABLE_MAP_H
    00007
    00008 #include "core/bitmath_func.hpp"
    00009 #include "tile_map.h"
    00010
    00011 enum {
    00012   HQ_NUM_TILE = 4,
    00013   HQ_NUM_SIZE = 5
    00014 };
    00015
    00017 enum UnmovableType {
    00018   UNMOVABLE_TRANSMITTER = 0,
    00019   UNMOVABLE_LIGHTHOUSE  = 1,
    00020   UNMOVABLE_STATUE      = 2,
    00021   UNMOVABLE_OWNED_LAND  = 3,
    00022   UNMOVABLE_HQ_NORTH    = 0x80,
    00023   UNMOVABLE_HQ_WEST     = 0x81,
    00024   UNMOVABLE_HQ_EAST     = 0x82,
    00025   UNMOVABLE_HQ_SOUTH    = 0x83,
    00026
    00028   UNMOVABLE_HQ_END      = UNMOVABLE_HQ_NORTH + HQ_NUM_SIZE * HQ_NUM_TILE
    00029 };
    00030
    00031
    00032
    00039 static inline UnmovableType GetUnmovableType(TileIndex t)
    00040 {
    00041   assert(IsTileType(t, MP_UNMOVABLE));
    00042   return (UnmovableType)_m[t].m5;
    00043 }
    00044
    00050 static inline bool IsTransmitterTile(TileIndex t)
    00051 {
    00052   return IsTileType(t, MP_UNMOVABLE) && GetUnmovableType(t) == UNMOVABLE_TRANSMITTER;
    00053 }
    00054
    00061 static inline bool IsOwnedLand(TileIndex t)
    00062 {
    00063   assert(IsTileType(t, MP_UNMOVABLE));
    00064   return GetUnmovableType(t) == UNMOVABLE_OWNED_LAND;
    00065 }
    00066
    00072 static inline bool IsOwnedLandTile(TileIndex t)
    00073 {
    00074   return IsTileType(t, MP_UNMOVABLE) && IsOwnedLand(t);
    00075 }
    00076
    00083 static inline bool IsCompanyHQ(TileIndex t)
    00084 {
    00085   assert(IsTileType(t, MP_UNMOVABLE));
    00086   return IsInsideMM(GetUnmovableType(t), UNMOVABLE_HQ_NORTH, UNMOVABLE_HQ_END);
    00087 }
    00088
    00095 static inline bool IsStatue(TileIndex t)
    00096 {
    00097   assert(IsTileType(t, MP_UNMOVABLE));
    00098   return GetUnmovableType(t) == UNMOVABLE_STATUE;
    00099 }
    00100
    00106 static inline bool IsStatueTile(TileIndex t)
    00107 {
    00108   return IsTileType(t, MP_UNMOVABLE) && IsStatue(t);
    00109 }
    00110
    00117 static inline TownID GetStatueTownID(TileIndex t)
    00118 {
    00119   assert(IsStatueTile(t));
    00120   return _m[t].m2;
    00121 }
    00122
    00129 static inline byte GetCompanyHQSize(TileIndex t)
    00130 {
    00131   assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    00132   return GB(_m[t].m5, 2, 3);
    00133 }
    00134
    00141 static inline byte GetCompanyHQSection(TileIndex t)
    00142 {
    00143   assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    00144   return GB(_m[t].m5, 0, 5);
    00145 }
    00146
    00154 static inline void EnlargeCompanyHQ(TileIndex t, byte size)
    00155 {
    00156   assert(GB(GetCompanyHQSection(t), 0, 2) == 0);
    00157
    00158   size *= 4;
    00159   if (size <= _m[t].m5 - UNMOVABLE_HQ_NORTH) return;
    00160
    00161   _m[t + TileDiffXY(0, 0)].m5 = UNMOVABLE_HQ_NORTH + size;
    00162   _m[t + TileDiffXY(0, 1)].m5 = UNMOVABLE_HQ_WEST  + size;
    00163   _m[t + TileDiffXY(1, 0)].m5 = UNMOVABLE_HQ_EAST  + size;
    00164   _m[t + TileDiffXY(1, 1)].m5 = UNMOVABLE_HQ_SOUTH + size;
    00165 }
    00166
    00167
    00175 static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o)
    00176 {
    00177   SetTileType(t, MP_UNMOVABLE);
    00178   SetTileOwner(t, o);
    00179   _m[t].m2 = 0;
    00180   _m[t].m3 = 0;
    00181   _m[t].m4 = 0;
    00182   _m[t].m5 = u;
    00183 }
    00184
    00185
    00190 static inline void MakeTransmitter(TileIndex t)
    00191 {
    00192   MakeUnmovable(t, UNMOVABLE_TRANSMITTER, OWNER_NONE);
    00193 }
    00194
    00199 static inline void MakeLighthouse(TileIndex t)
    00200 {
    00201   MakeUnmovable(t, UNMOVABLE_LIGHTHOUSE, OWNER_NONE);
    00202 }
    00203
    00210 static inline void MakeStatue(TileIndex t, Owner o, TownID town_id)
    00211 {
    00212   MakeUnmovable(t, UNMOVABLE_STATUE, o);
    00213   _m[t].m2 = town_id;
    00214 }
    00215
    00221 static inline void MakeOwnedLand(TileIndex t, Owner o)
    00222 {
    00223   MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o);
    00224 }
    00225
    00231 static inline void MakeCompanyHQ(TileIndex t, Owner o)
    00232 {
    00233   MakeUnmovable(t + TileDiffXY(0, 0), UNMOVABLE_HQ_NORTH, o);
    00234   MakeUnmovable(t + TileDiffXY(0, 1), UNMOVABLE_HQ_WEST, o);
    00235   MakeUnmovable(t + TileDiffXY(1, 0), UNMOVABLE_HQ_EAST, o);
    00236   MakeUnmovable(t + TileDiffXY(1, 1), UNMOVABLE_HQ_SOUTH, o);
    00237 }
    00238
    00239 #endif /* UNMOVABLE_MAP_H */