Skip to content

Commit

Permalink
Fill VTOLs when going offworld
Browse files Browse the repository at this point in the history
If, there are any built VTOL Rearming Pads. This is similar to droids getting repaired automatically if a Repair Facility is on the map.
  • Loading branch information
KJeff01 committed Aug 22, 2024
1 parent b826514 commit 29a6230
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
17 changes: 17 additions & 0 deletions src/droid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions src/droid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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)
Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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];
Expand Down
8 changes: 1 addition & 7 deletions src/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29a6230

Please sign in to comment.