1
0
Fork 0

Codechange: Use an enum for vehicle acceleration model.

pull/14357/head
Michael Lutz 2025-06-19 21:09:37 +02:00
parent de6e420917
commit c719566a09
11 changed files with 23 additions and 16 deletions

View File

@ -637,7 +637,7 @@ static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engin
y += GetCharacterHeight(FS_NORMAL); y += GetCharacterHeight(FS_NORMAL);
/* Max tractive effort - not applicable if old acceleration or maglev */ /* Max tractive effort - not applicable if old acceleration or maglev */
if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(rvi->railtype)->acceleration_type != 2) { if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(rvi->railtype)->acceleration_type != VehicleAccelerationModel::Maglev) {
DrawString(left, right, y, GetString(STR_PURCHASE_INFO_MAX_TE, e->GetDisplayMaxTractiveEffort())); DrawString(left, right, y, GetString(STR_PURCHASE_INFO_MAX_TE, e->GetDisplayMaxTractiveEffort()));
y += GetCharacterHeight(FS_NORMAL); y += GetCharacterHeight(FS_NORMAL);
} }

View File

@ -181,7 +181,7 @@ static std::string GetTrainEngineInfoString(const Engine &e)
res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight()); res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
res << '\n'; res << '\n';
if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(e.u.rail.railtype)->acceleration_type != 2) { if (_settings_game.vehicle.train_acceleration_model != AM_ORIGINAL && GetRailTypeInfo(e.u.rail.railtype)->acceleration_type != VehicleAccelerationModel::Maglev) {
res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort()); res << GetString(STR_ENGINE_PREVIEW_SPEED_POWER_MAX_TE, PackVelocity(e.GetDisplayMaxSpeed(), e.type), e.GetPower(), e.GetDisplayMaxTractiveEffort());
res << '\n'; res << '\n';
} else { } else {

View File

@ -43,6 +43,13 @@ enum EngineClass : uint8_t {
EC_MAGLEV, ///< Maglev engine. EC_MAGLEV, ///< Maglev engine.
}; };
/** Acceleration model of a vehicle. */
enum class VehicleAccelerationModel : uint8_t {
Normal, ///< Default acceleration model.
Monorail, ///< Monorail acceleration model.
Maglev, ///< Maglev acceleration model.
};
/** Information about a rail vehicle. */ /** Information about a rail vehicle. */
struct RailVehicleInfo { struct RailVehicleInfo {
uint8_t image_index = 0; uint8_t image_index = 0;

View File

@ -131,7 +131,7 @@ int GroundVehicle<T, Type>::GetAcceleration() const
*/ */
int64_t resistance = 0; int64_t resistance = 0;
bool maglev = v->GetAccelerationType() == 2; bool maglev = v->GetAccelerationType() == VehicleAccelerationModel::Maglev;
const int area = v->GetAirDragArea(); const int area = v->GetAirDragArea();
if (!maglev) { if (!maglev) {

View File

@ -117,7 +117,7 @@ static ChangeInfoResult RailTypeChangeInfo(uint first, uint last, int prop, Byte
break; break;
case 0x15: // Acceleration model case 0x15: // Acceleration model
rti->acceleration_type = Clamp(buf.ReadByte(), 0, 2); rti->acceleration_type = static_cast<VehicleAccelerationModel>(Clamp(buf.ReadByte(), 0, 2));
break; break;
case 0x16: // Map colour case 0x16: // Map colour

View File

@ -214,7 +214,7 @@ public:
/** /**
* Acceleration type of this rail type * Acceleration type of this rail type
*/ */
uint8_t acceleration_type; VehicleAccelerationModel acceleration_type;
/** /**
* Maximum speed for vehicles travelling on this rail type * Maximum speed for vehicles travelling on this rail type

View File

@ -250,11 +250,11 @@ protected: // These functions should not be called outside acceleration code.
/** /**
* Allows to know the acceleration type of a vehicle. * Allows to know the acceleration type of a vehicle.
* @return Zero, road vehicles always use a normal acceleration method. * @return \c VehicleAccelerationModel::Normal, road vehicles always use a normal acceleration method.
*/ */
inline int GetAccelerationType() const inline VehicleAccelerationModel GetAccelerationType() const
{ {
return 0; return VehicleAccelerationModel::Normal;
} }
/** /**

View File

@ -86,7 +86,7 @@ static const RailTypeInfo _original_railtypes[] = {
8, 8,
/* acceleration type */ /* acceleration type */
0, VehicleAccelerationModel::Normal,
/* max speed */ /* max speed */
0, 0,
@ -188,7 +188,7 @@ static const RailTypeInfo _original_railtypes[] = {
12, 12,
/* acceleration type */ /* acceleration type */
0, VehicleAccelerationModel::Normal,
/* max speed */ /* max speed */
0, 0,
@ -286,7 +286,7 @@ static const RailTypeInfo _original_railtypes[] = {
16, 16,
/* acceleration type */ /* acceleration type */
1, VehicleAccelerationModel::Monorail,
/* max speed */ /* max speed */
0, 0,
@ -384,7 +384,7 @@ static const RailTypeInfo _original_railtypes[] = {
24, 24,
/* acceleration type */ /* acceleration type */
2, VehicleAccelerationModel::Maglev,
/* max speed */ /* max speed */
0, 0,

View File

@ -302,7 +302,7 @@ protected: // These functions should not be called outside acceleration code.
* Allows to know the acceleration type of a vehicle. * Allows to know the acceleration type of a vehicle.
* @return Acceleration type of the vehicle. * @return Acceleration type of the vehicle.
*/ */
inline int GetAccelerationType() const inline VehicleAccelerationModel GetAccelerationType() const
{ {
return GetRailTypeInfo(this->railtype)->acceleration_type; return GetRailTypeInfo(this->railtype)->acceleration_type;
} }

View File

@ -3083,7 +3083,7 @@ static inline void AffectSpeedByZChange(Train *v, int old_z)
{ {
if (old_z == v->z_pos || _settings_game.vehicle.train_acceleration_model != AM_ORIGINAL) return; if (old_z == v->z_pos || _settings_game.vehicle.train_acceleration_model != AM_ORIGINAL) return;
const AccelerationSlowdownParams *asp = &_accel_slowdown[GetRailTypeInfo(v->railtype)->acceleration_type]; const AccelerationSlowdownParams *asp = &_accel_slowdown[static_cast<int>(GetRailTypeInfo(v->railtype)->acceleration_type)];
if (old_z < v->z_pos) { if (old_z < v->z_pos) {
v->cur_speed -= (v->cur_speed * asp->z_up >> 8); v->cur_speed -= (v->cur_speed * asp->z_up >> 8);
@ -3490,7 +3490,7 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse)
if (chosen_dir != v->direction) { if (chosen_dir != v->direction) {
if (prev == nullptr && _settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) { if (prev == nullptr && _settings_game.vehicle.train_acceleration_model == AM_ORIGINAL) {
const AccelerationSlowdownParams *asp = &_accel_slowdown[GetRailTypeInfo(v->railtype)->acceleration_type]; const AccelerationSlowdownParams *asp = &_accel_slowdown[static_cast<int>(GetRailTypeInfo(v->railtype)->acceleration_type)];
DirDiff diff = DirDifference(v->direction, chosen_dir); DirDiff diff = DirDifference(v->direction, chosen_dir);
v->cur_speed -= (diff == DIRDIFF_45RIGHT || diff == DIRDIFF_45LEFT ? asp->small_turn : asp->large_turn) * v->cur_speed >> 8; v->cur_speed -= (diff == DIRDIFF_45RIGHT || diff == DIRDIFF_45LEFT ? asp->small_turn : asp->large_turn) * v->cur_speed >> 8;
} }

View File

@ -2596,7 +2596,7 @@ struct VehicleDetailsWindow : Window {
(v->type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL)) { (v->type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL)) {
const GroundVehicleCache *gcache = v->GetGroundVehicleCache(); const GroundVehicleCache *gcache = v->GetGroundVehicleCache();
if (v->type == VEH_TRAIN && (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL || if (v->type == VEH_TRAIN && (_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL ||
GetRailTypeInfo(Train::From(v)->railtype)->acceleration_type == 2)) { GetRailTypeInfo(Train::From(v)->railtype)->acceleration_type == VehicleAccelerationModel::Maglev)) {
DrawString(tr, GetString(STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, gcache->cached_weight, gcache->cached_power, max_speed)); DrawString(tr, GetString(STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, gcache->cached_weight, gcache->cached_power, max_speed));
} else { } else {
DrawString(tr, GetString(STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE, gcache->cached_weight, gcache->cached_power, max_speed, gcache->cached_max_te)); DrawString(tr, GetString(STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE, gcache->cached_weight, gcache->cached_power, max_speed, gcache->cached_max_te));