Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VehicleFactionAffiliationComponent.c
Go to the documentation of this file.
5
7{
8 protected int m_iOccupantCount;
9 protected int m_iAliveOccupantCount;
10
11 //--------------------------------------------------------------------------------------------------------------------------
12 override event void OnPostInit(IEntity owner)
13 {
15 }
16
17 //--------------------------------------------------------------------------------------------------------------------------
20 {
21 return m_iOccupantCount > 0;
22 }
23
24 //--------------------------------------------------------------------------------------------------------------------------
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.GetOutVehicle(EGetOutType.TELEPORT, -1, ECloseDoorAfterActions.INVALID, false);
61 // Drop through, we need to account for this new occupant still
62 };
63
64 // Make us count.
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
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;
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)
118 }
119
120 //--------------------------------------------------------------------------------------------------------------------------
122 {
124 }
125};
void OnOccupantLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
void OnCompartmentEntered(IEntity vehicle, IEntity occupant, BaseCompartmentSlot compartment, bool move)
void OnCompartmentLeft(IEntity vehicle, IEntity occupant, BaseCompartmentSlot compartment, bool move)
bool IsVehicleOccupied()
Check if there are any occupants regardless of life state.
bool IsVehicleActive()
Check if there are any conscious and alive occupants among the occupants.
IEntity GetOwner()
Owner entity of the fuel tank.
ECharacterLifeState
proto external void SetAffiliatedFaction(Faction faction)
SCR_CampaignFaction GetAffiliatedFaction()
Returns the affiliated faction or null if none.
ECloseDoorAfterActions
EGetOutType
Definition EGetOutType.c:13