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 | |
parent | 6dff31d34b2df4c1fb1332d33380bb99a2b40924 (diff) | |
download | openttd-7f198507f724a20bc2c1257ad385a1fa4983a08e.tar.xz |
(svn r15358) -Add [NoAI]: AIEventVehicleCrashed::GetCrashReason()
-rw-r--r-- | src/ai/ai_instance.cpp | 1 | ||||
-rw-r--r-- | src/ai/api/ai_event_types.hpp | 22 | ||||
-rw-r--r-- | src/ai/api/ai_event_types.hpp.sq | 10 | ||||
-rw-r--r-- | src/aircraft_cmd.cpp | 5 | ||||
-rw-r--r-- | src/roadveh_cmd.cpp | 2 | ||||
-rw-r--r-- | src/train_cmd.cpp | 2 |
6 files changed, 37 insertions, 5 deletions
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp index 37529eeab..3e5f6f21f 100644 --- a/src/ai/ai_instance.cpp +++ b/src/ai/ai_instance.cpp @@ -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); 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); diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 881f0339d..caf2b0726 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -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, diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index f6b54934c..05c842f54 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -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( diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 0d1b69d47..6dbd49655 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -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, |