Skip to content

Commit b0e23bc

Browse files
committed
More optimize and code style thing based on fc80cbb
- Place the symbol at the beginning of the line - Use curly braces for multi line content - Optimize the repeated acquisition of variables and their order
1 parent a012293 commit b0e23bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+249
-241
lines changed

src/Ext/Aircraft/Hooks.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,9 @@ DEFINE_HOOK(0x708FC0, TechnoClass_ResponseMove_Pickup, 0x5)
835835
{
836836
auto const pType = pAircraft->Type;
837837

838-
if (pType->Carryall && pAircraft->HasAnyLink() &&
839-
generic_cast<FootClass*>(pAircraft->Destination))
838+
if (pType->Carryall
839+
&& pAircraft->HasAnyLink()
840+
&& generic_cast<FootClass*>(pAircraft->Destination))
840841
{
841842
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pType);
842843

src/Ext/Anim/Body.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ void AnimExt::HandleDebrisImpact(AnimTypeClass* pExpireAnim, AnimTypeClass* pWak
242242
{
243243
auto const lastIndex = (splashAnims.size() - 1);
244244
auto const defaultIndex = isMeteor ? lastIndex : 0;
245-
auto const animIndex = splashAnimsPickRandom ?
246-
ScenarioClass::Instance->Random.RandomRanged(0, lastIndex) : defaultIndex;
247-
245+
auto const animIndex = splashAnimsPickRandom
246+
? ScenarioClass::Instance->Random.RandomRanged(0, lastIndex)
247+
: defaultIndex;
248248
pSplashAnimToUse = splashAnims.at(animIndex);
249249
}
250250
}

src/Ext/Anim/Hooks.AnimCreateUnit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ DEFINE_HOOK(0x738807, UnitClass_Destroy_DestroyAnim, 0x8)
2929
{
3030
GET(UnitClass* const, pThis, ESI);
3131

32-
auto const Extension = TechnoExt::ExtMap.Find(pThis);
32+
auto const pExt = TechnoExt::ExtMap.Find(pThis);
3333

34-
if (!Extension->ReceiveDamage)
34+
if (!pExt->ReceiveDamage)
3535
AnimTypeExt::ProcessDestroyAnims(pThis);
3636

3737
return 0x73887E;

src/Ext/AnimType/Body.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ void AnimTypeExt::ProcessDestroyAnims(UnitClass* pThis, TechnoClass* pKiller)
4040
}
4141
else
4242
{
43-
int const nIDx_Rand = pType->DestroyAnim.Count == 1 ?
44-
0 : ScenarioClass::Instance->Random.RandomRanged(0, (pType->DestroyAnim.Count - 1));
43+
int const nIDx_Rand = pType->DestroyAnim.Count == 1
44+
? 0 : ScenarioClass::Instance->Random.RandomRanged(0, (pType->DestroyAnim.Count - 1));
4545
pAnimType = pType->DestroyAnim[nIDx_Rand];
46-
4746
}
4847

4948
if (pAnimType)

src/Ext/Building/Body.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ bool BuildingExt::CanGrindTechno(BuildingClass* pBuilding, TechnoClass* pTechno)
223223
if (!pBldType->Grinding || (whatAmI != AbstractType::Infantry && whatAmI != AbstractType::Unit))
224224
return false;
225225

226-
if ((pBldType->InfantryAbsorb || pBldType->UnitAbsorb) &&
227-
(whatAmI == AbstractType::Infantry && !pBldType->InfantryAbsorb ||
228-
whatAmI == AbstractType::Unit && !pBldType->UnitAbsorb))
226+
if ((pBldType->InfantryAbsorb || pBldType->UnitAbsorb)
227+
&& (whatAmI == AbstractType::Infantry && !pBldType->InfantryAbsorb
228+
|| whatAmI == AbstractType::Unit && !pBldType->UnitAbsorb))
229229
{
230230
return false;
231231
}
@@ -261,9 +261,9 @@ bool BuildingExt::DoGrindingExtras(BuildingClass* pBuilding, TechnoClass* pTechn
261261
pExt->AccumulatedIncome += refund;
262262
pExt->GrindingWeapon_AccumulatedCredits += refund;
263263

264-
if (pTypeExt->Grinding_Weapon &&
265-
Unsorted::CurrentFrame >= pExt->GrindingWeapon_LastFiredFrame + pTypeExt->Grinding_Weapon->ROF &&
266-
pExt->GrindingWeapon_AccumulatedCredits >= pTypeExt->Grinding_Weapon_RequiredCredits)
264+
if (pTypeExt->Grinding_Weapon
265+
&& Unsorted::CurrentFrame >= pExt->GrindingWeapon_LastFiredFrame + pTypeExt->Grinding_Weapon->ROF
266+
&& pExt->GrindingWeapon_AccumulatedCredits >= pTypeExt->Grinding_Weapon_RequiredCredits)
267267
{
268268
TechnoExt::FireWeaponAtSelf(pBuilding, pTypeExt->Grinding_Weapon);
269269
pExt->GrindingWeapon_LastFiredFrame = Unsorted::CurrentFrame;

src/Ext/Building/Hooks.Grinding.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ DEFINE_HOOK(0x51F0AF, InfantryClass_WhatAction_Grinding, 0x0)
100100
if (const auto pBuilding = abstract_cast<BuildingClass*>(pTarget))
101101
{
102102
const auto pType = pBuilding->Type;
103-
const auto pExt = BuildingTypeExt::ExtMap.Find(pType);
104103

105-
if (pType->Grinding && pThis->Owner->IsControlledByCurrentPlayer() && !pBuilding->IsBeingWarpedOut() &&
106-
pThis->Owner->IsAlliedWith(pTarget) && (pExt->Grinding_AllowAllies || action == Action::Select))
104+
if (pType->Grinding
105+
&& pThis->Owner->IsControlledByCurrentPlayer()
106+
&& !pBuilding->IsBeingWarpedOut()
107+
&& pThis->Owner->IsAlliedWith(pTarget)
108+
&& (BuildingTypeExt::ExtMap.Find(pType)->Grinding_AllowAllies || action == Action::Select))
107109
{
108110
action = BuildingExt::CanGrindTechno(pBuilding, pThis) ? Action::Repair : Action::NoEnter;
109111
R->EBP(action);

src/Ext/Building/Hooks.Production.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,8 @@ DEFINE_HOOK(0x4502F4, BuildingClass_Update_Factory_Phobos, 0x6)
101101
if (naval ? RulesExt::Global()->ForbidParallelAIQueues_Navy : RulesExt::Global()->ForbidParallelAIQueues_Vehicle)
102102
return Skip;
103103

104-
if (naval)
105-
{
106-
auto const pExt = HouseExt::ExtMap.Find(pOwner);
107-
index = pExt->ProducingNavalUnitTypeIndex;
108-
}
109-
else
110-
{
111-
index = pOwner->ProducingUnitTypeIndex;
112-
}
113-
104+
index = naval ? HouseExt::ExtMap.Find(pOwner)->ProducingNavalUnitTypeIndex : pOwner->ProducingUnitTypeIndex;
114105
pType = index >= 0 ? UnitTypeClass::Array.GetItem(index) : nullptr;
115-
116106
break;
117107
default:
118108
break;

src/Ext/Building/Hooks.Selling.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ DEFINE_HOOK(0x449CC1, BuildingClass_Mi_Selling_EVASold_UndeploysInto, 0x6)
5858
GET(BuildingClass*, pThis, EBP);
5959

6060
const auto pType = pThis->Type;
61-
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pType);
6261
// Fix Conyards can't play EVA_StructureSold
6362
if (pThis->IsOwnedByCurrentPlayer && (!pThis->ArchiveTarget || !pType->UndeploysInto))
64-
VoxClass::PlayIndex(pTypeExt->EVA_Sold.Get(VoxClass::FindIndex(GameStrings::EVA_StructureSold)));
63+
VoxClass::PlayIndex(TechnoTypeExt::ExtMap.Find(pType)->EVA_Sold.Get(VoxClass::FindIndex(GameStrings::EVA_StructureSold)));
6564

6665
return BuildingExt::CanUndeployOnSell(pThis) ? CreateUnit : SkipTheEntireShit;
6766
}
@@ -72,10 +71,7 @@ DEFINE_HOOK(0x44A7CF, BuildingClass_Mi_Selling_PlaySellSound, 0x6)
7271
GET(BuildingClass*, pThis, EBP);
7372

7473
if (!BuildingExt::CanUndeployOnSell(pThis))
75-
{
76-
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->Type);
77-
VocClass::PlayAt(pTypeExt->SellSound.Get(RulesClass::Instance->SellSound), pThis->Location);
78-
}
74+
VocClass::PlayAt(TechnoTypeExt::ExtMap.Find(pThis->Type)->SellSound.Get(RulesClass::Instance->SellSound), pThis->Location);
7975

8076
return FinishPlaying;
8177
}
@@ -102,10 +98,8 @@ DEFINE_HOOK(0x44AB22, BuildingClass_Mi_Selling_EVASold_Plug, 0x6)
10298
#if ANYBODY_NOTICED_THIS
10399
GET(BuildingClass*, pThis, EBP);
104100

105-
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->Type);
106-
107101
if (pThis->IsOwnedByCurrentPlayer)
108-
VoxClass::PlayIndex(pTypeExt->EVA_Sold.Get(VoxClass::FindIndex(GameStrings::EVA_StructureSold)));
102+
VoxClass::PlayIndex(TechnoTypeExt::ExtMap.Find(pThis->Type)->EVA_Sold.Get(VoxClass::FindIndex(GameStrings::EVA_StructureSold)));
109103
#endif
110104
return SkipVoxPlay;
111105
}

