Always show train speed adaptation info in vehicle details when enabled

This commit is contained in:
Jonathan G Rennison 2024-09-06 18:38:14 +01:00
parent b8ca23978c
commit a0333c5443
7 changed files with 43 additions and 16 deletions

View File

@ -1611,6 +1611,8 @@ STR_VEHICLE_AUTO_GROUP_CARGO_LIST : ({CARGO_LIST})
STR_VEHICLE_INFO_SPEED_RESTRICTION :{BLACK}Speed restriction: {LTBLUE}{VELOCITY}
STR_VEHICLE_INFO_SPEED_ADAPTATION_EXEMPT :{BLACK}Exempt from speed adaptation
STR_VEHICLE_INFO_SPEED_ADAPTATION_LIMIT :{BLACK}Speed adaptation: {LTBLUE}{VELOCITY}
STR_VEHICLE_INFO_SPEED_ADAPTATION_NONE :{BLACK}Speed adaptation: {LTBLUE}None
STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE_AND_SPEED :{LTBLUE}{ENGINE}{BLACK} Built: {LTBLUE}{NUM}{BLACK} Value: {LTBLUE}{CURRENCY_LONG} {BLACK}Max. speed: {LTBLUE}{VELOCITY}
STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE_AND_SPEED :{LTBLUE}{ENGINE}{BLACK} Value: {LTBLUE}{CURRENCY_LONG} {BLACK}Max. speed: {LTBLUE}{VELOCITY}

View File

@ -1285,12 +1285,12 @@ void FillTrainReservationLookAhead(Train *v)
if (signal_speed == 0) {
/* unrestricted signal ahead, remove current speed adaptation */
v->signal_speed_restriction = 0;
v->UpdateTrainSpeedAdaptationLimit(0);
break;
}
if (signal_speed > v->signal_speed_restriction) {
/* signal ahead with higher speed, increase current speed adaptation */
v->signal_speed_restriction = signal_speed;
v->UpdateTrainSpeedAdaptationLimit(signal_speed);
}
}
}

View File

