1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Move all callees to the game action framework. Fix CoordXY bug

This commit is contained in:
duncanspumpkin
2019-02-28 10:56:25 +00:00
parent 27046c2468
commit 7f586f50e1
6 changed files with 90 additions and 63 deletions

View File

@@ -13,6 +13,7 @@
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/actions/RideEntranceExitPlaceAction.hpp>
#include <openrct2/audio/audio.h>
#include <openrct2/drawing/Drawing.h>
#include <openrct2/localisation/Localisation.h>
@@ -364,38 +365,32 @@ static void window_maze_construction_entrance_tooldown(int32_t x, int32_t y, rct
return;
ride_id_t rideIndex = gRideEntranceExitPlaceRideIndex;
uint8_t entranceExitType = gRideEntranceExitPlaceType;
if (entranceExitType == ENTRANCE_TYPE_RIDE_ENTRANCE)
{
gGameCommandErrorTitle = STR_CANT_BUILD_MOVE_ENTRANCE_FOR_THIS_RIDE_ATTRACTION;
}
else
{
gGameCommandErrorTitle = STR_CANT_BUILD_MOVE_EXIT_FOR_THIS_RIDE_ATTRACTION;
}
money32 cost = game_do_command(
x, GAME_COMMAND_FLAG_APPLY | (direction_reverse(direction) << 8), y, rideIndex | (entranceExitType << 8),
GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, gRideEntranceExitPlaceStationIndex, 0);
auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction(
{ x, y }, direction_reverse(direction), rideIndex, gRideEntranceExitPlaceStationIndex,
gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_EXIT);
if (cost == MONEY32_UNDEFINED)
rideEntranceExitPlaceAction.SetCallback([=](const GameAction* ga, const GameActionResult* result) {
if (result->Error != GA_ERROR::OK)
return;
audio_play_sound_at_location(SOUND_PLACE_ITEM, gCommandPosition.x, gCommandPosition.y, gCommandPosition.z);
audio_play_sound_at_location(SOUND_PLACE_ITEM, result->Position.x, result->Position.y, result->Position.z);
Ride* ride = get_ride(rideIndex);
if (ride_are_all_possible_entrances_and_exits_built(ride))
{
tool_cancel();
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_NO_TRACK))
window_close(w);
window_close_by_class(WC_RIDE_CONSTRUCTION);
}
else
{
gRideEntranceExitPlaceType = entranceExitType ^ 1;
gRideEntranceExitPlaceType = gRideEntranceExitPlaceType ^ 1;
window_invalidate_by_class(WC_RIDE_CONSTRUCTION);
gCurrentToolWidget.widget_index = entranceExitType ? WIDX_MAZE_ENTRANCE : WIDX_MAZE_EXIT;
gCurrentToolWidget.widget_index = gRideEntranceExitPlaceType ? WIDX_MAZE_ENTRANCE : WIDX_MAZE_EXIT;
}
});
auto res = GameActions::Execute(&rideEntranceExitPlaceAction);
}
/**

View File

@@ -17,6 +17,7 @@
#include <openrct2/Context.h>
#include <openrct2/Game.h>
#include <openrct2/Input.h>
#include <openrct2/actions/RideEntranceExitPlaceAction.hpp>
#include <openrct2/actions/TrackPlaceAction.hpp>
#include <openrct2/actions/TrackRemoveAction.hpp>
#include <openrct2/audio/audio.h>
@@ -3938,15 +3939,36 @@ static void ride_construction_tooldown_entrance_exit(int32_t screenX, int32_t sc
if (gRideEntranceExitPlaceDirection == 255)
return;
gGameCommandErrorTitle = (gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_ENTRANCE)
? STR_CANT_BUILD_MOVE_ENTRANCE_FOR_THIS_RIDE_ATTRACTION
: STR_CANT_BUILD_MOVE_EXIT_FOR_THIS_RIDE_ATTRACTION;
auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction(
{ _unkF44188.x, _unkF44188.y }, direction_reverse(gRideEntranceExitPlaceDirection), gRideEntranceExitPlaceRideIndex,
gRideEntranceExitPlaceStationIndex,
gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_EXIT);
game_command_callback = game_command_callback_place_ride_entrance_or_exit;
game_do_command(
_unkF44188.x, (GAME_COMMAND_FLAG_APPLY) | (direction_reverse(gRideEntranceExitPlaceDirection) << 8), _unkF44188.y,
gRideEntranceExitPlaceRideIndex | (gRideEntranceExitPlaceType << 8), GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT,
gRideEntranceExitPlaceStationIndex, 0);
rideEntranceExitPlaceAction.SetCallback([=](const GameAction* ga, const GameActionResult* result) {
if (result->Error != GA_ERROR::OK)
return;
audio_play_sound_at_location(SOUND_PLACE_ITEM, result->Position.x, result->Position.y, result->Position.z);
Ride* ride = get_ride(gRideEntranceExitPlaceRideIndex);
if (ride_are_all_possible_entrances_and_exits_built(ride))
{
tool_cancel();
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_NO_TRACK))
{
window_close_by_class(WC_RIDE_CONSTRUCTION);
}
}
else
{
gRideEntranceExitPlaceType = gRideEntranceExitPlaceType ^ 1;
window_invalidate_by_class(WC_RIDE_CONSTRUCTION);
gCurrentToolWidget.widget_index = (gRideEntranceExitPlaceType == ENTRANCE_TYPE_RIDE_ENTRANCE)
? WC_RIDE_CONSTRUCTION__WIDX_ENTRANCE
: WC_RIDE_CONSTRUCTION__WIDX_EXIT;
}
});
auto res = GameActions::Execute(&rideEntranceExitPlaceAction);
}
void window_ride_construction_keyboard_shortcut_turn_left()

View File

@@ -14,6 +14,8 @@
#include "../ride/Station.h"
#include "../world/Entrance.h"
#include "../world/MapAnimation.h"
#include "../management/Finance.h"
#include "../world/Sprite.h"
#include "GameAction.h"
DEFINE_GAME_ACTION(RideEntranceExitPlaceAction, GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, GameActionResult)
@@ -46,7 +48,7 @@ public:
{
GameAction::Serialise(stream);
stream << DS_TAG(_loc) << DS_TAG(_rideIndex) << DS_TAG(_stationNum) << DS_TAG(_isExit);
stream << DS_TAG(_loc) << DS_TAG(_direction) << DS_TAG(_rideIndex) << DS_TAG(_stationNum) << DS_TAG(_isExit);
}
GameActionResult::Ptr Query() const override

View File

@@ -331,9 +331,9 @@ template<> struct DataSerializerTraits<CoordsXY>
}
static void decode(IStream* stream, CoordsXY& coords)
{
auto x = ByteSwapBE(stream->ReadValue<int16_t>());
auto y = ByteSwapBE(stream->ReadValue<int16_t>());
coords = CoordsXY(x, y);
auto x = ByteSwapBE(stream->ReadValue<int32_t>());
auto y = ByteSwapBE(stream->ReadValue<int32_t>());
coords = CoordsXY{x, y};
}
static void log(IStream* stream, const CoordsXY& coords)
{

View File

@@ -1232,9 +1232,10 @@ static int32_t track_design_place_maze(rct_track_td6* td6, int16_t x, int16_t y,
flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5
| GAME_COMMAND_FLAG_GHOST;
}
cost = game_do_command(
mapCoord.x, flags | rotation << 8, mapCoord.y, ride->id, GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT,
0, 0);
auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction(mapCoord, rotation, ride->id, 0, false);
rideEntranceExitPlaceAction.SetFlags(flags);
auto res = GameActions::ExecuteNested(&rideEntranceExitPlaceAction);
cost = res->Error == GA_ERROR::OK ? res->Cost : MONEY32_UNDEFINED;
}
if (cost != MONEY32_UNDEFINED)
{
@@ -1265,9 +1266,10 @@ static int32_t track_design_place_maze(rct_track_td6* td6, int16_t x, int16_t y,
flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5
| GAME_COMMAND_FLAG_GHOST;
}
cost = game_do_command(
mapCoord.x, flags | rotation << 8, mapCoord.y, ride->id | (1 << 8),
GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, 0, 0);
auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction(mapCoord, rotation, ride->id, 0, true);
rideEntranceExitPlaceAction.SetFlags(flags);
auto res = GameActions::ExecuteNested(&rideEntranceExitPlaceAction);
cost = res->Error == GA_ERROR::OK ? res->Cost : MONEY32_UNDEFINED;
}
if (cost != MONEY32_UNDEFINED)
{
@@ -1572,10 +1574,10 @@ static bool track_design_place_ride(rct_track_td6* td6, int16_t x, int16_t y, in
case PTD_OPERATION_GET_COST:
{
rotation = (rotation + entrance->direction) & 3;
uint8_t isExit = 0;
bool isExit = false;
if (entrance->direction & (1 << 7))
{
isExit = 1;
isExit = true;
}
if (_trackDesignPlaceOperation != PTD_OPERATION_1)
@@ -1600,29 +1602,33 @@ static bool track_design_place_ride(rct_track_td6* td6, int16_t x, int16_t y, in
}
int32_t stationIndex = tile_element->AsTrack()->GetStationIndex();
uint8_t bl = 1;
uint8_t flags = GAME_COMMAND_FLAG_APPLY;
if (_trackDesignPlaceOperation == PTD_OPERATION_GET_COST)
{
bl = 41;
flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5;
}
if (_trackDesignPlaceOperation == PTD_OPERATION_4)
{
bl = 105;
flags = GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5
| GAME_COMMAND_FLAG_GHOST;
}
if (_trackDesignPlaceOperation == PTD_OPERATION_1)
{
bl = 0;
flags = 0;
}
gGameCommandErrorTitle = STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE;
money32 cost = game_do_command(
x, bl | (rotation << 8), y, ride->id | (isExit << 8), GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT,
stationIndex, 0);
_trackDesignPlaceCost += cost;
auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction(
{ x, y }, rotation, ride->id, stationIndex, isExit);
rideEntranceExitPlaceAction.SetFlags(flags);
auto res = flags & GAME_COMMAND_FLAG_APPLY ? GameActions::ExecuteNested(&rideEntranceExitPlaceAction)
: GameActions::QueryNested(&rideEntranceExitPlaceAction);
if (cost == MONEY32_UNDEFINED)
_trackDesignPlaceCost += res->Cost;
if (res->Error != GA_ERROR::OK)
{
_trackDesignPlaceCost = cost;
_trackDesignPlaceCost = MONEY32_UNDEFINED;
return false;
}
_trackDesignPlaceStateEntranceExitPlaced = true;

View File

@@ -12,6 +12,7 @@
#include "../Cheats.h"
#include "../Game.h"
#include "../OpenRCT2.h"
#include "../actions/RideEntranceExitPlaceAction.hpp"
#include "../actions/RideEntranceExitRemoveAction.hpp"
#include "../localisation/StringIds.h"
#include "../management/Finance.h"
@@ -314,11 +315,12 @@ static money32 RideEntranceExitPlace(
static money32 RideEntranceExitPlaceGhost(
ride_id_t rideIndex, int16_t x, int16_t y, uint8_t direction, uint8_t placeType, uint8_t stationNum)
{
return game_do_command(
x,
(GAME_COMMAND_FLAG_APPLY | GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_5 | GAME_COMMAND_FLAG_GHOST)
| (direction << 8),
y, rideIndex | (placeType << 8), GAME_COMMAND_PLACE_RIDE_ENTRANCE_OR_EXIT, stationNum, 0);
auto rideEntranceExitPlaceAction = RideEntranceExitPlaceAction(
{ x, y }, direction, rideIndex, stationNum, placeType == ENTRANCE_TYPE_RIDE_EXIT);
rideEntranceExitPlaceAction.SetFlags(GAME_COMMAND_FLAG_ALLOW_DURING_PAUSED | GAME_COMMAND_FLAG_GHOST);
auto res = GameActions::Execute(&rideEntranceExitPlaceAction);
return res->Error == GA_ERROR::OK ? res->Cost : MONEY32_UNDEFINED;
}
/**