Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Targeting Optimizations #1364

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)

this->UseFixedVoxelLighting.Read(exINI, GameStrings::AudioVisual, "UseFixedVoxelLighting");

this->AINormalTargetingDelay.Read(exINI, GameStrings::General, "AINormalTargetingDelay");
this->PlayerNormalTargetingDelay.Read(exINI, GameStrings::General, "PlayerNormalTargetingDelay");
this->AIGuardAreaTargetingDelay.Read(exINI, GameStrings::General, "AIGuardAreaTargetingDelay");
this->PlayerGuardAreaTargetingDelay.Read(exINI, GameStrings::General, "PlayerGuardAreaTargetingDelay");

// Section AITargetTypes
int itemsCount = pINI->GetKeyCount("AITargetTypes");
for (int i = 0; i < itemsCount; ++i)
Expand Down Expand Up @@ -350,6 +355,10 @@ void RulesExt::ExtData::Serialize(T& Stm)
.Process(this->VoxelLightSource)
// .Process(this->VoxelShadowLightSource)
.Process(this->UseFixedVoxelLighting)
.Process(this->AINormalTargetingDelay)
.Process(this->PlayerNormalTargetingDelay)
.Process(this->AIGuardAreaTargetingDelay)
.Process(this->PlayerGuardAreaTargetingDelay)
;
}

Expand Down
9 changes: 9 additions & 0 deletions src/Ext/Rules/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class RulesExt
// Nullable<Vector3D<float>> VoxelShadowLightSource;
Valueable<bool> UseFixedVoxelLighting;

Nullable<int> AINormalTargetingDelay;
Nullable<int> PlayerNormalTargetingDelay;
Nullable<int> AIGuardAreaTargetingDelay;
Nullable<int> PlayerGuardAreaTargetingDelay;

ExtData(RulesClass* OwnerObject) : Extension<RulesClass>(OwnerObject)
, Storage_TiberiumIndex { -1 }
, InfantryGainSelfHealCap {}
Expand Down Expand Up @@ -245,6 +250,10 @@ class RulesExt
, VoxelLightSource { }
// , VoxelShadowLightSource { }
, UseFixedVoxelLighting { false }
, AINormalTargetingDelay {}
, PlayerNormalTargetingDelay {}
, AIGuardAreaTargetingDelay {}
, PlayerGuardAreaTargetingDelay {}
{ }

virtual ~ExtData() = default;
Expand Down
60 changes: 60 additions & 0 deletions src/Ext/Techno/Hooks.Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,63 @@ DEFINE_HOOK(0x6B7600, SpawnManagerClass_AI_InitDestination, 0x6)

return R->Origin() == 0x6B7600 ? SkipGameCode1 : SkipGameCode2;
}

DEFINE_HOOK(0x6FA697, TechnoClass_Update_DontScanIfUnarmed, 0x6)
{
enum { SkipTargeting = 0x6FA6F5, DoTargeting = 0 };

GET(TechnoClass*, pThis, ESI);

if (pThis->IsArmed())
return DoTargeting;
else
return SkipTargeting;
}

DEFINE_HOOK(0x709866, TechnoClass_TargetAndEstimateDamage_ScanDelayGuardArea, 0x6)
{
GET(TechnoClass*, pThis, ESI);

auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType());
auto const pOwner = pThis->Owner;
auto const pRulesExt = RulesExt::Global();
auto const pRules = RulesClass::Instance();
int delay = 1;

if (pOwner->IsHumanPlayer || pOwner->IsControlledByHuman())
{
delay = pTypeExt->PlayerGuardAreaTargetingDelay.Get(pRulesExt->PlayerGuardAreaTargetingDelay.Get(pRules->GuardAreaTargetingDelay));
}
else
{
delay = pTypeExt->AIGuardAreaTargetingDelay.Get(pRulesExt->AIGuardAreaTargetingDelay.Get(pRules->GuardAreaTargetingDelay));
}

R->ECX(delay);

return 0;
}

DEFINE_HOOK(0x70989C, TechnoClass_TargetAndEstimateDamage_ScanDelayNormal, 0x6)
{
GET(TechnoClass*, pThis, ESI);

auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->GetTechnoType());
auto const pOwner = pThis->Owner;
auto const pRulesExt = RulesExt::Global();
auto const pRules = RulesClass::Instance();
int delay = (pThis->Location.X + pThis->Location.Y + Unsorted::CurrentFrame) % 3;
TaranDahl marked this conversation as resolved.
Show resolved Hide resolved

if (pOwner->IsHumanPlayer || pOwner->IsControlledByHuman())
{
delay += pTypeExt->PlayerNormalTargetingDelay.Get(pRulesExt->PlayerNormalTargetingDelay.Get(pRules->NormalTargetingDelay));
}
else
{
delay += pTypeExt->AINormalTargetingDelay.Get(pRulesExt->AINormalTargetingDelay.Get(pRules->NormalTargetingDelay));
}

R->ECX(delay);

return 0;
}
9 changes: 9 additions & 0 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->Wake.Read(exINI, pSection, "Wake");
this->Wake_Grapple.Read(exINI, pSection, "Wake.Grapple");
this->Wake_Sinking.Read(exINI, pSection, "Wake.Sinking");
this->AINormalTargetingDelay.Read(exINI, pSection, "AINormalTargetingDelay");
this->PlayerNormalTargetingDelay.Read(exINI, pSection, "PlayerNormalTargetingDelay");
this->AIGuardAreaTargetingDelay.Read(exINI, pSection, "AIGuardAreaTargetingDelay");
this->PlayerGuardAreaTargetingDelay.Read(exINI, pSection, "PlayerGuardAreaTargetingDelay");

// Ares 0.2
this->RadarJamRadius.Read(exINI, pSection, "RadarJamRadius");
Expand Down Expand Up @@ -680,6 +684,11 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
.Process(this->Wake)
.Process(this->Wake_Grapple)
.Process(this->Wake_Sinking)

.Process(this->AINormalTargetingDelay)
.Process(this->PlayerNormalTargetingDelay)
.Process(this->AIGuardAreaTargetingDelay)
.Process(this->PlayerGuardAreaTargetingDelay)
;
}
void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)
Expand Down
10 changes: 10 additions & 0 deletions src/Ext/TechnoType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ class TechnoTypeExt
Nullable<AnimTypeClass*> Wake_Grapple;
Nullable<AnimTypeClass*> Wake_Sinking;

Nullable<int> AINormalTargetingDelay;
Nullable<int> PlayerNormalTargetingDelay;
Nullable<int> AIGuardAreaTargetingDelay;
Nullable<int> PlayerGuardAreaTargetingDelay;

struct LaserTrailDataEntry
{
ValueableIdx<LaserTrailTypeClass> idxType;
Expand Down Expand Up @@ -453,6 +458,11 @@ class TechnoTypeExt
, Wake { }
, Wake_Grapple { }
, Wake_Sinking { }

, AINormalTargetingDelay {}
, PlayerNormalTargetingDelay {}
, AIGuardAreaTargetingDelay {}
, PlayerGuardAreaTargetingDelay {}
{ }

virtual ~ExtData() = default;
Expand Down