Skip to content

Commit 4faa5ea

Browse files
committed
Added complete retail incompatible version.
1 parent 9cb2583 commit 4faa5ea

2 files changed

Lines changed: 87 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ class TunnelTracker : public MemoryPoolObject,
6666
void healObjects(); ///< heal all objects within the tunnel
6767
#endif
6868

69+
#if RETAIL_COMPATIBLE_CRC
6970
Bool isLastTunnel() const {return m_tunnelCount == 1;}///< TunnelContains are allowed to ask if they are the last one ahead of deletion time
71+
#else
72+
Bool isLastTunnel() const { return m_tunnelIDs.size() == 1; }///< TunnelContains are allowed to ask if they are the last one ahead of deletion time
73+
#endif
7074

7175
const std::list< ObjectID > *getContainerList() const {return &m_tunnelIDs;}
7276

@@ -87,7 +91,9 @@ class TunnelTracker : public MemoryPoolObject,
8791
std::list< ObjectID > m_xferContainList;///< for loading of m_containList during post processing
8892
Int m_containListSize; ///< size of the contain list
8993
UnsignedInt m_heroUnitsContained; ///< cached hero count
94+
#if RETAIL_COMPATIBLE_CRC
9095
UnsignedInt m_tunnelCount; ///< How many tunnels have registered so we know when we should kill our contain list
96+
#endif
9197
UnsignedInt m_framesForFullHeal; ///< How many frames it takes to fully heal a unit
9298
Bool m_needsFullHealTimeUpdate; ///< Set to true when needing to recalc full heal time to batch the operation
9399

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

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@
5050
// ------------------------------------------------------------------------
5151
TunnelTracker::TunnelTracker()
5252
{
53+
#if RETAIL_COMPATIBLE_CRC
5354
m_tunnelCount = 0;
55+
#endif
5456
m_containListSize = 0;
5557
m_heroUnitsContained = 0;
5658
m_curNemesisID = INVALID_ID;
@@ -224,21 +226,32 @@ Bool TunnelTracker::isInContainer( Object *obj )
224226
// ------------------------------------------------------------------------
225227
void TunnelTracker::onTunnelCreated( const Object *newTunnel )
226228
{
229+
DEBUG_ASSERTCRASH(std::find(m_tunnelIDs.begin(), m_tunnelIDs.end(), newTunnel->getID()) != m_tunnelIDs.end(),
230+
("TunnelTracker::onTunnelCreated - New tunnel was already added; this shouldn't happen"));
231+
232+
#if RETAIL_COMPATIBLE_CRC
227233
m_tunnelCount++;
234+
#endif
228235
m_tunnelIDs.push_back( newTunnel->getID() );
229236
m_needsFullHealTimeUpdate = true;
230237
}
231238

232239
// ------------------------------------------------------------------------
233240
void TunnelTracker::onTunnelDestroyed( const Object *deadTunnel )
234241
{
242+
#if RETAIL_COMPATIBLE_CRC
243+
235244
DEBUG_ASSERTCRASH(static_cast<Int>(m_tunnelCount) > 0 && m_tunnelCount == m_tunnelIDs.size(),
236245
("TunnelTracker::onTunnelDestroyed - Tunnel count is unexpected"));
237-
DEBUG_ASSERTCRASH(std::find(m_tunnelIDs.begin(), m_tunnelIDs.end(), deadTunnel->getID()) != m_tunnelIDs.end(),
238-
("TunnelTracker::onTunnelDestroyed - Attempting to remove object '%s' that has never been tracked as a tunnel", deadTunnel->getName().str()));
246+
247+
const size_t oldSize = m_tunnelIDs.size();
248+
m_tunnelIDs.remove(deadTunnel->getID());
249+
250+
static_cast<void>(oldSize);
251+
DEBUG_ASSERTCRASH(oldSize != m_tunnelIDs.size(),
252+
("TunnelTracker::onTunnelDestroyed - Attempting to remove object '%s' that has never been tracked as a tunnel"));
239253

240254
m_tunnelCount--;
241-
m_tunnelIDs.remove( deadTunnel->getID() );
242255
m_needsFullHealTimeUpdate = true;
243256

244257
if( m_tunnelCount == 0 )
@@ -265,6 +278,48 @@ void TunnelTracker::onTunnelDestroyed( const Object *deadTunnel )
265278
obj->onContainedBy( tunnel );
266279
}
267280
}
281+
282+
#else
283+
284+
const std::list<ObjectID>::iterator it = std::find(m_tunnelIDs.begin(), m_tunnelIDs.end(), deadTunnel->getID());
285+
if (it == m_tunnelIDs.end())
286+
{
287+
DEBUG_CRASH(("TunnelTracker::onTunnelDestroyed - Attempting to remove object '%s' that has never been tracked as a tunnel",
288+
deadTunnel->getName().str()));
289+
}
290+
else
291+
{
292+
DEBUG_ASSERTCRASH(std::find(std::next(it), m_tunnelIDs.end(), deadTunnel->getID()) == m_tunnelIDs.end(),
293+
("TunnelTracker::onTunnelDestroyed - Tunnel should have been tracked only once"));
294+
295+
m_tunnelIDs.erase(it);
296+
}
297+
298+
m_needsFullHealTimeUpdate = true;
299+
300+
if( m_tunnelIDs.empty() )
301+
{
302+
// Kill everyone in our contain list. Cave in!
303+
iterateContained( destroyObject, nullptr, FALSE );
304+
m_containList.clear();
305+
m_containListSize = 0;
306+
}
307+
else
308+
{
309+
Object *validTunnel = TheGameLogic->findObjectByID( m_tunnelIDs.front() );
310+
311+
// Otherwise, make sure nobody inside remembers the dead tunnel as the one they entered
312+
// (scripts need to use so there must be something valid here)
313+
for(ContainedItemsList::iterator it = m_containList.begin(); it != m_containList.end(); )
314+
{
315+
Object* obj = *it;
316+
++it;
317+
if( obj->getContainedBy() == deadTunnel )
318+
obj->onContainedBy( validTunnel );
319+
}
320+
}
321+
322+
#endif // RETAIL_COMPATIBLE_CRC
268323
}
269324

