diff --git a/src/openrct2-ui/windows/Staff.cpp b/src/openrct2-ui/windows/Staff.cpp index 4b5a6f8dad..4cd448f91b 100644 --- a/src/openrct2-ui/windows/Staff.cpp +++ b/src/openrct2-ui/windows/Staff.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -1225,7 +1226,8 @@ void window_staff_overview_tool_down(rct_window* w, rct_widgetindex widgetIndex, { _staffPatrolAreaPaintValue = PatrolAreaValue::SET; } - game_do_command(dest_x, 1, dest_y, w->number, GAME_COMMAND_SET_STAFF_PATROL, 0, 0); + auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(w->number, { dest_x, dest_y }); + GameActions::Execute(&staffSetPatrolAreaAction); } } @@ -1263,7 +1265,8 @@ void window_staff_overview_tool_drag(rct_window* w, rct_widgetindex widgetIndex, if (_staffPatrolAreaPaintValue == PatrolAreaValue::UNSET && patrolAreaValue == false) return; // Since area is already the value we want, skip... - game_do_command(dest_x, 1, dest_y, w->number, GAME_COMMAND_SET_STAFF_PATROL, 0, 0); + auto staffSetPatrolAreaAction = StaffSetPatrolAreaAction(w->number, { dest_x, dest_y }); + GameActions::Execute(&staffSetPatrolAreaAction); } void window_staff_overview_tool_up(rct_window* w, rct_widgetindex widgetIndex, int32_t x, int32_t y) diff --git a/src/openrct2-ui/windows/StaffFirePrompt.cpp b/src/openrct2-ui/windows/StaffFirePrompt.cpp index 965ed606d3..f3ae0ded12 100644 --- a/src/openrct2-ui/windows/StaffFirePrompt.cpp +++ b/src/openrct2-ui/windows/StaffFirePrompt.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -103,12 +104,13 @@ rct_window* window_staff_fire_prompt_open(Peep* peep) */ static void window_staff_fire_mouseup(rct_window *w, rct_widgetindex widgetIndex) { - Peep* peep = &get_sprite(w->number)->peep; - switch (widgetIndex){ case WIDX_YES: - game_do_command(peep->x, 1, peep->y, w->number, GAME_COMMAND_FIRE_STAFF_MEMBER, 0, 0); + { + auto staffFireAction = StaffFireAction(w->number); + GameActions::Execute(&staffFireAction); break; + } case WIDX_CANCEL: case WIDX_CLOSE: window_close(w); diff --git a/src/openrct2-ui/windows/StaffList.cpp b/src/openrct2-ui/windows/StaffList.cpp index 9de7e33540..289e3dba9e 100644 --- a/src/openrct2-ui/windows/StaffList.cpp +++ b/src/openrct2-ui/windows/StaffList.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -465,7 +466,10 @@ void window_staff_list_scrollmousedown(rct_window* w, int32_t scrollIndex, int32 if (i == 0) { if (_quick_fire_mode) - game_do_command(peep->x, 1, peep->y, spriteIndex, GAME_COMMAND_FIRE_STAFF_MEMBER, 0, 0); + { + auto staffFireAction = StaffFireAction(spriteIndex); + GameActions::Execute(&staffFireAction); + } else { auto intent = Intent(WC_PEEP); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 042ad67834..297a71b568 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -1273,8 +1273,8 @@ GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = { nullptr, nullptr, nullptr, - game_command_set_staff_patrol, - game_command_fire_staff_member, + nullptr, + nullptr, nullptr, nullptr, nullptr, diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index 3dcaf0c487..72486b85e8 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -49,11 +49,11 @@ enum GAME_COMMAND GAME_COMMAND_LOWER_WATER, // GA GAME_COMMAND_SET_BRAKES_SPEED, // GA GAME_COMMAND_HIRE_NEW_STAFF_MEMBER, // GA - GAME_COMMAND_SET_STAFF_PATROL, - GAME_COMMAND_FIRE_STAFF_MEMBER, - GAME_COMMAND_SET_STAFF_ORDERS, // GA - GAME_COMMAND_SET_PARK_NAME, // GA - GAME_COMMAND_SET_PARK_OPEN, // GA + GAME_COMMAND_SET_STAFF_PATROL, // GA + GAME_COMMAND_FIRE_STAFF_MEMBER, // GA + GAME_COMMAND_SET_STAFF_ORDERS, // GA + GAME_COMMAND_SET_PARK_NAME, // GA + GAME_COMMAND_SET_PARK_OPEN, // GA GAME_COMMAND_BUY_LAND_RIGHTS, GAME_COMMAND_PLACE_PARK_ENTRANCE, // GA GAME_COMMAND_REMOVE_PARK_ENTRANCE, diff --git a/src/openrct2/actions/GameActionRegistration.cpp b/src/openrct2/actions/GameActionRegistration.cpp index 0fb8b207d6..424af171fb 100644 --- a/src/openrct2/actions/GameActionRegistration.cpp +++ b/src/openrct2/actions/GameActionRegistration.cpp @@ -48,11 +48,13 @@ #include "SignSetStyleAction.hpp" #include "SmallSceneryPlaceAction.hpp" #include "SmallSceneryRemoveAction.hpp" +#include "StaffFireAction.hpp" #include "StaffHireNewAction.hpp" #include "StaffSetColourAction.hpp" #include "StaffSetCostumeAction.hpp" #include "StaffSetNameAction.hpp" #include "StaffSetOrdersAction.hpp" +#include "StaffSetPatrolAreaAction.hpp" #include "SurfaceSetStyleAction.hpp" #include "TrackPlaceAction.hpp" #include "TrackRemoveAction.hpp" @@ -96,11 +98,13 @@ namespace GameActions Register(); Register(); Register(); + Register(); Register(); Register(); Register(); Register(); Register(); + Register(); Register(); Register(); Register(); diff --git a/src/openrct2/actions/StaffFireAction.hpp b/src/openrct2/actions/StaffFireAction.hpp new file mode 100644 index 0000000000..49e1f70f05 --- /dev/null +++ b/src/openrct2/actions/StaffFireAction.hpp @@ -0,0 +1,72 @@ +/***************************************************************************** + * Copyright (c) 2014-2019 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../interface/Window.h" +#include "../peep/Peep.h" +#include "../world/Sprite.h" +#include "GameAction.h" + +DEFINE_GAME_ACTION(StaffFireAction, GAME_COMMAND_FIRE_STAFF_MEMBER, GameActionResult) +{ +private: + uint16_t _spriteId{ SPRITE_INDEX_NULL }; + +public: + StaffFireAction() + { + } + StaffFireAction(uint16_t spriteId) + : _spriteId(spriteId) + { + } + + uint16_t GetActionFlags() const override + { + return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED; + } + + void Serialise(DataSerialiser & stream) override + { + GameAction::Serialise(stream); + stream << DS_TAG(_spriteId); + } + + GameActionResult::Ptr Query() const override + { + if (_spriteId >= MAX_SPRITES) + { + log_error("Invalid spriteId. spriteId = %u", _spriteId); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); + } + + auto peep = GET_PEEP(_spriteId); + if (peep == nullptr || peep->sprite_identifier != SPRITE_IDENTIFIER_PEEP || peep->type != PEEP_TYPE_STAFF) + { + log_error("Invalid spriteId. spriteId = %u", _spriteId); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); + } + + return MakeResult(); + } + + GameActionResult::Ptr Execute() const override + { + auto peep = GET_PEEP(_spriteId); + if (peep == nullptr || peep->sprite_identifier != SPRITE_IDENTIFIER_PEEP || peep->type != PEEP_TYPE_STAFF) + { + log_error("Invalid spriteId. spriteId = %u", _spriteId); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); + } + window_close_by_class(WC_FIRE_PROMPT); + peep_sprite_remove(peep); + return MakeResult(); + } +}; diff --git a/src/openrct2/actions/StaffSetPatrolAreaAction.hpp b/src/openrct2/actions/StaffSetPatrolAreaAction.hpp new file mode 100644 index 0000000000..355494da4f --- /dev/null +++ b/src/openrct2/actions/StaffSetPatrolAreaAction.hpp @@ -0,0 +1,103 @@ +/***************************************************************************** + * Copyright (c) 2014-2019 OpenRCT2 developers + * + * For a complete list of all authors, please refer to contributors.md + * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2 + * + * OpenRCT2 is licensed under the GNU General Public License version 3. + *****************************************************************************/ + +#pragma once + +#include "../interface/Window.h" +#include "../peep/Peep.h" +#include "../peep/Staff.h" +#include "../world/Sprite.h" +#include "GameAction.h" + +DEFINE_GAME_ACTION(StaffSetPatrolAreaAction, GAME_COMMAND_SET_STAFF_PATROL, GameActionResult) +{ +private: + uint16_t _spriteId{ SPRITE_INDEX_NULL }; + CoordsXY _loc; + +public: + StaffSetPatrolAreaAction() + { + } + StaffSetPatrolAreaAction(uint16_t spriteId, CoordsXY loc) + : _spriteId(spriteId) + , _loc(loc) + { + } + + uint16_t GetActionFlags() const override + { + return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED; + } + + void Serialise(DataSerialiser & stream) override + { + GameAction::Serialise(stream); + stream << DS_TAG(_spriteId) << DS_TAG(_loc); + } + + GameActionResult::Ptr Query() const override + { + if (_spriteId >= MAX_SPRITES) + { + log_error("Invalid spriteId. spriteId = %u", _spriteId); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); + } + + auto peep = GET_PEEP(_spriteId); + if (peep == nullptr || peep->sprite_identifier != SPRITE_IDENTIFIER_PEEP || peep->type != PEEP_TYPE_STAFF) + { + log_error("Invalid spriteId. spriteId = %u", _spriteId); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); + } + + return MakeResult(); + } + + GameActionResult::Ptr Execute() const override + { + auto peep = GET_PEEP(_spriteId); + if (peep == nullptr || peep->sprite_identifier != SPRITE_IDENTIFIER_PEEP || peep->type != PEEP_TYPE_STAFF) + { + log_error("Invalid spriteId. spriteId = %u", _spriteId); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); + } + + int32_t patrolOffset = peep->staff_id * STAFF_PATROL_AREA_SIZE; + + staff_toggle_patrol_area(peep->staff_id, _loc.x, _loc.y); + + bool isPatrolling = false; + for (int32_t i = 0; i < 128; i++) + { + if (gStaffPatrolAreas[patrolOffset + i]) + { + isPatrolling = true; + break; + } + } + + gStaffModes[peep->staff_id] &= ~(1 << 1); + if (isPatrolling) + { + gStaffModes[peep->staff_id] |= (1 << 1); + } + + for (int32_t y = 0; y < 4 * 32; y += 32) + { + for (int32_t x = 0; x < 4 * 32; x += 32) + { + map_invalidate_tile_full((_loc.x & 0x1F80) + x, (_loc.y & 0x1F80) + y); + } + } + staff_update_greyed_patrol_areas(); + + return MakeResult(); + } +}; diff --git a/src/openrct2/peep/Staff.cpp b/src/openrct2/peep/Staff.cpp index 5fc4ce8cc7..06e2e51c47 100644 --- a/src/openrct2/peep/Staff.cpp +++ b/src/openrct2/peep/Staff.cpp @@ -82,93 +82,6 @@ void staff_reset_modes() staff_update_greyed_patrol_areas(); } -/** - * - * rct2: 0x006C09D1 - */ -void game_command_set_staff_patrol( - int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, [[maybe_unused]] int32_t* esi, [[maybe_unused]] int32_t* edi, - [[maybe_unused]] int32_t* ebp) -{ - if (*ebx & GAME_COMMAND_FLAG_APPLY) - { - int32_t x = *eax; - int32_t y = *ecx; - uint16_t sprite_id = *edx; - if (sprite_id >= MAX_SPRITES) - { - *ebx = MONEY32_UNDEFINED; - log_warning("Invalid sprite id %u", sprite_id); - return; - } - rct_sprite* sprite = get_sprite(sprite_id); - if (sprite->generic.sprite_identifier != SPRITE_IDENTIFIER_PEEP || sprite->peep.type != PEEP_TYPE_STAFF) - { - *ebx = MONEY32_UNDEFINED; - log_warning("Invalid type of sprite %u for game command", sprite_id); - return; - } - Peep* peep = &sprite->peep; - int32_t patrolOffset = peep->staff_id * STAFF_PATROL_AREA_SIZE; - - staff_toggle_patrol_area(peep->staff_id, x, y); - - int32_t ispatrolling = 0; - for (int32_t i = 0; i < 128; i++) - { - ispatrolling |= gStaffPatrolAreas[patrolOffset + i]; - } - - gStaffModes[peep->staff_id] &= ~2; - if (ispatrolling) - { - gStaffModes[peep->staff_id] |= 2; - } - - for (int32_t y2 = 0; y2 < 4; y2++) - { - for (int32_t x2 = 0; x2 < 4; x2++) - { - map_invalidate_tile_full((x & 0x1F80) + (x2 * 32), (y & 0x1F80) + (y2 * 32)); - } - } - staff_update_greyed_patrol_areas(); - } - *ebx = 0; -} - -/** - * - * rct2: 0x006C0B83 - */ -void game_command_fire_staff_member( - [[maybe_unused]] int32_t* eax, int32_t* ebx, [[maybe_unused]] int32_t* ecx, int32_t* edx, [[maybe_unused]] int32_t* esi, - [[maybe_unused]] int32_t* edi, [[maybe_unused]] int32_t* ebp) -{ - gCommandExpenditureType = RCT_EXPENDITURE_TYPE_WAGES; - if (*ebx & GAME_COMMAND_FLAG_APPLY) - { - window_close_by_class(WC_FIRE_PROMPT); - uint16_t sprite_id = *edx; - if (sprite_id >= MAX_SPRITES) - { - log_warning("Invalid game command, sprite_id = %u", sprite_id); - *ebx = MONEY32_UNDEFINED; - return; - } - Peep* peep = &get_sprite(sprite_id)->peep; - if (peep->sprite_identifier != SPRITE_IDENTIFIER_PEEP || peep->type != PEEP_TYPE_STAFF) - { - log_warning( - "Invalid game command, peep->sprite_identifier = %u, peep->type = %u", peep->sprite_identifier, peep->type); - *ebx = MONEY32_UNDEFINED; - return; - } - peep_sprite_remove(peep); - } - *ebx = 0; -} - /** * Hires a new staff member of the given type. */ diff --git a/src/openrct2/peep/Staff.h b/src/openrct2/peep/Staff.h index 68fe2e461c..696c66c7d9 100644 --- a/src/openrct2/peep/Staff.h +++ b/src/openrct2/peep/Staff.h @@ -75,10 +75,6 @@ void game_command_hire_new_staff_member( int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); void game_command_callback_hire_new_staff_member( int32_t eax, int32_t ebx, int32_t ecx, int32_t edx, int32_t esi, int32_t edi, int32_t ebp); -void game_command_set_staff_patrol( - int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); -void game_command_fire_staff_member( - int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); void game_command_set_staff_name( int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); void game_command_pickup_staff(