Skip to content

Commit

Permalink
Enum - Flags0C, Flags38 conversion (#1811)
Browse files Browse the repository at this point in the history
* Enum - Flags0C conversion

* Enum - Flags38 conversion

* Enum - StatusFlags conversion

* Revert "Enum - Flags38 conversion"

This reverts commit d034f64.

* Revert "Enum - StatusFlags conversion"

This reverts commit f9028dd.

* Rename Flags0C to EntityBaseFlags

* Enum - Flags38 conversion

* clang fix

* Wrapping && in () due to compiler warning

* Rename EntityBaseFlags to VehicleFlags

* Adding hex counts to EntityBase structure
  • Loading branch information
niceeffort committed Feb 10, 2023
1 parent 3c04d7d commit a5578f0
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 131 deletions.
52 changes: 32 additions & 20 deletions src/OpenLoco/src/Entities/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "Location.hpp"
#include "Map/Map.hpp"
#include "Types.hpp"

#include <OpenLoco/Core/EnumFlags.hpp>
#include <cstdint>
#include <limits>

Expand Down Expand Up @@ -34,6 +34,18 @@ namespace OpenLoco
down20deg = 12,
};

enum class VehicleFlags : uint16_t // commands?
{
none = 0U,
unk_0 = 1U << 0,
commandStop = 1U << 1, // commanded to stop??
sorted = 1U << 3, // vehicle list
unk_5 = 1U << 5,
manualControl = 1U << 6,
shuntCheat = 1U << 7,
};
OPENLOCO_ENABLE_ENUM_OPERATORS(VehicleFlags);

#pragma pack(push, 1)
struct EntityBase
{
Expand All @@ -42,25 +54,25 @@ namespace OpenLoco
private:
uint8_t type; // Use type specific getters/setters as this depends on baseType
public:
EntityId nextQuadrantId; // 0x02
EntityId nextThingId; // 0x04
EntityId llPreviousId; // 0x06
uint8_t linkedListOffset; // 0x8
uint8_t var_09;
EntityId id; // 0xA
uint16_t var_0C;
Map::Pos3 position; // 0x0E
uint8_t var_14;
uint8_t var_15;
int16_t spriteLeft; // 0x16
int16_t spriteTop; // 0x18
int16_t spriteRight; // 0x1A
int16_t spriteBottom; // 0x1C
uint8_t spriteYaw; // 0x1E
Pitch spritePitch; // 0x1F
uint8_t pad_20;
CompanyId owner; // 0x21
string_id name; // 0x22, combined with ordinalNumber on vehicles
EntityId nextQuadrantId; // 0x02
EntityId nextThingId; // 0x04
EntityId llPreviousId; // 0x06
uint8_t linkedListOffset; // 0x08
uint8_t var_09; // 0x09
EntityId id; // 0x0A
VehicleFlags vehicleFlags; // 0x0C, Move these to VehicleBase after full reimplementation
Map::Pos3 position; // 0x0E
uint8_t var_14; // 0x14
uint8_t var_15; // 0x15
int16_t spriteLeft; // 0x16
int16_t spriteTop; // 0x18
int16_t spriteRight; // 0x1A
int16_t spriteBottom; // 0x1C
uint8_t spriteYaw; // 0x1E
Pitch spritePitch; // 0x1F
uint8_t pad_20; // 0x20
CompanyId owner; // 0x21
string_id name; // 0x22, combined with ordinalNumber on vehicles

void moveTo(const Map::Pos3& loc);
void invalidateSprite();
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Entities/EntityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ namespace OpenLoco::EntityManager
newEntity->var_14 = 16;
newEntity->var_09 = 20;
newEntity->var_15 = 8;
newEntity->var_0C = 0;
newEntity->vehicleFlags = VehicleFlags::none;
newEntity->spriteLeft = Location::null;

return newEntity;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/GameCommands/Cheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ namespace OpenLoco::GameCommands
}
if (flags & Flags::apply)
{
veh->var_0C |= Vehicles::Flags0C::shuntCheat;
veh->vehicleFlags |= VehicleFlags::shuntCheat;
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/GameCommands/VehiclePickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace OpenLoco::GameCommands
// Clear ghost flag on primary vehicle pieces and all car components.
train.applyToComponents([](auto& component) { component.var_38 &= ~Vehicles::Flags38::isGhost; });

head->var_0C |= Vehicles::Flags0C::commandStop;
head->vehicleFlags |= VehicleFlags::commandStop;

return 0;
}
Expand Down
26 changes: 13 additions & 13 deletions src/OpenLoco/src/Paint/PaintVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace OpenLoco::Paint
uint8_t yaw = (bogie->spriteYaw + (session.getRotation() << 4)) & 0x3F;
auto pitch = bogie->spritePitch;

