tron@3319: /* $Id$ */ tron@3319: belugas@3432: /** @file town_map.h Accessors for towns */ belugas@3432: celestar@3426: #ifndef TOWN_MAP_H celestar@3426: #define TOWN_MAP_H celestar@3426: tron@3319: #include "town.h" tron@3319: celestar@3377: static inline int GetHouseType(TileIndex t) celestar@3377: { celestar@3377: assert(IsTileType(t, MP_HOUSE)); celestar@3377: return _m[t].m4; celestar@3377: } tron@3319: belugas@3432: static inline TownID GetTownIndex(TileIndex t) tron@3319: { tron@3369: assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_STREET)); // XXX incomplete tron@3319: return _m[t].m2; tron@3319: } tron@3319: belugas@3432: /** tron@3983: * Set the town index for a road or house tile. belugas@3432: * @param tile the tile belugas@3432: * @param index the index of the town belugas@3432: */ belugas@3432: static inline void SetTownIndex(TileIndex t, TownID index) belugas@3432: { tron@3983: assert(IsTileType(t, MP_STREET) || IsTileType(t, MP_HOUSE)); belugas@3432: _m[t].m2 = index; belugas@3432: } belugas@3432: celestar@3426: static inline bool LiftHasDestination(TileIndex t) celestar@3426: { celestar@3426: return HASBIT(_m[t].m5, 7); celestar@3426: } celestar@3426: celestar@3426: static inline void SetLiftDestination(TileIndex t, byte dest) celestar@3426: { celestar@3426: SB(_m[t].m5, 0, 6, dest); celestar@3426: SETBIT(_m[t].m1, 7); /* Start moving */ celestar@3426: } celestar@3426: celestar@3426: static inline byte GetLiftDestination(TileIndex t) celestar@3426: { celestar@3426: return GB(_m[t].m5, 0, 6); celestar@3426: } celestar@3426: celestar@3426: static inline bool IsLiftMoving(TileIndex t) celestar@3426: { celestar@3426: return HASBIT(_m[t].m1, 7); celestar@3426: } celestar@3426: celestar@3426: static inline void BeginLiftMovement(TileIndex t) celestar@3426: { celestar@3426: SETBIT(_m[t].m5, 7); celestar@3426: } celestar@3426: celestar@3426: static inline void HaltLift(TileIndex t) celestar@3426: { celestar@3426: CLRBIT(_m[t].m1, 7); celestar@3426: CLRBIT(_m[t].m5, 7); celestar@3426: SB(_m[t].m5, 0, 6, 0); celestar@3426: celestar@3426: DeleteAnimatedTile(t); celestar@3426: } celestar@3426: celestar@3426: static inline byte GetLiftPosition(TileIndex t) celestar@3426: { celestar@3426: return GB(_m[t].m1, 0, 7); celestar@3426: } celestar@3426: celestar@3426: static inline void SetLiftPosition(TileIndex t, byte pos) celestar@3426: { celestar@3426: SB(_m[t].m1, 0, 7, pos); celestar@3426: } celestar@3426: tron@3319: static inline Town* GetTownByTile(TileIndex t) tron@3319: { tron@3319: return GetTown(GetTownIndex(t)); tron@3319: } celestar@3382: tron@3983: tron@3983: Town* CalcClosestTownFromTile(TileIndex tile, uint threshold); tron@3983: tron@3983: celestar@3382: static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, byte type) celestar@3382: { celestar@3382: assert(IsTileType(t, MP_CLEAR)); celestar@3382: celestar@3382: SetTileType(t, MP_HOUSE); celestar@3382: _m[t].m1 = 0; celestar@3382: _m[t].m2 = tid; celestar@3382: SB(_m[t].m3, 6, 2, stage); celestar@3382: _m[t].m4 = type; celestar@3382: SB(_m[t].m5, 0, 2, counter); celestar@3382: celestar@3382: MarkTileDirtyByTile(t); celestar@3382: } celestar@3382: celestar@3382: enum { celestar@3382: TWO_BY_TWO_BIT = 2, ///< House is two tiles in X and Y directions celestar@3382: ONE_BY_TWO_BIT = 1, ///< House is two tiles in Y direction celestar@3382: TWO_BY_ONE_BIT = 0, ///< House is two tiles in X direction celestar@3382: }; celestar@3382: celestar@3382: static inline void MakeTownHouse(TileIndex t, TownID tid, byte counter, byte stage, byte size, byte type) celestar@3382: { celestar@3382: MakeHouseTile(t, tid, counter, stage, type); celestar@3382: if (HASBIT(size, TWO_BY_TWO_BIT) || HASBIT(size, ONE_BY_TWO_BIT)) MakeHouseTile(t + TileDiffXY(0, 1), tid, counter, stage, ++type); celestar@3382: if (HASBIT(size, TWO_BY_TWO_BIT) || HASBIT(size, TWO_BY_ONE_BIT)) MakeHouseTile(t + TileDiffXY(1, 0), tid, counter, stage, ++type); celestar@3382: if (HASBIT(size, TWO_BY_TWO_BIT)) MakeHouseTile(t + TileDiffXY(1, 1), tid, counter, stage, ++type); celestar@3382: } belugas@3432: belugas@3432: /** belugas@3432: * House Construction Scheme. belugas@3432: * Construction counter, for buildings under construction. Incremented on every belugas@3432: * periodic tile processing. belugas@3432: * On wraparound, the stage of building in is increased. belugas@3432: * (Get|Set|Inc)HouseBuildingStage are taking care of the real stages, belugas@3432: * (as the sprite for the next phase of house building) belugas@3432: * (Get|Set|Inc)HouseConstructionTick is simply a tick counter between the belugas@3432: * different stages belugas@3432: */ belugas@3432: belugas@3432: /** belugas@3432: * Gets the building stage of a house belugas@3432: * @param tile the tile of the house to get the building stage of belugas@3432: * @pre IsTileType(t, MP_HOUSE) belugas@3432: * @return the building stage of the house belugas@3432: */ belugas@3432: static inline byte GetHouseBuildingStage(TileIndex t) belugas@3432: { belugas@3432: assert(IsTileType(t, MP_HOUSE)); belugas@3432: return GB(_m[t].m3, 6, 2); belugas@3432: } belugas@3432: belugas@3432: /** belugas@3432: * Sets the building stage of a house belugas@3432: * @param tile the tile of the house to set the building stage of belugas@3432: * @param stage the new stage belugas@3432: * @pre IsTileType(t, MP_HOUSE) belugas@3432: */ belugas@3432: static inline void SetHouseBuildingStage(TileIndex t, byte stage) belugas@3432: { belugas@3432: assert(IsTileType(t, MP_HOUSE)); belugas@3432: SB(_m[t].m3, 6, 2, stage); belugas@3432: } belugas@3432: belugas@3432: /** belugas@3432: * Increments the building stage of a house belugas@3432: * @param tile the tile of the house to increment the building stage of belugas@3432: * @pre IsTileType(t, MP_HOUSE) belugas@3432: */ belugas@3432: static inline void IncHouseBuildingStage( TileIndex t ) belugas@3432: { belugas@3432: assert(IsTileType(t, MP_HOUSE)); belugas@3432: AB(_m[t].m3, 6, 2, 1); belugas@3432: } belugas@3432: belugas@3432: /** belugas@3432: * Gets the construction stage of a house belugas@3432: * @param tile the tile of the house to get the construction stage of belugas@3432: * @pre IsTileType(t, MP_HOUSE) belugas@3432: * @return the construction stage of the house belugas@3432: */ belugas@3432: static inline byte GetHouseConstructionTick(TileIndex t) belugas@3432: { belugas@3432: assert(IsTileType(t, MP_HOUSE)); belugas@3432: return GB(_m[t].m5, 0, 3); belugas@3432: } belugas@3432: belugas@3432: /** belugas@3432: * Sets the construction stage of a house belugas@3432: * @param tile the tile of the house to set the construction stage of belugas@3432: * @param stage the new stage belugas@3432: * @pre IsTileType(t, MP_HOUSE) belugas@3432: */ belugas@3432: static inline void SetHouseConstructionTick(TileIndex t, byte stage) belugas@3432: { belugas@3432: assert(IsTileType(t, MP_HOUSE)); belugas@3432: SB(_m[t].m5, 0, 3, stage); belugas@3432: } belugas@3432: belugas@3432: /** belugas@3432: * Sets the increment stage of a house belugas@3432: * @param tile the tile of the house to increment the construction stage of belugas@3432: * @pre IsTileType(t, MP_HOUSE) belugas@3432: */ belugas@3432: static inline void IncHouseConstructionTick(TileIndex t) belugas@3432: { belugas@3432: assert(IsTileType(t, MP_HOUSE)); belugas@3432: AB(_m[t].m5, 0, 3, 1); belugas@3432: } belugas@3432: belugas@3432: belugas@3432: #endif /* TOWN_MAP_H */