# ai_event_types.cpp

Go to the documentation of this file.

    00001 /* $Id: ai_event_types.cpp 15487 2009-02-14 21:13:45Z yexo $ */
    00002
    00005 #include "ai_event_types.hpp"
    00006 #include "../../strings_func.h"
    00007 #include "../../settings_type.h"
    00008 #include "../../aircraft.h"
    00009 #include "../../articulated_vehicles.h"
    00010 #include "table/strings.h"
    00011
    00012 char *AIEventEnginePreview::GetName()
    00013 {
    00014   static const int len = 64;
    00015   char *engine_name = MallocT<char>(len);
    00016
    00017   ::SetDParam(0, engine);
    00018   ::GetString(engine_name, STR_ENGINE_NAME, &engine_name[len - 1]);
    00019   return engine_name;
    00020 }
    00021
    00022 CargoID AIEventEnginePreview::GetCargoType()
    00023 {
    00024   switch (::GetEngine(engine)->type) {
    00025     case VEH_ROAD: {
    00026       const RoadVehicleInfo *vi = ::RoadVehInfo(engine);
    00027       return vi->cargo_type;
    00028     } break;
    00029
    00030     case VEH_TRAIN: {
    00031       const RailVehicleInfo *vi = ::RailVehInfo(engine);
    00032       return vi->cargo_type;
    00033     } break;
    00034
    00035     case VEH_SHIP: {
    00036       const ShipVehicleInfo *vi = ::ShipVehInfo(engine);
    00037       return vi->cargo_type;
    00038     } break;
    00039
    00040     case VEH_AIRCRAFT: {
    00041       return CT_PASSENGERS;
    00042     } break;
    00043
    00044     default: NOT_REACHED();
    00045   }
    00046 }
    00047
    00048 int32 AIEventEnginePreview::GetCapacity()
    00049 {
    00050   switch (::GetEngine(engine)->type) {
    00051     case VEH_ROAD:
    00052     case VEH_TRAIN: {
    00053       uint16 *capacities = GetCapacityOfArticulatedParts(engine, ::GetEngine(engine)->type);
    00054       for (CargoID c = 0; c < NUM_CARGO; c++) {
    00055         if (capacities[c] == 0) continue;
    00056         return capacities[c];
    00057       }
    00058       return -1;
    00059     } break;
    00060
    00061     case VEH_SHIP: {
    00062       const ShipVehicleInfo *vi = ::ShipVehInfo(engine);
    00063       return vi->capacity;
    00064     } break;
    00065
    00066     case VEH_AIRCRAFT: {
    00067       const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine);
    00068       return vi->passenger_capacity;
    00069     } break;
    00070
    00071     default: NOT_REACHED();
    00072   }
    00073 }
    00074
    00075 int32 AIEventEnginePreview::GetMaxSpeed()
    00076 {
    00077   const Engine *e = ::GetEngine(engine);
    00078   int32 max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
    00079   if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
    00080   return max_speed;
    00081 }
    00082
    00083 Money AIEventEnginePreview::GetPrice()
    00084 {
    00085   return ::GetEngine(engine)->GetCost();
    00086 }
    00087
    00088 Money AIEventEnginePreview::GetRunningCost()
    00089 {
    00090   return ::GetEngine(engine)->GetRunningCost();
    00091 }
    00092
    00093 AIVehicle::VehicleType AIEventEnginePreview::GetVehicleType()
    00094 {
    00095   switch (::GetEngine(engine)->type) {
    00096     case VEH_ROAD:     return AIVehicle::VT_ROAD;
    00097     case VEH_TRAIN:    return AIVehicle::VT_RAIL;
    00098     case VEH_SHIP:     return AIVehicle::VT_WATER;
    00099     case VEH_AIRCRAFT: return AIVehicle::VT_AIR;
    00100     default: NOT_REACHED();
    00101   }
    00102 }
    00103
    00104 bool AIEventEnginePreview::AcceptPreview()
    00105 {
    00106   return AIObject::DoCommand(0, engine, 0, CMD_WANT_ENGINE_PREVIEW);
    00107 }