Files
@ r10887:cdbf4a546981
Branch filter:
Location: cpp/openttd-patchpack/source/src/ai/api/ai_event_types.cpp
r10887:cdbf4a546981
4.3 KiB
text/x-c
(svn r15222) -Fix: The squirrel stack was corrupted if an AI called any C++ function during Save().
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | /* $Id$ */
/** @file ai_event_types.cpp Implementation of all EventTypes. */
#include "ai_event_types.hpp"
#include "../../openttd.h"
#include "../../core/alloc_func.hpp"
#include "../../strings_func.h"
#include "../../roadveh.h"
#include "../../train.h"
#include "../../ship.h"
#include "../../aircraft.h"
#include "../../settings_type.h"
#include "../../articulated_vehicles.h"
#include "table/strings.h"
bool AIEventVehicleCrashed::CloneCrashedVehicle(TileIndex depot)
{
return false;
}
char *AIEventEnginePreview::GetName()
{
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()
{
switch (::GetEngine(engine)->type) {
case VEH_ROAD: {
const RoadVehicleInfo *vi = ::RoadVehInfo(engine);
return vi->cargo_type;
} break;
case VEH_TRAIN: {
const RailVehicleInfo *vi = ::RailVehInfo(engine);
return vi->cargo_type;
} break;
case VEH_SHIP: {
const ShipVehicleInfo *vi = ::ShipVehInfo(engine);
return vi->cargo_type;
} break;
case VEH_AIRCRAFT: {
return CT_PASSENGERS;
} break;
default: NOT_REACHED();
}
}
int32 AIEventEnginePreview::GetCapacity()
{
switch (::GetEngine(engine)->type) {
case VEH_ROAD:
case VEH_TRAIN: {
uint16 *capacities = GetCapacityOfArticulatedParts(engine, ::GetEngine(engine)->type);
for (CargoID c = 0; c < NUM_CARGO; c++) {
if (capacities[c] == 0) continue;
return capacities[c];
}
return -1;
} break;
case VEH_SHIP: {
const ShipVehicleInfo *vi = ::ShipVehInfo(engine);
return vi->capacity;
} break;
case VEH_AIRCRAFT: {
const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine);
return vi->passenger_capacity;
} break;
default: NOT_REACHED();
}
}
int32 AIEventEnginePreview::GetMaxSpeed()
{
switch (::GetEngine(engine)->type) {
case VEH_ROAD: {
const RoadVehicleInfo *vi = ::RoadVehInfo(engine);
/* Internal speeds are km/h * 2 */
return vi->max_speed / 2;
} break;
case VEH_TRAIN: {
const RailVehicleInfo *vi = ::RailVehInfo(engine);
return vi->max_speed;
} break;
case VEH_SHIP: {
const ShipVehicleInfo *vi = ::ShipVehInfo(engine);
/* Internal speeds are km/h * 2 */
return vi->max_speed / 2;
} break;
case VEH_AIRCRAFT: {
const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine);
return vi->max_speed / _settings_game.vehicle.plane_speed;
} break;
default: NOT_REACHED();
}
}
Money AIEventEnginePreview::GetPrice()
{
switch (::GetEngine(engine)->type) {
case VEH_ROAD: {
const RoadVehicleInfo *vi = ::RoadVehInfo(engine);
return (_price.roadveh_base >> 3) * vi->cost_factor >> 5;
} break;
case VEH_TRAIN: {
const RailVehicleInfo *vi = ::RailVehInfo(engine);
return (_price.build_railvehicle >> 3) * vi->cost_factor >> 5;
} break;
case VEH_SHIP: {
const ShipVehicleInfo *vi = ::ShipVehInfo(engine);
return (_price.ship_base >> 3) * vi->cost_factor >> 5;
} break;
case VEH_AIRCRAFT: {
const AircraftVehicleInfo *vi = ::AircraftVehInfo(engine);
return (_price.aircraft_base >> 3) * vi->cost_factor >> 5;
} break;
default: NOT_REACHED();
}
}
Money AIEventEnginePreview::GetRunningCost()
{
/* We need to create an instance in order to obtain GetRunningCost.
* This means we temporary allocate a vehicle in the pool, but
* there is no other way.. */
Vehicle *vehicle;
switch (::GetEngine(engine)->type) {
case VEH_ROAD: {
vehicle = new RoadVehicle();
} break;
case VEH_TRAIN: {
vehicle = new Train();
} break;
case VEH_SHIP: {
vehicle = new Ship();
} break;
case VEH_AIRCRAFT: {
vehicle = new Aircraft();
} break;
default: NOT_REACHED();
}
vehicle->engine_type = engine;
Money runningCost = vehicle->GetRunningCost();
delete vehicle;
return runningCost >> 8;
}
AIVehicle::VehicleType AIEventEnginePreview::GetVehicleType()
{
switch (::GetEngine(engine)->type) {
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;
default: NOT_REACHED();
}
}
bool AIEventEnginePreview::AcceptPreview()
{
return AIObject::DoCommand(0, engine, 0, CMD_WANT_ENGINE_PREVIEW);
}
|