station_map.h
changeset 3545 b08ce1bbb589
parent 3541 de660582cff4
child 3568 c60d7aceed1a
equal deleted inserted replaced
3544:b7f47860e645 3545:b08ce1bbb589
     3 #ifndef STATION_MAP_H
     3 #ifndef STATION_MAP_H
     4 #define STATION_MAP_H
     4 #define STATION_MAP_H
     5 
     5 
     6 #include "station.h"
     6 #include "station.h"
     7 
     7 
       
     8 typedef byte StationGfx;
       
     9 
     8 static inline StationID GetStationIndex(TileIndex t)
    10 static inline StationID GetStationIndex(TileIndex t)
     9 {
    11 {
    10 	assert(IsTileType(t, MP_STATION));
    12 	assert(IsTileType(t, MP_STATION));
    11 	return (StationID)_m[t].m2;
    13 	return (StationID)_m[t].m2;
    12 }
    14 }
    16 	return GetStation(GetStationIndex(t));
    18 	return GetStation(GetStationIndex(t));
    17 }
    19 }
    18 
    20 
    19 
    21 
    20 enum {
    22 enum {
    21 	RAILWAY_BASE = 0x0,
    23 	GFX_RAILWAY_BASE              =   0,
    22 	AIRPORT_BASE = 0x8,
    24 	GFX_AIRPORT_BASE              =   8,
    23 	TRUCK_BASE = 0x43,
    25 	GFX_RADAR_LARGE_FIRST         =  39,
    24 	BUS_BASE = 0x47,
    26 	GFX_RADAR_LARGE_LAST          =  50,
    25 	OILRIG_BASE = 0x4B,
    27 	GFX_WINDSACK_FIRST            =  58,
    26 	DOCK_BASE = 0x4C,
    28 	GFX_WINDSACK_LAST             =  61,
    27 	DOCK_BASE_WATER_PART = 0x50,
    29 	GFX_TRUCK_BASE                =  67,
    28 	BUOY_BASE = 0x52,
    30 	GFX_BUS_BASE                  =  71,
    29 	AIRPORT_BASE_EXTENDED = 0x53,
    31 	GFX_OILRIG_BASE               =  75,
    30 
    32 	GFX_DOCK_BASE                 =  76,
    31 	BASE_END = 0x73
    33 	GFX_DOCK_BASE_WATER_PART      =  80,
       
    34 	GFX_BUOY_BASE                 =  82,
       
    35 	GFX_AIRPORT_BASE_EXTENDED     =  83,
       
    36 	GFX_RADAR_INTERNATIONAL_FIRST =  90,
       
    37 	GFX_RADAR_INTERNATIONAL_LAST  = 101,
       
    38 	GFX_RADAR_METROPOLITAN_FIRST  = 102,
       
    39 	GFX_RADAR_METROPOLITAN_LAST   = 113,
       
    40 	GFX_BASE_END                  = 155
    32 };
    41 };
    33 
    42 
    34 enum {
    43 enum {
    35 	RAILWAY_SIZE = AIRPORT_BASE - RAILWAY_BASE,
    44 	RAILWAY_SIZE = GFX_AIRPORT_BASE - GFX_RAILWAY_BASE,
    36 	AIRPORT_SIZE = TRUCK_BASE - AIRPORT_BASE,
    45 	AIRPORT_SIZE = GFX_TRUCK_BASE - GFX_AIRPORT_BASE,
    37 	TRUCK_SIZE = BUS_BASE - TRUCK_BASE,
    46 	TRUCK_SIZE = GFX_BUS_BASE - GFX_TRUCK_BASE,
    38 	BUS_SIZE = OILRIG_BASE - BUS_BASE,
    47 	BUS_SIZE = GFX_OILRIG_BASE - GFX_BUS_BASE,
    39 	DOCK_SIZE_TOTAL = BUOY_BASE - DOCK_BASE,
    48 	DOCK_SIZE_TOTAL = GFX_BUOY_BASE - GFX_DOCK_BASE,
    40 	AIRPORT_SIZE_EXTENDED = BASE_END - AIRPORT_BASE_EXTENDED
    49 	AIRPORT_SIZE_EXTENDED = GFX_BASE_END - GFX_AIRPORT_BASE_EXTENDED
    41 };
    50 };
    42 
    51 
    43 typedef enum HangarTiles {
    52 typedef enum HangarTiles {
    44 	HANGAR_TILE_0 = 32,
    53 	HANGAR_TILE_0 = 32,
    45 	HANGAR_TILE_1 = 65,
    54 	HANGAR_TILE_1 = 65,
    63 {
    72 {
    64 	assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS);
    73 	assert(GetStationType(t) == STATION_TRUCK || GetStationType(t) == STATION_BUS);
    65 	return GetStationType(t) == STATION_TRUCK ? RS_TRUCK : RS_BUS;
    74 	return GetStationType(t) == STATION_TRUCK ? RS_TRUCK : RS_BUS;
    66 }
    75 }
    67 
    76 
    68 static inline byte GetStationGfx(TileIndex t)
    77 static inline StationGfx GetStationGfx(TileIndex t)
    69 {
    78 {
    70 	assert(IsTileType(t, MP_STATION));
    79 	assert(IsTileType(t, MP_STATION));
    71 	return _m[t].m5;
    80 	return _m[t].m5;
    72 }
    81 }
    73 
    82 
    74 static inline void SetStationGfx(TileIndex t, byte gfx)
    83 static inline void SetStationGfx(TileIndex t, StationGfx gfx)
    75 {
    84 {
    76 	assert(IsTileType(t, MP_STATION));
    85 	assert(IsTileType(t, MP_STATION));
    77 	_m[t].m5 = gfx;
    86 	_m[t].m5 = gfx;
    78 }
    87 }
    79 
    88 
    80 static inline bool IsRailwayStation(TileIndex t)
    89 static inline bool IsRailwayStation(TileIndex t)
    81 {
    90 {
    82 	return GetStationGfx(t) < RAILWAY_BASE + RAILWAY_SIZE;
    91 	return GetStationGfx(t) < GFX_RAILWAY_BASE + RAILWAY_SIZE;
    83 }
    92 }
    84 
    93 
    85 static inline bool IsRailwayStationTile(TileIndex t)
    94 static inline bool IsRailwayStationTile(TileIndex t)
    86 {
    95 {
    87 	return IsTileType(t, MP_STATION) && IsRailwayStation(t);
    96 	return IsTileType(t, MP_STATION) && IsRailwayStation(t);
    88 }
    97 }
    89 
    98 
    90 static inline bool IsHangar(TileIndex t)
    99 static inline bool IsHangar(TileIndex t)
    91 {
   100 {
    92 	byte gfx = GetStationGfx(t);
   101 	StationGfx gfx = GetStationGfx(t);
    93 	return
   102 	return
    94 		gfx == HANGAR_TILE_0 ||
   103 		gfx == HANGAR_TILE_0 ||
    95 		gfx == HANGAR_TILE_1 ||
   104 		gfx == HANGAR_TILE_1 ||
    96 		gfx == HANGAR_TILE_2;
   105 		gfx == HANGAR_TILE_2;
    97 }
   106 }
    98 
   107 
    99 static inline bool IsAirport(TileIndex t)
   108 static inline bool IsAirport(TileIndex t)
   100 {
   109 {
   101 	byte gfx = GetStationGfx(t);
   110 	StationGfx gfx = GetStationGfx(t);
   102 	return
   111 	return
   103 		IS_INT_INSIDE(gfx, AIRPORT_BASE, AIRPORT_BASE + AIRPORT_SIZE) ||
   112 		(IS_BYTE_INSIDE(gfx, GFX_AIRPORT_BASE, GFX_AIRPORT_BASE + AIRPORT_SIZE)) ||
   104 		IS_INT_INSIDE(gfx, AIRPORT_BASE_EXTENDED, AIRPORT_BASE_EXTENDED + AIRPORT_SIZE_EXTENDED);
   113 		(IS_BYTE_INSIDE(gfx, GFX_AIRPORT_BASE_EXTENDED, GFX_AIRPORT_BASE_EXTENDED + AIRPORT_SIZE_EXTENDED));
   105 }
   114 }
   106 
   115 
   107 static inline bool IsTruckStop(TileIndex t)
   116 static inline bool IsTruckStop(TileIndex t)
   108 {
   117 {
   109 	return IS_INT_INSIDE(GetStationGfx(t), TRUCK_BASE, TRUCK_BASE + TRUCK_SIZE);
   118 	return IS_BYTE_INSIDE(GetStationGfx(t), GFX_TRUCK_BASE, GFX_TRUCK_BASE + TRUCK_SIZE);
   110 }
   119 }
   111 
   120 
   112 static inline bool IsBusStop(TileIndex t)
   121 static inline bool IsBusStop(TileIndex t)
   113 {
   122 {
   114 	return IS_INT_INSIDE(GetStationGfx(t), BUS_BASE, BUS_BASE + BUS_SIZE);
   123 	return IS_BYTE_INSIDE(GetStationGfx(t), GFX_BUS_BASE, GFX_BUS_BASE + BUS_SIZE);
   115 }
   124 }
   116 
   125 
   117 static inline bool IsRoadStop(TileIndex t)
   126 static inline bool IsRoadStop(TileIndex t)
   118 {
   127 {
   119 	return IsTruckStop(t) || IsBusStop(t);
   128 	return IsTruckStop(t) || IsBusStop(t);
   128  * Gets the direction the road stop entrance points towards.
   137  * Gets the direction the road stop entrance points towards.
   129  */
   138  */
   130 static inline DiagDirection GetRoadStopDir(TileIndex t)
   139 static inline DiagDirection GetRoadStopDir(TileIndex t)
   131 {
   140 {
   132 	assert(IsRoadStopTile(t));
   141 	assert(IsRoadStopTile(t));
   133 	return (GetStationGfx(t) - TRUCK_BASE) & 3;
   142 	return (GetStationGfx(t) - GFX_TRUCK_BASE) & 3;
   134 }
   143 }
   135 
   144 
   136 static inline bool IsOilRig(TileIndex t)
   145 static inline bool IsOilRig(TileIndex t)
   137 {
   146 {
   138 	return GetStationGfx(t) == OILRIG_BASE;
   147 	return GetStationGfx(t) == GFX_OILRIG_BASE;
   139 }
   148 }
   140 
   149 
   141 static inline bool IsDock(TileIndex t)
   150 static inline bool IsDock(TileIndex t)
   142 {
   151 {
   143 	return IS_INT_INSIDE(GetStationGfx(t), DOCK_BASE, DOCK_BASE + DOCK_SIZE_TOTAL);
   152 	return IS_BYTE_INSIDE(GetStationGfx(t), GFX_DOCK_BASE, GFX_DOCK_BASE + DOCK_SIZE_TOTAL);
   144 }
   153 }
   145 
   154 
   146 static inline bool IsBuoy_(TileIndex t) // XXX _ due to naming conflict
   155 static inline bool IsBuoy_(TileIndex t) // XXX _ due to naming conflict
   147 {
   156 {
   148 	return GetStationGfx(t) == BUOY_BASE;
   157 	return GetStationGfx(t) == GFX_BUOY_BASE;
   149 }
   158 }
   150 
   159 
   151 static inline bool IsBuoyTile(TileIndex t)
   160 static inline bool IsBuoyTile(TileIndex t)
   152 {
   161 {
   153 	return IsTileType(t, MP_STATION) && IsBuoy_(t);
   162 	return IsTileType(t, MP_STATION) && IsBuoy_(t);
   182 }
   191 }
   183 
   192 
   184 
   193 
   185 static inline DiagDirection GetDockDirection(TileIndex t)
   194 static inline DiagDirection GetDockDirection(TileIndex t)
   186 {
   195 {
   187 	byte gfx = GetStationGfx(t);
   196 	StationGfx gfx = GetStationGfx(t);
   188 	assert(gfx < DOCK_BASE_WATER_PART);
   197 	assert(gfx < GFX_DOCK_BASE_WATER_PART);
   189 	return (DiagDirection)(gfx - DOCK_BASE);
   198 	return (DiagDirection)(gfx - GFX_DOCK_BASE);
   190 }
   199 }
   191 
   200 
   192 static inline TileIndexDiffC GetDockOffset(TileIndex t)
   201 static inline TileIndexDiffC GetDockOffset(TileIndex t)
   193 {
   202 {
   194 	static const TileIndexDiffC buoy_offset = {0, 0};
   203 	static const TileIndexDiffC buoy_offset = {0, 0};
   244 	SetRailType(t, rt);
   253 	SetRailType(t, rt);
   245 }
   254 }
   246 
   255 
   247 static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, DiagDirection d)
   256 static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, DiagDirection d)
   248 {
   257 {
   249 	MakeStation(t, o, sid, (rst == RS_BUS ? BUS_BASE : TRUCK_BASE) + d);
   258 	MakeStation(t, o, sid, (rst == RS_BUS ? GFX_BUS_BASE : GFX_TRUCK_BASE) + d);
   250 }
   259 }
   251 
   260 
   252 static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section)
   261 static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section)
   253 {
   262 {
   254 	MakeStation(t, o, sid, section);
   263 	MakeStation(t, o, sid, section);
   255 }
   264 }
   256 
   265 
   257 static inline void MakeBuoy(TileIndex t, StationID sid)
   266 static inline void MakeBuoy(TileIndex t, StationID sid)
   258 {
   267 {
   259 	MakeStation(t, OWNER_NONE, sid, BUOY_BASE);
   268 	MakeStation(t, OWNER_NONE, sid, GFX_BUOY_BASE);
   260 }
   269 }
   261 
   270 
   262 static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d)
   271 static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d)
   263 {
   272 {
   264 	MakeStation(t, o, sid, DOCK_BASE + d);
   273 	MakeStation(t, o, sid, GFX_DOCK_BASE + d);
   265 	MakeStation(t + TileOffsByDir(d), o, sid, DOCK_BASE_WATER_PART + DiagDirToAxis(d));
   274 	MakeStation(t + TileOffsByDir(d), o, sid, GFX_DOCK_BASE_WATER_PART + DiagDirToAxis(d));
   266 }
   275 }
   267 
   276 
   268 static inline void MakeOilrig(TileIndex t, StationID sid)
   277 static inline void MakeOilrig(TileIndex t, StationID sid)
   269 {
   278 {
   270 	MakeStation(t, OWNER_NONE, sid, OILRIG_BASE);
   279 	MakeStation(t, OWNER_NONE, sid, GFX_OILRIG_BASE);
   271 }
   280 }
   272 
   281 
   273 #endif
   282 #endif