00001
00002
00005 #ifndef STATION_MAP_H
00006 #define STATION_MAP_H
00007
00008 #include "rail_map.h"
00009 #include "road_map.h"
00010 #include "water_map.h"
00011 #include "station_func.h"
00012 #include "station_base.h"
00013 #include "rail.h"
00014
00015 typedef byte StationGfx;
00016
00021 static inline StationID GetStationIndex(TileIndex t)
00022 {
00023 assert(IsTileType(t, MP_STATION));
00024 return (StationID)_m[t].m2;
00025 }
00026
00027 static inline Station *GetStationByTile(TileIndex t)
00028 {
00029 return GetStation(GetStationIndex(t));
00030 }
00031
00032
00033 enum {
00034 GFX_RADAR_LARGE_FIRST = 31,
00035 GFX_RADAR_LARGE_LAST = 42,
00036 GFX_WINDSACK_FIRST = 50,
00037 GFX_WINDSACK_LAST = 53,
00038
00039 GFX_DOCK_BASE_WATER_PART = 4,
00040 GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET = 4,
00041
00042 GFX_RADAR_INTERNATIONAL_FIRST = 66,
00043 GFX_RADAR_INTERNATIONAL_LAST = 77,
00044 GFX_RADAR_METROPOLITAN_FIRST = 78,
00045 GFX_RADAR_METROPOLITAN_LAST = 89,
00046 GFX_RADAR_DISTRICTWE_FIRST = 121,
00047 GFX_RADAR_DISTRICTWE_LAST = 132,
00048 GFX_WINDSACK_INTERCON_FIRST = 140,
00049 GFX_WINDSACK_INTERCON_LAST = 143,
00050 };
00051
00052 static inline StationType GetStationType(TileIndex t)
00053 {
00054 return (StationType)GB(_m[t].m6, 3, 3);
00055 }
00056
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
00063 static inline StationGfx GetStationGfx(TileIndex t)
00064 {
00065 assert(IsTileType(t, MP_STATION));
00066 return _m[t].m5;
00067 }
00068
00069 static inline void SetStationGfx(TileIndex t, StationGfx gfx)
00070 {
00071 assert(IsTileType(t, MP_STATION));
00072 _m[t].m5 = gfx;
00073 }
00074
00075 static inline uint8 GetStationAnimationFrame(TileIndex t)
00076 {
00077 assert(IsTileType(t, MP_STATION));
00078 return _me[t].m7;
00079 }
00080
00081 static inline void SetStationAnimationFrame(TileIndex t, uint8 frame)
00082 {
00083 assert(IsTileType(t, MP_STATION));
00084 _me[t].m7 = frame;
00085 }
00086
00087 static inline bool IsRailwayStation(TileIndex t)
00088 {
00089 return GetStationType(t) == STATION_RAIL;
00090 }
00091
00092 static inline bool IsRailwayStationTile(TileIndex t)
00093 {
00094 return IsTileType(t, MP_STATION) && IsRailwayStation(t);
00095 }
00096
00097 static inline bool IsAirport(TileIndex t)
00098 {
00099 return GetStationType(t) == STATION_AIRPORT;
00100 }
00101
00102 bool IsHangar(TileIndex t);
00103
00108 static inline bool IsTruckStop(TileIndex t)
00109 {
00110 return GetStationType(t) == STATION_TRUCK;
00111 }
00112
00117 static inline bool IsBusStop(TileIndex t)
00118 {
00119 return GetStationType(t) == STATION_BUS;
00120 }
00121
00127 static inline bool IsRoadStop(TileIndex t)
00128 {
00129 assert(IsTileType(t, MP_STATION));
00130 return IsTruckStop(t) || IsBusStop(t);
00131 }
00132
00133 static inline bool IsRoadStopTile(TileIndex t)
00134 {
00135 return IsTileType(t, MP_STATION) && IsRoadStop(t);
00136 }
00137
00138 static inline bool IsStandardRoadStopTile(TileIndex t)
00139 {
00140 return IsRoadStopTile(t) && GetStationGfx(t) < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET;
00141 }
00142
00143 static inline bool IsDriveThroughStopTile(TileIndex t)
00144 {
00145 return IsRoadStopTile(t) && GetStationGfx(t) >= GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET;
00146 }
00147
00148 static inline bool GetStopBuiltOnTownRoad(TileIndex t)
00149 {
00150 assert(IsDriveThroughStopTile(t));
00151 return HasBit(_m[t].m6, 2);
00152 }
00153
00154 static inline void SetStopBuiltOnTownRoad(TileIndex t, bool on_town_road)
00155 {
00156 assert(IsDriveThroughStopTile(t));
00157 SB(_m[t].m6, 2, 1, on_town_road);
00158 }
00159
00160
00164 static inline DiagDirection GetRoadStopDir(TileIndex t)
00165 {
00166 StationGfx gfx = GetStationGfx(t);
00167 assert(IsRoadStopTile(t));
00168 if (gfx < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET) {
00169 return (DiagDirection)(gfx);
00170 } else {
00171 return (DiagDirection)(gfx - GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET);
00172 }
00173 }
00174
00175 static inline bool IsOilRig(TileIndex t)
00176 {
00177 return GetStationType(t) == STATION_OILRIG;
00178 }
00179
00180 static inline bool IsDock(TileIndex t)
00181 {
00182 return GetStationType(t) == STATION_DOCK;
00183 }
00184
00185 static inline bool IsDockTile(TileIndex t)
00186 {
00187 return IsTileType(t, MP_STATION) && GetStationType(t) == STATION_DOCK;
00188 }
00189
00190 static inline bool IsBuoy(TileIndex t)
00191 {
00192 return GetStationType(t) == STATION_BUOY;
00193 }
00194
00195 static inline bool IsBuoyTile(TileIndex t)
00196 {
00197 return IsTileType(t, MP_STATION) && IsBuoy(t);
00198 }
00199
00200 static inline bool IsHangarTile(TileIndex t)
00201 {
00202 return IsTileType(t, MP_STATION) && IsHangar(t);
00203 }
00204
00205
00206 static inline Axis GetRailStationAxis(TileIndex t)
00207 {
00208 assert(IsRailwayStation(t));
00209 return HasBit(GetStationGfx(t), 0) ? AXIS_Y : AXIS_X;
00210 }
00211
00212
00213 static inline Track GetRailStationTrack(TileIndex t)
00214 {
00215 return AxisToTrack(GetRailStationAxis(t));
00216 }
00217
00218 static inline bool IsCompatibleTrainStationTile(TileIndex t1, TileIndex t2)
00219 {
00220 assert(IsRailwayStationTile(t2));
00221 return
00222 IsRailwayStationTile(t1) &&
00223 IsCompatibleRail(GetRailType(t1), GetRailType(t2)) &&
00224 GetRailStationAxis(t1) == GetRailStationAxis(t2) &&
00225 GetStationIndex(t1) == GetStationIndex(t2) &&
00226 !IsStationTileBlocked(t1);
00227 }
00228
00235 static inline bool GetRailwayStationReservation(TileIndex t)
00236 {
00237 assert(IsRailwayStationTile(t));
00238 return HasBit(_m[t].m6, 2);
00239 }
00240
00247 static inline void SetRailwayStationReservation(TileIndex t, bool b)
00248 {
00249 assert(IsRailwayStationTile(t));
00250 SB(_m[t].m6, 2, 1, b ? 1 : 0);
00251 }
00252
00259 static inline TrackBits GetRailStationReservation(TileIndex t)
00260 {
00261 return GetRailwayStationReservation(t) ? AxisToTrackBits(GetRailStationAxis(t)) : TRACK_BIT_NONE;
00262 }
00263
00264
00265 static inline DiagDirection GetDockDirection(TileIndex t)
00266 {
00267 StationGfx gfx = GetStationGfx(t);
00268 assert(IsDock(t) && gfx < GFX_DOCK_BASE_WATER_PART);
00269 return (DiagDirection)(gfx);
00270 }
00271
00272 static inline TileIndexDiffC GetDockOffset(TileIndex t)
00273 {
00274 static const TileIndexDiffC buoy_offset = {0, 0};
00275 static const TileIndexDiffC oilrig_offset = {2, 0};
00276 static const TileIndexDiffC dock_offset[DIAGDIR_END] = {
00277 {-2, 0},
00278 { 0, 2},
00279 { 2, 0},
00280 { 0, -2},
00281 };
00282 assert(IsTileType(t, MP_STATION));
00283
00284 if (IsBuoy(t)) return buoy_offset;
00285 if (IsOilRig(t)) return oilrig_offset;
00286
00287 assert(IsDock(t));
00288
00289 return dock_offset[GetDockDirection(t)];
00290 }
00291
00292 static inline bool IsCustomStationSpecIndex(TileIndex t)
00293 {
00294 assert(IsTileType(t, MP_STATION));
00295 return _m[t].m4 != 0;
00296 }
00297
00298 static inline void SetCustomStationSpecIndex(TileIndex t, byte specindex)
00299 {
00300 assert(IsTileType(t, MP_STATION));
00301 _m[t].m4 = specindex;
00302 }
00303
00304 static inline uint GetCustomStationSpecIndex(TileIndex t)
00305 {
00306 assert(IsTileType(t, MP_STATION));
00307 return _m[t].m4;
00308 }
00309
00310 static inline void SetStationTileRandomBits(TileIndex t, byte random_bits)
00311 {
00312 assert(IsTileType(t, MP_STATION));
00313 SB(_m[t].m3, 4, 4, random_bits);
00314 }
00315
00316 static inline byte GetStationTileRandomBits(TileIndex t)
00317 {
00318 assert(IsTileType(t, MP_STATION));
00319 return GB(_m[t].m3, 4, 4);
00320 }
00321
00322 static inline void MakeStation(TileIndex t, Owner o, StationID sid, StationType st, byte section)
00323 {
00324 SetTileType(t, MP_STATION);
00325 SetTileOwner(t, o);
00326 _m[t].m2 = sid;
00327 _m[t].m3 = 0;
00328 _m[t].m4 = 0;
00329 _m[t].m5 = section;
00330 SB(_m[t].m6, 3, 3, st);
00331 }
00332
00333 static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
00334 {
00335 MakeStation(t, o, sid, STATION_RAIL, section + a);
00336 SetRailType(t, rt);
00337 SetRailwayStationReservation(t, false);
00338 }
00339
00340 static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d)
00341 {
00342 MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), d);
00343 SetRoadTypes(t, rt);
00344 }
00345
00346 static inline void MakeDriveThroughRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, Axis a, bool on_town_road)
00347 {
00348 MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET + a);
00349 SB(_m[t].m6, 2, 1, on_town_road);
00350 SetRoadTypes(t, rt);
00351 }
00352
00353 static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section)
00354 {
00355 MakeStation(t, o, sid, STATION_AIRPORT, section);
00356 }
00357
00358 static inline void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
00359 {
00360
00361
00362
00363 MakeStation(t, GetTileOwner(t), sid, STATION_BUOY, 0);
00364 SetWaterClass(t, wc);
00365 }
00366
00367 static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc)
00368 {
00369 MakeStation(t, o, sid, STATION_DOCK, d);
00370 MakeStation(t + TileOffsByDiagDir(d), o, sid, STATION_DOCK, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d));
00371 SetWaterClass(t + TileOffsByDiagDir(d), wc);
00372 }
00373
00374 static inline void MakeOilrig(TileIndex t, StationID sid, WaterClass wc)
00375 {
00376 MakeStation(t, OWNER_NONE, sid, STATION_OILRIG, 0);
00377 SetWaterClass(t, wc);
00378 }
00379
00380 #endif