Skip to content

Commit 1ecd281

Browse files
committed
optimize usage of GetTechnoType()
- replace it with Type variable for Aircraft, Building, Infantry and Unit classes - replace Find(techno->GetTechnoType()) with Find(techno)->TypeExtData
1 parent b205830 commit 1ecd281

31 files changed

+105
-99
lines changed

src/Commands/NextIdleHarvester.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@ void NextIdleHarvesterCommandClass::Execute(WWKey eInput) const
4747

4848
do
4949
{
50-
if (auto pTechno = abstract_cast<TechnoClass*>(pNextObject))
50+
if (auto const pTechno = abstract_cast<TechnoClass*>(pNextObject))
5151
{
52-
if (auto pTypeExt = TechnoTypeExt::ExtMap.Find(pTechno->GetTechnoType()))
52+
auto const pTypeExt = TechnoExt::ExtMap.Find(pTechno)->TypeExtData;
53+
54+
if (pTypeExt->Harvester_Counted && !TechnoExt::IsHarvesting(pTechno))
5355
{
54-
if (pTypeExt->Harvester_Counted && !TechnoExt::IsHarvesting(pTechno))
55-
{
56-
pObjectToSelect = pNextObject;
57-
idleHarvestersPresent = true;
58-
break;
59-
}
56+
pObjectToSelect = pNextObject;
57+
idleHarvestersPresent = true;
58+
break;
6059
}
6160
}
6261

src/Ext/Aircraft/Body.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void AircraftExt::FireWeapon(AircraftClass* pThis, AbstractClass* pTarget)
5252
// Spy plane, airstrike etc.
5353
bool AircraftExt::PlaceReinforcementAircraft(AircraftClass* pThis, CellStruct edgeCell)
5454
{
55-
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType());
55+
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->Type);
5656
auto coords = CellClass::Cell2Coord(edgeCell);
5757
coords.Z = 0;
5858
AbstractClass* pTarget = nullptr;

src/Ext/Building/Hooks.Grinding.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ DEFINE_HOOK(0x43C30A, BuildingClass_ReceiveMessage_Grinding, 0x6)
1919
const bool isAmphibious = movementZone == MovementZone::Amphibious || movementZone == MovementZone::AmphibiousCrusher
2020
|| movementZone == MovementZone::AmphibiousDestroyer;
2121

22-
if (!isAmphibious && (pThis->GetTechnoType()->Naval != pFromType->Naval))
22+
if (!isAmphibious && (pThis->Type->Naval != pFromType->Naval))
2323
return ReturnNegative;
2424

