Skip to content

Commit fb5534b

Browse files
committed
Optimized Custom Status Codes + Fixed Custom Damage doesn't work with estimate damage
1 parent aa8a943 commit fb5534b

File tree

12 files changed

+152
-492
lines changed

12 files changed

+152
-492
lines changed

GeneralsMD/Code/GameEngine/Include/GameClient/GameClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class GameClient : public SubsystemInterface,
160160
void informClientNewDrawable(Drawable *draw);
161161
void addDrawableToEfficientList(Drawable *draw);
162162
void removeDrawableFromEfficientList(Drawable *draw);
163-
void clearEfficientDrawablesList() { m_drawablesIterateListMarkedForClear = TRUE; }
163+
void clearEfficientDrawablesList();
164164
void setEfficientDrawableRegion(Region3D *region) { m_axisAlignedRegion.lo = region->lo; m_axisAlignedRegion.hi = region->hi; }
165165
Region3D *getEfficientDrawableRegion() { return &m_axisAlignedRegion; }
166166
//void setEfficientDrawableRegion(const Coord3D *loWorld, const Coord3D *hiWorld) { m_loWorld.set(loWorld); m_hiWorld.set(hiWorld); }

GeneralsMD/Code/GameEngine/Include/GameLogic/Armor.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ class ArmorStore : public SubsystemInterface
168168
CustomDamageType m_customDamageTypeParse;
169169
AsciiString m_customDamageTypeParseNext;
170170

171-
Bool findNameInTypesList(NameKeyType nameKey, Real damage, const CustomDamageTypeVec& coefficients, DamageType &linkDamageType);
172-
Bool isNameInTypesList(NameKeyType nameKey) const;
171+
Bool findNameInTypesList(NameKeyType nameKey, Real &damage, const CustomDamageTypeVec& coefficients, DamageType &linkDamageType);
172+
//Bool isNameInTypesList(NameKeyType nameKey) const;
173173
std::vector<NameKeyType> GetLinkInTypesList(NameKeyType nameKey);
174-
DamageType GetDeclaredLinkDamageType(NameKeyType nameKey);
175-
Real GetDeclaredCoefficient(NameKeyType nameKey);
174+
//DamageType GetDeclaredLinkDamageType(NameKeyType nameKey);
175+
//Real GetDeclaredCoefficient(NameKeyType nameKey);
176176

177177
static void parseArmorDefinition(INI* ini);
178178
static void parseArmorExtendDefinition(INI* ini);

GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,9 @@ class Object : public Thing, public Snapshot
401401
void setStatus( ObjectStatusMaskType objectStatus, Bool set = true );
402402
inline void clearStatus( ObjectStatusMaskType objectStatus ) { setStatus( objectStatus, false ); }
403403
void setCustomStatus( const AsciiString& objectCustomStatus, Bool set = true );
404-
inline void clearCustomStatus( const AsciiString& statusName ) { setCustomStatus( statusName, false ); } // This is not being used so far.
404+
void clearCustomStatus( const AsciiString& statusName ) { setCustomStatus( statusName, false ); } // This is not being used so far.
405405
void setCustomStatus( const std::vector<AsciiString>& objectCustomStatus, Bool set = true );
406-
inline void clearCustomStatus( const std::vector<AsciiString>& statusName ) { setCustomStatus( statusName, false ); } // This is not being used so far.
406+
void clearCustomStatus( const std::vector<AsciiString>& statusName ) { setCustomStatus( statusName, false ); } // This is not being used so far.
407407
void updateUpgradeModules(); ///< We need to go through our Upgrade Modules and see which should be activated
408408
UpgradeMaskType getObjectCompletedUpgradeMask() const { return m_objectUpgradesCompleted; } ///< Upgrades I complete locally
409409

GeneralsMD/Code/GameEngine/Include/GameLogic/WeaponBonusConditionFlags.h

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,42 @@
2929
#pragma once
3030

