tron@3069: /* $Id$ */ tron@3069: richk@6719: /** @file road.h */ richk@6719: tron@3518: #ifndef ROAD_H tron@3518: #define ROAD_H tron@3069: rubidium@5838: #include "helpers.hpp" rubidium@5838: richk@6719: /** richk@6719: * The different roadtypes we support richk@6719: * @note currently only ROADTYPE_ROAD is supported. richk@6719: */ richk@6719: enum RoadType { richk@6719: ROADTYPE_ROAD = 0, richk@6719: ROADTYPE_TRAM = 1, richk@6719: ROADTYPE_HWAY = 2, ///< Only a placeholder. Not sure what we are going to do with this road type. richk@6719: ROADTYPE_END, richk@6719: INVALID_ROADTYPE = 0xFF richk@6719: }; richk@6719: DECLARE_POSTFIX_INCREMENT(RoadType); richk@6719: richk@6719: /** richk@6719: * The different roadtypes we support, but then a bitmask of them richk@6719: * @note currently only ROADTYPES_ROAD is supported. richk@6719: */ richk@6719: enum RoadTypes { richk@6719: ROADTYPES_NONE = 0, richk@6719: ROADTYPES_ROAD = 1 << ROADTYPE_ROAD, richk@6719: ROADTYPES_TRAM = 1 << ROADTYPE_TRAM, richk@6719: ROADTYPES_HWAY = 1 << ROADTYPE_HWAY, richk@6719: ROADTYPES_ROADTRAM = ROADTYPES_ROAD | ROADTYPES_TRAM, richk@6719: ROADTYPES_ROADHWAY = ROADTYPES_ROAD | ROADTYPES_HWAY, richk@6719: ROADTYPES_TRAMHWAY = ROADTYPES_TRAM | ROADTYPES_HWAY, richk@6719: ROADTYPES_ALL = ROADTYPES_ROAD | ROADTYPES_TRAM | ROADTYPES_HWAY, richk@6719: }; richk@6719: DECLARE_ENUM_AS_BIT_SET(RoadTypes); richk@6719: richk@6719: /** richk@6719: * Whether the given roadtype is valid. richk@6719: * @param rt the roadtype to check for validness richk@6719: * @return true if and only if valid richk@6719: */ richk@6719: static inline bool IsValidRoadType(RoadType rt) richk@6719: { richk@6719: return rt == ROADTYPE_ROAD || rt == ROADTYPE_TRAM; richk@6719: } richk@6719: richk@6719: /** richk@6719: * Are the given bits pointing to valid roadtypes? richk@6719: * @param rts the roadtypes to check for validness richk@6719: * @return true if and only if valid richk@6719: */ richk@6719: static inline bool AreValidRoadTypes(RoadTypes rts) richk@6719: { richk@6719: return HASBIT(rts, ROADTYPE_ROAD) || HASBIT(rts, ROADTYPE_TRAM); richk@6719: } richk@6719: richk@6719: /** richk@6719: * Maps a RoadType to the corresponding RoadTypes value richk@6719: */ richk@6719: static inline RoadTypes RoadTypeToRoadTypes(RoadType rt) richk@6719: { richk@6719: return (RoadTypes)(1 << rt); richk@6719: } richk@6719: richk@6719: static inline RoadTypes ComplementRoadTypes(RoadTypes r) richk@6719: { richk@6719: return (RoadTypes)(ROADTYPES_ALL ^ r); richk@6719: } richk@6719: rubidium@6574: enum RoadBits { rubidium@5838: ROAD_NONE = 0U, peter1138@3795: ROAD_NW = 1U, peter1138@3795: ROAD_SW = 2U, peter1138@3795: ROAD_SE = 4U, peter1138@3795: ROAD_NE = 8U, tron@3069: ROAD_X = ROAD_SW | ROAD_NE, tron@3069: ROAD_Y = ROAD_NW | ROAD_SE, tron@3069: ROAD_ALL = ROAD_X | ROAD_Y rubidium@6574: }; tron@3069: rubidium@5838: DECLARE_ENUM_AS_BIT_SET(RoadBits); rubidium@5838: tron@3103: static inline RoadBits ComplementRoadBits(RoadBits r) tron@3103: { KUDr@3900: return (RoadBits)(ROAD_ALL ^ r); tron@3103: } tron@3103: tron@3146: static inline RoadBits DiagDirToRoadBits(DiagDirection d) tron@3146: { KUDr@3900: return (RoadBits)(1U << (3 ^ d)); tron@3146: } tron@3146: rubidium@6335: /** Checks whether the trackdir means that we are reversing */ rubidium@6335: static inline bool IsReversingRoadTrackdir(Trackdir dir) rubidium@6335: { rubidium@6335: return (dir & 0x07) >= 6; rubidium@6335: } rubidium@6335: rubidium@6335: /** Checks whether the given trackdir is a straight road */ rubidium@6335: static inline bool IsStraightRoadTrackdir(Trackdir dir) rubidium@6335: { rubidium@6335: return (dir & 0x06) == 0; rubidium@6335: } rubidium@6335: rubidium@6442: /** rubidium@6442: * Is it allowed to remove the given road bits from the given tile? rubidium@6442: * @param tile the tile to remove the road from rubidium@6442: * @param remove the roadbits that are going to be removed rubidium@6442: * @param owner the actual owner of the roadbits of the tile rubidium@6442: * @param edge_road are the removed bits from a town? richk@6719: * @param rt the road type to remove the bits from rubidium@6442: * @return true when it is allowed to remove the road bits rubidium@6442: */ richk@6719: bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, bool *edge_road, RoadType rt); richk@6719: richk@6719: void DrawTramCatenary(TileInfo *ti, RoadBits tram); rubidium@6442: peter1138@4666: #endif /* ROAD_H */