Files
@ r6625:be98aa2ee7c6
Branch filter:
Location: cpp/openttd-patchpack/source/src/road_map.h
r6625:be98aa2ee7c6
5.0 KiB
text/x-c
(svn r9845) -Fix (r9844): svn:eol-style/svn:keywords were missing...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | /* $Id$ */
/** @file road_map.h */
#ifndef ROAD_MAP_H
#define ROAD_MAP_H
#include "macros.h"
#include "rail.h"
#include "road.h"
#include "tile.h"
enum RoadTileType {
ROAD_TILE_NORMAL,
ROAD_TILE_CROSSING,
ROAD_TILE_DEPOT
};
static inline RoadTileType GetRoadTileType(TileIndex t)
{
assert(IsTileType(t, MP_STREET));
return (RoadTileType)GB(_m[t].m5, 4, 4);
}
static inline bool IsLevelCrossing(TileIndex t)
{
return GetRoadTileType(t) == ROAD_TILE_CROSSING;
}
static inline bool IsLevelCrossingTile(TileIndex t)
{
return IsTileType(t, MP_STREET) && IsLevelCrossing(t);
}
static inline RoadBits GetRoadBits(TileIndex t)
{
assert(GetRoadTileType(t) == ROAD_TILE_NORMAL);
return (RoadBits)GB(_m[t].m5, 0, 4);
}
static inline void SetRoadBits(TileIndex t, RoadBits r)
{
assert(GetRoadTileType(t) == ROAD_TILE_NORMAL); // XXX incomplete
SB(_m[t].m5, 0, 4, r);
}
static inline Axis GetCrossingRoadAxis(TileIndex t)
{
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
return (Axis)GB(_m[t].m5, 3, 1);
}
static inline RoadBits GetCrossingRoadBits(TileIndex tile)
{
return GetCrossingRoadAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y;
}
static inline TrackBits GetCrossingRailBits(TileIndex tile)
{
return AxisToTrackBits(OtherAxis(GetCrossingRoadAxis(tile)));
}
// TODO swap owner of road and rail
static inline Owner GetCrossingRoadOwner(TileIndex t)
{
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
return (Owner)_m[t].m4;
}
static inline void SetCrossingRoadOwner(TileIndex t, Owner o)
{
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
_m[t].m4 = o;
}
static inline void UnbarCrossing(TileIndex t)
{
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
CLRBIT(_m[t].m5, 2);
}
static inline void BarCrossing(TileIndex t)
{
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
SETBIT(_m[t].m5, 2);
}
static inline bool IsCrossingBarred(TileIndex t)
{
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
return HASBIT(_m[t].m5, 2);
}
#define IsOnDesert IsOnSnow
static inline bool IsOnSnow(TileIndex t)
{
return HASBIT(_m[t].m3, 7);
}
#define ToggleDesert ToggleSnow
static inline void ToggleSnow(TileIndex t)
{
TOGGLEBIT(_m[t].m3, 7);
}
enum Roadside {
ROADSIDE_BARREN = 0,
ROADSIDE_GRASS = 1,
ROADSIDE_PAVED = 2,
ROADSIDE_STREET_LIGHTS = 3,
ROADSIDE_TREES = 5,
ROADSIDE_GRASS_ROAD_WORKS = 6,
ROADSIDE_PAVED_ROAD_WORKS = 7
};
static inline Roadside GetRoadside(TileIndex tile)
{
return (Roadside)GB(_m[tile].m3, 4, 3);
}
static inline void SetRoadside(TileIndex tile, Roadside s)
{
SB(_m[tile].m3, 4, 3, s);
}
static inline bool HasRoadWorks(TileIndex t)
{
return GetRoadside(t) >= ROADSIDE_GRASS_ROAD_WORKS;
}
static inline bool IncreaseRoadWorksCounter(TileIndex t)
{
AB(_m[t].m3, 0, 4, 1);
return GB(_m[t].m3, 0, 4) == 15;
}
static inline void StartRoadWorks(TileIndex t)
{
assert(!HasRoadWorks(t));
/* Remove any trees or lamps in case or roadwork */
switch (GetRoadside(t)) {
case ROADSIDE_BARREN:
case ROADSIDE_GRASS: SetRoadside(t, ROADSIDE_GRASS_ROAD_WORKS); break;
default: SetRoadside(t, ROADSIDE_PAVED_ROAD_WORKS); break;
}
}
static inline void TerminateRoadWorks(TileIndex t)
{
assert(HasRoadWorks(t));
SetRoadside(t, (Roadside)(GetRoadside(t) - ROADSIDE_GRASS_ROAD_WORKS + ROADSIDE_GRASS));
/* Stop the counter */
SB(_m[t].m3, 0, 4, 0);
}
static inline DiagDirection GetRoadDepotDirection(TileIndex t)
{
assert(GetRoadTileType(t) == ROAD_TILE_DEPOT);
return (DiagDirection)GB(_m[t].m5, 0, 2);
}
/**
* Returns the RoadBits on an arbitrary tile
* Special behaviour:
* - road depots: entrance is treated as road piece
* - road tunnels: entrance is treated as road piece
* - bridge ramps: start of the ramp is treated as road piece
* - bridge middle parts: bridge itself is ignored
* @param tile the tile to get the road bits for
* @return the road bits of the given tile
*/
RoadBits GetAnyRoadBits(TileIndex tile);
/**
* Get the accessible track bits for the given tile.
* Special behaviour:
* - road depots: no track bits
* - non-drive-through stations: no track bits
* @param tile the tile to get the track bits for
* @return the track bits for the given tile
*/
TrackBits GetAnyRoadTrackBits(TileIndex tile);
static inline void MakeRoadNormal(TileIndex t, Owner owner, RoadBits bits, TownID town)
{
SetTileType(t, MP_STREET);
SetTileOwner(t, owner);
_m[t].m2 = town;
_m[t].m3 = 0 << 7 | 0 << 4 | 0;
_m[t].m4 = 0;
_m[t].m5 = ROAD_TILE_NORMAL << 4 | bits;
}
static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner rail, Axis roaddir, RailType rt, uint town)
{
SetTileType(t, MP_STREET);
SetTileOwner(t, rail);
_m[t].m2 = town;
_m[t].m3 = 0 << 7 | 0 << 4 | rt;
_m[t].m4 = road;
_m[t].m5 = ROAD_TILE_CROSSING << 4 | roaddir << 3 | 0 << 2;
}
static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir)
{
SetTileType(t, MP_STREET);
SetTileOwner(t, owner);
_m[t].m2 = 0;
_m[t].m3 = 0;
_m[t].m4 = 0;
_m[t].m5 = ROAD_TILE_DEPOT << 4 | dir;
}
#endif /* ROAD_MAP_H */
|