# ai_vehicle.hpp

Go to the documentation of this file.

    00001 /* $Id: ai_vehicle.hpp 22995 2011-10-04 20:22:46Z 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_VEHICLE_HPP
    00013 #define AI_VEHICLE_HPP
    00014
    00015 #include "ai_road.hpp"
    00016
    00020 class AIVehicle : public AIObject {
    00021 public:
    00023   static const char *GetClassName() { return "AIVehicle"; }
    00024
    00028   enum ErrorMessages {
    00030     ERR_VEHICLE_BASE = AIError::ERR_CAT_VEHICLE << AIError::ERR_CAT_BIT_SIZE,
    00031
    00033     ERR_VEHICLE_TOO_MANY,                   // [STR_ERROR_TOO_MANY_VEHICLES_IN_GAME]
    00034
    00036     ERR_VEHICLE_NOT_AVAILABLE,              // [STR_ERROR_AIRCRAFT_NOT_AVAILABLE, STR_ERROR_ROAD_VEHICLE_NOT_AVAILABLE, STR_ERROR_SHIP_NOT_AVAILABLE, STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE]
    00037
    00039     ERR_VEHICLE_BUILD_DISABLED,             // [STR_ERROR_CAN_T_BUY_TRAIN, STR_ERROR_CAN_T_BUY_ROAD_VEHICLE, STR_ERROR_CAN_T_BUY_SHIP, STR_ERROR_CAN_T_BUY_AIRCRAFT]
    00040
    00042     ERR_VEHICLE_WRONG_DEPOT,                // [STR_ERROR_DEPOT_WRONG_DEPOT_TYPE]
    00043
    00045     ERR_VEHICLE_CANNOT_SEND_TO_DEPOT,       // [STR_ERROR_CAN_T_SEND_TRAIN_TO_DEPOT, STR_ERROR_CAN_T_SEND_ROAD_VEHICLE_TO_DEPOT, STR_ERROR_CAN_T_SEND_SHIP_TO_DEPOT, STR_ERROR_CAN_T_SEND_AIRCRAFT_TO_HANGAR]
    00046
    00048     ERR_VEHICLE_CANNOT_START_STOP,          // [STR_ERROR_CAN_T_STOP_START_TRAIN, STR_ERROR_CAN_T_STOP_START_ROAD_VEHICLE, STR_ERROR_CAN_T_STOP_START_SHIP, STR_ERROR_CAN_T_STOP_START_AIRCRAFT]
    00049
    00051     ERR_VEHICLE_CANNOT_TURN,                // [STR_ERROR_CAN_T_MAKE_ROAD_VEHICLE_TURN, STR_ERROR_CAN_T_REVERSE_DIRECTION_TRAIN, STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE, STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE_MULTIPLE_UNITS]
    00052
    00054     ERR_VEHICLE_CANNOT_REFIT,               // [STR_ERROR_CAN_T_REFIT_TRAIN, STR_ERROR_CAN_T_REFIT_ROAD_VEHICLE, STR_ERROR_CAN_T_REFIT_SHIP, STR_ERROR_CAN_T_REFIT_AIRCRAFT]
    00055
    00057     ERR_VEHICLE_IS_DESTROYED,               // [STR_ERROR_VEHICLE_IS_DESTROYED]
    00058
    00060     ERR_VEHICLE_NOT_IN_DEPOT,               // [STR_ERROR_AIRCRAFT_MUST_BE_STOPPED_INSIDE_HANGAR, STR_ERROR_ROAD_VEHICLE_MUST_BE_STOPPED_INSIDE_DEPOT, STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT, STR_ERROR_SHIP_MUST_BE_STOPPED_INSIDE_DEPOT]
    00061
    00063     ERR_VEHICLE_IN_FLIGHT,                  // [STR_ERROR_AIRCRAFT_IS_IN_FLIGHT]
    00064
    00066     ERR_VEHICLE_NO_POWER,                   // [STR_ERROR_TRAIN_START_NO_CATENARY]
    00067
    00069     ERR_VEHICLE_TOO_LONG,                   // [STR_ERROR_TRAIN_TOO_LONG]
    00070   };
    00071
    00076   enum VehicleType {
    00077     /* Order IS important, as it now matches the internal state of the game for vehicle type */
    00078     VT_RAIL,
    00079     VT_ROAD,
    00080     VT_WATER,
    00081     VT_AIR,
    00082     VT_INVALID = 0xFF,
    00083   };
    00084
    00088   enum VehicleState {
    00089     VS_RUNNING,
    00090     VS_STOPPED,
    00091     VS_IN_DEPOT,
    00092     VS_AT_STATION,
    00093     VS_BROKEN,
    00094     VS_CRASHED,
    00095
    00096     VS_INVALID = 0xFF,
    00097   };
    00098
    00099   static const VehicleID VEHICLE_INVALID = 0xFFFFF;
    00100
    00106   static bool IsValidVehicle(VehicleID vehicle_id);
    00107
    00114   static int32 GetNumWagons(VehicleID vehicle_id);
    00115
    00126   static bool SetName(VehicleID vehicle_id, const char *name);
    00127
    00134   static char *GetName(VehicleID vehicle_id);
    00135
    00142   static TileIndex GetLocation(VehicleID vehicle_id);
    00143
    00150   static EngineID GetEngineType(VehicleID vehicle_id);
    00151
    00160   static EngineID GetWagonEngineType(VehicleID vehicle_id, int wagon);
    00161
    00168   static int32 GetUnitNumber(VehicleID vehicle_id);
    00169
    00177   static int32 GetAge(VehicleID vehicle_id);
    00178
    00188   static int32 GetWagonAge(VehicleID vehicle_id, int wagon);
    00189
    00197   static int32 GetMaxAge(VehicleID vehicle_id);
    00198
    00206   static int32 GetAgeLeft(VehicleID vehicle_id);
    00207
    00217   static int32 GetCurrentSpeed(VehicleID vehicle_id);
    00218
    00225   static VehicleState GetState(VehicleID vehicle_id);
    00226
    00236   static Money GetRunningCost(VehicleID vehicle_id);
    00237
    00244   static Money GetProfitThisYear(VehicleID vehicle_id);
    00245
    00252   static Money GetProfitLastYear(VehicleID vehicle_id);
    00253
    00254
    00262   static Money GetCurrentValue(VehicleID vehicle_id);
    00263
    00270   static AIVehicle::VehicleType GetVehicleType(VehicleID vehicle_id);
    00271
    00279   static AIRoad::RoadType GetRoadType(VehicleID vehicle_id);
    00280
    00287   static bool IsInDepot(VehicleID vehicle_id);
    00288
    00295   static bool IsStoppedInDepot(VehicleID vehicle_id);
    00296
    00314   static VehicleID BuildVehicle(TileIndex depot, EngineID engine_id);
    00315
    00330   static VehicleID CloneVehicle(TileIndex depot, VehicleID vehicle_id, bool share_orders);
    00331
    00345   static bool MoveWagon(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon);
    00346
    00360   static bool MoveWagonChain(VehicleID source_vehicle_id, int source_wagon, int dest_vehicle_id, int dest_wagon);
    00361
    00372   static int GetRefitCapacity(VehicleID vehicle_id, CargoID cargo);
    00373
    00387   static bool RefitVehicle(VehicleID vehicle_id, CargoID cargo);
    00388
    00399   static bool SellVehicle(VehicleID vehicle_id);
    00400
    00413   static bool SellWagon(VehicleID vehicle_id, int wagon);
    00414
    00427   static bool SellWagonChain(VehicleID vehicle_id, int wagon);
    00428
    00437   static bool SendVehicleToDepot(VehicleID vehicle_id);
    00438
    00447   static bool SendVehicleToDepotForServicing(VehicleID vehicle_id);
    00448
    00458   static bool StartStopVehicle(VehicleID vehicle_id);
    00459
    00469   static bool ReverseVehicle(VehicleID vehicle_id);
    00470
    00479   static int32 GetCapacity(VehicleID vehicle_id, CargoID cargo);
    00480
    00488   static int GetLength(VehicleID vehicle_id);
    00489
    00498   static int32 GetCargoLoad(VehicleID vehicle_id, CargoID cargo);
    00499
    00505   static GroupID GetGroupID(VehicleID vehicle_id);
    00506
    00514   static bool IsArticulated(VehicleID vehicle_id);
    00515
    00522   static bool HasSharedOrders(VehicleID vehicle_id);
    00523
    00530   static int GetReliability(VehicleID vehicle_id);
    00531
    00532 private:
    00536   static bool _SellWagonInternal(VehicleID vehicle_id, int wagon, bool sell_attached_wagons);
    00537
    00541   static bool _MoveWagonInternal(VehicleID source_vehicle_id, int source_wagon, bool move_attached_wagons, int dest_vehicle_id, int dest_wagon);
    00542 };
    00543
    00544 #endif /* AI_VEHICLE_HPP */