Merge #8898 branch 'staff_ga' into game_actions

This commit is contained in:
duncanspumpkin 2019-03-18 20:00:34 +00:00
commit add40feb57
10 changed files with 201 additions and 104 deletions

View File

@ -18,6 +18,7 @@
#include <openrct2/Input.h>
#include <openrct2/actions/StaffSetCostumeAction.hpp>
#include <openrct2/actions/StaffSetOrdersAction.hpp>
#include <openrct2/actions/StaffSetPatrolAreaAction.hpp>
#include <openrct2/config/Config.h>
#include <openrct2/localisation/Localisation.h>
#include <openrct2/management/Finance.h>
@ -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)

View File

@ -10,6 +10,7 @@
#include <openrct2-ui/interface/Widget.h>
#include <openrct2-ui/windows/Window.h>
#include <openrct2/Game.h>
#include <openrct2/actions/StaffFireAction.hpp>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/interface/Colour.h>
#include <openrct2/localisation/Localisation.h>
@ -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);

View File

@ -15,6 +15,7 @@
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/actions/StaffFireAction.hpp>
#include <openrct2/actions/StaffSetColourAction.hpp>
#include <openrct2/config/Config.h>
#include <openrct2/drawing/Drawing.h>
@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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<SetParkEntranceFeeAction>();
Register<SignSetNameAction>();
Register<SignSetStyleAction>();
Register<StaffFireAction>();
Register<StaffHireNewAction>();
Register<StaffSetColourAction>();
Register<StaffSetNameAction>();
Register<StaffSetOrdersAction>();
Register<StaffSetCostumeAction>();
Register<StaffSetPatrolAreaAction>();
Register<SurfaceSetStyleAction>();
Register<WallRemoveAction>();
Register<SmallSceneryPlaceAction>();

View File

@ -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();
}
};

View File

@ -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();
}
};

View File

@ -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.
*/

View File

@ -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(