Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent launch button disappearing on LZ compromise #3604

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data/base/script/campaign/libcampaign_includes/victory.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ function __camVictoryOffworld()
//Protect against early access to reinforcements GUI if it shouldn't be available yet
if (__camVictoryData.reinforcements >= 0)
{
setReinforcementTime(LZ_COMPROMISED_TIME);
setReinforcementTime(LZ_COMPROMISED_TIME, false);
}
if (__camLZCompromisedTicker === 0)
{
Expand All @@ -474,7 +474,7 @@ function __camVictoryOffworld()
camTrace("LZ clear");
const pos = camMakePos(lz);
playSound(cam_sounds.lz.LZClear, pos.x, pos.y, 0);
setReinforcementTime(__camVictoryData.reinforcements);
setReinforcementTime(__camVictoryData.reinforcements, false);
__camLZCompromisedTicker = 0;
if (__camRTLZTicker === 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/quickjs_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3488,7 +3488,7 @@ bool quickjs_scripting_instance::registerFunctions(const std::string& scriptName
JS_REGISTER_FUNC(applyLimitSet, 0); // WZAPI
JS_REGISTER_FUNC(setMissionTime, 1); // WZAPI
JS_REGISTER_FUNC(getMissionTime, 0); // WZAPI
JS_REGISTER_FUNC(setReinforcementTime, 1); // WZAPI
JS_REGISTER_FUNC2(setReinforcementTime, 1, 2); // WZAPI
JS_REGISTER_FUNC2(completeResearch, 1, 3); // WZAPI
JS_REGISTER_FUNC2(completeAllResearch, 0, 1); // WZAPI
JS_REGISTER_FUNC2(enableResearch, 1, 2); // WZAPI
Expand Down
32 changes: 17 additions & 15 deletions src/wzapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2511,38 +2511,40 @@ int wzapi::getMissionTime(WZAPI_NO_PARAMS)
return (mission.time - (gameTime - mission.startTime)) / GAME_TICKS_PER_SEC;
}

//-- ## setReinforcementTime(time)
//-- ## setReinforcementTime(time[, removeLaunch])
//--
//-- Set time for reinforcements to arrive. If time is negative, the reinforcement GUI
//-- is removed and the timer stopped. Time is in seconds.
//-- If time equals to the magic ```LZ_COMPROMISED_TIME``` constant, reinforcement GUI ticker
//-- is set to "--:--" and reinforcements are suppressed until this function is called
//-- again with a regular time value.
//--
wzapi::no_return_value wzapi::setReinforcementTime(WZAPI_PARAMS(int _time))
wzapi::no_return_value wzapi::setReinforcementTime(WZAPI_PARAMS(int _time, optional<bool> _removeLaunch))
{
int time = _time * GAME_TICKS_PER_SEC;
SCRIPT_ASSERT({}, context, time == LZ_COMPROMISED_TIME || time < 60 * 60 * GAME_TICKS_PER_SEC,
"The transport timer cannot be set to more than 1 hour!");
bool removeLaunch = _removeLaunch.value_or(true);
SCRIPT_ASSERT({}, context, time == LZ_COMPROMISED_TIME || time < 60 * 60 * GAME_TICKS_PER_SEC, "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 (time < 0)
{
intRemoveTransporterTimer();
}
/* Search for a transport that is idle; if we can't find any, remove the launch button
* since there's no transport to launch */
auto droidIt = std::find_if(apsDroidLists[selectedPlayer].begin(), apsDroidLists[selectedPlayer].end(), [](DROID* d)
if (removeLaunch)
{
return isTransporter(d) && !transporterFlying(d);
});
DROID* psDroid = droidIt != apsDroidLists[selectedPlayer].end() ? *droidIt : nullptr;
/* Search for a transport that is idle; if we can't find any, remove the launch button
* since there's no transport to launch */
auto droidIt = std::find_if(apsDroidLists[selectedPlayer].begin(), apsDroidLists[selectedPlayer].end(), [](DROID* d)
{
return isTransporter(d) && !transporterFlying(d);
});
DROID* psDroid = droidIt != apsDroidLists[selectedPlayer].end() ? *droidIt : nullptr;

// Didn't find an idle transporter, we can remove the launch button
if (psDroid == nullptr)
{
intRemoveTransporterLaunch();
// Didn't find an idle transporter, we can remove the launch button
if (psDroid == nullptr)
{
intRemoveTransporterLaunch();
}
}
resetMissionWidgets();
addTransporterTimerInterface();
Expand Down
2 changes: 1 addition & 1 deletion src/wzapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ namespace wzapi
bool applyLimitSet(WZAPI_NO_PARAMS);
no_return_value setMissionTime(WZAPI_PARAMS(int _time));
int getMissionTime(WZAPI_NO_PARAMS);
no_return_value setReinforcementTime(WZAPI_PARAMS(int _time));
no_return_value setReinforcementTime(WZAPI_PARAMS(int _time, optional<bool> _removeLaunch));
no_return_value completeResearch(WZAPI_PARAMS(std::string researchName, optional<int> _player, optional<bool> _forceResearch));
no_return_value completeAllResearch(WZAPI_PARAMS(optional<int> _player));
bool enableResearch(WZAPI_PARAMS(std::string researchName, optional<int> _player));
Expand Down
Loading