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/>.
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"
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
);
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 CommandCost
DoCommand(TileIndex tile
, uint32 p1
, uint32 p2
, DoCommandFlag flags
, uint32 cmd
, const char *text
= NULL
);
38 CommandCost
DoCommand(const CommandContainer
*container
, DoCommandFlag flags
);
40 bool DoCommandP(TileIndex tile
, uint32 p1
, uint32 p2
, uint32 cmd
, CommandCallback
*callback
= NULL
, const char *text
= NULL
, bool my_cmd
= true, uint32 binary_length
= 0);
41 bool DoCommandP(const CommandContainer
*container
, bool my_cmd
= true);
43 CommandCost
DoCommandPInternal(TileIndex tile
, uint32 p1
, uint32 p2
, uint32 cmd
, CommandCallback
*callback
, const char *text
, bool my_cmd
, bool estimate_only
, uint32 binary_length
);
46 void NetworkSendCommand(TileIndex tile
, uint32 p1
, uint32 p2
, uint32 cmd
, CommandCallback
*callback
, const char *text
, CompanyID company
, uint32 binary_length
);
47 #endif /* ENABLE_NETWORK */
49 extern Money _additional_cash_required
;
51 bool IsValidCommand(uint32 cmd
);
52 CommandFlags
GetCommandFlags(uint32 cmd
);
53 const char *GetCommandName(uint32 cmd
);
54 Money
GetAvailableMoneyForCommand();
55 bool IsCommandAllowedWhilePaused(uint32 cmd
);
58 * Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags
59 * @param cmd_flags Flags from GetCommandFlags
60 * @return flags for DoCommand
62 static inline DoCommandFlag
CommandFlagsToDCFlags(CommandFlags cmd_flags
)
64 DoCommandFlag flags
= DC_NONE
;
65 if (cmd_flags
& CMD_NO_WATER
) flags
|= DC_NO_WATER
;
66 if (cmd_flags
& CMD_AUTO
) flags
|= DC_AUTO
;
67 if (cmd_flags
& CMD_ALL_TILES
) flags
|= DC_ALL_TILES
;
71 void ClearCommandLog();
72 char *DumpCommandLog(char *buffer
, const char *last
);
74 /*** All command callbacks that exist ***/
76 /* ai/ai_instance.cpp */
80 CommandCallback CcBuildAirport
;
83 CommandCallback CcBuildBridge
;
86 CommandCallback CcBuildDocks
;
87 CommandCallback CcPlaySound_SPLAT_WATER
;
90 CommandCallback CcCloneVehicle
;
92 /* game/game_instance.cpp */
93 CommandCallback CcGame
;
96 CommandCallback CcCreateGroup
;
97 CommandCallback CcAddVehicleNewGroup
;
99 /* industry_gui.cpp */
100 CommandCallback CcBuildIndustry
;
103 CommandCallback CcPlaySound_EXPLOSION
;
104 CommandCallback CcPlaceSign
;
105 CommandCallback CcTerraform
;
106 CommandCallback CcGiveMoney
;
109 CommandCallback CcAddPlan
;
112 CommandCallback CcPlaySound_SPLAT_RAIL
;
113 CommandCallback CcRailDepot
;
114 CommandCallback CcStation
;
115 CommandCallback CcBuildRailTunnel
;
118 CommandCallback CcPlaySound_SPLAT_OTHER
;
119 CommandCallback CcBuildRoadTunnel
;
120 CommandCallback CcRoadDepot
;
121 CommandCallback CcRoadStop
;
124 CommandCallback CcBuildWagon
;
127 CommandCallback CcFoundTown
;
128 CommandCallback CcFoundRandomTown
;
130 /* vehicle_gui.cpp */
131 CommandCallback CcBuildPrimaryVehicle
;
132 CommandCallback CcStartStopVehicle
;
134 /* tbtr_template_gui_create.cpp */
135 CommandCallback CcSetVirtualTrain
;
136 CommandCallback CcVirtualTrainWagonsMoved
;
137 CommandCallback CcDeleteVirtualTrain
;
139 /* build_vehicle_gui.cpp */
140 CommandCallback CcAddVirtualEngine
;
143 #endif /* COMMAND_FUNC_H */