command_type.h

Go to the documentation of this file.
00001 /* $Id: command_type.h 19603 2010-04-11 10:57:21Z rubidium $ */
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 
00029 public:
00033   CommandCost() : expense_type(INVALID_EXPENSES), cost(0), message(INVALID_STRING_ID), success(true) {}
00034 
00038   CommandCost(StringID msg) : expense_type(INVALID_EXPENSES), cost(0), message(msg), success(false) {}
00039 
00044   CommandCost(ExpensesType ex_t) : expense_type(ex_t), cost(0), message(INVALID_STRING_ID), success(true) {}
00045 
00051   CommandCost(ExpensesType ex_t, const Money &cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true) {}
00052 
00053 
00058   FORCEINLINE void AddCost(const Money &cost)
00059   {
00060     this->cost += cost;
00061   }
00062 
00063   void AddCost(const CommandCost &cmd_cost);
00064 
00069   FORCEINLINE void MultiplyCost(int factor)
00070   {
00071     this->cost *= factor;
00072   }
00073 
00078   FORCEINLINE Money GetCost() const
00079   {
00080     return this->cost;
00081   }
00082 
00087   FORCEINLINE ExpensesType GetExpensesType() const
00088   {
00089     return this->expense_type;
00090   }
00091 
00095   FORCEINLINE void SetGlobalErrorMessage() const
00096   {
00097     extern StringID _error_message;
00098     if (this->message != INVALID_STRING_ID) _error_message = this->message;
00099   }
00100 
00105   void MakeError(StringID message)
00106   {
00107     assert(message != INVALID_STRING_ID);
00108     this->success = false;
00109     this->message = message;
00110   }
00111 
00116   StringID GetErrorMessage() const
00117   {
00118     extern StringID _error_message;
00119 
00120     if (this->success) return INVALID_STRING_ID;
00121     if (this->message != INVALID_STRING_ID) return this->message;
00122     return _error_message;
00123   }
00124 
00129   FORCEINLINE bool Succeeded() const
00130   {
00131     return this->success;
00132   }
00133 
00138   FORCEINLINE bool Failed() const
00139   {
00140     return !this->success;
00141   }
00142 };
00143 
00154 enum {
00155   CMD_BUILD_RAILROAD_TRACK,         
00156   CMD_REMOVE_RAILROAD_TRACK,        
00157   CMD_BUILD_SINGLE_RAIL,            
00158   CMD_REMOVE_SINGLE_RAIL,           
00159   CMD_LANDSCAPE_CLEAR,              
00160   CMD_BUILD_BRIDGE,                 
00161   CMD_BUILD_RAIL_STATION,           
00162   CMD_BUILD_TRAIN_DEPOT,            
00163   CMD_BUILD_SIGNALS,                
00164   CMD_REMOVE_SIGNALS,               
00165   CMD_TERRAFORM_LAND,               
00166   CMD_PURCHASE_LAND_AREA,           
00167   CMD_SELL_LAND_AREA,               
00168   CMD_BUILD_TUNNEL,                 
00169 
00170   CMD_REMOVE_FROM_RAIL_STATION,     
00171   CMD_CONVERT_RAIL,                 
00172 
00173   CMD_BUILD_RAIL_WAYPOINT,          
00174   CMD_RENAME_WAYPOINT,              
00175   CMD_REMOVE_FROM_RAIL_WAYPOINT,    
00176 
00177   CMD_BUILD_ROAD_STOP,              
00178   CMD_REMOVE_ROAD_STOP,             
00179   CMD_BUILD_LONG_ROAD,              
00180   CMD_REMOVE_LONG_ROAD,             
00181   CMD_BUILD_ROAD,                   
00182   CMD_BUILD_ROAD_DEPOT,             
00183 
00184   CMD_BUILD_AIRPORT,                
00185 
00186   CMD_BUILD_DOCK,                   
00187 
00188   CMD_BUILD_SHIP_DEPOT,             
00189   CMD_BUILD_BUOY,                   
00190 
00191   CMD_PLANT_TREE,                   
00192 
00193   CMD_BUILD_RAIL_VEHICLE,           
00194   CMD_MOVE_RAIL_VEHICLE,            
00195 
00196   CMD_SELL_RAIL_WAGON,              
00197 
00198   CMD_SEND_TRAIN_TO_DEPOT,          
00199   CMD_FORCE_TRAIN_PROCEED,          
00200   CMD_REVERSE_TRAIN_DIRECTION,      
00201 
00202   CMD_MODIFY_ORDER,                 
00203   CMD_SKIP_TO_ORDER,                
00204   CMD_DELETE_ORDER,                 
00205   CMD_INSERT_ORDER,                 
00206 
00207   CMD_CHANGE_SERVICE_INT,           
00208 
00209   CMD_BUILD_INDUSTRY,               
00210 
00211   CMD_BUILD_COMPANY_HQ,             
00212   CMD_SET_COMPANY_MANAGER_FACE,     
00213   CMD_SET_COMPANY_COLOUR,            
00214 
00215   CMD_INCREASE_LOAN,                
00216   CMD_DECREASE_LOAN,                
00217 
00218   CMD_WANT_ENGINE_PREVIEW,          
00219 
00220   CMD_RENAME_VEHICLE,               
00221   CMD_RENAME_ENGINE,                
00222   CMD_RENAME_COMPANY,               
00223   CMD_RENAME_PRESIDENT,             
00224   CMD_RENAME_STATION,               
00225 
00226   CMD_SELL_AIRCRAFT,                
00227   CMD_BUILD_AIRCRAFT,               
00228   CMD_SEND_AIRCRAFT_TO_HANGAR,      
00229   CMD_REFIT_AIRCRAFT,               
00230 
00231   CMD_PLACE_SIGN,                   
00232   CMD_RENAME_SIGN,                  
00233 
00234   CMD_BUILD_ROAD_VEH,               
00235   CMD_SELL_ROAD_VEH,                
00236   CMD_SEND_ROADVEH_TO_DEPOT,        
00237   CMD_TURN_ROADVEH,                 
00238   CMD_REFIT_ROAD_VEH,               
00239 
00240   CMD_PAUSE,                        
00241 
00242   CMD_BUY_SHARE_IN_COMPANY,         
00243   CMD_SELL_SHARE_IN_COMPANY,        
00244   CMD_BUY_COMPANY,                  
00245 
00246   CMD_FOUND_TOWN,                   
00247   CMD_RENAME_TOWN,                  
00248   CMD_DO_TOWN_ACTION,               
00249 
00250   CMD_SELL_SHIP,                    
00251   CMD_BUILD_SHIP,                   
00252   CMD_SEND_SHIP_TO_DEPOT,           
00253   CMD_REFIT_SHIP,                   
00254 
00255   CMD_ORDER_REFIT,                  
00256   CMD_CLONE_ORDER,                  
00257   CMD_CLEAR_AREA,                   
00258 
00259   CMD_MONEY_CHEAT,                  
00260   CMD_BUILD_CANAL,                  
00261 
00262   CMD_COMPANY_CTRL,                 
00263   CMD_LEVEL_LAND,                   
00264 
00265   CMD_REFIT_RAIL_VEHICLE,           
00266   CMD_RESTORE_ORDER_INDEX,          
00267   CMD_BUILD_LOCK,                   
00268 
00269   CMD_BUILD_SIGNAL_TRACK,           
00270   CMD_REMOVE_SIGNAL_TRACK,          
00271 
00272   CMD_GIVE_MONEY,                   
00273   CMD_CHANGE_SETTING,               
00274   CMD_CHANGE_COMPANY_SETTING,       
00275 
00276   CMD_SET_AUTOREPLACE,              
00277 
00278   CMD_CLONE_VEHICLE,                
00279   CMD_START_STOP_VEHICLE,           
00280   CMD_MASS_START_STOP,              
00281   CMD_AUTOREPLACE_VEHICLE,          
00282   CMD_DEPOT_SELL_ALL_VEHICLES,      
00283   CMD_DEPOT_MASS_AUTOREPLACE,       
00284 
00285   CMD_CREATE_GROUP,                 
00286   CMD_DELETE_GROUP,                 
00287   CMD_RENAME_GROUP,                 
00288   CMD_ADD_VEHICLE_GROUP,            
00289   CMD_ADD_SHARED_VEHICLE_GROUP,     
00290   CMD_REMOVE_ALL_VEHICLES_GROUP,    
00291   CMD_SET_GROUP_REPLACE_PROTECTION, 
00292 
00293   CMD_MOVE_ORDER,                   
00294   CMD_CHANGE_TIMETABLE,             
00295   CMD_SET_VEHICLE_ON_TIME,          
00296   CMD_AUTOFILL_TIMETABLE,           
00297   CMD_SET_TIMETABLE_START,          
00298 };
00299 
00305 enum DoCommandFlag {
00306   DC_NONE                  = 0x000, 
00307   DC_EXEC                  = 0x001, 
00308   DC_AUTO                  = 0x002, 
00309   DC_QUERY_COST            = 0x004, 
00310   DC_NO_WATER              = 0x008, 
00311   DC_NO_RAIL_OVERLAP       = 0x010, 
00312   DC_NO_TEST_TOWN_RATING   = 0x020, 
00313   DC_BANKRUPT              = 0x040, 
00314   DC_AUTOREPLACE           = 0x080, 
00315   DC_ALL_TILES             = 0x100, 
00316   DC_NO_MODIFY_TOWN_RATING = 0x200, 
00317 };
00318 DECLARE_ENUM_AS_BIT_SET(DoCommandFlag);
00319 
00329 #define CMD_MSG(x) ((x) << 16)
00330 
00336 enum {
00337   CMD_NETWORK_COMMAND       = 0x0100, 
00338   CMD_NO_TEST_IF_IN_NETWORK = 0x0200, 
00339   CMD_FLAGS_MASK            = 0xFF00, 
00340   CMD_ID_MASK               = 0x00FF, 
00341 };
00342 
00348 enum {
00349   CMD_SERVER    = 0x01, 
00350   CMD_SPECTATOR = 0x02, 
00351   CMD_OFFLINE   = 0x04, 
00352   CMD_AUTO      = 0x08, 
00353   CMD_ALL_TILES = 0x10, 
00354   CMD_NO_TEST   = 0x20, 
00355   CMD_NO_WATER  = 0x40, 
00356 };
00357 
00376 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
00377 
00384 struct Command {
00385   CommandProc *proc; 
00386   const char *name;  
00387   byte flags;        
00388 };
00389 
00403 typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
00404 
00408 struct CommandContainer {
00409   TileIndex tile;            
00410   uint32 p1;                 
00411   uint32 p2;                 
00412   uint32 cmd;                
00413   CommandCallback *callback; 
00414   char text[80];             
00415 };
00416 
00417 #endif /* COMMAND_TYPE_H */

Generated on Sat Jul 17 18:43:16 2010 for OpenTTD by  doxygen 1.6.1