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 * Returns a specific StringID as error.
21 * @param error_msg The StringID to return
23 inline CommandCost
CommandError(StringID error_msg
= INVALID_STRING_ID
) { return CommandCost(error_msg
); }
25 CommandCost
DoCommand(TileIndex tile
, uint32 p1
, uint32 p2
, DoCommandFlag flags
, uint32 cmd
, const char *text
= nullptr);
26 CommandCost
DoCommand(const CommandContainer
*container
, DoCommandFlag flags
);
28 bool DoCommandP(TileIndex tile
, uint32 p1
, uint32 p2
, uint32 cmd
, CommandCallback
*callback
= nullptr, const char *text
= nullptr, bool my_cmd
= true, uint32 binary_length
= 0);
29 bool DoCommandP(const CommandContainer
*container
, bool my_cmd
= true);
31 CommandCost
DoCommandPInternal(TileIndex tile
, uint32 p1
, uint32 p2
, uint32 cmd
, CommandCallback
*callback
, const char *text
, bool my_cmd
, bool estimate_only
, uint32 binary_length
);
34 void NetworkSendCommand(TileIndex tile
, uint32 p1
, uint32 p2
, uint32 cmd
, CommandCallback
*callback
, const char *text
, CompanyID company
, uint32 binary_length
);
35 #endif /* ENABLE_NETWORK */
37 extern Money _additional_cash_required
;
39 bool IsValidCommand(uint32 cmd
);
40 CommandFlags
GetCommandFlags(uint32 cmd
);
41 const char *GetCommandName(uint32 cmd
);
42 Money
GetAvailableMoneyForCommand();
43 bool IsCommandAllowedWhilePaused(uint32 cmd
);
46 * Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags
47 * @param cmd_flags Flags from GetCommandFlags
48 * @return flags for DoCommand
50 static inline DoCommandFlag
CommandFlagsToDCFlags(CommandFlags cmd_flags
)
52 DoCommandFlag flags
= DC_NONE
;
53 if (cmd_flags
& CMD_NO_WATER
) flags
|= DC_NO_WATER
;
54 if (cmd_flags
& CMD_AUTO
) flags
|= DC_AUTO
;
55 if (cmd_flags
& CMD_ALL_TILES
) flags
|= DC_ALL_TILES
;
59 void ClearCommandLog();
60 char *DumpCommandLog(char *buffer
, const char *last
);
62 /*** All command callbacks that exist ***/
64 /* ai/ai_instance.cpp */
68 CommandCallback CcBuildAirport
;
71 CommandCallback CcBuildBridge
;
74 CommandCallback CcBuildDocks
;
75 CommandCallback CcPlaySound_SPLAT_WATER
;
78 CommandCallback CcCloneVehicle
;
80 /* game/game_instance.cpp */
81 CommandCallback CcGame
;
84 CommandCallback CcCreateGroup
;
85 CommandCallback CcAddVehicleNewGroup
;
87 /* industry_gui.cpp */
88 CommandCallback CcBuildIndustry
;
91 CommandCallback CcPlaySound_EXPLOSION
;
92 CommandCallback CcPlaceSign
;
93 CommandCallback CcTerraform
;
94 CommandCallback CcGiveMoney
;
97 CommandCallback CcAddPlan
;
100 CommandCallback CcPlaySound_SPLAT_RAIL
;
101 CommandCallback CcRailDepot
;
102 CommandCallback CcStation
;
103 CommandCallback CcBuildRailTunnel
;
106 CommandCallback CcPlaySound_SPLAT_OTHER
;
107 CommandCallback CcBuildRoadTunnel
;
108 CommandCallback CcRoadDepot
;
109 CommandCallback CcRoadStop
;
112 CommandCallback CcBuildWagon
;
115 CommandCallback CcFoundTown
;
116 CommandCallback CcFoundRandomTown
;
118 /* vehicle_gui.cpp */
119 CommandCallback CcBuildPrimaryVehicle
;
120 CommandCallback CcStartStopVehicle
;
122 /* tbtr_template_gui_create.cpp */
123 CommandCallback CcSetVirtualTrain
;
124 CommandCallback CcVirtualTrainWagonsMoved
;
125 CommandCallback CcDeleteVirtualTrain
;
127 /* build_vehicle_gui.cpp */
128 CommandCallback CcAddVirtualEngine
;
131 #endif /* COMMAND_FUNC_H */