From 7f198507f724a20bc2c1257ad385a1fa4983a08e Mon Sep 17 00:00:00 2001 From: frosch Date: Thu, 5 Feb 2009 17:28:37 +0000 Subject: (svn r15358) -Add [NoAI]: AIEventVehicleCrashed::GetCrashReason() --- src/ai/api/ai_event_types.hpp | 22 ++++++++++++++++++++-- src/ai/api/ai_event_types.hpp.sq | 10 ++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src/ai/api') diff --git a/src/ai/api/ai_event_types.hpp b/src/ai/api/ai_event_types.hpp index 044892ab7..da1b6989e 100644 --- a/src/ai/api/ai_event_types.hpp +++ b/src/ai/api/ai_event_types.hpp @@ -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; }; /** diff --git a/src/ai/api/ai_event_types.hpp.sq b/src/ai/api/ai_event_types.hpp.sq index 9c4537f8b..0eb23376a 100644 --- a/src/ai/api/ai_event_types.hpp.sq +++ b/src/ai/api/ai_event_types.hpp.sq @@ -4,6 +4,10 @@ #include "ai_event_types.hpp" namespace SQConvert { + /* Allow enums to be used as Squirrel parameters */ + template <> AIEventVehicleCrashed::CrashReason GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (AIEventVehicleCrashed::CrashReason)tmp; } + template <> int Return(HSQUIRRELVM vm, AIEventVehicleCrashed::CrashReason res) { sq_pushinteger(vm, (int32)res); return 1; } + /* Allow AIEventVehicleCrashed to be used as Squirrel parameter */ template <> AIEventVehicleCrashed *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AIEventVehicleCrashed *)instance; } template <> AIEventVehicleCrashed &GetParam(ForceType, 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 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); -- cgit v1.2.3-70-g09d2