Skip to content

Commit 3c9397c

Browse files
authored
[GEN][ZH] Refactor evacuation code in OpenContain, TunnelContain (#1007)
1 parent 824ca01 commit 3c9397c

File tree

5 files changed

+35
-43
lines changed

5 files changed

+35
-43
lines changed

Generals/Code/GameEngine/Include/Common/TunnelTracker.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class TunnelTracker : public MemoryPoolObject,
4949
UnsignedInt getContainCount() const { return m_containListSize; }
5050
Int getContainMax() const;
5151
const ContainedItemsList* getContainedItemsList() const { return &m_containList; }
52+
void swapContainedItemsList(ContainedItemsList& newList);
5253

5354
Bool isValidContainerFor(const Object* obj, Bool checkCapacity) const;
5455
void addToContainList( Object *obj ); ///< add 'obj' to contain list

Generals/Code/GameEngine/Source/Common/RTS/TunnelTracker.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ Int TunnelTracker::getContainMax() const
107107
return TheGlobalData->m_maxTunnelCapacity;
108108
}
109109

110+
// ------------------------------------------------------------------------
111+
void TunnelTracker::swapContainedItemsList(ContainedItemsList& newList)
112+
{
113+
m_containList.swap(newList);
114+
m_containListSize = (Int)m_containList.size();
115+
}
116+
110117
// ------------------------------------------------------------------------
111118
void TunnelTracker::updateNemesis(const Object *target)
112119
{

Generals/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ void TunnelContain::removeFromContain( Object *obj, Bool exposeStealthUnits )
102102
if( owningPlayer == NULL )
103103
return; //game tear down. We do the onRemove* stuff first because this is allowed to fail but that still needs to be done
104104

105-
if( ! owningPlayer->getTunnelSystem()->isInContainer( obj ) )
106-
{
107-
return;
108-
}
109-
110105
owningPlayer->getTunnelSystem()->removeFromContain( obj, exposeStealthUnits );
111106

112107
}
@@ -116,16 +111,17 @@ void TunnelContain::removeFromContain( Object *obj, Bool exposeStealthUnits )
116111
//-------------------------------------------------------------------------------------------------
117112
void TunnelContain::removeAllContained( Bool exposeStealthUnits )
118113
{
114+
ContainedItemsList list;
119115
Player *owningPlayer = getObject()->getControllingPlayer();
120-
const ContainedItemsList *fullList = owningPlayer->getTunnelSystem()->getContainedItemsList();
116+
owningPlayer->getTunnelSystem()->swapContainedItemsList(list);
117+
118+
ContainedItemsList::iterator it = list.begin();
121119

122-
Object *obj;
123-
ContainedItemsList::const_iterator it;
124-
it = (*fullList).begin();
125-
while( it != (*fullList).end() )
120+
while ( it != list.end() )
126121
{
127-
obj = *it;
128-
it++;
122+
Object *obj = *it++;
123+
DEBUG_ASSERTCRASH( obj, ("Contain list must not contain NULL element"));
124+
129125
removeFromContain( obj, exposeStealthUnits );
130126
}
131127
}

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -440,33 +440,25 @@ void OpenContain::killAllContained( void )
440440
// to the host container, which then attempts to remove all remaining occupants
441441
// on the death of the host container. This is reproducible by shooting with
442442
// Neutron Shells on a GLA Technical containing GLA Terrorists.
443+
443444
ContainedItemsList list;
444445
list.swap(m_containList);
445446
m_containListSize = 0;
446447

447448
ContainedItemsList::iterator it = list.begin();
448449

449-
while ( it != list.end() )
450+
while ( it != list.end() )
450451
{
451-
Object *rider = *it;
452-
453-
DEBUG_ASSERTCRASH( rider, ("Contain list must not contain NULL element"));
454-
if ( rider )
455-
{
456-
it = list.erase(it);
457-
458-
onRemoving( rider );
459-
rider->onRemovedFrom( getObject() );
460-
rider->kill();
461-
462-
}
463-
else
464-
++it;
452+
Object *rider = *it++;
465453

466-
} // end while
467-
468-
469-
DEBUG_ASSERTCRASH( m_containListSize == 0, ("killallcontain just made a booboo, list size != zero.") );
454+
DEBUG_ASSERTCRASH( rider, ("Contain list must not contain NULL element"));
455+
if ( rider )
456+
{
457+
onRemoving( rider );
458+
rider->onRemovedFrom( getObject() );
459+
rider->kill();
460+
}
461+
}
470462

471463
} // end killAllContained
472464

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/TunnelContain.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ void TunnelContain::removeFromContain( Object *obj, Bool exposeStealthUnits )
102102
if( owningPlayer == NULL )
103103
return; //game tear down. We do the onRemove* stuff first because this is allowed to fail but that still needs to be done
104104

105-
if( ! owningPlayer->getTunnelSystem()->isInContainer( obj ) )
106-
{
107-
return;
108-
}
109-
110105
owningPlayer->getTunnelSystem()->removeFromContain( obj, exposeStealthUnits );
111106

112107
}
@@ -177,16 +172,17 @@ void TunnelContain::killAllContained( void )
177172
//-------------------------------------------------------------------------------------------------
178173
void TunnelContain::removeAllContained( Bool exposeStealthUnits )
179174
{
175+
ContainedItemsList list;
180176
Player *owningPlayer = getObject()->getControllingPlayer();
181-
const ContainedItemsList *fullList = owningPlayer->getTunnelSystem()->getContainedItemsList();
177+
owningPlayer->getTunnelSystem()->swapContainedItemsList(list);
182178

183-
Object *obj;
184-
ContainedItemsList::const_iterator it;
185-
it = (*fullList).begin();
186-
while( it != (*fullList).end() )
179+
ContainedItemsList::iterator it = list.begin();
180+
181+
while ( it != list.end() )
187182
{
188-
obj = *it;
189-
it++;
183+
Object *obj = *it++;
184+
DEBUG_ASSERTCRASH( obj, ("Contain list must not contain NULL element"));
185+
190186
removeFromContain( obj, exposeStealthUnits );
191187
}
192188
}

0 commit comments

Comments
 (0)