Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AITargetReaction.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
2// TARGET REACTION BASE
3//------------------------------------------------------------------------------------------------
6{
7 void PerformReaction(notnull SCR_AIUtilityComponent utility, notnull SCR_AIThreatSystem threatSystem, BaseTarget baseTarget, vector lastSeenPosition) {}
8};
9
13{
14 void PerformReaction(notnull SCR_AIUtilityComponent utility, BaseTarget prevTarget, BaseTarget newTarget);
15}
16
17//------------------------------------------------------------------------------------------------
18// TARGET REACTIONS
19//------------------------------------------------------------------------------------------------
20
21
23class SCR_AITargetReaction_Unknown : SCR_AITargetReactionBase
24{
25 override void PerformReaction(notnull SCR_AIUtilityComponent utility, notnull SCR_AIThreatSystem threatSystem, BaseTarget baseTarget, vector lastSeenPosition)
26 {
27 IEntity targetEntity = baseTarget.GetTargetEntity();
28 if (targetEntity)
29 utility.m_LookAction.LookAt(targetEntity, SCR_AILookAction.PRIO_UNKNOWN_TARGET, 2.0);
30 }
31};
32
35{
36 override void PerformReaction(notnull SCR_AIUtilityComponent utility, notnull SCR_AIThreatSystem threatSystem, BaseTarget baseTarget, vector lastSeenPosition)
37 {
38 if (!baseTarget)
39 return;
40
41 // Find if we already have a retreat action from that target
42 utility.SetStateAllActionsOfType(SCR_AIRetreatFromTargetBehavior, EAIActionState.COMPLETED, true);
43
44 // Don't retreat if we are a car driver
45 if (utility.m_AIInfo.HasUnitState(EUnitState.PILOT))
46 return;
47
48 // Dismount if in static weapon
49 if (utility.m_AIInfo.HasUnitState(EUnitState.IN_TURRET))
50 {
51 CompartmentAccessComponent compAcc = CompartmentAccessComponent.Cast(utility.m_OwnerEntity.FindComponent(CompartmentAccessComponent));
52 if (!compAcc)
53 return;
54
55 IEntity vehicle = compAcc.GetVehicleIn(utility.m_OwnerEntity);
56 if (!vehicle)
57 return;
58
60 if (!vehicleUsageComp)
61 return;
62
63 if (vehicleUsageComp.GetVehicleType() == EAIVehicleType.STATIC_WEAPON)
64 utility.AddAction(new SCR_AIGetOutVehicle(utility, null, vehicle, priority: SCR_AIActionBase.PRIORITY_BEHAVIOR_GET_OUT_VEHICLE_HIGH_PRIORITY));
65 }
66
67 SCR_AIRetreatFromTargetBehavior behavior = new SCR_AIRetreatFromTargetBehavior(utility, null, baseTarget);
68 utility.AddAction(behavior);
69
70 // Cancel all investigations, if we have discovered something which we can't attack, it makes no sense to push further
71 utility.SetStateAllActionsOfType(SCR_AIMoveAndInvestigateBehavior, EAIActionState.FAILED);
72 }
73}
74
77class SCR_AITargetReaction_SelectedTargetChanged : SCR_AITargetReaction_SelectedTargetChangedBase
78{
79 //--------------------------------------------------------------------------------------------------
80 override void PerformReaction(notnull SCR_AIUtilityComponent utility, BaseTarget prevTarget, BaseTarget newTarget)
81 {
82 #ifdef AI_DEBUG
83 AddDebugMessage(utility, string.Format("Prev Target: %1, New Target: %2", prevTarget, newTarget));
84 #endif
85
86 if (prevTarget)
87 {
88 ReportPreviousTarget(utility, prevTarget, newTarget);
89 }
90
91 utility.SetStateAllActionsOfType(SCR_AIAttackBehavior, EAIActionState.COMPLETED, true);
92
93 if (newTarget)
94 {
95 utility.SetStateAllActionsOfType(SCR_AIRetreatFromTargetBehavior, EAIActionState.COMPLETED, true);
96 CreateAttackActionForTarget(utility, newTarget, prevTarget);
97
98 IEntity targetEntity = newTarget.GetTargetEntity();
99 if (targetEntity)
100 utility.m_LookAction.LookAt(targetEntity, SCR_AILookAction.PRIO_ENEMY_TARGET);
101 }
102 }
103
104 //--------------------------------------------------------------------------------------------------
105 protected void CreateAttackActionForTarget(notnull SCR_AIUtilityComponent utility, notnull BaseTarget target, BaseTarget prevTarget)
106 {
107 #ifdef AI_DEBUG
108 AddDebugMessage(utility, "CreateAttackActionForTarget()");
109 #endif
110
111 IEntity targetEntity = target.GetTargetEntity();
112 if (!targetEntity)
113 return;
114
115 // Create new attack behavior
116 auto behavior = new SCR_AIAttackBehavior(utility, null, target, prevTarget);
117
118 // AddAction must be used here, not AddActionIfMissing!
119 utility.AddAction(behavior);
120
121 // this is now disabled since group commands when we dismount
122 // If passenger and not in turret, dismount vehicle
123 //if (!utility.m_AIInfo.HasUnitState(EUnitState.IN_TURRET))
124 // utility.WrapBehaviorOutsideOfVehicle(behavior);
125 }
126
127 //--------------------------------------------------------------------------------------------------
129 protected void ReportPreviousTarget(notnull SCR_AIUtilityComponent utility, notnull BaseTarget prevTarget, BaseTarget newTarget)
130 {
131 #ifdef AI_DEBUG
132 AddDebugMessage(utility, "ReportPreviousTarget()");
133 #endif
134
135 IEntity targetEntity = prevTarget.GetTargetEntity();
136 ETargetCategory targetCategory = prevTarget.GetTargetCategory();
137 DamageManagerComponent damageMgr = prevTarget.GetDamageManagerComponent();
138
139 if (targetCategory == ETargetCategory.FRIENDLY)
140 {
141 #ifdef AI_DEBUG
142 AddDebugMessage(utility, " Target is now friendly");
143 #endif
144 }
145 else if (!targetEntity)
146 {
147 #ifdef AI_DEBUG
148 AddDebugMessage(utility, " Target entity is null, not reporting");
149 #endif
150 }
151 else if (prevTarget.IsDisarmed() || (damageMgr && damageMgr.IsDestroyed()))
152 {
153 // Target is destroyed or unconscious/disarmed (we pretend it's destroyed)
154 #ifdef AI_DEBUG
155 AddDebugMessage(utility, " Target is destroyed or disarmed");
156 #endif
157
158 // Report target destroyed
159 if (!utility.m_CommsHandler.CanBypass())
160 {
161 SCR_AITalkRequest rq = new SCR_AITalkRequest(ECommunicationType.REPORT_TARGET_DOWN, null, vector.Zero, 0, transmitIfNoReceivers: false, transmitIfPassenger: false, preset: SCR_EAITalkRequestPreset.IRRELEVANT_IMMEDIATE);
162 utility.m_CommsHandler.AddRequest(rq);
163 }
164 }
165 else if (!newTarget &&
166 (prevTarget.GetTimeSinceSeen() > SCR_AICombatComponent.TARGET_MAX_LAST_SEEN) &&
167 (prevTarget.GetUnitType() & utility.m_CombatComponent.GetUnitTypesCanAttack() != 0)) // We switched from this target not because we can't attack it any more
168 {
169 // We haven't seen the target for too long
170 #ifdef AI_DEBUG
171 AddDebugMessage(utility, string.Format(" Target is lost, time since seen: %1", prevTarget.GetTimeSinceSeen()));
172 #endif
173
174 // Report target lost
175 if (!utility.m_CommsHandler.CanBypass())
176 {
177 SCR_AITalkRequest rq = new SCR_AITalkRequest(ECommunicationType.REPORT_TARGET_LOST, null, vector.Zero, 0, transmitIfNoReceivers: false, transmitIfPassenger: false, preset: SCR_EAITalkRequestPreset.IRRELEVANT_IMMEDIATE);
178 utility.m_CommsHandler.AddRequest(rq);
179 }
180 }
181 }
182
183 #ifdef AI_DEBUG
184 protected void AddDebugMessage(notnull SCR_AIUtilityComponent utility, string str, LogLevel logLevel = LogLevel.NORMAL)
185 {
186 SCR_AIInfoBaseComponent infoComp = utility.m_AIInfo;
187 infoComp.AddDebugMessage("SCR_AITargetReaction_SelectedTargetChanged: " + str, msgType: EAIDebugMsgType.COMBAT, logLevel);
188 }
189 #endif
190}
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
EAIDebugMsgType
ECommunicationType
void SCR_AITalkRequest(ECommunicationType type, IEntity entity, vector pos, int enumSignal, bool transmitIfNoReceivers, bool transmitIfPassenger, SCR_EAITalkRequestPreset preset)
EAIVehicleType
Vehicle type from point view of AI usage.
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
This reaction is called every time selected target changes from anything to anything,...
EAIActionState
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
ETargetCategory