From 29a62301864d849029c7ee9df08ebac328db995a Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Thu, 22 Aug 2024 11:23:03 -0500 Subject: [PATCH] Fill VTOLs when going offworld If, there are any built VTOL Rearming Pads. This is similar to droids getting repaired automatically if a Repair Facility is on the map. --- src/droid.cpp | 17 +++++++++++++++++ src/droid.h | 2 ++ src/mission.cpp | 32 +++++++++++++++++++++----------- src/structure.cpp | 8 +------- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/droid.cpp b/src/droid.cpp index ec4e25612be..0efff78e6ed 100644 --- a/src/droid.cpp +++ b/src/droid.cpp @@ -3005,6 +3005,23 @@ bool vtolReadyToRearm(const DROID *psDroid, const STRUCTURE *psStruct) return true; } +// Fills all the weapons on a VTOL droid. +void fillVtolDroid(DROID *psDroid) +{ + CHECK_DROID(psDroid); + if (!psDroid->isVtol()) + { + return; + } + for (unsigned int i = 0; i < psDroid->numWeaps; ++i) + { + // Set rearm value to no runs made. + psDroid->asWeaps[i].usedAmmo = 0; + psDroid->asWeaps[i].ammo = psDroid->getWeaponStats(i)->upgrade[psDroid->player].numRounds; + psDroid->asWeaps[i].lastFired = 0; + } +} + // true if a vtol droid currently returning to be rearmed bool DROID::isVtolRearming() const { diff --git a/src/droid.h b/src/droid.h index 9eaf4bdc272..1d7c8f2befe 100644 --- a/src/droid.h +++ b/src/droid.h @@ -251,6 +251,8 @@ UWORD getNumAttackRuns(const DROID *psDroid, int weapon_slot); void assignVTOLPad(DROID *psNewDroid, STRUCTURE *psReArmPad); // true if a vtol is waiting to be rearmed by a particular rearm pad bool vtolReadyToRearm(const DROID *psDroid, const STRUCTURE *psStruct); +// Fill all the weapons on a VTOL droid. +void fillVtolDroid(DROID *psDroid); // see if there are any other vtols attacking the same target // but still rearming diff --git a/src/mission.cpp b/src/mission.cpp index 8ad1c4a0640..866be94dec1 100644 --- a/src/mission.cpp +++ b/src/mission.cpp @@ -653,8 +653,7 @@ void missionFlyTransportersIn(SDWORD iPlayer, bool bTrackTransporter) /* Saves the necessary data when moving from a home base Mission to an OffWorld mission */ static void saveMissionData() { - UDWORD inc; - bool bRepairExists; + bool bRepairExists = false, bRearmPadExists = false; debug(LOG_SAVE, "called"); @@ -663,9 +662,8 @@ static void saveMissionData() //clear out the audio audio_StopAll(); - bRepairExists = false; //set any structures currently being built to completed for the selected player - mutating_list_iterate(apsStructLists[selectedPlayer], [&bRepairExists](STRUCTURE* psStruct) + mutating_list_iterate(apsStructLists[selectedPlayer], [&bRepairExists, &bRearmPadExists](STRUCTURE* psStruct) { STRUCTURE* psStructBeingBuilt; if (psStruct->status == SS_BEING_BUILT) @@ -683,23 +681,35 @@ static void saveMissionData() } } } - //check if have a completed repair facility on home world - if (psStruct->pStructureType->type == REF_REPAIR_FACILITY && psStruct->status == SS_BUILT) + //check if have a completed repair facility or rearming pad on home world + if (psStruct->status == SS_BUILT && psStruct->pStructureType) { - bRepairExists = true; + if (psStruct->pStructureType->type == REF_REPAIR_FACILITY) + { + bRepairExists = true; + } + else if (psStruct->pStructureType->type == REF_REARM_PAD) + { + bRearmPadExists = true; + } } return IterationResult::CONTINUE_ITERATION; }); - //repair all droids back at home base if have a repair facility - if (bRepairExists) + //repair and rearm all droids back at home base if have a repair facility or rearming pad + if (bRepairExists || bRearmPadExists) { for (DROID* psDroid : apsDroidLists[selectedPlayer]) { - if (psDroid->isDamaged()) + bool vtolAndPadsExist = (psDroid->isVtol() && bRearmPadExists); + if ((bRepairExists || vtolAndPadsExist) && psDroid->isDamaged()) { psDroid->body = psDroid->originalBody; } + if (vtolAndPadsExist) + { + fillVtolDroid(psDroid); + } } } @@ -741,7 +751,7 @@ static void saveMissionData() mission.homeLZ_X = getLandingX(selectedPlayer); mission.homeLZ_Y = getLandingY(selectedPlayer); - for (inc = 0; inc < MAX_PLAYERS; inc++) + for (unsigned int inc = 0; inc < MAX_PLAYERS; ++inc) { mission.apsStructLists[inc] = apsStructLists[inc]; mission.apsDroidLists[inc] = apsDroidLists[inc]; diff --git a/src/structure.cpp b/src/structure.cpp index 91e337bfb46..7510b8c8ae1 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -3555,13 +3555,7 @@ static void aiUpdateStructure(STRUCTURE *psStructure, bool isMission) if (pointsToAdd >= psDroid->weight) // amount required is a factor of the droid weight { // We should be fully loaded by now. - for (unsigned i = 0; i < psDroid->numWeaps; i++) - { - // set rearm value to no runs made - psDroid->asWeaps[i].usedAmmo = 0; - psDroid->asWeaps[i].ammo = psDroid->getWeaponStats(i)->upgrade[psDroid->player].numRounds; - psDroid->asWeaps[i].lastFired = 0; - } + fillVtolDroid(psDroid); objTrace(psDroid->id, "fully loaded"); } else