Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIChangeCompartment.c
Go to the documentation of this file.
2{
3 protected static const int COMPARTMENT_INIT = 0;
4 protected static const int COMPARTMENT_WITH_CORPSE = 1;
5 protected static const int COMPARTMENT_EMPTYING = 2;
6 protected static const int COMPARTMENT_EMPTY = 3;
7 protected static const int COMPARTMENT_CHANGING = 4;
8 protected static const int COMPARTMENT_CHANGED = 5;
9 protected static const int NO_COMPARTMENT_AVAILABLE = 6;
10
11 [Attribute("0", UIWidgets.EditBox, "Which compartment type owner switches to", "", ParamEnumArray.FromEnum(ECompartmentType))]
13
14 protected static const string TARGET_VEHICLE_PORT = "TargetVehicle";
15 protected static const string COMPARTMENT_TYPE_PORT = "CompartmentType";
16 protected static const string TELEPORT_IN_PORT = "TeleportInside";
17
19 override TStringArray GetVariablesIn() { return s_aVarsIn; }
20
26 protected IEntity m_vehicle;
27 protected bool m_TeleportInside;
28
29 //----------------------------------------------------------------------------------------------------------------------------------------
30 override void OnInit(AIAgent owner)
31 {
33 m_compartmentSlot = null;
34 m_target = ChimeraCharacter.Cast(owner.GetControlledEntity());
35 if (m_target)
36 m_compartmentAccess = SCR_CompartmentAccessComponent.Cast(m_target.GetCompartmentAccessComponent());
37 }
38
39 //----------------------------------------------------------------------------------------------------------------------------------------
40 override void OnEnter(AIAgent owner)
41 {
44
46 m_TeleportInside = false;
47
48 ECompartmentType compartmentType;
49 if (GetVariableIn(COMPARTMENT_TYPE_PORT,compartmentType))
50 m_eCompartmentType = compartmentType;
51 }
52
53 //----------------------------------------------------------------------------------------------------------------------------------------
54 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
55 {
57 return ENodeResult.FAIL;
58
60 }
61
62 //----------------------------------------------------------------------------------------------------------------------------------------
64 ENodeResult UpdateCompartmentSwitchState(int currentState, out int newState)
65 {
66 switch (currentState)
67 {
68 case COMPARTMENT_INIT:
69 {
70 if (!m_vehicle)
71 {
72 newState = NO_COMPARTMENT_AVAILABLE;
73 return ENodeResult.FAIL;
74 }
75 SCR_BaseCompartmentManagerComponent compMan = SCR_BaseCompartmentManagerComponent.Cast(m_vehicle.FindComponent(SCR_BaseCompartmentManagerComponent));
76 if (!compMan)
77 {
78 newState = NO_COMPARTMENT_AVAILABLE;
79 return ENodeResult.FAIL;
80 }
81
82 array<BaseCompartmentSlot> compartmentSlots = {};
83 compMan.GetCompartmentsOfType(compartmentSlots, m_eCompartmentType);
84
85 foreach (BaseCompartmentSlot slot : compartmentSlots)
86 {
87 if (slot.IsOccupied())
88 {
89 ChimeraCharacter occupant = ChimeraCharacter.Cast(slot.GetOccupant());
90 if (!occupant)
91 continue;
92 CharacterControllerComponent contr = occupant.GetCharacterController();
93 if (!contr)
94 continue;
95 if (contr.GetLifeState() == ECharacterLifeState.ALIVE)
96 continue;
97 m_compartmentAccessOccupant = SCR_CompartmentAccessComponent.Cast(occupant.GetCompartmentAccessComponent());
99 continue;
100 newState = COMPARTMENT_WITH_CORPSE;
101 }
102 else
103 newState = COMPARTMENT_EMPTY;
104 m_compartmentSlot = slot;
105 }
107 {
108 newState = NO_COMPARTMENT_AVAILABLE;
109 return ENodeResult.FAIL;
110 }
111 return ENodeResult.RUNNING;
112 }
114 {
115 vector teleportLocation[4];
116 m_compartmentAccessOccupant.FindSuitableTeleportLocation(teleportLocation);
117 m_compartmentAccessOccupant.GetOutVehicle_NoDoor(teleportLocation, false, false);
118 newState = COMPARTMENT_EMPTYING;
119 return ENodeResult.RUNNING;
120 }
122 {
123 if (!m_compartmentSlot.IsOccupied())
124 newState = COMPARTMENT_EMPTY;
125 return ENodeResult.RUNNING;
126 }
128 {
130 newState = COMPARTMENT_CHANGING;
131 return ENodeResult.RUNNING;
132 }
134 {
135 if (m_compartmentSlot.IsOccupied())
136 {
137 newState = COMPARTMENT_CHANGED;
138 return ENodeResult.SUCCESS;
139 }
140 return ENodeResult.RUNNING;
141 }
142 default:
143 return ENodeResult.RUNNING;
144 }
145 return ENodeResult.FAIL;
146 }
147
148 //----------------------------------------------------------------------------------------------------------------------------------------
150 {
151 CompartmentAccessComponent acc = occupant.GetCompartmentAccessComponent();
152 return acc.GetOutVehicle(EGetOutType.TELEPORT, -1, ECloseDoorAfterActions.INVALID, false);
153 }
154
155 //----------------------------------------------------------------------------------------------------------------------------------------
156 static override bool VisibleInPalette() { return true; }
157
158 //----------------------------------------------------------------------------------------------------------------------------------------
159 static override bool CanReturnRunning() { return true; }
160
161 //----------------------------------------------------------------------------------------------------------------------------------------
162 static override string GetOnHoverDescription()
163 {
164 return "ChangeCompartment: Changes compartment within the vehicle and keeps running until the character is in the desired slottype. \nIf slot is occupied by corpse, it kicks the corpse out";
165 }
166};
ECompartmentType
proto bool GetVariableIn(string name, out void val)
bool EjectOccupant(ChimeraCharacter occupant)
static const int NO_COMPARTMENT_AVAILABLE
override void OnEnter(AIAgent owner)
SCR_CompartmentAccessComponent m_compartmentAccessOccupant
static const string TELEPORT_IN_PORT
static const string TARGET_VEHICLE_PORT
SCR_CompartmentAccessComponent m_compartmentAccess
static const int COMPARTMENT_EMPTYING
BaseCompartmentSlot m_compartmentSlot
static ref TStringArray s_aVarsIn
override void OnInit(AIAgent owner)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
static override string GetOnHoverDescription()
static override bool VisibleInPalette()
static override bool CanReturnRunning()
ENodeResult UpdateCompartmentSwitchState(int currentState, out int newState)
Returns node result and state of the compartment switching process.
static const int COMPARTMENT_WITH_CORPSE
static const string COMPARTMENT_TYPE_PORT
override TStringArray GetVariablesIn()
static const int COMPARTMENT_CHANGING
ENodeResult
Definition ENodeResult.c:13
ECharacterLifeState
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385
ECloseDoorAfterActions
EGetOutType
Definition EGetOutType.c:13