Skip to content

Commit

Permalink
Reset structure functionality references to objects when going offworld
Browse files Browse the repository at this point in the history
  • Loading branch information
KJeff01 committed Aug 23, 2024
1 parent 736fae8 commit 1de0822
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/mission.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ static UBYTE bPlayCountDown;

//FUNCTIONS**************
static void addLandingLights(UDWORD x, UDWORD y);
static void resetHomeStructureObjects();
static bool startMissionOffClear(const char *pGame);
static bool startMissionOffKeep(const char *pGame);
static bool startMissionCampaignStart(const char *pGame);
Expand Down Expand Up @@ -188,6 +189,38 @@ bool MissionResUp = false;
static SDWORD g_iReinforceTime = 0;


//Remove soon-to-be illegal references to objects for some structures before going offWorld.
static void resetHomeStructureObjects()
{
for (unsigned int i = 0; i < MAX_PLAYERS; ++i)
{
for (STRUCTURE *psStruct : apsStructLists[i])
{
if (!psStruct->pFunctionality || !psStruct->pStructureType)
{
continue;
}
if (psStruct->pStructureType->type == REF_REPAIR_FACILITY)
{
REPAIR_FACILITY *psRepairFac = &psStruct->pFunctionality->repairFacility;
if (psRepairFac->psObj)
{
psRepairFac->psObj = nullptr;
psRepairFac->state = RepairState::Idle;
}
}
else if (psStruct->pStructureType->type == REF_REARM_PAD)
{
REARM_PAD *psReArmPad = &psStruct->pFunctionality->rearmPad;
if (psReArmPad->psObj)
{
psReArmPad->psObj = nullptr;
}
}
}
}
}

//returns true if on an off world mission
bool missionIsOffworld()
{
Expand Down Expand Up @@ -720,6 +753,8 @@ static void saveMissionData()
}
}

resetHomeStructureObjects(); //get rid of soon-to-be illegal references of droids in repair facilities and rearming pads.

//save the mission data
mission.psMapTiles = std::move(psMapTiles);
mission.mapWidth = mapWidth;
Expand Down

0 comments on commit 1de0822

Please sign in to comment.