src/station_map.h
changeset 5726 8f399788f6c9
parent 4666 850b5b6e4bac
child 6087 b56c54f79335
equal deleted inserted replaced
5725:8ad0e96437e0 5726:8f399788f6c9
       
     1 /* $Id$ */
       
     2 
       
     3 #ifndef STATION_MAP_H
       
     4 #define STATION_MAP_H
       
     5 
       
     6 #include "rail_map.h"
       
     7 #include "station.h"
       
     8 
       
     9 typedef byte StationGfx;
       
    10 
       
    11 static inline StationID GetStationIndex(TileIndex t)
       
    12 {
       
    13 	assert(IsTileType(t, MP_STATION));
       
    14 	return (StationID)_m[t].m2;
       
    15 }
       
    16 
       
    17 static inline Station* GetStationByTile(TileIndex t)
       
    18 {
       
    19 	return GetStation(GetStationIndex(t));
       
    20 }
       
    21 
       
    22 
       
    23 enum {
       
    24 	GFX_RAILWAY_BASE              =   0,
       
    25 	GFX_AIRPORT_BASE              =   8,
       
    26 	GFX_RADAR_LARGE_FIRST         =  39,
       
    27 	GFX_RADAR_LARGE_LAST          =  50,
       
    28 	GFX_WINDSACK_FIRST            =  58,
       
    29 	GFX_WINDSACK_LAST             =  61,
       
    30 	GFX_TRUCK_BASE                =  67,
       
    31 	GFX_BUS_BASE                  =  71,
       
    32 	GFX_OILRIG_BASE               =  75,
       
    33 	GFX_DOCK_BASE                 =  76,
       
    34 	GFX_DOCK_BASE_WATER_PART      =  80,
       
    35 	GFX_BUOY_BASE                 =  82,
       
    36 	GFX_AIRPORT_BASE_EXTENDED     =  83,
       
    37 	GFX_RADAR_INTERNATIONAL_FIRST =  90,
       
    38 	GFX_RADAR_INTERNATIONAL_LAST  = 101,
       
    39 	GFX_RADAR_METROPOLITAN_FIRST  = 102,
       
    40 	GFX_RADAR_METROPOLITAN_LAST   = 113,
       
    41 	GFX_RADAR_DISTRICTWE_FIRST    = 145,
       
    42 	GFX_RADAR_DISTRICTWE_LAST     = 156,
       
    43 	GFX_WINDSACK_INTERCON_FIRST   = 164,
       
    44 	GFX_WINDSACK_INTERCON_LAST    = 167,
       
    45 	GFX_BASE_END                  = 168
       
    46 };
       
    47 
       
    48 enum {
       
    49 	RAILWAY_SIZE = GFX_AIRPORT_BASE - GFX_RAILWAY_BASE,
       
    50 	AIRPORT_SIZE = GFX_TRUCK_BASE - GFX_AIRPORT_BASE,
       
    51 	TRUCK_SIZE = GFX_BUS_BASE - GFX_TRUCK_BASE,
       
    52 	BUS_SIZE = GFX_OILRIG_BASE - GFX_BUS_BASE,
       
    53 	DOCK_SIZE_TOTAL = GFX_BUOY_BASE - GFX_DOCK_BASE,
       
    54 	AIRPORT_SIZE_EXTENDED = GFX_BASE_END - GFX_AIRPORT_BASE_EXTENDED
       
    55 };
       
    56 
       
    57 typedef enum HangarTiles {
       
    58 	HANGAR_TILE_0 = 32,
       
    59 	HANGAR_TILE_1 = 65,
       
    60 	HANGAR_TILE_2 = 86,
       
    61 	HANGAR_TILE_3 = 129, // added for west facing hangar
       
    62 	HANGAR_TILE_4 = 130, // added for north facing hangar
       
    63 	HANGAR_TILE_5 = 131 // added for east facing hangar
       
    64 } HangarTiles;
       
    65 
       
    66 typedef enum StationType {
       
    67 	STATION_RAIL,
       
    68 	STATION_AIRPORT,
       
    69 	STATION_TRUCK,
       
    70 	STATION_BUS,
       
    71 	STATION_OILRIG,
       
    72 	STATION_DOCK,
       
    73 	STATION_BUOY
       
    74 } StationType;
       
    75 
       
    76 StationType GetStationType(TileIndex);
       
    77 
       
    78 static inline RoadStopType GetRoadStopType(TileIndex t)
       
    79 {
       
    80 	assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS);
       
    81 	return GetStationType(t) == STATION_TRUCK ? RS_TRUCK : RS_BUS;
       
    82 }
       
    83 
       
    84 static inline StationGfx GetStationGfx(TileIndex t)
       
    85 {
       
    86 	assert(IsTileType(t, MP_STATION));
       
    87 	return _m[t].m5;
       
    88 }
       
    89 
       
    90 static inline void SetStationGfx(TileIndex t, StationGfx gfx)
       
    91 {
       
    92 	assert(IsTileType(t, MP_STATION));
       
    93 	_m[t].m5 = gfx;
       
    94 }
       
    95 
       
    96 static inline bool IsRailwayStation(TileIndex t)
       
    97 {
       
    98 	return GetStationGfx(t) < GFX_RAILWAY_BASE + RAILWAY_SIZE;
       
    99 }
       
   100 
       
   101 static inline bool IsRailwayStationTile(TileIndex t)
       
   102 {
       
   103 	return IsTileType(t, MP_STATION) && IsRailwayStation(t);
       
   104 }
       
   105 
       
   106 static inline bool IsHangar(TileIndex t)
       
   107 {
       
   108 	StationGfx gfx = GetStationGfx(t);
       
   109 	return
       
   110 		gfx == HANGAR_TILE_0 ||
       
   111 		gfx == HANGAR_TILE_1 ||
       
   112 		gfx == HANGAR_TILE_2 ||
       
   113 		gfx == HANGAR_TILE_3 ||
       
   114 		gfx == HANGAR_TILE_4 ||
       
   115 		gfx == HANGAR_TILE_5;
       
   116 }
       
   117 
       
   118 static inline bool IsAirport(TileIndex t)
       
   119 {
       
   120 	StationGfx gfx = GetStationGfx(t);
       
   121 	return
       
   122 		(IS_BYTE_INSIDE(gfx, GFX_AIRPORT_BASE, GFX_AIRPORT_BASE + AIRPORT_SIZE)) ||
       
   123 		(IS_BYTE_INSIDE(gfx, GFX_AIRPORT_BASE_EXTENDED, GFX_AIRPORT_BASE_EXTENDED + AIRPORT_SIZE_EXTENDED));
       
   124 }
       
   125 
       
   126 static inline bool IsTruckStop(TileIndex t)
       
   127 {
       
   128 	return IS_BYTE_INSIDE(GetStationGfx(t), GFX_TRUCK_BASE, GFX_TRUCK_BASE + TRUCK_SIZE);
       
   129 }
       
   130 
       
   131 static inline bool IsBusStop(TileIndex t)
       
   132 {
       
   133 	return IS_BYTE_INSIDE(GetStationGfx(t), GFX_BUS_BASE, GFX_BUS_BASE + BUS_SIZE);
       
   134 }
       
   135 
       
   136 static inline bool IsRoadStop(TileIndex t)
       
   137 {
       
   138 	return IsTruckStop(t) || IsBusStop(t);
       
   139 }
       
   140 
       
   141 static inline bool IsRoadStopTile(TileIndex t)
       
   142 {
       
   143 	return IsTileType(t, MP_STATION) && IsRoadStop(t);
       
   144 }
       
   145 
       
   146 /**
       
   147  * Gets the direction the road stop entrance points towards.
       
   148  */
       
   149 static inline DiagDirection GetRoadStopDir(TileIndex t)
       
   150 {
       
   151 	assert(IsRoadStopTile(t));
       
   152 	return (DiagDirection)((GetStationGfx(t) - GFX_TRUCK_BASE) & 3);
       
   153 }
       
   154 
       
   155 static inline bool IsOilRig(TileIndex t)
       
   156 {
       
   157 	return GetStationGfx(t) == GFX_OILRIG_BASE;
       
   158 }
       
   159 
       
   160 static inline bool IsDock(TileIndex t)
       
   161 {
       
   162 	return IS_BYTE_INSIDE(GetStationGfx(t), GFX_DOCK_BASE, GFX_DOCK_BASE + DOCK_SIZE_TOTAL);
       
   163 }
       
   164 
       
   165 static inline bool IsBuoy_(TileIndex t) // XXX _ due to naming conflict
       
   166 {
       
   167 	return GetStationGfx(t) == GFX_BUOY_BASE;
       
   168 }
       
   169 
       
   170 static inline bool IsBuoyTile(TileIndex t)
       
   171 {
       
   172 	return IsTileType(t, MP_STATION) && IsBuoy_(t);
       
   173 }
       
   174 
       
   175 
       
   176 static inline bool IsHangarTile(TileIndex t)
       
   177 {
       
   178 	return IsTileType(t, MP_STATION) && IsHangar(t);
       
   179 }
       
   180 
       
   181 
       
   182 static inline Axis GetRailStationAxis(TileIndex t)
       
   183 {
       
   184 	assert(IsRailwayStation(t));
       
   185 	return HASBIT(GetStationGfx(t), 0) ? AXIS_Y : AXIS_X;
       
   186 }
       
   187 
       
   188 
       
   189 static inline Track GetRailStationTrack(TileIndex t)
       
   190 {
       
   191 	return AxisToTrack(GetRailStationAxis(t));
       
   192 }
       
   193 
       
   194 static inline bool IsCompatibleTrainStationTile(TileIndex t1, TileIndex t2)
       
   195 {
       
   196 	assert(IsRailwayStationTile(t2));
       
   197 	return
       
   198 		IsRailwayStationTile(t1) &&
       
   199 		IsCompatibleRail(GetRailType(t1), GetRailType(t2)) &&
       
   200 		GetRailStationAxis(t1) == GetRailStationAxis(t2) &&
       
   201 		!IsStationTileBlocked(t1);
       
   202 }
       
   203 
       
   204 
       
   205 static inline DiagDirection GetDockDirection(TileIndex t)
       
   206 {
       
   207 	StationGfx gfx = GetStationGfx(t);
       
   208 	assert(gfx < GFX_DOCK_BASE_WATER_PART);
       
   209 	return (DiagDirection)(gfx - GFX_DOCK_BASE);
       
   210 }
       
   211 
       
   212 static inline TileIndexDiffC GetDockOffset(TileIndex t)
       
   213 {
       
   214 	static const TileIndexDiffC buoy_offset = {0, 0};
       
   215 	static const TileIndexDiffC oilrig_offset = {2, 0};
       
   216 	static const TileIndexDiffC dock_offset[DIAGDIR_END] = {
       
   217 		{-2,  0},
       
   218 		{ 0,  2},
       
   219 		{ 2,  0},
       
   220 		{ 0, -2},
       
   221 	};
       
   222 	assert(IsTileType(t, MP_STATION));
       
   223 
       
   224 	if (IsBuoy_(t)) return buoy_offset;
       
   225 	if (IsOilRig(t)) return oilrig_offset;
       
   226 
       
   227 	assert(IsDock(t));
       
   228 
       
   229 	return dock_offset[GetDockDirection(t)];
       
   230 }
       
   231 
       
   232 static inline bool IsCustomStationSpecIndex(TileIndex t)
       
   233 {
       
   234 	assert(IsTileType(t, MP_STATION));
       
   235 	return _m[t].m4 != 0;
       
   236 }
       
   237 
       
   238 static inline void SetCustomStationSpecIndex(TileIndex t, byte specindex)
       
   239 {
       
   240 	assert(IsTileType(t, MP_STATION));
       
   241 	_m[t].m4 = specindex;
       
   242 }
       
   243 
       
   244 static inline uint GetCustomStationSpecIndex(TileIndex t)
       
   245 {
       
   246 	assert(IsTileType(t, MP_STATION));
       
   247 	return _m[t].m4;
       
   248 }
       
   249 
       
   250 static inline void SetStationTileRandomBits(TileIndex t, byte random_bits)
       
   251 {
       
   252 	assert(IsTileType(t, MP_STATION));
       
   253 	SB(_m[t].m3, 4, 4, random_bits);
       
   254 }
       
   255 
       
   256 static inline byte GetStationTileRandomBits(TileIndex t)
       
   257 {
       
   258 	assert(IsTileType(t, MP_STATION));
       
   259 	return GB(_m[t].m3, 4, 4);
       
   260 }
       
   261 
       
   262 static inline void MakeStation(TileIndex t, Owner o, StationID sid, byte m5)
       
   263 {
       
   264 	SetTileType(t, MP_STATION);
       
   265 	SetTileOwner(t, o);
       
   266 	_m[t].m2 = sid;
       
   267 	_m[t].m3 = 0;
       
   268 	_m[t].m4 = 0;
       
   269 	_m[t].m5 = m5;
       
   270 }
       
   271 
       
   272 static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
       
   273 {
       
   274 	MakeStation(t, o, sid, section + a);
       
   275 	SetRailType(t, rt);
       
   276 }
       
   277 
       
   278 static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, DiagDirection d)
       
   279 {
       
   280 	MakeStation(t, o, sid, (rst == RS_BUS ? GFX_BUS_BASE : GFX_TRUCK_BASE) + d);
       
   281 }
       
   282 
       
   283 static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section)
       
   284 {
       
   285 	MakeStation(t, o, sid, section);
       
   286 }
       
   287 
       
   288 static inline void MakeBuoy(TileIndex t, StationID sid)
       
   289 {
       
   290 	MakeStation(t, OWNER_NONE, sid, GFX_BUOY_BASE);
       
   291 }
       
   292 
       
   293 static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d)
       
   294 {
       
   295 	MakeStation(t, o, sid, GFX_DOCK_BASE + d);
       
   296 	MakeStation(t + TileOffsByDiagDir(d), o, sid, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d));
       
   297 }
       
   298 
       
   299 static inline void MakeOilrig(TileIndex t, StationID sid)
       
   300 {
       
   301 	MakeStation(t, OWNER_NONE, sid, GFX_OILRIG_BASE);
       
   302 }
       
   303 
       
   304 #endif /* STATION_MAP_H */