3131
typedef UnsignedInt WeaponBonusConditionFlags;
32-
typedef std::hash_map< AsciiString, Int, rts::hash<AsciiString>, rts::equal_to<AsciiString> > ObjectCustomStatusType;
32+
//typedef std::hash_map< AsciiString, Int, rts::hash<AsciiString>, rts::equal_to<AsciiString> > ObjectCustomStatusType;
33+
34+
//-------------------------------------------------------------------------------------------------
35+
inline Bool checkWithinStringVec(const AsciiString& str, const std::vector<AsciiString>& vec)
36+
{
37+
for(std::vector<AsciiString>::const_iterator it = vec.begin(); it != vec.end(); ++it)
38+
{
39+
if((*it) == str)
40+
return TRUE;
41+
}
42+
return FALSE;
43+
}
44+
45+
//-------------------------------------------------------------------------------------------------
46+
inline Bool checkWithinStringVecSize(const AsciiString& str, const std::vector<AsciiString>& vec, Int size)
47+
{
48+
for(int i = 0; i < size; i++)
49+
{
50+
if(str == vec[i])
51+
return TRUE;
52+
}
53+
return FALSE;
54+
}
55+
56+
//-------------------------------------------------------------------------------------------------
57+
inline Bool removeWithinStringVec(const AsciiString& str, std::vector<AsciiString> &vec)
58+
{
59+
std::vector<AsciiString>::iterator it = vec.begin();
60+
for(it; it != vec.end();)
61+
{
62+
if((*it) == str)
63+
{
64+
it = vec.erase( it );
65+
return TRUE;
66+
}
67+
++it;
68+
}
69+
return FALSE;
70+
}

GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,15 @@ void GameClient::removeDrawableFromEfficientList(Drawable *draw)
951951
}
952952
}
953953

