mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 20:43:04 +01:00
Implement BalloonPressAction
Furthering reducing the number of game commands and moving them to the Game Action framework
This commit is contained in:
committed by
Michael Steenbeek
parent
4dc77bf121
commit
7793001f5d
@@ -16,6 +16,7 @@
|
||||
#include <openrct2/Game.h>
|
||||
#include <openrct2/Input.h>
|
||||
#include <openrct2/OpenRCT2.h>
|
||||
#include <openrct2/actions/BalloonPressAction.hpp>
|
||||
#include <openrct2/actions/FootpathSceneryRemoveAction.hpp>
|
||||
#include <openrct2/actions/LargeSceneryRemoveAction.hpp>
|
||||
#include <openrct2/actions/ParkEntranceRemoveAction.hpp>
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
61
src/openrct2/actions/BalloonPressAction.hpp
Normal file
61
src/openrct2/actions/BalloonPressAction.hpp
Normal file
@@ -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();
|
||||
}
|
||||
};
|
||||
@@ -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<BalloonPressAction>();
|
||||
Register<BannerPlaceAction>();
|
||||
Register<BannerRemoveAction>();
|
||||
Register<BannerSetColourAction>();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user