tron@3315: /* $Id$ */ tron@3315: rubidium@9111: /** @file station_map.h Maps accessors for stations. */ belugas@6420: celestar@3334: #ifndef STATION_MAP_H celestar@3334: #define STATION_MAP_H celestar@3334: tron@4041: #include "rail_map.h" rubidium@6661: #include "road_map.h" peter1138@8471: #include "water_map.h" rubidium@8785: #include "station_func.h" rubidium@8785: #include "station_base.h" rubidium@8138: #include "rail.h" tron@3315: belugas@3545: typedef byte StationGfx; belugas@3545: rubidium@10260: /** Get Station ID from a tile rubidium@10260: * @pre Tile \t must be part of the station rubidium@10260: * @param t Tile to query station ID from rubidium@10260: * @return Station ID of the station at \a t */ 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@7318: static inline Station *GetStationByTile(TileIndex t) tron@3315: { tron@3315: return GetStation(GetStationIndex(t)); tron@3315: } celestar@3334: celestar@3334: celestar@3334: enum { rubidium@7272: GFX_RADAR_LARGE_FIRST = 31, rubidium@7272: GFX_RADAR_LARGE_LAST = 42, rubidium@7272: GFX_WINDSACK_FIRST = 50, rubidium@7272: GFX_WINDSACK_LAST = 53, celestar@3334: rubidium@7272: GFX_DOCK_BASE_WATER_PART = 4, rubidium@7272: GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET = 4, rubidium@7272: rubidium@7272: GFX_RADAR_INTERNATIONAL_FIRST = 66, rubidium@7272: GFX_RADAR_INTERNATIONAL_LAST = 77, rubidium@7272: GFX_RADAR_METROPOLITAN_FIRST = 78, rubidium@7272: GFX_RADAR_METROPOLITAN_LAST = 89, rubidium@7272: GFX_RADAR_DISTRICTWE_FIRST = 121, rubidium@7272: GFX_RADAR_DISTRICTWE_LAST = 132, rubidium@7272: GFX_WINDSACK_INTERCON_FIRST = 140, rubidium@7272: GFX_WINDSACK_INTERCON_LAST = 143, celestar@3334: }; celestar@3334: rubidium@7272: static inline StationType GetStationType(TileIndex t) rubidium@7272: { rubidium@7272: return (StationType)GB(_m[t].m6, 3, 3); rubidium@7272: } celestar@3334: rubidium@8785: static inline RoadStopType GetRoadStopType(TileIndex t) celestar@3360: { celestar@3360: assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS); rubidium@8785: 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: peter1138@8955: static inline uint8 GetStationAnimationFrame(TileIndex t) peter1138@8955: { peter1138@8955: assert(IsTileType(t, MP_STATION)); peter1138@8955: return _me[t].m7; peter1138@8955: } peter1138@8955: peter1138@8955: static inline void SetStationAnimationFrame(TileIndex t, uint8 frame) peter1138@8955: { peter1138@8955: assert(IsTileType(t, MP_STATION)); peter1138@8955: _me[t].m7 = frame; peter1138@8955: } peter1138@8955: celestar@3334: static inline bool IsRailwayStation(TileIndex t) celestar@3334: { rubidium@7272: 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@7272: static inline bool IsAirport(TileIndex t) rubidium@7272: { rubidium@7272: return GetStationType(t) == STATION_AIRPORT; rubidium@7272: } rubidium@7272: rubidium@7320: bool IsHangar(TileIndex t); celestar@3334: rubidium@10260: /** rubidium@10260: * Is the station at \a t a truck stop? rubidium@10260: * @param t Tile to check rubidium@10260: * @return \c true if station is a truck stop, \c false otherwise */ celestar@3334: static inline bool IsTruckStop(TileIndex t) celestar@3334: { rubidium@7272: return GetStationType(t) == STATION_TRUCK; celestar@3334: } celestar@3334: rubidium@10260: /** rubidium@10260: * Is the station at \a t a bus stop? rubidium@10260: * @param t Tile to check rubidium@10260: * @return \c true if station is a bus stop, \c false otherwise */ celestar@3334: static inline bool IsBusStop(TileIndex t) celestar@3334: { rubidium@7272: return GetStationType(t) == STATION_BUS; celestar@3334: } celestar@3334: rubidium@10260: /** rubidium@10260: * Is the station at \a t a road station? rubidium@10260: * @pre Tile at \a t is a station tile rubidium@10260: * @param t Tile to check rubidium@10260: * @return \c true if station at the tile is a bus top or a truck stop, \c false otherwise */ celestar@3334: static inline bool IsRoadStop(TileIndex t) celestar@3334: { rubidium@7272: 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@6012: static inline bool IsStandardRoadStopTile(TileIndex t) rubidium@6012: { rubidium@7272: return IsRoadStopTile(t) && GetStationGfx(t) < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET; rubidium@6012: } rubidium@6012: rubidium@6012: static inline bool IsDriveThroughStopTile(TileIndex t) rubidium@6012: { rubidium@7272: return IsRoadStopTile(t) && GetStationGfx(t) >= GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET; rubidium@6012: } rubidium@6012: rubidium@6012: static inline bool GetStopBuiltOnTownRoad(TileIndex t) rubidium@6012: { rubidium@6012: assert(IsDriveThroughStopTile(t)); skidd13@7928: return HasBit(_m[t].m6, 2); rubidium@6012: } rubidium@6012: frosch@9342: static inline void SetStopBuiltOnTownRoad(TileIndex t, bool on_town_road) frosch@9342: { frosch@9342: assert(IsDriveThroughStopTile(t)); frosch@9342: SB(_m[t].m6, 2, 1, on_town_road); frosch@9342: } frosch@9342: rubidium@6012: 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@6012: StationGfx gfx = GetStationGfx(t); belugas@3540: assert(IsRoadStopTile(t)); rubidium@7272: if (gfx < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET) { rubidium@7272: return (DiagDirection)(gfx); rubidium@6012: } else { rubidium@7272: return (DiagDirection)(gfx - GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET); rubidium@6012: } celestar@3404: } celestar@3404: celestar@3334: static inline bool IsOilRig(TileIndex t) celestar@3334: { rubidium@7272: return GetStationType(t) == STATION_OILRIG; celestar@3334: } celestar@3334: celestar@3334: static inline bool IsDock(TileIndex t) celestar@3334: { rubidium@7272: return GetStationType(t) == STATION_DOCK; celestar@3334: } celestar@3334: frosch@10228: static inline bool IsDockTile(TileIndex t) frosch@10228: { frosch@10228: return IsTileType(t, MP_STATION) && GetStationType(t) == STATION_DOCK; frosch@10228: } frosch@10228: celestar@5905: static inline bool IsBuoy(TileIndex t) celestar@3334: { rubidium@7272: return GetStationType(t) == STATION_BUOY; celestar@3334: } celestar@3334: celestar@3442: static inline bool IsBuoyTile(TileIndex t) celestar@3442: { celestar@5905: 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@7928: 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@8422: GetStationIndex(t1) == GetStationIndex(t2) && peter1138@3766: !IsStationTileBlocked(t1); celestar@3444: } celestar@3444: rubidium@9784: /** rubidium@9784: * Get the reservation state of the rail station rubidium@9784: * @pre IsRailwayStationTile(t) rubidium@9784: * @param t the station tile rubidium@9784: * @return reservation state rubidium@9784: */ rubidium@9784: static inline bool GetRailwayStationReservation(TileIndex t) rubidium@9784: { rubidium@9784: assert(IsRailwayStationTile(t)); rubidium@9784: return HasBit(_m[t].m6, 2); rubidium@9784: } rubidium@9784: rubidium@9784: /** rubidium@9784: * Set the reservation state of the rail station rubidium@9784: * @pre IsRailwayStationTile(t) rubidium@9784: * @param t the station tile rubidium@9784: * @param b the reservation state rubidium@9784: */ rubidium@9784: static inline void SetRailwayStationReservation(TileIndex t, bool b) rubidium@9784: { rubidium@9784: assert(IsRailwayStationTile(t)); rubidium@9784: SB(_m[t].m6, 2, 1, b ? 1 : 0); rubidium@9784: } rubidium@9784: rubidium@9784: /** rubidium@9784: * Get the reserved track bits for a waypoint rubidium@9784: * @pre IsRailwayStationTile(t) rubidium@9784: * @param t the tile rubidium@9784: * @return reserved track bits rubidium@9784: */ rubidium@9784: static inline TrackBits GetRailStationReservation(TileIndex t) rubidium@9784: { rubidium@9784: return GetRailwayStationReservation(t) ? AxisToTrackBits(GetRailStationAxis(t)) : TRACK_BIT_NONE; rubidium@9784: } rubidium@9784: celestar@3334: celestar@3334: static inline DiagDirection GetDockDirection(TileIndex t) celestar@3334: { belugas@3545: StationGfx gfx = GetStationGfx(t); rubidium@7272: assert(IsDock(t) && gfx < GFX_DOCK_BASE_WATER_PART); rubidium@7272: 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@5905: 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@7272: 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@7272: _m[t].m5 = section; rubidium@7272: 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@7272: MakeStation(t, o, sid, STATION_RAIL, section + a); celestar@3334: SetRailType(t, rt); rubidium@9784: SetRailwayStationReservation(t, false); celestar@3334: } celestar@3334: rubidium@8785: static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d) celestar@3334: { rubidium@8785: MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), d); rubidium@6661: SetRoadTypes(t, rt); tron@6098: } tron@6098: rubidium@8785: static inline void MakeDriveThroughRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, Axis a, bool on_town_road) tron@6098: { rubidium@8785: MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET + a); rubidium@7272: SB(_m[t].m6, 2, 1, on_town_road); rubidium@6661: SetRoadTypes(t, rt); celestar@3334: } celestar@3334: celestar@3334: static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section) celestar@3334: { rubidium@7272: MakeStation(t, o, sid, STATION_AIRPORT, section); celestar@3334: } celestar@3334: peter1138@8471: static inline void MakeBuoy(TileIndex t, StationID sid, WaterClass wc) celestar@3334: { rubidium@5953: /* Make the owner of the buoy tile the same as the current owner of the rubidium@5953: * water tile. In this way, we can reset the owner of the water to its rubidium@5953: * original state when the buoy gets removed. */ rubidium@7272: MakeStation(t, GetTileOwner(t), sid, STATION_BUOY, 0); peter1138@8471: SetWaterClass(t, wc); celestar@3334: } celestar@3334: peter1138@8471: static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc) celestar@3334: { rubidium@7272: MakeStation(t, o, sid, STATION_DOCK, d); rubidium@7272: MakeStation(t + TileOffsByDiagDir(d), o, sid, STATION_DOCK, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d)); peter1138@8471: SetWaterClass(t + TileOffsByDiagDir(d), wc); celestar@3334: } celestar@3334: frosch@9718: static inline void MakeOilrig(TileIndex t, StationID sid, WaterClass wc) celestar@3334: { rubidium@7272: MakeStation(t, OWNER_NONE, sid, STATION_OILRIG, 0); frosch@9718: SetWaterClass(t, wc); celestar@3334: } celestar@3334: peter1138@4666: #endif /* STATION_MAP_H */