00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef STATION_MAP_H
00013 #define STATION_MAP_H
00014
00015 #include "rail_map.h"
00016 #include "road_map.h"
00017 #include "water_map.h"
00018 #include "station_func.h"
00019 #include "rail.h"
00020
00021 typedef byte StationGfx;
00022
00029 static inline StationID GetStationIndex(TileIndex t)
00030 {
00031 assert(IsTileType(t, MP_STATION));
00032 return (StationID)_m[t].m2;
00033 }
00034
00035
00036 static const int GFX_DOCK_BASE_WATER_PART = 4;
00037 static const int GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET = 4;
00038
00045 static inline StationType GetStationType(TileIndex t)
00046 {
00047 assert(IsTileType(t, MP_STATION));
00048 return (StationType)GB(_m[t].m6, 3, 3);
00049 }
00050
00057 static inline RoadStopType GetRoadStopType(TileIndex t)
00058 {
00059 assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS);
00060 return GetStationType(t) == STATION_TRUCK ? ROADSTOP_TRUCK : ROADSTOP_BUS;
00061 }
00062
00069 static inline StationGfx GetStationGfx(TileIndex t)
00070 {
00071 assert(IsTileType(t, MP_STATION));
00072 return _m[t].m5;
00073 }
00074
00081 static inline void SetStationGfx(TileIndex t, StationGfx gfx)
00082 {
00083 assert(IsTileType(t, MP_STATION));
00084 _m[t].m5 = gfx;
00085 }
00086
00093 static inline bool IsRailStation(TileIndex t)
00094 {
00095 return GetStationType(t) == STATION_RAIL;
00096 }
00097
00103 static inline bool IsRailStationTile(TileIndex t)
00104 {
00105 return IsTileType(t, MP_STATION) && IsRailStation(t);
00106 }
00107
00114 static inline bool IsRailWaypoint(TileIndex t)
00115 {
00116 return GetStationType(t) == STATION_WAYPOINT;
00117 }
00118
00124 static inline bool IsRailWaypointTile(TileIndex t)
00125 {
00126 return IsTileType(t, MP_STATION) && IsRailWaypoint(t);
00127 }
00128
00136 static inline bool HasStationRail(TileIndex t)
00137 {
00138 return IsRailStation(t) || IsRailWaypoint(t);
00139 }
00140
00147 static inline bool HasStationTileRail(TileIndex t)
00148 {
00149 return IsTileType(t, MP_STATION) && HasStationRail(t);
00150 }
00151
00158 static inline bool IsAirport(TileIndex t)
00159 {
00160 return GetStationType(t) == STATION_AIRPORT;
00161 }
00162
00168 static inline bool IsAirportTile(TileIndex t)
00169 {
00170 return IsTileType(t, MP_STATION) && IsAirport(t);
00171 }
00172
00173 bool IsHangar(TileIndex t);
00174
00181 static inline bool IsTruckStop(TileIndex t)
00182 {
00183 return GetStationType(t) == STATION_TRUCK;
00184 }
00185
00192 static inline bool IsBusStop(TileIndex t)
00193 {
00194 return GetStationType(t) == STATION_BUS;
00195 }
00196
00203 static inline bool IsRoadStop(TileIndex t)
00204 {
00205 assert(IsTileType(t, MP_STATION));
00206 return IsTruckStop(t) || IsBusStop(t);
00207 }
00208
00214 static inline bool IsRoadStopTile(TileIndex t)
00215 {
00216 return IsTileType(t, MP_STATION) && IsRoadStop(t);
00217 }
00218
00224 static inline bool IsStandardRoadStopTile(TileIndex t)
00225 {
00226 return IsRoadStopTile(t) && GetStationGfx(t) < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET;
00227 }
00228
00234 static inline bool IsDriveThroughStopTile(TileIndex t)
00235 {
00236 return IsRoadStopTile(t) && GetStationGfx(t) >= GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET;
00237 }
00238
00245 static inline StationGfx GetAirportGfx(TileIndex t)
00246 {
00247 assert(IsAirport(t));
00248 extern StationGfx GetTranslatedAirportTileID(StationGfx gfx);
00249 return GetTranslatedAirportTileID(GetStationGfx(t));
00250 }
00251
00258 static inline DiagDirection GetRoadStopDir(TileIndex t)
00259 {
00260 StationGfx gfx = GetStationGfx(t);
00261 assert(IsRoadStopTile(t));
00262 if (gfx < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET) {
00263 return (DiagDirection)(gfx);
00264 } else {
00265 return (DiagDirection)(gfx - GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET);
00266 }
00267 }
00268
00275 static inline bool IsOilRig(TileIndex t)
00276 {
00277 return GetStationType(t) == STATION_OILRIG;
00278 }
00279
00286 static inline bool IsDock(TileIndex t)
00287 {
00288 return GetStationType(t) == STATION_DOCK;
00289 }
00290
00296 static inline bool IsDockTile(TileIndex t)
00297 {
00298 return IsTileType(t, MP_STATION) && GetStationType(t) == STATION_DOCK;
00299 }
00300
00307 static inline bool IsBuoy(TileIndex t)
00308 {
00309 return GetStationType(t) == STATION_BUOY;
00310 }
00311
00317 static inline bool IsBuoyTile(TileIndex t)
00318 {
00319 return IsTileType(t, MP_STATION) && IsBuoy(t);
00320 }
00321
00327 static inline bool IsHangarTile(TileIndex t)
00328 {
00329 return IsTileType(t, MP_STATION) && IsHangar(t);
00330 }
00331
00338 static inline Axis GetRailStationAxis(TileIndex t)
00339 {
00340 assert(HasStationRail(t));
00341 return HasBit(GetStationGfx(t), 0) ? AXIS_Y : AXIS_X;
00342 }
00343
00350 static inline Track GetRailStationTrack(TileIndex t)
00351 {
00352 return AxisToTrack(GetRailStationAxis(t));
00353 }
00354
00361 static inline TrackBits GetRailStationTrackBits(TileIndex t)
00362 {
00363 return AxisToTrackBits(GetRailStationAxis(t));
00364 }
00365
00379 static inline bool IsCompatibleTrainStationTile(TileIndex test_tile, TileIndex station_tile)
00380 {
00381 assert(IsRailStationTile(station_tile));
00382 return IsRailStationTile(test_tile) && IsCompatibleRail(GetRailType(test_tile), GetRailType(station_tile)) &&
00383 GetRailStationAxis(test_tile) == GetRailStationAxis(station_tile) &&
00384 GetStationIndex(test_tile) == GetStationIndex(station_tile) &&
00385 !IsStationTileBlocked(test_tile);
00386 }
00387
00394 static inline bool HasStationReservation(TileIndex t)
00395 {
00396 assert(HasStationRail(t));
00397 return HasBit(_m[t].m6, 2);
00398 }
00399
00406 static inline void SetRailStationReservation(TileIndex t, bool b)
00407 {
00408 assert(HasStationRail(t));
00409 SB(_m[t].m6, 2, 1, b ? 1 : 0);
00410 }
00411
00418 static inline TrackBits GetStationReservationTrackBits(TileIndex t)
00419 {
00420 return HasStationReservation(t) ? GetRailStationTrackBits(t) : TRACK_BIT_NONE;
00421 }
00422
00430 static inline DiagDirection GetDockDirection(TileIndex t)
00431 {
00432 StationGfx gfx = GetStationGfx(t);
00433 assert(IsDock(t) && gfx < GFX_DOCK_BASE_WATER_PART);
00434 return (DiagDirection)(gfx);
00435 }
00436
00444 static inline TileIndexDiffC GetDockOffset(TileIndex t)
00445 {
00446 static const TileIndexDiffC buoy_offset = {0, 0};
00447 static const TileIndexDiffC oilrig_offset = {2, 0};
00448 static const TileIndexDiffC dock_offset[DIAGDIR_END] = {
00449 {-2, 0},
00450 { 0, 2},
00451 { 2, 0},
00452 { 0, -2},
00453 };
00454 assert(IsTileType(t, MP_STATION));
00455
00456 if (IsBuoy(t)) return buoy_offset;
00457 if (IsOilRig(t)) return oilrig_offset;
00458
00459 assert(IsDock(t));
00460
00461 return dock_offset[GetDockDirection(t)];
00462 }
00463
00470 static inline bool IsCustomStationSpecIndex(TileIndex t)
00471 {
00472 assert(HasStationTileRail(t));
00473 return _m[t].m4 != 0;
00474 }
00475
00482 static inline void SetCustomStationSpecIndex(TileIndex t, byte specindex)
00483 {
00484 assert(HasStationTileRail(t));
00485 _m[t].m4 = specindex;
00486 }
00487
00494 static inline uint GetCustomStationSpecIndex(TileIndex t)
00495 {
00496 assert(HasStationTileRail(t));
00497 return _m[t].m4;
00498 }
00499
00506 static inline void SetStationTileRandomBits(TileIndex t, byte random_bits)
00507 {
00508 assert(IsTileType(t, MP_STATION));
00509 SB(_m[t].m3, 4, 4, random_bits);
00510 }
00511
00518 static inline byte GetStationTileRandomBits(TileIndex t)
00519 {
00520 assert(IsTileType(t, MP_STATION));
00521 return GB(_m[t].m3, 4, 4);
00522 }
00523
00533 static inline void MakeStation(TileIndex t, Owner o, StationID sid, StationType st, byte section, WaterClass wc = WATER_CLASS_INVALID)
00534 {
00535 SetTileType(t, MP_STATION);
00536 SetTileOwner(t, o);
00537 SetWaterClass(t, wc);
00538 _m[t].m2 = sid;
00539 _m[t].m3 = 0;
00540 _m[t].m4 = 0;
00541 _m[t].m5 = section;
00542 SB(_m[t].m6, 2, 1, 0);
00543 SB(_m[t].m6, 3, 3, st);
00544 _me[t].m7 = 0;
00545 }
00546
00556 static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
00557 {
00558 MakeStation(t, o, sid, STATION_RAIL, section + a);
00559 SetRailType(t, rt);
00560 SetRailStationReservation(t, false);
00561 }
00562
00572 static inline void MakeRailWaypoint(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
00573 {
00574 MakeStation(t, o, sid, STATION_WAYPOINT, section + a);
00575 SetRailType(t, rt);
00576 SetRailStationReservation(t, false);
00577 }
00578
00588 static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d)
00589 {
00590 MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), d);
00591 SetRoadTypes(t, rt);
00592 SetRoadOwner(t, ROADTYPE_ROAD, o);
00593 SetRoadOwner(t, ROADTYPE_TRAM, o);
00594 }
00595
00607 static inline void MakeDriveThroughRoadStop(TileIndex t, Owner station, Owner road, Owner tram, StationID sid, RoadStopType rst, RoadTypes rt, Axis a)
00608 {
00609 MakeStation(t, station, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET + a);
00610 SetRoadTypes(t, rt);
00611 SetRoadOwner(t, ROADTYPE_ROAD, road);
00612 SetRoadOwner(t, ROADTYPE_TRAM, tram);
00613 }
00614
00623 static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section, WaterClass wc)
00624 {
00625 MakeStation(t, o, sid, STATION_AIRPORT, section, wc);
00626 }
00627
00634 static inline void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
00635 {
00636
00637
00638
00639 MakeStation(t, GetTileOwner(t), sid, STATION_BUOY, 0, wc);
00640 }
00641
00650 static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc)
00651 {
00652 MakeStation(t, o, sid, STATION_DOCK, d);
00653 MakeStation(t + TileOffsByDiagDir(d), o, sid, STATION_DOCK, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d), wc);
00654 }
00655
00662 static inline void MakeOilrig(TileIndex t, StationID sid, WaterClass wc)
00663 {
00664 MakeStation(t, OWNER_NONE, sid, STATION_OILRIG, 0, wc);
00665 }
00666
00667 #endif