command_type.h

Go to the documentation of this file.
00001 /* $Id: command_type.h 18975 2010-01-31 20:55:10Z 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 
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, Money cst) : expense_type(ex_t), cost(cst), message(INVALID_STRING_ID), success(true) {}
00052 
00059   CommandCost AddCost(CommandCost ret);
00060 
00066   CommandCost AddCost(Money cost)
00067   {
00068     this->cost += cost;
00069     return *this;
00070   }
00071 
00077   CommandCost MultiplyCost(int factor)
00078   {
00079     this->cost *= factor;
00080     return *this;
00081   }
00082 
00087   Money GetCost() const
00088   {
00089     return this->cost;
00090   }
00091 
00096   ExpensesType GetExpensesType() const
00097   {
00098     return this->expense_type;
00099   }
00100 
00104   void SetGlobalErrorMessage() const
00105   {
00106     extern StringID _error_message;
00107     if (this->message != INVALID_STRING_ID) _error_message = this->message;
00108   }
00109 
00114   void MakeError(StringID message)
00115   {
00116     assert(message != INVALID_STRING_ID);
00117     this->success = false;
00118     this->message = message;
00119   }
00120 
00125   StringID GetErrorMessage() const
00126   {
00127     extern StringID _error_message;
00128 
00129     if (this->success) return INVALID_STRING_ID;
00130     if (this->message != INVALID_STRING_ID) return this->message;
00131     return _error_message;
00132   }
00133 
00138   bool Succeeded() const
00139   {
00140     return this->success;
00141   }
00142 
00147   bool Failed() const
00148   {
00149     return !this->success;
00150   }
00151 };
00152 
00163 enum {
00164   CMD_BUILD_RAILROAD_TRACK,         
00165   CMD_REMOVE_RAILROAD_TRACK,        
00166   CMD_BUILD_SINGLE_RAIL,            
00167   CMD_REMOVE_SINGLE_RAIL,           
00168   CMD_LANDSCAPE_CLEAR,              
00169   CMD_BUILD_BRIDGE,                 
00170   CMD_BUILD_RAIL_STATION,           
00171   CMD_BUILD_TRAIN_DEPOT,            
00172   CMD_BUILD_SIGNALS,                
00173   CMD_REMOVE_SIGNALS,               
00174   CMD_TERRAFORM_LAND,               
00175   CMD_PURCHASE_LAND_AREA,           
00176   CMD_SELL_LAND_AREA,               
00177   CMD_BUILD_TUNNEL,                 
00178 
00179   CMD_REMOVE_FROM_RAIL_STATION,     
00180   CMD_CONVERT_RAIL,                 
00181 
00182   CMD_BUILD_RAIL_WAYPOINT,          
00183   CMD_RENAME_WAYPOINT,              
00184   CMD_REMOVE_FROM_RAIL_WAYPOINT,    
00185 
00186   CMD_BUILD_ROAD_STOP,              
00187   CMD_REMOVE_ROAD_STOP,             
00188   CMD_BUILD_LONG_ROAD,              
00189   CMD_REMOVE_LONG_ROAD,             
00190   CMD_BUILD_ROAD,                   
00191   CMD_BUILD_ROAD_DEPOT,             
00192 
00193   CMD_BUILD_AIRPORT,                
00194 
00195   CMD_BUILD_DOCK,                   
00196 
00197   CMD_BUILD_SHIP_DEPOT,             
00198   CMD_BUILD_BUOY,                   
00199 
00200   CMD_PLANT_TREE,                   
00201 
00202   CMD_BUILD_RAIL_VEHICLE,           
00203   CMD_MOVE_RAIL_VEHICLE,            
00204 
00205   CMD_SELL_RAIL_WAGON,              
00206 
00207   CMD_SEND_TRAIN_TO_DEPOT,          
00208   CMD_FORCE_TRAIN_PROCEED,          
00209   CMD_REVERSE_TRAIN_DIRECTION,      
00210 
00211   CMD_MODIFY_ORDER,                 
00212   CMD_SKIP_TO_ORDER,                
00213   CMD_DELETE_ORDER,                 
00214   CMD_INSERT_ORDER,                 
00215 
00216   CMD_CHANGE_SERVICE_INT,           
00217 
00218   CMD_BUILD_INDUSTRY,               
00219 
00220   CMD_BUILD_COMPANY_HQ,             
00221   CMD_SET_COMPANY_MANAGER_FACE,     
00222   CMD_SET_COMPANY_COLOUR,            
00223 
00224   CMD_INCREASE_LOAN,                
00225   CMD_DECREASE_LOAN,                
00226 
00227   CMD_WANT_ENGINE_PREVIEW,          
00228 
00229   CMD_RENAME_VEHICLE,               
00230   CMD_RENAME_ENGINE,                
00231   CMD_RENAME_COMPANY,               
00232   CMD_RENAME_PRESIDENT,             
00233   CMD_RENAME_STATION,               
00234 
00235   CMD_SELL_AIRCRAFT,                
00236   CMD_BUILD_AIRCRAFT,               
00237   CMD_SEND_AIRCRAFT_TO_HANGAR,      
00238   CMD_REFIT_AIRCRAFT,               
00239 
00240   CMD_PLACE_SIGN,                   
00241   CMD_RENAME_SIGN,                  
00242 
00243   CMD_BUILD_ROAD_VEH,               
00244   CMD_SELL_ROAD_VEH,                
00245   CMD_SEND_ROADVEH_TO_DEPOT,        
00246   CMD_TURN_ROADVEH,                 
00247   CMD_REFIT_ROAD_VEH,               
00248 
00249   CMD_PAUSE,                        
00250 
00251   CMD_BUY_SHARE_IN_COMPANY,         
00252   CMD_SELL_SHARE_IN_COMPANY,        
00253   CMD_BUY_COMPANY,                  
00254 
00255   CMD_FOUND_TOWN,                   
00256   CMD_RENAME_TOWN,                  
00257   CMD_DO_TOWN_ACTION,               
00258 
00259   CMD_SELL_SHIP,                    
00260   CMD_BUILD_SHIP,                   
00261   CMD_SEND_SHIP_TO_DEPOT,           
00262   CMD_REFIT_SHIP,                   
00263 
00264   CMD_ORDER_REFIT,                  
00265   CMD_CLONE_ORDER,                  
00266   CMD_CLEAR_AREA,                   
00267 
00268   CMD_MONEY_CHEAT,                  
00269   CMD_BUILD_CANAL,                  
00270 
00271   CMD_COMPANY_CTRL,                 
00272   CMD_LEVEL_LAND,                   
00273 
00274   CMD_REFIT_RAIL_VEHICLE,           
00275   CMD_RESTORE_ORDER_INDEX,          
00276   CMD_BUILD_LOCK,                   
00277 
00278   CMD_BUILD_SIGNAL_TRACK,           
00279   CMD_REMOVE_SIGNAL_TRACK,          
00280 
00281   CMD_GIVE_MONEY,                   
00282   CMD_CHANGE_SETTING,               
00283   CMD_CHANGE_COMPANY_SETTING,       
00284 
00285   CMD_SET_AUTOREPLACE,              
00286 
00287   CMD_CLONE_VEHICLE,                
00288   CMD_START_STOP_VEHICLE,           
00289   CMD_MASS_START_STOP,              
00290   CMD_AUTOREPLACE_VEHICLE,          
00291   CMD_DEPOT_SELL_ALL_VEHICLES,      
00292   CMD_DEPOT_MASS_AUTOREPLACE,       
00293 
00294   CMD_CREATE_GROUP,                 
00295   CMD_DELETE_GROUP,                 
00296   CMD_RENAME_GROUP,                 
00297   CMD_ADD_VEHICLE_GROUP,            
00298   CMD_ADD_SHARED_VEHICLE_GROUP,     
00299   CMD_REMOVE_ALL_VEHICLES_GROUP,    
00300   CMD_SET_GROUP_REPLACE_PROTECTION, 
00301 
00302   CMD_MOVE_ORDER,                   
00303   CMD_CHANGE_TIMETABLE,             
00304   CMD_SET_VEHICLE_ON_TIME,          
00305   CMD_AUTOFILL_TIMETABLE,           
00306   CMD_SET_TIMETABLE_START,          
00307 };
00308 
00314 enum DoCommandFlag {
00315   DC_NONE                  = 0x000, 
00316   DC_EXEC                  = 0x001, 
00317   DC_AUTO                  = 0x002, 
00318   DC_QUERY_COST            = 0x004, 
00319   DC_NO_WATER              = 0x008, 
00320   DC_NO_RAIL_OVERLAP       = 0x010, 
00321   DC_NO_TEST_TOWN_RATING   = 0x020, 
00322   DC_BANKRUPT              = 0x040, 
00323   DC_AUTOREPLACE           = 0x080, 
00324   DC_ALL_TILES             = 0x100, 
00325   DC_NO_MODIFY_TOWN_RATING = 0x200, 
00326 };
00327 DECLARE_ENUM_AS_BIT_SET(DoCommandFlag);
00328 
00338 #define CMD_MSG(x) ((x) << 16)
00339 
00345 enum {
00346   CMD_NETWORK_COMMAND       = 0x0100, 
00347   CMD_NO_TEST_IF_IN_NETWORK = 0x0200, 
00348   CMD_FLAGS_MASK            = 0xFF00, 
00349   CMD_ID_MASK               = 0x00FF, 
00350 };
00351 
00357 enum {
00358   CMD_SERVER    = 0x01, 
00359   CMD_SPECTATOR = 0x02, 
00360   CMD_OFFLINE   = 0x04, 
00361   CMD_AUTO      = 0x08, 
00362   CMD_ALL_TILES = 0x10, 
00363   CMD_NO_TEST   = 0x20, 
00364   CMD_NO_WATER  = 0x40, 
00365 };
00366 
00385 typedef CommandCost CommandProc(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text);
00386 
00393 struct Command {
00394   CommandProc *proc;
00395   byte flags;
00396 };
00397 
00411 typedef void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2);
00412 
00416 struct CommandContainer {
00417   TileIndex tile;            
00418   uint32 p1;                 
00419   uint32 p2;                 
00420   uint32 cmd;                
00421   CommandCallback *callback; 
00422   char text[80];             
00423 };
00424 
00425 #endif /* COMMAND_TYPE_H */

Generated on Thu Feb 4 17:20:23 2010 for OpenTTD by  doxygen 1.5.6