Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VehicleFactionAffiliationComponent.c
Go to the documentation of this file.
2 {
3 
4 };
5 
7 {
8  protected int m_iOccupantCount;
9  protected int m_iAliveOccupantCount;
10 
11  //--------------------------------------------------------------------------------------------------------------------------
12  override event void OnPostInit(IEntity owner)
13  {
14  ClearAffiliatedFaction();
15  }
16 
17  //--------------------------------------------------------------------------------------------------------------------------
19  bool IsVehicleOccupied()
20  {
21  return m_iOccupantCount > 0;
22  }
23 
24  //--------------------------------------------------------------------------------------------------------------------------
26  bool IsVehicleActive()
27  {
28  return m_iAliveOccupantCount > 0;
29  }
30 
31  //--------------------------------------------------------------------------------------------------------------------------
32  override protected void OnCompartmentEntered(IEntity vehicle, IEntity occupant, BaseCompartmentSlot compartment, bool move)
33  {
34  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(occupant);
35  if(!character)
36  return;
37 
38  // Test if the faction of the vehicle and the newly mounted passenger match.
39  // If not, we'll eject the new passenger
40  Faction characterFaction = character.GetFaction();
41  Faction vehicleFaction = GetAffiliatedFaction();
42 
43  if (characterFaction && !vehicleFaction)
44  {
45  // No faction on the vehicle, just set the occupant's faction
46  SetAffiliatedFaction(characterFaction);
47  }
48  else if (characterFaction && !characterFaction.IsFactionFriendly(GetAffiliatedFaction()))
49  {
50  // There is vehicleFaction set. Only overwrite it when there are no further occupants
51  if (!IsVehicleOccupied())
52  {
53  SetAffiliatedFaction(characterFaction);
54  }
55  };
56 
57  if (vehicleFaction && characterFaction && characterFaction.IsFactionEnemy(vehicleFaction) && !characterFaction.IsFactionEnemy(characterFaction))
58  {
59  CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
60  compartmentAccess.EjectOutOfVehicle();
61  // Drop through, we need to account for this new occupant still
62  };
63 
64  // Make us count.
65  m_iOccupantCount++;
66  UpdateOccupantsCount();
67  }
68 
69 
70  //--------------------------------------------------------------------------------------------------------------------------
71  override protected void OnCompartmentLeft(IEntity vehicle, IEntity occupant, BaseCompartmentSlot compartment, bool move)
72  {
73  if (move) // moving only between compartments
74  return;
75 
76  m_iOccupantCount--;
77  UpdateOccupantsCount(occupant);
78  }
79 
80  //--------------------------------------------------------------------------------------------------------------------------
81  void UpdateOccupantsCount(IEntity ignoreOccupant = null)
82  {
83  SCR_BaseCompartmentManagerComponent baseCompMan = SCR_BaseCompartmentManagerComponent.Cast(GetOwner().FindComponent(SCR_BaseCompartmentManagerComponent));
84  if (!baseCompMan)
85  return;
86 
87  array<IEntity> occupants = {};
88  baseCompMan.GetOccupants(occupants);
89  int aliveOccupants;
90  int allOccupants;
91  ECharacterLifeState state;
92  foreach(IEntity occupant : occupants)
93  {
94  if ((ignoreOccupant == occupant))
95  continue;
96 
97  ChimeraCharacter character = ChimeraCharacter.Cast(occupant);
98  if (!character)
99  continue;
100 
101  CharacterControllerComponent contr = character.GetCharacterController();
102  if (!contr)
103  continue;
104 
105  state = contr.GetLifeState();
106  if (state == ECharacterLifeState.ALIVE)
107  aliveOccupants++;
108 
109  if (state != ECharacterLifeState.DEAD)
110  allOccupants++;
111  }
112 
113  m_iAliveOccupantCount = aliveOccupants;
114  m_iOccupantCount = allOccupants;
115 
116  if (m_iOccupantCount < 1)
117  ClearAffiliatedFaction();
118  }
119 
120  //--------------------------------------------------------------------------------------------------------------------------
121  void OnOccupantLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
122  {
123  UpdateOccupantsCount();
124  }
125 };
SCR_VehicleFactionAffiliationComponent
Definition: SCR_VehicleFactionAffiliationComponent.c:6
ECharacterLifeState
ECharacterLifeState
Definition: ECharacterLifeState.c:12
SCR_VehicleFactionAffiliationComponentClass
Definition: SCR_VehicleFactionAffiliationComponent.c:1
SetAffiliatedFaction
proto external void SetAffiliatedFaction(Faction faction)
GetAffiliatedFaction
proto external Faction GetAffiliatedFaction()
Returns the affiliated faction or null if none.
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
Faction
Definition: Faction.c:12
SCR_FactionAffiliationComponent
Definition: SCR_FactionAffiliationComponent.c:10
SCR_FactionAffiliationComponentClass
Definition: SCR_FactionAffiliationComponent.c:1