Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FactionControlTriggerEntity.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Triggers", description: "")]
3 {
4 };
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  protected int m_iFriendlyCount, m_iEnemyCount;
14  protected bool m_bResult;
15  protected bool m_bEvaluateResult;
16 
22  void GetSideCounts(out int outFriendlyCount, out int outEnemyCount)
23  {
24  outFriendlyCount = m_iFriendlyCount;
25  outEnemyCount = m_iEnemyCount;
26  }
27  /*
28  Single entity evaluation in ScriptedEntityFilterForQuery cannot produce a result yet.
29  All entities have to be scanned first and counted.
30  At the end of each cycle, evaluation begins.
31  However, because trigger outcome is detemined by returned value of ScriptedEntityFilterForQuery, another cycle the simply returnes the result.
32 
33  Here's how it goes step by step:
34  1) ScriptedEntityFilterForQuery is called on each entity inside and counts them per faction.
35  2) OnQueryFinished is called at the end of the cycle and evaluates the result.
36  3) ScriptedEntityFilterForQuery is called on each entity inside, but instantly returns the result.
37  4) OnQueryFinished is called at the end of the cycle and resets the variables for new calculation.
38  Repeat from step 1)
39  */
40  override bool ScriptedEntityFilterForQuery(IEntity ent)
41  {
42  //--- Evaluation round, return the result instantly
43  if (m_bEvaluateResult)
44  {
45  return m_bResult;
46  }
47 
48  //--- No faction defined
49  if (!m_OwnerFaction)
50  {
51  m_iFriendlyCount = 0;
52  m_iEnemyCount = 0;
53  return false;
54  }
55 
56  //--- Evaluate engine-driven conditions, e.g., entity class
57  if (!IsAlive(ent))
58  return false;
59 
60  //--- Increase faction counters
61  FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(ent.FindComponent(FactionAffiliationComponent));
62  if (factionAffiliation)
63  {
64  Faction entFaction = factionAffiliation.GetAffiliatedFaction();
65  if (entFaction)
66  {
67  if (m_OwnerFaction.IsFactionEnemy(entFaction))
68  m_iEnemyCount++;
69  else
70  m_iFriendlyCount++;
71  }
72  }
73 
74  return false;
75  }
76  override protected void OnQueryFinished(bool bIsEmpty)
77  {
78  //--- Finished evaluation round. Reset variables and start again.
79  if (m_bEvaluateResult)
80  {
81  m_iFriendlyCount = 0;
82  m_iEnemyCount = 0;
83  m_bEvaluateResult = false;
84  return;
85  }
86 
87  m_bResult = false;
88  m_bEvaluateResult = true;
89 
90  //--- Nobody is in the trigger, skip evaluation
91  if (m_iFriendlyCount == 0 && m_iEnemyCount == 0)
92  return;
93 
94  float friendlyRatio = m_iFriendlyCount / Math.Max(m_iFriendlyCount + m_iEnemyCount, 1);
95  switch (m_iRatioMethod)
96  {
97  case 0:
98  {
99  m_bResult = friendlyRatio > m_fFriendlyRatioLimit;
100  break;
101  }
102  case 1:
103  {
104  m_bResult = float.AlmostEqual(friendlyRatio, m_fFriendlyRatioLimit);
105  break;
106  }
107  case 2:
108  {
109  m_bResult = friendlyRatio < m_fFriendlyRatioLimit;
110  break;
111  }
112  }
113 
114  super.OnQueryFinished(bIsEmpty);
115  }
116 };
m_OwnerFaction
protected Faction m_OwnerFaction
Definition: SCR_CharacterTriggerEntity.c:64
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_BaseFactionTriggerEntity
Definition: SCR_BaseFactionTriggerEntity.c:5
SCR_FactionControlTriggerEntityClass
Definition: SCR_FactionControlTriggerEntity.c:2
IsAlive
bool IsAlive()
Definition: SpectateTargetComponent.c:23
SCR_BaseFactionTriggerEntityClass
Definition: SCR_BaseFactionTriggerEntity.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
Faction
Definition: Faction.c:12
SCR_FactionControlTriggerEntity
Definition: SCR_FactionControlTriggerEntity.c:5
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180