2525
if (pThis->Type->Grinding)
@@ -146,7 +146,7 @@ DEFINE_HOOK(0x740134, UnitClass_WhatAction_Grinding, 0x0)
146146
{
147147
if (pThis->SendCommand(RadioCommand::QueryCanEnter, pTarget) == RadioCommand::AnswerPositive)
148148
{
149-
bool isFlying = pThis->GetTechnoType()->MovementZone == MovementZone::Fly;
149+
bool isFlying = pThis->Type->MovementZone == MovementZone::Fly;
150150
bool canBeGrinded = BuildingExt::CanGrindTechno(pBuilding, pThis);
151151
action = pBuilding->Type->Grinding ? canBeGrinded && !isFlying ? Action::Repair : Action::NoEnter : !isFlying ? Action::Enter : Action::NoEnter;
152152
R->EBX(action);

src/Ext/Building/Hooks.Selling.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ DEFINE_HOOK(0x4D9F7B, FootClass_Sell, 0x6)
1111

1212
if (pThis->Owner->IsControlledByCurrentPlayer())
1313
{
14-
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType());
14+
const auto pTypeExt = TechnoExt::ExtMap.Find(pThis)->TypeExtData;
1515
VoxClass::PlayIndex(pTypeExt->EVA_Sold.Get(VoxClass::FindIndex(GameStrings::EVA_UnitSold)));
1616
//WW used VocClass::PlayGlobal to play the SellSound, why did they do that?
1717
VocClass::PlayAt(pTypeExt->SellSound.Get(RulesClass::Instance->SellSound), pThis->Location);

src/Ext/Bullet/Body.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void BulletExt::ExtData::InterceptBullet(TechnoClass* pSource, WeaponTypeClass*
2121
auto pTypeExt = this->TypeExtData;
2222
bool canAffect = false;
2323
bool isIntercepted = false;
24-
const auto pTechnoTypeExt = TechnoTypeExt::ExtMap.Find(pSource->GetTechnoType());
24+
const auto pTechnoTypeExt = TechnoExt::ExtMap.Find(pSource)->TypeExtData;
2525
const auto pInterceptorType = pTechnoTypeExt->InterceptorType.get();
2626

2727
if (pTypeExt->Armor.isset())

src/Ext/CaptureManager/Body.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ bool CaptureManagerExt::CanCapture(CaptureManagerClass* pManager, TechnoClass* p
77
if (pManager->MaxControlNodes == 1)
88
return pManager->CanCapture(pTarget);
99

10-
auto pTechnoTypeExt = TechnoTypeExt::ExtMap.Find(pManager->Owner->GetTechnoType());
10+
const auto pTechnoTypeExt = TechnoExt::ExtMap.Find(pManager->Owner)->TypeExtData;
1111
if (pTechnoTypeExt->MultiMindControl_ReleaseVictim)
1212
{
1313
// I hate Ares' completely rewritten things - secsome
1414
pManager->MaxControlNodes += 1;
15-
bool result = pManager->CanCapture(pTarget);
15+
const bool result = pManager->CanCapture(pTarget);
1616
pManager->MaxControlNodes -= 1;
1717
return result;
1818
}
@@ -132,7 +132,7 @@ bool CaptureManagerExt::CaptureUnit(CaptureManagerClass* pManager, AbstractClass
132132
if (const auto pTarget = generic_cast<TechnoClass*>(pTechno))
133133
{
134134
bool bRemoveFirst = false;
135-
if (auto pTechnoTypeExt = TechnoTypeExt::ExtMap.Find(pManager->Owner->GetTechnoType()))
135+
if (const auto pTechnoTypeExt = TechnoExt::ExtMap.Find(pManager->Owner)->TypeExtData)
136136
bRemoveFirst = pTechnoTypeExt->MultiMindControl_ReleaseVictim;
137137

138138
return CaptureManagerExt::CaptureUnit(pManager, pTarget, bRemoveFirst, pControlledAnimType, false, threatDelay);

src/Ext/CaptureManager/Hooks.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Body.h"
22

33
#include <ParticleSystemClass.h>
4+
#include <Ext/Techno/Body.h>
45
#include <Utilities/Macro.h>
56
#include <Utilities/EnumFunctions.h>
67

@@ -66,13 +67,13 @@ DEFINE_HOOK(0x4721E6, CaptureManagerClass_DrawLinkToVictim, 0x6)
6667
GET_STACK(int, nNodeCount, STACK_OFFSET(0x30, -0x1C));
6768

6869
auto const pAttacker = pThis->Owner;
69-
const auto pExt = TechnoTypeExt::ExtMap.Find(pAttacker->GetTechnoType());
70+
auto const pExt = TechnoExt::ExtMap.Find(pAttacker)->TypeExtData;
7071

7172
if (EnumFunctions::CanTargetHouse(pExt->MindControlLink_VisibleToHouse, pAttacker->Owner, HouseClass::CurrentPlayer))
7273
{
7374
auto nVictimCoord = pVictim->Location;
7475
nVictimCoord.Z += pVictim->GetTechnoType()->LeptonMindControlOffset;
75-
auto nFLH = pAttacker->GetFLH(-1 - nNodeCount % 5, CoordStruct::Empty);
76+
auto const nFLH = pAttacker->GetFLH(-1 - nNodeCount % 5, CoordStruct::Empty);
7677
DrawALinkTo(nFLH, nVictimCoord, pAttacker->Owner->Color);
7778
}
7879

@@ -83,7 +84,7 @@ DEFINE_HOOK(0x4721E6, CaptureManagerClass_DrawLinkToVictim, 0x6)
8384
void __fastcall CaptureManagerClass_Overload_AI(CaptureManagerClass* pThis, void* _)
8485
{
8586
auto const pOwner = pThis->Owner;
86-
auto const pOwnerTypeExt = TechnoTypeExt::ExtMap.Find(pOwner->GetTechnoType());
87+
auto const pOwnerTypeExt = TechnoExt::ExtMap.Find(pOwner)->TypeExtData;
8788

8889
if (!pOwnerTypeExt) // we cant find type Ext for this , just return to original function !
8990
{

src/Ext/House/Hooks.UnitFromFactory.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <FactoryClass.h>
22

3+
#include <Ext/Techno/Body.h>
34
#include <Ext/TechnoType/Body.h>
45
#include <Utilities/EnumFunctions.h>
56
#include <Utilities/GeneralUtils.h>
@@ -18,7 +19,7 @@ DEFINE_HOOK(0x4FB64B, HouseClass_UnitFromFactory_VoiceCreated, 0x5)
1819
GET(TechnoClass* const, pThisTechno, ESI);
1920
GET(FactoryClass* const, pThisFactory, EBX);
2021

21-
auto const pThisTechnoType = TechnoTypeExt::ExtMap.Find(pThisTechno->GetTechnoType());
22+
auto const pThisTechnoType = TechnoExt::ExtMap.Find(pThisTechno)->TypeExtData;
2223
if (pThisTechno->Owner->IsControlledByCurrentPlayer() && pThisTechnoType->VoiceCreated.isset())
2324
{
2425
if (RulesExt::Global()->IsVoiceCreatedGlobal.Get())

src/Ext/Infantry/Hooks.Firing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ DEFINE_HOOK(0x5206D2, InfantryClass_FiringAI_SetContext, 0x6)
4444

4545
const auto pTarget = pThis->Target;
4646
FiringAITemp::weaponIndex = WeaponIndex;
47-
FiringAITemp::isSecondary = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType())->IsSecondary(WeaponIndex);
47+
FiringAITemp::isSecondary = TechnoTypeExt::ExtMap.Find(pThis->Type)->IsSecondary(WeaponIndex);
4848
FiringAITemp::WeaponType = pWeapon;
4949
FiringAITemp::fireError = pThis->GetFireError(pTarget, WeaponIndex, true);
5050
FiringAITemp::canFire = true;

src/Ext/Techno/Body.Internal.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ CoordStruct TechnoExt::GetBurstFLH(TechnoClass* pThis, int weaponIndex, bool& FL
7878
FLHFound = false;
7979
CoordStruct FLH = CoordStruct::Empty;
8080

81-
auto const pExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType());
81+
auto const pExt = TechnoExt::ExtMap.Find(pThis)->TypeExtData;
8282

83-
auto pInf = abstract_cast<InfantryClass*, true>(pThis);
83+
auto const pInf = abstract_cast<InfantryClass*, true>(pThis);
8484
std::span<std::vector<CoordStruct>> pickedFLHs = pExt->WeaponBurstFLHs;
8585

8686
if (pThis->Veterancy.IsElite())
@@ -184,11 +184,10 @@ int TechnoExt::GetTintColor(TechnoClass* pThis, bool invulnerability, bool airst
184184

185185
if (airstrike)
186186
{
187-
if (auto const pAirstrike = TechnoExt::ExtMap.Find(pThis)->AirstrikeTargetingMe)
188-
{
189-
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pAirstrike->Owner->GetTechnoType());
190-
tintColor |= pTypeExt->TintColorAirstrike;
191-
}
187+
auto const pExt = TechnoExt::ExtMap.Find(pThis);
188+
189+
if (auto const pAirstrike = pExt->AirstrikeTargetingMe)
190+
tintColor |= pExt->TypeExtData->TintColorAirstrike;
192191
}
193192

194193
if (berserk && pThis->Berzerk)

0 commit comments

Comments
 (0)