Improve performance of train breakdown detection
This commit is contained in:
@@ -3137,6 +3137,14 @@ bool AfterLoadGame()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (SlXvIsFeatureMissing(XSLFI_CONSIST_BREAKDOWN_FLAG)) {
|
||||||
|
Train *v;
|
||||||
|
FOR_ALL_TRAINS(v) {
|
||||||
|
if (v->breakdown_ctr != 0 && (v->IsEngine() || v->IsMultiheaded())) {
|
||||||
|
SetBit(v->First()->flags, VRF_CONSIST_BREAKDOWN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* The road owner of standard road stops was not properly accounted for. */
|
/* The road owner of standard road stops was not properly accounted for. */
|
||||||
if (IsSavegameVersionBefore(172)) {
|
if (IsSavegameVersionBefore(172)) {
|
||||||
|
@@ -60,6 +60,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
|
|||||||
{ XSLFI_TOWN_CARGO_ADJ, XSCF_IGNORABLE_UNKNOWN, 2, 2, "town_cargo_adj", NULL, NULL, NULL },
|
{ XSLFI_TOWN_CARGO_ADJ, XSCF_IGNORABLE_UNKNOWN, 2, 2, "town_cargo_adj", NULL, NULL, NULL },
|
||||||
{ XSLFI_SIG_TUNNEL_BRIDGE, XSCF_NULL, 7, 7, "signal_tunnel_bridge", NULL, NULL, "XBSS" },
|
{ XSLFI_SIG_TUNNEL_BRIDGE, XSCF_NULL, 7, 7, "signal_tunnel_bridge", NULL, NULL, "XBSS" },
|
||||||
{ XSLFI_IMPROVED_BREAKDOWNS, XSCF_NULL, 6, 6, "improved_breakdowns", NULL, NULL, NULL },
|
{ XSLFI_IMPROVED_BREAKDOWNS, XSCF_NULL, 6, 6, "improved_breakdowns", NULL, NULL, NULL },
|
||||||
|
{ XSLFI_CONSIST_BREAKDOWN_FLAG, XSCF_NULL, 1, 1, "consist_breakdown_flag", NULL, NULL, NULL },
|
||||||
{ XSLFI_TT_WAIT_IN_DEPOT, XSCF_NULL, 1, 1, "tt_wait_in_depot", NULL, NULL, NULL },
|
{ XSLFI_TT_WAIT_IN_DEPOT, XSCF_NULL, 1, 1, "tt_wait_in_depot", NULL, NULL, NULL },
|
||||||
{ XSLFI_AUTO_TIMETABLE, XSCF_NULL, 4, 4, "auto_timetables", NULL, NULL, NULL },
|
{ XSLFI_AUTO_TIMETABLE, XSCF_NULL, 4, 4, "auto_timetables", NULL, NULL, NULL },
|
||||||
{ XSLFI_VEHICLE_REPAIR_COST, XSCF_NULL, 2, 2, "vehicle_repair_cost", NULL, NULL, NULL },
|
{ XSLFI_VEHICLE_REPAIR_COST, XSCF_NULL, 2, 2, "vehicle_repair_cost", NULL, NULL, NULL },
|
||||||
|
@@ -34,6 +34,7 @@ enum SlXvFeatureIndex {
|
|||||||
XSLFI_TOWN_CARGO_ADJ, ///< Town cargo adjustment patch
|
XSLFI_TOWN_CARGO_ADJ, ///< Town cargo adjustment patch
|
||||||
XSLFI_SIG_TUNNEL_BRIDGE, ///< Signals on tunnels and bridges
|
XSLFI_SIG_TUNNEL_BRIDGE, ///< Signals on tunnels and bridges
|
||||||
XSLFI_IMPROVED_BREAKDOWNS, ///< Improved breakdowns patch
|
XSLFI_IMPROVED_BREAKDOWNS, ///< Improved breakdowns patch
|
||||||
|
XSLFI_CONSIST_BREAKDOWN_FLAG, ///< Consist breakdown flag
|
||||||
XSLFI_TT_WAIT_IN_DEPOT, ///< Timetabling waiting time in depot patch
|
XSLFI_TT_WAIT_IN_DEPOT, ///< Timetabling waiting time in depot patch
|
||||||
XSLFI_AUTO_TIMETABLE, ///< Auto timetables and separation patch
|
XSLFI_AUTO_TIMETABLE, ///< Auto timetables and separation patch
|
||||||
XSLFI_VEHICLE_REPAIR_COST, ///< Vehicle repair costs patch
|
XSLFI_VEHICLE_REPAIR_COST, ///< Vehicle repair costs patch
|
||||||
|
@@ -44,6 +44,7 @@ enum VehicleRailFlags {
|
|||||||
VRF_BEYOND_PLATFORM_END = 16,
|
VRF_BEYOND_PLATFORM_END = 16,
|
||||||
VRF_NOT_YET_IN_PLATFORM = 17,
|
VRF_NOT_YET_IN_PLATFORM = 17,
|
||||||
VRF_ADVANCE_IN_PLATFORM = 18,
|
VRF_ADVANCE_IN_PLATFORM = 18,
|
||||||
|
VRF_CONSIST_BREAKDOWN = 19,///< one or more vehicles in this consist have a breakdown of some sort (breakdown_ctr != 0)
|
||||||
|
|
||||||
VRF_IS_BROKEN = (1 << VRF_BREAKDOWN_POWER) | (1 << VRF_BREAKDOWN_SPEED) | (1 << VRF_BREAKDOWN_STOPPED), ///< Bitmask of all flags that indicate a broken train (braking is not included)
|
VRF_IS_BROKEN = (1 << VRF_BREAKDOWN_POWER) | (1 << VRF_BREAKDOWN_SPEED) | (1 << VRF_BREAKDOWN_STOPPED), ///< Bitmask of all flags that indicate a broken train (braking is not included)
|
||||||
};
|
};
|
||||||
|
@@ -4770,7 +4770,7 @@ static bool TrainLocoHandler(Train *v, bool mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* train is broken down? */
|
/* train is broken down? */
|
||||||
if (HandlePossibleBreakdowns(v)) return true;
|
if (HasBit(v->flags, VRF_CONSIST_BREAKDOWN) && HandlePossibleBreakdowns(v)) return true;
|
||||||
|
|
||||||
if (HasBit(v->flags, VRF_REVERSING) && v->cur_speed == 0) {
|
if (HasBit(v->flags, VRF_REVERSING) && v->cur_speed == 0) {
|
||||||
ReverseTrainDirection(v);
|
ReverseTrainDirection(v);
|
||||||
@@ -5548,6 +5548,7 @@ void TrainRoadVehicleCrashBreakdown(Vehicle *v)
|
|||||||
{
|
{
|
||||||
Train *t = Train::From(v)->First();
|
Train *t = Train::From(v)->First();
|
||||||
t->breakdown_ctr = 2;
|
t->breakdown_ctr = 2;
|
||||||
|
SetBit(t->flags, VRF_CONSIST_BREAKDOWN);
|
||||||
t->breakdown_delay = 255;
|
t->breakdown_delay = 255;
|
||||||
t->breakdown_type = BREAKDOWN_RV_CRASH;
|
t->breakdown_type = BREAKDOWN_RV_CRASH;
|
||||||
t->breakdown_severity = 0;
|
t->breakdown_severity = 0;
|
||||||
|
@@ -183,6 +183,7 @@ void VehicleServiceInDepot(Vehicle *v)
|
|||||||
if (!(Train::From(v)->IsEngine()) && !(Train::From(v)->IsRearDualheaded())) return;
|
if (!(Train::From(v)->IsEngine()) && !(Train::From(v)->IsRearDualheaded())) return;
|
||||||
ClrBit(Train::From(v)->flags, VRF_NEED_REPAIR);
|
ClrBit(Train::From(v)->flags, VRF_NEED_REPAIR);
|
||||||
ClrBit(Train::From(v)->flags, VRF_HAS_HIT_RV);
|
ClrBit(Train::From(v)->flags, VRF_HAS_HIT_RV);
|
||||||
|
ClrBit(Train::From(v)->flags, VRF_CONSIST_BREAKDOWN);
|
||||||
Train::From(v)->critical_breakdown_count = 0;
|
Train::From(v)->critical_breakdown_count = 0;
|
||||||
const RailVehicleInfo *rvi = &e->u.rail;
|
const RailVehicleInfo *rvi = &e->u.rail;
|
||||||
v->vcache.cached_max_speed = rvi->max_speed;
|
v->vcache.cached_max_speed = rvi->max_speed;
|
||||||
@@ -1715,6 +1716,7 @@ void CheckVehicleBreakdown(Vehicle *v)
|
|||||||
if ((uint32) (0xffff - v->reliability) * _settings_game.difficulty.vehicle_breakdowns * chance > GB(r1, 0, 24) * 10) {
|
if ((uint32) (0xffff - v->reliability) * _settings_game.difficulty.vehicle_breakdowns * chance > GB(r1, 0, 24) * 10) {
|
||||||
uint32 r2 = Random();
|
uint32 r2 = Random();
|
||||||
v->breakdown_ctr = GB(r1, 24, 6) + 0xF;
|
v->breakdown_ctr = GB(r1, 24, 6) + 0xF;
|
||||||
|
if (v->type == VEH_TRAIN) SetBit(Train::From(v)->First()->flags, VRF_CONSIST_BREAKDOWN);
|
||||||
v->breakdown_delay = GB(r2, 0, 7) + 0x80;
|
v->breakdown_delay = GB(r2, 0, 7) + 0x80;
|
||||||
v->breakdown_chance = 0;
|
v->breakdown_chance = 0;
|
||||||
DetermineBreakdownType(v, r2);
|
DetermineBreakdownType(v, r2);
|
||||||
|
Reference in New Issue
Block a user