src/Ext/BuildingType/Hooks.Upgrade.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,8 @@ static __forceinline bool AllowUpgradeAnim(BuildingClass* pBuilding, BuildingAni
251251

252252
auto const animData = pType->BuildingAnim[int(anim)];
253253

254-
if (((pType->Powered && pType->PowerDrain > 0 && (animData.PoweredLight || animData.PoweredEffect)) ||
255-
(pType->PoweredSpecial && animData.PoweredSpecial)) &&
256-
!(pBuilding->CurrentMission != Mission::Construction && pBuilding->CurrentMission != Mission::Selling && pBuilding->IsPowerOnline()))
254+
if (((pType->Powered && pType->PowerDrain > 0 && (animData.PoweredLight || animData.PoweredEffect)) || (pType->PoweredSpecial && animData.PoweredSpecial))
255+
&& !(pBuilding->CurrentMission != Mission::Construction && pBuilding->CurrentMission != Mission::Selling && pBuilding->IsPowerOnline()))
257256
{
258257
return false;
259258
}

src/Ext/BuildingType/Hooks.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ DEFINE_HOOK(0x459494, BuildingClass_BunkerSound, 0x5)
331331
BunkerWallDownSound_02_Handled_ret = 0x4594CD
332332
};
333333

334-
BuildingClass const* pThis = R->Origin() == BunkerWallDownSound_01 ?
335-
R->EDI<BuildingClass*>() : R->ESI<BuildingClass*>();
334+
BuildingClass const* pThis = R->Origin() == BunkerWallDownSound_01
335+
? R->EDI<BuildingClass*>() : R->ESI<BuildingClass*>();
336336

337337
BuildingTypeExt::PlayBunkerSound(pThis, R->Origin() == BunkerWallUpSound);
338338

0 commit comments

Comments
 (0)