# command_type.h

Go to the documentation of this file.

    00001 /* $Id: command_type.h 15452 2009-02-11 18:50:47Z frosch $ */
    00002
    00005 #ifndef COMMAND_TYPE_H
    00006 #define COMMAND_TYPE_H
    00007
    00008 #include "economy_type.h"
    00009 #include "strings_type.h"
    00010 #include "tile_type.h"
    00011
    00016 class CommandCost {
    00017   ExpensesType expense_type;
    00018   Money cost;
    00019   StringID message;
    00020   bool success;
    00021
    00022 public:
    00026   CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true) {}
    00027
    00031   CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false) {}
    00032
    00037   CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true) {}
    00038
    00044   CommandCost(ExpensesType ex_t, Money cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true) {}
    00045
    00052   CommandCost AddCost(CommandCost ret);
    00053
    00059   CommandCost AddCost(Money cost)
    00060   {
    00061     this->cost += cost;
    00062     return *this;
    00063   }
    00064
    00070   CommandCost MultiplyCost(int factor)
    00071   {
    00072     this->cost *= factor;
    00073     return *this;
    00074   }
    00075
    00080   Money GetCost() const
    00081   {
    00082     return this->cost;
    00083   }
    00084
    00089   ExpensesType GetExpensesType() const
    00090   {
    00091     return this->expense_type;
    00092   }
    00093
    00097   void SetGlobalErrorMessage() const
    00098   {
    00099     extern StringID _error_message;
    00100     if (this->message != INVALID_STRING_ID) _error_message = this->message;
    00101   }
    00102
    00107   StringID GetErrorMessage() const
    00108   {
    00109     extern StringID _error_message;
    00110
    00111     if (this->success) return INVALID_STRING_ID;
    00112     if (this->message != INVALID_STRING_ID) return this->message;
    00113     return _error_message;
    00114   }
    00115
    00120   bool Succeeded() const
    00121   {
    00122     return this->success;
    00123   }
    00124
    00129   bool Failed() const
    00130   {
    00131     return !this->success;
    00132   }
    00133 };
    00134
    00145 enum {
    00146   CMD_BUILD_RAILROAD_TRACK,
    00147   CMD_REMOVE_RAILROAD_TRACK,
    00148   CMD_BUILD_SINGLE_RAIL,
    00149   CMD_REMOVE_SINGLE_RAIL,
    00150   CMD_LANDSCAPE_CLEAR,
    00151   CMD_BUILD_BRIDGE,
    00152   CMD_BUILD_RAILROAD_STATION,
    00153   CMD_BUILD_TRAIN_DEPOT,
    00154   CMD_BUILD_SIGNALS,
    00155   CMD_REMOVE_SIGNALS,
    00156   CMD_TERRAFORM_LAND,
    00157   CMD_PURCHASE_LAND_AREA,
    00158   CMD_SELL_LAND_AREA,
    00159   CMD_BUILD_TUNNEL,
    00160
    00161   CMD_REMOVE_FROM_RAILROAD_STATION,
    00162   CMD_CONVERT_RAIL,
    00163
    00164   CMD_BUILD_TRAIN_WAYPOINT,
    00165   CMD_RENAME_WAYPOINT,
    00166   CMD_REMOVE_TRAIN_WAYPOINT,
    00167
    00168   CMD_BUILD_ROAD_STOP,
    00169   CMD_REMOVE_ROAD_STOP,
    00170   CMD_BUILD_LONG_ROAD,
    00171   CMD_REMOVE_LONG_ROAD,
    00172   CMD_BUILD_ROAD,
    00173   CMD_REMOVE_ROAD,
    00174   CMD_BUILD_ROAD_DEPOT,
    00175
    00176   CMD_BUILD_AIRPORT,
    00177
    00178   CMD_BUILD_DOCK,
    00179
    00180   CMD_BUILD_SHIP_DEPOT,
    00181   CMD_BUILD_BUOY,
    00182
    00183   CMD_PLANT_TREE,
    00184
    00185   CMD_BUILD_RAIL_VEHICLE,
    00186   CMD_MOVE_RAIL_VEHICLE,
    00187
    00188   CMD_SELL_RAIL_WAGON,
    00189
    00190   CMD_SEND_TRAIN_TO_DEPOT,
    00191   CMD_FORCE_TRAIN_PROCEED,
    00192   CMD_REVERSE_TRAIN_DIRECTION,
    00193
    00194   CMD_MODIFY_ORDER,
    00195   CMD_SKIP_TO_ORDER,
    00196   CMD_DELETE_ORDER,
    00197   CMD_INSERT_ORDER,
    00198
    00199   CMD_CHANGE_SERVICE_INT,
    00200
    00201   CMD_BUILD_INDUSTRY,
    00202
    00203   CMD_BUILD_COMPANY_HQ,
    00204   CMD_SET_COMPANY_MANAGER_FACE,
    00205   CMD_SET_COMPANY_COLOUR,
    00206
    00207   CMD_INCREASE_LOAN,
    00208   CMD_DECREASE_LOAN,
    00209
    00210   CMD_WANT_ENGINE_PREVIEW,
    00211
    00212   CMD_RENAME_VEHICLE,
    00213   CMD_RENAME_ENGINE,
    00214   CMD_RENAME_COMPANY,
    00215   CMD_RENAME_PRESIDENT,
    00216   CMD_RENAME_STATION,
    00217
    00218   CMD_SELL_AIRCRAFT,
    00219   CMD_BUILD_AIRCRAFT,
    00220   CMD_SEND_AIRCRAFT_TO_HANGAR,
    00221   CMD_REFIT_AIRCRAFT,
    00222
    00223   CMD_PLACE_SIGN,
    00224   CMD_RENAME_SIGN,
    00225
    00226   CMD_BUILD_ROAD_VEH,
    00227   CMD_SELL_ROAD_VEH,
    00228   CMD_SEND_ROADVEH_TO_DEPOT,
    00229   CMD_TURN_ROADVEH,
    00230   CMD_REFIT_ROAD_VEH,
    00231
    00232   CMD_PAUSE,
    00233
    00234   CMD_BUY_SHARE_IN_COMPANY,
    00235   CMD_SELL_SHARE_IN_COMPANY,
    00236   CMD_BUY_COMPANY,
    00237
    00238   CMD_BUILD_TOWN,
    00239
    00240   CMD_RENAME_TOWN,
    00241   CMD_DO_TOWN_ACTION,
    00242
    00243   CMD_SELL_SHIP,
    00244   CMD_BUILD_SHIP,
    00245   CMD_SEND_SHIP_TO_DEPOT,
    00246   CMD_REFIT_SHIP,
    00247
    00248   CMD_ORDER_REFIT,
    00249   CMD_CLONE_ORDER,
    00250   CMD_CLEAR_AREA,
    00251
    00252   CMD_MONEY_CHEAT,
    00253   CMD_BUILD_CANAL,
    00254
    00255   CMD_COMPANY_CTRL,
    00256   CMD_LEVEL_LAND,
    00257
    00258   CMD_REFIT_RAIL_VEHICLE,
    00259   CMD_RESTORE_ORDER_INDEX,
    00260   CMD_BUILD_LOCK,
    00261
    00262   CMD_BUILD_SIGNAL_TRACK,
    00263   CMD_REMOVE_SIGNAL_TRACK,
    00264
    00265   CMD_GIVE_MONEY,
    00266   CMD_CHANGE_SETTING,
    00267
    00268   CMD_SET_AUTOREPLACE,
    00269
    00270   CMD_CLONE_VEHICLE,
    00271   CMD_START_STOP_VEHICLE,
    00272   CMD_MASS_START_STOP,
    00273   CMD_AUTOREPLACE_VEHICLE,
    00274   CMD_DEPOT_SELL_ALL_VEHICLES,
    00275   CMD_DEPOT_MASS_AUTOREPLACE,
    00276
    00277   CMD_CREATE_GROUP,
    00278   CMD_DELETE_GROUP,
    00279   CMD_RENAME_GROUP,
    00280   CMD_ADD_VEHICLE_GROUP,
    00281   CMD_ADD_SHARED_VEHICLE_GROUP,
    00282   CMD_REMOVE_ALL_VEHICLES_GROUP,
    00283   CMD_SET_GROUP_REPLACE_PROTECTION,
    00284
    00285   CMD_MOVE_ORDER,
    00286   CMD_CHANGE_TIMETABLE,
    00287   CMD_SET_VEHICLE_ON_TIME,
    00288   CMD_AUTOFILL_TIMETABLE,
    00289 };
    00290
    00296 enum DoCommandFlag {
    00297   DC_NONE                  = 0x000,
    00298   DC_EXEC                  = 0x001,
    00299   DC_AUTO                  = 0x002,
    00300   DC_QUERY_COST            = 0x004,
    00301   DC_NO_WATER              = 0x008,
    00302   DC_NO_RAIL_OVERLAP       = 0x010,
    00303   DC_NO_TEST_TOWN_RATING   = 0x020,
    00304   DC_BANKRUPT              = 0x040,
    00305   DC_AUTOREPLACE           = 0x080,
    00306   DC_ALL_TILES             = 0x100,
    00307   DC_NO_MODIFY_TOWN_RATING = 0x200,
    00308 };
    00309 DECLARE_ENUM_AS_BIT_SET(DoCommandFlag);
    00310
    00320 #define CMD_MSG(x) ((x) << 16)
    00321
    00327 enum {
    00328   CMD_NETWORK_COMMAND       = 0x0100,
    00329   CMD_NO_TEST_IF_IN_NETWORK = 0x0200,
    00330   CMD_FLAGS_MASK            = 0xFF00,
    00331   CMD_ID_MASK               = 0x00FF,
    00332 };
    00333
    00339 enum {
    00340   CMD_SERVER    = 0x01,
    00341   CMD_SPECTATOR = 0x02,
    00342   CMD_OFFLINE   = 0x04,
    00343   CMD_AUTO      = 0x08,
    00344   CMD_ALL_TILES = 0x10,
    00345   CMD_NO_TEST   = 0x20,
    00346   CMD_NO_WATER  = 0x40,
    00347 };
    00348
    00367 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
    00368
    00375 struct Command {
    00376   CommandProc *proc;
    00377   byte flags;
    00378 };
    00379
    00393 typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
    00394
    00398 struct CommandContainer {
    00399   TileIndex tile;
    00400   uint32 p1;
    00401   uint32 p2;
    00402   uint32 cmd;
    00403   CommandCallback *callback;
    00404   char text[80];
    00405 };
    00406
    00407 #endif /* COMMAND_TYPE_H */