mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-26 00:04:43 +01:00
Modify StaffSetPatrolAreaAction to have three modes (#15494)
* Modify StaffSetPatrolAreaAction to have three modes * Actually serialise mode * Apply review comments * Increment network version * Apply review comment * Update replay
This commit is contained in:
@@ -567,11 +567,10 @@ void window_staff_overview_dropdown(rct_window* w, rct_widgetindex widgetIndex,
|
||||
{
|
||||
return;
|
||||
}
|
||||
// TODO: THIS SHOULD BE NETWORKED
|
||||
peep->ClearPatrolArea();
|
||||
|
||||
gfx_invalidate_screen();
|
||||
staff_update_greyed_patrol_areas();
|
||||
auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(
|
||||
peep->sprite_index, {}, StaffSetPatrolAreaMode::ClearAll);
|
||||
GameActions::Execute(&staffSetPatrolAreaAction);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1241,7 +1240,9 @@ void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex,
|
||||
{
|
||||
_staffPatrolAreaPaintValue = PatrolAreaValue::SET;
|
||||
}
|
||||
auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(w->number, destCoords);
|
||||
auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(
|
||||
w->number, destCoords,
|
||||
_staffPatrolAreaPaintValue == PatrolAreaValue::SET ? StaffSetPatrolAreaMode::Set : StaffSetPatrolAreaMode::Unset);
|
||||
GameActions::Execute(&staffSetPatrolAreaAction);
|
||||
}
|
||||
}
|
||||
@@ -1275,7 +1276,9 @@ void window_staff_overview_tool_drag(rct_window* w, rct_widgetindex widgetIndex,
|
||||
if (_staffPatrolAreaPaintValue == PatrolAreaValue::UNSET && !patrolAreaValue)
|
||||
return; // Since area is already the value we want, skip...
|
||||
|
||||
auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(w->number, destCoords);
|
||||
auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(
|
||||
w->number, destCoords,
|
||||
_staffPatrolAreaPaintValue == PatrolAreaValue::SET ? StaffSetPatrolAreaMode::Set : StaffSetPatrolAreaMode::Unset);
|
||||
GameActions::Execute(&staffSetPatrolAreaAction);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,10 @@
|
||||
#include "../peep/Staff.h"
|
||||
#include "../world/Entity.h"
|
||||
|
||||
StaffSetPatrolAreaAction::StaffSetPatrolAreaAction(uint16_t spriteId, const CoordsXY& loc)
|
||||
StaffSetPatrolAreaAction::StaffSetPatrolAreaAction(uint16_t spriteId, const CoordsXY& loc, const StaffSetPatrolAreaMode mode)
|
||||
: _spriteId(spriteId)
|
||||
, _loc(loc)
|
||||
, _mode(mode)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -28,7 +29,7 @@ uint16_t StaffSetPatrolAreaAction::GetActionFlags() const
|
||||
void StaffSetPatrolAreaAction::Serialise(DataSerialiser& stream)
|
||||
{
|
||||
GameAction::Serialise(stream);
|
||||
stream << DS_TAG(_spriteId) << DS_TAG(_loc);
|
||||
stream << DS_TAG(_spriteId) << DS_TAG(_loc) << DS_TAG(_mode);
|
||||
}
|
||||
|
||||
GameActions::Result::Ptr StaffSetPatrolAreaAction::Query() const
|
||||
@@ -54,19 +55,10 @@ GameActions::Result::Ptr StaffSetPatrolAreaAction::Query() const
|
||||
return MakeResult();
|
||||
}
|
||||
|
||||
GameActions::Result::Ptr StaffSetPatrolAreaAction::Execute() const
|
||||
static void UpdateStaffMode(const Staff& staff)
|
||||
{
|
||||
auto staff = TryGetEntity<Staff>(_spriteId);
|
||||
if (staff == nullptr)
|
||||
{
|
||||
log_error("Invalid spriteId. spriteId = %u", _spriteId);
|
||||
return MakeResult(GameActions::Status::InvalidParameters, STR_NONE);
|
||||
}
|
||||
|
||||
staff->TogglePatrolArea(_loc);
|
||||
|
||||
bool isPatrolling = false;
|
||||
const auto peepOffset = staff->StaffId * STAFF_PATROL_AREA_SIZE;
|
||||
const auto peepOffset = staff.StaffId * STAFF_PATROL_AREA_SIZE;
|
||||
for (size_t i = peepOffset; i < peepOffset + STAFF_PATROL_AREA_SIZE; i++)
|
||||
{
|
||||
if (gStaffPatrolAreas[i] != 0)
|
||||
@@ -78,20 +70,54 @@ GameActions::Result::Ptr StaffSetPatrolAreaAction::Execute() const
|
||||
|
||||
if (isPatrolling)
|
||||
{
|
||||
gStaffModes[staff->StaffId] = StaffMode::Patrol;
|
||||
gStaffModes[staff.StaffId] = StaffMode::Patrol;
|
||||
}
|
||||
else if (gStaffModes[staff->StaffId] == StaffMode::Patrol)
|
||||
else if (gStaffModes[staff.StaffId] == StaffMode::Patrol)
|
||||
{
|
||||
gStaffModes[staff->StaffId] = StaffMode::Walk;
|
||||
gStaffModes[staff.StaffId] = StaffMode::Walk;
|
||||
}
|
||||
}
|
||||
|
||||
static void InvalidatePatrolTile(const CoordsXY& loc)
|
||||
{
|
||||
// Align the location to the top left of the patrol square
|
||||
const auto alignedLoc = CoordsXY{ loc.x & 0x1F80, loc.y & 0x1F80 };
|
||||
for (int32_t y = 0; y < 4 * COORDS_XY_STEP; y += COORDS_XY_STEP)
|
||||
{
|
||||
for (int32_t x = 0; x < 4 * COORDS_XY_STEP; x += COORDS_XY_STEP)
|
||||
{
|
||||
map_invalidate_tile_full({ (_loc.x & 0x1F80) + x, (_loc.y & 0x1F80) + y });
|
||||
map_invalidate_tile_full(alignedLoc + CoordsXY{ x, y });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameActions::Result::Ptr StaffSetPatrolAreaAction::Execute() const
|
||||
{
|
||||
auto staff = TryGetEntity<Staff>(_spriteId);
|
||||
if (staff == nullptr)
|
||||
{
|
||||
log_error("Invalid spriteId. spriteId = %u", _spriteId);
|
||||
return MakeResult(GameActions::Status::InvalidParameters, STR_NONE);
|
||||
}
|
||||
|
||||
switch (_mode)
|
||||
{
|
||||
case StaffSetPatrolAreaMode::Set:
|
||||
staff->SetPatrolArea(_loc, true);
|
||||
UpdateStaffMode(*staff);
|
||||
InvalidatePatrolTile(_loc);
|
||||
break;
|
||||
case StaffSetPatrolAreaMode::Unset:
|
||||
staff->SetPatrolArea(_loc, false);
|
||||
UpdateStaffMode(*staff);
|
||||
InvalidatePatrolTile(_loc);
|
||||
break;
|
||||
case StaffSetPatrolAreaMode::ClearAll:
|
||||
staff->ClearPatrolArea();
|
||||
gfx_invalidate_screen();
|
||||
break;
|
||||
}
|
||||
|
||||
staff_update_greyed_patrol_areas();
|
||||
|
||||
return MakeResult();
|
||||
|
||||
@@ -11,15 +11,23 @@
|
||||
|
||||
#include "GameAction.h"
|
||||
|
||||
enum class StaffSetPatrolAreaMode : uint8_t
|
||||
{
|
||||
Set,
|
||||
Unset,
|
||||
ClearAll
|
||||
};
|
||||
|
||||
DEFINE_GAME_ACTION(StaffSetPatrolAreaAction, GameCommand::SetStaffPatrol, GameActions::Result)
|
||||
{
|
||||
private:
|
||||
uint16_t _spriteId{ SPRITE_INDEX_NULL };
|
||||
CoordsXY _loc;
|
||||
StaffSetPatrolAreaMode _mode;
|
||||
|
||||
public:
|
||||
StaffSetPatrolAreaAction() = default;
|
||||
StaffSetPatrolAreaAction(uint16_t spriteId, const CoordsXY& loc);
|
||||
StaffSetPatrolAreaAction(uint16_t spriteId, const CoordsXY& loc, const StaffSetPatrolAreaMode mode);
|
||||
|
||||
uint16_t GetActionFlags() const override;
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
// This string specifies which version of network stream current build uses.
|
||||
// It is used for making sure only compatible builds get connected, even within
|
||||
// single OpenRCT2 version.
|
||||
#define NETWORK_STREAM_VERSION "12"
|
||||
#define NETWORK_STREAM_VERSION "13"
|
||||
#define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION
|
||||
|
||||
static Peep* _pickup_peep = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user