station_map.h

Go to the documentation of this file.
00001 /* $Id: station_map.h 16481 2009-05-31 12:18:03Z rubidium $ */
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 
00151 static inline DiagDirection GetRoadStopDir(TileIndex t)
00152 {
00153   StationGfx gfx = GetStationGfx(t);
00154   assert(IsRoadStopTile(t));
00155   if (gfx < GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET) {
00156     return (DiagDirection)(gfx);
00157   } else {
00158     return (DiagDirection)(gfx - GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET);
00159   }
00160 }
00161 
00162 static inline bool IsOilRig(TileIndex t)
00163 {
00164   return GetStationType(t) == STATION_OILRIG;
00165 }
00166 
00167 static inline bool IsDock(TileIndex t)
00168 {
00169   return GetStationType(t) == STATION_DOCK;
00170 }
00171 
00172 static inline bool IsDockTile(TileIndex t)
00173 {
00174   return IsTileType(t, MP_STATION) && GetStationType(t) == STATION_DOCK;
00175 }
00176 
00177 static inline bool IsBuoy(TileIndex t)
00178 {
00179   return GetStationType(t) == STATION_BUOY;
00180 }
00181 
00182 static inline bool IsBuoyTile(TileIndex t)
00183 {
00184   return IsTileType(t, MP_STATION) && IsBuoy(t);
00185 }
00186 
00187 static inline bool IsHangarTile(TileIndex t)
00188 {
00189   return IsTileType(t, MP_STATION) && IsHangar(t);
00190 }
00191 
00192 
00193 static inline Axis GetRailStationAxis(TileIndex t)
00194 {
00195   assert(IsRailwayStation(t));
00196   return HasBit(GetStationGfx(t), 0) ? AXIS_Y : AXIS_X;
00197 }
00198 
00199 
00200 static inline Track GetRailStationTrack(TileIndex t)
00201 {
00202   return AxisToTrack(GetRailStationAxis(t));
00203 }
00204 
00205 static inline TrackBits GetRailStationTrackBits(TileIndex t)
00206 {
00207   return AxisToTrackBits(GetRailStationAxis(t));
00208 }
00209 
00210 static inline bool IsCompatibleTrainStationTile(TileIndex t1, TileIndex t2)
00211 {
00212   assert(IsRailwayStationTile(t2));
00213   return
00214     IsRailwayStationTile(t1) &&
00215     IsCompatibleRail(GetRailType(t1), GetRailType(t2)) &&
00216     GetRailStationAxis(t1) == GetRailStationAxis(t2) &&
00217     GetStationIndex(t1) == GetStationIndex(t2) &&
00218     !IsStationTileBlocked(t1);
00219 }
00220 
00227 static inline bool GetRailwayStationReservation(TileIndex t)
00228 {
00229   assert(IsRailwayStationTile(t));
00230   return HasBit(_m[t].m6, 2);
00231 }
00232 
00239 static inline void SetRailwayStationReservation(TileIndex t, bool b)
00240 {
00241   assert(IsRailwayStationTile(t));
00242   SB(_m[t].m6, 2, 1, b ? 1 : 0);
00243 }
00244 
00251 static inline TrackBits GetRailStationReservation(TileIndex t)
00252 {
00253   return GetRailwayStationReservation(t) ? GetRailStationTrackBits(t) : TRACK_BIT_NONE;
00254 }
00255 
00256 
00257 static inline DiagDirection GetDockDirection(TileIndex t)
00258 {
00259   StationGfx gfx = GetStationGfx(t);
00260   assert(IsDock(t) && gfx < GFX_DOCK_BASE_WATER_PART);
00261   return (DiagDirection)(gfx);
00262 }
00263 
00264 static inline TileIndexDiffC GetDockOffset(TileIndex t)
00265 {
00266   static const TileIndexDiffC buoy_offset = {0, 0};
00267   static const TileIndexDiffC oilrig_offset = {2, 0};
00268   static const TileIndexDiffC dock_offset[DIAGDIR_END] = {
00269     {-2,  0},
00270     { 0,  2},
00271     { 2,  0},
00272     { 0, -2},
00273   };
00274   assert(IsTileType(t, MP_STATION));
00275 
00276   if (IsBuoy(t)) return buoy_offset;
00277   if (IsOilRig(t)) return oilrig_offset;
00278 
00279   assert(IsDock(t));
00280 
00281   return dock_offset[GetDockDirection(t)];
00282 }
00283 
00284 static inline bool IsCustomStationSpecIndex(TileIndex t)
00285 {
00286   assert(IsTileType(t, MP_STATION));
00287   return _m[t].m4 != 0;
00288 }
00289 
00290 static inline void SetCustomStationSpecIndex(TileIndex t, byte specindex)
00291 {
00292   assert(IsTileType(t, MP_STATION));
00293   _m[t].m4 = specindex;
00294 }
00295 
00296 static inline uint GetCustomStationSpecIndex(TileIndex t)
00297 {
00298   assert(IsTileType(t, MP_STATION));
00299   return _m[t].m4;
00300 }
00301 
00302 static inline void SetStationTileRandomBits(TileIndex t, byte random_bits)
00303 {
00304   assert(IsTileType(t, MP_STATION));
00305   SB(_m[t].m3, 4, 4, random_bits);
00306 }
00307 
00308 static inline byte GetStationTileRandomBits(TileIndex t)
00309 {
00310   assert(IsTileType(t, MP_STATION));
00311   return GB(_m[t].m3, 4, 4);
00312 }
00313 
00314 static inline void MakeStation(TileIndex t, Owner o, StationID sid, StationType st, byte section)
00315 {
00316   SetTileType(t, MP_STATION);
00317   SetTileOwner(t, o);
00318   _m[t].m2 = sid;
00319   _m[t].m3 = 0;
00320   _m[t].m4 = 0;
00321   _m[t].m5 = section;
00322   SB(_m[t].m6, 2, 1, 0);
00323   SB(_m[t].m6, 3, 3, st);
00324   _me[t].m7 = 0;
00325 }
00326 
00327 static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
00328 {
00329   MakeStation(t, o, sid, STATION_RAIL, section + a);
00330   SetRailType(t, rt);
00331   SetRailwayStationReservation(t, false);
00332 }
00333 
00334 static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d)
00335 {
00336   MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), d);
00337   SetRoadTypes(t, rt);
00338   SetRoadOwner(t, ROADTYPE_ROAD, o);
00339   SetRoadOwner(t, ROADTYPE_TRAM, o);
00340 }
00341 
00342 static inline void MakeDriveThroughRoadStop(TileIndex t, Owner station, Owner road, Owner tram, StationID sid, RoadStopType rst, RoadTypes rt, Axis a)
00343 {
00344   MakeStation(t, station, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET + a);
00345   SetRoadTypes(t, rt);
00346   SetRoadOwner(t, ROADTYPE_ROAD, road);
00347   SetRoadOwner(t, ROADTYPE_TRAM, tram);
00348 }
00349 
00350 static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section)
00351 {
00352   MakeStation(t, o, sid, STATION_AIRPORT, section);
00353 }
00354 
00355 static inline void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
00356 {
00357   /* Make the owner of the buoy tile the same as the current owner of the
00358    * water tile. In this way, we can reset the owner of the water to its
00359    * original state when the buoy gets removed. */
00360   MakeStation(t, GetTileOwner(t), sid, STATION_BUOY, 0);
00361   SetWaterClass(t, wc);
00362 }
00363 
00364 static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc)
00365 {
00366   MakeStation(t, o, sid, STATION_DOCK, d);
00367   MakeStation(t + TileOffsByDiagDir(d), o, sid, STATION_DOCK, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d));
00368   SetWaterClass(t + TileOffsByDiagDir(d), wc);
00369 }
00370 
00371 static inline void MakeOilrig(TileIndex t, StationID sid, WaterClass wc)
00372 {
00373   MakeStation(t, OWNER_NONE, sid, STATION_OILRIG, 0);
00374   SetWaterClass(t, wc);
00375 }
00376 
00377 #endif /* STATION_MAP_H */

Generated on Mon Jun 8 23:04:07 2009 for OpenTTD by  doxygen 1.5.6