Skip to content
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
8 changes: 6 additions & 2 deletions Tactical/Rotting Corpses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ void RemoveCorpse( INT32 iCorpseID )
DeleteAniTile( gRottingCorpse[ iCorpseID ].pAniTile );

FreeCorpsePalettes( &( gRottingCorpse[ iCorpseID ] ) );

const auto sGridNo = gRottingCorpse[iCorpseID].def.sGridNo;
auto pStructure = FindLastStructure(sGridNo, STRUCTURE_CORPSE);
DeleteStructureFromWorld(pStructure);
}

BOOLEAN CreateCorpsePalette( ROTTING_CORPSE *pCorpse )
Expand Down Expand Up @@ -1770,10 +1774,10 @@ BOOLEAN IsValidDecapitationCorpse( ROTTING_CORPSE *pCorpse )

ROTTING_CORPSE *GetCorpseAtGridNo( INT32 sGridNo, INT8 bLevel )
{
STRUCTURE *pStructure, *pBaseStructure;
STRUCTURE *pStructure, *pBaseStructure;
INT32 sBaseGridNo;

pStructure = FindStructure( sGridNo, STRUCTURE_CORPSE );
pStructure = FindLastStructure( sGridNo, STRUCTURE_CORPSE );

if ( pStructure != NULL )
{
Expand Down
28 changes: 28 additions & 0 deletions TileEngine/structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,7 @@ STRUCTURE * SwapStructureForPartnerForcingGraphicalChange( INT32 sGridNo, STRUCT
}
#endif

// Finds the first structure with matching flag
STRUCTURE * FindStructure( INT32 sGridNo, UINT32 fFlags )
{
// finds a structure that matches any of the given flags
Expand All @@ -1451,6 +1452,33 @@ STRUCTURE * FindStructure( INT32 sGridNo, UINT32 fFlags )
return( NULL );
}

// Finds the last structure with matching flag
STRUCTURE* FindLastStructure(INT32 sGridNo, UINT32 fFlags)
{
// finds a structure that matches any of the given flags
STRUCTURE* pCurrent;
STRUCTURE* pLastMatch = nullptr;

//bug fix for win98 crash when traveling between sectors
if ( TileIsOutOfBounds(sGridNo) )
{
return(NULL);
}

pCurrent = gpWorldLevelData[sGridNo].pStructureHead;
while ( pCurrent != NULL )
{
if ( (pCurrent->fFlags & fFlags) != 0 )
{
pLastMatch = pCurrent;
//return(pCurrent);
}
pCurrent = pCurrent->pNext;
}

return(pLastMatch);
}

STRUCTURE * FindNextStructure( STRUCTURE * pStructure, UINT32 fFlags )
{
STRUCTURE * pCurrent;
Expand Down
1 change: 1 addition & 0 deletions TileEngine/structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ BOOLEAN DeleteStructureFromWorld( STRUCTURE * pStructure );
// functions to find a structure in a location
//
STRUCTURE * FindStructure( INT32 sGridNo, UINT32 fFlags );
STRUCTURE* FindLastStructure(INT32 sGridNo, UINT32 fFlags);
STRUCTURE * FindNextStructure( STRUCTURE * pStructure, UINT32 fFlags );
STRUCTURE * FindStructureByID( INT32 sGridNo, UINT16 usStructureID );
STRUCTURE * FindBaseStructure( STRUCTURE * pStructure );
Expand Down
Loading