7 [
Attribute(
"1", UIWidgets.ComboBox,
"How should friendly ratio limit be evaluated.",
category:
"Faction Control Trigger", enums: { ParamEnum(
"More than",
"0"), ParamEnum(
"Equals to",
"1"), ParamEnum(
"Less than",
"2") })]
8 protected int m_iRatioMethod;
10 [
Attribute(
"0.5", UIWidgets.Slider,
"Limit for how large portion of trigger entities are friendly.\n\nExamples:\n1 = Only friendlies are present\n0 = Only enemies are present\n0.5 = Equal number of friendlies and enemies\n\nEvaluated only when at least some friendlies or enemies are inside.\nWhen the trigger is empty, condition for ratio = 0 won't activate the trigger.",
category:
"Faction Control Trigger",
params:
"0 1 0.1")]
11 protected float m_fFriendlyRatioLimit;
13 protected int m_iFriendlyCount, m_iEnemyCount;
14 protected bool m_bResult;
15 protected bool m_bEvaluateResult;
22 void GetSideCounts(out
int outFriendlyCount, out
int outEnemyCount)
24 outFriendlyCount = m_iFriendlyCount;
25 outEnemyCount = m_iEnemyCount;
40 override bool ScriptedEntityFilterForQuery(IEntity ent)
43 if (m_bEvaluateResult)
61 FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(ent.FindComponent(FactionAffiliationComponent));
62 if (factionAffiliation)
64 Faction entFaction = factionAffiliation.GetAffiliatedFaction();
76 override protected void OnQueryFinished(
bool bIsEmpty)
79 if (m_bEvaluateResult)
83 m_bEvaluateResult =
false;
88 m_bEvaluateResult =
true;
91 if (m_iFriendlyCount == 0 && m_iEnemyCount == 0)
94 float friendlyRatio = m_iFriendlyCount / Math.Max(m_iFriendlyCount + m_iEnemyCount, 1);
95 switch (m_iRatioMethod)
99 m_bResult = friendlyRatio > m_fFriendlyRatioLimit;
104 m_bResult =
float.AlmostEqual(friendlyRatio, m_fFriendlyRatioLimit);
109 m_bResult = friendlyRatio < m_fFriendlyRatioLimit;
114 super.OnQueryFinished(bIsEmpty);