# ai_order.hpp

Go to the documentation of this file.

    00001 /* $Id: ai_order.hpp 18651 2009-12-28 12:12:57Z smatz $ */
    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
    00128   static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
    00129
    00137   static bool IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position);
    00138
    00146   static bool IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position);
    00147
    00155   static bool IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position);
    00156
    00164   static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
    00165
    00175   static bool IsCurrentOrderPartOfOrderList(VehicleID vehicle_id);
    00176
    00187   static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
    00188
    00195   static bool AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags);
    00196
    00203   static bool IsValidConditionalOrder(OrderCondition condition, CompareFunction compare);
    00204
    00212   static int32 GetOrderCount(VehicleID vehicle_id);
    00213
    00227   static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
    00228
    00242   static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
    00243
    00252   static OrderPosition GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position);
    00253
    00262   static OrderCondition GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position);
    00263
    00272   static CompareFunction GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position);
    00273
    00282   static int32 GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position);
    00283
    00294   static bool SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
    00295
    00306   static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
    00307
    00318   static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
    00319
    00330   static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
    00331
    00344   static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags);
    00345
    00356   static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
    00357
    00371   static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags);
    00372
    00384   static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
    00385
    00394   static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
    00395
    00396 #ifndef DOXYGEN_SKIP
    00397
    00400   static bool _SetOrderFlags();
    00401 #endif /* DOXYGEN_SKIP */
    00402
    00413   static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
    00414
    00429   static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
    00430
    00439   static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
    00440
    00452   static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
    00453
    00464   static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
    00465
    00472   static bool UnshareOrders(VehicleID vehicle_id);
    00473 };
    00474 DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags);
    00475
    00476 #endif /* AI_ORDER_HPP */