1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-06 06:32:56 +01:00

StaffHireNewAction: use peep anim objects; bump network version

This commit is contained in:
Aaron van Geffen
2024-12-05 15:29:34 +01:00
parent 7e3fe58067
commit 3cc8aec6b9
4 changed files with 38 additions and 45 deletions

View File

@@ -149,12 +149,7 @@ namespace OpenRCT2::Ui::Windows
case WIDX_STAFF_LIST_HIRE_BUTTON:
{
auto staffType = GetSelectedStaffType();
auto costume = EntertainerCostume::Count;
if (staffType == StaffType::Entertainer)
{
costume = GetRandomEntertainerCostume();
}
HireNewMember(staffType, costume);
HireNewMember(staffType);
break;
}
case WIDX_STAFF_LIST_SHOW_PATROL_AREA_BUTTON:
@@ -531,7 +526,7 @@ namespace OpenRCT2::Ui::Windows
/**
* Hires a new staff member of the given type.
*/
void HireNewMember(StaffType staffType, EntertainerCostume entertainerType)
void HireNewMember(StaffType staffType)
{
bool autoPosition = Config::Get().general.AutoStaffPlacement;
if (GetInputManager().IsModifierKeyPressed(ModifierKey::shift))
@@ -554,7 +549,15 @@ namespace OpenRCT2::Ui::Windows
staffOrders = STAFF_ORDERS_INSPECT_RIDES | STAFF_ORDERS_FIX_RIDES;
}
auto hireStaffAction = StaffHireNewAction(autoPosition, staffType, entertainerType, staffOrders);
// Select a (random) costume for this staff member
auto animPeepType = AnimationPeepType(static_cast<uint8_t>(staffType) + 1);
ObjectEntryIndex costume;
if (staffType == StaffType::Entertainer)
costume = findRandomPeepAnimationsIndexForType(animPeepType);
else
costume = findPeepAnimationsIndexForType(animPeepType);
auto hireStaffAction = StaffHireNewAction(autoPosition, staffType, costume, staffOrders);
hireStaffAction.SetCallback([=](const GameAction*, const GameActions::Result* res) -> void {
if (res->Error != GameActions::Status::Ok)
return;

View File

@@ -20,7 +20,8 @@
#include "../interface/Window.h"
#include "../localisation/StringIds.h"
#include "../management/Finance.h"
#include "../peep/PeepAnimationData.h"
#include "../object/ObjectManager.h"
#include "../object/PeepAnimationsObject.h"
#include "../ride/Ride.h"
#include "../scenario/Scenario.h"
#include "../ui/UiContext.h"
@@ -32,19 +33,11 @@
using namespace OpenRCT2;
/* rct2: 0x009929FC */
static constexpr PeepAnimationGroup spriteTypes[] = {
PeepAnimationGroup::Handyman,
PeepAnimationGroup::Mechanic,
PeepAnimationGroup::Security,
PeepAnimationGroup::EntertainerPanda,
};
StaffHireNewAction::StaffHireNewAction(
bool autoPosition, StaffType staffType, EntertainerCostume entertainerType, uint32_t staffOrders)
bool autoPosition, StaffType staffType, ObjectEntryIndex costumeIndex, uint32_t staffOrders)
: _autoPosition(autoPosition)
, _staffType(static_cast<uint8_t>(staffType))
, _entertainerType(entertainerType)
, _costumeIndex(costumeIndex)
, _staffOrders(staffOrders)
{
}
@@ -53,7 +46,7 @@ void StaffHireNewAction::AcceptParameters(GameActionParameterVisitor& visitor)
{
visitor.Visit("autoPosition", _autoPosition);
visitor.Visit("staffType", _staffType);
visitor.Visit("entertainerType", _entertainerType);
visitor.Visit("costumeIndex", _costumeIndex);
visitor.Visit("staffOrders", _staffOrders);
}
@@ -66,7 +59,7 @@ void StaffHireNewAction::Serialise(DataSerialiser& stream)
{
GameAction::Serialise(stream);
stream << DS_TAG(_autoPosition) << DS_TAG(_staffType) << DS_TAG(_entertainerType) << DS_TAG(_staffOrders);
stream << DS_TAG(_autoPosition) << DS_TAG(_staffType) << DS_TAG(_costumeIndex) << DS_TAG(_staffOrders);
}
GameActions::Result StaffHireNewAction::Query() const
@@ -97,17 +90,10 @@ GameActions::Result StaffHireNewAction::QueryExecute(bool execute) const
if (_staffType == static_cast<uint8_t>(StaffType::Entertainer))
{
if (static_cast<uint8_t>(_entertainerType) >= static_cast<uint8_t>(EntertainerCostume::Count))
auto costumes = findAllPeepAnimationsIndexesForType(AnimationPeepType::Entertainer);
if (std::find(costumes.begin(), costumes.end(), _costumeIndex) == costumes.end())
{
LOG_ERROR("Invalid entertainer type %u", static_cast<uint32_t>(_entertainerType));
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_ERR_VALUE_OUT_OF_RANGE);
}
uint32_t availableCostumes = StaffGetAvailableEntertainerCostumes();
if (!(availableCostumes & (1 << static_cast<uint8_t>(_entertainerType))))
{
LOG_ERROR("Unavailable entertainer costume %u", static_cast<uint32_t>(_entertainerType));
LOG_ERROR("Unavailable entertainer costume %u", static_cast<uint32_t>(_costumeIndex));
return GameActions::Result(
GameActions::Status::InvalidParameters, STR_CANT_HIRE_NEW_STAFF, STR_ERR_VALUE_OUT_OF_RANGE);
}
@@ -163,18 +149,22 @@ GameActions::Result StaffHireNewAction::QueryExecute(bool execute) const
newPeep->PeepId = newStaffId;
newPeep->AssignedStaffType = static_cast<StaffType>(_staffType);
PeepAnimationGroup spriteType = spriteTypes[_staffType];
if (_staffType == static_cast<uint8_t>(StaffType::Entertainer))
{
spriteType = EntertainerCostumeToSprite(_entertainerType);
}
newPeep->Name = nullptr;
newPeep->AnimationGroup = spriteType;
auto animPeepType = AnimationPeepType(static_cast<uint8_t>(_staffType) + 1);
ObjectEntryIndex animObjectIndex = _costumeIndex;
if (animPeepType != AnimationPeepType::Entertainer)
animObjectIndex = findPeepAnimationsIndexForType(animPeepType);
const SpriteBounds* spriteBounds = &GetSpriteBounds(spriteType);
newPeep->SpriteData.Width = spriteBounds->sprite_width;
newPeep->SpriteData.HeightMin = spriteBounds->sprite_height_negative;
newPeep->SpriteData.HeightMax = spriteBounds->sprite_height_positive;
newPeep->Name = nullptr;
newPeep->AnimationObjectIndex = animObjectIndex;
newPeep->AnimationGroup = PeepAnimationGroup::Normal;
auto& objManager = GetContext()->GetObjectManager();
auto* animObj = objManager.GetLoadedObject<PeepAnimationsObject>(animObjectIndex);
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)
{

View File

@@ -22,12 +22,12 @@ class StaffHireNewAction final : public GameActionBase<GameCommand::HireNewStaff
private:
bool _autoPosition{};
uint8_t _staffType{ EnumValue(StaffType::Count) };
EntertainerCostume _entertainerType{ EntertainerCostume::Count };
ObjectEntryIndex _costumeIndex;
uint32_t _staffOrders{};
public:
StaffHireNewAction() = default;
StaffHireNewAction(bool autoPosition, StaffType staffType, EntertainerCostume entertainerType, uint32_t staffOrders);
StaffHireNewAction(bool autoPosition, StaffType staffType, ObjectEntryIndex costumeIndex, uint32_t staffOrders);
void AcceptParameters(GameActionParameterVisitor& visitor) override;

View File

@@ -50,7 +50,7 @@ using namespace OpenRCT2;
// It is used for making sure only compatible builds get connected, even within
// single OpenRCT2 version.
constexpr uint8_t kNetworkStreamVersion = 0;
constexpr uint8_t kNetworkStreamVersion = 1;
const std::string kNetworkStreamID = std::string(OPENRCT2_VERSION) + "-" + std::to_string(kNetworkStreamVersion);