Skip to content

Commit

Permalink
Add eventTransporterEmbarked
Browse files Browse the repository at this point in the history
Need this for when a unit enters the transporter to update build/command reticules.
  • Loading branch information
KJeff01 committed Sep 28, 2023
1 parent ab2db15 commit 00ca99a
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
11 changes: 10 additions & 1 deletion data/base/script/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions data/mp/multiplay/script/rules/events/transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions src/order.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/
Expand Down
3 changes: 3 additions & 0 deletions src/qtscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/qtscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/quickjs_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 *)
Expand Down
6 changes: 6 additions & 0 deletions src/wzapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 00ca99a

Please sign in to comment.