From 452e21bc50b79b9d854b974e4256d20ad96b56c6 Mon Sep 17 00:00:00 2001 From: Dylan <28832631+DARwins1@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:52:48 -0700 Subject: [PATCH] Utilize the transport timer on Beta End (#3421) --- .../campaign/libcampaign_includes/events.js | 20 +++++++++++ src/mission.cpp | 29 +++++++-------- src/order.cpp | 5 +-- src/transporter.cpp | 5 +-- src/wzapi.cpp | 35 +++++++++---------- 5 files changed, 56 insertions(+), 38 deletions(-) diff --git a/data/base/script/campaign/libcampaign_includes/events.js b/data/base/script/campaign/libcampaign_includes/events.js index c3be570b351..9285c7febb2 100644 --- a/data/base/script/campaign/libcampaign_includes/events.js +++ b/data/base/script/campaign/libcampaign_includes/events.js @@ -236,6 +236,11 @@ function cam_eventTransporterExit(transport) setReinforcementTime(__camVictoryData.reinforcements); } } + // Show how long until the transporter comes back on Beta End. + if (__camWinLossCallback === CAM_VICTORY_TIMEOUT) + { + setReinforcementTime(__camVictoryData.reinforcements); + } } if (transport.player !== CAM_HUMAN_PLAYER || @@ -257,6 +262,14 @@ function cam_eventTransporterLanded(transport) { __camLandTransporter(transport.player, camMakePos(transport)); } + else + { + // Make the transporter timer on Beta End disappear, since the transporter has arrived. + if (__camWinLossCallback === CAM_VICTORY_TIMEOUT) + { + setReinforcementTime(-1); + } + } } function cam_eventMissionTimeout() @@ -357,6 +370,13 @@ function cam_eventGameLoaded() } } + if (__camWinLossCallback === CAM_VICTORY_TIMEOUT + && enumDroid(CAM_HUMAN_PLAYER, DROID_SUPERTRANSPORTER).length === 0) + { + // If the transport is gone on Beta End, put a timer up to show when it'll be back + setReinforcementTime(__camVictoryData.reinforcements); + } + //Subscribe to eventGroupSeen again. camSetEnemyBases(); diff --git a/src/mission.cpp b/src/mission.cpp index f2f6893fa1d..cbf56880fc8 100644 --- a/src/mission.cpp +++ b/src/mission.cpp @@ -543,8 +543,8 @@ void addTransporterTimerInterface() { bAddInterface = true; - //check timer is not already on the screen - if (!widgGetFromID(psWScreen, IDTRANTIMER_BUTTON)) + // Check that neither the timer nor the launch button are on screen + if (!widgGetFromID(psWScreen, IDTRANTIMER_BUTTON) && !widgGetFromID(psWScreen, IDTRANS_LAUNCH)) { intAddTransporterTimer(); } @@ -1434,11 +1434,8 @@ void endMission() abort(); } - if (missionCanReEnforce()) //mission.type == LDS_MCLEAR || mission.type == LDS_MKEEP) - { - intRemoveMissionTimer(); - intRemoveTransporterTimer(); - } + intRemoveMissionTimer(); + intRemoveTransporterTimer(); //at end of mission always do this intRemoveTransporterLaunch(); @@ -3087,7 +3084,7 @@ void clearMissionWidgets() intRemoveMissionTimer(); } - if (missionCanReEnforce()) + if (mission.ETA >= 0) { intRemoveTransporterTimer(); } @@ -3131,17 +3128,17 @@ void resetMissionWidgets() stopMissionButtonFlash(IDTIMER_FORM); } - if (missionCanReEnforce()) + DROID* transporter = find_transporter(); + + // Check if not a reinforcement type mission and we have an transporter + if (!missionForReInforcements() && transporter != nullptr && !transporterFlying(transporter)) { - addTransporterTimerInterface(); + // Show launch button if the transporter has not already been launched + intAddTransporterLaunch(transporter); } - //check not a typical reinforcement mission - else if (!missionForReInforcements()) + else if (mission.ETA >= 0) { - if (auto transporter = find_transporter()) - { - intAddTransporterLaunch(transporter); - } + addTransporterTimerInterface(); } } diff --git a/src/order.cpp b/src/order.cpp index 0248df4f901..5a4f2ac1846 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -484,11 +484,11 @@ void orderUpdateDroid(DROID *psDroid) } else { - //the script can call startMission for this callback for offworld missions - triggerEvent(TRIGGER_TRANSPORTER_EXIT, psDroid); /* clear order */ psDroid->order = DroidOrder(DORDER_NONE); } + //the script can call startMission for this callback for offworld missions (if we want to change level) + triggerEvent(TRIGGER_TRANSPORTER_EXIT, psDroid); psDroid->sMove.speed = 0; // Prevent radical movement vector when adjusting from home to away map exit and entry coordinates. } @@ -525,6 +525,7 @@ void orderUpdateDroid(DROID *psDroid) missionDroidsRemaining(selectedPlayer)) { resetTransporter(); + triggerEvent(TRIGGER_TRANSPORTER_LANDED, psDroid); } else { diff --git a/src/transporter.cpp b/src/transporter.cpp index 615dc2d08aa..e483d0ea00b 100644 --- a/src/transporter.cpp +++ b/src/transporter.cpp @@ -336,8 +336,9 @@ bool intAddTransporterLaunch(DROID *psDroid) //set up the static transporter psCurrTransporter = psDroid; - //check the button is not already up - if (widgGetFromID(psWScreen, IDTRANS_LAUNCH) != nullptr) + // Check that neither the launch button nor the transport timer are currently up + if (widgGetFromID(psWScreen, IDTRANS_LAUNCH) != nullptr + || widgGetFromID(psWScreen, IDTRANTIMER_BUTTON) != nullptr) { return true; } diff --git a/src/wzapi.cpp b/src/wzapi.cpp index e15c08a21a7..3dce423fd4c 100644 --- a/src/wzapi.cpp +++ b/src/wzapi.cpp @@ -2526,30 +2526,29 @@ wzapi::no_return_value wzapi::setReinforcementTime(WZAPI_PARAMS(int _time)) "The transport timer cannot be set to more than 1 hour!"); SCRIPT_ASSERT({}, context, selectedPlayer < MAX_PLAYERS, "Invalid selectedPlayer for current client: %" PRIu32 "", selectedPlayer); mission.ETA = time; - if (missionCanReEnforce()) - { - addTransporterTimerInterface(); - } + if (time < 0) { - DROID *psDroid; - intRemoveTransporterTimer(); - /* Only remove the launch if haven't got a transporter droid since the scripts set the - * time to -1 at the between stage if there are not going to be reinforcements on the submap */ - for (psDroid = apsDroidLists[selectedPlayer]; psDroid != nullptr; psDroid = psDroid->psNext) - { - if (isTransporter(psDroid)) - { - break; - } - } - // if not found a transporter, can remove the launch button - if (psDroid == nullptr) + } + DROID* psDroid; + + /* Search for a transport that is idle; if we can't find any, remove the launch button + * since there's no transport to launch */ + for (psDroid = apsDroidLists[selectedPlayer]; psDroid != nullptr; psDroid = psDroid->psNext) + { + if (isTransporter(psDroid) && !transporterFlying(psDroid)) { - intRemoveTransporterLaunch(); + break; } } + // Didn't find an idle transporter, we can remove the launch button + if (psDroid == nullptr) + { + intRemoveTransporterLaunch(); + } + resetMissionWidgets(); + addTransporterTimerInterface(); return {}; }