diff --git a/src/openrct2-ui/interface/ViewportInteraction.cpp b/src/openrct2-ui/interface/ViewportInteraction.cpp index 310dbcb54d..fb7d288f88 100644 --- a/src/openrct2-ui/interface/ViewportInteraction.cpp +++ b/src/openrct2-ui/interface/ViewportInteraction.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -161,10 +162,11 @@ int32_t viewport_interaction_left_click(int32_t x, int32_t y) switch (info.sprite->generic.type) { case SPRITE_MISC_BALLOON: - game_do_command( - info.sprite->balloon.sprite_index, GAME_COMMAND_FLAG_APPLY, 0, 0, - GAME_COMMAND_BALLOON_PRESS, 0, 0); - break; + { + auto balloonPress = BalloonPressAction(info.sprite->AsBalloon()->sprite_index); + GameActions::Execute(&balloonPress); + } + break; case SPRITE_MISC_DUCK: duck_press(&info.sprite->duck); break; diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index cb7f865879..2fb6fc2489 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -1224,7 +1224,7 @@ GAME_COMMAND_POINTER* new_game_command_table[GAME_COMMAND_COUNT] = { nullptr, game_command_pickup_guest, game_command_pickup_staff, - game_command_balloon_press, + nullptr, game_command_modify_tile, game_command_edit_scenario_options, NULL, diff --git a/src/openrct2/Game.h b/src/openrct2/Game.h index 177f165e1a..266e1dc925 100644 --- a/src/openrct2/Game.h +++ b/src/openrct2/Game.h @@ -87,7 +87,7 @@ enum GAME_COMMAND GAME_COMMAND_CHEAT, GAME_COMMAND_PICKUP_GUEST, GAME_COMMAND_PICKUP_STAFF, - GAME_COMMAND_BALLOON_PRESS, + GAME_COMMAND_BALLOON_PRESS, // GA GAME_COMMAND_MODIFY_TILE, GAME_COMMAND_EDIT_SCENARIO_OPTIONS, GAME_COMMAND_PLACE_PEEP_SPAWN, // GA, TODO: refactor to separate array for just game actions diff --git a/src/openrct2/actions/BalloonPressAction.hpp b/src/openrct2/actions/BalloonPressAction.hpp new file mode 100644 index 0000000000..087f0f6501 --- /dev/null +++ b/src/openrct2/actions/BalloonPressAction.hpp @@ -0,0 +1,61 @@ +/***************************************************************************** + * 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 "../world/Sprite.h" +#include "GameAction.h" + +DEFINE_GAME_ACTION(BalloonPressAction, GAME_COMMAND_BALLOON_PRESS, GameActionResult) +{ + uint16_t _spriteIndex = SPRITE_INDEX_NULL; + +public: + BalloonPressAction() = default; + BalloonPressAction(uint16_t spriteIndex) + : _spriteIndex(spriteIndex) + { + } + + uint16_t GetActionFlags() const override + { + return GameAction::GetActionFlags(); + } + + void Serialise(DataSerialiser & stream) override + { + GameAction::Serialise(stream); + stream << DS_TAG(_spriteIndex); + } + + GameActionResult::Ptr Query() const override + { + rct_sprite* sprite = try_get_sprite(_spriteIndex); + if (sprite == nullptr || !sprite->IsBalloon()) + { + log_error("Tried getting invalid sprite for balloon: %u", _spriteIndex); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); + } + return MakeResult(); + } + + GameActionResult::Ptr Execute() const override + { + rct_sprite* sprite = try_get_sprite(_spriteIndex); + if (sprite == nullptr || !sprite->IsBalloon()) + { + log_error("Tried getting invalid sprite for balloon: %u", _spriteIndex); + return MakeResult(GA_ERROR::INVALID_PARAMETERS, STR_NONE); + } + + sprite->AsBalloon()->Press(); + + return MakeResult(); + } +}; diff --git a/src/openrct2/actions/GameActionRegistration.cpp b/src/openrct2/actions/GameActionRegistration.cpp index 990a303e72..8bd8e40d2c 100644 --- a/src/openrct2/actions/GameActionRegistration.cpp +++ b/src/openrct2/actions/GameActionRegistration.cpp @@ -7,6 +7,7 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "BalloonPressAction.hpp" #include "BannerPlaceAction.hpp" #include "BannerRemoveAction.hpp" #include "BannerSetColourAction.hpp" @@ -84,6 +85,7 @@ namespace GameActions { void Register() { + Register(); Register(); Register(); Register(); diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 4864e554d7..560435b051 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -32,7 +32,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "28" +#define NETWORK_STREAM_VERSION "29" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr; diff --git a/src/openrct2/world/Balloon.cpp b/src/openrct2/world/Balloon.cpp index 3e1b982150..628b9746ef 100644 --- a/src/openrct2/world/Balloon.cpp +++ b/src/openrct2/world/Balloon.cpp @@ -84,24 +84,6 @@ void rct_balloon::Pop() audio_play_sound_at_location(SOUND_BALLOON_POP, x, y, z); } -static money32 game_command_balloon_press(uint16_t spriteIndex, uint8_t flags) -{ - rct_sprite* sprite = try_get_sprite(spriteIndex); - if (sprite == nullptr || !sprite->IsBalloon()) - { - log_error("Tried getting invalid sprite for balloon: %u", spriteIndex); - return MONEY32_UNDEFINED; - } - else - { - if (flags & GAME_COMMAND_FLAG_APPLY) - { - sprite->AsBalloon()->Press(); - } - return 0; - } -} - void create_balloon(int32_t x, int32_t y, int32_t z, int32_t colour, bool isPopped) { rct_sprite* sprite = create_sprite(2); @@ -124,10 +106,3 @@ void balloon_update(rct_balloon* balloon) { balloon->Update(); } - -void game_command_balloon_press( - int32_t* eax, int32_t* ebx, [[maybe_unused]] int32_t* ecx, [[maybe_unused]] int32_t* edx, [[maybe_unused]] int32_t* esi, - [[maybe_unused]] int32_t* edi, [[maybe_unused]] int32_t* ebp) -{ - *ebx = game_command_balloon_press(*eax & 0xFFFF, *ebx & 0xFF); -} diff --git a/src/openrct2/world/Sprite.h b/src/openrct2/world/Sprite.h index 6662a7dd64..7d41dd68a2 100644 --- a/src/openrct2/world/Sprite.h +++ b/src/openrct2/world/Sprite.h @@ -229,8 +229,6 @@ void sprite_position_tween_reset(); /////////////////////////////////////////////////////////////// void create_balloon(int32_t x, int32_t y, int32_t z, int32_t colour, bool isPopped); void balloon_update(rct_balloon* balloon); -void game_command_balloon_press( - int32_t* eax, int32_t* ebx, int32_t* ecx, int32_t* edx, int32_t* esi, int32_t* edi, int32_t* ebp); /////////////////////////////////////////////////////////////// // Duck