2006-02-23 08:20:28 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2006-03-05 11:18:34 +00:00
|
|
|
#ifndef ROAD_MAP_H
|
|
|
|
#define ROAD_MAP_H
|
2006-02-23 08:20:28 +00:00
|
|
|
|
|
|
|
#include "macros.h"
|
2006-02-28 21:19:50 +00:00
|
|
|
#include "rail.h"
|
2006-04-12 05:26:36 +00:00
|
|
|
#include "road.h"
|
2006-02-28 21:19:50 +00:00
|
|
|
#include "tile.h"
|
2006-02-23 08:20:28 +00:00
|
|
|
|
2006-03-05 12:22:20 +00:00
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
typedef enum RoadTileType {
|
|
|
|
ROAD_TILE_NORMAL,
|
|
|
|
ROAD_TILE_CROSSING,
|
|
|
|
ROAD_TILE_DEPOT
|
|
|
|
} RoadTileType;
|
2006-03-30 09:29:01 +00:00
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
static inline RoadTileType GetRoadTileType(TileIndex t)
|
2006-03-30 09:29:01 +00:00
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_STREET));
|
2006-06-10 08:37:41 +00:00
|
|
|
return (RoadTileType)GB(_m[t].m5, 4, 4);
|
2006-03-30 09:29:01 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 20:38:59 +00:00
|
|
|
static inline bool IsLevelCrossing(TileIndex t)
|
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
return GetRoadTileType(t) == ROAD_TILE_CROSSING;
|
2006-04-10 20:38:59 +00:00
|
|
|
}
|
|
|
|
|
2006-04-15 20:07:42 +00:00
|
|
|
static inline bool IsLevelCrossingTile(TileIndex t)
|
|
|
|
{
|
|
|
|
return IsTileType(t, MP_STREET) && IsLevelCrossing(t);
|
|
|
|
}
|
2006-03-30 09:29:01 +00:00
|
|
|
|
|
|
|
static inline RoadBits GetRoadBits(TileIndex t)
|
2006-02-23 08:20:28 +00:00
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
assert(GetRoadTileType(t) == ROAD_TILE_NORMAL);
|
2006-06-10 08:37:41 +00:00
|
|
|
return (RoadBits)GB(_m[t].m5, 0, 4);
|
2006-02-23 08:20:28 +00:00
|
|
|
}
|
|
|
|
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline void SetRoadBits(TileIndex t, RoadBits r)
|
2006-03-06 13:11:08 +00:00
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
assert(GetRoadTileType(t) == ROAD_TILE_NORMAL); // XXX incomplete
|
2006-03-30 09:29:01 +00:00
|
|
|
SB(_m[t].m5, 0, 4, r);
|
2006-03-06 13:11:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline Axis GetCrossingRoadAxis(TileIndex t)
|
2006-03-19 17:15:33 +00:00
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
|
2006-03-30 09:29:01 +00:00
|
|
|
return (Axis)GB(_m[t].m5, 3, 1);
|
2006-03-19 17:15:33 +00:00
|
|
|
}
|
|
|
|
|
2006-02-23 11:53:48 +00:00
|
|
|
static inline RoadBits GetCrossingRoadBits(TileIndex tile)
|
|
|
|
{
|
2006-03-19 17:15:33 +00:00
|
|
|
return GetCrossingRoadAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y;
|
2006-02-23 11:53:48 +00:00
|
|
|
}
|
|
|
|
|
2006-03-01 12:31:39 +00:00
|
|
|
static inline TrackBits GetCrossingRailBits(TileIndex tile)
|
|
|
|
{
|
2006-07-22 08:59:52 +00:00
|
|
|
return AxisToTrackBits(OtherAxis(GetCrossingRoadAxis(tile)));
|
2006-03-01 12:31:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-19 19:33:19 +00:00
|
|
|
// TODO swap owner of road and rail
|
|
|
|
static inline Owner GetCrossingRoadOwner(TileIndex t)
|
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
|
2006-03-19 19:33:19 +00:00
|
|
|
return (Owner)_m[t].m3;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SetCrossingRoadOwner(TileIndex t, Owner o)
|
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
|
2006-03-19 19:33:19 +00:00
|
|
|
_m[t].m3 = o;
|
|
|
|
}
|
|
|
|
|
2006-03-24 15:24:16 +00:00
|
|
|
static inline void UnbarCrossing(TileIndex t)
|
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
|
2006-03-24 15:24:16 +00:00
|
|
|
CLRBIT(_m[t].m5, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void BarCrossing(TileIndex t)
|
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
|
2006-03-24 15:24:16 +00:00
|
|
|
SETBIT(_m[t].m5, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsCrossingBarred(TileIndex t)
|
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
|
2006-03-24 15:24:16 +00:00
|
|
|
return HASBIT(_m[t].m5, 2);
|
|
|
|
}
|
2006-03-19 19:33:19 +00:00
|
|
|
|
2006-04-03 13:35:19 +00:00
|
|
|
#define IsOnDesert IsOnSnow
|
|
|
|
static inline bool IsOnSnow(TileIndex t)
|
|
|
|
{
|
|
|
|
return HASBIT(_m[t].m4, 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ToggleDesert ToggleSnow
|
|
|
|
static inline void ToggleSnow(TileIndex t)
|
|
|
|
{
|
|
|
|
TOGGLEBIT(_m[t].m4, 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-19 20:13:50 +00:00
|
|
|
typedef 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
|
|
|
|
} Roadside;
|
2006-04-03 13:35:19 +00:00
|
|
|
|
2006-06-19 20:13:50 +00:00
|
|
|
static inline Roadside GetRoadside(TileIndex tile)
|
2006-04-03 13:35:19 +00:00
|
|
|
{
|
2006-06-19 20:13:50 +00:00
|
|
|
return (Roadside)GB(_m[tile].m4, 4, 3);
|
2006-04-03 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
2006-06-19 20:13:50 +00:00
|
|
|
static inline void SetRoadside(TileIndex tile, Roadside s)
|
2006-04-03 13:35:19 +00:00
|
|
|
{
|
2006-06-19 20:13:50 +00:00
|
|
|
SB(_m[tile].m4, 4, 3, s);
|
2006-04-03 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool HasRoadWorks(TileIndex t)
|
|
|
|
{
|
2006-06-19 20:13:50 +00:00
|
|
|
return GetRoadside(t) >= ROADSIDE_GRASS_ROAD_WORKS;
|
2006-04-03 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IncreaseRoadWorksCounter(TileIndex t)
|
|
|
|
{
|
|
|
|
AB(_m[t].m4, 0, 4, 1);
|
|
|
|
|
|
|
|
return GB(_m[t].m4, 0, 4) == 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void StartRoadWorks(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(!HasRoadWorks(t));
|
|
|
|
/* Remove any trees or lamps in case or roadwork */
|
2006-06-19 20:13:50 +00:00
|
|
|
switch (GetRoadside(t)) {
|
|
|
|
case ROADSIDE_BARREN:
|
|
|
|
case ROADSIDE_GRASS: SetRoadside(t, ROADSIDE_GRASS_ROAD_WORKS); break;
|
|
|
|
default: SetRoadside(t, ROADSIDE_PAVED_ROAD_WORKS); break;
|
2006-06-19 09:40:08 +00:00
|
|
|
}
|
2006-04-03 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void TerminateRoadWorks(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(HasRoadWorks(t));
|
2006-06-19 20:13:50 +00:00
|
|
|
SetRoadside(t, (Roadside)(GetRoadside(t) - ROADSIDE_GRASS_ROAD_WORKS + ROADSIDE_GRASS));
|
2006-04-03 13:35:19 +00:00
|
|
|
/* Stop the counter */
|
|
|
|
SB(_m[t].m4, 0, 4, 0);
|
|
|
|
}
|
|
|
|
|
2006-02-28 21:19:50 +00:00
|
|
|
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline DiagDirection GetRoadDepotDirection(TileIndex t)
|
2006-03-08 15:29:23 +00:00
|
|
|
{
|
2006-05-09 08:25:31 +00:00
|
|
|
assert(GetRoadTileType(t) == ROAD_TILE_DEPOT);
|
2006-03-30 09:29:01 +00:00
|
|
|
return (DiagDirection)GB(_m[t].m5, 0, 2);
|
2006-03-08 15:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-05 12:22:20 +00:00
|
|
|
/**
|
|
|
|
* Returns the RoadBits on an arbitrary tile
|
|
|
|
* Special behavior:
|
|
|
|
* - road depots: entrance is treated as road piece
|
|
|
|
* - road tunnels: entrance is treated as road piece
|
2006-03-14 12:00:11 +00:00
|
|
|
* - bridge ramps: start of the ramp is treated as road piece
|
2006-03-05 12:22:20 +00:00
|
|
|
* - bridge middle parts: bridge itself is ignored
|
|
|
|
*/
|
|
|
|
RoadBits GetAnyRoadBits(TileIndex);
|
|
|
|
|
|
|
|
|
2006-03-06 13:11:08 +00:00
|
|
|
TrackBits GetAnyRoadTrackBits(TileIndex tile);
|
|
|
|
|
|
|
|
|
2006-02-28 21:19:50 +00:00
|
|
|
static inline void MakeRoadNormal(TileIndex t, Owner owner, RoadBits bits, uint town)
|
|
|
|
{
|
|
|
|
SetTileType(t, MP_STREET);
|
|
|
|
SetTileOwner(t, owner);
|
|
|
|
_m[t].m2 = town;
|
|
|
|
_m[t].m3 = 0;
|
|
|
|
_m[t].m4 = 0 << 7 | 0 << 4 | 0;
|
2006-05-09 08:25:31 +00:00
|
|
|
_m[t].m5 = ROAD_TILE_NORMAL << 4 | bits;
|
2006-02-28 21:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 = road;
|
|
|
|
_m[t].m4 = 0 << 7 | 0 << 4 | rt;
|
2006-05-09 08:25:31 +00:00
|
|
|
_m[t].m5 = ROAD_TILE_CROSSING << 4 | roaddir << 3 | 0 << 2;
|
2006-02-28 21:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
2006-05-09 08:25:31 +00:00
|
|
|
_m[t].m5 = ROAD_TILE_DEPOT << 4 | dir;
|
2006-02-28 21:19:50 +00:00
|
|
|
}
|
|
|
|
|
2006-02-23 08:20:28 +00:00
|
|
|
#endif
|