Files @ r4381:c965d1f3016a
Branch filter:

Location: cpp/openttd-patchpack/source/road_map.h - annotation

belugas
(svn r6131) -Codechange : Complete all missing _ttdpatch_flags entries
-Feature : both unifiedmaglevmode are now set.
Maglev and monorail are not allowed to run on each other tracks and will not be.
Setting those flags will allow grfsets as the Norvegian one to be loaded
-Codechange : link the TTDPatch's irregularstations with OTTD's nonuniform_stations
-Codechange : Reformat the whole array (thanks Rubidium, it sure looks better now)
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3145:90ae47e0a047
r3145:90ae47e0a047
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3518:098862dff341
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3146:b3862f32db0e
r3793:c42788f521bd
r3793:c42788f521bd
r3793:c42788f521bd
r3793:c42788f521bd
r3793:c42788f521bd
r3369:c4df9e1f62cd
r3793:c42788f521bd
r3144:5b175fed4b0b
r3369:c4df9e1f62cd
r4000:702cb45b8eab
r3150:6242a630abac
r3150:6242a630abac
r3497:da55a80fd9e2
r3497:da55a80fd9e2
r3793:c42788f521bd
r3497:da55a80fd9e2
r3497:da55a80fd9e2
r3560:ad5e3e34a211
r3560:ad5e3e34a211
r3560:ad5e3e34a211
r3560:ad5e3e34a211
r3150:6242a630abac
r3369:c4df9e1f62cd
r3369:c4df9e1f62cd
r3793:c42788f521bd
r4000:702cb45b8eab
r3369:c4df9e1f62cd
r3369:c4df9e1f62cd
r3369:c4df9e1f62cd
r3272:c4b59db11c94
r3793:c42788f521bd
r3369:c4df9e1f62cd
r3369:c4df9e1f62cd
r3369:c4df9e1f62cd
r3369:c4df9e1f62cd
r3369:c4df9e1f62cd
r3369:c4df9e1f62cd
r3793:c42788f521bd
r3369:c4df9e1f62cd
r3272:c4b59db11c94
r3272:c4b59db11c94
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3272:c4b59db11c94
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r4158:e34ff2424478
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3274:40dbd1d25717
r3274:40dbd1d25717
r3274:40dbd1d25717
r3793:c42788f521bd
r3274:40dbd1d25717
r3274:40dbd1d25717
r3274:40dbd1d25717
r3274:40dbd1d25717
r3274:40dbd1d25717
r3793:c42788f521bd
r3274:40dbd1d25717
r3274:40dbd1d25717
r3274:40dbd1d25717
r3322:fcb97823ac14
r3322:fcb97823ac14
r3793:c42788f521bd
r3322:fcb97823ac14
r3322:fcb97823ac14
r3322:fcb97823ac14
r3322:fcb97823ac14
r3322:fcb97823ac14
r3793:c42788f521bd
r3322:fcb97823ac14
r3322:fcb97823ac14
r3322:fcb97823ac14
r3322:fcb97823ac14
r3322:fcb97823ac14
r3793:c42788f521bd
r3322:fcb97823ac14
r3322:fcb97823ac14
r3274:40dbd1d25717
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r4048:868b1ca92809
r4048:868b1ca92809
r4048:868b1ca92809
r4048:868b1ca92809
r4048:868b1ca92809
r4048:868b1ca92809
r4048:868b1ca92809
r4048:868b1ca92809
r4048:868b1ca92809
r3430:2572d70e8d09
r4048:868b1ca92809
r3430:2572d70e8d09
r4048:868b1ca92809
r3430:2572d70e8d09
r3430:2572d70e8d09
r4048:868b1ca92809
r3430:2572d70e8d09
r4048:868b1ca92809
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r4048:868b1ca92809
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r4048:868b1ca92809
r4048:868b1ca92809
r4048:868b1ca92809
r4048:868b1ca92809
r4045:30002db3574a
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r4048:868b1ca92809
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3430:2572d70e8d09
r3144:5b175fed4b0b
r3369:c4df9e1f62cd
r3144:5b175fed4b0b
r3793:c42788f521bd
r3369:c4df9e1f62cd
r3167:c678c9ca682c
r3167:c678c9ca682c
r3167:c678c9ca682c
r3146:b3862f32db0e
r3146:b3862f32db0e
r3146:b3862f32db0e
r3146:b3862f32db0e
r3146:b3862f32db0e
r3196:ee64b4658e65
r3146:b3862f32db0e
r3146:b3862f32db0e
r3146:b3862f32db0e
r3146:b3862f32db0e
r3146:b3862f32db0e
r3150:6242a630abac
r3150:6242a630abac
r3150:6242a630abac
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3793:c42788f521bd
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3793:c42788f521bd
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3793:c42788f521bd
r3144:5b175fed4b0b
r3144:5b175fed4b0b
r3144:5b175fed4b0b
/* $Id$ */

#ifndef ROAD_MAP_H
#define ROAD_MAP_H

#include "macros.h"
#include "rail.h"
#include "road.h"
#include "tile.h"


typedef enum RoadTileType {
	ROAD_TILE_NORMAL,
	ROAD_TILE_CROSSING,
	ROAD_TILE_DEPOT
} RoadTileType;

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].m3;
}

static inline void SetCrossingRoadOwner(TileIndex t, Owner o)
{
	assert(GetRoadTileType(t) == ROAD_TILE_CROSSING);
	_m[t].m3 = 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].m4, 7);
}

#define ToggleDesert ToggleSnow
static inline void ToggleSnow(TileIndex t)
{
	TOGGLEBIT(_m[t].m4, 7);
}


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;

static inline Roadside GetRoadside(TileIndex tile)
{
	return (Roadside)GB(_m[tile].m4, 4, 3);
}

static inline void SetRoadside(TileIndex tile, Roadside s)
{
	SB(_m[tile].m4, 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].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 */
	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].m4, 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 behavior:
 * - 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
 */
RoadBits GetAnyRoadBits(TileIndex);


TrackBits GetAnyRoadTrackBits(TileIndex tile);


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;
	_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 = road;
	_m[t].m4 = 0 << 7 | 0 << 4 | rt;
	_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