Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIStaticArtilleryBehavior.c
Go to the documentation of this file.
3
4/*
5Behavior to operate a static artillery (like a mortar).
6Aims artillery, finds nearby arsenal with shells, then performs loop of taking shell and firing.
7*/
9{
10 protected ref SCR_BTParam<IEntity> m_ArtilleryEntity = new SCR_BTParam<IEntity>("ArtilleryEntity");
11 protected ref SCR_BTParam<vector> m_vTargetPos = new SCR_BTParam<vector>("TargetPos");
12
13 // Inventory entity where we will take ammo from. It is found automatically by the behavior
14 protected ref SCR_BTParam<IEntity> m_InventoryEntity = new SCR_BTParam<IEntity>("InventoryEntity");
15
16 // Ammo prefab, found automatically.
17 protected ref SCR_BTParam<ResourceName> m_AmmoPrefab = new SCR_BTParam<ResourceName>("AmmoPrefab");
18
19 // Counter of how many shots were made by this behavior
20 protected int m_iShotCount = 0;
21
22 // Ammo type which we were requested to use
24
25 protected ref ScriptInvokerBase<SCR_AIStaticArtilleryBehavior_OnArtilleryFired> m_OnArtilleryFired;
26
27 //------------------------------------------------------------------------------------------------------------------------------------------
28 void InitParameters(IEntity artilleryEntity, vector targetPos)
29 {
30 m_ArtilleryEntity.Init(this, artilleryEntity);
31 m_vTargetPos.Init(this, targetPos);
32 m_InventoryEntity.Init(this, null);
33 m_AmmoPrefab.Init(this, string.Empty);
34 }
35 //------------------------------------------------------------------------------------------------------------------------------------------
36 void SCR_AIStaticArtilleryBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, IEntity artilleryEntity, vector targetPos, SCR_EAIArtilleryAmmoType ammoType, float priorityLevel = PRIORITY_LEVEL_NORMAL)
37 {
38 InitParameters(artilleryEntity, targetPos);
39 m_eAmmoType = ammoType;
40
41 m_sBehaviorTree = "{2CB767812037EDDE}AI/BehaviorTrees/Chimera/Soldier/StaticArtilleryBehavior.bt";
42 SetPriority(PRIORITY_BEHAVIOR_STATIC_ARTILLERY);
43 m_fPriorityLevel.m_Value = priorityLevel;
44 m_bAllowLook = false; // Looking elsewhere is forbidden since it interferes with mortar aiming
45
46 if (artilleryEntity)
47 {
48 // Subscribe to deletion event. It can be deleted if destroyed.
50 if (vehicleUsageComp)
51 vehicleUsageComp.GetOnDeleted().Insert(OnArtilleryEntityDeleted);
52 }
53 }
54
55 //------------------------------------------------------------------------------------------------------------------------------------------
57 ScriptInvokerBase<SCR_AIStaticArtilleryBehavior_OnArtilleryFired> GetOnArtilleryFired()
58 {
60 m_OnArtilleryFired = new ScriptInvokerBase<SCR_AIStaticArtilleryBehavior_OnArtilleryFired>();
61 return m_OnArtilleryFired;
62 }
63
64 //------------------------------------------------------------------------------------------------------------------------------------------
66 {
67 return m_iShotCount;
68 }
69
70 //------------------------------------------------------------------------------------------------------------------------------------------
73 {
75
77 m_OnArtilleryFired.Invoke(this, m_Utility.GetAIAgent());
78 }
79
80 //------------------------------------------------------------------------------------------------------------------------------------------
81 override void OnActionSelected()
82 {
84 {
85 Print(string.Format("SCR_AIStaticArtilleryBehavior: Failed to resolve ammo prefab of type %1 for artillery entity: %2",
86 typename.EnumToString(SCR_EAIArtilleryAmmoType, m_eAmmoType), m_ArtilleryEntity.m_Value), LogLevel.ERROR);
87 Fail();
88 return;
89 }
90
91 // Temporary, prevent max LOD to keep the agent operate the artillery
92 AIAgent agent = m_Utility.GetOwner();
93 agent.PreventMaxLOD();
94 }
95
96 //------------------------------------------------------------------------------------------------------------------------------------------
97 override void OnActionDeselected()
98 {
99 AIAgent agent = m_Utility.GetOwner();
100 agent.AllowMaxLOD();
101 }
102
103 //------------------------------------------------------------------------------------------------------------------------------------------
109
110 //------------------------------------------------------------------------------------------------------------------------------------------
113 {
114 if (!m_ArtilleryEntity.m_Value)
115 return false;
116
117 // The artillery gun should have this component, which will resolve ammo type
119 if (!artilleryComp)
120 return false;
121
122 ResourceName ammoPrefab = artilleryComp.GetAmmoResourceName(m_eAmmoType);
123 if (ammoPrefab.IsEmpty())
124 return false;
125
126 m_AmmoPrefab.m_Value = ammoPrefab;
127 return true;
128 }
129
130 //------------------------------------------------------------------------------------------------------------------------------------------
131 override string GetActionDebugInfo()
132 {
133 return this.ToString() + " Operating " + m_ArtilleryEntity.m_Value.ToString();
134 }
135};
136
138{
139 static ref TStringArray s_aVarsOut = (new SCR_AIStaticArtilleryBehavior(null, null, null, vector.Zero, 0)).GetPortNames();
140 override TStringArray GetVariablesOut() { return s_aVarsOut; }
141
142 protected static override bool VisibleInPalette() { return true; }
143};
144
146{
147 static ref TStringArray s_aVarsIn = (new SCR_AIStaticArtilleryBehavior(null, null, null, vector.Zero, 0)).GetPortNames();
148 override TStringArray GetVariablesIn() { return s_aVarsIn; }
149
150 protected static override bool VisibleInPalette() { return true; }
151}
152
153/*
154Special node which is executed in static artillery behavior right after gunshot.
155*/
156class SCR_AIStaticArtilleryBehavior_ShootingLogic : AITaskScripted
157{
158 // Outputs
159 protected static const string PORT_AIMING_NEEDED = "AimingNeeded";
160
161 protected SCR_AIUtilityComponent m_Utility;
162
163 [Attribute("1", UIWidgets.EditBox, desc: "How many shots will be made before aiming the mortar again")]
165
166 //-----------------------------------------------------------------------
167 override void OnInit(AIAgent owner)
168 {
169 m_Utility = SCR_AIUtilityComponent.Cast(owner.FindComponent(SCR_AIUtilityComponent));
170 }
171
172 //-----------------------------------------------------------------------
173 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
174 {
175 if (!m_Utility)
176 return ENodeResult.FAIL;
177
178 SCR_AIStaticArtilleryBehavior behavior = SCR_AIStaticArtilleryBehavior.Cast(m_Utility.GetExecutedAction());
179 if (!behavior)
180 return ENodeResult.FAIL;
181
182 // Should we aim it again?
183 int shotCount = behavior.GetShotCount();
184 bool aimingNeeded = (shotCount > 0) &&
185 (m_iShotsBetweenAiming > 0) &&
186 ((shotCount % m_iShotsBetweenAiming) == 0);
187
188 SetVariableOut(PORT_AIMING_NEEDED, aimingNeeded);
189
190 // Notify behavior
191 behavior.Internal_OnArtilleryFired();
192
193 return ENodeResult.SUCCESS;
194 }
195
196 //-----------------------------------------------------------------------
197 protected static ref TStringArray s_aVarsOut = { PORT_AIMING_NEEDED };
198 override TStringArray GetVariablesOut() { return s_aVarsOut; }
199
200 override static bool VisibleInPalette() { return true; }
201}
ref SCR_BTParam< float > m_fPriorityLevel
enum EAIActionFailReason PRIORITY_LEVEL_NORMAL
TStringArray GetPortNames()
ResourceName m_sBehaviorTree
EAIActionFailReason
Fail reasons of actions. They can be generic or specific to some behavior.
Definition SCR_AIAction.c:3
void SetFailReason(EAIActionFailReason failReason)
Fail reason is an optional value which can be used to figure out why action failed.
void Fail(bool doNotCompleteWaypoint)
void SCR_AIActivityBase(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint)
enum SCR_EAIActivityCause m_Utility
void SCR_AIBehaviorBase(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity)
bool m_bAllowLook
override TStringArray GetVariablesIn()
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
SCR_AISetStaticArtilleryBehaviorParameters PORT_AIMING_NEEDED
func SCR_AIStaticArtilleryBehavior_OnArtilleryFired
override TStringArray GetVariablesOut()
SCR_AIUtilityComponent m_Utility
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto void SetVariableOut(string name, void val)
bool VisibleInPalette()
TStringArray GetVariablesOut()
Definition Node.c:28
ref SCR_BTParam< IEntity > m_ArtilleryEntity
void InitParameters(IEntity artilleryEntity, vector targetPos)
ScriptInvokerBase< SCR_AIStaticArtilleryBehavior_OnArtilleryFired > GetOnArtilleryFired()
Returns event which is invoked every time AI who executes this behavior fires an artillery.
bool InitAmmoPrefabValue()
Finds which prefab is used by the muzzle.
ref SCR_BTParam< ResourceName > m_AmmoPrefab
void SCR_AIStaticArtilleryBehavior(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity, IEntity artilleryEntity, vector targetPos, SCR_EAIArtilleryAmmoType ammoType, float priorityLevel=PRIORITY_LEVEL_NORMAL)
ref ScriptInvokerBase< SCR_AIStaticArtilleryBehavior_OnArtilleryFired > m_OnArtilleryFired
void OnArtilleryEntityDeleted(SCR_AIVehicleUsageComponent comp)
ref SCR_BTParam< IEntity > m_InventoryEntity
void Internal_OnArtilleryFired()
Called by the SCR_AIStaticArtilleryBehavior_ShootingLogic node from behavior tree.
ScriptInvokerBase< SCR_AIOnVehicleDeleted > GetOnDeleted()
ENodeResult
Definition ENodeResult.c:13
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
array< string > TStringArray
Definition Types.c:385
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.