mirror of https://github.com/OpenTTD/OpenTTD
Codechange: make VehicleID an enum
parent
c25c3e8710
commit
2cb59b1856
|
@ -141,7 +141,7 @@ struct SelectGameWindow : public Window {
|
|||
for (char c : match[2].str()) {
|
||||
if (isdigit(c)) {
|
||||
if (id_type == ID_VEHICLE) {
|
||||
vc.vehicle = vc.vehicle * 10 + (c - '0');
|
||||
vc.vehicle = static_cast<VehicleID>(vc.vehicle * 10 + (c - '0'));
|
||||
}
|
||||
} else {
|
||||
id_type = ID_NONE;
|
||||
|
@ -155,7 +155,7 @@ struct SelectGameWindow : public Window {
|
|||
case 'C': vc.align_h = IntroGameViewportCommand::CENTRE; break;
|
||||
case 'R': vc.align_h = IntroGameViewportCommand::RIGHT; break;
|
||||
case 'P': vc.pan_to_next = true; break;
|
||||
case 'V': id_type = ID_VEHICLE; vc.vehicle = 0; break;
|
||||
case 'V': id_type = ID_VEHICLE; vc.vehicle = VEHICLE_BEGIN; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1250,7 +1250,7 @@ bool LoadOldVehicle(LoadgameState &ls, int num)
|
|||
ReadTTDPatchFlags(ls);
|
||||
|
||||
for (uint i = 0; i < ls.vehicle_multiplier; i++) {
|
||||
_current_vehicle_id = num * ls.vehicle_multiplier + i;
|
||||
_current_vehicle_id = static_cast<VehicleID>(num * ls.vehicle_multiplier + i);
|
||||
|
||||
Vehicle *v;
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
if (!ScriptObject::Command<CMD_BUILD_VEHICLE>::Do(&ScriptInstance::DoCommandReturnVehicleID, depot, engine_id, true, cargo, INVALID_CLIENT_ID)) return VEHICLE_INVALID;
|
||||
|
||||
/* In case of test-mode, we return VehicleID 0 */
|
||||
return 0;
|
||||
return ::VEHICLE_BEGIN;
|
||||
}
|
||||
|
||||
/* static */ VehicleID ScriptVehicle::BuildVehicle(TileIndex depot, EngineID engine_id)
|
||||
|
@ -115,16 +115,16 @@
|
|||
if (!ScriptObject::Command<CMD_CLONE_VEHICLE>::Do(&ScriptInstance::DoCommandReturnVehicleID, depot, vehicle_id, share_orders)) return VEHICLE_INVALID;
|
||||
|
||||
/* In case of test-mode, we return VehicleID 0 */
|
||||
return 0;
|
||||
return ::VEHICLE_BEGIN;
|
||||
}
|
||||
|
||||
/* static */ bool ScriptVehicle::_MoveWagonInternal(VehicleID source_vehicle_id, SQInteger source_wagon, bool move_attached_wagons, SQInteger dest_vehicle_id, SQInteger dest_wagon)
|
||||
{
|
||||
EnforceCompanyModeValid(false);
|
||||
EnforcePrecondition(false, IsValidVehicle(source_vehicle_id) && source_wagon < GetNumWagons(source_vehicle_id));
|
||||
EnforcePrecondition(false, dest_vehicle_id == -1 || (IsValidVehicle(dest_vehicle_id) && dest_wagon < GetNumWagons(dest_vehicle_id)));
|
||||
EnforcePrecondition(false, dest_vehicle_id == -1 || (IsValidVehicle(static_cast<VehicleID>(dest_vehicle_id)) && dest_wagon < GetNumWagons(static_cast<VehicleID>(dest_vehicle_id))));
|
||||
EnforcePrecondition(false, ::Vehicle::Get(source_vehicle_id)->type == VEH_TRAIN);
|
||||
EnforcePrecondition(false, dest_vehicle_id == -1 || ::Vehicle::Get(dest_vehicle_id)->type == VEH_TRAIN);
|
||||
EnforcePrecondition(false, dest_vehicle_id == -1 || ::Vehicle::Get(static_cast<VehicleID>(dest_vehicle_id))->type == VEH_TRAIN);
|
||||
|
||||
const Train *v = ::Train::Get(source_vehicle_id);
|
||||
while (source_wagon-- > 0) v = v->GetNextUnit();
|
||||
|
|
|
@ -196,7 +196,7 @@ struct MutableSpriteCache {
|
|||
};
|
||||
|
||||
/** A vehicle pool for a little over 1 million vehicles. */
|
||||
typedef Pool<Vehicle, VehicleID, 512, 0xFF000> VehiclePool;
|
||||
typedef Pool<Vehicle, VehicleID, 512, VEHICLE_END> VehiclePool;
|
||||
extern VehiclePool _vehicle_pool;
|
||||
|
||||
/* Some declarations of functions, so we can make them friendly */
|
||||
|
|
|
@ -3382,7 +3382,7 @@ public:
|
|||
{
|
||||
if (!str.has_value()) return;
|
||||
|
||||
Command<CMD_RENAME_VEHICLE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type, this->window_number, *str);
|
||||
Command<CMD_RENAME_VEHICLE>::Post(STR_ERROR_CAN_T_RENAME_TRAIN + Vehicle::Get(this->window_number)->type, static_cast<VehicleID>(this->window_number), *str);
|
||||
}
|
||||
|
||||
void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override
|
||||
|
|
|
@ -13,7 +13,11 @@
|
|||
#include "core/enum_type.hpp"
|
||||
|
||||
/** The type all our vehicle IDs have. */
|
||||
typedef uint32_t VehicleID;
|
||||
enum VehicleID : uint32_t {
|
||||
VEHICLE_BEGIN = 0,
|
||||
VEHICLE_END = 0xFF000,
|
||||
INVALID_VEHICLE = 0xFFFFF ///< Constant representing a non-existing vehicle.
|
||||
};
|
||||
|
||||
static const int GROUND_ACCELERATION = 9800; ///< Acceleration due to gravity, 9.8 m/s^2
|
||||
|
||||
|
@ -51,8 +55,6 @@ struct BaseVehicle
|
|||
VehicleType type; ///< Type of vehicle
|
||||
};
|
||||
|
||||
static const VehicleID INVALID_VEHICLE = 0xFFFFF; ///< Constant representing a non-existing vehicle.
|
||||
|
||||
/** Flags for goto depot commands. */
|
||||
enum class DepotCommandFlag : uint8_t {
|
||||
Service, ///< The vehicle will leave the depot right after arrival (service only)
|
||||
|
|
Loading…
Reference in New Issue