src/command.h
branchNewGRF_ports
changeset 6870 ca3fd1fbe311
parent 6743 cabfaa4a0295
equal deleted inserted replaced
6869:76282d3b748d 6870:ca3fd1fbe311
     3 /** @file command.h */
     3 /** @file command.h */
     4 
     4 
     5 #ifndef COMMAND_H
     5 #ifndef COMMAND_H
     6 #define COMMAND_H
     6 #define COMMAND_H
     7 
     7 
       
     8 /**
       
     9  * List of commands.
       
    10  *
       
    11  * This enum defines all possible commands which can be executed to the game
       
    12  * engine. Observing the game like the query-tool or checking the profit of a
       
    13  * vehicle don't result in a command which should be executed in the engine
       
    14  * nor send to the server in a network game.
       
    15  *
       
    16  * @see _command_proc_table
       
    17  */
     8 enum {
    18 enum {
     9 	CMD_BUILD_RAILROAD_TRACK         =   0,
    19 	CMD_BUILD_RAILROAD_TRACK         =   0, ///< build a rail track
    10 	CMD_REMOVE_RAILROAD_TRACK        =   1,
    20 	CMD_REMOVE_RAILROAD_TRACK        =   1, ///< remove a rail track
    11 	CMD_BUILD_SINGLE_RAIL            =   2,
    21 	CMD_BUILD_SINGLE_RAIL            =   2, ///< build a single rail track
    12 	CMD_REMOVE_SINGLE_RAIL           =   3,
    22 	CMD_REMOVE_SINGLE_RAIL           =   3, ///< remove a single rail track
    13 	CMD_LANDSCAPE_CLEAR              =   4,
    23 	CMD_LANDSCAPE_CLEAR              =   4, ///< demolish a tile
    14 	CMD_BUILD_BRIDGE                 =   5,
    24 	CMD_BUILD_BRIDGE                 =   5, ///< build a bridge
    15 	CMD_BUILD_RAILROAD_STATION       =   6,
    25 	CMD_BUILD_RAILROAD_STATION       =   6, ///< build a railroad station
    16 	CMD_BUILD_TRAIN_DEPOT            =   7,
    26 	CMD_BUILD_TRAIN_DEPOT            =   7, ///< build a train depot
    17 	CMD_BUILD_SIGNALS                =   8,
    27 	CMD_BUILD_SIGNALS                =   8, ///< build a signal
    18 	CMD_REMOVE_SIGNALS               =   9,
    28 	CMD_REMOVE_SIGNALS               =   9, ///< remove a signal
    19 	CMD_TERRAFORM_LAND               =  10,
    29 	CMD_TERRAFORM_LAND               =  10, ///< terraform a tile
    20 	CMD_PURCHASE_LAND_AREA           =  11,
    30 	CMD_PURCHASE_LAND_AREA           =  11, ///< purchase a tile
    21 	CMD_SELL_LAND_AREA               =  12,
    31 	CMD_SELL_LAND_AREA               =  12, ///< sell a bought tile before
    22 	CMD_BUILD_TUNNEL                 =  13,
    32 	CMD_BUILD_TUNNEL                 =  13, ///< build a tunnel
    23 
    33 
    24 	CMD_REMOVE_FROM_RAILROAD_STATION =  14,
    34 	CMD_REMOVE_FROM_RAILROAD_STATION =  14, ///< remove a tile station
    25 	CMD_CONVERT_RAIL                 =  15,
    35 	CMD_CONVERT_RAIL                 =  15, ///< convert a rail type
    26 
    36 
    27 	CMD_BUILD_TRAIN_WAYPOINT         =  16,
    37 	CMD_BUILD_TRAIN_WAYPOINT         =  16, ///< build a waypoint
    28 	CMD_RENAME_WAYPOINT              =  17,
    38 	CMD_RENAME_WAYPOINT              =  17, ///< rename a waypoint
    29 	CMD_REMOVE_TRAIN_WAYPOINT        =  18,
    39 	CMD_REMOVE_TRAIN_WAYPOINT        =  18, ///< remove a waypoint
    30 
    40 
    31 	CMD_BUILD_ROAD_STOP              =  21,
    41 	CMD_BUILD_ROAD_STOP              =  21, ///< build a road stop
    32 	CMD_REMOVE_ROAD_STOP             =  22,
    42 	CMD_REMOVE_ROAD_STOP             =  22, ///< remove a road stop
    33 	CMD_BUILD_LONG_ROAD              =  23,
    43 	CMD_BUILD_LONG_ROAD              =  23, ///< build a complete road (not a "half" one)
    34 	CMD_REMOVE_LONG_ROAD             =  24,
    44 	CMD_REMOVE_LONG_ROAD             =  24, ///< remove a complete road (not a "half" one)
    35 	CMD_BUILD_ROAD                   =  25,
    45 	CMD_BUILD_ROAD                   =  25, ///< build a "half" road
    36 	CMD_REMOVE_ROAD                  =  26,
    46 	CMD_REMOVE_ROAD                  =  26, ///< remove a "half" road
    37 	CMD_BUILD_ROAD_DEPOT             =  27,
    47 	CMD_BUILD_ROAD_DEPOT             =  27, ///< build a road depot
    38 
    48 
    39 	CMD_BUILD_AIRPORT                =  29,
    49 	CMD_BUILD_AIRPORT                =  29, ///< build an airport
    40 
    50 
    41 	CMD_BUILD_DOCK                   =  30,
    51 	CMD_BUILD_DOCK                   =  30, ///< build a dock
    42 
    52 
    43 	CMD_BUILD_SHIP_DEPOT             =  31,
    53 	CMD_BUILD_SHIP_DEPOT             =  31, ///< build a ship depot
    44 	CMD_BUILD_BUOY                   =  32,
    54 	CMD_BUILD_BUOY                   =  32, ///< build a buoy
    45 
    55 
    46 	CMD_PLANT_TREE                   =  33,
    56 	CMD_PLANT_TREE                   =  33, ///< plant a tree
    47 
    57 
    48 	CMD_BUILD_RAIL_VEHICLE           =  34,
    58 	CMD_BUILD_RAIL_VEHICLE           =  34, ///< build a rail vehicle
    49 	CMD_MOVE_RAIL_VEHICLE            =  35,
    59 	CMD_MOVE_RAIL_VEHICLE            =  35, ///< move a rail vehicle (in the depot)
    50 
    60 
    51 	CMD_START_STOP_TRAIN             =  36,
    61 	CMD_START_STOP_TRAIN             =  36, ///< start or stop a train
    52 
    62 
    53 	CMD_SELL_RAIL_WAGON              =  38,
    63 	CMD_SELL_RAIL_WAGON              =  38, ///< sell a rail wagon
    54 
    64 
    55 	CMD_SEND_TRAIN_TO_DEPOT          =  39,
    65 	CMD_SEND_TRAIN_TO_DEPOT          =  39, ///< send a train to a depot
    56 	CMD_FORCE_TRAIN_PROCEED          =  40,
    66 	CMD_FORCE_TRAIN_PROCEED          =  40, ///< proceed a train to pass a red signal
    57 	CMD_REVERSE_TRAIN_DIRECTION      =  41,
    67 	CMD_REVERSE_TRAIN_DIRECTION      =  41, ///< turn a train around
    58 
    68 
    59 	CMD_MODIFY_ORDER                 =  42,
    69 	CMD_MODIFY_ORDER                 =  42, ///< modify an order (like set full-load)
    60 	CMD_SKIP_TO_ORDER                =  43,
    70 	CMD_SKIP_TO_ORDER                =  43, ///< skip an order to the next of specific one
    61 	CMD_DELETE_ORDER                 =  44,
    71 	CMD_DELETE_ORDER                 =  44, ///< delete an order
    62 	CMD_INSERT_ORDER                 =  45,
    72 	CMD_INSERT_ORDER                 =  45, ///< insert a new order
    63 
    73 
    64 	CMD_CHANGE_SERVICE_INT           =  46,
    74 	CMD_CHANGE_SERVICE_INT           =  46, ///< change the server interval of a vehicle
    65 
    75 
    66 	CMD_BUILD_INDUSTRY               =  47,
    76 	CMD_BUILD_INDUSTRY               =  47, ///< build a new industry
    67 
    77 
    68 	CMD_BUILD_COMPANY_HQ             =  48,
    78 	CMD_BUILD_COMPANY_HQ             =  48, ///< build the company headquarter
    69 	CMD_SET_PLAYER_FACE              =  49,
    79 	CMD_SET_PLAYER_FACE              =  49, ///< set the face of the player/company
    70 	CMD_SET_PLAYER_COLOR             =  50,
    80 	CMD_SET_PLAYER_COLOR             =  50, ///< set the color of the player/company
    71 
    81 
    72 	CMD_INCREASE_LOAN                =  51,
    82 	CMD_INCREASE_LOAN                =  51, ///< increase the loan from the bank
    73 	CMD_DECREASE_LOAN                =  52,
    83 	CMD_DECREASE_LOAN                =  52, ///< decrease the loan from the bank
    74 
    84 
    75 	CMD_WANT_ENGINE_PREVIEW          =  53,
    85 	CMD_WANT_ENGINE_PREVIEW          =  53, ///< confirm the preview of an engine
    76 
    86 
    77 	CMD_NAME_VEHICLE                 =  54,
    87 	CMD_NAME_VEHICLE                 =  54, ///< rename a whole vehicle
    78 	CMD_RENAME_ENGINE                =  55,
    88 	CMD_RENAME_ENGINE                =  55, ///< rename a engine (in the engine list)
    79 	CMD_CHANGE_COMPANY_NAME          =  56,
    89 	CMD_CHANGE_COMPANY_NAME          =  56, ///< change the company name
    80 	CMD_CHANGE_PRESIDENT_NAME        =  57,
    90 	CMD_CHANGE_PRESIDENT_NAME        =  57, ///< change the president name
    81 	CMD_RENAME_STATION               =  58,
    91 	CMD_RENAME_STATION               =  58, ///< rename a station
    82 
    92 
    83 	CMD_SELL_AIRCRAFT                =  59,
    93 	CMD_SELL_AIRCRAFT                =  59, ///< sell an aircraft
    84 	CMD_START_STOP_AIRCRAFT          =  60,
    94 	CMD_START_STOP_AIRCRAFT          =  60, ///< start/stop an aircraft
    85 	CMD_BUILD_AIRCRAFT               =  61,
    95 	CMD_BUILD_AIRCRAFT               =  61, ///< build an aircraft
    86 	CMD_SEND_AIRCRAFT_TO_HANGAR      =  62,
    96 	CMD_SEND_AIRCRAFT_TO_HANGAR      =  62, ///< send an aircraft to a hanger
    87 	CMD_REFIT_AIRCRAFT               =  64,
    97 	CMD_REFIT_AIRCRAFT               =  64, ///< refit the cargo space of an aircraft
    88 
    98 
    89 	CMD_PLACE_SIGN                   =  65,
    99 	CMD_PLACE_SIGN                   =  65, ///< place a sign
    90 	CMD_RENAME_SIGN                  =  66,
   100 	CMD_RENAME_SIGN                  =  66, ///< rename a sign
    91 
   101 
    92 	CMD_BUILD_ROAD_VEH               =  67,
   102 	CMD_BUILD_ROAD_VEH               =  67, ///< build a road vehicle
    93 	CMD_START_STOP_ROADVEH           =  68,
   103 	CMD_START_STOP_ROADVEH           =  68, ///< start/stop a road vehicle
    94 	CMD_SELL_ROAD_VEH                =  69,
   104 	CMD_SELL_ROAD_VEH                =  69, ///< sell a road vehicle
    95 	CMD_SEND_ROADVEH_TO_DEPOT        =  70,
   105 	CMD_SEND_ROADVEH_TO_DEPOT        =  70, ///< send a road vehicle to the depot
    96 	CMD_TURN_ROADVEH                 =  71,
   106 	CMD_TURN_ROADVEH                 =  71, ///< turn a road vehicle around
    97 	CMD_REFIT_ROAD_VEH               =  72,
   107 	CMD_REFIT_ROAD_VEH               =  72, ///< refit the cargo space of a road vehicle
    98 
   108 
    99 	CMD_PAUSE                        =  73,
   109 	CMD_PAUSE                        =  73, ///< pause the game
   100 
   110 
   101 	CMD_BUY_SHARE_IN_COMPANY         =  74,
   111 	CMD_BUY_SHARE_IN_COMPANY         =  74, ///< buy a share from a company
   102 	CMD_SELL_SHARE_IN_COMPANY        =  75,
   112 	CMD_SELL_SHARE_IN_COMPANY        =  75, ///< sell a share from a company
   103 	CMD_BUY_COMPANY                  =  76,
   113 	CMD_BUY_COMPANY                  =  76, ///< buy a company which is bankrupt
   104 
   114 
   105 	CMD_BUILD_TOWN                   =  77,
   115 	CMD_BUILD_TOWN                   =  77, ///< build a town
   106 
   116 
   107 	CMD_RENAME_TOWN                  =  80,
   117 	CMD_RENAME_TOWN                  =  80, ///< rename a town
   108 	CMD_DO_TOWN_ACTION               =  81,
   118 	CMD_DO_TOWN_ACTION               =  81, ///< do a action from the town detail window (like advertises or bribe)
   109 
   119 
   110 	CMD_SET_ROAD_DRIVE_SIDE          =  82,
   120 	CMD_SET_ROAD_DRIVE_SIDE          =  82, ///< set the side where the road vehicles drive
   111 
   121 
   112 	CMD_CHANGE_DIFFICULTY_LEVEL      =  85,
   122 	CMD_CHANGE_DIFFICULTY_LEVEL      =  85, ///< change the difficult of a game (each setting for it own)
   113 
   123 
   114 	CMD_START_STOP_SHIP              =  86,
   124 	CMD_START_STOP_SHIP              =  86, ///< start/stop a ship
   115 	CMD_SELL_SHIP                    =  87,
   125 	CMD_SELL_SHIP                    =  87, ///< sell a ship
   116 	CMD_BUILD_SHIP                   =  88,
   126 	CMD_BUILD_SHIP                   =  88, ///< build a new ship
   117 	CMD_SEND_SHIP_TO_DEPOT           =  89,
   127 	CMD_SEND_SHIP_TO_DEPOT           =  89, ///< send a ship to a depot
   118 	CMD_REFIT_SHIP                   =  91,
   128 	CMD_REFIT_SHIP                   =  91, ///< refit the cargo space of a ship
   119 
   129 
   120 	CMD_ORDER_REFIT                  =  98,
   130 	CMD_ORDER_REFIT                  =  98, ///< change the refit informaction of an order (for "goto depot" )
   121 	CMD_CLONE_ORDER                  =  99,
   131 	CMD_CLONE_ORDER                  =  99, ///< clone (and share) an order
   122 	CMD_CLEAR_AREA                   = 100,
   132 	CMD_CLEAR_AREA                   = 100, ///< clear an area
   123 
   133 
   124 	CMD_MONEY_CHEAT                  = 102,
   134 	CMD_MONEY_CHEAT                  = 102, ///< do the money cheat
   125 	CMD_BUILD_CANAL                  = 103,
   135 	CMD_BUILD_CANAL                  = 103, ///< build a canal
   126 
   136 
   127 	CMD_PLAYER_CTRL                  = 104, ///< used in multiplayer to create a new player etc.
   137 	CMD_PLAYER_CTRL                  = 104, ///< used in multiplayer to create a new player etc.
   128 	CMD_LEVEL_LAND                   = 105, ///< level land
   138 	CMD_LEVEL_LAND                   = 105, ///< level land
   129 
   139 
   130 	CMD_REFIT_RAIL_VEHICLE           = 106,
   140 	CMD_REFIT_RAIL_VEHICLE           = 106, ///< refit the cargo space of a train
   131 	CMD_RESTORE_ORDER_INDEX          = 107,
   141 	CMD_RESTORE_ORDER_INDEX          = 107, ///< restore vehicle order-index and service interval
   132 	CMD_BUILD_LOCK                   = 108,
   142 	CMD_BUILD_LOCK                   = 108, ///< build a lock
   133 
   143 
   134 	CMD_BUILD_SIGNAL_TRACK           = 110,
   144 	CMD_BUILD_SIGNAL_TRACK           = 110, ///< add signals along a track (by dragging)
   135 	CMD_REMOVE_SIGNAL_TRACK          = 111,
   145 	CMD_REMOVE_SIGNAL_TRACK          = 111, ///< remove signals along a track (by dragging)
   136 
   146 
   137 	CMD_GIVE_MONEY                   = 113,
   147 	CMD_GIVE_MONEY                   = 113, ///< give money to an other player
   138 	CMD_CHANGE_PATCH_SETTING         = 114,
   148 	CMD_CHANGE_PATCH_SETTING         = 114, ///< change a patch setting
   139 
   149 
   140 	CMD_SET_AUTOREPLACE              = 115,
   150 	CMD_SET_AUTOREPLACE              = 115, ///< set an autoreplace entry
   141 
   151 
   142 	CMD_CLONE_VEHICLE                = 116,
   152 	CMD_CLONE_VEHICLE                = 116, ///< clone a vehicle
   143 	CMD_MASS_START_STOP              = 117,
   153 	CMD_MASS_START_STOP              = 117, ///< start/stop all vehicles (in a depot)
   144 	CMD_DEPOT_SELL_ALL_VEHICLES      = 118,
   154 	CMD_DEPOT_SELL_ALL_VEHICLES      = 118, ///< sell all vehicles which are in a given depot
   145 	CMD_DEPOT_MASS_AUTOREPLACE       = 119,
   155 	CMD_DEPOT_MASS_AUTOREPLACE       = 119, ///< force the autoreplace to take action in a given depot
   146 
   156 
   147 	CMD_CREATE_GROUP                 = 120,
   157 	CMD_CREATE_GROUP                 = 120, ///< create a new group
   148 	CMD_DELETE_GROUP                 = 121,
   158 	CMD_DELETE_GROUP                 = 121, ///< delete a group
   149 	CMD_RENAME_GROUP                 = 122,
   159 	CMD_RENAME_GROUP                 = 122, ///< rename a group
   150 	CMD_ADD_VEHICLE_GROUP            = 123,
   160 	CMD_ADD_VEHICLE_GROUP            = 123, ///< add a vehicle to a group
   151 	CMD_ADD_SHARED_VEHICLE_GROUP     = 124,
   161 	CMD_ADD_SHARED_VEHICLE_GROUP     = 124, ///< add all other shared vehicles to a group which are missing
   152 	CMD_REMOVE_ALL_VEHICLES_GROUP    = 125,
   162 	CMD_REMOVE_ALL_VEHICLES_GROUP    = 125, ///< remove all vehicles from a group
   153 	CMD_SET_GROUP_REPLACE_PROTECTION = 126,
   163 	CMD_SET_GROUP_REPLACE_PROTECTION = 126, ///< set the autoreplace-protection for a group
   154 
   164 
   155 	CMD_MOVE_ORDER                   = 127,
   165 	CMD_MOVE_ORDER                   = 127, ///< move an order
   156 	CMD_CHANGE_TIMETABLE             = 128,
   166 	CMD_CHANGE_TIMETABLE             = 128, ///< change the timetable for a vehicle
   157 	CMD_SET_VEHICLE_ON_TIME          = 129,
   167 	CMD_SET_VEHICLE_ON_TIME          = 129, ///< set the vehicle on time feature (timetable)
   158 	CMD_AUTOFILL_TIMETABLE           = 130,
   168 	CMD_AUTOFILL_TIMETABLE           = 130, ///< autofill the timetable
   159 };
   169 };
   160 
   170 
       
   171 /**
       
   172  * List of flags for a command.
       
   173  *
       
   174  * This enums defines some flags which can be used for the commands.
       
   175  */
   161 enum {
   176 enum {
   162 	DC_EXEC            = 0x01,
   177 	DC_EXEC            = 0x01, ///< execute the given command
   163 	DC_AUTO            = 0x02, ///< don't allow building on structures
   178 	DC_AUTO            = 0x02, ///< don't allow building on structures
   164 	DC_QUERY_COST      = 0x04, ///< query cost only,  don't build.
   179 	DC_QUERY_COST      = 0x04, ///< query cost only,  don't build.
   165 	DC_NO_WATER        = 0x08, ///< don't allow building on water
   180 	DC_NO_WATER        = 0x08, ///< don't allow building on water
   166 	DC_NO_RAIL_OVERLAP = 0x10, ///< don't allow overlap of rails (used in buildrail)
   181 	DC_NO_RAIL_OVERLAP = 0x10, ///< don't allow overlap of rails (used in buildrail)
   167 	DC_AI_BUILDING     = 0x20, ///< special building rules for AI
   182 	DC_AI_BUILDING     = 0x20, ///< special building rules for AI
   168 	DC_NO_TOWN_RATING  = 0x40, ///< town rating does not disallow you from building
   183 	DC_NO_TOWN_RATING  = 0x40, ///< town rating does not disallow you from building
   169 	DC_FORCETEST       = 0x80, ///< force test too.
   184 	DC_FORCETEST       = 0x80, ///< force test too.
   170 };
   185 };
   171 
   186 
       
   187 /**
       
   188  * Used to combine a StringID with the command.
       
   189  *
       
   190  * This macro can be used to add a StringID (the error message to show) on a command-id
       
   191  * (CMD_xxx). Use the binary or-operator "|" to combine the command with the result from
       
   192  * this macro.
       
   193  *
       
   194  * @param x The StringID to combine with a command-id
       
   195  */
   172 #define CMD_MSG(x) ((x) << 16)
   196 #define CMD_MSG(x) ((x) << 16)
   173 
   197 
       
   198 /**
       
   199  * Defines some flags.
       
   200  *
       
   201  * This enumeration defines some flags which are binary-or'ed on a command.
       
   202  */
   174 enum {
   203 enum {
   175 	CMD_AUTO                  = 0x0200,
   204 	CMD_NO_WATER              = 0x0400, ///< dont build on water
   176 	CMD_NO_WATER              = 0x0400,
       
   177 	CMD_NETWORK_COMMAND       = 0x0800, ///< execute the command without sending it on the network
   205 	CMD_NETWORK_COMMAND       = 0x0800, ///< execute the command without sending it on the network
   178 	CMD_NO_TEST_IF_IN_NETWORK = 0x1000, ///< When enabled, the command will bypass the no-DC_EXEC round if in network
   206 	CMD_NO_TEST_IF_IN_NETWORK = 0x1000, ///< When enabled, the command will bypass the no-DC_EXEC round if in network
   179 	CMD_SHOW_NO_ERROR         = 0x2000,
   207 	CMD_SHOW_NO_ERROR         = 0x2000, ///< do not show the error message
   180 };
   208 };
   181 
   209 
   182 /** Command flags for the command table _command_proc_table */
   210 /**
       
   211  * Command flags for the command table _command_proc_table.
       
   212  *
       
   213  * This enumeration defines flags for the _command_proc_table.
       
   214  */
   183 enum {
   215 enum {
   184 	CMD_SERVER  = 0x1, ///< the command can only be initiated by the server
   216 	CMD_SERVER  = 0x1, ///< the command can only be initiated by the server
   185 	CMD_OFFLINE = 0x2, ///< the command cannot be executed in a multiplayer game; single-player only
   217 	CMD_OFFLINE = 0x2, ///< the command cannot be executed in a multiplayer game; single-player only
   186 };
   218 	CMD_AUTO    = 0x4, ///< set the DC_AUTO flag on this command
   187 
   219 };
       
   220 
       
   221 /**
       
   222  * Defines the callback type for all command handler functions.
       
   223  *
       
   224  * This type defines the function header for all functions which handles a CMD_* command.
       
   225  * A command handler use the parameters to act according to the meaning of the command.
       
   226  * The tile parameter defines the tile to perform an action on.
       
   227  * The flag parameter is filled with flags from the DC_* enumeration. The parameters
       
   228  * p1 and p2 are filled with parameters for the command like "which road type", "which
       
   229  * order" or "direction". Each function should mentioned in there doxygen comments
       
   230  * the usage of these parameters.
       
   231  *
       
   232  * @param tile The tile to apply a command on
       
   233  * @param flags Flags for the command, from the DC_* enumeration
       
   234  * @param p1 Additional data for the command
       
   235  * @param p2 Additional data for the command
       
   236  * @return The CommandCost of the command, which can be succeeded or failed.
       
   237  */
   188 typedef CommandCost CommandProc(TileIndex tile, uint32 flags, uint32 p1, uint32 p2);
   238 typedef CommandCost CommandProc(TileIndex tile, uint32 flags, uint32 p1, uint32 p2);
   189 
   239 
       
   240 /**
       
   241  * Define a command with the flags which belongs to it.
       
   242  *
       
   243  * This struct connect a command handler function with the flags created with
       
   244  * the #CMD_AUTO, #CMD_OFFLINE and #CMD_SERVER values.
       
   245  */
   190 struct Command {
   246 struct Command {
   191 	CommandProc *proc;
   247 	CommandProc *proc;
   192 	byte flags;
   248 	byte flags;
   193 };
   249 };
   194 
   250 
       
   251 /**
       
   252  * Checks if a command failes.
       
   253  *
       
   254  * As you see the parameter is not a command but the return value of a command,
       
   255  * the CommandCost class. This function checks if the command executed by
       
   256  * the CommandProc function failed and returns true if it does.
       
   257  *
       
   258  * @param cost The return value of a CommandProc call
       
   259  * @return true if the command failes
       
   260  * @see CmdSucceded
       
   261  */
   195 static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); }
   262 static inline bool CmdFailed(CommandCost cost) { return cost.Failed(); }
       
   263 
       
   264 /**
       
   265  * Checks if a command succeeded.
       
   266  *
       
   267  * As #CmdFailed this function checks if a command succeeded
       
   268  *
       
   269  * @param cost The return value of a CommandProc call
       
   270  * @return true if the command succeeded
       
   271  * @see CmdSucceeded
       
   272  */
   196 static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); }
   273 static inline bool CmdSucceeded(CommandCost cost) { return cost.Succeeded(); }
   197 
   274 
       
   275 /**
       
   276  * Define a default return value for a failed command.
       
   277  *
       
   278  * This variable contains a CommandCost object with is declared as "failed".
       
   279  * Other functions just need to return this error if there is an error,
       
   280  * which doesn't need to specific by a StringID.
       
   281  */
   198 static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
   282 static const CommandCost CMD_ERROR = CommandCost(INVALID_STRING_ID);
   199 
   283 
   200 #define return_cmd_error(errcode) do { return CommandCost(errcode); } while (0)
   284 /**
       
   285  * Returns from a function with a specific StringID as error.
       
   286  *
       
   287  * This macro is used to return from a function. The parameter contains the
       
   288  * StringID which will be returned.
       
   289  *
       
   290  * @param errcode The StringID to return
       
   291  */
       
   292 #define return_cmd_error(errcode) return CommandCost(errcode);
   201 
   293 
   202 /* command.cpp */
   294 /* command.cpp */
       
   295 /**
       
   296  * Define a callback function for the client, after the command is finished.
       
   297  *
       
   298  * Functions of this type are called after the command is finished. The parameters
       
   299  * are from the #CommandProc callback type. The boolean parameter indicates if the
       
   300  * command succeeded or failed.
       
   301  *
       
   302  * @param success If the command succeeded or not.
       
   303  * @param tile The tile of the command action
       
   304  * @param p1 Additional data of the command
       
   305  * @param p1 Additional data of the command
       
   306  * @see CommandProc
       
   307  */
   203 typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
   308 typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
       
   309 
       
   310 /**
       
   311  * Execute a command
       
   312  */
   204 CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
   313 CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
       
   314 
       
   315 /**
       
   316  * Execute a network safe DoCommand function
       
   317  */
   205 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd, bool my_cmd = true);
   318 bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd, bool my_cmd = true);
   206 
   319 
   207 #ifdef ENABLE_NETWORK
   320 #ifdef ENABLE_NETWORK
   208 
   321 
       
   322 /**
       
   323  * Send a command over the network
       
   324  */
   209 void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
   325 void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
   210 #endif /* ENABLE_NETWORK */
   326 #endif /* ENABLE_NETWORK */
   211 
   327 
   212 extern const char* _cmd_text; ///< Text, which gets sent with a command
   328 /**
   213 
   329  * Text, which gets sent with a command
       
   330  *
       
   331  * This variable contains a string (be specific a pointer of the first
       
   332  * char of this string) which will be send with a command. This is
       
   333  * used for user input data like names or chat messages.
       
   334  */
       
   335 extern const char *_cmd_text;
       
   336 
       
   337 /**
       
   338  * Checks if a integer value belongs to a command.
       
   339  */
   214 bool IsValidCommand(uint cmd);
   340 bool IsValidCommand(uint cmd);
       
   341 /**
       
   342  * Returns the flags from a given command.
       
   343  */
   215 byte GetCommandFlags(uint cmd);
   344 byte GetCommandFlags(uint cmd);
       
   345 /**
       
   346  * Returns the current money available which can be used for a command.
       
   347  */
   216 Money GetAvailableMoneyForCommand();
   348 Money GetAvailableMoneyForCommand();
   217 
   349 
   218 #endif /* COMMAND_H */
   350 #endif /* COMMAND_H */