YAPF: Prevent user for configuring signal penalties to negative values
Warn if signal penalty polynomial goes negative, and clamp to non-negative
This commit is contained in:
@@ -70,8 +70,8 @@ protected:
|
|||||||
int p1 = Yapf().PfGetSettings().rail_look_ahead_signal_p1;
|
int p1 = Yapf().PfGetSettings().rail_look_ahead_signal_p1;
|
||||||
int p2 = Yapf().PfGetSettings().rail_look_ahead_signal_p2;
|
int p2 = Yapf().PfGetSettings().rail_look_ahead_signal_p2;
|
||||||
int *pen = m_sig_look_ahead_costs.GrowSizeNC(Yapf().PfGetSettings().rail_look_ahead_max_signals);
|
int *pen = m_sig_look_ahead_costs.GrowSizeNC(Yapf().PfGetSettings().rail_look_ahead_max_signals);
|
||||||
for (uint i = 0; i < Yapf().PfGetSettings().rail_look_ahead_max_signals; i++) {
|
for (int i = 0; i < (int) Yapf().PfGetSettings().rail_look_ahead_max_signals; i++) {
|
||||||
pen[i] = p0 + i * (p1 + i * p2);
|
pen[i] = max<int>(0, p0 + i * (p1 + i * p2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include "../../viewport_func.h"
|
#include "../../viewport_func.h"
|
||||||
#include "../../newgrf_station.h"
|
#include "../../newgrf_station.h"
|
||||||
#include "../../tracerestrict.h"
|
#include "../../tracerestrict.h"
|
||||||
|
#include "../../debug.h"
|
||||||
|
|
||||||
#include "../../safeguards.h"
|
#include "../../safeguards.h"
|
||||||
|
|
||||||
@@ -762,3 +763,18 @@ void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
|
|||||||
{
|
{
|
||||||
CSegmentCostCacheBase::NotifyTrackLayoutChange(tile, track);
|
CSegmentCostCacheBase::NotifyTrackLayoutChange(tile, track);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void YapfCheckRailSignalPenalties()
|
||||||
|
{
|
||||||
|
bool negative = false;
|
||||||
|
int p0 = _settings_game.pf.yapf.rail_look_ahead_signal_p0;
|
||||||
|
int p1 = _settings_game.pf.yapf.rail_look_ahead_signal_p1;
|
||||||
|
int p2 = _settings_game.pf.yapf.rail_look_ahead_signal_p2;
|
||||||
|
for (int i = 0; i < (int) _settings_game.pf.yapf.rail_look_ahead_max_signals; i++) {
|
||||||
|
if (p0 + i * (p1 + i * p2) < 0) negative = true;
|
||||||
|
}
|
||||||
|
if (negative) {
|
||||||
|
DEBUG(misc, 0, "Settings: pf.yapf.rail_look_ahead_signal_p0, pf.yapf.rail_look_ahead_signal_p1, pf.yapf.rail_look_ahead_signal_p2 and pf.yapf.rail_look_ahead_max_signal "
|
||||||
|
"are set to incorrect values (i.e. resulting in hegative penalties), negative penalties will be truncated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -3795,6 +3795,9 @@ bool AfterLoadGame()
|
|||||||
InvalidateVehicleTickCaches();
|
InvalidateVehicleTickCaches();
|
||||||
ClearVehicleTickCaches();
|
ClearVehicleTickCaches();
|
||||||
|
|
||||||
|
extern void YapfCheckRailSignalPenalties();
|
||||||
|
YapfCheckRailSignalPenalties();
|
||||||
|
|
||||||
/* Show this message last to avoid covering up an error message if we bail out part way */
|
/* Show this message last to avoid covering up an error message if we bail out part way */
|
||||||
switch (gcf_res) {
|
switch (gcf_res) {
|
||||||
case GLC_COMPATIBLE: ShowErrorMessage(STR_NEWGRF_COMPATIBLE_LOAD_WARNING, INVALID_STRING_ID, WL_CRITICAL); break;
|
case GLC_COMPATIBLE: ShowErrorMessage(STR_NEWGRF_COMPATIBLE_LOAD_WARNING, INVALID_STRING_ID, WL_CRITICAL); break;
|
||||||
|
@@ -1228,6 +1228,14 @@ static bool EnableSingleVehSharedOrderGuiChanged(int32)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool CheckYapfRailSignalPenalties(int32)
|
||||||
|
{
|
||||||
|
extern void YapfCheckRailSignalPenalties();
|
||||||
|
YapfCheckRailSignalPenalties();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/** Checks if any settings are set to incorrect values, and sets them to correct values in that case. */
|
/** Checks if any settings are set to incorrect values, and sets them to correct values in that case. */
|
||||||
static void ValidateSettings()
|
static void ValidateSettings()
|
||||||
{
|
{
|
||||||
|
@@ -47,6 +47,7 @@ static bool ImprovedBreakdownsSettingChanged(int32 p1);
|
|||||||
static bool DayLengthChanged(int32 p1);
|
static bool DayLengthChanged(int32 p1);
|
||||||
static bool SimulatedWormholeSignalsChanged(int32 p1);
|
static bool SimulatedWormholeSignalsChanged(int32 p1);
|
||||||
static bool EnableSingleVehSharedOrderGuiChanged(int32 p1);
|
static bool EnableSingleVehSharedOrderGuiChanged(int32 p1);
|
||||||
|
static bool CheckYapfRailSignalPenalties(int32 p1);
|
||||||
|
|
||||||
static bool UpdateClientName(int32 p1);
|
static bool UpdateClientName(int32 p1);
|
||||||
static bool UpdateServerPassword(int32 p1);
|
static bool UpdateServerPassword(int32 p1);
|
||||||
@@ -3078,6 +3079,7 @@ def = 10
|
|||||||
min = 1
|
min = 1
|
||||||
max = 100
|
max = 100
|
||||||
cat = SC_EXPERT
|
cat = SC_EXPERT
|
||||||
|
proc = CheckYapfRailSignalPenalties
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
base = GameSettings
|
base = GameSettings
|
||||||
@@ -3088,6 +3090,7 @@ def = 500
|
|||||||
min = -1000000
|
min = -1000000
|
||||||
max = 1000000
|
max = 1000000
|
||||||
cat = SC_EXPERT
|
cat = SC_EXPERT
|
||||||
|
proc = CheckYapfRailSignalPenalties
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
base = GameSettings
|
base = GameSettings
|
||||||
@@ -3098,6 +3101,7 @@ def = -100
|
|||||||
min = -1000000
|
min = -1000000
|
||||||
max = 1000000
|
max = 1000000
|
||||||
cat = SC_EXPERT
|
cat = SC_EXPERT
|
||||||
|
proc = CheckYapfRailSignalPenalties
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
base = GameSettings
|
base = GameSettings
|
||||||
@@ -3108,6 +3112,7 @@ def = 5
|
|||||||
min = -1000000
|
min = -1000000
|
||||||
max = 1000000
|
max = 1000000
|
||||||
cat = SC_EXPERT
|
cat = SC_EXPERT
|
||||||
|
proc = CheckYapfRailSignalPenalties
|
||||||
|
|
||||||
[SDT_VAR]
|
[SDT_VAR]
|
||||||
base = GameSettings
|
base = GameSettings
|
||||||
|
Reference in New Issue
Block a user