# ai_vehicle.hpp

Go to the documentation of this file.

    00001 /* $Id: ai_vehicle.hpp 16246 2009-05-06 22:31:52Z rubidium $ */
    00002
    00005 #ifndef AI_VEHICLE_HPP
    00006 #define AI_VEHICLE_HPP
    00007
    00008 #include "ai_object.hpp"
    00009 #include "ai_error.hpp"
    00010 #include "ai_road.hpp"
    00011 #include "ai_order.hpp"
    00012
    00016 class AIVehicle : public AIObject {
    00017 public:
    00018   static const char *GetClassName() { return "AIVehicle"; }
    00019
    00023   enum ErrorMessages {
    00025     ERR_VEHICLE_BASE = AIError::ERR_CAT_VEHICLE << AIError::ERR_CAT_BIT_SIZE,
    00026
    00028     ERR_VEHICLE_TOO_MANY,                   // [STR_00E1_TOO_MANY_VEHICLES_IN_GAME]
    00029
    00031     ERR_VEHICLE_NOT_AVAILABLE,              // [STR_AIRCRAFT_NOT_AVAILABLE, STR_ROAD_VEHICLE_NOT_AVAILABLE, STR_SHIP_NOT_AVAILABLE, STR_RAIL_VEHICLE_NOT_AVAILABLE]
    00032
    00034     ERR_VEHICLE_BUILD_DISABLED,             // [STR_A008_CAN_T_BUILD_AIRCRAFT, STR_980D_CAN_T_BUILD_SHIP, STR_9009_CAN_T_BUILD_ROAD_VEHICLE, STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE]
    00035
    00037     ERR_VEHICLE_WRONG_DEPOT,                // [STR_DEPOT_WRONG_DEPOT_TYPE]
    00038
    00040     ERR_VEHICLE_CANNOT_SEND_TO_DEPOT,       // [STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT, STR_9018_CAN_T_SEND_VEHICLE_TO_DEPOT, STR_9819_CAN_T_SEND_SHIP_TO_DEPOT, STR_A012_CAN_T_SEND_AIRCRAFT_TO]
    00041
    00043     ERR_VEHICLE_CANNOT_START_STOP,          // [STR_883B_CAN_T_STOP_START_TRAIN, STR_9015_CAN_T_STOP_START_ROAD_VEHICLE, STR_9818_CAN_T_STOP_START_SHIP, STR_A016_CAN_T_STOP_START_AIRCRAFT]
    00044
    00046     ERR_VEHICLE_CANNOT_TURN,                // [STR_8869_CAN_T_REVERSE_DIRECTION, STR_9033_CAN_T_MAKE_VEHICLE_TURN]
    00047
    00049     ERR_VEHICLE_CANNOT_REFIT,               // [STR_RAIL_CAN_T_REFIT_VEHICLE, STR_REFIT_ROAD_VEHICLE_CAN_T, STR_9841_CAN_T_REFIT_SHIP, STR_A042_CAN_T_REFIT_AIRCRAFT]
    00050
    00052     ERR_VEHICLE_IS_DESTROYED,               // [STR_CAN_T_REFIT_DESTROYED_VEHICLE, STR_CAN_T_SELL_DESTROYED_VEHICLE]
    00053
    00055     ERR_VEHICLE_NOT_IN_DEPOT,               // [STR_A01B_AIRCRAFT_MUST_BE_STOPPED, STR_9013_MUST_BE_STOPPED_INSIDE, STR_TRAIN_MUST_BE_STOPPED, STR_980B_SHIP_MUST_BE_STOPPED_IN]
    00056
    00058     ERR_VEHICLE_IN_FLIGHT,                  // [STR_A017_AIRCRAFT_IS_IN_FLIGHT]
    00059
    00061     ERR_VEHCILE_NO_POWER,                   // [STR_TRAIN_START_NO_CATENARY]
    00062
    00063   };
    00064
    00069   enum VehicleType {
    00070     /* Order IS important, as it now matches the internal state of the game for vehicle type */
    00071     VT_RAIL,
    00072     VT_ROAD,
    00073     VT_WATER,
    00074     VT_AIR,
    00075     VT_INVALID = 0xFF,
    00076
    00077 #ifdef DEFINE_SCRIPT_FILES
    00078     VEHICLE_INVALID = -1,
    00079 #endif /* DEFINE_SCRIPT_FILES */
    00080   };
    00081
    00085   enum VehicleState {
    00086     VS_RUNNING,
    00087     VS_STOPPED,
    00088     VS_IN_DEPOT,
    00089     VS_AT_STATION,
    00090     VS_BROKEN,
    00091     VS_CRASHED,
    00092
    00093     VS_INVALID = 0xFF,
    00094   };
    00095
    00101   static bool IsValidVehicle(VehicleID vehicle_id);
    00102
    00109   static int32 GetNumWagons(VehicleID vehicle_id);
    00110
    00121   static bool SetName(VehicleID vehicle_id, const char *name);
    00122
    00129   static char *GetName(VehicleID vehicle_id);
    00130
    00137   static TileIndex GetLocation(VehicleID vehicle_id);
    00138
    00145   static EngineID GetEngineType(VehicleID vehicle_id);
    00146
    00155   static EngineID GetWagonEngineType(VehicleID vehicle_id, int wagon);
    00156
    00163   static int32 GetUnitNumber(VehicleID vehicle_id);
    00164
    00172   static int32 GetAge(VehicleID vehicle_id);
    00173
    00183   static int32 GetWagonAge(VehicleID vehicle_id, int wagon);
    00184
    00192   static int32 GetMaxAge(VehicleID vehicle_id);
    00193
    00201   static int32 GetAgeLeft(VehicleID vehicle_id);
    00202
    00212   static int32 GetCurrentSpeed(VehicleID vehicle_id);
    00213
    00220   static VehicleState GetState(VehicleID vehicle_id);
    00221
    00231   static Money GetRunningCost(VehicleID vehicle_id);
    00232
    00239   static Money GetProfitThisYear(VehicleID vehicle_id);
    00240
    00247   static Money GetProfitLastYear(VehicleID vehicle_id);
    00248
    00249
    00257   static Money GetCurrentValue(VehicleID vehicle_id);
    00258
    00265   static AIVehicle::VehicleType GetVehicleType(VehicleID vehicle_id);
    00266
    00274   static AIRoad::RoadType GetRoadType(VehicleID vehicle_id);
    00275
    00282   static bool IsInDepot(VehicleID vehicle_id);
    00283
    00290   static bool IsStoppedInDepot(VehicleID vehicle_id);
    00291
    00309   static VehicleID BuildVehicle(TileIndex depot, EngineID engine_id);
    00310
    00325   static VehicleID CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders);
    00326
    00340   static bool MoveWagon(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon);
    00341
    00355   static bool MoveWagonChain(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon);
    00356
    00367   static int GetRefitCapacity(VehicleID vehicle_id, CargoID cargo);
    00368
    00382   static bool RefitVehicle(VehicleID vehicle_id, CargoID cargo);
    00383
    00394   static bool SellVehicle(VehicleID vehicle_id);
    00395
    00408   static bool SellWagon(VehicleID vehicle_id, int wagon);
    00409
    00422   static bool SellWagonChain(VehicleID vehicle_id, int wagon);
    00423
    00432   static bool SendVehicleToDepot(VehicleID vehicle_id);
    00433
    00442   static bool SendVehicleToDepotForServicing(VehicleID vehicle_id);
    00443
    00453   static bool StartStopVehicle(VehicleID vehicle_id);
    00454
    00462   static bool SkipToVehicleOrder(VehicleID vehicle_id, AIOrder::OrderPosition order_position);
    00463
    00473   static bool ReverseVehicle(VehicleID vehicle_id);
    00474
    00483   static int32 GetCapacity(VehicleID vehicle_id, CargoID cargo);
    00484
    00492   static int GetLength(VehicleID vehicle_id);
    00493
    00502   static int32 GetCargoLoad(VehicleID vehicle_id, CargoID cargo);
    00503
    00509   static GroupID GetGroupID(VehicleID vehicle_id);
    00510
    00518   static bool IsArticulated(VehicleID vehicle_id);
    00519
    00526   static bool HasSharedOrders(VehicleID vehicle_id);
    00527
    00528 private:
    00532   static bool _SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons);
    00533
    00537   static bool _MoveWagonInternal(VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon);
    00538 };
    00539
    00540 #endif /* AI_VEHICLE_HPP */