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 4 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
5 changes: 5 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ This page lists all the individual contributions to the project by their author.
- Skirmish AI "sell all buildings and set all technos to hunt" behavior dehardcode
- Skirmish AI "gather when MCV deploy" behavior dehardcode
- Global value of `RepairBaseNodes` and `MCVRedeploys`
- Target scanning delay customization.(codes)
- Skip target scanning function calling for unarmed technos.(codes)
**solar-III (凤九歌)**
- Target scanning delay customization.(docs)
- Skip target scanning function calling for unarmed technos.(docs)
MortonPL marked this conversation as resolved.
Show resolved Hide resolved
- **Ares developers**
- YRpp and Syringe which are used, save/load, project foundation and generally useful code from Ares
- unfinished RadTypes code
Expand Down
20 changes: 20 additions & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
- Fixed some locomotors (Tunnel, Walk, Mech) getting stuck when moving too fast.
- Animations with `MakeInfantry` and `UseNormalLight=false` that are drawn in unit palette will now have cell lighting changes applied on them (by Starkku)
- Fixed Nuke & Dominator Level lighting not applying to AircraftTypes.
- Skip target scanning function calling for unarmed technos.

## Fixes / interactions with other extensions

Expand Down Expand Up @@ -1391,6 +1392,25 @@ In `rulesmd.ini`:
IsSingleColor=false ; boolean
```

### Target scanning delay optimization
In Vanilla, the game used 'NormalTargetingDelay' and 'GuardAreaTargetingDelay' to globally control the target searching intervals. Increasing these values would make units stupid, while decreasing them would cause the game lagging.
Now, you can define them per techno, also allowing different values for AI and players. The default values are the same as those originally defined by the vanilla flags.
MortonPL marked this conversation as resolved.
Show resolved Hide resolved

In `rulesmd.ini`:
```ini
[General]
AINormalTargetingDelay= ;integer, game frames
PlayerNormalTargetingDelay= ;integer, game frames
AIGuardAreaTargetingDelay= ;integer, game frames
PlayerGuardAreaTargetingDelay= ;integer, game frames

[SOMETECHNO]
AINormalTargetingDelay= ;integer, game frames
PlayerNormalTargetingDelay= ;integer, game frames
AIGuardAreaTargetingDelay= ;integer, game frames
PlayerGuardAreaTargetingDelay= ;integer, game frames
```
MortonPL marked this conversation as resolved.
Show resolved Hide resolved

### Toggle-able ElectricBolt visuals

![image](_static/images/ebolt.gif)
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ Vanilla fixes:
- Fixed some locomotors (Tunnel, Walk, Mech) getting stuck when moving too fast (by NetsuNegi)
- Animations with `MakeInfantry` and `UseNormalLight=false` that are drawn in unit palette will now have cell lighting changes applied on them (by Starkku)
- Fixed Nuke & Dominator Level lighting not applying to AircraftTypes (by Starkku)
- Skip target scanning function calling for unarmed technos.(by TaranDahl and solar-III)
MortonPL marked this conversation as resolved.
Show resolved Hide resolved

Phobos fixes:
- Fixed a few errors of calling for superweapon launch by `LaunchSW` or building infiltration (by Trsdy)
Expand Down
9 changes: 9 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)
this->RepairBaseNodes.Read(exINI, GameStrings::General, "RepairBaseNodes");
this->MCVRedeploysInCampaign.Read(exINI, GameStrings::General, "MCVRedeploysInCampaign");

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 @@ -381,6 +386,10 @@ void RulesExt::ExtData::Serialize(T& Stm)
.Process(this->AIAllToHunt)
.Process(this->RepairBaseNodes)
.Process(this->MCVRedeploysInCampaign)
.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 @@ -161,6 +161,11 @@ class RulesExt
ValueableVector<bool> RepairBaseNodes;
Valueable<bool> MCVRedeploysInCampaign;

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 @@ -277,6 +282,10 @@ class RulesExt
, AIAllToHunt { true }
, RepairBaseNodes {}
, MCVRedeploysInCampaign { 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 @@ -108,3 +108,63 @@ DEFINE_HOOK(0x739920, UnitClass_TryToDeploy_DisableRegroupAtNewConYard, 0x6)

return pRules->GatherWhenMCVDeploy ? DoNotSkipRegroup : SkipRegroup;
}

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 @@ -318,6 +318,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 @@ -688,6 +692,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 @@ -233,6 +233,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 @@ -461,6 +466,11 @@ class TechnoTypeExt
, Wake { }
, Wake_Grapple { }
, Wake_Sinking { }

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

virtual ~ExtData() = default;
Expand Down
Loading