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

Reset structure functionality references to objects when going offworld #4047

Merged
merged 1 commit into from
Aug 23, 2024
Merged
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
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
Loading