1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-19 21:13:05 +01:00

Merge pull request #12605 from ion232/refactor-vehicle-type

closes #12439: Refactor VEHICLE_TYPE to use strong enum
This commit is contained in:
Arran Ireland
2020-08-08 18:41:04 +01:00
committed by GitHub
parent 933570fd62
commit 1702c90c8e
4 changed files with 11 additions and 10 deletions

View File

@@ -1124,7 +1124,8 @@ private:
if (srcVehicle->x != LOCATION_NULL)
{
// If vehicle is the first car on a train add to train list
auto llt = srcVehicle->type == VEHICLE_TYPE_HEAD ? EntityListId::TrainHead : EntityListId::Vehicle;
auto isFirstCar = srcVehicle->type == static_cast<uint8_t>(Vehicle::Type::Head);
auto llt = isFirstCar ? EntityListId::TrainHead : EntityListId::Vehicle;
Vehicle* vehicle = reinterpret_cast<Vehicle*>(create_sprite(SPRITE_IDENTIFIER_VEHICLE, llt));
spriteIndexMap[i] = vehicle->sprite_index;

View File

@@ -32,7 +32,7 @@ Vehicle* cable_lift_segment_create(
{
ride.cable_lift = current->sprite_index;
}
current->type = head ? VEHICLE_TYPE_HEAD : VEHICLE_TYPE_TAIL;
current->type = static_cast<uint8_t>(head ? Vehicle::Type::Head : Vehicle::Type::Tail);
current->var_44 = var_44;
current->remaining_distance = remaining_distance;
current->sprite_width = 10;

View File

@@ -4346,7 +4346,7 @@ static Vehicle* vehicle_create_car(
vehicle->ride_subtype = ride->subtype;
vehicle->vehicle_type = vehicleEntryIndex;
vehicle->type = carIndex == 0 ? VEHICLE_TYPE_HEAD : VEHICLE_TYPE_TAIL;
vehicle->type = static_cast<uint8_t>(carIndex == 0 ? Vehicle::Type::Head : Vehicle::Type::Tail);
vehicle->var_44 = ror32(vehicleEntry->spacing, 10) & 0xFFFF;
auto edx = vehicleEntry->spacing >> 1;
*remainingDistance -= edx;

View File

@@ -109,12 +109,6 @@ static_assert(sizeof(rct_ride_entry_vehicle) % 4 == 0, "Invalid struct size");
static_assert(sizeof(rct_ride_entry_vehicle) % 8 == 0, "Invalid struct size");
#endif
enum VEHICLE_TYPE : uint8_t
{
VEHICLE_TYPE_HEAD = 0,
VEHICLE_TYPE_TAIL = 1,
};
enum VEHICLE_STATUS
{
VEHICLE_STATUS_MOVING_TO_END_OF_STATION,
@@ -200,6 +194,12 @@ struct rct_vehicle_info
struct Vehicle : SpriteBase
{
enum class Type : uint8_t
{
Head,
Tail,
};
uint8_t vehicle_sprite_type;
uint8_t bank_rotation;
int32_t remaining_distance;
@@ -314,7 +314,7 @@ struct Vehicle : SpriteBase
constexpr bool IsHead() const
{
return type == VEHICLE_TYPE_HEAD;
return type == static_cast<uint8_t>(Vehicle::Type::Head);
}
void Update();
Vehicle* GetHead();