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_AISwitchMagazine.c
Go to the documentation of this file.
1
class
SCR_AISwitchMagazine
:
SCR_AIWeaponHandlingBase
2
{
3
protected
static
const
string
PORT_MAGAZINE_COMPONENT
=
"MagazineComponent"
;
4
5
// Used for reloading of turret
6
// Acrual reload timer is not implemented in gamecode yet for AI, so we fake the reload time
7
protected
bool
m_bReloadingTimer
;
8
protected
float
m_fReloadFinishTime_ms
;
9
10
//--------------------------------------------------------------------------------------------
11
override
ENodeResult
EOnTaskSimulate
(AIAgent owner,
float
dt)
12
{
13
if
(!
m_WeaponMgrComp
|| !
m_ControlComp
|| !
m_InventoryMgr
)
14
return
ENodeResult
.FAIL;
15
16
BaseMagazineComponent
newMagazineComp = null;
17
GetVariableIn
(
PORT_MAGAZINE_COMPONENT
, newMagazineComp);
18
19
if
(!newMagazineComp)
20
{
21
#ifdef AI_DEBUG
22
AddDebugMessage(
"Skipped magazine switch, no magazine was provided"
);
23
#endif
24
return
ENodeResult
.SUCCESS;
25
}
26
27
// Resolve which weapon manager to use
28
BaseCompartmentSlot
compartmentSlot =
m_CompartmentAccessComp
.GetCompartment();
29
BaseWeaponManagerComponent weaponMgr;
30
if
(compartmentSlot)
31
weaponMgr = BaseWeaponManagerComponent.Cast(compartmentSlot.GetOwner().FindComponent(BaseWeaponManagerComponent));
32
else
33
weaponMgr =
m_WeaponMgrComp
;
34
35
// Check if we already have this magazine
36
BaseMagazineComponent
currentMagazineComp =
SCR_AIWeaponHandling
.GetCurrentMagazineComponent(weaponMgr);
37
if
(currentMagazineComp == newMagazineComp)
38
{
39
if
(!compartmentSlot)
40
{
41
if
(
m_ControlComp
.IsReloading())
42
return
ENodeResult
.RUNNING;
43
44
if
(!
SCR_AIWeaponHandling
.IsCurrentMuzzleChambered(weaponMgr,
true
))
45
{
46
#ifdef AI_DEBUG
47
AddDebugMessage(
"Muzzle is not chambered, requesting reload"
);
48
#endif
49
50
m_ControlComp
.ReloadWeapon();
51
return
ENodeResult
.RUNNING;
52
}
53
}
54
55
56
#ifdef AI_DEBUG
57
AddDebugMessage(
"Magazine switch completed"
);
58
#endif
59
return
ENodeResult
.SUCCESS;
60
}
61
62
// Switch magazine
63
if
(compartmentSlot)
64
{
65
//-----------------------------------------
66
// Turret magazine switching
67
68
IEntity
compartmentParentEntity = compartmentSlot.GetOwner();
69
TurretControllerComponent
turretController =
TurretControllerComponent
.Cast(compartmentParentEntity.
FindComponent
(
TurretControllerComponent
));
70
InventoryStorageManagerComponent
turretInventoryMgr = turretController.GetInventoryManager();
71
72
if
(turretInventoryMgr.Contains(newMagazineComp.GetOwner()))
73
{
74
if
(!
m_bReloadingTimer
)
75
{
76
// Start reloading timer
77
m_bReloadingTimer
=
true
;
78
float
reloadDuration_ms = 1000 * turretController.GetReloadDuration();
79
m_fReloadFinishTime_ms
=
GetGame
().GetWorld().GetWorldTime() + reloadDuration_ms;
80
81
#ifdef AI_DEBUG
82
AddDebugMessage(
string
.Format(
"Started turret reload timer: %1s %2 %3 %4"
, reloadDuration_ms/1000.0, newMagazineComp, newMagazineComp.GetOwner(), newMagazineComp.GetOwner().
GetPrefabData
().GetPrefabName()));
83
#endif
84
}
85
else
86
{
87
float
currentTime_ms =
GetGame
().GetWorld().GetWorldTime();
88
if
(currentTime_ms >=
m_fReloadFinishTime_ms
)
89
{
90
m_bReloadingTimer
=
false
;
91
92
#ifdef AI_DEBUG
93
AddDebugMessage(
string
.Format(
"StartMagazineSwitchTurret() %1 %2 %3"
, newMagazineComp, newMagazineComp.GetOwner(), newMagazineComp.GetOwner().
GetPrefabData
().GetPrefabName()));
94
#endif
95
SCR_AIWeaponHandling
.StartMagazineSwitchTurret(turretController, newMagazineComp);
96
}
97
}
98
99
return
ENodeResult
.RUNNING;
100
}
101
else
102
{
103
#ifdef AI_DEBUG
104
AddDebugMessage(
"Failed magazine switch, the magazine was not found in turret inventory"
);
105
#endif
106
return
ENodeResult
.FAIL;
107
}
108
}
109
else
110
{
111
//-----------------------------------------
112
// Character magazine switching
113
114
if
(
m_ControlComp
.IsReloading())
115
{
116
return
ENodeResult
.RUNNING;
117
}
118
else
119
{
120
// Start magazine change
121
// Ensure that the magazine is indeed in our inventory
122
// This check prevents AI equipping a rocket he just shot
123
if
(
m_InventoryMgr
.Contains(newMagazineComp.GetOwner()))
124
{
125
#ifdef AI_DEBUG
126
AddDebugMessage(
string
.Format(
"StartMagazineSwitchCharacter() %1 %2 %3"
, newMagazineComp, newMagazineComp.GetOwner(), newMagazineComp.GetOwner().
GetPrefabData
().GetPrefabName()));
127
#endif
128
SCR_AIWeaponHandling
.StartMagazineSwitchCharacter(
m_ControlComp
, newMagazineComp);
129
return
ENodeResult
.RUNNING;
130
}
131
else
132
{
133
#ifdef AI_DEBUG
134
AddDebugMessage(
"Failed magazine switch, the magazine was not found in inventory"
);
135
#endif
136
return
ENodeResult
.FAIL;
137
}
138
}
139
}
140
141
return
ENodeResult
.FAIL;
142
}
143
144
//--------------------------------------------------------------------------------------------
145
protected
static
ref
TStringArray
s_aVarsIn
= {
PORT_MAGAZINE_COMPONENT
};
146
override
TStringArray
GetVariablesIn
() {
return
s_aVarsIn
; }
147
148
static
override
bool
VisibleInPalette
() {
return
true
; }
149
}
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
BaseCompartmentSlot
Definition
BaseCompartmentSlot.c:2
BaseMagazineComponent
Definition
BaseMagazineComponent.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
IEntity::GetPrefabData
proto external EntityPrefabData GetPrefabData()
InventoryStorageManagerComponent
Definition
InventoryStorageManagerComponent.c:13
Node::GetVariableIn
proto bool GetVariableIn(string name, out void val)
SCR_AISwitchMagazine
Definition
SCR_AISwitchMagazine.c:2
SCR_AISwitchMagazine::VisibleInPalette
static override bool VisibleInPalette()
Definition
SCR_AISwitchMagazine.c:148
SCR_AISwitchMagazine::PORT_MAGAZINE_COMPONENT
static const string PORT_MAGAZINE_COMPONENT
Definition
SCR_AISwitchMagazine.c:3
SCR_AISwitchMagazine::m_fReloadFinishTime_ms
float m_fReloadFinishTime_ms
Definition
SCR_AISwitchMagazine.c:8
SCR_AISwitchMagazine::GetVariablesIn
override TStringArray GetVariablesIn()
Definition
SCR_AISwitchMagazine.c:146
SCR_AISwitchMagazine::m_bReloadingTimer
bool m_bReloadingTimer
Definition
SCR_AISwitchMagazine.c:7
SCR_AISwitchMagazine::EOnTaskSimulate
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Definition
SCR_AISwitchMagazine.c:11
SCR_AISwitchMagazine::s_aVarsIn
static ref TStringArray s_aVarsIn
Definition
SCR_AISwitchMagazine.c:145
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
TurretControllerComponent
Definition
TurretControllerComponent.c:13
ENodeResult
ENodeResult
Definition
ENodeResult.c:13
TStringArray
array< string > TStringArray
Definition
Types.c:385
scripts
Game
AI
ScriptedNodes
Weapons
SCR_AISwitchMagazine.c
Generated by
1.17.0