tron@3315: /* $Id$ */ tron@3315: celestar@3334: #ifndef STATION_MAP_H celestar@3334: #define STATION_MAP_H celestar@3334: tron@4041: #include "rail_map.h" tron@3315: #include "station.h" tron@3315: belugas@3545: typedef byte StationGfx; belugas@3545: 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 { belugas@3545: GFX_RAILWAY_BASE = 0, belugas@3545: GFX_AIRPORT_BASE = 8, belugas@3545: GFX_RADAR_LARGE_FIRST = 39, belugas@3545: GFX_RADAR_LARGE_LAST = 50, belugas@3545: GFX_WINDSACK_FIRST = 58, belugas@3545: GFX_WINDSACK_LAST = 61, belugas@3545: GFX_TRUCK_BASE = 67, belugas@3545: GFX_BUS_BASE = 71, belugas@3545: GFX_OILRIG_BASE = 75, belugas@3545: GFX_DOCK_BASE = 76, belugas@3545: GFX_DOCK_BASE_WATER_PART = 80, belugas@3545: GFX_BUOY_BASE = 82, belugas@3545: GFX_AIRPORT_BASE_EXTENDED = 83, belugas@3545: GFX_RADAR_INTERNATIONAL_FIRST = 90, belugas@3545: GFX_RADAR_INTERNATIONAL_LAST = 101, belugas@3545: GFX_RADAR_METROPOLITAN_FIRST = 102, belugas@3545: GFX_RADAR_METROPOLITAN_LAST = 113, richk@4059: GFX_RADAR_DISTRICTWE_FIRST = 145, richk@4059: GFX_RADAR_DISTRICTWE_LAST = 156, richk@4066: GFX_WINDSACK_INTERCON_FIRST = 164, richk@4066: GFX_WINDSACK_INTERCON_LAST = 167, truelight@4136: GFX_BASE_END = 168 celestar@3334: }; celestar@3334: celestar@3334: enum { belugas@3545: RAILWAY_SIZE = GFX_AIRPORT_BASE - GFX_RAILWAY_BASE, belugas@3545: AIRPORT_SIZE = GFX_TRUCK_BASE - GFX_AIRPORT_BASE, belugas@3545: TRUCK_SIZE = GFX_BUS_BASE - GFX_TRUCK_BASE, belugas@3545: BUS_SIZE = GFX_OILRIG_BASE - GFX_BUS_BASE, belugas@3545: DOCK_SIZE_TOTAL = GFX_BUOY_BASE - GFX_DOCK_BASE, belugas@3545: AIRPORT_SIZE_EXTENDED = GFX_BASE_END - GFX_AIRPORT_BASE_EXTENDED celestar@3334: }; celestar@3334: celestar@3334: typedef enum HangarTiles { celestar@3334: HANGAR_TILE_0 = 32, tron@3337: HANGAR_TILE_1 = 65, richk@4059: HANGAR_TILE_2 = 86, richk@4059: HANGAR_TILE_3 = 129, // added for west facing hangar richk@4059: HANGAR_TILE_4 = 130, // added for north facing hangar richk@4059: HANGAR_TILE_5 = 131 // added for east facing hangar celestar@3334: } HangarTiles; celestar@3334: celestar@3334: typedef enum StationType { celestar@3334: STATION_RAIL, 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: belugas@3545: static inline StationGfx GetStationGfx(TileIndex t) belugas@3540: { belugas@3540: assert(IsTileType(t, MP_STATION)); belugas@3540: return _m[t].m5; belugas@3540: } belugas@3540: belugas@3545: static inline void SetStationGfx(TileIndex t, StationGfx gfx) belugas@3540: { belugas@3540: assert(IsTileType(t, MP_STATION)); belugas@3540: _m[t].m5 = gfx; belugas@3540: } belugas@3540: celestar@3334: static inline bool IsRailwayStation(TileIndex t) celestar@3334: { belugas@3545: return GetStationGfx(t) < GFX_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: { belugas@3545: StationGfx gfx = GetStationGfx(t); tron@3337: return belugas@3540: gfx == HANGAR_TILE_0 || belugas@3540: gfx == HANGAR_TILE_1 || richk@4059: gfx == HANGAR_TILE_2 || richk@4059: gfx == HANGAR_TILE_3 || richk@4059: gfx == HANGAR_TILE_4 || richk@4059: gfx == HANGAR_TILE_5; celestar@3334: } celestar@3334: celestar@3334: static inline bool IsAirport(TileIndex t) celestar@3334: { belugas@3545: StationGfx gfx = GetStationGfx(t); celestar@3334: return belugas@3545: (IS_BYTE_INSIDE(gfx, GFX_AIRPORT_BASE, GFX_AIRPORT_BASE + AIRPORT_SIZE)) || belugas@3545: (IS_BYTE_INSIDE(gfx, GFX_AIRPORT_BASE_EXTENDED, GFX_AIRPORT_BASE_EXTENDED + AIRPORT_SIZE_EXTENDED)); celestar@3334: } celestar@3334: celestar@3334: static inline bool IsTruckStop(TileIndex t) celestar@3334: { belugas@3545: return IS_BYTE_INSIDE(GetStationGfx(t), GFX_TRUCK_BASE, GFX_TRUCK_BASE + TRUCK_SIZE); celestar@3334: } celestar@3334: celestar@3334: static inline bool IsBusStop(TileIndex t) celestar@3334: { belugas@3545: return IS_BYTE_INSIDE(GetStationGfx(t), GFX_BUS_BASE, GFX_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: */ belugas@3540: static inline DiagDirection GetRoadStopDir(TileIndex t) celestar@3404: { belugas@3540: assert(IsRoadStopTile(t)); KUDr@3900: return (DiagDirection)((GetStationGfx(t) - GFX_TRUCK_BASE) & 3); celestar@3404: } celestar@3404: celestar@3334: static inline bool IsOilRig(TileIndex t) celestar@3334: { belugas@3545: return GetStationGfx(t) == GFX_OILRIG_BASE; celestar@3334: } celestar@3334: celestar@3334: static inline bool IsDock(TileIndex t) celestar@3334: { belugas@3545: return IS_BYTE_INSIDE(GetStationGfx(t), GFX_DOCK_BASE, GFX_DOCK_BASE + DOCK_SIZE_TOTAL); celestar@3334: } celestar@3334: celestar@3334: static inline bool IsBuoy_(TileIndex t) // XXX _ due to naming conflict celestar@3334: { belugas@3545: return GetStationGfx(t) == GFX_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: { belugas@3541: assert(IsRailwayStation(t)); belugas@3540: return HASBIT(GetStationGfx(t), 0) ? AXIS_Y : AXIS_X; celestar@3334: } celestar@3334: celestar@3334: celestar@3334: static inline Track GetRailStationTrack(TileIndex t) celestar@3334: { tron@4158: return AxisToTrack(GetRailStationAxis(t)); 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)) && peter1138@3766: GetRailStationAxis(t1) == GetRailStationAxis(t2) && peter1138@3766: !IsStationTileBlocked(t1); celestar@3444: } celestar@3444: celestar@3334: celestar@3334: static inline DiagDirection GetDockDirection(TileIndex t) celestar@3334: { belugas@3545: StationGfx gfx = GetStationGfx(t); belugas@3545: assert(gfx < GFX_DOCK_BASE_WATER_PART); belugas@3545: return (DiagDirection)(gfx - GFX_DOCK_BASE); celestar@3334: } celestar@3334: celestar@3472: static inline TileIndexDiffC GetDockOffset(TileIndex t) celestar@3472: { celestar@3472: static const TileIndexDiffC buoy_offset = {0, 0}; celestar@3472: static const TileIndexDiffC oilrig_offset = {2, 0}; celestar@3472: static const TileIndexDiffC dock_offset[DIAGDIR_END] = { celestar@3472: {-2, 0}, celestar@3472: { 0, 2}, celestar@3472: { 2, 0}, celestar@3472: { 0, -2}, celestar@3472: }; celestar@3472: assert(IsTileType(t, MP_STATION)); celestar@3472: celestar@3472: if (IsBuoy_(t)) return buoy_offset; celestar@3472: if (IsOilRig(t)) return oilrig_offset; celestar@3472: celestar@3472: assert(IsDock(t)); celestar@3472: celestar@3472: return dock_offset[GetDockDirection(t)]; celestar@3472: } celestar@3334: peter1138@3568: static inline bool IsCustomStationSpecIndex(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); peter1138@3568: return _m[t].m4 != 0; celestar@3334: } celestar@3334: peter1138@3568: static inline void SetCustomStationSpecIndex(TileIndex t, byte specindex) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); peter1138@3568: _m[t].m4 = specindex; celestar@3334: } celestar@3334: peter1138@3568: static inline uint GetCustomStationSpecIndex(TileIndex t) celestar@3334: { tron@3369: assert(IsTileType(t, MP_STATION)); celestar@3334: return _m[t].m4; celestar@3334: } celestar@3334: peter1138@3742: static inline void SetStationTileRandomBits(TileIndex t, byte random_bits) peter1138@3742: { peter1138@3742: assert(IsTileType(t, MP_STATION)); peter1138@3742: SB(_m[t].m3, 4, 4, random_bits); peter1138@3742: } peter1138@3742: peter1138@3742: static inline byte GetStationTileRandomBits(TileIndex t) peter1138@3742: { peter1138@3742: assert(IsTileType(t, MP_STATION)); peter1138@3742: return GB(_m[t].m3, 4, 4); peter1138@3742: } peter1138@3742: 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: { belugas@3545: MakeStation(t, o, sid, (rst == RS_BUS ? GFX_BUS_BASE : GFX_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: { belugas@3545: MakeStation(t, OWNER_NONE, sid, GFX_BUOY_BASE); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d) celestar@3334: { belugas@3545: MakeStation(t, o, sid, GFX_DOCK_BASE + d); Darkvater@4559: MakeStation(t + TileOffsByDiagDir(d), o, sid, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d)); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeOilrig(TileIndex t, StationID sid) celestar@3334: { belugas@3545: MakeStation(t, OWNER_NONE, sid, GFX_OILRIG_BASE); celestar@3334: } celestar@3334: peter1138@4666: #endif /* STATION_MAP_H */