From cc5f17561571b45b52e7406fb66051446f8cceb4 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Sun, 10 Mar 2019 09:12:47 +0100 Subject: Feature: Railtype flags to allow/disallow 90 degree curves. (#7352) --- src/rail.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/rail.h') diff --git a/src/rail.h b/src/rail.h index eec87bfb3..ac5805d09 100644 --- a/src/rail.h +++ b/src/rail.h @@ -21,6 +21,7 @@ #include "strings_type.h" #include "date_type.h" #include "signal_type.h" +#include "settings_type.h" /** Railtype flags. */ enum RailTypeFlags { @@ -28,12 +29,16 @@ enum RailTypeFlags { RTF_NO_LEVEL_CROSSING = 1, ///< Bit number for disallowing level crossings. RTF_HIDDEN = 2, ///< Bit number for hiding from selection. RTF_NO_SPRITE_COMBINE = 3, ///< Bit number for using non-combined junctions. + RTF_ALLOW_90DEG = 4, ///< Bit number for always allowed 90 degree turns, regardless of setting. + RTF_DISALLOW_90DEG = 5, ///< Bit number for never allowed 90 degree turns, regardless of setting. RTFB_NONE = 0, ///< All flags cleared. RTFB_CATENARY = 1 << RTF_CATENARY, ///< Value for drawing a catenary. RTFB_NO_LEVEL_CROSSING = 1 << RTF_NO_LEVEL_CROSSING, ///< Value for disallowing level crossings. RTFB_HIDDEN = 1 << RTF_HIDDEN, ///< Value for hiding from selection. RTFB_NO_SPRITE_COMBINE = 1 << RTF_NO_SPRITE_COMBINE, ///< Value for using non-combined junctions. + RTFB_ALLOW_90DEG = 1 << RTF_ALLOW_90DEG, ///< Value for always allowed 90 degree turns, regardless of setting. + RTFB_DISALLOW_90DEG = 1 << RTF_DISALLOW_90DEG, ///< Value for never allowed 90 degree turns, regardless of setting. }; DECLARE_ENUM_AS_BIT_SET(RailTypeFlags) @@ -341,6 +346,26 @@ static inline bool RailNoLevelCrossings(RailType rt) return HasBit(GetRailTypeInfo(rt)->flags, RTF_NO_LEVEL_CROSSING); } +/** + * Test if 90 degree turns are disallowed between two railtypes. + * @param rt1 First railtype to test for. + * @param rt2 Second railtype to test for. + * @param def Default value to use if the rail type doesn't specify anything. + * @return True if 90 degree turns are disallowed between the two rail types. + */ +static inline bool Rail90DegTurnDisallowed(RailType rt1, RailType rt2, bool def = _settings_game.pf.forbid_90_deg) +{ + if (rt1 == INVALID_RAILTYPE || rt2 == INVALID_RAILTYPE) return def; + + const RailtypeInfo *rti1 = GetRailTypeInfo(rt1); + const RailtypeInfo *rti2 = GetRailTypeInfo(rt2); + + bool rt1_90deg = HasBit(rti1->flags, RTF_DISALLOW_90DEG) || (!HasBit(rti1->flags, RTF_ALLOW_90DEG) && def); + bool rt2_90deg = HasBit(rti2->flags, RTF_DISALLOW_90DEG) || (!HasBit(rti2->flags, RTF_ALLOW_90DEG) && def); + + return rt1_90deg || rt2_90deg; +} + /** * Returns the cost of building the specified railtype. * @param railtype The railtype being built. -- cgit v1.2.3-54-g00ecf