command_type.h

Go to the documentation of this file.
00001 /* $Id: command_type.h 26241 2014-01-12 18:00:39Z frosch $ */
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 
00019 struct GRFFile;
00020 
00025 class CommandCost {
00026   ExpensesType expense_type; 
00027   Money cost;       
00028   StringID message; 
00029   bool success;     
00030   const GRFFile *textref_stack_grffile; 
00031   uint textref_stack_size;   
00032 
00033   static uint32 textref_stack[16];
00034 
00035 public:
00039   CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
00040 
00044   explicit CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false), textref_stack_grffile(NULL), textref_stack_size(0) {}
00045 
00050   explicit CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
00051 
00057   CommandCost(ExpensesType ex_t, const Money &cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true), textref_stack_grffile(NULL), textref_stack_size(0) {}
00058 
00059 
00064   inline void AddCost(const Money &cost)
00065   {
00066     this->cost += cost;
00067   }
00068 
00069   void AddCost(const CommandCost &cmd_cost);
00070 
00075   inline void MultiplyCost(int factor)
00076   {
00077     this->cost *= factor;
00078   }
00079 
00084   inline Money GetCost() const
00085   {
00086     return this->cost;
00087   }
00088 
00093   inline ExpensesType GetExpensesType() const
00094   {
00095     return this->expense_type;
00096   }
00097 
00102   void MakeError(StringID message)
00103   {
00104     assert(message != INVALID_STRING_ID);
00105     this->success = false;
00106     this->message = message;
00107   }
00108 
00109   void UseTextRefStack(const GRFFile *grffile, uint num_registers);
00110 
00115   const GRFFile *GetTextRefStackGRF() const
00116   {
00117     return this->textref_stack_grffile;
00118   }
00119 
00124   uint GetTextRefStackSize() const
00125   {
00126     return this->textref_stack_size;
00127   }
00128 
00133   const uint32 *GetTextRefStack() const
00134   {
00135     return textref_stack;
00136   }
00137 
00142   StringID GetErrorMessage() const
00143   {
00144     if (this->success) return INVALID_STRING_ID;
00145     return this->message;
00146   }
00147 
00152   inline bool Succeeded() const
00153   {
00154     return this->success;
00155   }
00156 
00161   inline bool Failed() const
00162   {
00163     return !this->success;
00164   }
00165 };
00166 
00177 enum Commands {
00178   CMD_BUILD_RAILROAD_TRACK,         
00179   CMD_REMOVE_RAILROAD_TRACK,        
00180   CMD_BUILD_SINGLE_RAIL,            
00181   CMD_REMOVE_SINGLE_RAIL,           
00182   CMD_LANDSCAPE_CLEAR,              
00183   CMD_BUILD_BRIDGE,                 
00184   CMD_BUILD_RAIL_STATION,           
00185   CMD_BUILD_TRAIN_DEPOT,            
00186   CMD_BUILD_SIGNALS,                
00187   CMD_REMOVE_SIGNALS,               
00188   CMD_TERRAFORM_LAND,               
00189   CMD_BUILD_OBJECT,                 
00190   CMD_BUILD_TUNNEL,                 
00191 
00192   CMD_REMOVE_FROM_RAIL_STATION,     
00193   CMD_CONVERT_RAIL,                 
00194 
00195   CMD_BUILD_RAIL_WAYPOINT,          
00196   CMD_RENAME_WAYPOINT,              
00197   CMD_REMOVE_FROM_RAIL_WAYPOINT,    
00198 
00199   CMD_BUILD_ROAD_STOP,              
00200   CMD_REMOVE_ROAD_STOP,             
00201   CMD_BUILD_LONG_ROAD,              
00202   CMD_REMOVE_LONG_ROAD,             
00203   CMD_BUILD_ROAD,                   
00204   CMD_BUILD_ROAD_DEPOT,             
00205 
00206   CMD_BUILD_AIRPORT,                
00207 
00208   CMD_BUILD_DOCK,                   
00209 
00210   CMD_BUILD_SHIP_DEPOT,             
00211   CMD_BUILD_BUOY,                   
00212 
00213   CMD_PLANT_TREE,                   
00214 
00215   CMD_BUILD_VEHICLE,                
00216   CMD_SELL_VEHICLE,                 
00217   CMD_REFIT_VEHICLE,                
00218   CMD_SEND_VEHICLE_TO_DEPOT,        
00219 
00220   CMD_MOVE_RAIL_VEHICLE,            
00221   CMD_FORCE_TRAIN_PROCEED,          
00222   CMD_REVERSE_TRAIN_DIRECTION,      
00223 
00224   CMD_CLEAR_ORDER_BACKUP,           
00225   CMD_MODIFY_ORDER,                 
00226   CMD_SKIP_TO_ORDER,                
00227   CMD_DELETE_ORDER,                 
00228   CMD_INSERT_ORDER,                 
00229 
00230   CMD_CHANGE_SERVICE_INT,           
00231 
00232   CMD_BUILD_INDUSTRY,               
00233 
00234   CMD_SET_COMPANY_MANAGER_FACE,     
00235   CMD_SET_COMPANY_COLOUR,           
00236 
00237   CMD_INCREASE_LOAN,                
00238   CMD_DECREASE_LOAN,                
00239 
00240   CMD_WANT_ENGINE_PREVIEW,          
00241 
00242   CMD_RENAME_VEHICLE,               
00243   CMD_RENAME_ENGINE,                
00244   CMD_RENAME_COMPANY,               
00245   CMD_RENAME_PRESIDENT,             
00246   CMD_RENAME_STATION,               
00247   CMD_RENAME_DEPOT,                 
00248 
00249   CMD_PLACE_SIGN,                   
00250   CMD_RENAME_SIGN,                  
00251 
00252   CMD_TURN_ROADVEH,                 
00253 
00254   CMD_PAUSE,                        
00255 
00256   CMD_BUY_SHARE_IN_COMPANY,         
00257   CMD_SELL_SHARE_IN_COMPANY,        
00258   CMD_BUY_COMPANY,                  
00259 
00260   CMD_FOUND_TOWN,                   
00261   CMD_RENAME_TOWN,                  
00262   CMD_DO_TOWN_ACTION,               
00263   CMD_TOWN_CARGO_GOAL,              
00264   CMD_TOWN_GROWTH_RATE,             
00265   CMD_TOWN_SET_TEXT,                
00266   CMD_EXPAND_TOWN,                  
00267   CMD_DELETE_TOWN,                  
00268 
00269   CMD_ORDER_REFIT,                  
00270   CMD_CLONE_ORDER,                  
00271   CMD_CLEAR_AREA,                   
00272 
00273   CMD_MONEY_CHEAT,                  
00274   CMD_CHANGE_BANK_BALANCE,          
00275   CMD_BUILD_CANAL,                  
00276 
00277   CMD_CREATE_SUBSIDY,               
00278   CMD_COMPANY_CTRL,                 
00279   CMD_CUSTOM_NEWS_ITEM,             
00280   CMD_CREATE_GOAL,                  
00281   CMD_REMOVE_GOAL,                  
00282   CMD_SET_GOAL_TEXT,                
00283   CMD_SET_GOAL_PROGRESS,            
00284   CMD_SET_GOAL_COMPLETED,           
00285   CMD_GOAL_QUESTION,                
00286   CMD_GOAL_QUESTION_ANSWER,         
00287   CMD_CREATE_STORY_PAGE,            
00288   CMD_CREATE_STORY_PAGE_ELEMENT,    
00289   CMD_UPDATE_STORY_PAGE_ELEMENT,    
00290   CMD_SET_STORY_PAGE_TITLE,         
00291   CMD_SHOW_STORY_PAGE,              
00292   CMD_REMOVE_STORY_PAGE,            
00293   CMD_LEVEL_LAND,                   
00294 
00295   CMD_BUILD_LOCK,                   
00296 
00297   CMD_BUILD_SIGNAL_TRACK,           
00298   CMD_REMOVE_SIGNAL_TRACK,          
00299 
00300   CMD_GIVE_MONEY,                   
00301   CMD_CHANGE_SETTING,               
00302   CMD_CHANGE_COMPANY_SETTING,       
00303 
00304   CMD_SET_AUTOREPLACE,              
00305 
00306   CMD_CLONE_VEHICLE,                
00307   CMD_START_STOP_VEHICLE,           
00308   CMD_MASS_START_STOP,              
00309   CMD_AUTOREPLACE_VEHICLE,          
00310   CMD_DEPOT_SELL_ALL_VEHICLES,      
00311   CMD_DEPOT_MASS_AUTOREPLACE,       
00312 
00313   CMD_CREATE_GROUP,                 
00314   CMD_DELETE_GROUP,                 
00315   CMD_RENAME_GROUP,                 
00316   CMD_ADD_VEHICLE_GROUP,            
00317   CMD_ADD_SHARED_VEHICLE_GROUP,     
00318   CMD_REMOVE_ALL_VEHICLES_GROUP,    
00319   CMD_SET_GROUP_REPLACE_PROTECTION, 
00320 
00321   CMD_MOVE_ORDER,                   
00322   CMD_CHANGE_TIMETABLE,             
00323   CMD_SET_VEHICLE_ON_TIME,          
00324   CMD_AUTOFILL_TIMETABLE,           
00325   CMD_SET_TIMETABLE_START,          
00326 
00327   CMD_OPEN_CLOSE_AIRPORT,           
00328 
00329   CMD_END,                          
00330 };
00331 
00337 enum DoCommandFlag {
00338   DC_NONE                  = 0x000, 
00339   DC_EXEC                  = 0x001, 
00340   DC_AUTO                  = 0x002, 
00341   DC_QUERY_COST            = 0x004, 
00342   DC_NO_WATER              = 0x008, 
00343   DC_NO_RAIL_OVERLAP       = 0x010, 
00344   DC_NO_TEST_TOWN_RATING   = 0x020, 
00345   DC_BANKRUPT              = 0x040, 
00346   DC_AUTOREPLACE           = 0x080, 
00347   DC_NO_CARGO_CAP_CHECK    = 0x100, 
00348   DC_ALL_TILES             = 0x200, 
00349   DC_NO_MODIFY_TOWN_RATING = 0x400, 
00350   DC_FORCE_CLEAR_TILE      = 0x800, 
00351 };
00352 DECLARE_ENUM_AS_BIT_SET(DoCommandFlag)
00353 
00354 
00363 #define CMD_MSG(x) ((x) << 16)
00364 
00370 enum FlaggedCommands {
00371   CMD_NETWORK_COMMAND       = 0x0100, 
00372   CMD_FLAGS_MASK            = 0xFF00, 
00373   CMD_ID_MASK               = 0x00FF, 
00374 };
00375 
00381 enum CommandFlags {
00382   CMD_SERVER    = 0x001, 
00383   CMD_SPECTATOR = 0x002, 
00384   CMD_OFFLINE   = 0x004, 
00385   CMD_AUTO      = 0x008, 
00386   CMD_ALL_TILES = 0x010, 
00387   CMD_NO_TEST   = 0x020, 
00388   CMD_NO_WATER  = 0x040, 
00389   CMD_CLIENT_ID = 0x080, 
00390   CMD_DEITY     = 0x100, 
00391   CMD_STR_CTRL  = 0x200, 
00392 };
00393 DECLARE_ENUM_AS_BIT_SET(CommandFlags)
00394 
00395 
00396 enum CommandType {
00397   CMDT_LANDSCAPE_CONSTRUCTION, 
00398   CMDT_VEHICLE_CONSTRUCTION,   
00399   CMDT_MONEY_MANAGEMENT,       
00400   CMDT_VEHICLE_MANAGEMENT,     
00401   CMDT_ROUTE_MANAGEMENT,       
00402   CMDT_OTHER_MANAGEMENT,       
00403   CMDT_COMPANY_SETTING,        
00404   CMDT_SERVER_SETTING,         
00405   CMDT_CHEAT,                  
00406 
00407   CMDT_END,                    
00408 };
00409 
00411 enum CommandPauseLevel {
00412   CMDPL_NO_ACTIONS,      
00413   CMDPL_NO_CONSTRUCTION, 
00414   CMDPL_NO_LANDSCAPING,  
00415   CMDPL_ALL_ACTIONS,     
00416 };
00417 
00436 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
00437 
00444 struct Command {
00445   CommandProc *proc;  
00446   const char *name;   
00447   CommandFlags flags; 
00448   CommandType type;   
00449 };
00450 
00464 typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
00465 
00469 struct CommandContainer {
00470   TileIndex tile;                  
00471   uint32 p1;                       
00472   uint32 p2;                       
00473   uint32 cmd;                      
00474   CommandCallback *callback;       
00475   char text[32 * MAX_CHAR_LENGTH]; 
00476 };
00477 
00478 #endif /* COMMAND_TYPE_H */