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

Customizable disguised target evaluation behaviour in new ScriptType attack actions #1169

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ This page lists all the individual contributions to the project by their author.
- Shared ammo logic
- Customizable FLH when infantry is prone or deployed
- Initial strength for cloned infantry
- Customizable disguised target evaluation behaviour in new ScriptType attack actions
- **Starkku**:
- Misc. minor bugfixes & improvements
- AI script actions:
Expand Down
11 changes: 11 additions & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,17 @@ In `rulesmd.ini`:
TargetZoneScanType=same ; target zone scan enumeration (same|any|inrange)
```

### Customizable disguised target evaluation behaviour in new ScriptType attack actions

- By default, any unit with `DetectDisguise=yes` seeking targets via new [attack team missions introduced in Phobos](AI-Scripting-and-Mapping.md#10000-10049-attack-actions) always detects the disguised units. The probability to detect a disguised object now can be customized.
- `DetectDisguise.Percent` values represent the probabilities in hard, medium & easy difficulty, in that order.

In `rulesmd.ini`:
```ini
[SOMETECHNO] ; TechnoType
DetectDisguise.Percent=1.0, 1.0, 1.0 ; float, percents or absolute
```

### Customizable unit image in art

- `Image` tag in art INI is no longer limited to AnimationTypes and BuildingTypes, and can be applied to all TechnoTypes (InfantryTypes, VehicleTypes, AircraftTypes, BuildingTypes).
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ New:
- Customizable straight trajectory detonation & snap distance and pass-through option (by Starkku)
- Airstrike & spy plane fixed spawn distance & height (by Starkku)
- Allow enabling application of `Verses` and `PercentAtMax` for negative damage (by Starkku)
- Customizable disguised target evaluation behaviour in new ScriptType attack actions (by FS-21)

Vanilla fixes:
- Allow AI to repair structures built from base nodes/trigger action 125/SW delivery in single player missions (by Trsdy)
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/Script/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class ScriptExt

// Mission.Attack.cpp
static void Mission_Attack(TeamClass* pTeam, bool repeatAction, int calcThreatMode, int attackAITargetType, int IdxAITargetTypeItem);
static TechnoClass* GreatestThreat(TechnoClass* pTechno, int method, int calcThreatMode, HouseClass* onlyTargetThisHouseEnemy, int attackAITargetType, int idxAITargetTypeItem, bool agentMode);
static TechnoClass* GreatestThreat(TechnoClass* pTechno, int method, int calcThreatMode, HouseClass* onlyTargetThisHouseEnemy, int attackAITargetType, int idxAITargetTypeItem, bool agentMode, std::vector<double> disguiseDetection);
static bool EvaluateObjectWithMask(TechnoClass* pTechno, int mask, int attackAITargetType, int idxAITargetTypeItem, TechnoClass* pTeamLeader);
static void Mission_Attack_List(TeamClass* pTeam, bool repeatAction, int calcThreatMode, int attackAITargetType);
static void Mission_Attack_List1Random(TeamClass* pTeam, bool repeatAction, int calcThreatMode, int attackAITargetType);
Expand Down
41 changes: 39 additions & 2 deletions src/Ext/Script/Mission.Attack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void ScriptExt::Mission_Attack(TeamClass* pTeam, bool repeatAction = true, int c
bool agentMode = false;
bool pacifistTeam = true;
auto pTeamData = TeamExt::ExtMap.Find(pTeam);
std::vector<double> disguiseDetection = {};

if (!pScript)
return;
Expand Down Expand Up @@ -136,6 +137,19 @@ void ScriptExt::Mission_Attack(TeamClass* pTeam, bool repeatAction = true, int c
if ((pTypeInf->Agent && pTypeInf->Infiltrate) || pTypeInf->Engineer)
agentMode = true;
}

auto pTechnoData = TechnoTypeExt::ExtMap.Find(pTechnoType);
if (pTechnoType->DetectDisguise)
{
auto const AIDifficulty = static_cast<int>(pFoot->Owner->GetAIDifficultyIndex());
double detectionValue = 1.0;

if (pTechnoData->DetectDisguise_Percent.size() == 3)
detectionValue = pTechnoData->DetectDisguise_Percent[AIDifficulty];

detectionValue = detectionValue > 0.0 ? detectionValue : 1.0;
disguiseDetection.push_back(detectionValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont do this every time function called, fix this on INIReading moment instead.

}
}
}

Expand Down Expand Up @@ -194,7 +208,7 @@ void ScriptExt::Mission_Attack(TeamClass* pTeam, bool repeatAction = true, int c
enemyHouse = HouseClass::Array->GetItem(pLeaderUnit->Owner->EnemyHouseIndex);

int targetMask = scriptArgument;
selectedTarget = GreatestThreat(pLeaderUnit, targetMask, calcThreatMode, enemyHouse, attackAITargetType, idxAITargetTypeItem, agentMode);
selectedTarget = GreatestThreat(pLeaderUnit, targetMask, calcThreatMode, enemyHouse, attackAITargetType, idxAITargetTypeItem, agentMode, disguiseDetection);

if (selectedTarget)
{
Expand Down Expand Up @@ -399,7 +413,7 @@ void ScriptExt::Mission_Attack(TeamClass* pTeam, bool repeatAction = true, int c
}
}

TechnoClass* ScriptExt::GreatestThreat(TechnoClass* pTechno, int method, int calcThreatMode = 0, HouseClass* onlyTargetThisHouseEnemy = nullptr, int attackAITargetType = -1, int idxAITargetTypeItem = -1, bool agentMode = false)
TechnoClass* ScriptExt::GreatestThreat(TechnoClass* pTechno, int method, int calcThreatMode = 0, HouseClass* onlyTargetThisHouseEnemy = nullptr, int attackAITargetType = -1, int idxAITargetTypeItem = -1, bool agentMode = false, std::vector<double> disguiseDetection = {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass the value of PartialVector3D as const reference if no modification required , to avoid unnessesary copy.

{
TechnoClass* bestObject = nullptr;
double bestVal = -1;
Expand Down Expand Up @@ -492,6 +506,29 @@ TechnoClass* ScriptExt::GreatestThreat(TechnoClass* pTechno, int method, int cal
&& object->Owner != pTechno->Owner
&& (!pTechno->Owner->IsAlliedWith(object) || IsUnitMindControlledFriendly(pTechno->Owner, object)))
{
if (object->IsDisguised())
{
if (disguiseDetection.size() == 0)
continue;

bool detected = false;

for (double item : disguiseDetection)
{
int dice = ScenarioClass::Instance->Random.RandomRanged(0, 99);
int detectionValue = std::round(item * 100.0);

if (detectionValue > dice)
{
detected = true;
break;
}
}

if (!detected)
continue;
}

double value = 0;

if (EvaluateObjectWithMask(object, method, attackAITargetType, idxAITargetTypeItem, pTechno))
Expand Down
4 changes: 4 additions & 0 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
this->SpawnDistanceFromTarget.Read(exINI, pSection, "SpawnDistanceFromTarget");
this->SpawnHeight.Read(exINI, pSection, "SpawnHeight");

this->DetectDisguise_Percent.Read(exINI, pSection, "DetectDisguise.Percent");

// Ares 0.2
this->RadarJamRadius.Read(exINI, pSection, "RadarJamRadius");

Expand Down Expand Up @@ -569,6 +571,8 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)

.Process(this->SpawnDistanceFromTarget)
.Process(this->SpawnHeight)

.Process(this->DetectDisguise_Percent)
;
}
void TechnoTypeExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)
Expand Down
3 changes: 3 additions & 0 deletions src/Ext/TechnoType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ class TechnoTypeExt
Nullable<Leptons> SpawnDistanceFromTarget;
Nullable<int> SpawnHeight;

ValueableVector<double> DetectDisguise_Percent;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is only use based on AIDifficulty right ?
mean it is only require 3 items at max , please use PartialVector3D instead of ValueableVector.


struct LaserTrailDataEntry
{
ValueableIdx<LaserTrailTypeClass> idxType;
Expand Down Expand Up @@ -359,6 +361,7 @@ class TechnoTypeExt

, SpawnDistanceFromTarget {}
, SpawnHeight {}
, DetectDisguise_Percent {}
{ }

virtual ~ExtData() = default;
Expand Down