2007-12-18 20:38:16 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/** @file road_func.h Functions related to roads. */
|
|
|
|
|
|
|
|
#ifndef ROAD_FUNC_H
|
|
|
|
#define ROAD_FUNC_H
|
|
|
|
|
2007-12-21 19:21:21 +00:00
|
|
|
#include "core/bitmath_func.hpp"
|
2007-12-18 20:38:16 +00:00
|
|
|
#include "road_type.h"
|
2007-12-25 23:42:52 +00:00
|
|
|
#include "direction_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_type.h"
|
2007-12-18 20:38:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the given roadtype is valid.
|
|
|
|
* @param rt the roadtype to check for validness
|
|
|
|
* @return true if and only if valid
|
|
|
|
*/
|
|
|
|
static inline bool IsValidRoadType(RoadType rt)
|
|
|
|
{
|
|
|
|
return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Are the given bits pointing to valid roadtypes?
|
|
|
|
* @param rts the roadtypes to check for validness
|
|
|
|
* @return true if and only if valid
|
|
|
|
*/
|
|
|
|
static inline bool AreValidRoadTypes(RoadTypes rts)
|
|
|
|
{
|
|
|
|
return HasBit(rts, ROADTYPE_ROAD) || HasBit(rts, ROADTYPE_TRAM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps a RoadType to the corresponding RoadTypes value
|
|
|
|
*
|
|
|
|
* @param rt the roadtype to get the roadtypes from
|
|
|
|
* @return the roadtypes with the given roadtype
|
|
|
|
*/
|
|
|
|
static inline RoadTypes RoadTypeToRoadTypes(RoadType rt)
|
|
|
|
{
|
|
|
|
return (RoadTypes)(1 << rt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the RoadTypes which are not present in the given RoadTypes
|
|
|
|
*
|
|
|
|
* This function returns the complement of a given RoadTypes.
|
|
|
|
*
|
|
|
|
* @param r The given RoadTypes
|
|
|
|
* @return The complement of the given RoadTypes
|
|
|
|
* @note The unused value ROADTYPES_HWAY will be used, too.
|
|
|
|
*/
|
|
|
|
static inline RoadTypes ComplementRoadTypes(RoadTypes r)
|
|
|
|
{
|
|
|
|
return (RoadTypes)(ROADTYPES_ALL ^ r);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the complement of a RoadBits value
|
|
|
|
*
|
|
|
|
* Simply flips all bits in the RoadBits value to get the complement
|
|
|
|
* of the RoadBits.
|
|
|
|
*
|
|
|
|
* @param r The given RoadBits value
|
|
|
|
* @return the complement
|
|
|
|
*/
|
|
|
|
static inline RoadBits ComplementRoadBits(RoadBits r)
|
|
|
|
{
|
|
|
|
return (RoadBits)(ROAD_ALL ^ r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the mirrored RoadBits
|
|
|
|
*
|
|
|
|
* Simply move the bits to their new position.
|
|
|
|
*
|
|
|
|
* @param r The given RoadBits value
|
|
|
|
* @return the mirrored
|
|
|
|
*/
|
|
|
|
static inline RoadBits MirrorRoadBits(RoadBits r)
|
|
|
|
{
|
|
|
|
return (RoadBits)(GB(r, 0, 2) << 2 | GB(r, 2, 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate rotated RoadBits
|
|
|
|
*
|
|
|
|
* Move the Roadbits clockwise til they are in their final position.
|
|
|
|
*
|
|
|
|
* @param r The given RoadBits value
|
|
|
|
* @param rot The given Rotation angle
|
|
|
|
* @return the rotated
|
|
|
|
*/
|
|
|
|
static inline RoadBits RotateRoadBits(RoadBits r, DiagDirDiff rot)
|
|
|
|
{
|
|
|
|
for (; rot > (DiagDirDiff)0; rot--){
|
|
|
|
r = (RoadBits)(GB(r, 0, 1) << 3 | GB(r, 1, 3));
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-03-25 18:59:25 +00:00
|
|
|
/**
|
|
|
|
* Check if we've got a straight road
|
|
|
|
*
|
|
|
|
* @param r The given RoadBits
|
|
|
|
* @return true if we've got a straight road
|
|
|
|
*/
|
|
|
|
static inline bool IsStraightRoad(RoadBits r)
|
|
|
|
{
|
|
|
|
return (r == ROAD_X || r == ROAD_Y);
|
|
|
|
}
|
|
|
|
|
2007-12-18 20:38:16 +00:00
|
|
|
/**
|
|
|
|
* Create the road-part which belongs to the given DiagDirection
|
|
|
|
*
|
|
|
|
* This function returns a RoadBits value which belongs to
|
|
|
|
* the given DiagDirection.
|
|
|
|
*
|
|
|
|
* @param d The DiagDirection
|
|
|
|
* @return The result RoadBits which the selected road-part set
|
|
|
|
*/
|
|
|
|
static inline RoadBits DiagDirToRoadBits(DiagDirection d)
|
|
|
|
{
|
|
|
|
return (RoadBits)(ROAD_NW << (3 ^ d));
|
|
|
|
}
|
|
|
|
|
2008-03-22 10:56:08 +00:00
|
|
|
/**
|
|
|
|
* Create the road-part which belongs to the given Axis
|
|
|
|
*
|
|
|
|
* This function returns a RoadBits value which belongs to
|
|
|
|
* the given Axis.
|
|
|
|
*
|
|
|
|
* @param a The Axis
|
|
|
|
* @return The result RoadBits which the selected road-part set
|
|
|
|
*/
|
|
|
|
static inline RoadBits AxisToRoadBits(Axis a)
|
|
|
|
{
|
|
|
|
return a == AXIS_X ? ROAD_X : ROAD_Y;
|
|
|
|
}
|
|
|
|
|
2008-01-09 21:05:03 +00:00
|
|
|
/**
|
2008-09-30 20:39:50 +00:00
|
|
|
* Finds out, whether given company has all given RoadTypes available
|
|
|
|
* @param company ID of company
|
2008-01-09 21:05:03 +00:00
|
|
|
* @param rts RoadTypes to test
|
2008-09-30 20:39:50 +00:00
|
|
|
* @return true if company has all requested RoadTypes available
|
2008-01-09 21:05:03 +00:00
|
|
|
*/
|
2008-09-30 20:39:50 +00:00
|
|
|
bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts);
|
2008-01-09 21:05:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate functions for rail building.
|
|
|
|
* @param rt road type to check.
|
2008-09-30 20:39:50 +00:00
|
|
|
* @return true if the current company may build the road.
|
2008-01-09 21:05:03 +00:00
|
|
|
*/
|
|
|
|
bool ValParamRoadType(const RoadType rt);
|
|
|
|
|
|
|
|
/**
|
2008-09-30 20:39:50 +00:00
|
|
|
* Get the road types the given company can build.
|
|
|
|
* @param company the company to get the roadtypes for.
|
2008-01-09 21:05:03 +00:00
|
|
|
* @return the road types.
|
|
|
|
*/
|
2008-09-30 20:39:50 +00:00
|
|
|
RoadTypes GetCompanyRoadtypes(const CompanyID company);
|
2008-01-09 21:05:03 +00:00
|
|
|
|
2008-01-17 20:41:33 +00:00
|
|
|
void UpdateLevelCrossing(TileIndex tile, bool sound = true);
|
2008-01-17 19:49:06 +00:00
|
|
|
|
2007-12-18 20:38:16 +00:00
|
|
|
#endif /* ROAD_FUNC_H */
|