tron@3310: /* $Id$ */ tron@3310: rubidium@9111: /** @file unmovable_map.h Map accessors for unmovable tiles. */ belugas@6423: peter1138@4666: #ifndef UNMOVABLE_MAP_H peter1138@4666: #define UNMOVABLE_MAP_H peter1138@4666: rubidium@8210: #include "core/bitmath_func.hpp" rubidium@8210: #include "tile_map.h" rubidium@8210: celestar@3427: enum { rubidium@6489: HQ_NUM_TILE = 4, ///< Number of HQ tiles rubidium@6489: HQ_NUM_SIZE = 5 ///< Number of stages of an HQ celestar@3427: }; celestar@3427: rubidium@6489: /** Types of unmovable structure */ rubidium@6248: enum UnmovableType { rubidium@6489: UNMOVABLE_TRANSMITTER = 0, ///< The large antenna rubidium@6489: UNMOVABLE_LIGHTHOUSE = 1, ///< The nice lighthouse rubidium@6489: UNMOVABLE_STATUE = 2, ///< Statue in towns rubidium@6489: UNMOVABLE_OWNED_LAND = 3, ///< Owned land 'flag' rubidium@6489: UNMOVABLE_HQ_NORTH = 0x80, ///< Offset for the northern HQ tile rubidium@6489: UNMOVABLE_HQ_WEST = 0x81, ///< Offset for the western HQ tile rubidium@6489: UNMOVABLE_HQ_EAST = 0x82, ///< Offset for the eastern HQ tile rubidium@6489: UNMOVABLE_HQ_SOUTH = 0x83, ///< Offset for the southern HQ tile celestar@3427: skidd13@7954: /** End of the HQ (rather end + 1 for IsInside) */ celestar@3427: UNMOVABLE_HQ_END = UNMOVABLE_HQ_NORTH + HQ_NUM_SIZE * HQ_NUM_TILE rubidium@6248: }; tron@3310: tron@3310: celestar@3427: rubidium@6489: /** rubidium@6489: * Gets the UnmovableType of the given unmovable tile rubidium@6489: * @param t the tile to get the type from. rubidium@6489: * @pre IsTileType(t, MP_UNMOVABLE) rubidium@6489: * @return the type. rubidium@6489: */ tron@3310: static inline UnmovableType GetUnmovableType(TileIndex t) tron@3310: { tron@3369: assert(IsTileType(t, MP_UNMOVABLE)); rubidium@5587: return (UnmovableType)_m[t].m5; tron@3310: } tron@3310: rubidium@6489: /** rubidium@6489: * Does the given tile have a transmitter? rubidium@6489: * @param t the tile to inspect. rubidium@6489: * @return true if and only if the tile has a transmitter. rubidium@6489: */ tron@3310: static inline bool IsTransmitterTile(TileIndex t) tron@3310: { rubidium@6489: return IsTileType(t, MP_UNMOVABLE) && GetUnmovableType(t) == UNMOVABLE_TRANSMITTER; tron@3310: } tron@3310: rubidium@6489: /** rubidium@6489: * Is this unmovable tile an 'owned land' tile? rubidium@6489: * @param t the tile to inspect. rubidium@6489: * @pre IsTileType(t, MP_UNMOVABLE) rubidium@6489: * @return true if and only if the tile is an 'owned land' tile. rubidium@6489: */ tron@3310: static inline bool IsOwnedLand(TileIndex t) tron@3310: { tron@3369: assert(IsTileType(t, MP_UNMOVABLE)); tron@3310: return GetUnmovableType(t) == UNMOVABLE_OWNED_LAND; tron@3310: } tron@3310: rubidium@6489: /** rubidium@6489: * Is the given tile (pre-)owned by someone (the little flags)? rubidium@6489: * @param t the tile to inspect. rubidium@6489: * @return true if and only if the tile is an 'owned land' tile. rubidium@6489: */ tron@3310: static inline bool IsOwnedLandTile(TileIndex t) tron@3310: { tron@3310: return IsTileType(t, MP_UNMOVABLE) && IsOwnedLand(t); tron@3310: } tron@3310: rubidium@6489: /** rubidium@6489: * Is this unmovable tile a HQ tile? rubidium@6489: * @param t the tile to inspect. rubidium@6489: * @pre IsTileType(t, MP_UNMOVABLE) rubidium@6489: * @return true if and only if the tile is a HQ tile. rubidium@6489: */ celestar@3427: static inline bool IsCompanyHQ(TileIndex t) celestar@3427: { rubidium@6489: assert(IsTileType(t, MP_UNMOVABLE)); belugas@10012: return HasBit(_m[t].m5, 7); celestar@3427: } celestar@3427: rubidium@6489: /** rubidium@6489: * Is this unmovable tile a statue? rubidium@6489: * @param t the tile to inspect. rubidium@6489: * @pre IsTileType(t, MP_UNMOVABLE) rubidium@6489: * @return true if and only if the tile is a statue. rubidium@6489: */ truelight@6257: static inline bool IsStatue(TileIndex t) truelight@6257: { truelight@6257: assert(IsTileType(t, MP_UNMOVABLE)); truelight@6257: return GetUnmovableType(t) == UNMOVABLE_STATUE; truelight@6257: } truelight@6257: rubidium@6489: /** rubidium@6489: * Is the given tile a statue? rubidium@6489: * @param t the tile to inspect. rubidium@6489: * @return true if and only if the tile is a statue. rubidium@6489: */ truelight@6257: static inline bool IsStatueTile(TileIndex t) truelight@6257: { truelight@6257: return IsTileType(t, MP_UNMOVABLE) && IsStatue(t); truelight@6257: } truelight@6257: rubidium@6489: /** rubidium@6489: * Get the town of the given statue tile. rubidium@6489: * @param t the tile of the statue. rubidium@6489: * @pre IsStatueTile(t) rubidium@6489: * @return the town the given statue is in. rubidium@6489: */ truelight@6257: static inline TownID GetStatueTownID(TileIndex t) truelight@6257: { rubidium@6489: assert(IsStatueTile(t)); truelight@6257: return _m[t].m2; truelight@6257: } truelight@6257: rubidium@6489: /** rubidium@6489: * Get the 'stage' of the HQ. rubidium@6489: * @param t a tile of the HQ. rubidium@6489: * @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t) rubidium@6489: * @return the 'stage' of the HQ. rubidium@6489: */ celestar@3427: static inline byte GetCompanyHQSize(TileIndex t) celestar@3427: { celestar@3427: assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t)); celestar@3427: return GB(_m[t].m5, 2, 3); celestar@3427: } celestar@3427: rubidium@6489: /** rubidium@6489: * Get the 'section' (including stage) of the HQ. rubidium@6489: * @param t a tile of the HQ. rubidium@6489: * @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t) rubidium@6489: * @return the 'section' of the HQ. rubidium@6489: */ celestar@3427: static inline byte GetCompanyHQSection(TileIndex t) celestar@3427: { celestar@3427: assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t)); celestar@3427: return GB(_m[t].m5, 0, 5); celestar@3427: } celestar@3427: rubidium@6489: /** rubidium@6489: * Enlarge the given HQ to the given size. If the new size rubidium@6489: * is larger than the current size, nothing happens. rubidium@6489: * @param t the tile of the HQ. rubidium@6489: * @param size the new size of the HQ. rubidium@6489: * @pre t is the northern tile of the HQ rubidium@6489: */ celestar@3388: static inline void EnlargeCompanyHQ(TileIndex t, byte size) celestar@3388: { rubidium@6489: assert(GB(GetCompanyHQSection(t), 0, 2) == 0); rubidium@6489: Darkvater@3705: size *= 4; celestar@3388: if (size <= _m[t].m5 - UNMOVABLE_HQ_NORTH) return; celestar@3388: Darkvater@3705: _m[t + TileDiffXY(0, 0)].m5 = UNMOVABLE_HQ_NORTH + size; Darkvater@3705: _m[t + TileDiffXY(0, 1)].m5 = UNMOVABLE_HQ_WEST + size; Darkvater@3705: _m[t + TileDiffXY(1, 0)].m5 = UNMOVABLE_HQ_EAST + size; Darkvater@3705: _m[t + TileDiffXY(1, 1)].m5 = UNMOVABLE_HQ_SOUTH + size; celestar@3388: } celestar@3388: celestar@3388: rubidium@6489: /** rubidium@6489: * Make an Unmovable tile. rubidium@6489: * @note do not use this function directly. Use one of the other Make* functions. rubidium@6489: * @param t the tile to make unmovable. rubidium@6489: * @param u the unmovable type of the tile. rubidium@6489: * @param o the new owner of the tile. rubidium@6489: */ tron@3310: static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o) tron@3310: { tron@3310: SetTileType(t, MP_UNMOVABLE); tron@3310: SetTileOwner(t, o); tron@3310: _m[t].m2 = 0; tron@3310: _m[t].m3 = 0; tron@3310: _m[t].m4 = 0; tron@3310: _m[t].m5 = u; tron@3310: } tron@3310: tron@3310: rubidium@6489: /** rubidium@6489: * Make a transmitter tile. rubidium@6489: * @param t the tile to make a transmitter. rubidium@6489: */ tron@3310: static inline void MakeTransmitter(TileIndex t) tron@3310: { tron@3310: MakeUnmovable(t, UNMOVABLE_TRANSMITTER, OWNER_NONE); tron@3310: } tron@3310: rubidium@6489: /** rubidium@6489: * Make a lighthouse tile. rubidium@6489: * @param t the tile to make a transmitter. rubidium@6489: */ tron@3310: static inline void MakeLighthouse(TileIndex t) tron@3310: { tron@3310: MakeUnmovable(t, UNMOVABLE_LIGHTHOUSE, OWNER_NONE); tron@3310: } tron@3310: rubidium@6489: /** rubidium@6489: * Make a statue tile. rubidium@6489: * @param t the tile to make a statue. rubidium@6489: * @param o the owner of the statue. rubidium@6489: * @param town_id the town the statue was built in. rubidium@6489: */ truelight@6257: static inline void MakeStatue(TileIndex t, Owner o, TownID town_id) tron@3310: { tron@3310: MakeUnmovable(t, UNMOVABLE_STATUE, o); truelight@6257: _m[t].m2 = town_id; tron@3310: } tron@3310: rubidium@6489: /** rubidium@6489: * Make an 'owned land' tile. rubidium@6489: * @param t the tile to make an 'owned land' tile. rubidium@6489: * @param o the owner of the land. rubidium@6489: */ tron@3310: static inline void MakeOwnedLand(TileIndex t, Owner o) tron@3310: { tron@3310: MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o); tron@3310: } celestar@3385: rubidium@6489: /** rubidium@6489: * Make an HQ with the give tile as it's northern tile. rubidium@6489: * @param t the tile to make the northern tile of a HQ. rubidium@6489: * @param o the owner of the HQ. rubidium@6489: */ celestar@3385: static inline void MakeCompanyHQ(TileIndex t, Owner o) celestar@3385: { celestar@3385: MakeUnmovable(t + TileDiffXY(0, 0), UNMOVABLE_HQ_NORTH, o); celestar@3385: MakeUnmovable(t + TileDiffXY(0, 1), UNMOVABLE_HQ_WEST, o); celestar@3385: MakeUnmovable(t + TileDiffXY(1, 0), UNMOVABLE_HQ_EAST, o); celestar@3385: MakeUnmovable(t + TileDiffXY(1, 1), UNMOVABLE_HQ_SOUTH, o); celestar@3385: } peter1138@4666: peter1138@4666: #endif /* UNMOVABLE_MAP_H */