# ai_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 AI_ORDER_HPP
    00013 #define AI_ORDER_HPP
    00014
    00015 #include "ai_error.hpp"
    00016
    00020 class AIOrder : public AIObject {
    00021 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
    00122   enum OrderPosition {
    00123     ORDER_CURRENT = 0xFF,
    00124     ORDER_INVALID = -1,
    00125   };
    00126
    00128   enum StopLocation {
    00129     STOPLOCATION_NEAR,
    00130     STOPLOCATION_MIDDLE,
    00131     STOPLOCATION_FAR,
    00132     STOPLOCATION_INVALID = -1,
    00133   };
    00134
    00142   static bool IsValidVehicleOrder(VehicleID vehicle_id, OrderPosition order_position);
    00143
    00151   static bool IsGotoStationOrder(VehicleID vehicle_id, OrderPosition order_position);
    00152
    00160   static bool IsGotoDepotOrder(VehicleID vehicle_id, OrderPosition order_position);
    00161
    00169   static bool IsGotoWaypointOrder(VehicleID vehicle_id, OrderPosition order_position);
    00170
    00178   static bool IsConditionalOrder(VehicleID vehicle_id, OrderPosition order_position);
    00179
    00190   static bool IsVoidOrder(VehicleID vehicle_id, OrderPosition order_position);
    00191
    00201   static bool IsCurrentOrderPartOfOrderList(VehicleID vehicle_id);
    00202
    00213   static OrderPosition ResolveOrderPosition(VehicleID vehicle_id, OrderPosition order_position);
    00214
    00221   static bool AreOrderFlagsValid(TileIndex destination, AIOrderFlags order_flags);
    00222
    00229   static bool IsValidConditionalOrder(OrderCondition condition, CompareFunction compare);
    00230
    00238   static int32 GetOrderCount(VehicleID vehicle_id);
    00239
    00253   static TileIndex GetOrderDestination(VehicleID vehicle_id, OrderPosition order_position);
    00254
    00268   static AIOrderFlags GetOrderFlags(VehicleID vehicle_id, OrderPosition order_position);
    00269
    00278   static OrderPosition GetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position);
    00279
    00288   static OrderCondition GetOrderCondition(VehicleID vehicle_id, OrderPosition order_position);
    00289
    00298   static CompareFunction GetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position);
    00299
    00308   static int32 GetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position);
    00309
    00319   static StopLocation GetStopLocation(VehicleID vehicle_id, OrderPosition order_position);
    00320
    00331   static bool SetOrderJumpTo(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
    00332
    00343   static bool SetOrderCondition(VehicleID vehicle_id, OrderPosition order_position, OrderCondition condition);
    00344
    00355   static bool SetOrderCompareFunction(VehicleID vehicle_id, OrderPosition order_position, CompareFunction compare);
    00356
    00367   static bool SetOrderCompareValue(VehicleID vehicle_id, OrderPosition order_position, int32 value);
    00368
    00380   static bool SetStopLocation(VehicleID vehicle_id, OrderPosition order_position, StopLocation stop_location);
    00381
    00394   static bool AppendOrder(VehicleID vehicle_id, TileIndex destination, AIOrderFlags order_flags);
    00395
    00406   static bool AppendConditionalOrder(VehicleID vehicle_id, OrderPosition jump_to);
    00407
    00421   static bool InsertOrder(VehicleID vehicle_id, OrderPosition order_position, TileIndex destination, AIOrderFlags order_flags);
    00422
    00434   static bool InsertConditionalOrder(VehicleID vehicle_id, OrderPosition order_position, OrderPosition jump_to);
    00435
    00444   static bool RemoveOrder(VehicleID vehicle_id, OrderPosition order_position);
    00445
    00446 #ifndef DOXYGEN_SKIP
    00447
    00450   static bool _SetOrderFlags();
    00451 #endif /* DOXYGEN_SKIP */
    00452
    00464   static bool SetOrderFlags(VehicleID vehicle_id, OrderPosition order_position, AIOrderFlags order_flags);
    00465
    00480   static bool MoveOrder(VehicleID vehicle_id, OrderPosition order_position_move, OrderPosition order_position_target);
    00481
    00490   static bool SkipToOrder(VehicleID vehicle_id, OrderPosition next_order);
    00491
    00503   static bool CopyOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
    00504
    00515   static bool ShareOrders(VehicleID vehicle_id, VehicleID main_vehicle_id);
    00516
    00523   static bool UnshareOrders(VehicleID vehicle_id);
    00524 };
    00525 DECLARE_ENUM_AS_BIT_SET(AIOrder::AIOrderFlags)
    00526
    00527 #endif /* AI_ORDER_HPP */