OpenTTD Source: src/command_func.h Source File

OpenTTD Source 1.11.0-RC1

command_func.h
Go to the documentation of this file.
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 */
7
10 #ifndef COMMAND_FUNC_H
11 #define COMMAND_FUNC_H
12
13 #include "command_type.h"
14 #include "company_type.h"
15
23 static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
24
33 #define return_cmd_error(errcode) return CommandCost(errcode);
34
35 CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text = nullptr);
36 CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags);
37
38 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = nullptr, const char *text = nullptr, bool my_cmd = true);
39 bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
40
41 CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only);
42
43 void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company);
44
45 extern Money _additional_cash_required;
46
47 bool IsValidCommand(uint32 cmd);
48 CommandFlags GetCommandFlags(uint32 cmd);
49 const char *GetCommandName(uint32 cmd);
50 Money GetAvailableMoneyForCommand();
51 bool IsCommandAllowedWhilePaused(uint32 cmd);
52
58 static inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
59 {
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;
65 }
66
67 /*** All command callbacks that exist ***/
68
69 /* ai/ai_instance.cpp */
70 CommandCallback CcAI;
71
72 /* airport_gui.cpp */
73 CommandCallback CcBuildAirport;
74
75 /* bridge_gui.cpp */
76 CommandCallback CcBuildBridge;
77
78 /* dock_gui.cpp */
79 CommandCallback CcBuildDocks;
80 CommandCallback CcPlaySound_CONSTRUCTION_WATER;
81
82 /* depot_gui.cpp */
83 CommandCallback CcCloneVehicle;
84
85 /* game/game_instance.cpp */
86 CommandCallback CcGame;
87
88 /* group_gui.cpp */
89 CommandCallback CcCreateGroup;
90 CommandCallback CcAddVehicleNewGroup;
91
92 /* industry_gui.cpp */
93 CommandCallback CcBuildIndustry;
94
95 /* main_gui.cpp */
96 CommandCallback CcPlaySound_EXPLOSION;
97 CommandCallback CcPlaceSign;
98 CommandCallback CcTerraform;
99
100 /* rail_gui.cpp */
101 CommandCallback CcPlaySound_CONSTRUCTION_RAIL;
102 CommandCallback CcRailDepot;
103 CommandCallback CcStation;
104 CommandCallback CcBuildRailTunnel;
105
106 /* road_gui.cpp */
107 CommandCallback CcPlaySound_CONSTRUCTION_OTHER;
108 CommandCallback CcBuildRoadTunnel;
109 CommandCallback CcRoadDepot;
110 CommandCallback CcRoadStop;
111
112 /* train_gui.cpp */
113 CommandCallback CcBuildWagon;
114
115 /* town_gui.cpp */
116 CommandCallback CcFoundTown;
117 CommandCallback CcFoundRandomTown;
118
119 /* vehicle_gui.cpp */
120 CommandCallback CcBuildPrimaryVehicle;
121 CommandCallback CcStartStopVehicle;
122
123 #endif /* COMMAND_FUNC_H */
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
CcBuildPrimaryVehicle
void CcBuildPrimaryVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
This is the Callback method after the construction attempt of a primary vehicle.
Definition: vehicle_gui.cpp:3082
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:23
GetCommandFlags
CommandFlags GetCommandFlags(uint32 cmd)
Definition: command.cpp:393
CcRoadStop
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback for building road stops.
Definition: road_gui.cpp:158
IsValidCommand
bool IsValidCommand(uint32 cmd)
Definition: command.cpp:379
CcStartStopVehicle
void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
This is the Callback method after attempting to start/stop a vehicle.
Definition: vehicle_gui.cpp:2582
CommandCallback
void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Define a callback function for the client, after the command is finished.
Definition: command_type.h:474
CommandContainer
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:479
DC_NO_WATER
@ DC_NO_WATER
don't allow building on water
Definition: command_type.h:351
DC_ALL_TILES
@ DC_ALL_TILES
allow this command also on MP_VOID tiles
Definition: command_type.h:357
IsCommandAllowedWhilePaused
bool IsCommandAllowedWhilePaused(uint32 cmd)
Returns whether the command is allowed while the game is paused.
Definition: command.cpp:419
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:346
DoCommandP
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback=nullptr, const char *text=nullptr, bool my_cmd=true)
Definition: command.cpp:561
DoCommand
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text=nullptr)
Definition: command.cpp:468
CcBuildBridge
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build Bridge CMD has been called.
Definition: bridge_gui.cpp:61
CcAddVehicleNewGroup
void CcAddVehicleNewGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Open rename window after adding a vehicle to a new group via drag and drop.
Definition: group_gui.cpp:1159
CcCreateGroup
void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Opens a 'Rename group' window for newly created group.
Definition: group_gui.cpp:1142
CcBuildIndustry
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback.
Definition: industry_gui.cpp:226
CommandFlags
CommandFlags
Command flags for the command table _command_proc_table.
Definition: command_type.h:390
CommandCost
Common return value for all commands.
Definition: command_type.h:23
CMD_AUTO
@ CMD_AUTO
set the DC_AUTO flag on this command
Definition: command_type.h:394
CcPlaceSign
void CcPlaceSign(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Callback function that is called after a sign is placed.
Definition: signs_cmd.cpp:117
CcGame
void CcGame(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
DoCommand callback function for all commands executed by Game Scripts.
Definition: game_instance.cpp:90
CcBuildWagon
void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Callback for building wagons.
Definition: train_gui.cpp:30
command_type.h
GetCommandName
const char * GetCommandName(uint32 cmd)
Definition: command.cpp:407
CMD_NO_WATER
@ CMD_NO_WATER
set the DC_NO_WATER flag on this command
Definition: command_type.h:397
CMD_ALL_TILES
@ CMD_ALL_TILES
allow this command also on MP_VOID tiles
Definition: command_type.h:395
NetworkSendCommand
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
Prepare a DoCommand to be send over the network.
Definition: network_command.cpp:136
DC_AUTO
@ DC_AUTO
don't allow building on structures
Definition: command_type.h:349
CcBuildRailTunnel
void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Command callback for building a tunnel.
Definition: rail_gui.cpp:278
CommandFlagsToDCFlags
static DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition: command_func.h:58
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
Definition: command.cpp:528
CcCloneVehicle
void CcCloneVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
This is the Callback method after the cloning attempt of a vehicle.
Definition: depot_gui.cpp:120
CcAI
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
DoCommand callback function for all commands executed by AIs.
Definition: ai_instance.cpp:101
DC_NONE
@ DC_NONE
no flag is set
Definition: command_type.h:347
company_type.h
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
CcBuildRoadTunnel
void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2, uint32 cmd)
Callback executed after a build road tunnel command has been called.
Definition: road_gui.cpp:99
DoCommandPInternal
CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only)
Definition: command.cpp:634