Files
OpenRCT2-Web/src/openrct2/actions/GameActionCompat.cpp
T

159 lines
4.4 KiB
C++
Raw Normal View History

2017-07-21 18:14:20 +01:00
/*****************************************************************************
2019-03-17 08:16:15 +01:00
* Copyright (c) 2014-2019 OpenRCT2 developers
2018-06-15 14:07:34 +02:00
*
* 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.
*****************************************************************************/
2017-07-21 18:14:20 +01:00
#include "GameAction.h"
#include "GuestSetNameAction.hpp"
2018-06-22 22:56:21 +02:00
#include "MazeSetTrackAction.hpp"
#include "PlaceParkEntranceAction.hpp"
2018-06-22 22:56:21 +02:00
#include "PlacePeepSpawnAction.hpp"
#include "RideCreateAction.hpp"
#include "RideDemolishAction.hpp"
#include "RideSetName.hpp"
#include "RideSetStatus.hpp"
#include "SetParkEntranceFeeAction.hpp"
#include "StaffSetNameAction.hpp"
#include "WallRemoveAction.hpp"
#pragma region PlaceParkEntranceAction
2018-06-22 22:56:21 +02:00
/**
*
* rct2: 0x00666F4E
*/
money32 park_entrance_place_ghost(const CoordsXYZD& entranceLoc)
2018-06-22 22:56:21 +02:00
{
park_entrance_remove_ghost();
2019-12-12 09:58:27 +00:00
auto gameAction = PlaceParkEntranceAction(entranceLoc);
2018-06-22 22:56:21 +02:00
gameAction.SetFlags(GAME_COMMAND_FLAG_GHOST);
auto result = GameActions::Execute(&gameAction);
if (result->Error == GA_ERROR::OK)
{
2019-12-12 09:58:27 +00:00
gParkEntranceGhostPosition = entranceLoc;
2018-06-22 22:56:21 +02:00
gParkEntranceGhostExists = true;
}
2018-06-22 22:56:21 +02:00
return result->Cost;
}
#pragma endregion
#pragma region SetParkEntranceFeeAction
2018-06-22 22:56:21 +02:00
void park_set_entrance_fee(money32 fee)
{
2020-04-22 17:09:29 +02:00
auto gameAction = SetParkEntranceFeeAction(static_cast<money16>(fee));
2018-06-22 22:56:21 +02:00
GameActions::Execute(&gameAction);
}
#pragma endregion
#pragma region RideCreateAction
2018-06-22 22:56:21 +02:00
/**
*
* rct2: 0x006B4800
*/
void ride_construct_new(RideSelection listItem)
2018-06-22 22:56:21 +02:00
{
int32_t rideEntryIndex = ride_get_entry_index(listItem.Type, listItem.EntryIndex);
int32_t colour1 = ride_get_random_colour_preset_index(listItem.Type);
2018-06-22 22:56:21 +02:00
int32_t colour2 = ride_get_unused_preset_vehicle_colour(rideEntryIndex);
auto gameAction = RideCreateAction(listItem.Type, listItem.EntryIndex, colour1, colour2);
2018-06-22 22:56:21 +02:00
gameAction.SetCallback([](const GameAction* ga, const RideCreateGameActionResult* result) {
if (result->Error != GA_ERROR::OK)
return;
2019-01-18 18:46:22 +00:00
auto ride = get_ride(result->rideIndex);
ride_construct(ride);
2018-06-22 22:56:21 +02:00
});
2018-06-22 22:56:21 +02:00
GameActions::Execute(&gameAction);
}
#pragma endregion
#pragma region RideSetStatusAction
2019-02-12 23:58:45 +00:00
void ride_set_status(Ride* ride, int32_t status)
2018-06-22 22:56:21 +02:00
{
2019-02-12 23:58:45 +00:00
auto gameAction = RideSetStatusAction(ride->id, status);
2018-06-22 22:56:21 +02:00
GameActions::Execute(&gameAction);
}
#pragma endregion
#pragma region RideSetNameAction
2019-02-12 23:58:45 +00:00
void ride_set_name(Ride* ride, const char* name, uint32_t flags)
2018-06-22 22:56:21 +02:00
{
2019-02-12 23:58:45 +00:00
auto gameAction = RideSetNameAction(ride->id, name);
gameAction.SetFlags(flags);
2018-06-22 22:56:21 +02:00
GameActions::Execute(&gameAction);
}
#pragma endregion
2018-03-29 11:17:54 +02:00
#pragma region RideModifyAction
2019-01-20 14:54:59 +00:00
void ride_action_modify(Ride* ride, int32_t modifyType, int32_t flags)
2018-06-22 22:56:21 +02:00
{
2019-01-20 14:54:59 +00:00
auto gameAction = RideDemolishAction(ride->id, modifyType);
2018-06-22 22:56:21 +02:00
gameAction.SetFlags(flags);
2018-06-22 22:56:21 +02:00
GameActions::Execute(&gameAction);
}
#pragma endregion
#pragma region GuestSetName
2018-06-22 22:56:21 +02:00
void guest_set_name(uint16_t spriteIndex, const char* name)
{
auto gameAction = GuestSetNameAction(spriteIndex, name);
GameActions::Execute(&gameAction);
}
#pragma endregion
2017-10-02 14:56:23 +02:00
#pragma region StaffSetName
2018-06-22 22:56:21 +02:00
void staff_set_name(uint16_t spriteIndex, const char* name)
{
auto gameAction = StaffSetNameAction(spriteIndex, name);
GameActions::Execute(&gameAction);
}
2018-02-19 15:11:14 -05:00
#pragma endregion
#pragma region MazeSetTrack
2018-06-22 22:56:21 +02:00
money32 maze_set_track(
2019-01-12 10:11:55 +00:00
uint16_t x, uint16_t y, uint16_t z, uint8_t flags, bool initialPlacement, uint8_t direction, ride_id_t rideIndex,
2018-06-22 22:56:21 +02:00
uint8_t mode)
{
2019-07-07 04:53:59 +03:00
auto gameAction = MazeSetTrackAction({ x, y, z, direction }, initialPlacement, rideIndex, mode);
2018-06-22 22:56:21 +02:00
gameAction.SetFlags(flags);
GameActionResult::Ptr res;
if (!(flags & GAME_COMMAND_FLAG_APPLY))
res = GameActions::Query(&gameAction);
else
res = GameActions::Execute(&gameAction);
// NOTE: ride_construction_tooldown_construct requires them to be set.
// Refactor result type once theres no C code referencing this function.
2020-04-20 23:30:37 +01:00
if (auto title = res->ErrorTitle.AsStringId())
2020-03-03 21:11:26 +00:00
gGameCommandErrorTitle = *title;
else
gGameCommandErrorTitle = STR_NONE;
2020-04-20 23:30:37 +01:00
if (auto message = res->ErrorMessage.AsStringId())
2020-03-03 21:11:26 +00:00
gGameCommandErrorText = *message;
else
gGameCommandErrorText = STR_NONE;
2018-06-22 22:56:21 +02:00
if (res->Error != GA_ERROR::OK)
{
2018-06-22 22:56:21 +02:00
return MONEY32_UNDEFINED;
}
2018-06-22 22:56:21 +02:00
return res->Cost;
}
#pragma endregion