Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RemoveCasualtyUserAction.c
Go to the documentation of this file.
2{
3 const string m_sCannotPerformHostile = "#AR-UserAction_SeatHostile";
4 const string m_sCannotPerformObstructed = "#AR-UserAction_SeatObstructed";
5
6 [Attribute(desc: "If true, the action will be only shown if player is inside a vehicle")]
7 protected bool m_bInteriorOnly;
8
9 [Attribute(desc: "If true, the action will be only shown if player is not inside a vehicle")]
10 protected bool m_bExteriorOnly;
11
12 //------------------------------------------------------------------------------------------------
13 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
14 {
15 if (!pOwnerEntity)
16 return;
17
18 BaseCompartmentSlot compartment = GetCompartmentSlot();
19 if (!compartment)
20 return;
21
22 ChimeraCharacter casualty = ChimeraCharacter.Cast(compartment.GetOccupant());
23 if (!casualty)
24 return;
25
26 ChimeraCharacter user = ChimeraCharacter.Cast(pUserEntity);
27 if (!user)
28 return;
29
30 SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(user.GetCharacterController());
31 if (controller && controller.IsLoitering())
32 return;
33
34 CompartmentAccessComponent userCompartmentAccess = user.GetCompartmentAccessComponent();
35 CompartmentAccessComponent casualtyCompartmentAccess = casualty.GetCompartmentAccessComponent();
36 if (casualtyCompartmentAccess && userCompartmentAccess)
37 {
38 int doorIdx = GetRelevantDoorIndex(pUserEntity);
39 casualtyCompartmentAccess.KickFromVehicle(doorIdx);
40 }
41
42 if (compartment.IsPiloting()) // even a dead driver applies brakes to the car using the engine, so when we remove the driver from the compartment
43 { // we pull the handbrake to make it less confusing during gameplay
44 CarControllerComponent car = CarControllerComponent.Cast(compartment.GetController());
45 if(car)
46 car.SetPersistentHandBrake(true)
47 }
48
49 super.PerformAction(pOwnerEntity, pUserEntity);
50 }
51
52 //------------------------------------------------------------------------------------------------
53 override bool CanBePerformedScript(IEntity user)
54 {
55 BaseCompartmentSlot compartment = GetCompartmentSlot();
56 if (!compartment)
57 return false;
58
59 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(user);
60 if (!character)
61 return false;
62
63 SCR_CharacterControllerComponent controller = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
64 if (controller && controller.IsLoitering())
65 return false;
66
67 CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
68 if (!compartmentAccess)
69 return false;
70
71 // Restrict removing casualty from another compartment in case the section does not match
72 BaseCompartmentSlot characterCompartment = compartmentAccess.GetCompartment();
73 if (characterCompartment && characterCompartment.GetCompartmentSection() != compartment.GetCompartmentSection())
74 return false;
75
76 IEntity owner = compartment.GetOwner();
77 Vehicle vehicle = Vehicle.Cast(owner.GetRootParent());
78 if (vehicle)
79 {
80 Faction characterFaction = character.GetFaction();
81 Faction vehicleFaction = vehicle.GetFaction();
82
83 if (characterFaction && vehicleFaction && characterFaction.IsFactionEnemy(vehicleFaction))
84 {
85 bool isActive = true;
86 SCR_VehicleFactionAffiliationComponent vehicleAffiliation = vehicle.GetFactionAffiliation();
87 if (vehicleAffiliation)
88 isActive = vehicleAffiliation.IsVehicleActive();
89
90 if (isActive)
91 {
92 SetCannotPerformReason(m_sCannotPerformHostile);
93 return false;
94 }
95 }
96 }
97
98 BaseCompartmentManagerComponent managerComponent = compartment.GetManager();
99 if (!managerComponent)
100 return false;
101
102 // Make sure vehicle can be enter via provided door, if not, set reason.
103 if (!character.IsInVehicle() && !compartmentAccess.CanGetInVehicleViaDoor(owner, managerComponent, GetRelevantDoorIndex(user)))
104 {
105 SetCannotPerformReason(m_sCannotPerformObstructed);
106 return false;
107 }
108
109 return true;
110 }
111
112 //------------------------------------------------------------------------------------------------
113 override bool CanBeShownScript(IEntity user)
114 {
115 BaseCompartmentSlot compartment = GetCompartmentSlot();
116 if (!compartment)
117 return false;
118
119 ChimeraCharacter character = ChimeraCharacter.Cast(user);
120 if (!character)
121 return false;
122
123 CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
124 if (!compartmentAccess)
125 return false;
126
127 if (compartmentAccess.IsGettingIn() || compartmentAccess.IsGettingOut())
128 return false;
129
130 // Restrict removing casualty from another compartment in case the section does not match
131 BaseCompartmentSlot characterCompartment = compartmentAccess.GetCompartment();
132 if (characterCompartment && characterCompartment.GetCompartmentSection() != compartment.GetCompartmentSection())
133 return false;
134
135 ChimeraCharacter casualty = ChimeraCharacter.Cast(compartment.GetOccupant());
136 if (!casualty)
137 return false;
138
139 CharacterControllerComponent controller = casualty.GetCharacterController();
140 if (!controller)
141 return false;
142
143 if (m_bInteriorOnly && !SCR_InteractionHandlerComponent.CanBeShownInVehicle(character, this, interiorOnly: m_bInteriorOnly))
144 return false;
145
146 if (m_bExteriorOnly && character.IsInVehicle())
147 return false;
148
149 return controller.GetLifeState() != ECharacterLifeState.ALIVE;
150 }
151
152 //------------------------------------------------------------------------------------------------
154 {
155 return false;
156 }
157}
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
int GetCompartmentSection()
Switching seats is allowed only between compartments with matching area.
void SetCannotPerformReason(string reason)
proto external IEntity GetRootParent()
override bool CanBePerformedScript(IEntity user)
override bool CanBeShownScript(IEntity user)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
bool IsVehicleActive()
Check if there are any conscious and alive occupants among the occupants.
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
ECharacterLifeState
SCR_FieldOfViewSettings Attribute