# ai_event_types.cpp

Go to the documentation of this file.

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