summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-08 14:55:28 +0000
committerrubidium <rubidium@openttd.org>2009-01-08 14:55:28 +0000
commit78c43297e276af4f4403108b5ad93715897c62a9 (patch)
tree9fe08d5845cf6f8e94b83f9103044e7460ced669
parent0e1127e8b5b94d5966333662d0cd13e306b39cbb (diff)
downloadopenttd-78c43297e276af4f4403108b5ad93715897c62a9.tar.xz
(svn r14916) -Codechange: make it possible to send CommandContainers directly to DoCommand(P).
-rw-r--r--src/command.cpp25
-rw-r--r--src/command_func.h2
-rw-r--r--src/network/network_command.cpp17
3 files changed, 32 insertions, 12 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 08a9269aa..3956c2c88 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -373,6 +373,19 @@ byte GetCommandFlags(uint32 cmd)
static int _docommand_recursive = 0;
+/**
+ * Shorthand for calling the long DoCommand with a container.
+ *
+ * @param container Container with (almost) all information
+ * @param flags Flags for the command and how to execute the command
+ * @see CommandProc
+ * @return the cost
+ */
+CommandCost DoCommand(const CommandContainer *container, uint32 flags)
+{
+ return DoCommand(container->tile, container->p1, container->p2, flags, container->cmd, container->text);
+}
+
/*!
* This function executes a given command with the parameters from the #CommandProc parameter list.
* Depending on the flags parameter it execute or test a command.
@@ -383,6 +396,7 @@ static int _docommand_recursive = 0;
* @param flags Flags for the command and how to execute the command
* @param cmd The command-id to execute (a value of the CMD_* enums)
* @see CommandProc
+ * @return the cost
*/
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 cmd, const char *text)
{
@@ -457,6 +471,17 @@ Money GetAvailableMoneyForCommand()
return GetCompany(company)->money;
}
+/**
+ * Shortcut for the long DoCommandP when having a container with the data.
+ * @param container the container with information.
+ * @param my_cmd indicator if the command is from a company or server (to display error messages for a user)
+ * @return true if the command succeeded, else false
+ */
+bool DoCommandP(const CommandContainer *container, bool my_cmd)
+{
+ return DoCommandP(container->tile, container->p1, container->p2, container->cmd, container->callback, container->text, my_cmd);
+}
+
/*!
* Toplevel network safe docommand function for the current company. Must not be called recursively.
* The callback is called when the command succeeded or failed. The parameters
diff --git a/src/command_func.h b/src/command_func.h
index b3370d9b1..1b8af25b9 100644
--- a/src/command_func.h
+++ b/src/command_func.h
@@ -54,11 +54,13 @@ static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
* Execute a command
*/
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint32 cmd, const char *text = NULL);
+CommandCost DoCommand(const CommandContainer *container, uint32 flags);
/**
* Execute a network safe DoCommand function
*/
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = NULL, const char *text = NULL, bool my_cmd = true);
+bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
#ifdef ENABLE_NETWORK
diff --git a/src/network/network_command.cpp b/src/network/network_command.cpp
index 52f680aaa..4adeb92f6 100644
--- a/src/network/network_command.cpp
+++ b/src/network/network_command.cpp
@@ -93,16 +93,6 @@ void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, Comma
}
/**
- * Execute a DoCommand we received from the network
- * @param cp the command to execute
- */
-static void NetworkExecuteCommand(CommandPacket *cp)
-{
- _current_company = cp->company;
- DoCommandP(cp->tile, cp->p1, cp->p2, cp->cmd | CMD_NETWORK_COMMAND, cp->callback, cp->text, cp->my_cmd);
-}
-
-/**
* Execute all commands on the local command queue that ought to be executed this frame.
*/
void NetworkExecuteLocalCommandQueue()
@@ -119,10 +109,13 @@ void NetworkExecuteLocalCommandQueue()
error("[net] Trying to execute a packet in the past!");
}
+ CommandPacket *cp = _local_command_queue;
+
/* We can execute this command */
- NetworkExecuteCommand(_local_command_queue);
+ _current_company = cp->company;
+ cp->cmd |= CMD_NETWORK_COMMAND;
+ DoCommandP(cp, cp->my_cmd);
- CommandPacket *cp = _local_command_queue;
_local_command_queue = _local_command_queue->next;
free(cp);
}