Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FactionControlTriggerEntity.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Triggers", description: "")]
6{
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;
9
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;
12
13 [Attribute(desc: "Ignored Faction Keys that won't be used for any calculations for this trigger", category: "Faction Trigger")]
14 protected ref array<FactionKey> m_aIgnoredFactionKeys;
15
17 protected bool m_bResult;
18 protected bool m_bEvaluateResult;
19
20 //------------------------------------------------------------------------------------------------
22 void AddIgnoredFactionKeys(notnull array<FactionKey> ignoredFactionKeys)
23 {
24 foreach (FactionKey factionKey : ignoredFactionKeys)
25 {
26 if (!m_aIgnoredFactionKeys.Contains(factionKey))
27 m_aIgnoredFactionKeys.Insert(factionKey);
28 }
29 }
30
36 void GetSideCounts(out int outFriendlyCount, out int outEnemyCount)
37 {
38 outFriendlyCount = m_iFriendlyCount;
39 outEnemyCount = m_iEnemyCount;
40 }
41 /*
42 Single entity evaluation in ScriptedEntityFilterForQuery cannot produce a result yet.
43 All entities have to be scanned first and counted.
44 At the end of each cycle, evaluation begins.
45 However, because trigger outcome is detemined by returned value of ScriptedEntityFilterForQuery, another cycle the simply returnes the result.
46
47 Here's how it goes step by step:
48 1) ScriptedEntityFilterForQuery is called on each entity inside and counts them per faction.
49 2) OnQueryFinished is called at the end of the cycle and evaluates the result.
50 3) ScriptedEntityFilterForQuery is called on each entity inside, but instantly returns the result.
51 4) OnQueryFinished is called at the end of the cycle and resets the variables for new calculation.
52 Repeat from step 1)
53 */
55 {
56 //--- Evaluation round, return the result instantly
58 {
59 return m_bResult;
60 }
61
62 //--- No faction defined
64 {
66 m_iEnemyCount = 0;
67 return false;
68 }
69
70 //--- Evaluate engine-driven conditions, e.g., entity class
71 if (!IsAlive(ent))
72 return false;
73
74 //--- Increase faction counters
75 FactionManager factionManager = GetGame().GetFactionManager();
76 if (!factionManager)
77 return false;
78
79 FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(ent.FindComponent(FactionAffiliationComponent));
80 if (factionAffiliation)
81 {
82 Faction entFaction = factionAffiliation.GetAffiliatedFaction();
83 if (entFaction)
84 {
85 if (!m_aIgnoredFactionKeys || m_aIgnoredFactionKeys.IsEmpty() || !m_aIgnoredFactionKeys.Contains(entFaction.GetFactionKey()))
86 {
87 foreach (FactionKey key : m_aOwnerFactionKeys)
88 {
89 if (factionManager.GetFactionByKey(key).IsFactionEnemy(entFaction))
91 else
93 }
94 }
95 }
96 }
97
98 return false;
99 }
100 override protected void OnQueryFinished(bool bIsEmpty)
101 {
102 //--- Finished evaluation round. Reset variables and start again.
104 {
106 m_iEnemyCount = 0;
107 m_bEvaluateResult = false;
108 return;
109 }
110
111 m_bResult = false;
112 m_bEvaluateResult = true;
113
114 //--- Nobody is in the trigger, skip evaluation
115 if (m_iFriendlyCount == 0 && m_iEnemyCount == 0)
116 return;
117
118 float friendlyRatio = m_iFriendlyCount / Math.Max(m_iFriendlyCount + m_iEnemyCount, 1);
119 switch (m_iRatioMethod)
120 {
121 case 0:
122 {
123 m_bResult = friendlyRatio > m_fFriendlyRatioLimit;
124 break;
125 }
126 case 1:
127 {
128 m_bResult = float.AlmostEqual(friendlyRatio, m_fFriendlyRatioLimit);
129 break;
130 }
131 case 2:
132 {
133 m_bResult = friendlyRatio < m_fFriendlyRatioLimit;
134 break;
135 }
136 }
137
138 super.OnQueryFinished(bIsEmpty);
139 }
140};
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_BaseFactionTriggerEntity(IEntitySource src, IEntity parent)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ref array< string > m_aOwnerFactionKeys
Definition SCR_Task.c:99
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
override bool ScriptedEntityFilterForQuery(IEntity ent)
void AddIgnoredFactionKeys(notnull array< FactionKey > ignoredFactionKeys)
void GetSideCounts(out int outFriendlyCount, out int outEnemyCount)
SCR_FieldOfViewSettings Attribute