2006-02-23 08:20:28 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file road_map.h Map accessors for roads. */
|
2007-03-28 20:41:35 +00:00
|
|
|
|
2006-03-05 11:18:34 +00:00
|
|
|
#ifndef ROAD_MAP_H
|
|
|
|
#define ROAD_MAP_H
|
2006-02-23 08:20:28 +00:00
|
|
|
|
2007-12-18 20:10:21 +00:00
|
|
|
#include "track_func.h"
|
|
|
|
#include "rail_type.h"
|
2008-01-07 14:02:26 +00:00
|
|
|
#include "town_type.h"
|
2007-12-18 20:38:16 +00:00
|
|
|
#include "road_func.h"
|
2007-12-19 23:26:02 +00:00
|
|
|
#include "tile_map.h"
|
2006-02-23 08:20:28 +00:00
|
|
|
|
2006-03-05 12:22:20 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum RoadTileType {
|
2006-05-09 08:25:31 +00:00
|
|
|
ROAD_TILE_NORMAL,
|
|
|
|
ROAD_TILE_CROSSING,
|
|
|
|
ROAD_TILE_DEPOT
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-03-30 09:29:01 +00:00
|
|
|
|
2006-05-09 08:25:31 +00:00
|
|
|
static inline RoadTileType GetRoadTileType(TileIndex t)
|
2008-02-10 18:31:33 +00:00
|
|
|
{
|
2007-07-29 23:42:59 +00:00
|
|
|
assert(IsTileType(t, MP_ROAD));
|
2007-05-20 19:14:08 +00:00
|
|
|
return (RoadTileType)GB(_m[t].m5, 6, 2);
|
2006-03-30 09:29:01 +00:00
|
|
|
}
|
|
|
|
|
2008-02-14 15:59:16 +00:00
|
|
|
static inline bool IsNormalRoad(TileIndex t)
|
|
|
|
{
|
|
|
|
return GetRoadTileType(t) == ROAD_TILE_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsNormalRoadTile(TileIndex t)
|
|
|
|
{
|
|
|
|
return IsTileType(t, MP_ROAD) && IsNormalRoad(t);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2007-07-29 23:42:59 +00:00
|
|
|
return IsTileType(t, MP_ROAD) && IsLevelCrossing(t);
|
2006-04-15 20:07:42 +00:00
|
|
|
}
|
2006-03-30 09:29:01 +00:00
|
|
|
|
2008-02-14 15:59:16 +00:00
|
|
|
static inline bool IsRoadDepot(TileIndex t)
|
|
|
|
{
|
|
|
|
return GetRoadTileType(t) == ROAD_TILE_DEPOT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsRoadDepotTile(TileIndex t)
|
|
|
|
{
|
|
|
|
return IsTileType(t, MP_ROAD) && IsRoadDepot(t);
|
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline RoadBits GetRoadBits(TileIndex t, RoadType rt)
|
2006-02-23 08:20:28 +00:00
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
assert(IsNormalRoad(t));
|
2007-05-20 19:14:08 +00:00
|
|
|
switch (rt) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case ROADTYPE_ROAD: return (RoadBits)GB(_m[t].m4, 0, 4);
|
|
|
|
case ROADTYPE_TRAM: return (RoadBits)GB(_m[t].m4, 4, 4);
|
|
|
|
case ROADTYPE_HWAY: return (RoadBits)GB(_m[t].m6, 2, 4);
|
|
|
|
}
|
2006-02-23 08:20:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-27 14:26:31 +00:00
|
|
|
/**
|
|
|
|
* Get all RoadBits set on a tile except from the given RoadType
|
|
|
|
*
|
|
|
|
* @param t The tile from which we want to get the RoadBits
|
|
|
|
* @param rt The RoadType which we exclude from the querry
|
|
|
|
* @return all set RoadBits of the tile which are not from the given RoadType
|
|
|
|
*/
|
|
|
|
static inline RoadBits GetOtherRoadBits(TileIndex t, RoadType rt)
|
|
|
|
{
|
|
|
|
return ((rt == ROADTYPE_ROAD) ? ROAD_NONE : GetRoadBits(t, ROADTYPE_ROAD)) |
|
|
|
|
((rt == ROADTYPE_TRAM) ? ROAD_NONE : GetRoadBits(t, ROADTYPE_TRAM)) |
|
|
|
|
((rt == ROADTYPE_HWAY) ? ROAD_NONE : GetRoadBits(t, ROADTYPE_HWAY));
|
|
|
|
}
|
|
|
|
|
2008-03-25 18:59:25 +00:00
|
|
|
/**
|
|
|
|
* Get all set RoadBits on the given tile
|
|
|
|
*
|
|
|
|
* @param tile The tile from which we want to get the RoadBits
|
|
|
|
* @return all set RoadBits of the tile
|
|
|
|
*/
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline RoadBits GetAllRoadBits(TileIndex tile)
|
2006-03-06 13:11:08 +00:00
|
|
|
{
|
2007-05-20 19:14:08 +00:00
|
|
|
return GetRoadBits(tile, ROADTYPE_ROAD) | GetRoadBits(tile, ROADTYPE_TRAM) | GetRoadBits(tile, ROADTYPE_HWAY);
|
2006-03-06 13:11:08 +00:00
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline void SetRoadBits(TileIndex t, RoadBits r, RoadType rt)
|
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
assert(IsNormalRoad(t)); // XXX incomplete
|
2007-05-20 19:14:08 +00:00
|
|
|
switch (rt) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case ROADTYPE_ROAD: SB(_m[t].m4, 0, 4, r); break;
|
|
|
|
case ROADTYPE_TRAM: SB(_m[t].m4, 4, 4, r); break;
|
|
|
|
case ROADTYPE_HWAY: SB(_m[t].m6, 2, 4, r); break;
|
|
|
|
}
|
|
|
|
}
|
2006-03-06 13:11:08 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline RoadTypes GetRoadTypes(TileIndex t)
|
2006-03-19 17:15:33 +00:00
|
|
|
{
|
2007-07-29 23:42:59 +00:00
|
|
|
if (IsTileType(t, MP_ROAD)) {
|
2007-05-20 19:14:08 +00:00
|
|
|
return (RoadTypes)GB(_me[t].m7, 5, 3);
|
|
|
|
} else {
|
|
|
|
return (RoadTypes)GB(_m[t].m3, 0, 3);
|
|
|
|
}
|
2006-03-19 17:15:33 +00:00
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline void SetRoadTypes(TileIndex t, RoadTypes rt)
|
2006-02-23 11:53:48 +00:00
|
|
|
{
|
2007-07-29 23:42:59 +00:00
|
|
|
if (IsTileType(t, MP_ROAD)) {
|
2007-05-20 19:14:08 +00:00
|
|
|
SB(_me[t].m7, 5, 3, rt);
|
|
|
|
} else {
|
|
|
|
assert(IsTileType(t, MP_STATION) || IsTileType(t, MP_TUNNELBRIDGE));
|
|
|
|
SB(_m[t].m3, 0, 2, rt);
|
|
|
|
}
|
2006-02-23 11:53:48 +00:00
|
|
|
}
|
|
|
|
|
2008-02-14 15:59:16 +00:00
|
|
|
static inline bool HasTileRoadType(TileIndex t, RoadType rt)
|
|
|
|
{
|
|
|
|
return HasBit(GetRoadTypes(t), rt);
|
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline Owner GetRoadOwner(TileIndex t, RoadType rt)
|
2006-03-01 12:31:39 +00:00
|
|
|
{
|
2007-07-29 23:42:59 +00:00
|
|
|
if (!IsTileType(t, MP_ROAD)) return GetTileOwner(t);
|
2007-05-20 19:14:08 +00:00
|
|
|
|
|
|
|
switch (GetRoadTileType(t)) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case ROAD_TILE_NORMAL:
|
|
|
|
switch (rt) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case ROADTYPE_ROAD: return (Owner)GB( _m[t].m1, 0, 5);
|
2007-05-31 15:15:00 +00:00
|
|
|
case ROADTYPE_TRAM: {
|
|
|
|
/* Trams don't need OWNER_TOWN, and remapping OWNER_NONE
|
|
|
|
* to OWNER_TOWN makes it use one bit less */
|
|
|
|
Owner o = (Owner)GB( _m[t].m5, 0, 4);
|
|
|
|
return o == OWNER_TOWN ? OWNER_NONE : o;
|
|
|
|
}
|
2007-05-20 19:14:08 +00:00
|
|
|
case ROADTYPE_HWAY: return (Owner)GB(_me[t].m7, 0, 5);
|
|
|
|
}
|
|
|
|
case ROAD_TILE_CROSSING:
|
|
|
|
switch (rt) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case ROADTYPE_ROAD: return (Owner)GB( _m[t].m4, 0, 5);
|
2007-05-31 15:15:00 +00:00
|
|
|
case ROADTYPE_TRAM: {
|
|
|
|
/* Trams don't need OWNER_TOWN, and remapping OWNER_NONE
|
|
|
|
* to OWNER_TOWN makes it use one bit less */
|
|
|
|
Owner o = (Owner)GB( _m[t].m5, 0, 4);
|
|
|
|
return o == OWNER_TOWN ? OWNER_NONE : o;
|
|
|
|
}
|
2007-05-20 19:14:08 +00:00
|
|
|
case ROADTYPE_HWAY: return (Owner)GB(_me[t].m7, 0, 5);
|
|
|
|
}
|
|
|
|
case ROAD_TILE_DEPOT: return GetTileOwner(t);
|
|
|
|
}
|
2006-03-01 12:31:39 +00:00
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline void SetRoadOwner(TileIndex t, RoadType rt, Owner o)
|
|
|
|
{
|
2007-07-29 23:42:59 +00:00
|
|
|
if (!IsTileType(t, MP_ROAD)) return SetTileOwner(t, o);
|
2007-05-20 19:14:08 +00:00
|
|
|
|
|
|
|
switch (GetRoadTileType(t)) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case ROAD_TILE_NORMAL:
|
|
|
|
switch (rt) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case ROADTYPE_ROAD: SB( _m[t].m1, 0, 5, o); break;
|
2007-05-31 15:15:00 +00:00
|
|
|
case ROADTYPE_TRAM: SB( _m[t].m5, 0, 4, o == OWNER_NONE ? OWNER_TOWN : o); break;
|
2007-05-20 19:14:08 +00:00
|
|
|
case ROADTYPE_HWAY: SB(_me[t].m7, 0, 5, o); break;
|
|
|
|
}
|
2007-05-20 22:04:24 +00:00
|
|
|
break;
|
2007-05-20 19:14:08 +00:00
|
|
|
case ROAD_TILE_CROSSING:
|
|
|
|
switch (rt) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case ROADTYPE_ROAD: SB( _m[t].m4, 0, 5, o); break;
|
2007-05-31 15:15:00 +00:00
|
|
|
/* Trams don't need OWNER_TOWN, and remapping OWNER_NONE
|
|
|
|
* to OWNER_TOWN makes it use one bit less */
|
|
|
|
case ROADTYPE_TRAM: SB( _m[t].m5, 0, 4, o == OWNER_NONE ? OWNER_TOWN : o); break;
|
2007-05-20 19:14:08 +00:00
|
|
|
case ROADTYPE_HWAY: SB(_me[t].m7, 0, 5, o); break;
|
|
|
|
}
|
2007-05-20 22:04:24 +00:00
|
|
|
break;
|
2007-05-20 19:14:08 +00:00
|
|
|
case ROAD_TILE_DEPOT: return SetTileOwner(t, o);
|
|
|
|
}
|
|
|
|
}
|
2006-03-01 12:31:39 +00:00
|
|
|
|
2008-05-24 19:36:20 +00:00
|
|
|
static inline bool IsRoadOwner(TileIndex t, RoadType rt, Owner o)
|
|
|
|
{
|
2008-11-18 22:43:59 +00:00
|
|
|
assert(HasTileRoadType(t, rt));
|
2008-05-24 19:36:20 +00:00
|
|
|
return (GetRoadOwner(t, rt) == o);
|
|
|
|
}
|
|
|
|
|
2008-11-18 22:43:59 +00:00
|
|
|
/** Checks if given tile has town owned road
|
|
|
|
* @param t tile to check
|
|
|
|
* @return true iff tile has road and the road is owned by a town
|
|
|
|
* @pre IsTileType(t, MP_ROAD)
|
|
|
|
*/
|
|
|
|
static inline bool HasTownOwnedRoad(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_ROAD));
|
|
|
|
return HasTileRoadType(t, ROADTYPE_ROAD) && IsRoadOwner(t, ROADTYPE_ROAD, OWNER_TOWN);
|
|
|
|
}
|
|
|
|
|
2007-05-31 15:15:00 +00:00
|
|
|
/** Which directions are disallowed ? */
|
|
|
|
enum DisallowedRoadDirections {
|
|
|
|
DRD_NONE, ///< None of the directions are disallowed
|
|
|
|
DRD_SOUTHBOUND, ///< All southbound traffic is disallowed
|
|
|
|
DRD_NORTHBOUND, ///< All northbound traffic is disallowed
|
|
|
|
DRD_BOTH, ///< All directions are disallowed
|
|
|
|
DRD_END
|
|
|
|
};
|
|
|
|
DECLARE_ENUM_AS_BIT_SET(DisallowedRoadDirections);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the disallowed directions
|
|
|
|
* @param t the tile to get the directions from
|
|
|
|
* @return the disallowed directions
|
|
|
|
*/
|
|
|
|
static inline DisallowedRoadDirections GetDisallowedRoadDirections(TileIndex t)
|
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
assert(IsNormalRoad(t));
|
2007-05-31 15:15:00 +00:00
|
|
|
return (DisallowedRoadDirections)GB(_m[t].m5, 4, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the disallowed directions
|
|
|
|
* @param t the tile to set the directions for
|
|
|
|
* @param drd the disallowed directions
|
|
|
|
*/
|
|
|
|
static inline void SetDisallowedRoadDirections(TileIndex t, DisallowedRoadDirections drd)
|
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
assert(IsNormalRoad(t));
|
2007-05-31 15:15:00 +00:00
|
|
|
assert(drd < DRD_END);
|
|
|
|
SB(_m[t].m5, 4, 2, drd);
|
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline Axis GetCrossingRoadAxis(TileIndex t)
|
2006-03-19 19:33:19 +00:00
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
assert(IsLevelCrossing(t));
|
2007-05-20 19:14:08 +00:00
|
|
|
return (Axis)GB(_m[t].m4, 6, 1);
|
2006-03-19 19:33:19 +00:00
|
|
|
}
|
|
|
|
|
2008-02-18 18:35:36 +00:00
|
|
|
static inline Axis GetCrossingRailAxis(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsLevelCrossing(t));
|
|
|
|
return OtherAxis((Axis)GetCrossingRoadAxis(t));
|
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline RoadBits GetCrossingRoadBits(TileIndex tile)
|
2006-03-19 19:33:19 +00:00
|
|
|
{
|
2007-05-20 19:14:08 +00:00
|
|
|
return GetCrossingRoadAxis(tile) == AXIS_X ? ROAD_X : ROAD_Y;
|
|
|
|
}
|
|
|
|
|
2008-02-18 18:35:36 +00:00
|
|
|
static inline Track GetCrossingRailTrack(TileIndex tile)
|
|
|
|
{
|
|
|
|
return AxisToTrack(GetCrossingRailAxis(tile));
|
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline TrackBits GetCrossingRailBits(TileIndex tile)
|
|
|
|
{
|
2008-02-18 18:35:36 +00:00
|
|
|
return AxisToTrackBits(GetCrossingRailAxis(tile));
|
2006-03-19 19:33:19 +00:00
|
|
|
}
|
|
|
|
|
2008-08-02 22:47:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the reservation state of the rail crossing
|
|
|
|
* @pre IsLevelCrossingTile(t)
|
|
|
|
* @param t the crossing tile
|
|
|
|
* @return reservation state
|
|
|
|
*/
|
|
|
|
static inline bool GetCrossingReservation(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsLevelCrossingTile(t));
|
|
|
|
return HasBit(_m[t].m5, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the reservation state of the rail crossing
|
|
|
|
* @note Works for both waypoints and rail depots
|
|
|
|
* @pre IsLevelCrossingTile(t)
|
|
|
|
* @param t the crossing tile
|
|
|
|
* @param b the reservation state
|
|
|
|
*/
|
|
|
|
static inline void SetCrossingReservation(TileIndex t, bool b)
|
|
|
|
{
|
|
|
|
assert(IsLevelCrossingTile(t));
|
|
|
|
SB(_m[t].m5, 4, 1, b ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the reserved track bits for a rail crossing
|
|
|
|
* @pre IsLevelCrossingTile(t)
|
|
|
|
* @param t the tile
|
|
|
|
* @return reserved track bits
|
|
|
|
*/
|
|
|
|
static inline TrackBits GetRailCrossingReservation(TileIndex t)
|
|
|
|
{
|
|
|
|
return GetCrossingReservation(t) ? GetCrossingRailBits(t) : TRACK_BIT_NONE;
|
|
|
|
}
|
|
|
|
|
2008-01-17 20:41:33 +00:00
|
|
|
static inline bool IsCrossingBarred(TileIndex t)
|
2006-03-24 15:24:16 +00:00
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
assert(IsLevelCrossing(t));
|
2008-01-17 20:41:33 +00:00
|
|
|
return HasBit(_m[t].m4, 5);
|
2006-03-24 15:24:16 +00:00
|
|
|
}
|
|
|
|
|
2008-01-17 20:41:33 +00:00
|
|
|
static inline void SetCrossingBarred(TileIndex t, bool barred)
|
2006-03-24 15:24:16 +00:00
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
assert(IsLevelCrossing(t));
|
2008-01-17 20:41:33 +00:00
|
|
|
SB(_m[t].m4, 5, 1, barred);
|
2006-03-24 15:24:16 +00:00
|
|
|
}
|
|
|
|
|
2008-01-17 20:41:33 +00:00
|
|
|
static inline void UnbarCrossing(TileIndex t)
|
2006-03-24 15:24:16 +00:00
|
|
|
{
|
2008-01-17 20:41:33 +00:00
|
|
|
SetCrossingBarred(t, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void BarCrossing(TileIndex t)
|
|
|
|
{
|
|
|
|
SetCrossingBarred(t, true);
|
2006-03-24 15:24:16 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2007-11-19 21:02:30 +00:00
|
|
|
return HasBit(_m[t].m3, 7);
|
2006-04-03 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define ToggleDesert ToggleSnow
|
|
|
|
static inline void ToggleSnow(TileIndex t)
|
|
|
|
{
|
2007-11-20 14:11:19 +00:00
|
|
|
ToggleBit(_m[t].m3, 7);
|
2006-04-03 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum Roadside {
|
2006-06-19 20:13:50 +00:00
|
|
|
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
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
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
|
|
|
{
|
2007-02-27 23:36:28 +00:00
|
|
|
return (Roadside)GB(_m[tile].m3, 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
|
|
|
{
|
2007-02-27 23:36:28 +00:00
|
|
|
SB(_m[tile].m3, 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)
|
|
|
|
{
|
2007-02-27 23:36:28 +00:00
|
|
|
AB(_m[t].m3, 0, 4, 1);
|
2006-04-03 13:35:19 +00:00
|
|
|
|
2007-02-27 23:36:28 +00:00
|
|
|
return GB(_m[t].m3, 0, 4) == 15;
|
2006-04-03 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2007-02-27 23:36:28 +00:00
|
|
|
SB(_m[t].m3, 0, 4, 0);
|
2006-04-03 13:35:19 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-02-14 15:59:16 +00:00
|
|
|
assert(IsRoadDepot(t));
|
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
|
2007-03-28 20:06:28 +00:00
|
|
|
* Special behaviour:
|
2006-03-05 12:22:20 +00:00
|
|
|
* - 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
|
2008-03-22 10:56:08 +00:00
|
|
|
*
|
|
|
|
* If straight_tunnel_bridge_entrance is set a ROAD_X or ROAD_Y
|
|
|
|
* for bridge ramps and tunnel entrances is returned depending
|
|
|
|
* on the orientation of the tunnel or bridge.
|
2007-04-03 21:51:40 +00:00
|
|
|
* @param tile the tile to get the road bits for
|
2007-05-20 19:14:08 +00:00
|
|
|
* @param rt the road type to get the road bits form
|
2008-03-22 10:56:08 +00:00
|
|
|
* @param stbe whether to return straight road bits for tunnels/bridges.
|
2007-04-03 21:51:40 +00:00
|
|
|
* @return the road bits of the given tile
|
2006-03-05 12:22:20 +00:00
|
|
|
*/
|
2008-03-22 10:56:08 +00:00
|
|
|
RoadBits GetAnyRoadBits(TileIndex tile, RoadType rt, bool straight_tunnel_bridge_entrance = false);
|
2006-03-05 12:22:20 +00:00
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2007-05-20 19:14:08 +00:00
|
|
|
TrackBits GetAnyRoadTrackBits(TileIndex tile, RoadType rt);
|
2006-03-06 13:11:08 +00:00
|
|
|
|
2007-12-18 20:38:16 +00:00
|
|
|
/**
|
|
|
|
* Return if the tile is a valid tile for a crossing.
|
|
|
|
*
|
|
|
|
* @note function is overloaded
|
|
|
|
* @param tile the curent tile
|
|
|
|
* @param ax the axis of the road over the rail
|
|
|
|
* @return true if it is a valid tile
|
|
|
|
*/
|
|
|
|
bool IsPossibleCrossing(const TileIndex tile, Axis ax);
|
|
|
|
|
2006-03-06 13:11:08 +00:00
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline void MakeRoadNormal(TileIndex t, RoadBits bits, RoadTypes rot, TownID town, Owner road, Owner tram, Owner hway)
|
2006-02-28 21:19:50 +00:00
|
|
|
{
|
2007-07-29 23:42:59 +00:00
|
|
|
SetTileType(t, MP_ROAD);
|
2007-05-20 19:14:08 +00:00
|
|
|
SetTileOwner(t, road);
|
2006-02-28 21:19:50 +00:00
|
|
|
_m[t].m2 = town;
|
2007-05-20 19:14:08 +00:00
|
|
|
_m[t].m3 = 0;
|
2007-11-19 21:02:30 +00:00
|
|
|
_m[t].m4 = (HasBit(rot, ROADTYPE_TRAM) ? bits : 0) << 4 | (HasBit(rot, ROADTYPE_ROAD) ? bits : 0);
|
2007-06-01 17:58:43 +00:00
|
|
|
_m[t].m5 = ROAD_TILE_NORMAL << 6;
|
|
|
|
SetRoadOwner(t, ROADTYPE_TRAM, tram);
|
2007-11-19 21:02:30 +00:00
|
|
|
SB(_m[t].m6, 2, 4, HasBit(rot, ROADTYPE_HWAY) ? bits : 0);
|
2007-05-20 19:14:08 +00:00
|
|
|
_me[t].m7 = rot << 5 | hway;
|
2006-02-28 21:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
static inline void MakeRoadCrossing(TileIndex t, Owner road, Owner tram, Owner hway, Owner rail, Axis roaddir, RailType rat, RoadTypes rot, uint town)
|
2006-02-28 21:19:50 +00:00
|
|
|
{
|
2007-07-29 23:42:59 +00:00
|
|
|
SetTileType(t, MP_ROAD);
|
2006-02-28 21:19:50 +00:00
|
|
|
SetTileOwner(t, rail);
|
|
|
|
_m[t].m2 = town;
|
2007-05-20 19:14:08 +00:00
|
|
|
_m[t].m3 = rat;
|
|
|
|
_m[t].m4 = roaddir << 6 | road;
|
2007-06-01 17:58:43 +00:00
|
|
|
_m[t].m5 = ROAD_TILE_CROSSING << 6;
|
|
|
|
SetRoadOwner(t, ROADTYPE_TRAM, tram);
|
2007-05-20 19:14:08 +00:00
|
|
|
SB(_m[t].m6, 2, 4, 0);
|
|
|
|
_me[t].m7 = rot << 5 | hway;
|
2006-02-28 21:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-25 13:51:47 +00:00
|
|
|
static inline void MakeRoadDepot(TileIndex t, Owner owner, DiagDirection dir, RoadType rt, TownID town)
|
2006-02-28 21:19:50 +00:00
|
|
|
{
|
2007-07-29 23:42:59 +00:00
|
|
|
SetTileType(t, MP_ROAD);
|
2006-02-28 21:19:50 +00:00
|
|
|
SetTileOwner(t, owner);
|
2008-10-25 13:51:47 +00:00
|
|
|
_m[t].m2 = town;
|
2006-02-28 21:19:50 +00:00
|
|
|
_m[t].m3 = 0;
|
|
|
|
_m[t].m4 = 0;
|
2007-05-20 19:14:08 +00:00
|
|
|
_m[t].m5 = ROAD_TILE_DEPOT << 6 | dir;
|
|
|
|
SB(_m[t].m6, 2, 4, 0);
|
|
|
|
_me[t].m7 = RoadTypeToRoadTypes(rt) << 5;
|
2006-02-28 21:19:50 +00:00
|
|
|
}
|
|
|
|
|
2006-09-28 18:42:35 +00:00
|
|
|
#endif /* ROAD_MAP_H */
|