21 SetPriority(PRIORITY_ACTIVITY_ARTILLERY_SUPPORT);
23 SetIsUniqueInActionQueue(
false);
29 super.OnActionSelected();
33 array<ref SCR_AIGroupVehicle> allVehicles = {};
34 array<ref SCR_AIGroupVehicle> usableTurrets = {};
35 array<AIAgent> freeAgents = {};
36 array<AIAgent> assignedAgents = {};
38 m_Utility.m_VehicleMgr.GetAllVehicles(allVehicles);
45 if (!vehicleUsageComp)
56 IEntity occupant = slot.GetOccupant();
59 AIAgent occupantAgent =
SCR_AIUtils.GetAIAgent(occupant);
62 else if (occupantAgent.GetParentGroup() !=
m_Utility.m_Owner)
66 usableTurrets.Insert(v);
67 assignedAgents.Insert(occupantAgent);
68 freeAgents.RemoveItem(occupantAgent);
73 usableTurrets.Insert(v);
74 assignedAgents.Insert(null);
79 for (
int i = 0; i < usableTurrets.Count(); i++)
82 if (assignedAgents[i])
86 if (freeAgents.IsEmpty())
95 assignedAgents[i] = bestAgent;
96 freeAgents.Remove(bestAgentId);
104 foreach (
auto a : assignedAgents)
116 float minDistSq =
float.MAX;
117 AIAgent bestAgent = null;
118 int bestAgentIndex = -1;
119 vector artilleryPos = artilleryEntity.GetOrigin();
121 foreach (
int i, AIAgent agent : agents)
123 IEntity controlledEntity = agent.GetControlledEntity();
124 if (!controlledEntity)
127 float distSq =
vector.DistanceSq(controlledEntityPos, artilleryPos);
128 if (distSq < minDistSq)
136 outIndex = bestAgentIndex;
143 super.OnActionDeselected();
150 super.OnActionCompleted();
157 super.OnActionFailed();
166 protected void SendMessages(notnull array<ref SCR_AIGroupVehicle> turrets, notnull array<AIAgent> assignedAgents)
168 AICommunicationComponent myComms =
m_Utility.m_Owner.GetCommunicationComponent();
172 for (
int i = 0; i < turrets.Count(); i++)
175 AIAgent agent = assignedAgents[i];
181 msg.m_RelatedGroupActivity =
this;
183 msg.m_ArtilleryEntity = turret.
GetEntity();
186 msg.SetReceiver(agent);
188 myComms.RequestBroadcast(msg, agent);
199 if (!artilleryBehavior)
219 int failReason = childBehavior.GetFailReason();
223 AIAgent agent = childBehavior.m_Utility.GetAIAgent();
228 int nValidAssigned = 0;
240 if (nValidAssigned == nFailed)
244 Print(
string.Format(
"SCR_AIStaticArtilleryActivity: FAILED, noone can shoot at the target position: %1, or there is no ammo",
m_vTargetPos),
LogLevel.DEBUG);
ref SCR_BTParam< float > m_fPriorityLevel
enum EAIActionFailReason PRIORITY_LEVEL_NORMAL
EAIActionFailReason
Fail reasons of actions. They can be generic or specific to some behavior.
void Fail(bool doNotCompleteWaypoint)
void SendCancelMessagesToAllAgents()
void SCR_AIActivityBase(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint)
enum SCR_EAIActivityCause m_Utility
AIWaypoint m_RelatedWaypoint
void SCR_AIBehaviorBase(SCR_AIUtilityComponent utility, SCR_AIActivityBase groupActivity)
void SCR_AIMessage_ArtillerySupport()
EAIVehicleType
Vehicle type from point view of AI usage.
proto external vector GetOrigin()
This class is used for keeping track of vehicles assigned to group.
ref array< AIAgent > m_aAssignedAgents
ref array< AIAgent > m_aFailedAgents
override void OnActionSelected()
override void OnActionDeselected()
override void OnActionCompleted()
override void OnChildBehaviorCreated(SCR_AIBehaviorBase childBehavior)
SCR_EAIArtilleryAmmoType m_eAmmoType
void OnChildBehaviorArtilleryFired(SCR_AIStaticArtilleryBehavior behavior, AIAgent agent)
void SendMessages(notnull array< ref SCR_AIGroupVehicle > turrets, notnull array< AIAgent > assignedAgents)
override void OnActionFailed()
AIAgent FindBestAgentForArtillery(notnull array< AIAgent > agents, notnull IEntity artilleryEntity, out int outIndex)
Selects best agent to operate artillery entity. Now selects nearest agent.
void SCR_AIStaticArtilleryActivity(SCR_AIGroupUtilityComponent utility, AIWaypoint relatedWaypoint, vector targetPos, SCR_EAIArtilleryAmmoType ammoType, int targetShotCount, float priorityLevel=PRIORITY_LEVEL_NORMAL)
override void OnChildBehaviorFinished(SCR_AIBehaviorBase childBehavior)
Called by agent when he failed his behavior related to this activity.
ScriptInvokerBase< SCR_AIStaticArtilleryBehavior_OnArtilleryFired > GetOnArtilleryFired()
Returns event which is invoked every time AI who executes this behavior fires an artillery.
TurretCompartmentSlot GetTurretCompartmentSlot()
EAIVehicleType GetVehicleType()
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.