station_map.h
changeset 3334 b72ac8637a30
parent 3315 1f65f8260092
child 3337 07e476ea35b5
equal deleted inserted replaced
3333:41f8abe65d1e 3334:b72ac8637a30
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
       
     3 #ifndef STATION_MAP_H
       
     4 #define STATION_MAP_H
       
     5 
     3 #include "station.h"
     6 #include "station.h"
       
     7 #include "water_map.h" /* for IsClearWaterTile */
     4 
     8 
     5 
     9 
     6 static inline StationID GetStationIndex(TileIndex t)
    10 static inline StationID GetStationIndex(TileIndex t)
     7 {
    11 {
     8 	return (StationID)_m[t].m2;
    12 	return (StationID)_m[t].m2;
    10 
    14 
    11 static inline Station* GetStationByTile(TileIndex t)
    15 static inline Station* GetStationByTile(TileIndex t)
    12 {
    16 {
    13 	return GetStation(GetStationIndex(t));
    17 	return GetStation(GetStationIndex(t));
    14 }
    18 }
       
    19 
       
    20 
       
    21 enum {
       
    22 	RAILWAY_BASE = 0x0,
       
    23 	AIRPORT_BASE = 0x8,
       
    24 	TRUCK_BASE = 0x43,
       
    25 	BUS_BASE = 0x47,
       
    26 	OILRIG_BASE = 0x4B,
       
    27 	DOCK_BASE = 0x4C,
       
    28 	DOCK_BASE_WATER_PART = 0x50,
       
    29 	BUOY_BASE = 0x52,
       
    30 	AIRPORT_BASE_EXTENDED = 0x53,
       
    31 
       
    32 	TYPE_MAX = 0x72
       
    33 };
       
    34 
       
    35 enum {
       
    36 	RAILWAY_SIZE = AIRPORT_BASE - RAILWAY_BASE,
       
    37 	AIRPORT_SIZE = TRUCK_BASE - AIRPORT_BASE,
       
    38 	TRUCK_SIZE = BUS_BASE - TRUCK_BASE,
       
    39 	BUS_SIZE = OILRIG_BASE - BUS_BASE,
       
    40 	DOCK_SIZE_TOTAL = BUOY_BASE - DOCK_BASE,
       
    41 	AIRPORT_SIZE_EXTENDED = TYPE_MAX - AIRPORT_BASE_EXTENDED
       
    42 };
       
    43 
       
    44 typedef enum HangarTiles {
       
    45 	HANGAR_TILE_0 = 32,
       
    46 	HANGAR_TILE_1 = 65
       
    47 } HangarTiles;
       
    48 
       
    49 typedef enum StationType {
       
    50 	STATION_RAIL,
       
    51 	STATION_HANGAR,
       
    52 	STATION_AIRPORT,
       
    53 	STATION_TRUCK,
       
    54 	STATION_BUS,
       
    55 	STATION_OILRIG,
       
    56 	STATION_DOCK,
       
    57 	STATION_BUOY
       
    58 } StationType;
       
    59 
       
    60 StationType GetStationType(TileIndex);
       
    61 
       
    62 static inline bool IsRailwayStation(TileIndex t)
       
    63 {
       
    64 	return _m[t].m5 < RAILWAY_BASE + RAILWAY_SIZE;
       
    65 }
       
    66 
       
    67 static inline bool IsHangar(TileIndex t)
       
    68 {
       
    69 	return _m[t].m5 == HANGAR_TILE_0 || _m[t].m5 == HANGAR_TILE_1;
       
    70 }
       
    71 
       
    72 static inline bool IsAirport(TileIndex t)
       
    73 {
       
    74 	return
       
    75 		IS_INT_INSIDE(_m[t].m5, AIRPORT_BASE, AIRPORT_BASE + AIRPORT_SIZE) ||
       
    76 		IS_INT_INSIDE(_m[t].m5, AIRPORT_BASE_EXTENDED, AIRPORT_BASE_EXTENDED + AIRPORT_SIZE_EXTENDED);
       
    77 }
       
    78 
       
    79 static inline bool IsTruckStop(TileIndex t)
       
    80 {
       
    81 	return IS_INT_INSIDE(_m[t].m5, TRUCK_BASE, TRUCK_BASE + TRUCK_SIZE);
       
    82 }
       
    83 
       
    84 static inline bool IsBusStop(TileIndex t)
       
    85 {
       
    86 	return IS_INT_INSIDE(_m[t].m5, BUS_BASE, BUS_BASE + BUS_SIZE);
       
    87 }
       
    88 
       
    89 static inline bool IsRoadStop(TileIndex t)
       
    90 {
       
    91 	return IsTruckStop(t) || IsBusStop(t);
       
    92 }
       
    93 
       
    94 static inline bool IsOilRig(TileIndex t)
       
    95 {
       
    96 	return _m[t].m5 == OILRIG_BASE;
       
    97 }
       
    98 
       
    99 static inline bool IsDock(TileIndex t)
       
   100 {
       
   101 	return IS_INT_INSIDE(_m[t].m5, DOCK_BASE, DOCK_BASE + DOCK_SIZE_TOTAL);
       
   102 }
       
   103 
       
   104 static inline bool IsBuoy_(TileIndex t) // XXX _ due to naming conflict
       
   105 {
       
   106 	return _m[t].m5 == BUOY_BASE;
       
   107 }
       
   108 
       
   109 
       
   110 static inline Axis GetRailStationAxis(TileIndex t)
       
   111 {
       
   112 	assert(IsRailwayStation(t));
       
   113 	return HASBIT(_m[t].m5, 0) ? AXIS_Y : AXIS_X;
       
   114 }
       
   115 
       
   116 
       
   117 static inline Track GetRailStationTrack(TileIndex t)
       
   118 {
       
   119 	return GetRailStationAxis(t) == AXIS_X ? TRACK_X : TRACK_Y;
       
   120 }
       
   121 
       
   122 
       
   123 static inline DiagDirection GetDockDirection(TileIndex t)
       
   124 {
       
   125 	assert(IsTileType(t, MP_STATION));
       
   126 	assert(_m[t].m5 > DOCK_BASE_WATER_PART);
       
   127 
       
   128 	return (DiagDirection)(_m[t].m5 - DOCK_BASE);
       
   129 }
       
   130 
       
   131 
       
   132 static inline bool IsCustomStationSprite(TileIndex t)
       
   133 {
       
   134 	return HASBIT(_m[t].m3, 4);
       
   135 }
       
   136 
       
   137 static inline void SetCustomStationSprite(TileIndex t, byte sprite)
       
   138 {
       
   139 	SETBIT(_m[t].m3, 4);
       
   140 	_m[t].m4 = sprite;
       
   141 }
       
   142 
       
   143 static inline uint GetCustomStationSprite(TileIndex t)
       
   144 {
       
   145 	return _m[t].m4;
       
   146 }
       
   147 
       
   148 
       
   149 static inline void MakeStation(TileIndex t, Owner o, StationID sid, byte m5)
       
   150 {
       
   151 	SetTileType(t, MP_STATION);
       
   152 	SetTileOwner(t, o);
       
   153 	_m[t].m2 = sid;
       
   154 	_m[t].m3 = 0;
       
   155 	_m[t].m4 = 0;
       
   156 	_m[t].m5 = m5;
       
   157 }
       
   158 
       
   159 static inline void MakeRailStation(TileIndex t, Owner o, StationID sid, Axis a, byte section, RailType rt)
       
   160 {
       
   161 	MakeStation(t, o, sid, section + a);
       
   162 	SetRailType(t, rt);
       
   163 }
       
   164 
       
   165 static inline void MakeRoadStop(TileIndex t, Owner o, StationID sid, RoadStopType rst, DiagDirection d)
       
   166 {
       
   167 	MakeStation(t, o, sid, (rst == RS_BUS ? BUS_BASE : TRUCK_BASE) + d);
       
   168 }
       
   169 
       
   170 static inline void MakeAirport(TileIndex t, Owner o, StationID sid, byte section)
       
   171 {
       
   172 	MakeStation(t, o, sid, section);
       
   173 }
       
   174 
       
   175 static inline void MakeBuoy(TileIndex t, StationID sid)
       
   176 {
       
   177 	MakeStation(t, OWNER_NONE, sid, BUOY_BASE);
       
   178 }
       
   179 
       
   180 static inline void MakeDock(TileIndex t, Owner o, StationID sid, DiagDirection d)
       
   181 {
       
   182 	MakeStation(t, o, sid, DOCK_BASE + d);
       
   183 	MakeStation(t + TileOffsByDir(d), o, sid, DOCK_BASE_WATER_PART + DiagDirToAxis(d));
       
   184 }
       
   185 
       
   186 static inline void MakeOilrig(TileIndex t, StationID sid)
       
   187 {
       
   188 	MakeStation(t, OWNER_NONE, sid, OILRIG_BASE);
       
   189 }
       
   190 
       
   191 #endif