if (bogie->getFlags38() & Flags38::isReversed)
if (bogie->has38Flags(Flags38::isReversed))
{
// Flip the highest bit to reverse the yaw
yaw ^= (1 << 5);
Expand Down Expand Up @@ -85,20 +85,20 @@ namespace OpenLoco::Paint
}
const auto imageIndex = sprite.numRollSprites * yawIndex + bogie->var_46 + sprite.flatImageIds;
ImageId imageId{};
if (bogie->getFlags38() & Flags38::isGhost)
if (bogie->has38Flags(Flags38::isGhost))
{
session.setItemType(Ui::ViewportInteraction::InteractionItem::noInteraction);
imageId = Gfx::applyGhostToImage(imageIndex);
}
else if (bogie->var_0C & Flags0C::unk_5)
else if (bogie->hasVehicleFlags(VehicleFlags::unk_5))
{
imageId = ImageId(imageIndex, ExtColour::unk74);
}
else if (bogie->getTransportMode() == TransportMode::air)
{
// Airplane bogies are the shadows of the plane

if (bogie->getFlags38() & Flags38::isGhost)
if (bogie->has38Flags(Flags38::isGhost))
{
// Ghosts don't cast shadows
return;
Expand Down Expand Up @@ -132,7 +132,7 @@ namespace OpenLoco::Paint
{
const auto imageIndex = sprite.numRollSprites * yawIndex + bogie->var_46 + sprite.gentleImageIds;
ImageId imageId{};
if (bogie->getFlags38() & Flags38::isGhost)
if (bogie->has38Flags(Flags38::isGhost))
{
session.setItemType(Ui::ViewportInteraction::InteractionItem::noInteraction);
imageId = Gfx::applyGhostToImage(imageIndex);
Expand All @@ -157,7 +157,7 @@ namespace OpenLoco::Paint
{
const auto imageIndex = sprite.numRollSprites * yawIndex + bogie->var_46 + sprite.steepImageIds;
ImageId imageId{};
if (bogie->getFlags38() & Flags38::isGhost)
if (bogie->has38Flags(Flags38::isGhost))
{
session.setItemType(Ui::ViewportInteraction::InteractionItem::noInteraction);
imageId = Gfx::applyGhostToImage(imageIndex);
Expand Down Expand Up @@ -343,7 +343,7 @@ namespace OpenLoco::Paint
auto originalYaw = yaw; // edi
auto pitch = body->spritePitch;

if (body->getFlags38() & Flags38::isReversed)
if (body->has38Flags(Flags38::isReversed))
{
yaw ^= (1 << 5);
pitch = kReversePitch[static_cast<uint8_t>(body->spritePitch)];
Expand Down Expand Up @@ -404,7 +404,7 @@ namespace OpenLoco::Paint
{
auto& unk = vehObject->var_24[body->bodyIndex];
auto offsetModifier = unk.length - unk.var_01;
if (body->getFlags38() & Flags38::isReversed)
if (body->has38Flags(Flags38::isReversed))
{
offsetModifier = -offsetModifier;
}
Expand All @@ -429,11 +429,11 @@ namespace OpenLoco::Paint
}

ImageId imageId{};
if (body->getFlags38() & Flags38::isGhost)
if (body->has38Flags(Flags38::isGhost))
{
imageId = Gfx::applyGhostToImage(bodyImageIndex);
}
else if (body->var_0C & Flags0C::unk_5)
else if (body->hasVehicleFlags(VehicleFlags::unk_5))
{
imageId = ImageId(bodyImageIndex, ExtColour::unk74);
}
Expand All @@ -447,8 +447,8 @@ namespace OpenLoco::Paint
{
Vehicle train(body->head);
if (train.veh2->var_5B != 0
&& !(body->getFlags38() & Flags38::isGhost)
&& !(body->var_0C & Flags0C::unk_5))
&& !body->has38Flags(Flags38::isGhost)
&& !body->hasVehicleFlags(VehicleFlags::unk_5))
{
session.attachToPrevious(ImageId{ *brakingImageIndex }, { 0, 0 });
}
Expand All @@ -458,7 +458,7 @@ namespace OpenLoco::Paint
// 0x004B0CCE
void paintVehicleEntity(PaintSession& session, Vehicles::VehicleBase* base)
{
if (base->getFlags38() & Flags38::isGhost)
if (base->has38Flags(Flags38::isGhost))
{
if (base->owner != CompanyManager::getControllingId())
{
Expand Down
13 changes: 6 additions & 7 deletions src/OpenLoco/src/Vehicles/CreateVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace OpenLoco::Vehicles
{
return nullptr;
}
newBogie->var_38 = 0;
newBogie->var_38 = Flags38::none;

int32_t reliability = vehObject.reliability * 256;
if (getCurrentYear() + 2 > vehObject.designed)
Expand Down Expand Up @@ -430,7 +430,7 @@ namespace OpenLoco::Vehicles
EntityManager::moveEntityToList(newHead, EntityManager::EntityListType::vehicleHead);
newHead->owner = _updatingCompanyId;
newHead->head = newHead->id;
newHead->var_0C |= Flags0C::commandStop;
newHead->vehicleFlags |= VehicleFlags::commandStop;
newHead->trackType = trackType;
newHead->mode = mode;
newHead->tileX = -1;
Expand All @@ -443,7 +443,7 @@ namespace OpenLoco::Vehicles
newHead->var_14 = 0;
newHead->var_09 = 0;
newHead->var_15 = 0;
newHead->var_38 = 0;
newHead->var_38 = Flags38::none;
newHead->var_3C = 0;
newHead->vehicleType = vehicleType;
newHead->name = static_cast<uint8_t>(vehicleType) + 4;
Expand Down Expand Up @@ -481,7 +481,7 @@ namespace OpenLoco::Vehicles
newVeh1->var_14 = 0;
newVeh1->var_09 = 0;
newVeh1->var_15 = 0;
newVeh1->var_38 = 0;
newVeh1->var_38 = Flags38::none;
newVeh1->var_3C = 0;
newVeh1->var_44 = 0_mph;
newVeh1->timeAtSignal = 0;
Expand Down Expand Up @@ -512,8 +512,7 @@ namespace OpenLoco::Vehicles
newVeh2->var_14 = 0;
newVeh2->var_09 = 0;
newVeh2->var_15 = 0;
newVeh2->var_38 = 0;

newVeh2->var_38 = Flags38::none;
newVeh2->currentSpeed = 0.0_mph;
newVeh2->var_5A = 0;
newVeh2->var_5B = 0;
Expand Down Expand Up @@ -549,7 +548,7 @@ namespace OpenLoco::Vehicles
newTail->var_14 = 0;
newTail->var_09 = 0;
newTail->var_15 = 0;
newTail->var_38 = 0;
newTail->var_38 = Flags38::none;
newTail->drivingSoundId = SoundObjectId::null;
newTail->objectId = -1;
newTail->var_4A = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/OpenLoco/src/Vehicles/Routing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ namespace OpenLoco::Vehicles
continue;
}

if (vehicle->getFlags38() & (Vehicles::Flags38::unk_0 | Vehicles::Flags38::unk_2))
if (vehicle->has38Flags(Vehicles::Flags38::unk_0 | Vehicles::Flags38::unk_2))
{
continue;
}
Expand Down
16 changes: 14 additions & 2 deletions src/OpenLoco/src/Vehicles/Vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace OpenLoco::Vehicles
Map::SmallZ tileBaseZ; // 0x34
uint8_t trackType; // 0x35 field same in all vehicles
RoutingHandle routingHandle; // 0x36 field same in all vehicles
uint8_t var_38; // 0x38
Flags38 var_38; // 0x38
uint8_t pad_39;
EntityId nextCarId; // 0x3A
uint8_t pad_3C[0x42 - 0x3C];
Expand All @@ -52,7 +52,7 @@ namespace OpenLoco::Vehicles
return veh->mode;
}

uint8_t VehicleBase::getFlags38() const
Flags38 VehicleBase::getFlags38() const
{
const auto* veh = reinterpret_cast<const VehicleCommon*>(this);
return veh->var_38;
Expand Down Expand Up @@ -94,6 +94,18 @@ namespace OpenLoco::Vehicles
veh->nextCarId = newNextCar;
}

bool VehicleBase::has38Flags(Flags38 flagsToTest) const
{
const auto* veh = reinterpret_cast<const VehicleCommon*>(this);
return (veh->var_38 & flagsToTest) != Flags38::none;
}

bool VehicleBase::hasVehicleFlags(VehicleFlags flagsToTest) const
{
const auto* ent = reinterpret_cast<const EntityBase*>(this);
return (ent->vehicleFlags & flagsToTest) != VehicleFlags::none;
}

// 0x004AA464
void VehicleBase::sub_4AA464()
{
Expand Down

0 comments on commit a5578f0

Please sign in to comment.