mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Use an enum for vehicle acceleration model.
parent
de6e420917
commit
c719566a09
|
@ -637,7 +637,7 @@ static int DrawRailEnginePurchaseInfo(int left, int right, int y, EngineID engin
|
|||
y += GetCharacterHeight(FS_NORMAL);
|
||||
|
||||
/* 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()));
|
||||
y += GetCharacterHeight(FS_NORMAL);
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ static std::string GetTrainEngineInfoString(const Engine &e)
|
|||
res << GetString(STR_ENGINE_PREVIEW_COST_WEIGHT, e.GetCost(), e.GetDisplayWeight());
|
||||
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 << '\n';
|
||||
} else {
|
||||
|
|
|
@ -43,6 +43,13 @@ enum EngineClass : uint8_t {
|
|||
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. */
|
||||
struct RailVehicleInfo {
|
||||
uint8_t image_index = 0;
|
||||
|
|
|
@ -131,7 +131,7 @@ int GroundVehicle<T, Type>::GetAcceleration() const
|
|||
*/
|
||||
int64_t resistance = 0;
|
||||
|
||||
bool maglev = v->GetAccelerationType() == 2;
|
||||
bool maglev = v->GetAccelerationType() == VehicleAccelerationModel::Maglev;
|
||||
|
||||
const int area = v->GetAirDragArea();
|
||||
if (!maglev) {
|
||||
|
|
|
@ -117,7 +117,7 @@ static ChangeInfoResult RailTypeChangeInfo(uint first, uint last, int prop, Byte
|
|||
break;
|
||||
|
||||
case 0x15: // Acceleration model
|
||||
rti->acceleration_type = Clamp(buf.ReadByte(), 0, 2);
|
||||
rti->acceleration_type = static_cast<VehicleAccelerationModel>(Clamp(buf.ReadByte(), 0, 2));
|
||||
break;
|
||||
|
||||
case 0x16: // Map colour
|
||||
|
|
|
@ -214,7 +214,7 @@ public:
|
|||
/**
|
||||
* Acceleration type of this rail type
|
||||
*/
|
||||
uint8_t acceleration_type;
|
||||
VehicleAccelerationModel acceleration_type;
|
||||
|
||||
/**
|
||||
* Maximum speed for vehicles travelling on this rail type
|
||||
|
|
|
@ -250,11 +250,11 @@ protected: // These functions should not be called outside acceleration code.
|
|||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -86,7 +86,7 @@ static const RailTypeInfo _original_railtypes[] = {
|
|||
8,
|
||||
|
||||
/* acceleration type */
|
||||
0,
|
||||
VehicleAccelerationModel::Normal,
|
||||
|
||||
/* max speed */
|
||||
0,
|
||||
|
@ -188,7 +188,7 @@ static const RailTypeInfo _original_railtypes[] = {
|
|||
12,
|
||||
|
||||
/* acceleration type */
|
||||
0,
|
||||
VehicleAccelerationModel::Normal,
|
||||
|
||||
/* max speed */
|
||||
0,
|
||||
|
@ -286,7 +286,7 @@ static const RailTypeInfo _original_railtypes[] = {
|
|||
16,
|
||||
|
||||
/* acceleration type */
|
||||
1,
|
||||
VehicleAccelerationModel::Monorail,
|
||||
|
||||
/* max speed */
|
||||
0,
|
||||
|
@ -384,7 +384,7 @@ static const RailTypeInfo _original_railtypes[] = {
|
|||
24,
|
||||
|
||||
/* acceleration type */
|
||||
2,
|
||||
VehicleAccelerationModel::Maglev,
|
||||
|
||||
/* max speed */
|
||||
0,
|
||||
|
|
|
@ -302,7 +302,7 @@ protected: // These functions should not be called outside acceleration code.
|
|||
* Allows to know the acceleration type of a vehicle.
|
||||
* @return Acceleration type of the vehicle.
|
||||
*/
|
||||
inline int GetAccelerationType() const
|
||||
inline VehicleAccelerationModel GetAccelerationType() const
|
||||
{
|
||||
return GetRailTypeInfo(this->railtype)->acceleration_type;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
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) {
|
||||
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 (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);
|
||||
v->cur_speed -= (diff == DIRDIFF_45RIGHT || diff == DIRDIFF_45LEFT ? asp->small_turn : asp->large_turn) * v->cur_speed >> 8;
|
||||
}
|
||||
|
|
|
@ -2596,7 +2596,7 @@ struct VehicleDetailsWindow : Window {
|
|||
(v->type == VEH_ROAD && _settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL)) {
|
||||
const GroundVehicleCache *gcache = v->GetGroundVehicleCache();
|
||||
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));
|
||||
} 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));
|
||||
|
|
Loading…
Reference in New Issue