Add ParkSetParameterAction

This commit is contained in:
duncanspumpkin 2019-03-15 20:53:17 +00:00
parent b7edca8ef3
commit 9a1532ecc4
9 changed files with 122 additions and 82 deletions

View File

@ -658,10 +658,10 @@ static void window_park_entrance_mouseup(rct_window* w, rct_widgetindex widgetIn
window_text_input_open(w, WIDX_RENAME, STR_PARK_NAME, STR_ENTER_PARK_NAME, gParkName, 0, USER_STRING_MAX_LENGTH);
break;
case WIDX_CLOSE_LIGHT:
park_set_open(0);
park_set_open(false);
break;
case WIDX_OPEN_LIGHT:
park_set_open(1);
park_set_open(true);
break;
}
}
@ -718,13 +718,11 @@ static void window_park_entrance_dropdown(rct_window* w, rct_widgetindex widgetI
if (dropdownIndex != 0)
{
gGameCommandErrorTitle = STR_CANT_CLOSE_PARK;
park_set_open(1);
park_set_open(true);
}
else
{
gGameCommandErrorTitle = STR_CANT_OPEN_PARK;
park_set_open(0);
park_set_open(false);
}
}
}

View File

@ -23,6 +23,7 @@
#include <openrct2/Input.h>
#include <openrct2/OpenRCT2.h>
#include <openrct2/actions/GameAction.h>
#include <openrct2/actions/ParkSetParameterAction.hpp>
#include <openrct2/actions/RideSetAppearanceAction.hpp>
#include <openrct2/actions/RideSetColourScheme.hpp>
#include <openrct2/actions/RideSetPriceAction.hpp>
@ -6157,11 +6158,13 @@ static void update_same_price_throughout_flags(uint32_t shop_item)
{
newFlags = gSamePriceThroughoutParkA;
newFlags ^= (1 << SHOP_ITEM_PHOTO);
game_do_command(0, 1, 0, (0x2 << 8), GAME_COMMAND_SET_PARK_OPEN, newFlags, shop_item);
auto parkSetParameterA = ParkSetParameterAction(ParkParameter::SamePriceInParkA, shop_item);
GameActions::Execute(&parkSetParameterA);
newFlags = gSamePriceThroughoutParkB;
newFlags ^= (1 << (SHOP_ITEM_PHOTO2 - 32)) | (1 << (SHOP_ITEM_PHOTO3 - 32)) | (1 << (SHOP_ITEM_PHOTO4 - 32));
game_do_command(0, 1, 0, (0x3 << 8), GAME_COMMAND_SET_PARK_OPEN, newFlags, shop_item);
auto parkSetParameterB = ParkSetParameterAction(ParkParameter::SamePriceInParkB, shop_item);
GameActions::Execute(&parkSetParameterB);
}
else
{
@ -6169,13 +6172,15 @@ static void update_same_price_throughout_flags(uint32_t shop_item)
{
newFlags = gSamePriceThroughoutParkA;
newFlags ^= (1u << shop_item);
game_do_command(0, 1, 0, (0x2 << 8), GAME_COMMAND_SET_PARK_OPEN, newFlags, shop_item);
auto parkSetParameterA = ParkSetParameterAction(ParkParameter::SamePriceInParkA, shop_item);
GameActions::Execute(&parkSetParameterA);
}
else
{
newFlags = gSamePriceThroughoutParkB;
newFlags ^= (1u << (shop_item - 32));
game_do_command(0, 1, 0, (0x3 << 8), GAME_COMMAND_SET_PARK_OPEN, newFlags, shop_item);
auto parkSetParameterB = ParkSetParameterAction(ParkParameter::SamePriceInParkB, shop_item);
GameActions::Execute(&parkSetParameterB);
}
}
}

View File

