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.h"
00012 #include "rail.h"
00013
00014 typedef byte StationGfx;
00015
00016 static inline StationID GetStationIndex(TileIndex t)
00017 {
00018 assert(IsTileType(t, MP_STATION));
00019 return (StationID)_m[t].m2;
00020 }
00021
00022 static inline Station *GetStationByTile(TileIndex t)
00023 {
00024 return GetStation(GetStationIndex(t));
00025 }
00026
00027
00028 enum {
00029 GFX_RADAR_LARGE_FIRST = 31,
00030 GFX_RADAR_LARGE_LAST = 42,
00031 GFX_WINDSACK_FIRST = 50,
00032 GFX_WINDSACK_LAST = 53,
00033
00034 GFX_DOCK_BASE_WATER_PART = 4,
00035 GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET = 4,
00036
00037 GFX_RADAR_INTERNATIONAL_FIRST = 66,
00038 GFX_RADAR_INTERNATIONAL_LAST = 77,
00039 GFX_RADAR_METROPOLITAN_FIRST = 78,
00040 GFX_RADAR_METROPOLITAN_LAST = 89,
00041 GFX_RADAR_DISTRICTWE_FIRST = 121,
00042 GFX_RADAR_DISTRICTWE_LAST = 132,
00043 GFX_WINDSACK_INTERCON_FIRST = 140,
00044 GFX_WINDSACK_INTERCON_LAST = 143,
00045 };
00046
00047 static inline StationType GetStationType(TileIndex t)
00048 {
00049 return (StationType)GB(_m[t].m6, 3, 3);
00050 }
00051
00052 static inline RoadStop::Type GetRoadStopType(TileIndex t)
00053 {
00054 assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS);
00055 return GetStationType(t) == STATION_TRUCK ? RoadStop::TRUCK : RoadStop::BUS;
00056 }
00057
00058 static inline StationGfx GetStationGfx(TileIndex t)
00059 {
00060 assert(IsTileType(t, MP_STATION));
00061 return _m[t].m5;
00062 }
00063
00064 static inline void SetStationGfx(TileIndex t, StationGfx gfx)
00065 {
00066 assert(IsTileType(t, MP_STATION));
00067 _m[t].m5 = gfx;
00068 }
00069
00070 static inline bool IsRailwayStation(TileIndex t)
00071 {
00072 return GetStationType(t) == STATION_RAIL;
00073 }
00074
00075 static inline bool IsRailwayStationTile(TileIndex t)
00076 {
00077 return IsTileType(t, MP_STATION) && IsRailwayStation(t);
00078 }
00079
00080 static inline bool IsAirport(TileIndex t)
00081 {
00082 return GetStationType(t) == STATION_AIRPORT;
00083 }
00084
00085 bool IsHangar(TileIndex t);
00086
00087 static inline bool IsTruckStop(TileIndex t)
00088 {
00089 return GetStationType(t) == STATION_TRUCK;
00090 }
00091
00092 static inline bool IsBusStop(TileIndex t)
00093 {
00094 return GetStationType(t) == STATION_BUS;
00095 }
00096
00097 static inline bool IsRoadStop(TileIndex t)
00098 {
00099 assert(IsTileType(t, MP_STATION));
00100 return IsTruckStop(t) || IsBusStop(t);
00101 }
00102
00103 static inline bool IsRoadStopTile(TileIndex t)
00104 {
00105 return IsTileType(t, MP_STATION) && IsRoadStop(t);
00106 }
00107
00108 static inline bool IsStandardRoadStopTile(TileIndex t)
00109 {
00110 return IsRoadStopTile(t) && GetStationGfx(t) < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET;
00111 }
00112
00113 static inline bool IsDriveThroughStopTile(TileIndex t)
00114 {
00115 return IsRoadStopTile(t) && GetStationGfx(t) >= GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET;
00116 }
00117
00118 static inline bool GetStopBuiltOnTownRoad(TileIndex t)
00119 {
00120 assert(IsDriveThroughStopTile(t));
00121 return HasBit(_m[t].m6, 2);
00122 }
00123
00124
00128 static inline DiagDirection GetRoadStopDir(TileIndex t)
00129 {
00130 StationGfx gfx = GetStationGfx(t);
00131 assert(IsRoadStopTile(t));
00132 if (gfx < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET) {
00133 return (DiagDirection)(gfx);
00134 } else {
00135 return (DiagDirection)(gfx - GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET);
00136 }
00137 }
00138
00139 static inline bool IsOilRig(TileIndex t)
00140 {
00141 return GetStationType(t) == STATION_OILRIG;
00142 }
00143
00144 static inline bool IsDock(TileIndex t)
00145 {
00146 return GetStationType(t) == STATION_DOCK;
00147 }
00148
00149 static inline bool IsBuoy(TileIndex t)
00150 {
00151 return GetStationType(t) == STATION_BUOY;
00152 }
00153
00154 static inline bool IsBuoyTile(TileIndex t)
00155 {
00156 return IsTileType(t, MP_STATION) && IsBuoy(t);
00157 }
00158
00159 static inline bool IsHangarTile(TileIndex t)
00160 {
00161 return IsTileType(t, MP_STATION) && IsHangar(t);
00162 }
00163
00164
00165 static inline Axis GetRailStationAxis(TileIndex t)
00166 {
00167 assert(IsRailwayStation(t));
00168 return HasBit(GetStationGfx(t), 0) ? AXIS_Y : AXIS_X;
00169 }
00170
00171
00172 static inline Track GetRailStationTrack(TileIndex t)
00173 {
00174 return AxisToTrack(GetRailStationAxis(t));
00175 }
00176
00177 static inline bool IsCompatibleTrainStationTile(TileIndex t1, TileIndex t2)
00178 {
00179 assert(IsRailwayStationTile(t2));
00180 return
00181 IsRailwayStationTile(t1) &&
00182 IsCompatibleRail(GetRailType(t1), GetRailType(t2)) &&
00183 GetRailStationAxis(t1) == GetRailStationAxis(t2) &&
00184 GetStationIndex(t1) == GetStationIndex(t2) &&
00185 !IsStationTileBlocked(t1);
00186 }
00187
00188
00189 static inline DiagDirection GetDockDirection(TileIndex t)
00190 {
00191 StationGfx gfx = GetStationGfx(t);
00192 assert(IsDock(t) && gfx < GFX_DOCK_BASE_WATER_PART);
00193 return (DiagDirection)(gfx);
00194 }
00195
00196 static inline TileIndexDiffC GetDockOffset(TileIndex t)
00197 {
00198 static const TileIndexDiffC buoy_offset = {0, 0};
00199 static const TileIndexDiffC oilrig_offset = {2, 0};
00200 static const TileIndexDiffC dock_offset[DIAGDIR_END] = {
00201 {-2, 0},
00202 { 0, 2},
00203 { 2, 0},
00204 { 0, -2},
00205 };
00206 assert(IsTileType(t, MP_STATION));
00207
00208 if (IsBuoy(t)) return buoy_offset;
00209 if (IsOilRig(t)) return oilrig_offset;
00210
00211 assert(IsDock(t));
00212
00213 return dock_offset[GetDockDirection(t)];
00214 }
00215
00216 static inline bool IsCustomStationSpecIndex(TileIndex t)
00217 {
00218 assert(IsTileType(t, MP_STATION));
00219 return _m[t].m4 != 0;
00220 }
00221
00222 static inline void SetCustomStationSpecIndex(TileIndex t, byte specindex)
00223 {
00224 assert(IsTileType(t, MP_STATION));
00225 _m[t].m4 = specindex;
00226 }
00227
00228 static inline uint GetCustomStationSpecIndex(TileIndex t)
00229 {
00230 assert(IsTileType(t, MP_STATION));
00231 return _m[t].m4;
00232 }
00233
00234 static inline void SetStationTileRandomBits(TileIndex t, byte random_bits)
00235 {
00236 assert(IsTileType(t, MP_STATION));
00237 SB(_m[t].m3, 4, 4, random_bits);
00238 }
00239
00240 static inline byte GetStationTileRandomBits(TileIndex t)
00241 {
00242 assert(IsTileType(t, MP_STATION));
00243 return GB(_m[t].m3, 4, 4);
00244 }
00245
00246 static inline void MakeStation(TileIndex t, Owner o, StationID sid, StationType st, byte section)
00247 {
00248 SetTileType(t, MP_STATION);
00249 SetTileOwner(t, o);
00250 _m[t].m2 = sid;
00251 _m[t].m3 = 0;
00252 _m[t].m4 = 0;
00253 _m[t].m5 = section;
00254 SB(_m[t].m6, 3, 3, st);
00255 }
00256
00257 static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
00258 {
00259 MakeStation(t, o, sid, STATION_RAIL, section + a);
00260 SetRailType(t, rt);
00261 }
00262
00263 static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStop::Type rst, RoadTypes rt, DiagDirection d)
00264 {
00265 MakeStation(t, o, sid, (rst == RoadStop::BUS ? STATION_BUS : STATION_TRUCK), d);
00266 SetRoadTypes(t, rt);
00267 }
00268
00269 static inline void MakeDriveThroughRoadStop(TileIndex t, Owner o, StationID sid, RoadStop::Type rst, RoadTypes rt, Axis a, bool on_town_road)
00270 {
00271 MakeStation(t, o, sid, (rst == RoadStop::BUS ? STATION_BUS : STATION_TRUCK), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET + a);
00272 SB(_m[t].m6, 2, 1, on_town_road);
00273 SetRoadTypes(t, rt);
00274 }
00275
00276 static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section)
00277 {
00278 MakeStation(t, o, sid, STATION_AIRPORT, section);
00279 }
00280
00281 static inline void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
00282 {
00283
00284
00285
00286 MakeStation(t, GetTileOwner(t), sid, STATION_BUOY, 0);
00287 SetWaterClass(t, wc);
00288 }
00289
00290 static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc)
00291 {
00292 MakeStation(t, o, sid, STATION_DOCK, d);
00293 MakeStation(t + TileOffsByDiagDir(d), o, sid, STATION_DOCK, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d));
00294 SetWaterClass(t + TileOffsByDiagDir(d), wc);
00295 }
00296
00297 static inline void MakeOilrig(TileIndex t, StationID sid)
00298 {
00299 MakeStation(t, OWNER_NONE, sid, STATION_OILRIG, 0);
00300 }
00301
00302 #endif