Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_AISwitchWeapon.c
Go to the documentation of this file.
1
class
SCR_AISwitchWeaponMovedCallback :
ScriptedInventoryOperationCallback
2
{
3
ref
SCR_AISwitchWeapon
m_Task;
4
5
//------------------------------------------------------------------------------------------------
6
void
SCR_AISwitchWeaponMovedCallback(
SCR_AISwitchWeapon
task
)
7
{
8
m_Task =
task
;
9
}
10
11
void
Invalidate() { m_Task = null; }
12
13
//------------------------------------------------------------------------------------------------
14
override
protected
void
OnComplete
()
15
{
16
if
(m_Task)
17
{
18
m_Task.OnMoveWeaponFinished(
true
);
19
Invalidate();
20
}
21
22
}
23
24
//------------------------------------------------------------------------------------------------
25
override
protected
void
OnFailed
()
26
{
27
if
(m_Task)
28
{
29
m_Task.OnMoveWeaponFinished(
false
);
30
Invalidate();
31
}
32
33
}
34
};
35
36
37
class
SCR_AISwitchWeapon
:
SCR_AIWeaponHandlingBase
38
{
39
protected
static
const
int
WEAPON_STATE_IDLE
= 0;
40
protected
static
const
int
WEAPON_STATE_MOVING
= 1;
41
protected
static
const
int
WEAPON_STATE_MOVED
= 2;
42
43
protected
static
const
string
PORT_WEAPON_COMPONENT
=
"WeaponComponent"
;
44
45
protected
int
m_iWeaponState
;
46
47
protected
EquipedWeaponStorageComponent
m_EqWeaponStorageComp
;
48
protected
ref
SCR_AISwitchWeaponMovedCallback
m_WeaponMoveCallback
;
49
50
//--------------------------------------------------------------------------------------------
51
void
OnMoveWeaponFinished
(
bool
result)
52
{
53
#ifdef AI_DEBUG
54
AddDebugMessage(
string
.Format(
"OnMoveWeaponFinished: %1"
, result));
55
#endif
56
57
m_iWeaponState
=
WEAPON_STATE_MOVED
;
58
}
59
60
//--------------------------------------------------------------------------------------------
61
override
ENodeResult
EOnTaskSimulate
(AIAgent owner,
float
dt)
62
{
63
if
(!
m_WeaponMgrComp
|| !
m_ControlComp
|| !
m_InventoryMgr
)
64
return
ENodeResult
.FAIL;
65
66
BaseWeaponComponent
newWeaponComp = null;
67
GetVariableIn
(
PORT_WEAPON_COMPONENT
, newWeaponComp);
68
if
(!newWeaponComp)
69
return
ENodeResult
.FAIL;
70
71
// Resolve which weapon manager to use
72
BaseCompartmentSlot
compartmentSlot =
m_CompartmentAccessComp
.GetCompartment();
73
BaseWeaponManagerComponent weaponMgr;
74
if
(compartmentSlot)
75
weaponMgr = BaseWeaponManagerComponent.Cast(compartmentSlot.GetOwner().FindComponent(BaseWeaponManagerComponent));
76
else
77
weaponMgr =
m_WeaponMgrComp
;
78
79
if
(!weaponMgr)
80
return
ENodeResult
.FAIL;
81
82
BaseWeaponComponent
currentWeaponComp = weaponMgr.GetCurrentWeapon();
83
84
if
(compartmentSlot)
85
{
86
//-----------------------------------------
87
// Turret weapon switching
88
89
IEntity
compartmentParentEntity = compartmentSlot.GetOwner();
90
TurretControllerComponent
turretController =
TurretControllerComponent
.Cast(compartmentParentEntity.
FindComponent
(
TurretControllerComponent
));
91
92
if
(!turretController)
93
{
94
#ifdef AI_DEBUG
95
AddDebugMessage(
"Weapon switch failed: no turret controller on turret"
,
LogLevel
.WARNING);
96
#endif
97
return
ENodeResult
.FAIL;
98
}
99
100
if
(currentWeaponComp == newWeaponComp)
// Return success if done
101
{
102
#ifdef AI_DEBUG
103
AddDebugMessage(
"Weapon switch completed"
);
104
#endif
105
return
ENodeResult
.SUCCESS;
106
}
107
108
#ifdef AI_DEBUG
109
AddDebugMessage(
string
.Format(
"StartWeaponSwitchTurret: %1 %2 %3"
, newWeaponComp, newWeaponComp.GetOwner(), newWeaponComp.GetOwner().
GetPrefabData
().GetPrefabName()));
110
#endif
111
SCR_AIWeaponHandling
.StartWeaponSwitchTurret(turretController, newWeaponComp, owner.GetControlledEntity());
112
return
ENodeResult
.RUNNING;
113
}
114
else
115
{
116
//-----------------------------------------
117
// Character weapon switching
118
119
if
(
m_ControlComp
.IsChangingItem())
120
return
ENodeResult
.RUNNING;
121
122
if
(currentWeaponComp == newWeaponComp)
// Return success if done
123
{
124
#ifdef AI_DEBUG
125
AddDebugMessage(
"Weapon switch completed"
);
126
#endif
127
return
ENodeResult
.SUCCESS;
128
}
129
130
if
(!
m_InventoryMgr
.Contains(newWeaponComp.GetOwner()))
131
{
132
#ifdef AI_DEBUG
133
AddDebugMessage(
"Weapon switch failed: weapon is not in inventory"
,
LogLevel
.WARNING);
134
#endif
135
return
ENodeResult
.FAIL;
136
}
137
138
#ifdef AI_DEBUG
139
AddDebugMessage(
string
.Format(
"StartWeaponSwitchCharacter: %1 %2 %3"
, newWeaponComp, newWeaponComp.GetOwner(), newWeaponComp.GetOwner().
GetPrefabData
().GetPrefabName()));
140
#endif
141
142
if
(
m_iWeaponState
==
WEAPON_STATE_MOVING
)
143
return
ENodeResult
.RUNNING;
144
145
array<IEntity> weapons = {};
146
m_WeaponMgrComp
.GetWeaponsList(weapons);
147
148
IEntity
newWeaponEnt = newWeaponComp.GetOwner();
149
150
if
(!weapons.Contains(newWeaponEnt))
151
{
152
// Return fail if weapon was moved and it's still unavailable
153
if
(
m_iWeaponState
==
WEAPON_STATE_MOVED
)
154
return
ENodeResult
.FAIL;
155
156
IEntity
controlledEnt = owner.GetControlledEntity();
157
158
if
(!
m_EqWeaponStorageComp
)
159
m_EqWeaponStorageComp
=
EquipedWeaponStorageComponent
.Cast(controlledEnt.
FindComponent
(
EquipedWeaponStorageComponent
));
160
161
if
(!
m_EqWeaponStorageComp
)
162
return
ENodeResult
.FAIL;
163
164
m_iWeaponState
=
WEAPON_STATE_MOVING
;
165
166
if
(
m_WeaponMoveCallback
)
167
m_WeaponMoveCallback
.Invalidate();
168
169
m_WeaponMoveCallback
=
new
SCR_AISwitchWeaponMovedCallback
(
this
);
170
171
InventoryStorageSlot
slot =
m_EqWeaponStorageComp
.FindSuitableSlotForItem(newWeaponEnt);
172
IEntity
existingEntityAtSlot = null;
173
if
(slot)
174
existingEntityAtSlot = slot.GetAttachedEntity();
175
176
if
(existingEntityAtSlot)
177
{
178
#ifdef AI_DEBUG
179
AddDebugMessage(
"Weapon is not in the weapon manager list, slot already occupied, requesting swap of weapon and existing entity in slot"
);
180
#endif
181
m_InventoryMgr
.TrySwapItemStorages(newWeaponEnt, existingEntityAtSlot,
m_WeaponMoveCallback
);
182
}
183
else
184
{
185
#ifdef AI_DEBUG
186
AddDebugMessage(
"Weapon is not in the weapon manager list, requesting move to EquipedWeaponStorageComponent"
);
187
#endif
188
m_InventoryMgr
.TryMoveItemToStorage(newWeaponEnt,
m_EqWeaponStorageComp
, -1,
m_WeaponMoveCallback
);
189
}
190
191
return
ENodeResult
.RUNNING;
192
}
193
194
m_iWeaponState
=
WEAPON_STATE_IDLE
;
195
SCR_AIWeaponHandling
.StartWeaponSwitchCharacter(
m_ControlComp
, newWeaponComp);
196
197
return
ENodeResult
.RUNNING;
198
}
199
200
return
ENodeResult
.FAIL;
201
}
202
203
204
override
void
OnAbort
(AIAgent owner,
Node
nodeCausingAbort)
205
{
206
m_iWeaponState
=
WEAPON_STATE_IDLE
;
207
208
if
(
m_WeaponMoveCallback
)
209
m_WeaponMoveCallback
.Invalidate();
210
211
m_WeaponMoveCallback
= null;
212
}
213
214
//--------------------------------------------------------------------------------------------
215
protected
static
ref
TStringArray
s_aVarsIn
= {
PORT_WEAPON_COMPONENT
};
216
override
TStringArray
GetVariablesIn
() {
return
s_aVarsIn
; }
217
218
static
override
bool
VisibleInPalette
() {
return
true
; }
219
}
task
from task
Definition
SCR_TaskNotificationConfigs.c:12
BaseCompartmentSlot
Definition
BaseCompartmentSlot.c:2
BaseWeaponComponent
Definition
BaseWeaponComponent.c:13
EquipedWeaponStorageComponent
Definition
EquipedWeaponStorageComponent.c:6
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
IEntity::GetPrefabData
proto external EntityPrefabData GetPrefabData()
InventoryStorageSlot
Definition
InventoryStorageSlot.c:13
Node
Definition
Node.c:13
Node::GetVariableIn
proto bool GetVariableIn(string name, out void val)
SCR_AISwitchWeapon
Definition
SCR_AISwitchWeapon.c:38
SCR_AISwitchWeapon::WEAPON_STATE_IDLE
static const int WEAPON_STATE_IDLE
Definition
SCR_AISwitchWeapon.c:39
SCR_AISwitchWeapon::m_WeaponMoveCallback
ref SCR_AISwitchWeaponMovedCallback m_WeaponMoveCallback
Definition
SCR_AISwitchWeapon.c:48
SCR_AISwitchWeapon::GetVariablesIn
override TStringArray GetVariablesIn()
Definition
SCR_AISwitchWeapon.c:216
SCR_AISwitchWeapon::OnAbort
override void OnAbort(AIAgent owner, Node nodeCausingAbort)
Definition
SCR_AISwitchWeapon.c:204
SCR_AISwitchWeapon::WEAPON_STATE_MOVED
static const int WEAPON_STATE_MOVED
Definition
SCR_AISwitchWeapon.c:41
SCR_AISwitchWeapon::m_EqWeaponStorageComp
EquipedWeaponStorageComponent m_EqWeaponStorageComp
Definition
SCR_AISwitchWeapon.c:47
SCR_AISwitchWeapon::s_aVarsIn
static ref TStringArray s_aVarsIn
Definition
SCR_AISwitchWeapon.c:215
SCR_AISwitchWeapon::m_iWeaponState
int m_iWeaponState
Definition
SCR_AISwitchWeapon.c:45
SCR_AISwitchWeapon::WEAPON_STATE_MOVING
static const int WEAPON_STATE_MOVING
Definition
SCR_AISwitchWeapon.c:40
SCR_AISwitchWeapon::PORT_WEAPON_COMPONENT
static const string PORT_WEAPON_COMPONENT
Definition
SCR_AISwitchWeapon.c:43
SCR_AISwitchWeapon::EOnTaskSimulate
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Definition
SCR_AISwitchWeapon.c:61
SCR_AISwitchWeapon::OnMoveWeaponFinished
void OnMoveWeaponFinished(bool result)
Definition
SCR_AISwitchWeapon.c:51
SCR_AISwitchWeapon::VisibleInPalette
static override bool VisibleInPalette()
Definition
SCR_AISwitchWeapon.c:218
SCR_AISwitchWeaponMovedCallback
Definition
SCR_AISwitchWeapon.c:2
SCR_AISwitchWeaponMovedCallback::OnFailed
void OnFailed()
Definition
SCR_AISwitchWeapon.c:25
SCR_AISwitchWeaponMovedCallback::OnComplete
void OnComplete()
Definition
SCR_AISwitchWeapon.c:14
SCR_AIWeaponHandlingBase
Base class for nodes which handle magazine switching.
Definition
SCR_AIWeaponHandlingBase.c:3
SCR_AIWeaponHandlingBase::m_CompartmentAccessComp
CompartmentAccessComponent m_CompartmentAccessComp
Definition
SCR_AIWeaponHandlingBase.c:7
SCR_AIWeaponHandlingBase::m_WeaponMgrComp
BaseWeaponManagerComponent m_WeaponMgrComp
Definition
SCR_AIWeaponHandlingBase.c:5
SCR_AIWeaponHandlingBase::m_ControlComp
CharacterControllerComponent m_ControlComp
Definition
SCR_AIWeaponHandlingBase.c:4
SCR_AIWeaponHandlingBase::m_InventoryMgr
SCR_InventoryStorageManagerComponent m_InventoryMgr
Definition
SCR_AIWeaponHandlingBase.c:6
SCR_AIWeaponHandling
Definition
SCR_AIUtils.c:299
ScriptedInventoryOperationCallback
Definition
ScriptedInventoryOperationCallback.c:13
TurretControllerComponent
Definition
TurretControllerComponent.c:13
ENodeResult
ENodeResult
Definition
ENodeResult.c:13
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
TStringArray
array< string > TStringArray
Definition
Types.c:385
scripts
Game
AI
ScriptedNodes
Weapons
SCR_AISwitchWeapon.c
Generated by
1.17.0