From 00ca99a53a61d9951fe94bce934b33b9996e8181 Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Mon, 25 Sep 2023 21:09:06 -0500 Subject: [PATCH] Add eventTransporterEmbarked Need this for when a unit enters the transporter to update build/command reticules. --- data/base/script/rules.js | 11 ++++++++++- data/mp/multiplay/script/rules/events/transfer.js | 8 ++++++++ src/order.cpp | 5 +++++ src/qtscript.cpp | 3 +++ src/qtscript.h | 1 + src/quickjs_backend.cpp | 7 +++++++ src/wzapi.h | 6 ++++++ 7 files changed, 40 insertions(+), 1 deletion(-) diff --git a/data/base/script/rules.js b/data/base/script/rules.js index 5d2d09deb0a..9d29f8f461e 100644 --- a/data/base/script/rules.js +++ b/data/base/script/rules.js @@ -410,7 +410,7 @@ function eventObjectTransfer(obj, from) } } -//Could be the last remaining trucks are on it. +//Could be the last remaining trucks/commanders are on it. function eventTransporterLanded(transport) { if (transport.player === selectedPlayer) @@ -419,6 +419,15 @@ function eventTransporterLanded(transport) } } +//Maybe no more truck/commanders on the map. +function eventTransporterEmbarked(transport) +{ + if (transport.player === selectedPlayer) + { + reticuleUpdate(transport, TRANSFER_LIKE_EVENT); + } +} + function eventResearched(research, structure, player) { // NOTE: Research upgrades are handled by the C++ core game engine since 4.1.0 diff --git a/data/mp/multiplay/script/rules/events/transfer.js b/data/mp/multiplay/script/rules/events/transfer.js index 5d9b4bb852f..eb78f603271 100644 --- a/data/mp/multiplay/script/rules/events/transfer.js +++ b/data/mp/multiplay/script/rules/events/transfer.js @@ -5,3 +5,11 @@ function eventObjectTransfer(obj, from) reticuleUpdate(obj, TRANSFER_LIKE_EVENT); } } + +function eventTransporterEmbarked(transport) +{ + if (transport.player === selectedPlayer) + { + reticuleUpdate(transport, TRANSFER_LIKE_EVENT); + } +} diff --git a/src/order.cpp b/src/order.cpp index e03b5482820..a5168d247da 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -893,6 +893,11 @@ void orderUpdateDroid(DROID *psDroid) psDroid->order.psObj = nullptr; secondarySetState(psDroid, DSO_RETURN_TO_LOC, DSS_NONE); + // Fire off embark event + transporterSetScriptCurrent(transporter); + triggerEvent(TRIGGER_TRANSPORTER_EMBARKED, transporter); + transporterSetScriptCurrent(nullptr); + /* We must add the droid to the transporter only *after* * processing changing its orders (see above). */ diff --git a/src/qtscript.cpp b/src/qtscript.cpp index 2c21b7215b3..5e1eb06fc99 100644 --- a/src/qtscript.cpp +++ b/src/qtscript.cpp @@ -1076,6 +1076,9 @@ bool triggerEvent(SCRIPT_TRIGGER_TYPE trigger, BASE_OBJECT *psObj) case TRIGGER_TRANSPORTER_LANDED: instance->handle_eventTransporterLanded(psObj); break; + case TRIGGER_TRANSPORTER_EMBARKED: + instance->handle_eventTransporterEmbarked(psObj); + break; case TRIGGER_MISSION_TIMEOUT: instance->handle_eventMissionTimeout(); break; diff --git a/src/qtscript.h b/src/qtscript.h index 55dd496f642..45d8c2aaf2e 100644 --- a/src/qtscript.h +++ b/src/qtscript.h @@ -43,6 +43,7 @@ enum SCRIPT_TRIGGER_TYPE TRIGGER_GAME_INIT, TRIGGER_START_LEVEL, TRIGGER_TRANSPORTER_ARRIVED, + TRIGGER_TRANSPORTER_EMBARKED, TRIGGER_TRANSPORTER_LANDED, TRIGGER_TRANSPORTER_LAUNCH, TRIGGER_TRANSPORTER_EXIT, diff --git a/src/quickjs_backend.cpp b/src/quickjs_backend.cpp index cab3b4a76c4..e45ffcf00c0 100644 --- a/src/quickjs_backend.cpp +++ b/src/quickjs_backend.cpp @@ -339,6 +339,12 @@ class quickjs_scripting_instance : public wzapi::scripting_instance //__ virtual bool handle_eventTransporterLanded(const BASE_OBJECT *psTransport) override; + //__ ## eventTransporterEmbarked(transport) + //__ + //__ An event that is run when a unit embarks into a transporter. + //__ + virtual bool handle_eventTransporterEmbarked(const BASE_OBJECT *psTransport) override; + public: // MARK: UI-related events (intended for the tutorial) @@ -2941,6 +2947,7 @@ IMPL_EVENT_HANDLER(eventTransporterArrived, const BASE_OBJECT *) IMPL_EVENT_HANDLER(eventTransporterExit, const BASE_OBJECT *) IMPL_EVENT_HANDLER(eventTransporterDone, const BASE_OBJECT *) IMPL_EVENT_HANDLER(eventTransporterLanded, const BASE_OBJECT *) +IMPL_EVENT_HANDLER(eventTransporterEmbarked, const BASE_OBJECT *) // MARK: UI-related events (intended for the tutorial) IMPL_EVENT_HANDLER(eventDeliveryPointMoving, const BASE_OBJECT *) diff --git a/src/wzapi.h b/src/wzapi.h index e4a71e049ca..49837f4d34c 100644 --- a/src/wzapi.h +++ b/src/wzapi.h @@ -230,6 +230,12 @@ namespace wzapi //__ virtual bool handle_eventTransporterLanded(const BASE_OBJECT *psTransport) SCRIPTING_EVENT_NON_REQUIRED + //__ ## eventTransporterEmbarked(transport) + //__ + //__ An event that is run when a unit embarks into a transporter. + //__ + virtual bool handle_eventTransporterEmbarked(const BASE_OBJECT *psTransport) SCRIPTING_EVENT_NON_REQUIRED + public: // MARK: UI-related events (intended for the tutorial)