Merge pull request #8693 from ZehMatt/ga-ridesetprice

Refactor Ride Set Price to game actions.
This commit is contained in:
ζeh Matt 2019-02-09 21:06:17 +01:00 committed by GitHub
commit 7861d64ca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 213 additions and 145 deletions

View File

@ -25,6 +25,7 @@
2AA050322209A8E300D3A922 /* StaffSetCostumeAction.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2AA050302209A8E300D3A922 /* StaffSetCostumeAction.hpp */; };
2AA050332209A8E300D3A922 /* StaffSetOrdersAction.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2AA050312209A8E300D3A922 /* StaffSetOrdersAction.hpp */; };
2AAFD800220DD3D2002461A4 /* LandSetHeightAction.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2AAFD7FF220DD3D2002461A4 /* LandSetHeightAction.hpp */; };
2AAFD7FC220DD336002461A4 /* RideSetPriceAction.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2AAFD7FB220DD336002461A4 /* RideSetPriceAction.hpp */; };
2AF7893D220B253E0072754A /* RideSetAppearanceAction.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2AF7893C220B253E0072754A /* RideSetAppearanceAction.hpp */; };
4C29DEB3218C6AE500E8707F /* RCT12.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C29DEB2218C6AE500E8707F /* RCT12.cpp */; };
4C358E5221C445F700ADE6BC /* ReplayManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4C358E5021C445F700ADE6BC /* ReplayManager.cpp */; };
@ -623,6 +624,7 @@
2AA050302209A8E300D3A922 /* StaffSetCostumeAction.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = StaffSetCostumeAction.hpp; sourceTree = "<group>"; };
2AA050312209A8E300D3A922 /* StaffSetOrdersAction.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = StaffSetOrdersAction.hpp; sourceTree = "<group>"; };
2AAFD7FF220DD3D2002461A4 /* LandSetHeightAction.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = LandSetHeightAction.hpp; sourceTree = "<group>"; };
2AAFD7FB220DD336002461A4 /* RideSetPriceAction.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RideSetPriceAction.hpp; sourceTree = "<group>"; };
2AF7893C220B253E0072754A /* RideSetAppearanceAction.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RideSetAppearanceAction.hpp; sourceTree = "<group>"; };
4C04D69F2056AA9600F82EBA /* linenoise.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = linenoise.hpp; sourceTree = "<group>"; };
4C1A53EC205FD19F000F8EF5 /* SceneryObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SceneryObject.cpp; sourceTree = "<group>"; };
@ -2003,6 +2005,7 @@
isa = PBXGroup;
children = (
2AAFD7FF220DD3D2002461A4 /* LandSetHeightAction.hpp */,
2AAFD7FB220DD336002461A4 /* RideSetPriceAction.hpp */,
2AF7893C220B253E0072754A /* RideSetAppearanceAction.hpp */,
2A5354EB22099D7700A5440F /* SignSetStyleAction.hpp */,
2AA050302209A8E300D3A922 /* StaffSetCostumeAction.hpp */,
@ -3324,6 +3327,7 @@
C6352B841F477022006CCEE3 /* DataSerialiser.h in Headers */,
939A35A020C12FDE00630B3F /* Paint.TileElement.h in Headers */,
2AF7893D220B253E0072754A /* RideSetAppearanceAction.hpp in Headers */,
2AAFD7FC220DD336002461A4 /* RideSetPriceAction.hpp in Headers */,
C67B28162002D67A00109C93 /* Window.h in Headers */,
C6352B961F477032006CCEE3 /* RideSetStatus.hpp in Headers */,
2AAFD800220DD3D2002461A4 /* LandSetHeightAction.hpp in Headers */,

View File

