OpenTTD

command_func.h
Go to the documentation of this file.
1 /* $Id: command_func.h 27571 2016-05-22 10:07:48Z frosch $ */
2
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 */
9
12 #ifndef COMMAND_FUNC_H
13 #define COMMAND_FUNC_H
14
15 #include "command_type.h"
16 #include "company_type.h"
17
25 static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
26
35 #define return_cmd_error(errcode) return CommandCost(errcode);
36
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);
39
40 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback = NULL, const char *text = NULL, bool my_cmd = true);
41 bool DoCommandP(const CommandContainer *container, bool my_cmd = true);
42
43 CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, bool my_cmd, bool estimate_only);
44
45 #ifdef ENABLE_NETWORK
46 void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company);
47 #endif /* ENABLE_NETWORK */
48
49 extern Money _additional_cash_required;
50
51 bool IsValidCommand(uint32 cmd);
52 CommandFlags GetCommandFlags(uint32 cmd);
53 const char *GetCommandName(uint32 cmd);
54 Money GetAvailableMoneyForCommand();
55 bool IsCommandAllowedWhilePaused(uint32 cmd);
56
62 static inline DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
63 {
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;
68 return flags;
69 }
70
71 /*** All command callbacks that exist ***/
72
73 /* ai/ai_instance.cpp */
74 CommandCallback CcAI;
75
76 /* airport_gui.cpp */
77 CommandCallback CcBuildAirport;
78
79 /* bridge_gui.cpp */
80 CommandCallback CcBuildBridge;
81
82 /* dock_gui.cpp */
83 CommandCallback CcBuildDocks;
84 CommandCallback CcPlaySound_SPLAT_WATER;
85
86 /* depot_gui.cpp */
87 CommandCallback CcCloneVehicle;
88
89 /* game/game_instance.cpp */
90 CommandCallback CcGame;
91
92 /* group_gui.cpp */
93 CommandCallback CcCreateGroup;
94 CommandCallback CcAddVehicleNewGroup;
95
96 /* industry_gui.cpp */
97 CommandCallback CcBuildIndustry;
98
99 /* main_gui.cpp */
100 CommandCallback CcPlaySound_EXPLOSION;
101 CommandCallback CcPlaceSign;
102 CommandCallback CcTerraform;
103 CommandCallback CcGiveMoney;
104
105 /* rail_gui.cpp */
106 CommandCallback CcPlaySound_SPLAT_RAIL;
107 CommandCallback CcRailDepot;
108 CommandCallback CcStation;
109 CommandCallback CcBuildRailTunnel;
110
111 /* road_gui.cpp */
112 CommandCallback CcPlaySound_SPLAT_OTHER;
113 CommandCallback CcBuildRoadTunnel;
114 CommandCallback CcRoadDepot;
115 CommandCallback CcRoadStop;
116
117 /* train_gui.cpp */
118 CommandCallback CcBuildWagon;
119
120 /* town_gui.cpp */
121 CommandCallback CcFoundTown;
122 CommandCallback CcFoundRandomTown;
123
124 /* vehicle_gui.cpp */
125 CommandCallback CcBuildPrimaryVehicle;
126 CommandCallback CcStartStopVehicle;
127
128 #endif /* COMMAND_FUNC_H */
CcPlaceSign
void CcPlaceSign(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Callback function that is called after a sign is placed.
Definition: signs_cmd.cpp:118
DC_AUTO
don&#39;t allow building on structures
Definition: command_type.h:343
CMD_NO_WATER
set the DC_NO_WATER flag on this command
Definition: command_type.h:391
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:140
CcGame
void CcGame(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
DoCommand callback function for all commands executed by Game Scripts.
Definition: game_instance.cpp:254
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:25
CcCreateGroup
void CcCreateGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Opens a &#39;Rename group&#39; window for newly created group.
Definition: group_gui.cpp:987
CMD_AUTO
set the DC_AUTO flag on this command
Definition: command_type.h:388
DC_NONE
no flag is set
Definition: command_type.h:341
CommandFlags
CommandFlags
Command flags for the command table _command_proc_table.
Definition: command_type.h:384
IsCommandAllowedWhilePaused
bool IsCommandAllowedWhilePaused(uint32 cmd)
Returns whether the command is allowed while the game is paused.
Definition: command.cpp:405
CcRoadStop
void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Command callback for building road stops.
Definition: road_gui.cpp:199
CommandCost
Common return value for all commands.
Definition: command_type.h:25
command_type.h
Types related to commands.
CcAI
void CcAI(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
DoCommand callback function for all commands executed by AIs.
Definition: ai_instance.cpp:252
CcBuildWagon
void CcBuildWagon(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Callback for building wagons.
Definition: train_gui.cpp:31
CcCloneVehicle
void CcCloneVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
This is the Callback method after the cloning attempt of a vehicle.
Definition: depot_gui.cpp:121
IsValidCommand
bool IsValidCommand(uint32 cmd)
Definition: command.cpp:365
CcBuildRoadTunnel
void CcBuildRoadTunnel(const CommandCost &result, TileIndex start_tile, uint32 p1, uint32 p2)
Callback executed after a build road tunnel command has been called.
Definition: road_gui.cpp:96
CommandContainer
Structure for buffering the build command when selecting a station to join.
Definition: command_type.h:472
DoCommandFlag
DoCommandFlag
List of flags for a command.
Definition: command_type.h:340
CcBuildIndustry
void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Command callback.
Definition: industry_gui.cpp:200
DC_NO_WATER
don&#39;t allow building on water
Definition: command_type.h:345
CommandFlagsToDCFlags
static DoCommandFlag CommandFlagsToDCFlags(CommandFlags cmd_flags)
Extracts the DC flags needed for DoCommand from the flags returned by GetCommandFlags.
Definition: command_func.h:62
DC_ALL_TILES
allow this command also on MP_VOID tiles
Definition: command_type.h:351
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
Definition: command.cpp:514
CcBuildBridge
void CcBuildBridge(const CommandCost &result, TileIndex end_tile, uint32 p1, uint32 p2)
Callback executed after a build Bridge CMD has been called.
Definition: bridge_gui.cpp:61
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
CcBuildPrimaryVehicle
void CcBuildPrimaryVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
This is the Callback method after the construction attempt of a primary vehicle.
Definition: vehicle_gui.cpp:2826
DoCommandP
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback=NULL, const char *text=NULL, bool my_cmd=true)
Definition: command.cpp:547
DoCommand
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, DoCommandFlag flags, uint32 cmd, const char *text=NULL)
Definition: command.cpp:454
CcStartStopVehicle
void CcStartStopVehicle(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
This is the Callback method after attempting to start/stop a vehicle.
Definition: vehicle_gui.cpp:2384
company_type.h
Types related to companies.
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:19
CommandCallback
void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Define a callback function for the client, after the command is finished.
Definition: command_type.h:467
CcAddVehicleNewGroup
void CcAddVehicleNewGroup(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Open rename window after adding a vehicle to a new group via drag and drop.
Definition: group_gui.cpp:1003
CcBuildRailTunnel
void CcBuildRailTunnel(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
Command callback for building a tunnel.
Definition: rail_gui.cpp:275
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:20
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:623
GetCommandName
const char * GetCommandName(uint32 cmd)
Definition: command.cpp:393
OverflowSafeInt< int64, INT64_MAX, INT64_MIN >
CMD_ALL_TILES
allow this command also on MP_VOID tiles
Definition: command_type.h:389
GetCommandFlags
CommandFlags GetCommandFlags(uint32 cmd)
Definition: command.cpp:379