diff options
author | frosch <frosch@openttd.org> | 2009-02-05 17:28:37 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2009-02-05 17:28:37 +0000 |
commit | 7f198507f724a20bc2c1257ad385a1fa4983a08e (patch) | |
tree | 4de4c102c811abe4c55218244a0c848367082bf0 /src/ai/api | |
parent | 6dff31d34b2df4c1fb1332d33380bb99a2b40924 (diff) | |
download | openttd-7f198507f724a20bc2c1257ad385a1fa4983a08e.tar.xz |
(svn r15358) -Add [NoAI]: AIEventVehicleCrashed::GetCrashReason()
Diffstat (limited to 'src/ai/api')
-rw-r--r-- | src/ai/api/ai_event_types.hpp | 22 | ||||
-rw-r--r-- | src/ai/api/ai_event_types.hpp.sq | 10 |
2 files changed, 30 insertions, 2 deletions
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 @@ -24,13 +24,24 @@ 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) {} /** @@ -53,6 +64,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. * @return True when the cloning succeeded. @@ -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<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); |