diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index b4331995d5..bbf8158560 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -651,8 +651,9 @@ namespace OpenRCT2::Ui::Windows _pickedPeepX = peep->x; CoordsXYZ nullLoc{}; nullLoc.SetNull(); - PeepPickupAction pickupAction{ PeepPickupType::Pickup, EntityId::FromUnderlying(number), nullLoc, - NetworkGetCurrentPlayerId() }; + GameActions::PeepPickupAction pickupAction{ GameActions::PeepPickupType::Pickup, + EntityId::FromUnderlying(number), nullLoc, + NetworkGetCurrentPlayerId() }; pickupAction.SetCallback([peepnum = number](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) return; @@ -1018,10 +1019,10 @@ namespace OpenRCT2::Ui::Windows if (destCoords.IsNull()) return; - PeepPickupAction pickupAction{ PeepPickupType::Place, - EntityId::FromUnderlying(number), - { destCoords, tileElement->GetBaseZ() }, - NetworkGetCurrentPlayerId() }; + GameActions::PeepPickupAction pickupAction{ GameActions::PeepPickupType::Place, + EntityId::FromUnderlying(number), + { destCoords, tileElement->GetBaseZ() }, + NetworkGetCurrentPlayerId() }; pickupAction.SetCallback([](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) return; @@ -1036,9 +1037,10 @@ namespace OpenRCT2::Ui::Windows if (widgetIndex != WIDX_PICKUP) return; - PeepPickupAction pickupAction{ - PeepPickupType::Cancel, EntityId::FromUnderlying(number), { _pickedPeepX, 0, 0 }, NetworkGetCurrentPlayerId() - }; + GameActions::PeepPickupAction pickupAction{ GameActions::PeepPickupType::Cancel, + EntityId::FromUnderlying(number), + { _pickedPeepX, 0, 0 }, + NetworkGetCurrentPlayerId() }; GameActions::Execute(&pickupAction); } diff --git a/src/openrct2-ui/windows/PatrolArea.cpp b/src/openrct2-ui/windows/PatrolArea.cpp index 82e842e81b..cfcaa6c851 100644 --- a/src/openrct2-ui/windows/PatrolArea.cpp +++ b/src/openrct2-ui/windows/PatrolArea.cpp @@ -206,7 +206,8 @@ namespace OpenRCT2::Ui::Windows auto staff = GetEntity(_staffId); if (staff != nullptr) { - _mode = staff->IsPatrolAreaSet(*mapTile) ? StaffSetPatrolAreaMode::Unset : StaffSetPatrolAreaMode::Set; + _mode = staff->IsPatrolAreaSet(*mapTile) ? GameActions::StaffSetPatrolAreaMode::Unset + : GameActions::StaffSetPatrolAreaMode::Set; } } @@ -219,7 +220,7 @@ namespace OpenRCT2::Ui::Windows if (staff != nullptr) { MapRange range(gMapSelectPositionA, gMapSelectPositionB); - auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(_staffId, range, _mode); + auto staffSetPatrolAreaAction = GameActions::StaffSetPatrolAreaAction(_staffId, range, _mode); GameActions::Execute(&staffSetPatrolAreaAction); } } @@ -237,7 +238,7 @@ namespace OpenRCT2::Ui::Windows private: EntityId _staffId; - StaffSetPatrolAreaMode _mode; + GameActions::StaffSetPatrolAreaMode _mode; void EnableTool() { diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 62f920b03c..094c7cae0a 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -381,8 +381,9 @@ namespace OpenRCT2::Ui::Windows _pickedPeepOldX = staff->x; CoordsXYZ nullLoc{}; nullLoc.SetNull(); - PeepPickupAction pickupAction{ PeepPickupType::Pickup, EntityId::FromUnderlying(number), nullLoc, - NetworkGetCurrentPlayerId() }; + GameActions::PeepPickupAction pickupAction{ GameActions::PeepPickupType::Pickup, + EntityId::FromUnderlying(number), nullLoc, + NetworkGetCurrentPlayerId() }; pickupAction.SetCallback([peepnum = number](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) return; @@ -480,8 +481,8 @@ namespace OpenRCT2::Ui::Windows auto* windowMgr = Ui::GetWindowManager(); windowMgr->CloseByClass(WindowClass::PatrolArea); - auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction( - staff->Id, {}, StaffSetPatrolAreaMode::ClearAll); + auto staffSetPatrolAreaAction = GameActions::StaffSetPatrolAreaAction( + staff->Id, {}, GameActions::StaffSetPatrolAreaMode::ClearAll); GameActions::Execute(&staffSetPatrolAreaAction); } else @@ -706,9 +707,10 @@ namespace OpenRCT2::Ui::Windows if (destCoords.IsNull()) return; - PeepPickupAction pickupAction{ - PeepPickupType::Place, staffEntityId, { destCoords, tileElement->GetBaseZ() }, NetworkGetCurrentPlayerId() - }; + GameActions::PeepPickupAction pickupAction{ GameActions::PeepPickupType::Place, + staffEntityId, + { destCoords, tileElement->GetBaseZ() }, + NetworkGetCurrentPlayerId() }; pickupAction.SetCallback([](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) return; @@ -723,9 +725,10 @@ namespace OpenRCT2::Ui::Windows if (widgetIndex != WIDX_PICKUP) return; - PeepPickupAction pickupAction{ - PeepPickupType::Cancel, EntityId::FromUnderlying(number), { _pickedPeepOldX, 0, 0 }, NetworkGetCurrentPlayerId() - }; + GameActions::PeepPickupAction pickupAction{ GameActions::PeepPickupType::Cancel, + EntityId::FromUnderlying(number), + { _pickedPeepOldX, 0, 0 }, + NetworkGetCurrentPlayerId() }; GameActions::Execute(&pickupAction); } @@ -742,7 +745,7 @@ namespace OpenRCT2::Ui::Windows if (text.empty()) return; - auto gameAction = StaffSetNameAction(EntityId::FromUnderlying(number), std::string{ text }); + auto gameAction = GameActions::StaffSetNameAction(EntityId::FromUnderlying(number), std::string{ text }); GameActions::Execute(&gameAction); } #pragma endregion @@ -812,7 +815,7 @@ namespace OpenRCT2::Ui::Windows return; ObjectEntryIndex costume = _availableCostumes[dropdownIndex].index; - auto staffSetCostumeAction = StaffSetCostumeAction(EntityId::FromUnderlying(number), costume); + auto staffSetCostumeAction = GameActions::StaffSetCostumeAction(EntityId::FromUnderlying(number), costume); GameActions::Execute(&staffSetCostumeAction); } @@ -1099,7 +1102,7 @@ namespace OpenRCT2::Ui::Windows } uint8_t newOrders = staff->StaffOrders ^ (1 << orderId); - auto staffSetOrdersAction = StaffSetOrdersAction(EntityId::FromUnderlying(number), newOrders); + auto staffSetOrdersAction = GameActions::StaffSetOrdersAction(EntityId::FromUnderlying(number), newOrders); GameActions::Execute(&staffSetOrdersAction); } diff --git a/src/openrct2-ui/windows/StaffFirePrompt.cpp b/src/openrct2-ui/windows/StaffFirePrompt.cpp index d281112fc4..192f779d37 100644 --- a/src/openrct2-ui/windows/StaffFirePrompt.cpp +++ b/src/openrct2-ui/windows/StaffFirePrompt.cpp @@ -61,7 +61,7 @@ namespace OpenRCT2::Ui::Windows { case WIDX_YES: { - auto staffFireAction = StaffFireAction(EntityId::FromUnderlying(number)); + auto staffFireAction = GameActions::StaffFireAction(EntityId::FromUnderlying(number)); GameActions::Execute(&staffFireAction); break; } diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 4feb486dd7..66ead3e95e 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -232,7 +232,8 @@ namespace OpenRCT2::Ui::Windows } if (widgetIndex == WIDX_STAFF_LIST_UNIFORM_COLOUR_PICKER) { - auto action = StaffSetColourAction(GetSelectedStaffType(), ColourDropDownIndexToColour(dropdownIndex)); + auto action = GameActions::StaffSetColourAction( + GetSelectedStaffType(), ColourDropDownIndexToColour(dropdownIndex)); GameActions::Execute(&action); } } @@ -341,7 +342,7 @@ namespace OpenRCT2::Ui::Windows { if (_quickFireMode) { - auto staffFireAction = StaffFireAction(entry.Id); + auto staffFireAction = GameActions::StaffFireAction(entry.Id); GameActions::Execute(&staffFireAction); } else @@ -536,12 +537,12 @@ namespace OpenRCT2::Ui::Windows else costume = findPeepAnimationsIndexForType(animPeepType); - auto hireStaffAction = StaffHireNewAction(autoPosition, staffType, costume, staffOrders); + auto hireStaffAction = GameActions::StaffHireNewAction(autoPosition, staffType, costume, staffOrders); hireStaffAction.SetCallback([=](const GameAction*, const GameActions::Result* res) -> void { if (res->Error != GameActions::Status::Ok) return; - auto actionResult = res->GetData(); + auto actionResult = res->GetData(); auto* staff = GetEntity(actionResult.StaffEntityId); if (staff == nullptr) return; @@ -552,7 +553,8 @@ namespace OpenRCT2::Ui::Windows CoordsXYZ nullLoc{}; nullLoc.SetNull(); - PeepPickupAction pickupAction{ PeepPickupType::Pickup, staff->Id, nullLoc, NetworkGetCurrentPlayerId() }; + GameActions::PeepPickupAction pickupAction{ GameActions::PeepPickupType::Pickup, staff->Id, nullLoc, + NetworkGetCurrentPlayerId() }; pickupAction.SetCallback([staffId = staff->Id](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) return; diff --git a/src/openrct2/actions/PeepPickupAction.cpp b/src/openrct2/actions/PeepPickupAction.cpp index 68930945e3..e4f0c2a308 100644 --- a/src/openrct2/actions/PeepPickupAction.cpp +++ b/src/openrct2/actions/PeepPickupAction.cpp @@ -15,191 +15,192 @@ #include "../entity/Peep.h" #include "../network/Network.h" -using namespace OpenRCT2; - -PeepPickupAction::PeepPickupAction(PeepPickupType type, EntityId entityId, const CoordsXYZ& loc, NetworkPlayerId_t owner) - : _type(type) - , _entityId(entityId) - , _loc(loc) - , _owner(owner) +namespace OpenRCT2::GameActions { -} - -void PeepPickupAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("type", _type); - visitor.Visit("id", _entityId); - visitor.Visit(_loc); - visitor.Visit("playerId", _owner); -} - -uint16_t PeepPickupAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void PeepPickupAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_type) << DS_TAG(_entityId) << DS_TAG(_loc) << DS_TAG(_owner); -} - -GameActions::Result PeepPickupAction::Query() const -{ - if (_entityId.ToUnderlying() >= kMaxEntities || _entityId.IsNull()) + PeepPickupAction::PeepPickupAction(PeepPickupType type, EntityId entityId, const CoordsXYZ& loc, NetworkPlayerId_t owner) + : _type(type) + , _entityId(entityId) + , _loc(loc) + , _owner(owner) { - LOG_ERROR("Failed to pick up peep for sprite %d", _entityId); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); } - if (!_loc.IsNull() && !LocationValid(_loc)) + void PeepPickupAction::AcceptParameters(GameActionParameterVisitor& visitor) { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); + visitor.Visit("type", _type); + visitor.Visit("id", _entityId); + visitor.Visit(_loc); + visitor.Visit("playerId", _owner); } - auto* const peep = TryGetEntity(_entityId); - if (peep == nullptr) + uint16_t PeepPickupAction::GetActionFlags() const { - LOG_ERROR("Failed to pick up peep for sprite %d", _entityId); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; } - auto res = GameActions::Result(); - - switch (_type) + void PeepPickupAction::Serialise(DataSerialiser& stream) { - case PeepPickupType::Pickup: + GameAction::Serialise(stream); + + stream << DS_TAG(_type) << DS_TAG(_entityId) << DS_TAG(_loc) << DS_TAG(_owner); + } + + Result PeepPickupAction::Query() const + { + if (_entityId.ToUnderlying() >= kMaxEntities || _entityId.IsNull()) { - res.Position = peep->GetLocation(); - if (!peep->CanBePickedUp()) - { - return GameActions::Result(GameActions::Status::Disallowed, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); - } - Peep* existing = NetworkGetPickupPeep(_owner); - if (existing != nullptr) - { - // already picking up a peep - PeepPickupAction existingPickupAction{ - PeepPickupType::Cancel, existing->Id, { NetworkGetPickupPeepOldX(_owner), 0, 0 }, _owner - }; - auto result = GameActions::QueryNested(&existingPickupAction); + LOG_ERROR("Failed to pick up peep for sprite %d", _entityId); + return Result(Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); + } - if (existing == peep) + if (!_loc.IsNull() && !LocationValid(_loc)) + { + return Result(Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); + } + + auto* const peep = TryGetEntity(_entityId); + if (peep == nullptr) + { + LOG_ERROR("Failed to pick up peep for sprite %d", _entityId); + return Result(Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); + } + + auto res = Result(); + + switch (_type) + { + case PeepPickupType::Pickup: + { + res.Position = peep->GetLocation(); + if (!peep->CanBePickedUp()) { - return result; + return Result(Status::Disallowed, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); + } + Peep* existing = NetworkGetPickupPeep(_owner); + if (existing != nullptr) + { + // already picking up a peep + PeepPickupAction existingPickupAction{ + PeepPickupType::Cancel, existing->Id, { NetworkGetPickupPeepOldX(_owner), 0, 0 }, _owner + }; + auto result = QueryNested(&existingPickupAction); + + if (existing == peep) + { + return result; + } } } - } - break; - case PeepPickupType::Cancel: - res.Position = peep->GetLocation(); break; - case PeepPickupType::Place: - res.Position = _loc; - if (NetworkGetPickupPeep(_owner) != peep) - { - return GameActions::Result(GameActions::Status::Unknown, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); - } - - if (auto res2 = peep->Place(TileCoordsXYZ(_loc), false); res2.Error != GameActions::Status::Ok) - { - return res2; - } - break; - default: - LOG_ERROR("Invalid peep pickup type %u", _type); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); - } - return res; -} - -GameActions::Result PeepPickupAction::Execute() const -{ - Peep* const peep = TryGetEntity(_entityId); - if (peep == nullptr) - { - LOG_ERROR("Failed to pick up peep for sprite %d", _entityId); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); - } - - auto res = GameActions::Result(); - - switch (_type) - { - case PeepPickupType::Pickup: - { - res.Position = peep->GetLocation(); - - Peep* existing = NetworkGetPickupPeep(_owner); - if (existing != nullptr) - { - // already picking up a peep - PeepPickupAction existingPickupAction{ - PeepPickupType::Cancel, existing->Id, { NetworkGetPickupPeepOldX(_owner), 0, 0 }, _owner - }; - auto result = GameActions::ExecuteNested(&existingPickupAction); - - if (existing == peep) + case PeepPickupType::Cancel: + res.Position = peep->GetLocation(); + break; + case PeepPickupType::Place: + res.Position = _loc; + if (NetworkGetPickupPeep(_owner) != peep) { - return result; + return Result(Status::Unknown, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); } - if (_owner == NetworkGetCurrentPlayerId()) + + if (auto res2 = peep->Place(TileCoordsXYZ(_loc), false); res2.Error != Status::Ok) { - // prevent tool_cancel() - gInputFlags.unset(InputFlag::toolActive); + return res2; } - } - - NetworkSetPickupPeep(_owner, peep); - NetworkSetPickupPeepOldX(_owner, peep->x); - peep->Pickup(); + break; + default: + LOG_ERROR("Invalid peep pickup type %u", _type); + return Result(Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); } - break; - case PeepPickupType::Cancel: - { - res.Position = peep->GetLocation(); - - Peep* const pickedUpPeep = NetworkGetPickupPeep(_owner); - if (pickedUpPeep != nullptr) - { - pickedUpPeep->PickupAbort(_loc.x); - } - NetworkSetPickupPeep(_owner, nullptr); - } - break; - case PeepPickupType::Place: - res.Position = _loc; - if (auto res2 = peep->Place(TileCoordsXYZ(_loc), true); res2.Error != GameActions::Status::Ok) - { - return res2; - } - CancelConcurrentPickups(peep); - break; - default: - LOG_ERROR("Invalid peep pickup type %u", _type); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); + return res; } - return res; -} -void PeepPickupAction::CancelConcurrentPickups(Peep* pickedPeep) const -{ - // This part is only relevant in multiplayer games. - if (NetworkGetMode() == NETWORK_MODE_NONE) - return; + Result PeepPickupAction::Execute() const + { + Peep* const peep = TryGetEntity(_entityId); + if (peep == nullptr) + { + LOG_ERROR("Failed to pick up peep for sprite %d", _entityId); + return Result(Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); + } - // Not relevant for owner, owner gets to place it normally. - NetworkPlayerId_t currentPlayerId = NetworkGetCurrentPlayerId(); - if (currentPlayerId == _owner) - return; + auto res = Result(); - Peep* peep = NetworkGetPickupPeep(NetworkGetCurrentPlayerId()); - if (peep != pickedPeep) - return; + switch (_type) + { + case PeepPickupType::Pickup: + { + res.Position = peep->GetLocation(); - // By assigning the peep to null before calling tool_cancel we can avoid - // resetting the peep to the initial position. - NetworkSetPickupPeep(currentPlayerId, nullptr); - ToolCancel(); -} + Peep* existing = NetworkGetPickupPeep(_owner); + if (existing != nullptr) + { + // already picking up a peep + PeepPickupAction existingPickupAction{ + PeepPickupType::Cancel, existing->Id, { NetworkGetPickupPeepOldX(_owner), 0, 0 }, _owner + }; + auto result = ExecuteNested(&existingPickupAction); + + if (existing == peep) + { + return result; + } + if (_owner == NetworkGetCurrentPlayerId()) + { + // prevent tool_cancel() + gInputFlags.unset(InputFlag::toolActive); + } + } + + NetworkSetPickupPeep(_owner, peep); + NetworkSetPickupPeepOldX(_owner, peep->x); + peep->Pickup(); + } + break; + case PeepPickupType::Cancel: + { + res.Position = peep->GetLocation(); + + Peep* const pickedUpPeep = NetworkGetPickupPeep(_owner); + if (pickedUpPeep != nullptr) + { + pickedUpPeep->PickupAbort(_loc.x); + } + NetworkSetPickupPeep(_owner, nullptr); + } + break; + case PeepPickupType::Place: + res.Position = _loc; + if (auto res2 = peep->Place(TileCoordsXYZ(_loc), true); res2.Error != Status::Ok) + { + return res2; + } + CancelConcurrentPickups(peep); + break; + default: + LOG_ERROR("Invalid peep pickup type %u", _type); + return Result(Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, kStringIdNone); + } + return res; + } + + void PeepPickupAction::CancelConcurrentPickups(Peep* pickedPeep) const + { + // This part is only relevant in multiplayer games. + if (NetworkGetMode() == NETWORK_MODE_NONE) + return; + + // Not relevant for owner, owner gets to place it normally. + NetworkPlayerId_t currentPlayerId = NetworkGetCurrentPlayerId(); + if (currentPlayerId == _owner) + return; + + Peep* peep = NetworkGetPickupPeep(NetworkGetCurrentPlayerId()); + if (peep != pickedPeep) + return; + + // By assigning the peep to null before calling tool_cancel we can avoid + // resetting the peep to the initial position. + NetworkSetPickupPeep(currentPlayerId, nullptr); + ToolCancel(); + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/PeepPickupAction.h b/src/openrct2/actions/PeepPickupAction.h index 82c7b94c7f..903a15d7a7 100644 --- a/src/openrct2/actions/PeepPickupAction.h +++ b/src/openrct2/actions/PeepPickupAction.h @@ -12,34 +12,37 @@ #include "../Identifiers.h" #include "GameAction.h" -enum class PeepPickupType : uint8_t +namespace OpenRCT2::GameActions { - Pickup, - Cancel, - Place, - Count -}; + enum class PeepPickupType : uint8_t + { + Pickup, + Cancel, + Place, + Count + }; -class PeepPickupAction final : public GameActionBase -{ -private: - PeepPickupType _type{ PeepPickupType::Count }; - EntityId _entityId{ EntityId::GetNull() }; - CoordsXYZ _loc; - NetworkPlayerId_t _owner{ -1 }; + class PeepPickupAction final : public GameActionBase + { + private: + PeepPickupType _type{ PeepPickupType::Count }; + EntityId _entityId{ EntityId::GetNull() }; + CoordsXYZ _loc; + NetworkPlayerId_t _owner{ -1 }; -public: - PeepPickupAction() = default; - PeepPickupAction(PeepPickupType type, EntityId entityId, const CoordsXYZ& loc, NetworkPlayerId_t owner); + public: + PeepPickupAction() = default; + PeepPickupAction(PeepPickupType type, EntityId entityId, const CoordsXYZ& loc, NetworkPlayerId_t owner); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; -private: - void CancelConcurrentPickups(Peep* pickedPeep) const; -}; + private: + void CancelConcurrentPickups(Peep* pickedPeep) const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffFireAction.cpp b/src/openrct2/actions/StaffFireAction.cpp index 1d055eecf0..5cc4830379 100644 --- a/src/openrct2/actions/StaffFireAction.cpp +++ b/src/openrct2/actions/StaffFireAction.cpp @@ -14,72 +14,72 @@ #include "../entity/Staff.h" #include "../ui/WindowManager.h" -using namespace OpenRCT2; - -StaffFireAction::StaffFireAction(EntityId spriteId) - : _spriteId(spriteId) +namespace OpenRCT2::GameActions { -} - -void StaffFireAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("id", _spriteId); -} - -uint16_t StaffFireAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void StaffFireAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - stream << DS_TAG(_spriteId); -} - -GameActions::Result StaffFireAction::Query() const -{ - if (_spriteId.ToUnderlying() >= kMaxEntities || _spriteId.IsNull()) + StaffFireAction::StaffFireAction(EntityId spriteId) + : _spriteId(spriteId) { - LOG_ERROR("Invalid spriteId %u", _spriteId); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); } - auto staff = TryGetEntity(_spriteId); - if (staff == nullptr) + void StaffFireAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Staff entity not found for spriteId %u", _spriteId); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + visitor.Visit("id", _spriteId); } - if (staff->State == PeepState::Fixing) + uint16_t StaffFireAction::GetActionFlags() const { - return GameActions::Result(GameActions::Status::Disallowed, STR_CANT_FIRE_STAFF_FIXING, kStringIdNone); - } - else if (staff->State == PeepState::Inspecting) - { - return GameActions::Result(GameActions::Status::Disallowed, STR_CANT_FIRE_STAFF_INSPECTING, kStringIdNone); + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; } - return GameActions::Result(); -} - -GameActions::Result StaffFireAction::Execute() const -{ - auto staff = TryGetEntity(_spriteId); - if (staff == nullptr) + void StaffFireAction::Serialise(DataSerialiser& stream) { - LOG_ERROR("Staff entity not found for spriteId %u", _spriteId); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + GameAction::Serialise(stream); + stream << DS_TAG(_spriteId); } - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->CloseByClass(WindowClass::FirePrompt); + Result StaffFireAction::Query() const + { + if (_spriteId.ToUnderlying() >= kMaxEntities || _spriteId.IsNull()) + { + LOG_ERROR("Invalid spriteId %u", _spriteId); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); + } - PeepEntityRemove(staff); - // Due to patrol areas best to invalidate the whole screen on removal of staff - GfxInvalidateScreen(); + auto staff = TryGetEntity(_spriteId); + if (staff == nullptr) + { + LOG_ERROR("Staff entity not found for spriteId %u", _spriteId); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + } - return GameActions::Result(); -} + if (staff->State == PeepState::Fixing) + { + return Result(Status::Disallowed, STR_CANT_FIRE_STAFF_FIXING, kStringIdNone); + } + else if (staff->State == PeepState::Inspecting) + { + return Result(Status::Disallowed, STR_CANT_FIRE_STAFF_INSPECTING, kStringIdNone); + } + + return Result(); + } + + Result StaffFireAction::Execute() const + { + auto staff = TryGetEntity(_spriteId); + if (staff == nullptr) + { + LOG_ERROR("Staff entity not found for spriteId %u", _spriteId); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + } + + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->CloseByClass(WindowClass::FirePrompt); + + PeepEntityRemove(staff); + // Due to patrol areas best to invalidate the whole screen on removal of staff + GfxInvalidateScreen(); + + return Result(); + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffFireAction.h b/src/openrct2/actions/StaffFireAction.h index 276a4e0793..00e9a2d910 100644 --- a/src/openrct2/actions/StaffFireAction.h +++ b/src/openrct2/actions/StaffFireAction.h @@ -11,20 +11,23 @@ #include "GameAction.h" -class StaffFireAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - EntityId _spriteId{ EntityId::GetNull() }; + class StaffFireAction final : public GameActionBase + { + private: + EntityId _spriteId{ EntityId::GetNull() }; -public: - StaffFireAction() = default; - StaffFireAction(EntityId spriteId); + public: + StaffFireAction() = default; + StaffFireAction(EntityId spriteId); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; -}; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffHireNewAction.cpp b/src/openrct2/actions/StaffHireNewAction.cpp index 7d5a3e4948..2da9417bbe 100644 --- a/src/openrct2/actions/StaffHireNewAction.cpp +++ b/src/openrct2/actions/StaffHireNewAction.cpp @@ -30,275 +30,275 @@ #include -using namespace OpenRCT2; - -StaffHireNewAction::StaffHireNewAction( - bool autoPosition, StaffType staffType, ObjectEntryIndex costumeIndex, uint32_t staffOrders) - : _autoPosition(autoPosition) - , _staffType(static_cast(staffType)) - , _costumeIndex(costumeIndex) - , _staffOrders(staffOrders) +namespace OpenRCT2::GameActions { -} - -void StaffHireNewAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("autoPosition", _autoPosition); - visitor.Visit("staffType", _staffType); - visitor.Visit("costumeIndex", _costumeIndex); - visitor.Visit("staffOrders", _staffOrders); -} - -uint16_t StaffHireNewAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void StaffHireNewAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_autoPosition) << DS_TAG(_staffType) << DS_TAG(_costumeIndex) << DS_TAG(_staffOrders); -} - -GameActions::Result StaffHireNewAction::Query() const -{ - return QueryExecute(false); -} - -GameActions::Result StaffHireNewAction::Execute() const -{ - return QueryExecute(true); -} - -GameActions::Result StaffHireNewAction::QueryExecute(bool execute) const -{ - auto res = GameActions::Result(); - res.Expenditure = ExpenditureType::wages; - - if (_staffType >= static_cast(StaffType::Count)) + StaffHireNewAction::StaffHireNewAction( + bool autoPosition, StaffType staffType, ObjectEntryIndex costumeIndex, uint32_t staffOrders) + : _autoPosition(autoPosition) + , _staffType(static_cast(staffType)) + , _costumeIndex(costumeIndex) + , _staffOrders(staffOrders) { - LOG_ERROR("Invalid staff type %u", static_cast(_staffType)); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_ERR_VALUE_OUT_OF_RANGE); } - if (GetNumFreeEntities() < 400) + void StaffHireNewAction::AcceptParameters(GameActionParameterVisitor& visitor) { - return GameActions::Result(GameActions::Status::NoFreeElements, STR_CANT_HIRE_NEW_STAFF, STR_TOO_MANY_PEOPLE_IN_GAME); + visitor.Visit("autoPosition", _autoPosition); + visitor.Visit("staffType", _staffType); + visitor.Visit("costumeIndex", _costumeIndex); + visitor.Visit("staffOrders", _staffOrders); } - if (_staffType == static_cast(StaffType::Entertainer)) + uint16_t StaffHireNewAction::GetActionFlags() const { - auto costumes = findAllPeepAnimationsIndexesForType(AnimationPeepType::Entertainer); - if (std::find(costumes.begin(), costumes.end(), _costumeIndex) == costumes.end()) + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; + } + + void StaffHireNewAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + + stream << DS_TAG(_autoPosition) << DS_TAG(_staffType) << DS_TAG(_costumeIndex) << DS_TAG(_staffOrders); + } + + Result StaffHireNewAction::Query() const + { + return QueryExecute(false); + } + + Result StaffHireNewAction::Execute() const + { + return QueryExecute(true); + } + + Result StaffHireNewAction::QueryExecute(bool execute) const + { + auto res = Result(); + res.Expenditure = ExpenditureType::wages; + + if (_staffType >= static_cast(StaffType::Count)) { - LOG_ERROR("Unavailable entertainer costume %u", static_cast(_costumeIndex)); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_ERR_VALUE_OUT_OF_RANGE); - } - } - - Staff* newPeep = CreateEntity(); - if (newPeep == nullptr) - { - // Too many peeps exist already. - return GameActions::Result(GameActions::Status::NoFreeElements, STR_CANT_HIRE_NEW_STAFF, STR_TOO_MANY_PEOPLE_IN_GAME); - } - - if (execute == false) - { - // In query we just want to see if we can obtain a sprite slot. - EntityRemove(newPeep); - - res.SetData(StaffHireNewActionResult{ EntityId::GetNull() }); - } - else - { - newPeep->WindowInvalidateFlags = 0; - newPeep->Action = PeepActionType::Walking; - newPeep->SpecialSprite = 0; - newPeep->AnimationImageIdOffset = 0; - newPeep->WalkingAnimationFrameNum = 0; - newPeep->AnimationType = PeepAnimationType::Walking; - newPeep->PathCheckOptimisation = 0; - newPeep->PeepFlags = 0; - newPeep->StaffLawnsMown = 0; - newPeep->StaffGardensWatered = 0; - newPeep->StaffLitterSwept = 0; - newPeep->StaffBinsEmptied = 0; - newPeep->StaffOrders = _staffOrders; - - // We search for the first available Id for a given staff type - std::set usedStaffIds; - - for (auto searchPeep : EntityList()) - { - if (static_cast(searchPeep->AssignedStaffType) != _staffType) - continue; - - usedStaffIds.insert(searchPeep->PeepId); + LOG_ERROR("Invalid staff type %u", static_cast(_staffType)); + return Result(Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_ERR_VALUE_OUT_OF_RANGE); } - uint32_t newStaffId = 1; - while (usedStaffIds.find(newStaffId) != usedStaffIds.end()) + if (GetNumFreeEntities() < 400) { - newStaffId++; + return Result(Status::NoFreeElements, STR_CANT_HIRE_NEW_STAFF, STR_TOO_MANY_PEOPLE_IN_GAME); } - newPeep->PeepId = newStaffId; - newPeep->AssignedStaffType = static_cast(_staffType); - - auto animPeepType = AnimationPeepType(static_cast(_staffType) + 1); - ObjectEntryIndex animObjectIndex = _costumeIndex; - if (animPeepType != AnimationPeepType::Entertainer) - animObjectIndex = findPeepAnimationsIndexForType(animPeepType); - - newPeep->Name = nullptr; - newPeep->AnimationObjectIndex = animObjectIndex; - newPeep->AnimationGroup = PeepAnimationGroup::Normal; - - auto& objManager = GetContext()->GetObjectManager(); - auto* animObj = objManager.GetLoadedObject(animObjectIndex); - - newPeep->PeepFlags &= ~PEEP_FLAGS_SLOW_WALK; - if (animObj->IsSlowWalking(PeepAnimationGroup::Normal)) - newPeep->PeepFlags |= PEEP_FLAGS_SLOW_WALK; - - const auto& spriteBounds = animObj->GetSpriteBounds(newPeep->AnimationGroup); - newPeep->SpriteData.Width = spriteBounds.sprite_width; - newPeep->SpriteData.HeightMin = spriteBounds.sprite_height_negative; - newPeep->SpriteData.HeightMax = spriteBounds.sprite_height_positive; - - if (_autoPosition) + if (_staffType == static_cast(StaffType::Entertainer)) { - AutoPositionNewStaff(newPeep); + auto costumes = findAllPeepAnimationsIndexesForType(AnimationPeepType::Entertainer); + if (std::find(costumes.begin(), costumes.end(), _costumeIndex) == costumes.end()) + { + LOG_ERROR("Unavailable entertainer costume %u", static_cast(_costumeIndex)); + return Result(Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_ERR_VALUE_OUT_OF_RANGE); + } + } + + Staff* newPeep = CreateEntity(); + if (newPeep == nullptr) + { + // Too many peeps exist already. + return Result(Status::NoFreeElements, STR_CANT_HIRE_NEW_STAFF, STR_TOO_MANY_PEOPLE_IN_GAME); + } + + if (execute == false) + { + // In query we just want to see if we can obtain a sprite slot. + EntityRemove(newPeep); + + res.SetData(StaffHireNewActionResult{ EntityId::GetNull() }); } else { - // NOTE: This state is required for the window to act. - newPeep->State = PeepState::Picked; + newPeep->WindowInvalidateFlags = 0; + newPeep->Action = PeepActionType::Walking; + newPeep->SpecialSprite = 0; + newPeep->AnimationImageIdOffset = 0; + newPeep->WalkingAnimationFrameNum = 0; + newPeep->AnimationType = PeepAnimationType::Walking; + newPeep->PathCheckOptimisation = 0; + newPeep->PeepFlags = 0; + newPeep->StaffLawnsMown = 0; + newPeep->StaffGardensWatered = 0; + newPeep->StaffLitterSwept = 0; + newPeep->StaffBinsEmptied = 0; + newPeep->StaffOrders = _staffOrders; - // INVESTIGATE: x and y are LOCATION_NULL at this point. - newPeep->MoveTo(newPeep->GetLocation()); - } + // We search for the first available Id for a given staff type + std::set usedStaffIds; - // Staff uses this - newPeep->As()->SetHireDate(GetDate().GetMonthsElapsed()); - newPeep->PathfindGoal.x = 0xFF; - newPeep->PathfindGoal.y = 0xFF; - newPeep->PathfindGoal.z = 0xFF; - newPeep->PathfindGoal.direction = kInvalidDirection; - - uint8_t colour = StaffGetColour(static_cast(_staffType)); - newPeep->TshirtColour = colour; - newPeep->TrousersColour = colour; - - // Staff energy determines their walking speed - switch (getGameState().cheats.selectedStaffSpeed) - { - case StaffSpeedCheat::None: - newPeep->Energy = kCheatsStaffNormalSpeed; - newPeep->EnergyTarget = kCheatsStaffNormalSpeed; - break; - - case StaffSpeedCheat::Frozen: - newPeep->Energy = kCheatsStaffFreezeSpeed; - newPeep->EnergyTarget = kCheatsStaffFreezeSpeed; - break; - - case StaffSpeedCheat::Fast: - newPeep->Energy = kCheatsStaffFastSpeed; - newPeep->EnergyTarget = kCheatsStaffFastSpeed; - break; - } - - newPeep->StaffMowingTimeout = 0; - newPeep->PatrolInfo = nullptr; - - res.SetData(StaffHireNewActionResult{ newPeep->Id }); - } - - return res; -} - -void StaffHireNewAction::AutoPositionNewStaff(Peep* newPeep) const -{ - // Find a location to place new staff member - newPeep->State = PeepState::Falling; - - uint32_t count = 0; - PathElement* guest_tile = nullptr; - - // Count number of walking guests - { - for (auto guest : EntityList()) - { - if (guest->State == PeepState::Walking) + for (auto searchPeep : EntityList()) { - // Check the walking guest's tile. Only count them if they're on a path tile. - guest_tile = MapGetPathElementAt(TileCoordsXYZ{ guest->NextLoc }); - if (guest_tile != nullptr) - ++count; + if (static_cast(searchPeep->AssignedStaffType) != _staffType) + continue; + + usedStaffIds.insert(searchPeep->PeepId); } + + uint32_t newStaffId = 1; + while (usedStaffIds.find(newStaffId) != usedStaffIds.end()) + { + newStaffId++; + } + + newPeep->PeepId = newStaffId; + newPeep->AssignedStaffType = static_cast(_staffType); + + auto animPeepType = AnimationPeepType(static_cast(_staffType) + 1); + ObjectEntryIndex animObjectIndex = _costumeIndex; + if (animPeepType != AnimationPeepType::Entertainer) + animObjectIndex = findPeepAnimationsIndexForType(animPeepType); + + newPeep->Name = nullptr; + newPeep->AnimationObjectIndex = animObjectIndex; + newPeep->AnimationGroup = PeepAnimationGroup::Normal; + + auto& objManager = GetContext()->GetObjectManager(); + auto* animObj = objManager.GetLoadedObject(animObjectIndex); + + newPeep->PeepFlags &= ~PEEP_FLAGS_SLOW_WALK; + if (animObj->IsSlowWalking(PeepAnimationGroup::Normal)) + newPeep->PeepFlags |= PEEP_FLAGS_SLOW_WALK; + + const auto& spriteBounds = animObj->GetSpriteBounds(newPeep->AnimationGroup); + newPeep->SpriteData.Width = spriteBounds.sprite_width; + newPeep->SpriteData.HeightMin = spriteBounds.sprite_height_negative; + newPeep->SpriteData.HeightMax = spriteBounds.sprite_height_positive; + + if (_autoPosition) + { + AutoPositionNewStaff(newPeep); + } + else + { + // NOTE: This state is required for the window to act. + newPeep->State = PeepState::Picked; + + // INVESTIGATE: x and y are LOCATION_NULL at this point. + newPeep->MoveTo(newPeep->GetLocation()); + } + + // Staff uses this + newPeep->As()->SetHireDate(GetDate().GetMonthsElapsed()); + newPeep->PathfindGoal.x = 0xFF; + newPeep->PathfindGoal.y = 0xFF; + newPeep->PathfindGoal.z = 0xFF; + newPeep->PathfindGoal.direction = kInvalidDirection; + + uint8_t colour = StaffGetColour(static_cast(_staffType)); + newPeep->TshirtColour = colour; + newPeep->TrousersColour = colour; + + // Staff energy determines their walking speed + switch (getGameState().cheats.selectedStaffSpeed) + { + case StaffSpeedCheat::None: + newPeep->Energy = kCheatsStaffNormalSpeed; + newPeep->EnergyTarget = kCheatsStaffNormalSpeed; + break; + + case StaffSpeedCheat::Frozen: + newPeep->Energy = kCheatsStaffFreezeSpeed; + newPeep->EnergyTarget = kCheatsStaffFreezeSpeed; + break; + + case StaffSpeedCheat::Fast: + newPeep->Energy = kCheatsStaffFastSpeed; + newPeep->EnergyTarget = kCheatsStaffFastSpeed; + break; + } + + newPeep->StaffMowingTimeout = 0; + newPeep->PatrolInfo = nullptr; + + res.SetData(StaffHireNewActionResult{ newPeep->Id }); } + + return res; } - CoordsXYZ newLocation{}; - if (count > 0) + void StaffHireNewAction::AutoPositionNewStaff(Peep* newPeep) const { - // Place staff at a random guest - uint32_t rand = ScenarioRandMax(count); - Guest* chosenGuest = nullptr; + // Find a location to place new staff member + newPeep->State = PeepState::Falling; - for (auto guest : EntityList()) + uint32_t count = 0; + PathElement* guest_tile = nullptr; + + // Count number of walking guests { - if (guest->State == PeepState::Walking) + for (auto guest : EntityList()) { - guest_tile = MapGetPathElementAt(TileCoordsXYZ{ guest->NextLoc }); - if (guest_tile != nullptr) + if (guest->State == PeepState::Walking) { - if (rand == 0) - { - chosenGuest = guest; - break; - } - --rand; + // Check the walking guest's tile. Only count them if they're on a path tile. + guest_tile = MapGetPathElementAt(TileCoordsXYZ{ guest->NextLoc }); + if (guest_tile != nullptr) + ++count; } } } - if (chosenGuest != nullptr) + CoordsXYZ newLocation{}; + if (count > 0) { - newLocation = chosenGuest->GetLocation(); - } - else - { - // User must pick a location - newPeep->State = PeepState::Picked; - newLocation = newPeep->GetLocation(); - } - } - else - { - // No walking guests; pick random park entrance - const auto& park = getGameState().park; - if (!park.entrances.empty()) - { - auto rand = ScenarioRandMax(static_cast(park.entrances.size())); - const auto& entrance = park.entrances[rand]; - auto dir = entrance.direction; - newLocation = entrance; - // TODO: Replace with CoordsDirectionDelta - newLocation.x += 16 + ((dir & 1) == 0 ? ((dir & 2) ? 32 : -32) : 0); - newLocation.y += 16 + ((dir & 1) == 1 ? ((dir & 2) ? -32 : 32) : 0); - } - else - { - // User must pick a location - newPeep->State = PeepState::Picked; - newLocation = newPeep->GetLocation(); - } - } + // Place staff at a random guest + uint32_t rand = ScenarioRandMax(count); + Guest* chosenGuest = nullptr; - newPeep->MoveTo(newLocation + CoordsXYZ{ 0, 0, 16 }); -} + for (auto guest : EntityList()) + { + if (guest->State == PeepState::Walking) + { + guest_tile = MapGetPathElementAt(TileCoordsXYZ{ guest->NextLoc }); + if (guest_tile != nullptr) + { + if (rand == 0) + { + chosenGuest = guest; + break; + } + --rand; + } + } + } + + if (chosenGuest != nullptr) + { + newLocation = chosenGuest->GetLocation(); + } + else + { + // User must pick a location + newPeep->State = PeepState::Picked; + newLocation = newPeep->GetLocation(); + } + } + else + { + // No walking guests; pick random park entrance + const auto& park = getGameState().park; + if (!park.entrances.empty()) + { + auto rand = ScenarioRandMax(static_cast(park.entrances.size())); + const auto& entrance = park.entrances[rand]; + auto dir = entrance.direction; + newLocation = entrance; + // TODO: Replace with CoordsDirectionDelta + newLocation.x += 16 + ((dir & 1) == 0 ? ((dir & 2) ? 32 : -32) : 0); + newLocation.y += 16 + ((dir & 1) == 1 ? ((dir & 2) ? -32 : 32) : 0); + } + else + { + // User must pick a location + newPeep->State = PeepState::Picked; + newLocation = newPeep->GetLocation(); + } + } + + newPeep->MoveTo(newLocation + CoordsXYZ{ 0, 0, 16 }); + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffHireNewAction.h b/src/openrct2/actions/StaffHireNewAction.h index 3c1cfd228f..5040d33b9a 100644 --- a/src/openrct2/actions/StaffHireNewAction.h +++ b/src/openrct2/actions/StaffHireNewAction.h @@ -12,32 +12,35 @@ #include "../entity/Staff.h" #include "GameAction.h" -struct StaffHireNewActionResult +namespace OpenRCT2::GameActions { - EntityId StaffEntityId = EntityId::GetNull(); -}; + struct StaffHireNewActionResult + { + EntityId StaffEntityId = EntityId::GetNull(); + }; -class StaffHireNewAction final : public GameActionBase -{ -private: - bool _autoPosition{}; - uint8_t _staffType{ EnumValue(StaffType::Count) }; - OpenRCT2::ObjectEntryIndex _costumeIndex; - uint32_t _staffOrders{}; + class StaffHireNewAction final : public GameActionBase + { + private: + bool _autoPosition{}; + uint8_t _staffType{ EnumValue(StaffType::Count) }; + ObjectEntryIndex _costumeIndex; + uint32_t _staffOrders{}; -public: - StaffHireNewAction() = default; - StaffHireNewAction(bool autoPosition, StaffType staffType, OpenRCT2::ObjectEntryIndex costumeIndex, uint32_t staffOrders); + public: + StaffHireNewAction() = default; + StaffHireNewAction(bool autoPosition, StaffType staffType, ObjectEntryIndex costumeIndex, uint32_t staffOrders); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; -private: - OpenRCT2::GameActions::Result QueryExecute(bool execute) const; - void AutoPositionNewStaff(Peep* newPeep) const; -}; + private: + Result QueryExecute(bool execute) const; + void AutoPositionNewStaff(Peep* newPeep) const; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffSetColourAction.cpp b/src/openrct2/actions/StaffSetColourAction.cpp index aa083d5203..3400462ed9 100644 --- a/src/openrct2/actions/StaffSetColourAction.cpp +++ b/src/openrct2/actions/StaffSetColourAction.cpp @@ -19,62 +19,62 @@ #include "../ui/WindowManager.h" #include "../windows/Intent.h" -using namespace OpenRCT2; - -StaffSetColourAction::StaffSetColourAction(StaffType staffType, uint8_t colour) - : _staffType(static_cast(staffType)) - , _colour(colour) +namespace OpenRCT2::GameActions { -} - -void StaffSetColourAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("staffType", _staffType); - visitor.Visit("colour", _colour); -} - -uint16_t StaffSetColourAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void StaffSetColourAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - stream << DS_TAG(_staffType) << DS_TAG(_colour); -} - -GameActions::Result StaffSetColourAction::Query() const -{ - auto staffType = static_cast(_staffType); - if (staffType != StaffType::Handyman && staffType != StaffType::Mechanic && staffType != StaffType::Security) + StaffSetColourAction::StaffSetColourAction(StaffType staffType, uint8_t colour) + : _staffType(static_cast(staffType)) + , _colour(colour) { - LOG_ERROR("Staff color can't be changed for staff type %d", _staffType); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_ACTION_INVALID_FOR_THAT_STAFF_TYPE); - } - return GameActions::Result(); -} - -GameActions::Result StaffSetColourAction::Execute() const -{ - // Update global uniform colour property - auto res = StaffSetColour(static_cast(_staffType), _colour); - if (res.Error != GameActions::Status::Ok) - { - return res; } - // Update each staff member's uniform - for (auto peep : EntityList()) + void StaffSetColourAction::AcceptParameters(GameActionParameterVisitor& visitor) { - if (peep->AssignedStaffType == static_cast(_staffType)) + visitor.Visit("staffType", _staffType); + visitor.Visit("colour", _colour); + } + + uint16_t StaffSetColourAction::GetActionFlags() const + { + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; + } + + void StaffSetColourAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + stream << DS_TAG(_staffType) << DS_TAG(_colour); + } + + Result StaffSetColourAction::Query() const + { + auto staffType = static_cast(_staffType); + if (staffType != StaffType::Handyman && staffType != StaffType::Mechanic && staffType != StaffType::Security) { - peep->TshirtColour = _colour; - peep->TrousersColour = _colour; + LOG_ERROR("Staff color can't be changed for staff type %d", _staffType); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_ACTION_INVALID_FOR_THAT_STAFF_TYPE); } + return Result(); } - GfxInvalidateScreen(); - return GameActions::Result(); -} + Result StaffSetColourAction::Execute() const + { + // Update global uniform colour property + auto res = StaffSetColour(static_cast(_staffType), _colour); + if (res.Error != Status::Ok) + { + return res; + } + + // Update each staff member's uniform + for (auto peep : EntityList()) + { + if (peep->AssignedStaffType == static_cast(_staffType)) + { + peep->TshirtColour = _colour; + peep->TrousersColour = _colour; + } + } + + GfxInvalidateScreen(); + return Result(); + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffSetColourAction.h b/src/openrct2/actions/StaffSetColourAction.h index 2fc990fd69..2ee3787814 100644 --- a/src/openrct2/actions/StaffSetColourAction.h +++ b/src/openrct2/actions/StaffSetColourAction.h @@ -12,21 +12,24 @@ #include "../entity/Staff.h" #include "GameAction.h" -class StaffSetColourAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - uint8_t _staffType{}; - uint8_t _colour{}; + class StaffSetColourAction final : public GameActionBase + { + private: + uint8_t _staffType{}; + uint8_t _colour{}; -public: - StaffSetColourAction() = default; - StaffSetColourAction(StaffType staffType, uint8_t colour); + public: + StaffSetColourAction() = default; + StaffSetColourAction(StaffType staffType, uint8_t colour); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; -}; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffSetCostumeAction.cpp b/src/openrct2/actions/StaffSetCostumeAction.cpp index 0be4fe9873..281fd34e49 100644 --- a/src/openrct2/actions/StaffSetCostumeAction.cpp +++ b/src/openrct2/actions/StaffSetCostumeAction.cpp @@ -18,92 +18,91 @@ #include "../ui/WindowManager.h" #include "../windows/Intent.h" -using namespace OpenRCT2; - -StaffSetCostumeAction::StaffSetCostumeAction(EntityId spriteIndex, ObjectEntryIndex costume) - : _spriteIndex(spriteIndex) - , _costume(costume) +namespace OpenRCT2::GameActions { -} - -void StaffSetCostumeAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("id", _spriteIndex); - visitor.Visit("costume", _costume); -} - -uint16_t StaffSetCostumeAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void StaffSetCostumeAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_spriteIndex) << DS_TAG(_costume); -} - -GameActions::Result StaffSetCostumeAction::Query() const -{ - if (_spriteIndex.ToUnderlying() >= kMaxEntities || _spriteIndex.IsNull()) + StaffSetCostumeAction::StaffSetCostumeAction(EntityId spriteIndex, ObjectEntryIndex costume) + : _spriteIndex(spriteIndex) + , _costume(costume) { - LOG_ERROR("Invalid sprite index %u", _spriteIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); } - auto* staff = TryGetEntity(_spriteIndex); - if (staff == nullptr) + void StaffSetCostumeAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + visitor.Visit("id", _spriteIndex); + visitor.Visit("costume", _costume); } - auto& objManager = GetContext()->GetObjectManager(); - auto* animObj = objManager.GetLoadedObject(_costume); - - auto animPeepType = AnimationPeepType(static_cast(staff->AssignedStaffType) + 1); - if (animObj->GetPeepType() != animPeepType) + uint16_t StaffSetCostumeAction::GetActionFlags() const { - LOG_ERROR("Invalid entertainer costume %u", _costume); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); - } - return GameActions::Result(); -} - -GameActions::Result StaffSetCostumeAction::Execute() const -{ - auto* staff = TryGetEntity(_spriteIndex); - if (staff == nullptr) - { - LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; } - staff->AnimationObjectIndex = _costume; - staff->AnimationGroup = PeepAnimationGroup::Normal; + void StaffSetCostumeAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); - auto& objManager = GetContext()->GetObjectManager(); - auto* animObj = objManager.GetLoadedObject(_costume); + stream << DS_TAG(_spriteIndex) << DS_TAG(_costume); + } - staff->PeepFlags &= ~PEEP_FLAGS_SLOW_WALK; - if (animObj->IsSlowWalking(PeepAnimationGroup::Normal)) - staff->PeepFlags |= PEEP_FLAGS_SLOW_WALK; + Result StaffSetCostumeAction::Query() const + { + if (_spriteIndex.ToUnderlying() >= kMaxEntities || _spriteIndex.IsNull()) + { + LOG_ERROR("Invalid sprite index %u", _spriteIndex); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); + } - staff->AnimationFrameNum = 0; - staff->UpdateCurrentAnimationType(); - staff->Invalidate(); + auto* staff = TryGetEntity(_spriteIndex); + if (staff == nullptr) + { + LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + } - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByNumber(WindowClass::Peep, _spriteIndex); + auto& objManager = GetContext()->GetObjectManager(); + auto* animObj = objManager.GetLoadedObject(_costume); - auto intent = Intent(INTENT_ACTION_REFRESH_STAFF_LIST); - ContextBroadcastIntent(&intent); + auto animPeepType = AnimationPeepType(static_cast(staff->AssignedStaffType) + 1); + if (animObj->GetPeepType() != animPeepType) + { + LOG_ERROR("Invalid entertainer costume %u", _costume); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); + } + return Result(); + } - auto res = GameActions::Result(); - res.Position = staff->GetLocation(); + Result StaffSetCostumeAction::Execute() const + { + auto* staff = TryGetEntity(_spriteIndex); + if (staff == nullptr) + { + LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + } - return res; -} + staff->AnimationObjectIndex = _costume; + staff->AnimationGroup = PeepAnimationGroup::Normal; + + auto& objManager = GetContext()->GetObjectManager(); + auto* animObj = objManager.GetLoadedObject(_costume); + + staff->PeepFlags &= ~PEEP_FLAGS_SLOW_WALK; + if (animObj->IsSlowWalking(PeepAnimationGroup::Normal)) + staff->PeepFlags |= PEEP_FLAGS_SLOW_WALK; + + staff->AnimationFrameNum = 0; + staff->UpdateCurrentAnimationType(); + staff->Invalidate(); + + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByNumber(WindowClass::Peep, _spriteIndex); + + auto intent = Intent(INTENT_ACTION_REFRESH_STAFF_LIST); + ContextBroadcastIntent(&intent); + + auto res = Result(); + res.Position = staff->GetLocation(); + + return res; + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffSetCostumeAction.h b/src/openrct2/actions/StaffSetCostumeAction.h index dcb353dd6f..2cdd356383 100644 --- a/src/openrct2/actions/StaffSetCostumeAction.h +++ b/src/openrct2/actions/StaffSetCostumeAction.h @@ -12,21 +12,24 @@ #include "../entity/Staff.h" #include "GameAction.h" -class StaffSetCostumeAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - EntityId _spriteIndex{ EntityId::GetNull() }; - OpenRCT2::ObjectEntryIndex _costume = OpenRCT2::kObjectEntryIndexNull; + class StaffSetCostumeAction final : public GameActionBase + { + private: + EntityId _spriteIndex{ EntityId::GetNull() }; + ObjectEntryIndex _costume = OpenRCT2::kObjectEntryIndexNull; -public: - StaffSetCostumeAction() = default; - StaffSetCostumeAction(EntityId spriteIndex, OpenRCT2::ObjectEntryIndex costume); + public: + StaffSetCostumeAction() = default; + StaffSetCostumeAction(EntityId spriteIndex, OpenRCT2::ObjectEntryIndex costume); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; -}; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffSetNameAction.cpp b/src/openrct2/actions/StaffSetNameAction.cpp index a90c49f98f..09596c3f31 100644 --- a/src/openrct2/actions/StaffSetNameAction.cpp +++ b/src/openrct2/actions/StaffSetNameAction.cpp @@ -20,80 +20,78 @@ #include "../windows/Intent.h" #include "../world/Park.h" -using namespace OpenRCT2; - -StaffSetNameAction::StaffSetNameAction(EntityId spriteIndex, const std::string& name) - : _spriteIndex(spriteIndex) - , _name(name) +namespace OpenRCT2::GameActions { -} - -void StaffSetNameAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("id", _spriteIndex); - visitor.Visit("name", _name); -} - -uint16_t StaffSetNameAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void StaffSetNameAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_spriteIndex) << DS_TAG(_name); -} - -GameActions::Result StaffSetNameAction::Query() const -{ - if (_spriteIndex.ToUnderlying() >= kMaxEntities || _spriteIndex.IsNull()) + StaffSetNameAction::StaffSetNameAction(EntityId spriteIndex, const std::string& name) + : _spriteIndex(spriteIndex) + , _name(name) { - LOG_ERROR("Invalid sprite index %u", _spriteIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER, STR_ERR_VALUE_OUT_OF_RANGE); } - auto staff = TryGetEntity(_spriteIndex); - if (staff == nullptr) + void StaffSetNameAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER, STR_ERR_STAFF_NOT_FOUND); + visitor.Visit("id", _spriteIndex); + visitor.Visit("name", _name); } - return GameActions::Result(); -} - -GameActions::Result StaffSetNameAction::Execute() const -{ - auto staff = TryGetEntity(_spriteIndex); - if (staff == nullptr) + uint16_t StaffSetNameAction::GetActionFlags() const { - LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER, STR_ERR_STAFF_NOT_FOUND); + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; } - auto curName = staff->GetName(); - if (curName == _name) + void StaffSetNameAction::Serialise(DataSerialiser& stream) { - return GameActions::Result(); + GameAction::Serialise(stream); + + stream << DS_TAG(_spriteIndex) << DS_TAG(_name); } - if (!staff->SetName(_name)) + Result StaffSetNameAction::Query() const { - return GameActions::Result(GameActions::Status::Unknown, STR_CANT_NAME_GUEST, kStringIdNone); + if (_spriteIndex.ToUnderlying() >= kMaxEntities || _spriteIndex.IsNull()) + { + LOG_ERROR("Invalid sprite index %u", _spriteIndex); + return Result(Status::InvalidParameters, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER, STR_ERR_VALUE_OUT_OF_RANGE); + } + + auto staff = TryGetEntity(_spriteIndex); + if (staff == nullptr) + { + LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); + return Result(Status::InvalidParameters, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER, STR_ERR_STAFF_NOT_FOUND); + } + + return Result(); } - GfxInvalidateScreen(); + Result StaffSetNameAction::Execute() const + { + auto staff = TryGetEntity(_spriteIndex); + if (staff == nullptr) + { + LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); + return Result(Status::InvalidParameters, STR_STAFF_ERROR_CANT_NAME_STAFF_MEMBER, STR_ERR_STAFF_NOT_FOUND); + } - auto intent = Intent(INTENT_ACTION_REFRESH_STAFF_LIST); - ContextBroadcastIntent(&intent); + auto curName = staff->GetName(); + if (curName == _name) + { + return Result(); + } - auto res = GameActions::Result(); - res.Position = staff->GetLocation(); + if (!staff->SetName(_name)) + { + return Result(Status::Unknown, STR_CANT_NAME_GUEST, kStringIdNone); + } - return res; -} + GfxInvalidateScreen(); + + auto intent = Intent(INTENT_ACTION_REFRESH_STAFF_LIST); + ContextBroadcastIntent(&intent); + + auto res = Result(); + res.Position = staff->GetLocation(); + + return res; + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffSetNameAction.h b/src/openrct2/actions/StaffSetNameAction.h index 5df2048f69..59bab0c6e7 100644 --- a/src/openrct2/actions/StaffSetNameAction.h +++ b/src/openrct2/actions/StaffSetNameAction.h @@ -11,20 +11,23 @@ #include "GameAction.h" -class StaffSetNameAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - EntityId _spriteIndex{ EntityId::GetNull() }; - std::string _name; + class StaffSetNameAction final : public GameActionBase + { + private: + EntityId _spriteIndex{ EntityId::GetNull() }; + std::string _name; -public: - StaffSetNameAction() = default; - StaffSetNameAction(EntityId spriteIndex, const std::string& name); + public: + StaffSetNameAction() = default; + StaffSetNameAction(EntityId spriteIndex, const std::string& name); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; -}; + uint16_t GetActionFlags() const override; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffSetOrdersAction.cpp b/src/openrct2/actions/StaffSetOrdersAction.cpp index 54c0d8353c..1f5f3f6a3e 100644 --- a/src/openrct2/actions/StaffSetOrdersAction.cpp +++ b/src/openrct2/actions/StaffSetOrdersAction.cpp @@ -17,70 +17,69 @@ #include "../ui/WindowManager.h" #include "../windows/Intent.h" -using namespace OpenRCT2; - -StaffSetOrdersAction::StaffSetOrdersAction(EntityId spriteIndex, uint8_t ordersId) - : _spriteIndex(spriteIndex) - , _ordersId(ordersId) +namespace OpenRCT2::GameActions { -} - -void StaffSetOrdersAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("id", _spriteIndex); - visitor.Visit("staffOrders", _ordersId); -} - -uint16_t StaffSetOrdersAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void StaffSetOrdersAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - - stream << DS_TAG(_spriteIndex) << DS_TAG(_ordersId); -} - -GameActions::Result StaffSetOrdersAction::Query() const -{ - if (_spriteIndex.ToUnderlying() >= kMaxEntities || _spriteIndex.IsNull()) + StaffSetOrdersAction::StaffSetOrdersAction(EntityId spriteIndex, uint8_t ordersId) + : _spriteIndex(spriteIndex) + , _ordersId(ordersId) { - LOG_ERROR("Invalid sprite index %u", _spriteIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); } - auto* staff = TryGetEntity(_spriteIndex); - if (staff == nullptr - || (staff->AssignedStaffType != StaffType::Handyman && staff->AssignedStaffType != StaffType::Mechanic)) + void StaffSetOrdersAction::AcceptParameters(GameActionParameterVisitor& visitor) { - LOG_ERROR("Staff orders can't be changed for staff of type %u", _spriteIndex); - return GameActions::Result( - GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_ACTION_INVALID_FOR_THAT_STAFF_TYPE); + visitor.Visit("id", _spriteIndex); + visitor.Visit("staffOrders", _ordersId); } - return GameActions::Result(); -} - -GameActions::Result StaffSetOrdersAction::Execute() const -{ - auto* staff = TryGetEntity(_spriteIndex); - if (staff == nullptr) + uint16_t StaffSetOrdersAction::GetActionFlags() const { - LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; } - staff->StaffOrders = _ordersId; - auto* windowMgr = Ui::GetWindowManager(); - windowMgr->InvalidateByNumber(WindowClass::Peep, _spriteIndex); - auto intent = Intent(INTENT_ACTION_REFRESH_STAFF_LIST); - ContextBroadcastIntent(&intent); + void StaffSetOrdersAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); - auto res = GameActions::Result(); - res.Position = staff->GetLocation(); + stream << DS_TAG(_spriteIndex) << DS_TAG(_ordersId); + } - return res; -} + Result StaffSetOrdersAction::Query() const + { + if (_spriteIndex.ToUnderlying() >= kMaxEntities || _spriteIndex.IsNull()) + { + LOG_ERROR("Invalid sprite index %u", _spriteIndex); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_VALUE_OUT_OF_RANGE); + } + + auto* staff = TryGetEntity(_spriteIndex); + if (staff == nullptr + || (staff->AssignedStaffType != StaffType::Handyman && staff->AssignedStaffType != StaffType::Mechanic)) + { + LOG_ERROR("Staff orders can't be changed for staff of type %u", _spriteIndex); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_ACTION_INVALID_FOR_THAT_STAFF_TYPE); + } + + return Result(); + } + + Result StaffSetOrdersAction::Execute() const + { + auto* staff = TryGetEntity(_spriteIndex); + if (staff == nullptr) + { + LOG_ERROR("Staff entity not found for spriteIndex %u", _spriteIndex); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + } + staff->StaffOrders = _ordersId; + + auto* windowMgr = Ui::GetWindowManager(); + windowMgr->InvalidateByNumber(WindowClass::Peep, _spriteIndex); + auto intent = Intent(INTENT_ACTION_REFRESH_STAFF_LIST); + ContextBroadcastIntent(&intent); + + auto res = Result(); + res.Position = staff->GetLocation(); + + return res; + } +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffSetOrdersAction.h b/src/openrct2/actions/StaffSetOrdersAction.h index f68bdc5c4b..24a0d6be14 100644 --- a/src/openrct2/actions/StaffSetOrdersAction.h +++ b/src/openrct2/actions/StaffSetOrdersAction.h @@ -11,21 +11,24 @@ #include "GameAction.h" -class StaffSetOrdersAction final : public GameActionBase +namespace OpenRCT2::GameActions { -private: - EntityId _spriteIndex{ EntityId::GetNull() }; - uint8_t _ordersId{}; + class StaffSetOrdersAction final : public GameActionBase + { + private: + EntityId _spriteIndex{ EntityId::GetNull() }; + uint8_t _ordersId{}; -public: - StaffSetOrdersAction() = default; - StaffSetOrdersAction(EntityId spriteIndex, uint8_t ordersId); + public: + StaffSetOrdersAction() = default; + StaffSetOrdersAction(EntityId spriteIndex, uint8_t ordersId); - void AcceptParameters(GameActionParameterVisitor& visitor) override; + void AcceptParameters(GameActionParameterVisitor& visitor) override; - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; -}; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffSetPatrolAreaAction.cpp b/src/openrct2/actions/StaffSetPatrolAreaAction.cpp index a1c0d506fd..2aa14504fe 100644 --- a/src/openrct2/actions/StaffSetPatrolAreaAction.cpp +++ b/src/openrct2/actions/StaffSetPatrolAreaAction.cpp @@ -15,91 +15,93 @@ #include "../entity/Peep.h" #include "../entity/Staff.h" -using namespace OpenRCT2; - -StaffSetPatrolAreaAction::StaffSetPatrolAreaAction(EntityId spriteId, const MapRange& range, const StaffSetPatrolAreaMode mode) - : _spriteId(spriteId) - , _range(range) - , _mode(mode) +namespace OpenRCT2::GameActions { -} - -void StaffSetPatrolAreaAction::AcceptParameters(GameActionParameterVisitor& visitor) -{ - visitor.Visit("id", _spriteId); - visitor.Visit(_range); - visitor.Visit("mode", _mode); -} - -uint16_t StaffSetPatrolAreaAction::GetActionFlags() const -{ - return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused; -} - -void StaffSetPatrolAreaAction::Serialise(DataSerialiser& stream) -{ - GameAction::Serialise(stream); - stream << DS_TAG(_spriteId) << DS_TAG(_range) << DS_TAG(_mode); -} - -GameActions::Result StaffSetPatrolAreaAction::Query() const -{ - return QueryExecute(false); -} - -GameActions::Result StaffSetPatrolAreaAction::Execute() const -{ - return QueryExecute(true); -} - -static void InvalidatePatrolTiles(const MapRange& range) -{ - MapInvalidateRegion(range.Point1, range.Point2); -} - -GameActions::Result StaffSetPatrolAreaAction::QueryExecute(bool executing) const -{ - auto staff = TryGetEntity(_spriteId); - if (staff == nullptr) + StaffSetPatrolAreaAction::StaffSetPatrolAreaAction( + EntityId spriteId, const MapRange& range, const StaffSetPatrolAreaMode mode) + : _spriteId(spriteId) + , _range(range) + , _mode(mode) { - LOG_ERROR("Staff entity not found for spriteID %u", _spriteId.ToUnderlying()); - return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); } - auto validRange = ClampRangeWithinMap(_range); - for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += kCoordsXYStep) + void StaffSetPatrolAreaAction::AcceptParameters(GameActionParameterVisitor& visitor) { - for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += kCoordsXYStep) + visitor.Visit("id", _spriteId); + visitor.Visit(_range); + visitor.Visit("mode", _mode); + } + + uint16_t StaffSetPatrolAreaAction::GetActionFlags() const + { + return GameAction::GetActionFlags() | Flags::AllowWhilePaused; + } + + void StaffSetPatrolAreaAction::Serialise(DataSerialiser& stream) + { + GameAction::Serialise(stream); + stream << DS_TAG(_spriteId) << DS_TAG(_range) << DS_TAG(_mode); + } + + Result StaffSetPatrolAreaAction::Query() const + { + return QueryExecute(false); + } + + Result StaffSetPatrolAreaAction::Execute() const + { + return QueryExecute(true); + } + + static void InvalidatePatrolTiles(const MapRange& range) + { + MapInvalidateRegion(range.Point1, range.Point2); + } + + Result StaffSetPatrolAreaAction::QueryExecute(bool executing) const + { + auto staff = TryGetEntity(_spriteId); + if (staff == nullptr) { - if (!LocationValid({ x, y })) + LOG_ERROR("Staff entity not found for spriteID %u", _spriteId.ToUnderlying()); + return Result(Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_STAFF_NOT_FOUND); + } + + auto validRange = ClampRangeWithinMap(_range); + for (int32_t y = validRange.GetTop(); y <= validRange.GetBottom(); y += kCoordsXYStep) + { + for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += kCoordsXYStep) { - return GameActions::Result(GameActions::Status::InvalidParameters, STR_SET_PATROL_AREA, STR_OFF_EDGE_OF_MAP); + if (!LocationValid({ x, y })) + { + return Result(Status::InvalidParameters, STR_SET_PATROL_AREA, STR_OFF_EDGE_OF_MAP); + } } } - } - if (executing) - { - switch (_mode) + if (executing) { - case StaffSetPatrolAreaMode::Set: - staff->SetPatrolArea(_range, true); - InvalidatePatrolTiles(_range); - break; - case StaffSetPatrolAreaMode::Unset: - staff->SetPatrolArea(_range, false); - if (!staff->HasPatrolArea()) - { + switch (_mode) + { + case StaffSetPatrolAreaMode::Set: + staff->SetPatrolArea(_range, true); + InvalidatePatrolTiles(_range); + break; + case StaffSetPatrolAreaMode::Unset: + staff->SetPatrolArea(_range, false); + if (!staff->HasPatrolArea()) + { + staff->ClearPatrolArea(); + } + InvalidatePatrolTiles(_range); + break; + case StaffSetPatrolAreaMode::ClearAll: staff->ClearPatrolArea(); - } - InvalidatePatrolTiles(_range); - break; - case StaffSetPatrolAreaMode::ClearAll: - staff->ClearPatrolArea(); - GfxInvalidateScreen(); - break; + GfxInvalidateScreen(); + break; + } + UpdateConsolidatedPatrolAreas(); } - UpdateConsolidatedPatrolAreas(); + return Result(); } - return GameActions::Result(); -} +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/actions/StaffSetPatrolAreaAction.h b/src/openrct2/actions/StaffSetPatrolAreaAction.h index 188cacf45e..f18ee9a9cc 100644 --- a/src/openrct2/actions/StaffSetPatrolAreaAction.h +++ b/src/openrct2/actions/StaffSetPatrolAreaAction.h @@ -11,30 +11,33 @@ #include "GameAction.h" -enum class StaffSetPatrolAreaMode : uint8_t +namespace OpenRCT2::GameActions { - Set, - Unset, - ClearAll -}; + enum class StaffSetPatrolAreaMode : uint8_t + { + Set, + Unset, + ClearAll + }; -class StaffSetPatrolAreaAction final : public GameActionBase -{ -private: - EntityId _spriteId{ EntityId::GetNull() }; - MapRange _range; - StaffSetPatrolAreaMode _mode; + class StaffSetPatrolAreaAction final : public GameActionBase + { + private: + EntityId _spriteId{ EntityId::GetNull() }; + MapRange _range; + StaffSetPatrolAreaMode _mode; - OpenRCT2::GameActions::Result QueryExecute(bool executing) const; + Result QueryExecute(bool executing) const; -public: - StaffSetPatrolAreaAction() = default; - StaffSetPatrolAreaAction(EntityId spriteId, const MapRange& range, const StaffSetPatrolAreaMode mode); + public: + StaffSetPatrolAreaAction() = default; + StaffSetPatrolAreaAction(EntityId spriteId, const MapRange& range, const StaffSetPatrolAreaMode mode); - uint16_t GetActionFlags() const override; + uint16_t GetActionFlags() const override; - void AcceptParameters(GameActionParameterVisitor& visitor) override; - void Serialise(DataSerialiser& stream) override; - OpenRCT2::GameActions::Result Query() const override; - OpenRCT2::GameActions::Result Execute() const override; -}; + void AcceptParameters(GameActionParameterVisitor& visitor) override; + void Serialise(DataSerialiser& stream) override; + Result Query() const override; + Result Execute() const override; + }; +} // namespace OpenRCT2::GameActions diff --git a/src/openrct2/interface/InteractiveConsole.cpp b/src/openrct2/interface/InteractiveConsole.cpp index 5ee22f3a33..627110c7f2 100644 --- a/src/openrct2/interface/InteractiveConsole.cpp +++ b/src/openrct2/interface/InteractiveConsole.cpp @@ -530,7 +530,7 @@ static void ConsoleCommandStaff(InteractiveConsole& console, const arguments_t& } auto costume = static_cast(int_val[1]); - auto staffSetCostumeAction = StaffSetCostumeAction(EntityId::FromUnderlying(int_val[0]), costume); + auto staffSetCostumeAction = GameActions::StaffSetCostumeAction(EntityId::FromUnderlying(int_val[0]), costume); GameActions::Execute(&staffSetCostumeAction); } } diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index ee3a71d959..c8dfead369 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -2062,10 +2062,10 @@ void NetworkBase::ServerClientDisconnected(std::unique_ptr& c Peep* pickup_peep = NetworkGetPickupPeep(connection_player->Id); if (pickup_peep != nullptr) { - PeepPickupAction pickupAction{ PeepPickupType::Cancel, - pickup_peep->Id, - { NetworkGetPickupPeepOldX(connection_player->Id), 0, 0 }, - NetworkGetCurrentPlayerId() }; + GameActions::PeepPickupAction pickupAction{ GameActions::PeepPickupType::Cancel, + pickup_peep->Id, + { NetworkGetPickupPeepOldX(connection_player->Id), 0, 0 }, + NetworkGetCurrentPlayerId() }; auto res = GameActions::Execute(&pickupAction); } ServerSendEventPlayerDisconnected( diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 091a75149c..afae8a8ea2 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -1234,7 +1234,7 @@ DukValue ScriptEngine::GameActionResultToDuk(const GameAction& action, const Gam { if (result.Error == GameActions::Status::Ok) { - const auto actionResult = result.GetData(); + const auto actionResult = result.GetData(); if (!actionResult.StaffEntityId.IsNull()) { obj.Set("peep", actionResult.StaffEntityId.ToUnderlying());