tron@3315: /* $Id$ */ tron@3315: celestar@3334: #ifndef STATION_MAP_H celestar@3334: #define STATION_MAP_H celestar@3334: tron@3315: #include "station.h" tron@3315: tron@3315: static inline StationID GetStationIndex(TileIndex t) tron@3315: { tron@3369: assert(IsTileType(t, MP_STATION)); tron@3315: return (StationID)_m[t].m2; tron@3315: } tron@3315: tron@3315: static inline Station* GetStationByTile(TileIndex t) tron@3315: { tron@3315: return GetStation(GetStationIndex(t)); tron@3315: } celestar@3334: celestar@3334: celestar@3334: enum { celestar@3334: RAILWAY_BASE = 0x0, celestar@3334: AIRPORT_BASE = 0x8, celestar@3334: TRUCK_BASE = 0x43, celestar@3334: BUS_BASE = 0x47, celestar@3334: OILRIG_BASE = 0x4B, celestar@3334: DOCK_BASE = 0x4C, celestar@3334: DOCK_BASE_WATER_PART = 0x50, celestar@3334: BUOY_BASE = 0x52, celestar@3334: AIRPORT_BASE_EXTENDED = 0x53, celestar@3334: celestar@3353: BASE_END = 0x73 celestar@3334: }; celestar@3334: celestar@3334: enum { celestar@3334: RAILWAY_SIZE = AIRPORT_BASE - RAILWAY_BASE, celestar@3334: AIRPORT_SIZE = TRUCK_BASE - AIRPORT_BASE, celestar@3334: TRUCK_SIZE = BUS_BASE - TRUCK_BASE, celestar@3334: BUS_SIZE = OILRIG_BASE - BUS_BASE, celestar@3334: DOCK_SIZE_TOTAL = BUOY_BASE - DOCK_BASE, celestar@3353: AIRPORT_SIZE_EXTENDED = BASE_END - AIRPORT_BASE_EXTENDED celestar@3334: }; celestar@3334: celestar@3334: typedef enum HangarTiles { celestar@3334: HANGAR_TILE_0 = 32, tron@3337: HANGAR_TILE_1 = 65, tron@3337: HANGAR_TILE_2 = 86 celestar@3334: } HangarTiles; celestar@3334: celestar@3334: typedef enum StationType { celestar@3334: STATION_RAIL, celestar@3334: STATION_HANGAR, celestar@3334: STATION_AIRPORT, celestar@3334: STATION_TRUCK, celestar@3334: STATION_BUS, celestar@3334: STATION_OILRIG, celestar@3334: STATION_DOCK, celestar@3334: STATION_BUOY celestar@3334: } StationType; celestar@3334: celestar@3334: StationType GetStationType(TileIndex); celestar@3334: celestar@3360: static inline RoadStopType GetRoadStopType(TileIndex t) celestar@3360: { celestar@3360: assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS); celestar@3360: return GetStationType(t) == STATION_TRUCK ? RS_TRUCK : RS_BUS; celestar@3360: } celestar@3360: celestar@3334: static inline bool IsRailwayStation(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: return _m[t].m5 < RAILWAY_BASE + RAILWAY_SIZE; celestar@3334: } celestar@3334: celestar@3442: static inline bool IsRailwayStationTile(TileIndex t) celestar@3442: { celestar@3442: return IsTileType(t, MP_STATION) && IsRailwayStation(t); celestar@3442: } celestar@3442: celestar@3334: static inline bool IsHangar(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); tron@3337: return tron@3337: _m[t].m5 == HANGAR_TILE_0 || tron@3337: _m[t].m5 == HANGAR_TILE_1 || tron@3337: _m[t].m5 == HANGAR_TILE_2; celestar@3334: } celestar@3334: celestar@3334: static inline bool IsAirport(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: return celestar@3334: IS_INT_INSIDE(_m[t].m5, AIRPORT_BASE, AIRPORT_BASE + AIRPORT_SIZE) || celestar@3334: IS_INT_INSIDE(_m[t].m5, AIRPORT_BASE_EXTENDED, AIRPORT_BASE_EXTENDED + AIRPORT_SIZE_EXTENDED); celestar@3334: } celestar@3334: celestar@3334: static inline bool IsTruckStop(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: return IS_INT_INSIDE(_m[t].m5, TRUCK_BASE, TRUCK_BASE + TRUCK_SIZE); celestar@3334: } celestar@3334: celestar@3334: static inline bool IsBusStop(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: return IS_INT_INSIDE(_m[t].m5, BUS_BASE, BUS_BASE + BUS_SIZE); celestar@3334: } celestar@3334: celestar@3334: static inline bool IsRoadStop(TileIndex t) celestar@3334: { celestar@3334: return IsTruckStop(t) || IsBusStop(t); celestar@3334: } celestar@3334: celestar@3404: static inline bool IsRoadStopTile(TileIndex t) celestar@3404: { celestar@3404: return IsTileType(t, MP_STATION) && IsRoadStop(t); celestar@3404: } celestar@3404: celestar@3404: /** celestar@3404: * Gets the direction the road stop entrance points towards. celestar@3404: */ celestar@3404: static inline DiagDirection GetRoadStopDir(TileIndex tile) celestar@3404: { celestar@3404: assert(IsRoadStopTile(tile)); celestar@3404: return (_m[tile].m5 - TRUCK_BASE) & 3; celestar@3404: } celestar@3404: celestar@3334: static inline bool IsOilRig(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: return _m[t].m5 == OILRIG_BASE; celestar@3334: } celestar@3334: celestar@3334: static inline bool IsDock(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: return IS_INT_INSIDE(_m[t].m5, DOCK_BASE, DOCK_BASE + DOCK_SIZE_TOTAL); celestar@3334: } celestar@3334: celestar@3334: static inline bool IsBuoy_(TileIndex t) // XXX _ due to naming conflict celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: return _m[t].m5 == BUOY_BASE; celestar@3334: } celestar@3334: celestar@3442: static inline bool IsBuoyTile(TileIndex t) celestar@3442: { celestar@3442: return IsTileType(t, MP_STATION) && IsBuoy_(t); celestar@3442: } celestar@3442: celestar@3334: tron@3338: static inline bool IsHangarTile(TileIndex t) tron@3338: { tron@3338: return IsTileType(t, MP_STATION) && IsHangar(t); tron@3338: } tron@3338: tron@3338: celestar@3334: static inline Axis GetRailStationAxis(TileIndex t) celestar@3334: { celestar@3334: assert(IsRailwayStation(t)); celestar@3334: return HASBIT(_m[t].m5, 0) ? AXIS_Y : AXIS_X; celestar@3334: } celestar@3334: celestar@3334: celestar@3334: static inline Track GetRailStationTrack(TileIndex t) celestar@3334: { celestar@3334: return GetRailStationAxis(t) == AXIS_X ? TRACK_X : TRACK_Y; celestar@3334: } celestar@3334: celestar@3444: static inline bool IsCompatibleTrainStationTile(TileIndex t1, TileIndex t2) celestar@3444: { celestar@3444: assert(IsRailwayStationTile(t2)); celestar@3444: return celestar@3444: IsRailwayStationTile(t1) && celestar@3444: IsCompatibleRail(GetRailType(t1), GetRailType(t2)) && celestar@3444: GetRailStationAxis(t1) == GetRailStationAxis(t2); celestar@3444: } celestar@3444: celestar@3334: celestar@3334: static inline DiagDirection GetDockDirection(TileIndex t) celestar@3334: { celestar@3334: assert(IsTileType(t, MP_STATION)); celestar@3370: assert(_m[t].m5 < DOCK_BASE_WATER_PART); celestar@3334: celestar@3334: return (DiagDirection)(_m[t].m5 - DOCK_BASE); celestar@3334: } celestar@3334: celestar@3334: celestar@3334: static inline bool IsCustomStationSprite(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: return HASBIT(_m[t].m3, 4); celestar@3334: } celestar@3334: celestar@3334: static inline void SetCustomStationSprite(TileIndex t, byte sprite) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: SETBIT(_m[t].m3, 4); celestar@3334: _m[t].m4 = sprite; celestar@3334: } celestar@3334: celestar@3334: static inline uint GetCustomStationSprite(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: return _m[t].m4; celestar@3334: } celestar@3334: celestar@3334: celestar@3334: static inline void MakeStation(TileIndex t, Owner o, StationID sid, byte m5) celestar@3334: { celestar@3334: SetTileType(t, MP_STATION); celestar@3334: SetTileOwner(t, o); celestar@3334: _m[t].m2 = sid; celestar@3334: _m[t].m3 = 0; celestar@3334: _m[t].m4 = 0; celestar@3334: _m[t].m5 = m5; celestar@3334: } celestar@3334: celestar@3334: static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt) celestar@3334: { celestar@3334: MakeStation(t, o, sid, section + a); celestar@3334: SetRailType(t, rt); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, DiagDirection d) celestar@3334: { celestar@3334: MakeStation(t, o, sid, (rst == RS_BUS ? BUS_BASE : TRUCK_BASE) + d); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section) celestar@3334: { celestar@3334: MakeStation(t, o, sid, section); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeBuoy(TileIndex t, StationID sid) celestar@3334: { celestar@3334: MakeStation(t, OWNER_NONE, sid, BUOY_BASE); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d) celestar@3334: { celestar@3334: MakeStation(t, o, sid, DOCK_BASE + d); celestar@3334: MakeStation(t + TileOffsByDir(d), o, sid, DOCK_BASE_WATER_PART + DiagDirToAxis(d)); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeOilrig(TileIndex t, StationID sid) celestar@3334: { celestar@3334: MakeStation(t, OWNER_NONE, sid, OILRIG_BASE); celestar@3334: } celestar@3334: celestar@3334: #endif