2009-01-12 18:11:45 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/** @file ai_event_types.cpp Implementation of all EventTypes. */
|
|
|
|
|
|
|
|
#include "ai_event_types.hpp"
|
2009-04-26 01:51:15 +02:00
|
|
|
#include "ai_vehicle.hpp"
|
2009-03-18 20:32:13 +01:00
|
|
|
#include "../../command_type.h"
|
2009-01-12 18:11:45 +01:00
|
|
|
#include "../../strings_func.h"
|
|
|
|
#include "../../settings_type.h"
|
2009-03-18 20:32:13 +01:00
|
|
|
#include "../../rail.h"
|
|
|
|
#include "../../engine_base.h"
|
2009-01-12 18:11:45 +01:00
|
|
|
#include "../../articulated_vehicles.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2009-01-17 16:31:30 +01:00
|
|
|
char *AIEventEnginePreview::GetName()
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
|
|
|
static const int len = 64;
|
|
|
|
char *engine_name = MallocT<char>(len);
|
|
|
|
|
|
|
|
::SetDParam(0, engine);
|
|
|
|
::GetString(engine_name, STR_ENGINE_NAME, &engine_name[len - 1]);
|
|
|
|
return engine_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
CargoID AIEventEnginePreview::GetCargoType()
|
|
|
|
{
|
2009-05-17 01:34:14 +02:00
|
|
|
const Engine *e = ::Engine::Get(engine);
|
2009-02-21 13:52:41 +01:00
|
|
|
if (!e->CanCarryCargo()) return CT_INVALID;
|
|
|
|
return e->GetDefaultCargoType();
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int32 AIEventEnginePreview::GetCapacity()
|
|
|
|
{
|
2009-05-17 01:34:14 +02:00
|
|
|
const Engine *e = ::Engine::Get(engine);
|
2009-03-14 00:49:12 +01:00
|
|
|
switch (e->type) {
|
2009-01-12 18:11:45 +01:00
|
|
|
case VEH_ROAD:
|
|
|
|
case VEH_TRAIN: {
|
2009-03-14 00:49:12 +01:00
|
|
|
uint16 *capacities = GetCapacityOfArticulatedParts(engine, e->type);
|
2009-01-12 18:11:45 +01:00
|
|
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
|
|
|
if (capacities[c] == 0) continue;
|
|
|
|
return capacities[c];
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
} break;
|
|
|
|
|
2009-03-14 00:49:12 +01:00
|
|
|
case VEH_SHIP:
|
|
|
|
case VEH_AIRCRAFT:
|
2009-03-18 20:32:13 +01:00
|
|
|
return e->GetDisplayDefaultCapacity();
|
2009-03-14 00:49:12 +01:00
|
|
|
break;
|
2009-01-12 18:11:45 +01:00
|
|
|
|
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 AIEventEnginePreview::GetMaxSpeed()
|
|
|
|
{
|
2009-05-17 01:34:14 +02:00
|
|
|
const Engine *e = ::Engine::Get(engine);
|
2009-02-01 18:14:39 +01:00
|
|
|
int32 max_speed = e->GetDisplayMaxSpeed(); // km-ish/h
|
2009-02-01 17:10:06 +01:00
|
|
|
if (e->type == VEH_AIRCRAFT) max_speed /= _settings_game.vehicle.plane_speed;
|
|
|
|
return max_speed;
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Money AIEventEnginePreview::GetPrice()
|
|
|
|
{
|
2009-05-17 01:34:14 +02:00
|
|
|
return ::Engine::Get(engine)->GetCost();
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Money AIEventEnginePreview::GetRunningCost()
|
|
|
|
{
|
2009-05-17 01:34:14 +02:00
|
|
|
return ::Engine::Get(engine)->GetRunningCost();
|
2009-01-12 18:11:45 +01:00
|
|
|
}
|
|
|
|
|
2009-04-26 01:51:15 +02:00
|
|
|
int32 AIEventEnginePreview::GetVehicleType()
|
2009-01-12 18:11:45 +01:00
|
|
|
{
|
2009-05-17 01:34:14 +02:00
|
|
|
switch (::Engine::Get(engine)->type) {
|
2009-01-16 01:27:22 +01:00
|
|
|
case VEH_ROAD: return AIVehicle::VT_ROAD;
|
|
|
|
case VEH_TRAIN: return AIVehicle::VT_RAIL;
|
|
|
|
case VEH_SHIP: return AIVehicle::VT_WATER;
|
|
|
|
case VEH_AIRCRAFT: return AIVehicle::VT_AIR;
|
2009-01-12 18:11:45 +01:00
|
|
|
default: NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AIEventEnginePreview::AcceptPreview()
|
|
|
|
{
|
|
|
|
return AIObject::DoCommand(0, engine, 0, CMD_WANT_ENGINE_PREVIEW);
|
|
|
|
}
|