Fix #8316: Make sort industries by production and transported with a cargo filter...
[openttd-github.git] / src / command_func.h
blob426283bd3aebf1f47424ebefac7fbd2add7999d1
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file command_func.h Functions related to commands. */
10 #ifndef COMMAND_FUNC_H
11 #define COMMAND_FUNC_H
13 #include "command_type.h"
14 #include "company_type.h"
16 /**
17 * Define a default return value for a failed command.
19 * This variable contains a CommandCost object with is declared as "failed".
20 * Other functions just need to return this error if there is an error,
21 * which doesn't need to specific by a StringID.
23 static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
25 /**
26 * Returns from a function with a specific StringID as error.
28 * This macro is used to return from a function. The parameter contains the
29 * StringID which will be returned.
31 * @param errcode The StringID to return
33 #define return_cmd_error(errcode) return CommandCost(errcode);
35 CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const std::string &text = {});
36 CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags);
38 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = nullptr, const std::string &text = {}, bool my_cmd = true);
39 bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
41 CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, bool my_cmd, bool estimate_only);
43 void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const std::string &text, CompanyID company);
45 extern Money _additional_cash_required;
47 bool IsValidCommand(uint32 cmd);
48 CommandFlags GetCommandFlags(uint32 cmd);
49 const char *GetCommandName(uint32 cmd);
50 Money GetAvailableMoneyForCommand();
51 bool IsCommandAllowedWhilePaused(uint32 cmd);
53 /**
54 * Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags
55 * @param cmd_flags Flags from GetCommandFlags
56 * @return flags for DoCommand
58 static inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
60 DoCommandFlag flags = DC_NONE;
61 if (cmd_flags & CMD_NO_WATER) flags |= DC_NO_WATER;
62 if (cmd_flags & CMD_AUTO) flags |= DC_AUTO;
63 if (cmd_flags & CMD_ALL_TILES) flags |= DC_ALL_TILES;
64 return flags;
67 /*** All command callbacks that exist ***/
69 /* ai/ai_instance.cpp */
70 CommandCallback CcAI;
72 /* airport_gui.cpp */
73 CommandCallback CcBuildAirport;
75 /* bridge_gui.cpp */
76 CommandCallback CcBuildBridge;
78 /* dock_gui.cpp */
79 CommandCallback CcBuildDocks;
80 CommandCallback CcPlaySound_CONSTRUCTION_WATER;
82 /* depot_gui.cpp */
83 CommandCallback CcCloneVehicle;
85 /* game/game_instance.cpp */
86 CommandCallback CcGame;
88 /* group_gui.cpp */
89 CommandCallback CcCreateGroup;
90 CommandCallback CcAddVehicleNewGroup;
92 /* industry_gui.cpp */
93 CommandCallback CcBuildIndustry;
95 /* main_gui.cpp */
96 CommandCallback CcPlaySound_EXPLOSION;
97 CommandCallback CcPlaceSign;
98 CommandCallback CcTerraform;
100 /* rail_gui.cpp */
101 CommandCallback CcPlaySound_CONSTRUCTION_RAIL;
102 CommandCallback CcRailDepot;
103 CommandCallback CcStation;
104 CommandCallback CcBuildRailTunnel;
106 /* road_gui.cpp */
107 CommandCallback CcPlaySound_CONSTRUCTION_OTHER;
108 CommandCallback CcBuildRoadTunnel;
109 CommandCallback CcRoadDepot;
110 CommandCallback CcRoadStop;
112 /* train_gui.cpp */
113 CommandCallback CcBuildWagon;
115 /* town_gui.cpp */
116 CommandCallback CcFoundTown;
117 CommandCallback CcFoundRandomTown;
119 /* vehicle_gui.cpp */
120 CommandCallback CcBuildPrimaryVehicle;
121 CommandCallback CcStartStopVehicle;
123 #endif /* COMMAND_FUNC_H */