Feature: Railtype flags to allow/disallow 90 degree curves. (#7352)

This commit is contained in:
Michael Lutz
2019-03-10 09:12:47 +01:00
committed by PeterN
parent 26b0615c47
commit cc5f175615
5 changed files with 43 additions and 15 deletions

View File

@@ -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.