mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-04 13:42:55 +01:00
Refactor GameActions to allow non-top level actions.
This commit is contained in:
@@ -137,7 +137,7 @@ namespace GameActions
|
||||
return false;
|
||||
}
|
||||
|
||||
GameActionResult::Ptr Query(const GameAction* action)
|
||||
GameActionResult::Ptr Query(const GameAction* action, bool topLevel /* = true */)
|
||||
{
|
||||
Guard::ArgumentNotNull(action);
|
||||
|
||||
@@ -155,9 +155,13 @@ namespace GameActions
|
||||
|
||||
auto result = action->Query();
|
||||
|
||||
gCommandPosition.x = result->Position.x;
|
||||
gCommandPosition.y = result->Position.y;
|
||||
gCommandPosition.z = result->Position.z;
|
||||
// Only top level actions affect the command position.
|
||||
if (topLevel == true)
|
||||
{
|
||||
gCommandPosition.x = result->Position.x;
|
||||
gCommandPosition.y = result->Position.y;
|
||||
gCommandPosition.z = result->Position.z;
|
||||
}
|
||||
|
||||
if (result->Error == GA_ERROR::OK)
|
||||
{
|
||||
@@ -223,7 +227,7 @@ namespace GameActions
|
||||
network_append_server_log(text);
|
||||
}
|
||||
|
||||
GameActionResult::Ptr Execute(const GameAction* action)
|
||||
GameActionResult::Ptr Execute(const GameAction* action, bool topLevel /* = true */)
|
||||
{
|
||||
Guard::ArgumentNotNull(action);
|
||||
|
||||
@@ -247,31 +251,34 @@ namespace GameActions
|
||||
}
|
||||
}
|
||||
|
||||
GameActionResult::Ptr result = Query(action);
|
||||
GameActionResult::Ptr result = Query(action, topLevel);
|
||||
if (result->Error == GA_ERROR::OK)
|
||||
{
|
||||
// Networked games send actions to the server to be run
|
||||
if (network_get_mode() == NETWORK_MODE_CLIENT)
|
||||
if (topLevel)
|
||||
{
|
||||
// As a client we have to wait or send it first.
|
||||
if (!(actionFlags & GA_FLAGS::CLIENT_ONLY) && !(flags & GAME_COMMAND_FLAG_NETWORKED))
|
||||
// Networked games send actions to the server to be run
|
||||
if (network_get_mode() == NETWORK_MODE_CLIENT)
|
||||
{
|
||||
log_verbose("[%s] GameAction::Execute %s (Out)", GetRealm(), action->GetName());
|
||||
network_send_game_action(action);
|
||||
// As a client we have to wait or send it first.
|
||||
if (!(actionFlags & GA_FLAGS::CLIENT_ONLY) && !(flags & GAME_COMMAND_FLAG_NETWORKED))
|
||||
{
|
||||
log_verbose("[%s] GameAction::Execute %s (Out)", GetRealm(), action->GetName());
|
||||
network_send_game_action(action);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (network_get_mode() == NETWORK_MODE_SERVER)
|
||||
{
|
||||
// If player is the server it would execute right away as where clients execute the commands
|
||||
// at the beginning of the frame, so we have to put them into the queue.
|
||||
if (!(actionFlags & GA_FLAGS::CLIENT_ONLY) && !(flags & GAME_COMMAND_FLAG_NETWORKED))
|
||||
else if (network_get_mode() == NETWORK_MODE_SERVER)
|
||||
{
|
||||
log_verbose("[%s] GameAction::Execute %s (Queue)", GetRealm(), action->GetName());
|
||||
network_enqueue_game_action(action);
|
||||
// If player is the server it would execute right away as where clients execute the commands
|
||||
// at the beginning of the frame, so we have to put them into the queue.
|
||||
if (!(actionFlags & GA_FLAGS::CLIENT_ONLY) && !(flags & GAME_COMMAND_FLAG_NETWORKED))
|
||||
{
|
||||
log_verbose("[%s] GameAction::Execute %s (Queue)", GetRealm(), action->GetName());
|
||||
network_enqueue_game_action(action);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,6 +290,10 @@ namespace GameActions
|
||||
|
||||
LogActionFinish(logContext, action, result);
|
||||
|
||||
// If not top level just give away the result.
|
||||
if (topLevel == false)
|
||||
return result;
|
||||
|
||||
gCommandPosition.x = result->Position.x;
|
||||
gCommandPosition.y = result->Position.y;
|
||||
gCommandPosition.z = result->Position.z;
|
||||
@@ -349,6 +360,7 @@ namespace GameActions
|
||||
std::copy(result->ErrorMessageArgs.begin(), result->ErrorMessageArgs.end(), gCommonFormatArgs);
|
||||
context_show_error(result->ErrorTitle, result->ErrorMessage);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -244,8 +244,8 @@ namespace GameActions
|
||||
bool IsValidId(uint32_t id);
|
||||
GameAction::Ptr Create(uint32_t id);
|
||||
GameAction::Ptr Clone(const GameAction* action);
|
||||
GameActionResult::Ptr Query(const GameAction* action);
|
||||
GameActionResult::Ptr Execute(const GameAction* action);
|
||||
GameActionResult::Ptr Query(const GameAction* action, bool topLevel = true);
|
||||
GameActionResult::Ptr Execute(const GameAction* action, bool topLevel = true);
|
||||
GameActionFactory Register(uint32_t id, GameActionFactory action);
|
||||
|
||||
template<typename T> static GameActionFactory Register()
|
||||
|
||||
Reference in New Issue
Block a user