# ai_event_types.cpp

Go to the documentation of this file.

    00001 /* $Id: ai_event_types.cpp 15541 2009-02-21 12:52:41Z frosch $ */
    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   const Engine *e = ::GetEngine(engine);
    00025   if (!e->CanCarryCargo()) return CT_INVALID;
    00026   return e->GetDefaultCargoType();
    00027 }
    00028
    00029 int32 AIEventEnginePreview::GetCapacity()
    00030 {
    00031   switch (::GetEngine(engine)->type) {
    00032     case VEH_ROAD:
    00033     case VEH_TRAIN: {
    00034       uint16 *capacities = GetCapacityOfArticulatedParts(engine, ::GetEngine(engine)->type);
    00035       for (CargoID c = 0; c < NUM_CARGO; c++) {
    00036         if (capacities[c] == 0) continue;
    00037         return capacities[c];
    00038       }
    00039       return -1;
    00040     } break;
    00041
    00042     case VEH_SHIP: {
    00043       const ShipVehicleInfo *vi = ::ShipVehInfo(engine);
    00044       return vi->capacity;
    00045     } break;
    00046
    00047     case VEH_AIRCRAFT: {
    00048       const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine);
    00049       return vi->passenger_capacity;
    00050     } break;
    00051
    00052     default: NOT_REACHED();
    00053   }
    00054 }
    00055
    00056 int32 AIEventEnginePreview::GetMaxSpeed()
    00057 {
    00058   const Engine *e = ::GetEngine(engine);
    00059   int32 max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
    00060   if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
    00061   return max_speed;
    00062 }
    00063
    00064 Money AIEventEnginePreview::GetPrice()
    00065 {
    00066   return ::GetEngine(engine)->GetCost();
    00067 }
    00068
    00069 Money AIEventEnginePreview::GetRunningCost()
    00070 {
    00071   return ::GetEngine(engine)->GetRunningCost();
    00072 }
    00073
    00074 AIVehicle::VehicleType AIEventEnginePreview::GetVehicleType()
    00075 {
    00076   switch (::GetEngine(engine)->type) {
    00077     case VEH_ROAD:     return AIVehicle::VT_ROAD;
    00078     case VEH_TRAIN:    return AIVehicle::VT_RAIL;
    00079     case VEH_SHIP:     return AIVehicle::VT_WATER;
    00080     case VEH_AIRCRAFT: return AIVehicle::VT_AIR;
    00081     default: NOT_REACHED();
    00082   }
    00083 }
    00084
    00085 bool AIEventEnginePreview::AcceptPreview()
    00086 {
    00087   return AIObject::DoCommand(0, engine, 0, CMD_WANT_ENGINE_PREVIEW);
    00088 }