# ai_event_types.cpp

Go to the documentation of this file.

    00001 /* $Id: ai_event_types.cpp 15765 2009-03-18 19:50:34Z rubidium $ */
    00002
    00005 #include "ai_event_types.hpp"
    00006 #include "../../command_type.h"
    00007 #include "../../strings_func.h"
    00008 #include "../../settings_type.h"
    00009 #include "../../rail.h"
    00010 #include "../../engine_base.h"
    00011 #include "../../articulated_vehicles.h"
    00012 #include "table/strings.h"
    00013
    00014 char *AIEventEnginePreview::GetName()
    00015 {
    00016   static const int len = 64;
    00017   char *engine_name = MallocT<char>(len);
    00018
    00019   ::SetDParam(0, engine);
    00020   ::GetString(engine_name, STR_ENGINE_NAME, &engine_name[len - 1]);
    00021   return engine_name;
    00022 }
    00023
    00024 CargoID AIEventEnginePreview::GetCargoType()
    00025 {
    00026   const Engine *e = ::GetEngine(engine);
    00027   if (!e->CanCarryCargo()) return CT_INVALID;
    00028   return e->GetDefaultCargoType();
    00029 }
    00030
    00031 int32 AIEventEnginePreview::GetCapacity()
    00032 {
    00033   const Engine *e = ::GetEngine(engine);
    00034   switch (e->type) {
    00035     case VEH_ROAD:
    00036     case VEH_TRAIN: {
    00037       uint16 *capacities = GetCapacityOfArticulatedParts(engine, e->type);
    00038       for (CargoID c = 0; c < NUM_CARGO; c++) {
    00039         if (capacities[c] == 0) continue;
    00040         return capacities[c];
    00041       }
    00042       return -1;
    00043     } break;
    00044
    00045     case VEH_SHIP:
    00046     case VEH_AIRCRAFT:
    00047       return e->GetDisplayDefaultCapacity();
    00048       break;
    00049
    00050     default: NOT_REACHED();
    00051   }
    00052 }
    00053
    00054 int32 AIEventEnginePreview::GetMaxSpeed()
    00055 {
    00056   const Engine *e = ::GetEngine(engine);
    00057   int32 max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
    00058   if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
    00059   return max_speed;
    00060 }
    00061
    00062 Money AIEventEnginePreview::GetPrice()
    00063 {
    00064   return ::GetEngine(engine)->GetCost();
    00065 }
    00066
    00067 Money AIEventEnginePreview::GetRunningCost()
    00068 {
    00069   return ::GetEngine(engine)->GetRunningCost();
    00070 }
    00071
    00072 AIVehicle::VehicleType AIEventEnginePreview::GetVehicleType()
    00073 {
    00074   switch (::GetEngine(engine)->type) {
    00075     case VEH_ROAD:     return AIVehicle::VT_ROAD;
    00076     case VEH_TRAIN:    return AIVehicle::VT_RAIL;
    00077     case VEH_SHIP:     return AIVehicle::VT_WATER;
    00078     case VEH_AIRCRAFT: return AIVehicle::VT_AIR;
    00079     default: NOT_REACHED();
    00080   }
    00081 }
    00082
    00083 bool AIEventEnginePreview::AcceptPreview()
    00084 {
    00085   return AIObject::DoCommand(0, engine, 0, CMD_WANT_ENGINE_PREVIEW);
    00086 }