diff options
author | Michael Lutz <michi@icosahedron.de> | 2019-03-10 09:12:47 +0100 |
---|---|---|
committer | PeterN <peter@fuzzle.org> | 2019-03-10 08:12:47 +0000 |
commit | cc5f17561571b45b52e7406fb66051446f8cceb4 (patch) | |
tree | 2d5f5d0ffd8fd9495b0f82ae3b46196c9f38e192 /src/rail.h | |
parent | 26b0615c476039c43b4a845c6b01d590d1fb20dd (diff) | |
download | openttd-cc5f17561571b45b52e7406fb66051446f8cceb4.tar.xz |
Feature: Railtype flags to allow/disallow 90 degree curves. (#7352)
Diffstat (limited to 'src/rail.h')
-rw-r--r-- | src/rail.h | 25 |
1 files changed, 25 insertions, 0 deletions
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) @@ -342,6 +347,26 @@ static inline bool RailNoLevelCrossings(RailType rt) } /** + * 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. * @return The cost multiplier. |