ai_order.hpp

Go to the documentation of this file.
00001 /* $Id: ai_order.hpp 19017 2010-02-05 16:11:23Z 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 AI_ORDER_HPP
00013 #define AI_ORDER_HPP
00014 
00015 #include "ai_object.hpp"
00016 #include "ai_error.hpp"
00017 
00021 class AIOrder : public AIObject {
00022 public:
00023   static const char *GetClassName() { return "AIOrder"; }
00024 
00028   enum ErrorMessages {
00030     ERR_ORDER_BASE = AIError::ERR_CAT_ORDER << AIError::ERR_CAT_BIT_SIZE,
00031 
00033     ERR_ORDER_TOO_MANY,                                  // [STR_ERROR_NO_MORE_SPACE_FOR_ORDERS]
00034 
00036     ERR_ORDER_TOO_FAR_AWAY_FROM_PREVIOUS_DESTINATION,    // [STR_ERROR_TOO_FAR_FROM_PREVIOUS_DESTINATION]
00037   };
00038 
00042   enum AIOrderFlags {
00044     AIOF_NONE              = 0,
00045 
00047     AIOF_NON_STOP_INTERMEDIATE = 1 << 0,
00049     AIOF_NON_STOP_DESTINATION  = 1 << 1,
00050 
00052     AIOF_UNLOAD            = 1 << 2,
00054     AIOF_TRANSFER          = 1 << 3,
00056     AIOF_NO_UNLOAD         = 1 << 4,
00057 
00059     AIOF_FULL_LOAD         = 2 << 5,
00061     AIOF_FULL_LOAD_ANY     = 3 << 5,
00063     AIOF_NO_LOAD           = 1 << 7,
00064 
00066     AIOF_SERVICE_IF_NEEDED = 1 << 2,
00068     AIOF_STOP_IN_DEPOT     = 1 << 3,
00070     AIOF_GOTO_NEAREST_DEPOT = 1 << 8,
00071 
00073     AIOF_NON_STOP_FLAGS    = AIOF_NON_STOP_INTERMEDIATE | AIOF_NON_STOP_DESTINATION,
00075     AIOF_UNLOAD_FLAGS      = AIOF_TRANSFER | AIOF_UNLOAD | AIOF_NO_UNLOAD,
00077     AIOF_LOAD_FLAGS        = AIOF_FULL_LOAD | AIOF_FULL_LOAD_ANY | AIOF_NO_LOAD,
00079     AIOF_DEPOT_FLAGS       = AIOF_SERVICE_IF_NEEDED | AIOF_STOP_IN_DEPOT | AIOF_GOTO_NEAREST_DEPOT,
00080 
00082     AIOF_INVALID           = 0xFFFF,
00083   };
00084 
00088   enum OrderCondition {
00089     /* Order _is_ important, as it's based on OrderConditionVariable in order_type.h. */
00090     OC_LOAD_PERCENTAGE,  
00091     OC_RELIABILITY,      
00092     OC_MAX_SPEED,        
00093     OC_AGE,              
00094     OC_REQUIRES_SERVICE, 
00095     OC_UNCONDITIONALLY,  
00096     OC_INVALID = -1,     
00097   };
00098 
00102   enum CompareFunction {
00103     /* Order _is_ important, as it's based on OrderConditionComparator in order_type.h. */
00104     CF_EQUALS,       
00105     CF_NOT_EQUALS,   
00106     CF_LESS_THAN,    
00107     CF_LESS_EQUALS,  
00108     CF_MORE_THAN,    
00109     CF_MORE_EQUALS,  
00110     CF_IS_TRUE,      
00111     CF_IS_FALSE,     
00112     CF_INVALID = -1, 
00113   };
00114 
00116   enum OrderPosition {
00117     ORDER_CURRENT = 0xFF, 
00118     ORDER_INVALID = -1,   
00119   };
00120 
00122   enum StopLocation {
00123     STOPLOCATION_NEAR,         
00124     STOPLOCATION_MIDDLE,       
00125     STOPLOCATION_FAR,          
00126     STOPLOCATION_INVALID = -1, 
00127   };
00128 
00136   static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
00137 
00145   static bool IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position);
00146 
00154   static bool IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position);
00155 
00163   static bool IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position);
00164 
00172   static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
00173 
00183   static bool IsCurrentOrderPartOfOrderList(VehicleID vehicle_id);
00184 
00195   static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
00196 
00203   static bool AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags);
00204 
00211   static bool IsValidConditionalOrder(OrderCondition condition, CompareFunction compare);
00212 
00220   static int32 GetOrderCount(VehicleID vehicle_id);
00221 
00235   static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
00236 
00250   static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
00251 
00260   static OrderPosition GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position);
00261 
00270   static OrderCondition GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position);
00271 
00280   static CompareFunction GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position);
00281 
00290   static int32 GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position);
00291 
00301   static StopLocation GetStopLocation(VehicleID vehicle_id, OrderPosition order_position);
00302 
00313   static bool SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00314 
00325   static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
00326 
00337   static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
00338 
00349   static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
00350 
00362   static bool SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location);
00363 
00376   static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags);
00377 
00388   static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
00389 
00403   static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags);
00404 
00416   static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
00417 
00426   static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
00427 
00428 #ifndef DOXYGEN_SKIP
00429 
00432   static bool _SetOrderFlags();
00433 #endif /* DOXYGEN_SKIP */
00434 
00445   static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
00446 
00461   static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
00462 
00471   static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
00472 
00484   static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00485 
00496   static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
00497 
00504   static bool UnshareOrders(VehicleID vehicle_id);
00505 };
00506 DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags);
00507 
00508 #endif /* AI_ORDER_HPP */

Generated on Tue Sep 14 17:06:46 2010 for OpenTTD by  doxygen 1.6.1