script_order.hpp

Go to the documentation of this file.
00001 /* $Id$ */
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 SCRIPT_ORDER_HPP
00013 #define SCRIPT_ORDER_HPP
00014 
00015 #include "script_error.hpp"
00016 
00021 class ScriptOrder : public ScriptObject {
00022 public:
00026   enum ErrorMessages {
00028     ERR_ORDER_BASE = ScriptError::ERR_CAT_ORDER << ScriptError::ERR_CAT_BIT_SIZE,
00029 
00031     ERR_ORDER_TOO_MANY,                                  // [STR_ERROR_NO_MORE_SPACE_FOR_ORDERS]
00032 
00034     ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION,    // [STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION]
00035   };
00036 
00040   enum ScriptOrderFlags {
00042     AIOF_NONE              = 0,
00043 
00045     AIOF_NON_STOP_INTERMEDIATE = 1 << 0,
00047     AIOF_NON_STOP_DESTINATION  = 1 << 1,
00048 
00050     AIOF_UNLOAD            = 1 << 2,
00052     AIOF_TRANSFER          = 1 << 3,
00054     AIOF_NO_UNLOAD         = 1 << 4,
00055 
00057     AIOF_FULL_LOAD         = 2 << 5,
00059     AIOF_FULL_LOAD_ANY     = 3 << 5,
00061     AIOF_NO_LOAD           = 1 << 7,
00062 
00064     AIOF_SERVICE_IF_NEEDED = 1 << 2,
00066     AIOF_STOP_IN_DEPOT     = 1 << 3,
00068     AIOF_GOTO_NEAREST_DEPOT = 1 << 8,
00069 
00071     AIOF_NON_STOP_FLAGS    = AIOF_NON_STOP_INTERMEDIATE | AIOF_NON_STOP_DESTINATION,
00073     AIOF_UNLOAD_FLAGS      = AIOF_TRANSFER | AIOF_UNLOAD | AIOF_NO_UNLOAD,
00075     AIOF_LOAD_FLAGS        = AIOF_FULL_LOAD | AIOF_FULL_LOAD_ANY | AIOF_NO_LOAD,
00077     AIOF_DEPOT_FLAGS       = AIOF_SERVICE_IF_NEEDED | AIOF_STOP_IN_DEPOT | AIOF_GOTO_NEAREST_DEPOT,
00078 
00080     AIOF_INVALID           = 0xFFFF,
00081   };
00082 
00086   enum OrderCondition {
00087     /* Order _is_ important, as it's based on OrderConditionVariable in order_type.h. */
00088     OC_LOAD_PERCENTAGE,    
00089     OC_RELIABILITY,        
00090     OC_MAX_SPEED,          
00091     OC_AGE,                
00092     OC_REQUIRES_SERVICE,   
00093     OC_UNCONDITIONALLY,    
00094     OC_REMAINING_LIFETIME, 
00095     OC_INVALID = -1,       
00096   };
00097 
00101   enum CompareFunction {
00102     /* Order _is_ important, as it's based on OrderConditionComparator in order_type.h. */
00103     CF_EQUALS,       
00104     CF_NOT_EQUALS,   
00105     CF_LESS_THAN,    
00106     CF_LESS_EQUALS,  
00107     CF_MORE_THAN,    
00108     CF_MORE_EQUALS,  
00109     CF_IS_TRUE,      
00110     CF_IS_FALSE,     
00111     CF_INVALID = -1, 
00112   };
00113 
00121   enum OrderPosition {
00122     ORDER_CURRENT = 0xFF, 
00123     ORDER_INVALID = -1,   
00124   };
00125 
00127   enum StopLocation {
00128     STOPLOCATION_NEAR,         
00129     STOPLOCATION_MIDDLE,       
00130     STOPLOCATION_FAR,          
00131     STOPLOCATION_INVALID = -1, 
00132   };
00133 
00141   static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
00142 
00150   static bool IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position);
00151 
00159   static bool IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position);
00160 
00168   static bool IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position);
00169 
00177   static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
00178 
00189   static bool IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position);
00190 
00198   static bool IsRefitOrder(VehicleID vehicle_id, OrderPosition order_position);
00199 
00209   static bool IsCurrentOrderPartOfOrderList(VehicleID vehicle_id);
00210 
00221   static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
00222 
00229   static bool AreOrderFlagsValid(TileIndex destination, ScriptOrderFlags order_flags);
00230 
00237   static bool IsValidConditionalOrder(OrderCondition condition, CompareFunction compare);
00238 
00246   static int32 GetOrderCount(VehicleID vehicle_id);
00247 
00261   static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
00262 
00276   static ScriptOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
00277 
00286   static OrderPosition GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position);
00287 
00296   static OrderCondition GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position);
00297 
00306   static CompareFunction GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position);
00307 
00316   static int32 GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position);
00317 
00327   static StopLocation GetStopLocation(VehicleID vehicle_id, OrderPosition order_position);
00328 
00342   static CargoID GetOrderRefit(VehicleID vehicle_id, OrderPosition order_position);
00343 
00354   static bool SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00355 
00366   static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
00367 
00378   static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
00379 
00390   static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
00391 
00403   static bool SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location);
00404 
00415   static bool SetOrderRefit(VehicleID vehicle_id, OrderPosition order_position, CargoID refit_cargo);
00416 
00429   static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, ScriptOrderFlags order_flags);
00430 
00441   static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
00442 
00456   static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, ScriptOrderFlags order_flags);
00457 
00469   static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00470 
00479   static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
00480 
00485   static bool _SetOrderFlags();
00486 
00498   static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, ScriptOrderFlags order_flags);
00499 
00514   static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
00515 
00524   static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
00525 
00537   static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00538 
00549   static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00550 
00557   static bool UnshareOrders(VehicleID vehicle_id);
00558 };
00559 DECLARE_ENUM_AS_BIT_SET(ScriptOrder::ScriptOrderFlags)
00560 
00561 #endif /* SCRIPT_ORDER_HPP */