270325
// ------------------------------------------------------------------------
@@ -379,13 +434,19 @@ void TunnelTracker::crc( Xfer *xfer )
379434
// ------------------------------------------------------------------------------------------------
380435
/** Xfer method
381436
* Version Info:
382-
* 1: Initial version */
437+
* 1: Initial version
438+
* 2: TheSuperHackers @tweak Removed m_tunnelCount (should always be equal to m_tunnelIDs.size())
439+
*/
383440
// ------------------------------------------------------------------------------------------------
384441
void TunnelTracker::xfer( Xfer *xfer )
385442
{
386443

387444
// version
445+
#if RETAIL_COMPATIBLE_XFER_SAVE
388446
XferVersion currentVersion = 1;
447+
#else
448+
XferVersion currentVersion = 2;
449+
#endif
389450
XferVersion version = currentVersion;
390451
xfer->xferVersion( &version, currentVersion );
391452

@@ -424,8 +485,22 @@ void TunnelTracker::xfer( Xfer *xfer )
424485
m_needsFullHealTimeUpdate = true;
425486
}
426487

427-
// tunnel count
428-
xfer->xferUnsignedInt( &m_tunnelCount );
488+
#if RETAIL_COMPATIBLE_CRC
489+
if (version <= 1)
490+
{
491+
xfer->xferUnsignedInt(&m_tunnelCount);
492+
}
493+
else
494+
{
495+
m_tunnelCount = m_tunnelIDs.size();
496+
}
497+
#else
498+
if (version <= 1)
499+
{
500+
UnsignedInt tunnelCount = m_tunnelIDs.size();
501+
xfer->xferUnsignedInt(&tunnelCount);
502+
}
503+
#endif
429504

430505
}
431506

0 commit comments

Comments
 (0)