@ -25,6 +25,7 @@
#include <openrct2/actions/GameAction.h>
#include <openrct2/actions/RideSetAppearanceAction.hpp>
#include <openrct2/actions/RideSetColourScheme.hpp>
#include <openrct2/actions/RideSetPriceAction.hpp>
#include <openrct2/audio/audio.h>
#include <openrct2/config/Config.h>
#include <openrct2/localisation/Date.h>
@ -47,7 +48,6 @@
#include <openrct2/sprites.h>
#include <openrct2/windows/Intent.h>
#include <openrct2/world/Park.h>
using namespace OpenRCT2;
enum
@ -6179,7 +6179,6 @@ static void window_ride_income_toggle_primary_price(rct_window* w)
Ride* ride;
rct_ride_entry* rideEntry;
uint32_t shop_item;
money16 price;
ride = get_ride(w->number);
rideEntry = get_ride_entry(ride->subtype);
@ -6197,8 +6196,8 @@ static void window_ride_income_toggle_primary_price(rct_window* w)
update_same_price_throughout_flags(shop_item);
price = ride->price;
game_do_command(0, 1, 0, w->number, GAME_COMMAND_SET_RIDE_PRICE, price, 0);
auto rideSetPriceAction = RideSetPriceAction(w->number, ride->price, true);
GameActions::Execute(&rideSetPriceAction);
}
/**
@ -6210,7 +6209,6 @@ static void window_ride_income_toggle_secondary_price(rct_window* w)
Ride* ride;
rct_ride_entry* rideEntry;
uint32_t shop_item;
money16 price;
ride = get_ride(w->number);
rideEntry = get_ride_entry(ride->subtype);
@ -6221,13 +6219,14 @@ static void window_ride_income_toggle_secondary_price(rct_window* w)
update_same_price_throughout_flags(shop_item);
price = ride->price_secondary;
game_do_command(0, 1, 0, (1 << 8) | w->number, GAME_COMMAND_SET_RIDE_PRICE, price, 0);
auto rideSetPriceAction = RideSetPriceAction(w->number, ride->price_secondary, false);
GameActions::Execute(&rideSetPriceAction);
}
static void window_ride_income_set_primary_price(rct_window* w, money16 price)
{
game_do_command(0, GAME_COMMAND_FLAG_APPLY, 0, w->number, GAME_COMMAND_SET_RIDE_PRICE, price, 0);
auto rideSetPriceAction = RideSetPriceAction(w->number, price, true);
GameActions::Execute(&rideSetPriceAction);
}
/**
@ -6273,7 +6272,8 @@ static money16 window_ride_income_get_secondary_price(rct_window* w)
static void window_ride_income_set_secondary_price(rct_window* w, money16 price)
{
game_do_command(0, GAME_COMMAND_FLAG_APPLY, 0, (w->number & 0x00FF) | 0x0100, GAME_COMMAND_SET_RIDE_PRICE, price, 0);
auto rideSetPriceAction = RideSetPriceAction((w->number & 0x00FF), price, false);
GameActions::Execute(&rideSetPriceAction);
}
static bool window_ride_income_can_modify_primary_price(rct_window* w)

View File

@ -1475,7 +1475,7 @@ GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = {
game_command_place_footpath_from_track,
nullptr,
game_command_change_surface_style,
game_command_set_ride_price,
nullptr,
game_command_set_guest_name,
game_command_set_staff_name,
game_command_raise_land,

View File

@ -39,7 +39,7 @@ enum GAME_COMMAND
GAME_COMMAND_PLACE_PATH_FROM_TRACK,
GAME_COMMAND_REMOVE_PATH,
GAME_COMMAND_CHANGE_SURFACE_STYLE,
GAME_COMMAND_SET_RIDE_PRICE,
GAME_COMMAND_SET_RIDE_PRICE, // GA
GAME_COMMAND_SET_GUEST_NAME, // GA
GAME_COMMAND_SET_STAFF_NAME, // GA
GAME_COMMAND_RAISE_LAND,

View File

@ -27,6 +27,7 @@
#include "RideSetAppearanceAction.hpp"
#include "RideSetColourScheme.hpp"
#include "RideSetName.hpp"
#include "RideSetPriceAction.hpp"
#include "RideSetStatus.hpp"
#include "SetParkEntranceFeeAction.hpp"
#include "SignSetNameAction.hpp"
@ -57,6 +58,7 @@ namespace GameActions
Register<RideDemolishAction>();
Register<RideSetColourSchemeAction>();
Register<RideSetNameAction>();
Register<RideSetPriceAction>();
Register<RideSetStatusAction>();
Register<RideSetAppearanceAction>();
Register<SetParkEntranceFeeAction>();

View File

@ -0,0 +1,196 @@
/*****************************************************************************
* 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 "../Cheats.h"
#include "../common.h"
#include "../core/MemoryStream.h"
#include "../interface/Window.h"
#include "../localisation/Localisation.h"
#include "../localisation/StringIds.h"
#include "../management/Finance.h"
#include "../ride/Ride.h"
#include "../ride/RideData.h"
#include "../ride/ShopItem.h"
#include "../world/Park.h"
#include "../world/Sprite.h"
#include "GameAction.h"
DEFINE_GAME_ACTION(RideSetPriceAction, GAME_COMMAND_SET_RIDE_PRICE, GameActionResult)
{
private:
NetworkRideId_t _rideIndex{ -1 };
money16 _price = MONEY16_UNDEFINED;
bool _primaryPrice = true;
public:
RideSetPriceAction()
{
}
RideSetPriceAction(ride_id_t rideIndex, money16 price, bool primaryPrice)
: _rideIndex(rideIndex)
, _price(price)
, _primaryPrice(primaryPrice)
{
}
uint16_t GetActionFlags() const override
{
return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED;
}
void Serialise(DataSerialiser & stream) override
{
GameAction::Serialise(stream);
stream << DS_TAG(_rideIndex) << DS_TAG(_price) << DS_TAG(_primaryPrice);
}
GameActionResult::Ptr Query() const override
{
GameActionResult::Ptr res = std::make_unique<GameActionResult>();
if (_rideIndex >= MAX_RIDES || _rideIndex == RIDE_ID_NULL)
{
log_warning("Invalid game command for ride %u", _rideIndex);
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
}
Ride* ride = get_ride(_rideIndex);
if (ride == nullptr || ride->type == RIDE_TYPE_NULL)
{
log_warning("Invalid game command, ride_id = %u", _rideIndex);
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
}
rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
if (rideEntry == nullptr)
{
log_warning("Invalid game command for ride %u", _rideIndex);
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
}
return res;
}
GameActionResult::Ptr Execute() const override
{
GameActionResult::Ptr res = std::make_unique<GameActionResult>();
res->ExpenditureType = RCT_EXPENDITURE_TYPE_PARK_RIDE_TICKETS;
Ride* ride = get_ride(_rideIndex);
if (ride == nullptr || ride->type == RIDE_TYPE_NULL)
{
log_warning("Invalid game command, ride_id = %u", _rideIndex);
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
}
rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
if (rideEntry == nullptr)
{
log_warning("Invalid game command for ride %u", _rideIndex);
return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE);
}
if (ride->overall_view.xy != RCT_XY8_UNDEFINED)
{
LocationXYZ16 coord;
coord.x = ride->overall_view.x * 32 + 16;
coord.y = ride->overall_view.y * 32 + 16;
coord.z = tile_element_height(coord.x, coord.y);
network_set_player_last_action_coord(network_get_player_index(game_command_playerid), coord);
}
uint32_t shopItem;
if (_primaryPrice)
{
shopItem = SHOP_ITEM_ADMISSION;
if (ride->type != RIDE_TYPE_TOILETS)
{
shopItem = rideEntry->shop_item;
if (shopItem == SHOP_ITEM_NONE)
{
ride->price = _price;
window_invalidate_by_class(WC_RIDE);
return res;
}
}
// Check same price in park flags
if (!shop_item_has_common_price(shopItem))
{
ride->price = _price;
window_invalidate_by_class(WC_RIDE);
return res;
}
}
else
{
shopItem = rideEntry->shop_item_secondary;
if (shopItem == SHOP_ITEM_NONE)
{
shopItem = RidePhotoItems[ride->type];
if ((ride->lifecycle_flags & RIDE_LIFECYCLE_ON_RIDE_PHOTO) == 0)
{
ride->price_secondary = _price;
window_invalidate_by_class(WC_RIDE);
return res;
}
}
// Check same price in park flags
if (!shop_item_has_common_price(shopItem))
{
ride->price_secondary = _price;
window_invalidate_by_class(WC_RIDE);
return res;
}
}
// Synchronize prices if enabled.
RideSetCommonPrice(shopItem);
return res;
}
private:
void RideSetCommonPrice(int32_t shopItem) const
{
Ride* ride = get_ride(0);
for (uint8_t rideId = 0; rideId < MAX_RIDES; rideId++, ride++)
{
// Unplaced rides have a type of NULL
if (ride->type == RIDE_TYPE_NULL)
continue;
rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
if (ride->type != RIDE_TYPE_TOILETS || shopItem != SHOP_ITEM_ADMISSION)
{
if (rideEntry->shop_item == shopItem)
{
ride->price = _price;
window_invalidate_by_number(WC_RIDE, rideId);
}
}
else
{
ride->price = _price;
window_invalidate_by_number(WC_RIDE, rideId);
}
// If the shop item is the same or an on-ride photo
if (rideEntry->shop_item_secondary == shopItem
|| (rideEntry->shop_item_secondary == SHOP_ITEM_NONE && shop_item_is_photo(shopItem)))
{
ride->price_secondary = _price;
window_invalidate_by_number(WC_RIDE, rideId);
}
}
}
};

View File

@ -6389,138 +6389,6 @@ void game_command_callback_ride_remove_track_piece(
window_ride_construction_mouseup_demolish_next_piece(x, y, z, direction, type);
}
/**
*
* rct2: 0x006B53E9
*/
void game_command_set_ride_price(
[[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)
{
uint32_t flags = *ebx;
uint8_t ride_number = (*edx & 0xFF);
if (ride_number >= MAX_RIDES)
{
log_warning("Invalid game command for ride %u", ride_number);
*ebx = MONEY32_UNDEFINED;
return;
}
Ride* ride = get_ride(ride_number);
if (ride->type == RIDE_TYPE_NULL)
{
log_warning("Invalid game command for ride %u", ride_number);
*ebx = MONEY32_UNDEFINED;
return;
}
rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
money16 price = *edi;
bool secondary_price = (*edx >> 8);
if (rideEntry == nullptr)
{
log_warning("Invalid game command for ride %u", ride_number);
*ebx = MONEY32_UNDEFINED;
return;
}
// eax
// ebx flags
// ecx ecx
// edx ride_number
// ebp rideEntry
*ebx = 0; // for cost check - changing ride price does not cost anything
gCommandExpenditureType = RCT_EXPENDITURE_TYPE_PARK_RIDE_TICKETS;
if (flags & GAME_COMMAND_FLAG_APPLY)
{
uint32_t shop_item;
if (ride->overall_view.xy != RCT_XY8_UNDEFINED)
{
LocationXYZ16 coord;
coord.x = ride->overall_view.x * 32 + 16;
coord.y = ride->overall_view.y * 32 + 16;
coord.z = tile_element_height(coord.x, coord.y);
network_set_player_last_action_coord(network_get_player_index(game_command_playerid), coord);
}
if (!secondary_price)
{
shop_item = SHOP_ITEM_ADMISSION;
if (ride->type != RIDE_TYPE_TOILETS)
{
shop_item = rideEntry->shop_item;
if (shop_item == SHOP_ITEM_NONE)
{
ride->price = price;
window_invalidate_by_class(WC_RIDE);
return;
}
}
// Check same price in park flags
if (!shop_item_has_common_price(shop_item))
{
ride->price = price;
window_invalidate_by_class(WC_RIDE);
return;
}
}
else
{
shop_item = rideEntry->shop_item_secondary;
if (shop_item == SHOP_ITEM_NONE)
{
shop_item = RidePhotoItems[ride->type];
if ((ride->lifecycle_flags & RIDE_LIFECYCLE_ON_RIDE_PHOTO) == 0)
{
ride->price_secondary = price;
window_invalidate_by_class(WC_RIDE);
return;
}
}
// Check same price in park flags
if (!shop_item_has_common_price(shop_item))
{
ride->price_secondary = price;
window_invalidate_by_class(WC_RIDE);
return;
}
}
ride = get_ride(0);
for (uint8_t rideId = 0; rideId < MAX_RIDES; rideId++, ride++)
{
// Unplaced rides have a type of NULL
if (ride->type == RIDE_TYPE_NULL)
continue;
rideEntry = get_ride_entry(ride->subtype);
if (ride->type != RIDE_TYPE_TOILETS || shop_item != SHOP_ITEM_ADMISSION)
{
if (rideEntry->shop_item == shop_item)
{
ride->price = price;
window_invalidate_by_number(WC_RIDE, rideId);
}
}
else
{
ride->price = price;
window_invalidate_by_number(WC_RIDE, rideId);
}
// If the shop item is the same or an on-ride photo
if (rideEntry->shop_item_secondary == shop_item
|| (rideEntry->shop_item_secondary == SHOP_ITEM_NONE && shop_item_is_photo(shop_item)))
{
ride->price_secondary = price;
window_invalidate_by_number(WC_RIDE, rideId);
}
}
}
}
bool ride_type_has_flag(int32_t rideType, int32_t flag)
{
return (RideProperties[rideType].flags & flag) != 0;

View File

@ -1077,8 +1077,6 @@ void game_command_callback_ride_remove_track_piece(
int32_t eax, int32_t ebx, int32_t ecx, int32_t edx, int32_t esi, int32_t edi, int32_t ebp);
void game_command_demolish_ride(
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_ride_price(
int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp);
money32 ride_create_command(int32_t type, int32_t subType, int32_t flags, ride_id_t* outRideIndex, uint8_t* outRideColour);
void ride_set_name_to_default(Ride* ride, rct_ride_entry* rideEntry);