Page MenuHomeFeedback Tracker

SCR_FactionControlTriggerEntity should not skip evaluation if empty
Assigned, NormalPublic

Description

The SCR_FactionControlTriggerEntity currently skips evaluation if neither friendlies nor enemies are present. This is unintuitive for two reasons.

Details

Severity
Minor
Resolution
Open
Reproducibility
N/A
Operating System
Windows 7
Category
General
Additional Information

In line 90 of SCR_FactionControlTriggerEntity, OnQueryFinished():

m_bResult = false;
m_bEvaluateResult = true;
//--- Nobody is in the trigger, skip evaluation
if (m_iFriendlyCount == 0 && m_iEnemyCount == 0)
	return;
float friendlyRatio = m_iFriendlyCount / Math.Max(m_iFriendlyCount + m_iEnemyCount, 1);

Why this is a problem:
Imagine there is a trigger with a ratio method of "equal to 0".
The ratio is defined as seen in the code. This way of avoiding a zero division (setting the divisor to 1) is useful because the trigger will still work if no enemies are currently inside of it.
For example, if the occupants are killed from outside of the trigger, you would still want the "factions share in the trigger is equal to zero" result to be true.
However, the instruction before it means the result will be false, completely regardless of any other factors.

While this may still seem like okay on the surface (after all, it's just a different definition of zero division), it is not:
If the result, which has an arbitrary meaning because of the ratio method parameter, will always be false regardless of it, the trigger can behave in a completely unintuitive way.

Clearly, the "if (m_iFriendlyCount == 0 && m_iEnemyCount == 0) return;" line should be removed from the code, because of the max(x,1) it is unneccessary and only results in problems.

Event Timeline

TilW created this task.May 7 2024, 3:31 AM
Geez changed the task status from New to Assigned.May 7 2024, 11:23 AM