Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MilitaryBaseLogicComponent.c
Go to the documentation of this file.
1 class SCR_MilitaryBaseLogicComponentClass : ScriptComponentClass
2 {
3 }
4 
5 class SCR_MilitaryBaseLogicComponent : ScriptComponent
6 {
7  protected ref array<SCR_MilitaryBaseComponent> m_aBases = {};
8 
9  //------------------------------------------------------------------------------------------------
12  void RegisterBase(notnull SCR_MilitaryBaseComponent base)
13  {
14  if (m_aBases.Contains(base))
15  return;
16 
17  m_aBases.Insert(base);
18  OnBaseRegistered(base);
19  }
20 
21  //------------------------------------------------------------------------------------------------
23  void OnBaseRegistered(notnull SCR_MilitaryBaseComponent base)
24  {
25  if (base.GetOwner() == GetOwner())
26  return;
27 
28  if (m_aBases.Count() == 1)
29  OnBaseFactionChanged(base.GetFaction());
30  }
31 
32  //------------------------------------------------------------------------------------------------
35  void UnregisterBase(notnull SCR_MilitaryBaseComponent base)
36  {
37  if (!m_aBases.Contains(base))
38  return;
39 
40  m_aBases.RemoveItem(base);
41  OnBaseUnregistered(base);
42  }
43 
44  //------------------------------------------------------------------------------------------------
46  void OnBaseUnregistered(notnull SCR_MilitaryBaseComponent base);
47 
48  //------------------------------------------------------------------------------------------------
51  int GetBases(out array<SCR_MilitaryBaseComponent> bases)
52  {
53  if (bases)
54  return bases.Copy(m_aBases);
55  else
56  return m_aBases.Count();
57  }
58 
59  //------------------------------------------------------------------------------------------------
62  {
63  FactionAffiliationComponent factionControl = FactionAffiliationComponent.Cast(GetOwner().FindComponent(FactionAffiliationComponent));
64 
65  if (!factionControl || factionControl.GetAffiliatedFaction() == faction)
66  return;
67 
68  factionControl.SetAffiliatedFaction(faction);
69  }
70 
71  //------------------------------------------------------------------------------------------------
72  override void EOnInit(IEntity owner)
73  {
74  super.EOnInit(owner);
75 
76  // Check for play mode again in case init event was set from outside of this class
77  if (!GetGame().InPlayMode())
78  return;
79 
80  SCR_MilitaryBaseSystem baseManager = SCR_MilitaryBaseSystem.GetInstance();
81 
82  if (baseManager)
83  baseManager.RegisterLogicComponent(this);
84  }
85 
86  //------------------------------------------------------------------------------------------------
87  override void OnPostInit(IEntity owner)
88  {
89  super.OnPostInit(owner);
90 
91  if (!GetGame().InPlayMode())
92  return;
93 
94  SetEventMask(owner, EntityEvent.INIT);
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  // destructor
100  {
101  SCR_MilitaryBaseSystem baseManager = SCR_MilitaryBaseSystem.GetInstance();
102 
103  if (baseManager)
104  baseManager.UnregisterLogicComponent(this);
105 
106  foreach (SCR_MilitaryBaseComponent base : m_aBases)
107  {
108  if (base)
109  base.UnregisterLogicComponent(this);
110  }
111  }
112 }
OnBaseFactionChanged
void OnBaseFactionChanged(Faction faction)
Definition: SCR_MilitaryBaseLogicComponent.c:61
OnBaseRegistered
void OnBaseRegistered(notnull SCR_MilitaryBaseComponent base)
Definition: SCR_MilitaryBaseLogicComponent.c:23
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
SCR_MilitaryBaseLogicComponentClass
Definition: SCR_MilitaryBaseLogicComponent.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_MilitaryBaseSystem
Definition: SCR_MilitaryBaseSystem.c:11
m_aBases
SCR_MilitaryBaseLogicComponentClass m_aBases
OnBaseUnregistered
void OnBaseUnregistered(notnull SCR_MilitaryBaseComponent base)
Definition: SCR_ServicePointComponent.c:104
GetBases
int GetBases(out array< SCR_MilitaryBaseComponent > bases)
Definition: SCR_MilitaryBaseLogicComponent.c:51
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_MilitaryBaseLogicComponent.c:87
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
RegisterBase
void RegisterBase(notnull SCR_MilitaryBaseComponent base)
Definition: SCR_MilitaryBaseLogicComponent.c:12
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_MilitaryBaseLogicComponent.c:72
Faction
Definition: Faction.c:12
~SCR_MilitaryBaseLogicComponent
void ~SCR_MilitaryBaseLogicComponent()
Definition: SCR_MilitaryBaseLogicComponent.c:99
UnregisterBase
void UnregisterBase(notnull SCR_MilitaryBaseComponent base)
Definition: SCR_MilitaryBaseLogicComponent.c:35