Translations update
[openttd/fttd.git] / src / command_func.h
blobed71fc49796b0ac8d0f19946f264c07c97e25538
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file command_func.h Functions related to commands. */
12 #ifndef COMMAND_FUNC_H
13 #define COMMAND_FUNC_H
15 #include "command_type.h"
16 #include "company_type.h"
18 /**
19 * Define a default return value for a failed command.
21 * This variable contains a CommandCost object with is declared as "failed".
22 * Other functions just need to return this error if there is an error,
23 * which doesn't need to specific by a StringID.
25 static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
27 /**
28 * Returns from a function with a specific StringID as error.
30 * This macro is used to return from a function. The parameter contains the
31 * StringID which will be returned.
33 * @param errcode The StringID to return
35 #define return_cmd_error(errcode) return CommandCost(errcode);
37 /*!
38 * This function executes a given command with the parameters from the #CommandProc parameter list.
39 * Depending on the flags parameter it execute or test a command.
41 * @param tile The tile to apply the command on (for the #CommandProc)
42 * @param p1 Additional data for the command (for the #CommandProc)
43 * @param p2 Additional data for the command (for the #CommandProc)
44 * @param flags Flags for the command and how to execute the command
45 * @param cmd The command-id to execute (a value of the CMD_* enums)
46 * @param text The text to pass
47 * @see CommandProc
48 * @return the cost
50 static inline CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, CommandID cmd, const char *text = NULL)
52 const Command c (tile, p1, p2, cmd, text);
54 return c.exec (flags);
57 /*!
58 * Toplevel network safe docommand function for the current company. Must not be called recursively.
59 * The parameters \a tile, \a p1, and \a p2 are from the #CommandProc function.
60 * The parameter \a cmd is the command to execute.
62 * @param tile The tile to perform a command on (see #CommandProc)
63 * @param p1 Additional data for the command (see #CommandProc)
64 * @param p2 Additional data for the command (see #CommandProc)
65 * @param cmd The command to execute (a CMD_* value)
66 * @param text The text to pass
67 * @return \c true if the command succeeded, else \c false.
69 static inline bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandID cmd, const char *text = NULL)
71 Command c (tile, p1, p2, cmd, text);
73 return c.execp ();
76 /*!
77 * Helper function for the toplevel network safe docommand function for the current company.
79 * @param tile The tile to perform a command on (see #CommandProc)
80 * @param p1 Additional data for the command (see #CommandProc)
81 * @param p2 Additional data for the command (see #CommandProc)
82 * @param cmd The command to execute (a CMD_* value)
83 * @param text The text to pass
84 * @param estimate_only whether to give only the estimate or also execute the command
85 * @param cmdsrc Source of the command
86 * @return the command cost of this function.
88 static inline CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, CommandID cmd, const char *text, bool estimate_only, CommandSource cmdsrc = CMDSRC_SELF)
90 Command c (tile, p1, p2, cmd, text);
92 return c.execp_internal (estimate_only, cmdsrc);
95 #ifdef ENABLE_NETWORK
96 void NetworkSendCommand (const Command *cc, CompanyID company, CommandSource cmdsrc = CMDSRC_SELF);
98 /**
99 * Prepare a DoCommand to be send over the network
100 * @param tile The tile to perform a command on (see #CommandProc)
101 * @param p1 Additional data for the command (see #CommandProc)
102 * @param p2 Additional data for the command (see #CommandProc)
103 * @param cmd The command to execute (a CMD_* value)
104 * @param text The text to pass
105 * @param company The company that wants to send the command
107 static inline void NetworkSendCommand (TileIndex tile, uint32 p1, uint32 p2, CommandID cmd, const char *text, CompanyID company)
109 Command c (tile, p1, p2, cmd, text);
111 NetworkSendCommand (&c, company);
113 #endif /* ENABLE_NETWORK */
115 extern Money _additional_cash_required;
117 bool IsValidCommand(CommandID cmd);
118 CommandFlags GetCommandFlags(CommandID cmd);
119 const char *GetCommandName(CommandID cmd);
120 Money GetAvailableMoneyForCommand();
121 bool IsCommandAllowedWhilePaused(CommandID cmd);
124 * Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags
125 * @param cmd_flags Flags from GetCommandFlags
126 * @return flags for DoCommand
128 static inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
130 DoCommandFlag flags = DC_NONE;
131 if (cmd_flags & CMDF_NO_WATER) flags |= DC_NO_WATER;
132 if (cmd_flags & CMDF_AUTO) flags |= DC_AUTO;
133 if (cmd_flags & CMDF_ALL_TILES) flags |= DC_ALL_TILES;
134 return flags;
137 /*** All command callbacks that exist ***/
139 /* airport_gui.cpp */
140 CommandCallback CcBuildAirport;
142 /* bridge_gui.cpp */
143 CommandCallback CcBuildBridge;
145 /* dock_gui.cpp */
146 CommandCallback CcBuildDocks;
147 CommandCallback CcPlaySound_SPLAT_WATER;
149 /* depot_gui.cpp */
150 CommandCallback CcCloneVehicle;
152 /* group_gui.cpp */
153 CommandCallback CcCreateGroup;
154 CommandCallback CcAddVehicleGroup;
156 /* industry_gui.cpp */
157 CommandCallback CcBuildIndustry;
159 /* main_gui.cpp */
160 CommandCallback CcPlaySound_EXPLOSION;
161 CommandCallback CcPlaceSign;
162 CommandCallback CcTerraform;
163 CommandCallback CcTerraformLand;
164 CommandCallback CcGiveMoney;
166 /* object_gui.cpp */
167 CommandCallback CcBuildObject;
169 /* rail_gui.cpp */
170 CommandCallback CcPlaySound_SPLAT_RAIL;
171 CommandCallback CcSingleRail;
172 CommandCallback CcRailDepot;
173 CommandCallback CcStation;
175 /* road_gui.cpp */
176 CommandCallback CcPlaySound_SPLAT_OTHER;
177 CommandCallback CcBuildTunnel;
178 CommandCallback CcRoadDepot;
179 CommandCallback CcRoadStop;
181 /* town_gui.cpp */
182 CommandCallback CcFoundTown;
184 /* vehicle_gui.cpp */
185 CommandCallback CcBuildVehicle;
186 CommandCallback CcStartStopVehicle;
188 #endif /* COMMAND_FUNC_H */