src/command.h
branchcpp_gui
changeset 6268 4b5241e5dd10
parent 6254 abc6ad7c035c
child 6298 c30fe89622df
child 6573 7624f942237f
equal deleted inserted replaced
6267:7c8ec33959b1 6268:4b5241e5dd10
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file command.h */
     2 
     4 
     3 #ifndef COMMAND_H
     5 #ifndef COMMAND_H
     4 #define COMMAND_H
     6 #define COMMAND_H
     5 
     7 
     6 enum {
     8 enum {
   120 	CMD_CLEAR_AREA                   = 100,
   122 	CMD_CLEAR_AREA                   = 100,
   121 
   123 
   122 	CMD_MONEY_CHEAT                  = 102,
   124 	CMD_MONEY_CHEAT                  = 102,
   123 	CMD_BUILD_CANAL                  = 103,
   125 	CMD_BUILD_CANAL                  = 103,
   124 
   126 
   125 	CMD_PLAYER_CTRL                  = 104, // used in multiplayer to create a new player etc.
   127 	CMD_PLAYER_CTRL                  = 104, ///< used in multiplayer to create a new player etc.
   126 	CMD_LEVEL_LAND                   = 105, // level land
   128 	CMD_LEVEL_LAND                   = 105, ///< level land
   127 
   129 
   128 	CMD_REFIT_RAIL_VEHICLE           = 106,
   130 	CMD_REFIT_RAIL_VEHICLE           = 106,
   129 	CMD_RESTORE_ORDER_INDEX          = 107,
   131 	CMD_RESTORE_ORDER_INDEX          = 107,
   130 	CMD_BUILD_LOCK                   = 108,
   132 	CMD_BUILD_LOCK                   = 108,
   131 
   133 
   143 	CMD_DEPOT_MASS_AUTOREPLACE       = 119,
   145 	CMD_DEPOT_MASS_AUTOREPLACE       = 119,
   144 };
   146 };
   145 
   147 
   146 enum {
   148 enum {
   147 	DC_EXEC            = 0x01,
   149 	DC_EXEC            = 0x01,
   148 	DC_AUTO            = 0x02, // don't allow building on structures
   150 	DC_AUTO            = 0x02, ///< don't allow building on structures
   149 	DC_QUERY_COST      = 0x04, // query cost only,  don't build.
   151 	DC_QUERY_COST      = 0x04, ///< query cost only,  don't build.
   150 	DC_NO_WATER        = 0x08, // don't allow building on water
   152 	DC_NO_WATER        = 0x08, ///< don't allow building on water
   151 	DC_NO_RAIL_OVERLAP = 0x10, // don't allow overlap of rails (used in buildrail)
   153 	DC_NO_RAIL_OVERLAP = 0x10, ///< don't allow overlap of rails (used in buildrail)
   152 	DC_AI_BUILDING     = 0x20, // special building rules for AI
   154 	DC_AI_BUILDING     = 0x20, ///< special building rules for AI
   153 	DC_NO_TOWN_RATING  = 0x40, // town rating does not disallow you from building
   155 	DC_NO_TOWN_RATING  = 0x40, ///< town rating does not disallow you from building
   154 	DC_FORCETEST       = 0x80, // force test too.
   156 	DC_FORCETEST       = 0x80, ///< force test too.
   155 
   157 
   156 	CMD_ERROR = ((int32)0x80000000),
   158 	CMD_ERROR = ((int32)0x80000000),
   157 };
   159 };
   158 
   160 
   159 #define CMD_MSG(x) ((x)<<16)
   161 #define CMD_MSG(x) ((x)<<16)
   160 
   162 
   161 enum {
   163 enum {
   162 	CMD_AUTO                  = 0x0200,
   164 	CMD_AUTO                  = 0x0200,
   163 	CMD_NO_WATER              = 0x0400,
   165 	CMD_NO_WATER              = 0x0400,
   164 	CMD_NETWORK_COMMAND       = 0x0800, // execute the command without sending it on the network
   166 	CMD_NETWORK_COMMAND       = 0x0800, ///< execute the command without sending it on the network
   165 	CMD_NO_TEST_IF_IN_NETWORK = 0x1000, // When enabled, the command will bypass the no-DC_EXEC round if in network
   167 	CMD_NO_TEST_IF_IN_NETWORK = 0x1000, ///< When enabled, the command will bypass the no-DC_EXEC round if in network
   166 	CMD_SHOW_NO_ERROR         = 0x2000,
   168 	CMD_SHOW_NO_ERROR         = 0x2000,
   167 };
   169 };
   168 
   170 
   169 /** Command flags for the command table
   171 /** Command flags for the command table _command_proc_table */
   170  * @see _command_proc_table
   172 enum {
   171  */
   173 	CMD_SERVER  = 0x1, ///< the command can only be initiated by the server
   172 enum {
   174 	CMD_OFFLINE = 0x2, ///< the command cannot be executed in a multiplayer game; single-player only
   173 	CMD_SERVER  = 0x1, /// the command can only be initiated by the server
       
   174 	CMD_OFFLINE = 0x2, /// the command cannot be executed in a multiplayer game; single-player only
       
   175 };
   175 };
   176 
   176 
   177 typedef int32 CommandProc(TileIndex tile, uint32 flags, uint32 p1, uint32 p2);
   177 typedef int32 CommandProc(TileIndex tile, uint32 flags, uint32 p1, uint32 p2);
   178 
   178 
   179 typedef struct Command {
   179 typedef struct Command {
   189  * @param res the resulting value from the command to be checked
   189  * @param res the resulting value from the command to be checked
   190  * @return Return true if the command failed, false otherwise
   190  * @return Return true if the command failed, false otherwise
   191  */
   191  */
   192 static inline bool CmdFailed(int32 res)
   192 static inline bool CmdFailed(int32 res)
   193 {
   193 {
   194 	// lower 16bits are the StringID of the possible error
   194 	/* lower 16bits are the StringID of the possible error */
   195 	return res <= (CMD_ERROR | INVALID_STRING_ID);
   195 	return res <= (CMD_ERROR | INVALID_STRING_ID);
   196 }
   196 }
   197 
   197 
   198 /* command.c */
   198 /* command.cpp */
   199 typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
   199 typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
   200 int32 DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
   200 int32 DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
   201 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd);
   201 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd);
   202 
   202 
   203 #ifdef ENABLE_NETWORK
   203 #ifdef ENABLE_NETWORK
   204 
   204 
   205 void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
   205 void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
   206 #endif /* ENABLE_NETWORK */
   206 #endif /* ENABLE_NETWORK */
   207 
   207 
   208 extern const char* _cmd_text; // Text, which gets sent with a command
   208 extern const char* _cmd_text; ///< Text, which gets sent with a command
   209 
   209 
   210 bool IsValidCommand(uint cmd);
   210 bool IsValidCommand(uint cmd);
   211 byte GetCommandFlags(uint cmd);
   211 byte GetCommandFlags(uint cmd);
   212 int32 GetAvailableMoneyForCommand(void);
   212 int32 GetAvailableMoneyForCommand(void);
   213 
   213