station_map.h

Go to the documentation of this file.
00001 /* $Id: station_map.h 15643 2009-03-08 16:10:39Z smatz $ */
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 bool IsCompatibleTrainStationTile(TileIndex t1, TileIndex t2)
00206 {
00207   assert(IsRailwayStationTile(t2));
00208   return
00209     IsRailwayStationTile(t1) &&
00210     IsCompatibleRail(GetRailType(t1), GetRailType(t2)) &&
00211     GetRailStationAxis(t1) == GetRailStationAxis(t2) &&
00212     GetStationIndex(t1) == GetStationIndex(t2) &&
00213     !IsStationTileBlocked(t1);
00214 }
00215 
00222 static inline bool GetRailwayStationReservation(TileIndex t)
00223 {
00224   assert(IsRailwayStationTile(t));
00225   return HasBit(_m[t].m6, 2);
00226 }
00227 
00234 static inline void SetRailwayStationReservation(TileIndex t, bool b)
00235 {
00236   assert(IsRailwayStationTile(t));
00237   SB(_m[t].m6, 2, 1, b ? 1 : 0);
00238 }
00239 
00246 static inline TrackBits GetRailStationReservation(TileIndex t)
00247 {
00248   return GetRailwayStationReservation(t) ? AxisToTrackBits(GetRailStationAxis(t)) : TRACK_BIT_NONE;
00249 }
00250 
00251 
00252 static inline DiagDirection GetDockDirection(TileIndex t)
00253 {
00254   StationGfx gfx = GetStationGfx(t);
00255   assert(IsDock(t) && gfx < GFX_DOCK_BASE_WATER_PART);
00256   return (DiagDirection)(gfx);
00257 }
00258 
00259 static inline TileIndexDiffC GetDockOffset(TileIndex t)
00260 {
00261   static const TileIndexDiffC buoy_offset = {0, 0};
00262   static const TileIndexDiffC oilrig_offset = {2, 0};
00263   static const TileIndexDiffC dock_offset[DIAGDIR_END] = {
00264     {-2,  0},
00265     { 0,  2},
00266     { 2,  0},
00267     { 0, -2},
00268   };
00269   assert(IsTileType(t, MP_STATION));
00270 
00271   if (IsBuoy(t)) return buoy_offset;
00272   if (IsOilRig(t)) return oilrig_offset;
00273 
00274   assert(IsDock(t));
00275 
00276   return dock_offset[GetDockDirection(t)];
00277 }
00278 
00279 static inline bool IsCustomStationSpecIndex(TileIndex t)
00280 {
00281   assert(IsTileType(t, MP_STATION));
00282   return _m[t].m4 != 0;
00283 }
00284 
00285 static inline void SetCustomStationSpecIndex(TileIndex t, byte specindex)
00286 {
00287   assert(IsTileType(t, MP_STATION));
00288   _m[t].m4 = specindex;
00289 }
00290 
00291 static inline uint GetCustomStationSpecIndex(TileIndex t)
00292 {
00293   assert(IsTileType(t, MP_STATION));
00294   return _m[t].m4;
00295 }
00296 
00297 static inline void SetStationTileRandomBits(TileIndex t, byte random_bits)
00298 {
00299   assert(IsTileType(t, MP_STATION));
00300   SB(_m[t].m3, 4, 4, random_bits);
00301 }
00302 
00303 static inline byte GetStationTileRandomBits(TileIndex t)
00304 {
00305   assert(IsTileType(t, MP_STATION));
00306   return GB(_m[t].m3, 4, 4);
00307 }
00308 
00309 static inline void MakeStation(TileIndex t, Owner o, StationID sid, StationType st, byte section)
00310 {
00311   SetTileType(t, MP_STATION);
00312   SetTileOwner(t, o);
00313   _m[t].m2 = sid;
00314   _m[t].m3 = 0;
00315   _m[t].m4 = 0;
00316   _m[t].m5 = section;
00317   SB(_m[t].m6, 2, 1, 0);
00318   SB(_m[t].m6, 3, 3, st);
00319   _me[t].m7 = 0;
00320 }
00321 
00322 static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
00323 {
00324   MakeStation(t, o, sid, STATION_RAIL, section + a);
00325   SetRailType(t, rt);
00326   SetRailwayStationReservation(t, false);
00327 }
00328 
00329 static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, RoadTypes rt, DiagDirection d)
00330 {
00331   MakeStation(t, o, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), d);
00332   SetRoadTypes(t, rt);
00333   SetRoadOwner(t, ROADTYPE_ROAD, o);
00334   SetRoadOwner(t, ROADTYPE_TRAM, o);
00335 }
00336 
00337 static inline void MakeDriveThroughRoadStop(TileIndex t, Owner station, Owner road, Owner tram, StationID sid, RoadStopType rst, RoadTypes rt, Axis a)
00338 {
00339   MakeStation(t, station, sid, (rst == ROADSTOP_BUS ? STATION_BUS : STATION_TRUCK), GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET + a);
00340   SetRoadTypes(t, rt);
00341   SetRoadOwner(t, ROADTYPE_ROAD, road);
00342   SetRoadOwner(t, ROADTYPE_TRAM, tram);
00343 }
00344 
00345 static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section)
00346 {
00347   MakeStation(t, o, sid, STATION_AIRPORT, section);
00348 }
00349 
00350 static inline void MakeBuoy(TileIndex t, StationID sid, WaterClass wc)
00351 {
00352   /* Make the owner of the buoy tile the same as the current owner of the
00353    * water tile. In this way, we can reset the owner of the water to its
00354    * original state when the buoy gets removed. */
00355   MakeStation(t, GetTileOwner(t), sid, STATION_BUOY, 0);
00356   SetWaterClass(t, wc);
00357 }
00358 
00359 static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d, WaterClass wc)
00360 {
00361   MakeStation(t, o, sid, STATION_DOCK, d);
00362   MakeStation(t + TileOffsByDiagDir(d), o, sid, STATION_DOCK, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d));
00363   SetWaterClass(t + TileOffsByDiagDir(d), wc);
00364 }
00365 
00366 static inline void MakeOilrig(TileIndex t, StationID sid, WaterClass wc)
00367 {
00368   MakeStation(t, OWNER_NONE, sid, STATION_OILRIG, 0);
00369   SetWaterClass(t, wc);
00370 }
00371 
00372 #endif /* STATION_MAP_H */

Generated on Mon May 11 15:48:07 2009 for OpenTTD by  doxygen 1.5.6