# command_type.h

Go to the documentation of this file.

    00001 /* $Id: command_type.h 24900 2013-01-08 22:46:42Z planetmaker $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef COMMAND_TYPE_H
    00013 #define COMMAND_TYPE_H
    00014
    00015 #include "economy_type.h"
    00016 #include "strings_type.h"
    00017 #include "tile_type.h"
    00018
    00023 class CommandCost {
    00024   ExpensesType expense_type;
    00025   Money cost;
    00026   StringID message;
    00027   bool success;
    00028   uint textref_stack_size;
    00029
    00030   static uint32 textref_stack[16];
    00031
    00032 public:
    00036   CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_size(0) {}
    00037
    00041   explicit CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false), textref_stack_size(0) {}
    00042
    00047   explicit CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_size(0) {}
    00048
    00054   CommandCost(ExpensesType ex_t, const Money &cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true), textref_stack_size(0) {}
    00055
    00056
    00061   inline void AddCost(const Money &cost)
    00062   {
    00063     this->cost += cost;
    00064   }
    00065
    00066   void AddCost(const CommandCost &cmd_cost);
    00067
    00072   inline void MultiplyCost(int factor)
    00073   {
    00074     this->cost *= factor;
    00075   }
    00076
    00081   inline Money GetCost() const
    00082   {
    00083     return this->cost;
    00084   }
    00085
    00090   inline ExpensesType GetExpensesType() const
    00091   {
    00092     return this->expense_type;
    00093   }
    00094
    00099   void MakeError(StringID message)
    00100   {
    00101     assert(message != INVALID_STRING_ID);
    00102     this->success = false;
    00103     this->message = message;
    00104   }
    00105
    00106   void UseTextRefStack(uint num_registers);
    00107
    00112   uint GetTextRefStackSize() const
    00113   {
    00114     return this->textref_stack_size;
    00115   }
    00116
    00121   const uint32 *GetTextRefStack() const
    00122   {
    00123     return textref_stack;
    00124   }
    00125
    00130   StringID GetErrorMessage() const
    00131   {
    00132     if (this->success) return INVALID_STRING_ID;
    00133     return this->message;
    00134   }
    00135
    00140   inline bool Succeeded() const
    00141   {
    00142     return this->success;
    00143   }
    00144
    00149   inline bool Failed() const
    00150   {
    00151     return !this->success;
    00152   }
    00153 };
    00154
    00165 enum Commands {
    00166   CMD_BUILD_RAILROAD_TRACK,
    00167   CMD_REMOVE_RAILROAD_TRACK,
    00168   CMD_BUILD_SINGLE_RAIL,
    00169   CMD_REMOVE_SINGLE_RAIL,
    00170   CMD_LANDSCAPE_CLEAR,
    00171   CMD_BUILD_BRIDGE,
    00172   CMD_BUILD_RAIL_STATION,
    00173   CMD_BUILD_TRAIN_DEPOT,
    00174   CMD_BUILD_SIGNALS,
    00175   CMD_REMOVE_SIGNALS,
    00176   CMD_TERRAFORM_LAND,
    00177   CMD_BUILD_OBJECT,
    00178   CMD_BUILD_TUNNEL,
    00179
    00180   CMD_REMOVE_FROM_RAIL_STATION,
    00181   CMD_CONVERT_RAIL,
    00182
    00183   CMD_BUILD_RAIL_WAYPOINT,
    00184   CMD_RENAME_WAYPOINT,
    00185   CMD_REMOVE_FROM_RAIL_WAYPOINT,
    00186
    00187   CMD_BUILD_ROAD_STOP,
    00188   CMD_REMOVE_ROAD_STOP,
    00189   CMD_BUILD_LONG_ROAD,
    00190   CMD_REMOVE_LONG_ROAD,
    00191   CMD_BUILD_ROAD,
    00192   CMD_BUILD_ROAD_DEPOT,
    00193
    00194   CMD_BUILD_AIRPORT,
    00195
    00196   CMD_BUILD_DOCK,
    00197
    00198   CMD_BUILD_SHIP_DEPOT,
    00199   CMD_BUILD_BUOY,
    00200
    00201   CMD_PLANT_TREE,
    00202
    00203   CMD_BUILD_VEHICLE,
    00204   CMD_SELL_VEHICLE,
    00205   CMD_REFIT_VEHICLE,
    00206   CMD_SEND_VEHICLE_TO_DEPOT,
    00207
    00208   CMD_MOVE_RAIL_VEHICLE,
    00209   CMD_FORCE_TRAIN_PROCEED,
    00210   CMD_REVERSE_TRAIN_DIRECTION,
    00211
    00212   CMD_CLEAR_ORDER_BACKUP,
    00213   CMD_MODIFY_ORDER,
    00214   CMD_SKIP_TO_ORDER,
    00215   CMD_DELETE_ORDER,
    00216   CMD_INSERT_ORDER,
    00217
    00218   CMD_CHANGE_SERVICE_INT,
    00219
    00220   CMD_BUILD_INDUSTRY,
    00221
    00222   CMD_SET_COMPANY_MANAGER_FACE,
    00223   CMD_SET_COMPANY_COLOUR,
    00224
    00225   CMD_INCREASE_LOAN,
    00226   CMD_DECREASE_LOAN,
    00227
    00228   CMD_WANT_ENGINE_PREVIEW,
    00229
    00230   CMD_RENAME_VEHICLE,
    00231   CMD_RENAME_ENGINE,
    00232   CMD_RENAME_COMPANY,
    00233   CMD_RENAME_PRESIDENT,
    00234   CMD_RENAME_STATION,
    00235   CMD_RENAME_DEPOT,
    00236
    00237   CMD_PLACE_SIGN,
    00238   CMD_RENAME_SIGN,
    00239
    00240   CMD_TURN_ROADVEH,
    00241
    00242   CMD_PAUSE,
    00243
    00244   CMD_BUY_SHARE_IN_COMPANY,
    00245   CMD_SELL_SHARE_IN_COMPANY,
    00246   CMD_BUY_COMPANY,
    00247
    00248   CMD_FOUND_TOWN,
    00249   CMD_RENAME_TOWN,
    00250   CMD_DO_TOWN_ACTION,
    00251   CMD_TOWN_CARGO_GOAL,
    00252   CMD_TOWN_GROWTH_RATE,
    00253   CMD_TOWN_SET_TEXT,
    00254   CMD_EXPAND_TOWN,
    00255   CMD_DELETE_TOWN,
    00256
    00257   CMD_ORDER_REFIT,
    00258   CMD_CLONE_ORDER,
    00259   CMD_CLEAR_AREA,
    00260
    00261   CMD_MONEY_CHEAT,
    00262   CMD_BUILD_CANAL,
    00263
    00264   CMD_CREATE_SUBSIDY,
    00265   CMD_COMPANY_CTRL,
    00266   CMD_CUSTOM_NEWS_ITEM,
    00267   CMD_CREATE_GOAL,
    00268   CMD_REMOVE_GOAL,
    00269   CMD_GOAL_QUESTION,
    00270   CMD_GOAL_QUESTION_ANSWER,
    00271   CMD_LEVEL_LAND,
    00272
    00273   CMD_BUILD_LOCK,
    00274
    00275   CMD_BUILD_SIGNAL_TRACK,
    00276   CMD_REMOVE_SIGNAL_TRACK,
    00277
    00278   CMD_GIVE_MONEY,
    00279   CMD_CHANGE_SETTING,
    00280   CMD_CHANGE_COMPANY_SETTING,
    00281
    00282   CMD_SET_AUTOREPLACE,
    00283
    00284   CMD_CLONE_VEHICLE,
    00285   CMD_START_STOP_VEHICLE,
    00286   CMD_MASS_START_STOP,
    00287   CMD_AUTOREPLACE_VEHICLE,
    00288   CMD_DEPOT_SELL_ALL_VEHICLES,
    00289   CMD_DEPOT_MASS_AUTOREPLACE,
    00290
    00291   CMD_CREATE_GROUP,
    00292   CMD_DELETE_GROUP,
    00293   CMD_RENAME_GROUP,
    00294   CMD_ADD_VEHICLE_GROUP,
    00295   CMD_ADD_SHARED_VEHICLE_GROUP,
    00296   CMD_REMOVE_ALL_VEHICLES_GROUP,
    00297   CMD_SET_GROUP_REPLACE_PROTECTION,
    00298
    00299   CMD_MOVE_ORDER,
    00300   CMD_CHANGE_TIMETABLE,
    00301   CMD_SET_VEHICLE_ON_TIME,
    00302   CMD_AUTOFILL_TIMETABLE,
    00303   CMD_SET_TIMETABLE_START,
    00304
    00305   CMD_OPEN_CLOSE_AIRPORT,
    00306
    00307   CMD_END,
    00308 };
    00309
    00315 enum DoCommandFlag {
    00316   DC_NONE                  = 0x000,
    00317   DC_EXEC                  = 0x001,
    00318   DC_AUTO                  = 0x002,
    00319   DC_QUERY_COST            = 0x004,
    00320   DC_NO_WATER              = 0x008,
    00321   DC_NO_RAIL_OVERLAP       = 0x010,
    00322   DC_NO_TEST_TOWN_RATING   = 0x020,
    00323   DC_BANKRUPT              = 0x040,
    00324   DC_AUTOREPLACE           = 0x080,
    00325   DC_NO_CARGO_CAP_CHECK    = 0x100,
    00326   DC_ALL_TILES             = 0x200,
    00327   DC_NO_MODIFY_TOWN_RATING = 0x400,
    00328   DC_FORCE_CLEAR_TILE      = 0x800,
    00329 };
    00330 DECLARE_ENUM_AS_BIT_SET(DoCommandFlag)
    00331
    00332
    00341 #define CMD_MSG(x) ((x) << 16)
    00342
    00348 enum FlaggedCommands {
    00349   CMD_NETWORK_COMMAND       = 0x0100,
    00350   CMD_FLAGS_MASK            = 0xFF00,
    00351   CMD_ID_MASK               = 0x00FF,
    00352 };
    00353
    00359 enum CommandFlags {
    00360   CMD_SERVER    = 0x001,
    00361   CMD_SPECTATOR = 0x002,
    00362   CMD_OFFLINE   = 0x004,
    00363   CMD_AUTO      = 0x008,
    00364   CMD_ALL_TILES = 0x010,
    00365   CMD_NO_TEST   = 0x020,
    00366   CMD_NO_WATER  = 0x040,
    00367   CMD_CLIENT_ID = 0x080,
    00368   CMD_DEITY     = 0x100,
    00369   CMD_STR_CTRL  = 0x200,
    00370 };
    00371 DECLARE_ENUM_AS_BIT_SET(CommandFlags)
    00372
    00373
    00374 enum CommandType {
    00375   CMDT_LANDSCAPE_CONSTRUCTION,
    00376   CMDT_VEHICLE_CONSTRUCTION,
    00377   CMDT_MONEY_MANAGEMENT,
    00378   CMDT_VEHICLE_MANAGEMENT,
    00379   CMDT_ROUTE_MANAGEMENT,
    00380   CMDT_OTHER_MANAGEMENT,
    00381   CMDT_COMPANY_SETTING,
    00382   CMDT_SERVER_SETTING,
    00383   CMDT_CHEAT,
    00384
    00385   CMDT_END,
    00386 };
    00387
    00389 enum CommandPauseLevel {
    00390   CMDPL_NO_ACTIONS,
    00391   CMDPL_NO_CONSTRUCTION,
    00392   CMDPL_NO_LANDSCAPING,
    00393   CMDPL_ALL_ACTIONS,
    00394 };
    00395
    00414 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
    00415
    00422 struct Command {
    00423   CommandProc *proc;
    00424   const char *name;
    00425   CommandFlags flags;
    00426   CommandType type;
    00427 };
    00428
    00442 typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
    00443
    00447 struct CommandContainer {
    00448   TileIndex tile;
    00449   uint32 p1;
    00450   uint32 p2;
    00451   uint32 cmd;
    00452   CommandCallback *callback;
    00453   char text[32 * MAX_CHAR_LENGTH];
    00454 };
    00455
    00456 #endif /* COMMAND_TYPE_H */