@ -1784,6 +1784,7 @@ static void TrainSpeedAdaptationChanged(int32_t new_value) {
for (Train *t : Train::Iterate()) {
t->signal_speed_restriction = 0;
}
SetWindowClassesDirty(WC_VEHICLE_DETAILS);
}
static void AutosaveModeChanged(int32_t new_value) {

View File

@ -518,6 +518,15 @@ protected: // These functions should not be called outside acceleration code.
{
return false;
}
private:
void UpdateTrainSpeedAdaptationLimitInternal(uint16_t speed);
public:
inline void UpdateTrainSpeedAdaptationLimit(uint16_t speed)
{
if (speed != this->signal_speed_restriction) this->UpdateTrainSpeedAdaptationLimitInternal(speed);
}
};
struct TrainDecelerationStats {

View File

@ -1643,6 +1643,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, DoCommandFlag flags, const Engin
v->last_loading_station = INVALID_STATION;
v->reverse_distance = 0;
v->speed_restriction = 0;
v->signal_speed_restriction = 0;
v->engine_type = e->index;
v->gcache.first_engine = INVALID_ENGINE; // needs to be set before first callback
@ -4907,7 +4908,7 @@ static void TrainEnterStation(Train *v, StationID station)
v->current_order.MakeWaiting();
v->current_order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
v->cur_speed = 0;
v->signal_speed_restriction = 0;
v->UpdateTrainSpeedAdaptationLimit(0);
return;
}
@ -7727,7 +7728,7 @@ void ApplySignalTrainAdaptationSpeed(Train *v, TileIndex tile, uint16_t track)
if (signal_speed == 0) {
/* unrestricted signal ahead, disregard speed adaptation at earlier signal */
v->signal_speed_restriction = 0;
v->UpdateTrainSpeedAdaptationLimit(0);
return;
}
if (signal_speed > speed) {
@ -7738,7 +7739,7 @@ void ApplySignalTrainAdaptationSpeed(Train *v, TileIndex tile, uint16_t track)
}
}
v->signal_speed_restriction = speed;
v->UpdateTrainSpeedAdaptationLimit(speed);
}
uint16_t GetLowestSpeedTrainAdaptationSpeedAtSignal(TileIndex tile, uint16_t track)
@ -7776,6 +7777,14 @@ uint16_t Train::GetMaxWeight() const
return weight;
}
void Train::UpdateTrainSpeedAdaptationLimitInternal(uint16_t speed)
{
this->signal_speed_restriction = speed;
if (!HasBit(this->flags, VRF_SPEED_ADAPTATION_EXEMPT)) {
SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
}
}
/**
* Set train speed restriction
* @param tile unused

View File

@ -2707,7 +2707,7 @@ void VehicleEnterDepot(Vehicle *v)
ClrBit(t->flags, VRF_TOGGLE_REVERSE);
t->ConsistChanged(CCF_ARRANGE);
t->reverse_distance = 0;
t->signal_speed_restriction = 0;
t->UpdateTrainSpeedAdaptationLimit(0);
t->lookahead.reset();
if (!(t->vehstatus & VS_CRASHED)) {
t->crash_anim_pos = 0;

View File

@ -2940,7 +2940,7 @@ struct VehicleDetailsWindow : Window {
bool vehicle_weight_ratio_line_shown;
bool vehicle_slots_line_shown;
bool vehicle_speed_restriction_line_shown;
bool vehicle_speed_adaptation_exempt_line_shown;
bool vehicle_speed_adaptation_line_shown;
enum DropDownAction {
VDWDDA_CLEAR_SPEED_RESTRICTION,
@ -3047,10 +3047,9 @@ struct VehicleDetailsWindow : Window {
return Train::From(v)->speed_restriction != 0;
}
bool ShouldShowSpeedAdaptationExemptLine(const Vehicle *v) const
bool ShouldShowSpeedAdaptationLine(const Vehicle *v) const
{
if (v->type != VEH_TRAIN) return false;
return HasBit(Train::From(v)->flags, VRF_SPEED_ADAPTATION_EXEMPT);
return (v->type == VEH_TRAIN && _settings_game.vehicle.train_speed_adaptation);
}
std::vector<TraceRestrictSlotID> GetVehicleSlots(const Vehicle *v) const
@ -3076,13 +3075,13 @@ struct VehicleDetailsWindow : Window {
this->vehicle_weight_ratio_line_shown = ShouldShowWeightRatioLine(v);
this->vehicle_slots_line_shown = ShouldShowSlotsLine(v);
this->vehicle_speed_restriction_line_shown = ShouldShowSpeedRestrictionLine(v);
this->vehicle_speed_adaptation_exempt_line_shown = ShouldShowSpeedAdaptationExemptLine(v);
this->vehicle_speed_adaptation_line_shown = ShouldShowSpeedAdaptationLine(v);
int lines = 4;
if (this->vehicle_group_line_shown) lines++;
if (this->vehicle_weight_ratio_line_shown) lines++;
if (this->vehicle_slots_line_shown) lines++;
if (this->vehicle_speed_restriction_line_shown) lines++;
if (this->vehicle_speed_adaptation_exempt_line_shown) lines++;
if (this->vehicle_speed_adaptation_line_shown) lines++;
size.height = lines * GetCharacterHeight(FS_NORMAL) + padding.height;
for (uint i = 0; i < 5; i++) SetDParamMaxValue(i, INT16_MAX);
@ -3358,9 +3357,16 @@ struct VehicleDetailsWindow : Window {
tr.top += GetCharacterHeight(FS_NORMAL);
}
bool should_show_speed_adaptation_exempt = this->ShouldShowSpeedAdaptationExemptLine(v);
if (should_show_speed_adaptation_exempt) {
DrawString(tr, STR_VEHICLE_INFO_SPEED_ADAPTATION_EXEMPT);
bool should_show_speed_adaptation = this->ShouldShowSpeedAdaptationLine(v);
if (should_show_speed_adaptation) {
if (HasBit(this->flags, VRF_SPEED_ADAPTATION_EXEMPT)) {
DrawString(tr, STR_VEHICLE_INFO_SPEED_ADAPTATION_EXEMPT);
} else if (Train::From(v)->signal_speed_restriction != 0) {
SetDParam(0, Train::From(v)->signal_speed_restriction);
DrawString(tr, STR_VEHICLE_INFO_SPEED_ADAPTATION_LIMIT);
} else {
DrawString(tr, STR_VEHICLE_INFO_SPEED_ADAPTATION_NONE);
}
tr.top += GetCharacterHeight(FS_NORMAL);
}
@ -3368,7 +3374,7 @@ struct VehicleDetailsWindow : Window {
this->vehicle_weight_ratio_line_shown != should_show_weight_ratio ||
this->vehicle_slots_line_shown != should_show_slots ||
this->vehicle_speed_restriction_line_shown != should_show_speed_restriction ||
this->vehicle_speed_adaptation_exempt_line_shown != should_show_speed_adaptation_exempt) {
this->vehicle_speed_adaptation_line_shown != should_show_speed_adaptation) {
const_cast<VehicleDetailsWindow *>(this)->ReInit();
}
break;