tron@3315: /* $Id$ */ tron@3315: belugas@6916: /** @file station_map.h */ belugas@6916: celestar@3334: #ifndef STATION_MAP_H celestar@3334: #define STATION_MAP_H celestar@3334: tron@4041: #include "rail_map.h" rubidium@7157: #include "road_map.h" peter1138@8967: #include "water_map.h" rubidium@9281: #include "station_func.h" rubidium@9281: #include "station_base.h" rubidium@8634: #include "rail.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: rubidium@7814: static inline Station *GetStationByTile(TileIndex t) tron@3315: { tron@3315: return GetStation(GetStationIndex(t)); tron@3315: } celestar@3334: celestar@3334: celestar@3334: enum { rubidium@7768: GFX_RADAR_LARGE_FIRST = 31, rubidium@7768: GFX_RADAR_LARGE_LAST = 42, rubidium@7768: GFX_WINDSACK_FIRST = 50, rubidium@7768: GFX_WINDSACK_LAST = 53, celestar@3334: rubidium@7768: GFX_DOCK_BASE_WATER_PART = 4, rubidium@7768: GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET = 4, rubidium@7768: rubidium@7768: GFX_RADAR_INTERNATIONAL_FIRST = 66, rubidium@7768: GFX_RADAR_INTERNATIONAL_LAST = 77, rubidium@7768: GFX_RADAR_METROPOLITAN_FIRST = 78, rubidium@7768: GFX_RADAR_METROPOLITAN_LAST = 89, rubidium@7768: GFX_RADAR_DISTRICTWE_FIRST = 121, rubidium@7768: GFX_RADAR_DISTRICTWE_LAST = 132, rubidium@7768: GFX_WINDSACK_INTERCON_FIRST = 140, rubidium@7768: GFX_WINDSACK_INTERCON_LAST = 143, celestar@3334: }; celestar@3334: rubidium@7768: static inline StationType GetStationType(TileIndex t) rubidium@7768: { rubidium@7768: return (StationType)GB(_m[t].m6, 3, 3); rubidium@7768: } celestar@3334: rubidium@9281: static inline RoadStopType GetRoadStopType(TileIndex t) celestar@3360: { celestar@3360: assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS); rubidium@9281: return GetStationType(t) == STATION_TRUCK ? ROADSTOP_TRUCK : ROADSTOP_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: { rubidium@7768: return GetStationType(t) == STATION_RAIL; 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: rubidium@7768: static inline bool IsAirport(TileIndex t) rubidium@7768: { rubidium@7768: return GetStationType(t) == STATION_AIRPORT; rubidium@7768: } rubidium@7768: rubidium@7816: bool IsHangar(TileIndex t); celestar@3334: celestar@3334: static inline bool IsTruckStop(TileIndex t) celestar@3334: { rubidium@7768: return GetStationType(t) == STATION_TRUCK; celestar@3334: } celestar@3334: celestar@3334: static inline bool IsBusStop(TileIndex t) celestar@3334: { rubidium@7768: return GetStationType(t) == STATION_BUS; celestar@3334: } celestar@3334: celestar@3334: static inline bool IsRoadStop(TileIndex t) celestar@3334: { rubidium@7768: assert(IsTileType(t, MP_STATION)); 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: rubidium@6338: static inline bool IsStandardRoadStopTile(TileIndex t) rubidium@6338: { rubidium@7768: return IsRoadStopTile(t) && GetStationGfx(t) < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET; rubidium@6338: } rubidium@6338: rubidium@6338: static inline bool IsDriveThroughStopTile(TileIndex t) rubidium@6338: { rubidium@7768: return IsRoadStopTile(t) && GetStationGfx(t) >= GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET; rubidium@6338: } rubidium@6338: rubidium@6338: static inline bool GetStopBuiltOnTownRoad(TileIndex t) rubidium@6338: { rubidium@6338: assert(IsDriveThroughStopTile(t)); skidd13@8424: return HasBit(_m[t].m6, 2); rubidium@6338: } rubidium@6338: rubidium@6338: 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: { rubidium@6338: StationGfx gfx = GetStationGfx(t); belugas@3540: assert(IsRoadStopTile(t)); rubidium@7768: if (gfx < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET) { rubidium@7768: return (DiagDirection)(gfx); rubidium@6338: } else { rubidium@7768: return (DiagDirection)(gfx - GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET); rubidium@6338: } celestar@3404: } celestar@3404: celestar@3334: static inline bool IsOilRig(TileIndex t) celestar@3334: { rubidium@7768: return GetStationType(t) == STATION_OILRIG; celestar@3334: } celestar@3334: celestar@3334: static inline bool IsDock(TileIndex t) celestar@3334: { rubidium@7768: return GetStationType(t) == STATION_DOCK; celestar@3334: } celestar@3334: celestar@6156: static inline bool IsBuoy(TileIndex t) celestar@3334: { rubidium@7768: return GetStationType(t) == STATION_BUOY; celestar@3334: } celestar@3334: celestar@3442: static inline bool IsBuoyTile(TileIndex t) celestar@3442: { celestar@6156: return IsTileType(t, MP_STATION) && IsBuoy(t); celestar@3442: } celestar@3442: 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)); skidd13@8424: 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) && bjarni@8918: GetStationIndex(t1) == GetStationIndex(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); rubidium@7768: assert(IsDock(t) && gfx < GFX_DOCK_BASE_WATER_PART); rubidium@7768: return (DiagDirection)(gfx); 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@6156: 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: rubidium@7768: static inline void MakeStation(TileIndex t, Owner o, StationID sid, StationType st, byte section) 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; rubidium@7768: _m[t].m5 = section; rubidium@7768: SB(_m[t].m6, 3, 3, st); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt) celestar@3334: { rubidium@7768: MakeStation(t, o, sid, STATION_RAIL, section + a); celestar@3334: SetRailType(t, rt); celestar@3334: } celestar@3334: rubidium@9281: static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d) celestar@3334: { rubidium@9281: MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), d); rubidium@7157: SetRoadTypes(t, rt); tron@6424: } tron@6424: rubidium@9281: static inline void MakeDriveThroughRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, Axis a, bool on_town_road) tron@6424: { rubidium@9281: MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET + a); rubidium@7768: SB(_m[t].m6, 2, 1, on_town_road); rubidium@7157: SetRoadTypes(t, rt); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section) celestar@3334: { rubidium@7768: MakeStation(t, o, sid, STATION_AIRPORT, section); celestar@3334: } celestar@3334: peter1138@8967: static inline void MakeBuoy(TileIndex t, StationID sid, WaterClass wc) celestar@3334: { rubidium@6204: /* Make the owner of the buoy tile the same as the current owner of the rubidium@6204: * water tile. In this way, we can reset the owner of the water to its rubidium@6204: * original state when the buoy gets removed. */ rubidium@7768: MakeStation(t, GetTileOwner(t), sid, STATION_BUOY, 0); peter1138@8967: SetWaterClass(t, wc); celestar@3334: } celestar@3334: peter1138@8967: static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc) celestar@3334: { rubidium@7768: MakeStation(t, o, sid, STATION_DOCK, d); rubidium@7768: MakeStation(t + TileOffsByDiagDir(d), o, sid, STATION_DOCK, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d)); peter1138@8967: SetWaterClass(t + TileOffsByDiagDir(d), wc); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeOilrig(TileIndex t, StationID sid) celestar@3334: { rubidium@7768: MakeStation(t, OWNER_NONE, sid, STATION_OILRIG, 0); celestar@3334: } celestar@3334: peter1138@4666: #endif /* STATION_MAP_H */