Page MenuHomeFeedback Tracker

"KnowsAboutChanged" + "EnemyDetected" + "forgetTarget" Not Working As Expected for Preventing Hostile Group Engagement
New, NormalPublic

Description

When applying the "KnowsAboutChanged" and "EnemyDetected" event handlers with forgetTarget to units within two hostile groups, they should not engage with each other due to their 'knowsAbout' values being reset. However, the groups still proceed to attack each other. This indicates that either forgetTarget is not working as expected or the execution of the event handlers is unstable. See the steps to reproduce section.

Details

Severity
Major
Resolution
Open
Reproducibility
Always
Operating System
Windows 11 x64
Category
AI Issues
Steps To Reproduce

Open the Editor and create two hostile groups (e.g., BLUFOR and OPFOR).

Add the following SQF codes to both groups' initialization fields:

this addEventHandler ["KnowsAboutChanged", {
    params ["_group", "_targetUnit", "_newKnowsAbout", "_oldKnowsAbout"];
    _group forgetTarget _targetUnit;
    {
        _x forgetTarget _targetUnit;
    } foreach (units _group);
    (units _group) doWatch objNull;
    hint format ["%1 forgot about %2", _group, _targetUnit];
}];

this addEventHandler ["EnemyDetected", {
    params ["_group", "_newTarget"];
    _group forgetTarget _newTarget;
    {
        _x forgetTarget _newTarget;
    } foreach (units _group);
    (units _group) doWatch objNull;
    hint format ["%1 forgot about enemy %2", _group, _newTarget];
}];

Start the mission.
Observe that the two groups engage each other despite the forgetTarget function calls.

Additional Information

The expected behavior is for the two hostile groups to never engage each other as their "knowsAbout" value is supposed to be reset through the use of the forgetTarget function within the event handlers. The purpose behind applying this approach is to simulate more than the standard two or three factions in the game. By having a single faction and then using scripts to manually overwrite the "knowsAbout" values between different groups within that faction, we aim to create a more complex and nuanced conflict environment involving more than just two or three sides.

This bug severely hampers the capability to introduce this level of complexity into scenarios and affects the realism and strategic depth that can be achieved.

Event Timeline

Nerexis created this task.Aug 27 2023, 12:27 PM

Would cause recursion as conditions to "know" target would not be changed (if I'm looking directly at somebody and forget they exist, I instantly know they exist).

Better solution IMO would be to change EH to similar to HandleDamage etc, have return value override new knowsAbout; backwards compatibility shouldn't be a problem in this instance as no point in returning in EH currently & is recent addition anyways.

The suggestion to make the event handler function more like HandleDamage—where the return value can be used to override the new "knowsAbout" value—is an excellent idea. This would allow for more control over the AI's behavior without running into the problems currently faced. Additionally, because this would be a new way to use the event handler, it should not disrupt existing scripts or functionality, thereby ensuring backward compatibility.

Overall, implementing a return value to override the new "knowsAbout" would provide a more robust and versatile solution for those looking to manually control AI behavior and inter-group relations.