Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RemoveCasualtyUserAction.c
Go to the documentation of this file.
1 class SCR_RemoveCasualtyUserAction : SCR_CompartmentUserAction
2 {
3  const string m_sCannotPerformHostile = "#AR-UserAction_SeatHostile";
4  const string m_sCannotPerformObstructed = "#AR-UserAction_SeatObstructed";
5 
6  //------------------------------------------------------------------------------------------------
7  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
8  {
9  if (!pOwnerEntity)
10  return;
11 
12  BaseCompartmentSlot compartment = GetCompartmentSlot();
13  if (!compartment)
14  return;
15 
16  ChimeraCharacter casualty = ChimeraCharacter.Cast(compartment.GetOccupant());
17  if (!casualty)
18  return;
19 
20  CompartmentAccessComponent casualtyCompartmentAccess = casualty.GetCompartmentAccessComponent();
21  if (casualtyCompartmentAccess)
22  casualtyCompartmentAccess.EjectOutOfVehicle();
23 
24  super.PerformAction(pOwnerEntity, pUserEntity);
25  }
26 
27  //------------------------------------------------------------------------------------------------
28  override bool CanBePerformedScript(IEntity user)
29  {
30  BaseCompartmentSlot compartment = GetCompartmentSlot();
31  if (!compartment)
32  return false;
33 
34  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(user);
35  if (!character)
36  return false;
37 
38  CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
39  if (!compartmentAccess)
40  return false;
41 
42  // Restrict removing casualty from another compartment in case the section does not match
43  BaseCompartmentSlot characterCompartment = compartmentAccess.GetCompartment();
44  if (characterCompartment && characterCompartment.GetCompartmentSection() != compartment.GetCompartmentSection())
45  return false;
46 
47  IEntity owner = compartment.GetOwner();
48  Vehicle vehicle = Vehicle.Cast(owner.GetRootParent());
49  if (vehicle)
50  {
51  Faction characterFaction = character.GetFaction();
52  Faction vehicleFaction = vehicle.GetFaction();
53 
54  if (characterFaction && vehicleFaction && characterFaction.IsFactionEnemy(vehicleFaction))
55  {
56  bool isActive = true;
57  SCR_VehicleFactionAffiliationComponent vehicleAffiliation = vehicle.GetFactionAffiliation();
58  if (vehicleAffiliation)
59  isActive = vehicleAffiliation.IsVehicleActive();
60 
61  if (isActive)
62  {
63  SetCannotPerformReason(m_sCannotPerformHostile);
64  return false;
65  }
66  }
67  }
68 
69  // Make sure vehicle can be enter via provided door, if not, set reason.
70  if (!character.IsInVehicle() && !compartmentAccess.CanGetInVehicleViaDoor(owner, compartment, GetRelevantDoorIndex(user)))
71  {
72  SetCannotPerformReason(m_sCannotPerformObstructed);
73  return false;
74  }
75 
76  return true;
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  override bool CanBeShownScript(IEntity user)
81  {
82  BaseCompartmentSlot compartment = GetCompartmentSlot();
83  if (!compartment)
84  return false;
85 
86  ChimeraCharacter character = ChimeraCharacter.Cast(user);
87  if (!character)
88  return false;
89 
90  CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
91  if (!compartmentAccess)
92  return false;
93 
94  if (compartmentAccess.IsGettingIn() || compartmentAccess.IsGettingOut())
95  return false;
96 
97  // Restrict removing casualty from another compartment in case the section does not match
98  BaseCompartmentSlot characterCompartment = compartmentAccess.GetCompartment();
99  if (characterCompartment && characterCompartment.GetCompartmentSection() != compartment.GetCompartmentSection())
100  return false;
101 
102  ChimeraCharacter casualty = ChimeraCharacter.Cast(compartment.GetOccupant());
103  if (!casualty)
104  return false;
105 
106  CharacterControllerComponent controller = casualty.GetCharacterController();
107  if (!controller)
108  return false;
109 
110  return controller.GetLifeState() != ECharacterLifeState.ALIVE;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  override bool HasLocalEffectOnlyScript()
115  {
116  return false;
117  }
118 }
SCR_VehicleFactionAffiliationComponent
Definition: SCR_VehicleFactionAffiliationComponent.c:6
ECharacterLifeState
ECharacterLifeState
Definition: ECharacterLifeState.c:12
Faction
Definition: Faction.c:12
SCR_RemoveCasualtyUserAction
Definition: SCR_RemoveCasualtyUserAction.c:1