mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-02 09:40:35 +00:00
(svn r15358) -Add [NoAI]: AIEventVehicleCrashed::GetCrashReason()
This commit is contained in:
parent
6dff31d34b
commit
7f198507f7
@ -221,6 +221,7 @@ void AIInstance::RegisterAPI()
|
||||
SQAITunnel_Register(this->engine);
|
||||
SQAIVehicle_Register(this->engine);
|
||||
SQAIVehicleList_Register(this->engine);
|
||||
SQAIVehicleList_SharedOrders_Register(this->engine);
|
||||
SQAIVehicleList_Station_Register(this->engine);
|
||||
|
||||
this->engine->SetGlobalPointer(this->engine);
|
||||
|
@ -23,14 +23,25 @@ class AIEventVehicleCrashed : public AIEvent {
|
||||
public:
|
||||
static const char *GetClassName() { return "AIEventVehicleCrashed"; }
|
||||
|
||||
/**
|
||||
* The reasons for vehicle crashes
|
||||
*/
|
||||
enum CrashReason {
|
||||
CRASH_TRAIN, ///< Two trains collided
|
||||
CRASH_RV_LEVEL_CROSSING, ///< Road vehicle got under a train
|
||||
CRASH_PLANE_LANDING, ///< Plane crashed on landing
|
||||
CRASH_AIRCRAFT_NO_AIRPORT, ///< Aircraft crashed after it found not a single airport for landing
|
||||
};
|
||||
|
||||
/**
|
||||
* @param vehicle The vehicle that crashed.
|
||||
* @param crash_site Where the vehicle crashed.
|
||||
*/
|
||||
AIEventVehicleCrashed(VehicleID vehicle, TileIndex crash_site) :
|
||||
AIEventVehicleCrashed(VehicleID vehicle, TileIndex crash_site, CrashReason crash_reason) :
|
||||
AIEvent(AI_ET_VEHICLE_CRASHED),
|
||||
crash_site(crash_site),
|
||||
vehicle(vehicle)
|
||||
vehicle(vehicle),
|
||||
crash_reason(crash_reason)
|
||||
{}
|
||||
|
||||
/**
|
||||
@ -52,6 +63,12 @@ public:
|
||||
*/
|
||||
TileIndex GetCrashSite() { return crash_site; }
|
||||
|
||||
/**
|
||||
* Get the reason for crashing
|
||||
* @return The reason for crashing
|
||||
*/
|
||||
CrashReason GetCrashReason() { return crash_reason; }
|
||||
|
||||
/**
|
||||
* Clone the crashed vehicle and send it on its way again.
|
||||
* @param depot the depot to build the vehicle in.
|
||||
@ -63,6 +80,7 @@ public:
|
||||
private:
|
||||
TileIndex crash_site;
|
||||
VehicleID vehicle;
|
||||
CrashReason crash_reason;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,10 @@
|
||||
#include "ai_event_types.hpp"
|
||||
|
||||
namespace SQConvert {
|
||||
/* Allow enums to be used as Squirrel parameters */
|
||||
template <> AIEventVehicleCrashed::CrashReason GetParam(ForceType<AIEventVehicleCrashed::CrashReason>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIEventVehicleCrashed::CrashReason)tmp; }
|
||||
template <> int Return<AIEventVehicleCrashed::CrashReason>(HSQUIRRELVM vm, AIEventVehicleCrashed::CrashReason res) { sq_pushinteger(vm, (int32)res); return 1; }
|
||||
|
||||
/* Allow AIEventVehicleCrashed to be used as Squirrel parameter */
|
||||
template <> AIEventVehicleCrashed *GetParam(ForceType<AIEventVehicleCrashed *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventVehicleCrashed *)instance; }
|
||||
template <> AIEventVehicleCrashed &GetParam(ForceType<AIEventVehicleCrashed &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AIEventVehicleCrashed *)instance; }
|
||||
@ -16,11 +20,17 @@ void SQAIEventVehicleCrashed_Register(Squirrel *engine) {
|
||||
DefSQClass <AIEventVehicleCrashed> SQAIEventVehicleCrashed("AIEventVehicleCrashed");
|
||||
SQAIEventVehicleCrashed.PreRegister(engine, "AIEvent");
|
||||
|
||||
SQAIEventVehicleCrashed.DefSQConst(engine, AIEventVehicleCrashed::CRASH_TRAIN, "CRASH_TRAIN");
|
||||
SQAIEventVehicleCrashed.DefSQConst(engine, AIEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING, "CRASH_RV_LEVEL_CROSSING");
|
||||
SQAIEventVehicleCrashed.DefSQConst(engine, AIEventVehicleCrashed::CRASH_PLANE_LANDING, "CRASH_PLANE_LANDING");
|
||||
SQAIEventVehicleCrashed.DefSQConst(engine, AIEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT, "CRASH_AIRCRAFT_NO_AIRPORT");
|
||||
|
||||
SQAIEventVehicleCrashed.DefSQStaticMethod(engine, &AIEventVehicleCrashed::GetClassName, "GetClassName", 1, "x");
|
||||
SQAIEventVehicleCrashed.DefSQStaticMethod(engine, &AIEventVehicleCrashed::Convert, "Convert", 2, "xx");
|
||||
|
||||
SQAIEventVehicleCrashed.DefSQMethod(engine, &AIEventVehicleCrashed::GetVehicleID, "GetVehicleID", 1, "x");
|
||||
SQAIEventVehicleCrashed.DefSQMethod(engine, &AIEventVehicleCrashed::GetCrashSite, "GetCrashSite", 1, "x");
|
||||
SQAIEventVehicleCrashed.DefSQMethod(engine, &AIEventVehicleCrashed::GetCrashReason, "GetCrashReason", 1, "x");
|
||||
SQAIEventVehicleCrashed.DefSQMethod(engine, &AIEventVehicleCrashed::CloneCrashedVehicle, "CloneCrashedVehicle", 2, "xi");
|
||||
|
||||
SQAIEventVehicleCrashed.PostRegister(engine);
|
||||
|
@ -1323,14 +1323,17 @@ static void CrashAirplane(Vehicle *v)
|
||||
v->Next()->cargo.Truncate(0);
|
||||
const Station *st = GetTargetAirportIfValid(v);
|
||||
StringID newsitem;
|
||||
AIEventVehicleCrashed::CrashReason crash_reason;
|
||||
if (st == NULL) {
|
||||
newsitem = STR_PLANE_CRASH_OUT_OF_FUEL;
|
||||
crash_reason = AIEventVehicleCrashed::CRASH_AIRCRAFT_NO_AIRPORT;
|
||||
} else {
|
||||
SetDParam(1, st->index);
|
||||
newsitem = STR_A034_PLANE_CRASH_DIE_IN_FIREBALL;
|
||||
crash_reason = AIEventVehicleCrashed::CRASH_PLANE_LANDING;
|
||||
}
|
||||
|
||||
AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile));
|
||||
AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile, crash_reason));
|
||||
|
||||
AddNewsItem(newsitem,
|
||||
NS_ACCIDENT_VEHICLE,
|
||||
|
@ -600,7 +600,7 @@ static void RoadVehCrash(Vehicle *v)
|
||||
|
||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
||||
|
||||
AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile));
|
||||
AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile, AIEventVehicleCrashed::CRASH_RV_LEVEL_CROSSING));
|
||||
|
||||
SetDParam(0, pass);
|
||||
AddNewsItem(
|
||||
|
@ -3584,7 +3584,7 @@ static bool CheckTrainCollision(Vehicle *v)
|
||||
/* any dead -> no crash */
|
||||
if (tcc.num == 0) return false;
|
||||
|
||||
AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile));
|
||||
AI::NewEvent(v->owner, new AIEventVehicleCrashed(v->index, v->tile, AIEventVehicleCrashed::CRASH_TRAIN));
|
||||
SetDParam(0, tcc.num);
|
||||
AddNewsItem(STR_8868_TRAIN_CRASH_DIE_IN_FIREBALL,
|
||||
NS_ACCIDENT_VEHICLE,
|
||||
|
Loading…
Reference in New Issue
Block a user