954+
/** -----------------------------------------------------------------------------------------------
955+
* Clear Efficient Drawable List, Mark for Later
956+
*/
957+
void GameClient::clearEfficientDrawablesList()
958+
{
959+
m_drawablesIterateListMarkedForClear = TRUE;
960+
TheTacticalView->setUpdateEfficient();
961+
}
962+
954963
/**Helper function to update fake GLA structures to become visible to certain players.
955964
We should only call this during critical moments, such as changing teams, changing to
956965
observer, etc.*/

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Armor.cpp

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,12 @@ Real ArmorTemplate::adjustDamage(DamageType t, Real damage, const AsciiString& c
190190
for(CustomDamageTypeVec::const_iterator it = m_customCoefficients.begin(); it != m_customCoefficients.begin(); ++it )
191191
{
192192
if (nameKey == it->first)
193-
{
194-
damage *= it->second;
195-
return damage;
196-
}
193+
return damage *= it->second;
197194
}
198195

199196
// returns true if found multiplier
200197
DamageType declaredLinkedDamage = DAMAGE_NUM_TYPES;
201-
if(TheArmorStore->findNameInTypesList(nameKey, damage, m_customMultCoefficients, declaredLinkedDamage))
198+
if(TheArmorStore->findNameInTypesList(nameKey, damage, m_customCoefficients, declaredLinkedDamage))
202199
{
203200
if(declaredLinkedDamage != DAMAGE_NUM_TYPES)
204201
damage *= m_damageCoefficient[declaredLinkedDamage];
@@ -331,10 +328,9 @@ Real ArmorTemplate::adjustDamage(DamageType t, Real damage, const AsciiString& c
331328
{
332329
// Compatible with ArmorExtend
333330
NameKeyType nameKey = TheNameKeyGenerator->nameToKey( damageNameStr );
334-
CustomDamageTypeVec::iterator it = self->m_customCoefficients.begin();
335331

336332
Bool hasSet = false;
337-
for(it; it != self->m_customCoefficients.end(); ++it)
333+
for(CustomDamageTypeVec::iterator it = self->m_customCoefficients.begin(); it != self->m_customCoefficients.end(); ++it)
338334
{
339335
if(it->first == nameKey)
340336
{
@@ -381,10 +377,9 @@ void ArmorTemplate::parseArmorMultiplier(INI* ini, void* instance, void* /* stor
381377
else
382378
{
383379
NameKeyType nameKey = TheNameKeyGenerator->nameToKey( damageNameStr );
384-
CustomDamageTypeVec::iterator it = self->m_customMultCoefficients.begin();
385380

386381
Bool hasSet = false;
387-
for(it; it != self->m_customMultCoefficients.end(); ++it)
382+
for(CustomDamageTypeVec::iterator it = self->m_customMultCoefficients.begin(); it != self->m_customMultCoefficients.end(); ++it)
388383
{
389384
if(it->first == nameKey)
390385
{
@@ -694,15 +689,14 @@ void ArmorStore::parseCustomDamageTypesDefinition(INI* ini)
694689
}
695690

696691
//-------------------------------------------------------------------------------------------------
697-
Bool ArmorStore::findNameInTypesList(NameKeyType nameKey, Real damage, const CustomDamageTypeVec& coefficients, DamageType &linkDamageType)
692+
Bool ArmorStore::findNameInTypesList(NameKeyType nameKey, Real &damage, const CustomDamageTypeVec& coefficients, DamageType &linkDamageType)
698693
{
699694
CustomDamageTypesMap::const_iterator it = m_customDamageTypes.find(nameKey);
700695
if(it != m_customDamageTypes.end())
701696
{
702697
// Find if any of CustomDamageType is assigned with any of the CustomArmor.
703698
// Ignore if the unit does not haven any CustomArmor Coefficient assigned or the Linked Custom Armor List is empty.
704-
std::vector<NameKeyType> nameKeyListParent;
705-
nameKeyListParent = GetLinkInTypesList(nameKey);
699+
std::vector<NameKeyType> nameKeyListParent = it->second.m_customDamageTypeLink;
706700
if (!coefficients.empty() && !nameKeyListParent.empty())
707701
{
708702
//std::vector<NameKeyType> nameKeyListParent;
@@ -716,9 +710,7 @@ Bool ArmorStore::findNameInTypesList(NameKeyType nameKey, Real damage, const Cus
716710
{
717711
// Check if there's a String List that exists for the Child.
718712
// If we do, clear the parents DNA that has been searched and find relative Childs DNA.
719-
//nameKeyListParent.clear();
720713
nameKeyListParent = nameKeyListChild;
721-
nameKeyListChild.clear();
722714

723715
// Begin finding the LinkedCustomDamageTypes and see if they are exactly the same as configured Custom Armor List.
724716
for (std::vector<NameKeyType>::const_iterator it2 = nameKeyListParent.begin();
@@ -729,11 +721,11 @@ Bool ArmorStore::findNameInTypesList(NameKeyType nameKey, Real damage, const Cus
729721
// This is to prevent infinite loop.
730722
//if(nameKeyListChecked[*it2] == 1)
731723
Bool checked = FALSE;
732-
for (std::vector<NameKeyType>::const_iterator str_it = nameKeyListChecked.begin();
733-
str_it != nameKeyListChecked.end();
734-
++str_it)
724+
for (std::vector<NameKeyType>::const_iterator key_it = nameKeyListChecked.begin();
725+
key_it != nameKeyListChecked.end();
726+
++key_it)
735727
{
736-
if((*str_it) == (*it2))
728+
if((*key_it) == (*it2))
737729
{
738730
checked = TRUE;
739731
break;
@@ -786,27 +778,24 @@ Bool ArmorStore::findNameInTypesList(NameKeyType nameKey, Real damage, const Cus
786778
}
787779

788780
//-------------------------------------------------------------------------------------------------
789-
Bool ArmorStore::isNameInTypesList(NameKeyType nameKey) const
781+
/*Bool ArmorStore::isNameInTypesList(NameKeyType nameKey) const
790782
{
791783
CustomDamageTypesMap::const_iterator it = m_customDamageTypes.find(nameKey);
792784
793785
// The found the CustomDamageType at the declared CustomDamageTypes data.
794786
if (it != m_customDamageTypes.end())
795-
{
796787
return TRUE;
797-
}
798-
return FALSE;
799-
}
788+
else
789+
return FALSE;
790+
}*/
800791

801792
//-------------------------------------------------------------------------------------------------
802793
std::vector<NameKeyType> ArmorStore::GetLinkInTypesList(NameKeyType nameKey)
803794
{
804795
CustomDamageTypesMap::const_iterator it = m_customDamageTypes.find(nameKey);
805-
for(it; it != m_customDamageTypes.end(); ++it)
806-
{
807-
if(it->first == nameKey)
808-
return it->second.m_customDamageTypeLink;
809-
}
796+
if(it != m_customDamageTypes.end())
797+
return it->second.m_customDamageTypeLink;
798+
810799
std::vector<NameKeyType> dummyList;
811800
return dummyList;
812801

@@ -819,7 +808,7 @@ std::vector<NameKeyType> ArmorStore::GetLinkInTypesList(NameKeyType nameKey)
819808
}
820809

821810
//-------------------------------------------------------------------------------------------------
822-
DamageType ArmorStore::GetDeclaredLinkDamageType(NameKeyType nameKey)
811+
/*DamageType ArmorStore::GetDeclaredLinkDamageType(NameKeyType nameKey)
823812
{
824813
CustomDamageTypesMap::const_iterator it = m_customDamageTypes.find(nameKey);
825814
@@ -847,3 +836,4 @@ Real ArmorStore::GetDeclaredCoefficient(NameKeyType nameKey)
847836
}
848837
return -1.0f;
849838
}
839+
*/

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,16 +1665,7 @@ void RiderChangeContain::doStatusChecks()
16651665
{
16661666
// If the status is not present in the Previous Status, yet present Recently, check if it is a Valid Status to change a Rider
16671667
//std::vector<AsciiString>::const_iterator it2 = m_prevCustomStatusTypes.find((*it).first);
1668-
Bool hasPrevious = false;
1669-
for (std::vector<AsciiString>::const_iterator it2 = m_prevCustomStatusTypes.begin(); it2 != m_prevCustomStatusTypes.end(); ++it2)
1670-
{
1671-
if((*it2) == (*it))
1672-
{
1673-
hasPrevious = true;
1674-
break;
1675-
}
1676-
}
1677-
if(!hasPrevious)
1668+
if(!checkWithinStringVec((*it), m_prevCustomStatusTypes))
16781669
{
16791670
if(riderTemplateIsValidChange( *it ) )
16801671
break;
@@ -1683,16 +1674,7 @@ void RiderChangeContain::doStatusChecks()
16831674
for (std::vector<AsciiString>::const_iterator it = m_prevCustomStatusTypes.begin(); it != m_prevCustomStatusTypes.end(); ++it)
16841675
{
16851676
// If the status is present in the Previous Status, yet not present Recently, check if it is a Valid Template Removal
1686-
Bool hasNow = false;
1687-
for (std::vector<AsciiString>::const_iterator it2 = NewCustomStatusTypes.begin(); it2 != NewCustomStatusTypes.end(); ++it2)
1688-
{
1689-
if((*it2) == (*it))
1690-
{
1691-
hasNow = true;
1692-
break;
1693-
}
1694-
}
1695-
if(!hasNow)
1677+
if(!checkWithinStringVec((*it), NewCustomStatusTypes))
16961678
{
16971679
if(riderTemplateIsValidRemoval( *it ) )
16981680
break;

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Die/DieModule.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,9 @@ Bool DieMuxData::isDieApplicable(const Object* obj, const DamageInfo *damageInfo
102102
if( m_requiredStatus.any() && !obj->getStatusBits().testForAll( m_requiredStatus ) )
103103
return false;
104104

105-
if(!m_requiredCustomStatus.empty())
106-
{
107-
std::vector<AsciiString> customStatus = obj->getCustomStatus();
108-
std::vector<AsciiString>::const_iterator it2;
109-
for(std::vector<AsciiString>::const_iterator it = m_requiredCustomStatus.begin(); it != m_requiredCustomStatus.end(); ++it)
110-
{
111-
Bool hasRequired = true;
112-
for(it2 = customStatus.begin(); it2 != obj->getCustomStatus().end(); ++it2)
113-
{
114-
if((*it2) == (*it))
115-
hasRequired = true;
116-
}
117-
if(!hasRequired)
118-
return false;
119-
}
120-
}
105+
// all 'required' custom statuses must be set for us to run
106+
if(!obj->testCustomStatusForAll(m_requiredCustomStatus))
107+
return false;
121108

122109
return true;
123110
}

0 commit comments

Comments
 (0)