@ -620,7 +620,7 @@ void game_command_cheat(
gCheatsNeverendingMarketing = *edx != 0;
break;
case CHEAT_OPENCLOSEPARK:
park_set_open(park_is_open() ? 0 : 1);
park_set_open(!park_is_open());
break;
case CHEAT_HAVEFUN:
gScenarioObjectiveType = OBJECTIVE_HAVE_FUN;

View File

@ -611,24 +611,6 @@ void game_log_multiplayer_command(int command, const int* eax, const int* ebx, c
format_string(log_msg, 256, STR_LOG_DEMOLISH_RIDE, args);
network_append_server_log(log_msg);
}
else if (command == GAME_COMMAND_SET_PARK_OPEN)
{
// Log change in park open/close
char* args[1] = {
(char*)player_name,
};
if (*edx >> 8 == 0)
{
format_string(log_msg, 256, STR_LOG_PARK_OPEN, args);
}
else if (*edx >> 8 == 1)
{
format_string(log_msg, 256, STR_LOG_PARK_CLOSED, args);
}
network_append_server_log(log_msg);
}
else if (
command == GAME_COMMAND_PLACE_WALL || command == GAME_COMMAND_PLACE_LARGE_SCENERY
|| command == GAME_COMMAND_PLACE_BANNER)
@ -1295,7 +1277,7 @@ GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = {
game_command_fire_staff_member,
nullptr,
nullptr,
game_command_set_park_open,
nullptr,
game_command_buy_land_rights,
game_command_place_park_entrance,
game_command_remove_park_entrance,

View File

@ -53,7 +53,7 @@ enum GAME_COMMAND
GAME_COMMAND_FIRE_STAFF_MEMBER,
GAME_COMMAND_SET_STAFF_ORDERS, // GA
GAME_COMMAND_SET_PARK_NAME, // GA
GAME_COMMAND_SET_PARK_OPEN,
GAME_COMMAND_SET_PARK_OPEN, // GA
GAME_COMMAND_BUY_LAND_RIGHTS,
GAME_COMMAND_PLACE_PARK_ENTRANCE, // GA
GAME_COMMAND_REMOVE_PARK_ENTRANCE,

View File

@ -26,6 +26,7 @@
#include "ParkMarketingAction.hpp"
#include "ParkSetLoanAction.hpp"
#include "ParkSetNameAction.hpp"
#include "ParkSetParameterAction.hpp"
#include "ParkSetResearchFundingAction.hpp"
#include "PauseToggleAction.hpp"
#include "PlaceParkEntranceAction.hpp"
@ -75,6 +76,7 @@ namespace GameActions
Register<ParkMarketingAction>();
Register<ParkSetLoanAction>();
Register<ParkSetNameAction>();
Register<ParkSetParameterAction>();
Register<ParkSetResearchFundingAction>();
Register<PlaceParkEntranceAction>();
Register<PlacePeepSpawnAction>();

View File

@ -0,0 +1,99 @@
/*****************************************************************************
* 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 "../ride/ShopItem.h"
#include "../world/Park.h"
#include "GameAction.h"
enum class ParkParameter : uint8_t
{
Close,
Open,
SamePriceInParkA,
SamePriceInParkB,
Count
};
DEFINE_GAME_ACTION(ParkSetParameterAction, GAME_COMMAND_SET_PARK_OPEN, GameActionResult)
{
private:
uint8_t _parameter;
uint32_t _value;
constexpr static rct_string_id _ErrorTitles[] = { STR_CANT_CLOSE_PARK, STR_CANT_OPEN_PARK, STR_NONE, STR_NONE };
public:
ParkSetParameterAction()
{
}
ParkSetParameterAction(ParkParameter parameter, uint32_t value = 0)
: _parameter(static_cast<uint8_t>(parameter))
, _value(value)
{
}
uint16_t GetActionFlags() const override
{
return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED;
}
void Serialise(DataSerialiser & stream) override
{
GameAction::Serialise(stream);
stream << DS_TAG(_parameter) << DS_TAG(_value);
}
GameActionResult::Ptr Query() const override
{
if (_parameter >= static_cast<uint8_t>(ParkParameter::Count))
{
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
}
auto res = MakeResult();
res->ErrorTitle = _ErrorTitles[_parameter];
return res;
}
GameActionResult::Ptr Execute() const override
{
switch (static_cast<ParkParameter>(_parameter))
{
case ParkParameter::Close:
if (gParkFlags & PARK_FLAGS_PARK_OPEN)
{
gParkFlags &= ~PARK_FLAGS_PARK_OPEN;
window_invalidate_by_class(WC_PARK_INFORMATION);
}
break;
case ParkParameter::Open:
if (!(gParkFlags & PARK_FLAGS_PARK_OPEN))
{
gParkFlags |= PARK_FLAGS_PARK_OPEN;
window_invalidate_by_class(WC_PARK_INFORMATION);
}
break;
case ParkParameter::SamePriceInParkA:
gSamePriceThroughoutParkA = _value;
window_invalidate_by_class(WC_RIDE);
break;
case ParkParameter::SamePriceInParkB:
gSamePriceThroughoutParkB = _value;
window_invalidate_by_class(WC_RIDE);
break;
}
auto res = MakeResult();
res->ErrorTitle = _ErrorTitles[_parameter];
return res;
}
};

View File

@ -15,6 +15,7 @@
#include "../Game.h"
#include "../GameState.h"
#include "../OpenRCT2.h"
#include "../actions/ParkSetParameterAction.hpp"
#include "../config/Config.h"
#include "../core/Memory.hpp"
#include "../interface/Colour.h"
@ -104,55 +105,10 @@ static PeepSpawn* get_random_peep_spawn()
}
}
void park_set_open(int32_t open)
void park_set_open(bool open)
{
game_do_command(0, GAME_COMMAND_FLAG_APPLY, 0, open << 8, GAME_COMMAND_SET_PARK_OPEN, 0, 0);
}
/**
*
* rct2: 0x00669D4A
*/
void game_command_set_park_open(
[[maybe_unused]] int32_t* eax, int32_t* ebx, [[maybe_unused]] int32_t* ecx, int32_t* edx, [[maybe_unused]] int32_t* esi,
int32_t* edi, [[maybe_unused]] int32_t* ebp)
{
if (!(*ebx & GAME_COMMAND_FLAG_APPLY))
{
*ebx = 0;
return;
}
int32_t dh = (*edx >> 8) & 0xFF;
gCommandExpenditureType = RCT_EXPENDITURE_TYPE_PARK_ENTRANCE_TICKETS;
switch (dh)
{
case 0:
if (gParkFlags & PARK_FLAGS_PARK_OPEN)
{
gParkFlags &= ~PARK_FLAGS_PARK_OPEN;
window_invalidate_by_class(WC_PARK_INFORMATION);
}
break;
case 1:
if (!(gParkFlags & PARK_FLAGS_PARK_OPEN))
{
gParkFlags |= PARK_FLAGS_PARK_OPEN;
window_invalidate_by_class(WC_PARK_INFORMATION);
}
break;
case 2:
gSamePriceThroughoutParkA = *edi;
window_invalidate_by_class(WC_RIDE);
break;
case 3:
gSamePriceThroughoutParkB = *edi;
window_invalidate_by_class(WC_RIDE);
break;
}
*ebx = 0;
auto parkSetParameter = ParkSetParameterAction(open ? ParkParameter::Open : ParkParameter::Close);
GameActions::Execute(&parkSetParameter);
}
/**

View File

@ -132,7 +132,7 @@ void update_park_fences_around_tile(CoordsXY coords);
uint8_t calculate_guest_initial_happiness(uint8_t percentage);
void park_set_open(int32_t open);
void park_set_open(bool open);
int32_t park_entrance_get_index(int32_t x, int32_t y, int32_t z);
void park_set_name(const char* name);
void park_set_entrance_fee(money32 value);
@ -141,8 +141,6 @@ int32_t map_buy_land_rights(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int3
void game_command_set_park_entrance_fee(
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_park_open(
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
void game_command_buy_land_rights(
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);