Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
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 
23 class 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  SCR_AIRetreatFromTargetBehavior behavior = new SCR_AIRetreatFromTargetBehavior(utility, null, baseTarget);
45  utility.AddAction(behavior);
46  }
47 }
48 
51 class SCR_AITargetReaction_SelectedTargetChanged : SCR_AITargetReaction_SelectedTargetChangedBase
52 {
53  //--------------------------------------------------------------------------------------------------
54  override void PerformReaction(notnull SCR_AIUtilityComponent utility, BaseTarget prevTarget, BaseTarget newTarget)
55  {
56  #ifdef AI_DEBUG
57  AddDebugMessage(utility, string.Format("Prev Target: %1, New Target: %2", prevTarget, newTarget));
58  #endif
59 
60  if (prevTarget)
61  {
62  ReportPreviousTarget(utility, prevTarget, newTarget);
63  }
64 
65  utility.SetStateAllActionsOfType(SCR_AIAttackBehavior, EAIActionState.COMPLETED, true);
66 
67  if (newTarget)
68  {
69  utility.SetStateAllActionsOfType(SCR_AIRetreatFromTargetBehavior, EAIActionState.COMPLETED, true);
70  CreateAttackActionForTarget(utility, newTarget, prevTarget);
71 
72  IEntity targetEntity = newTarget.GetTargetEntity();
73  if (targetEntity)
74  utility.m_LookAction.LookAt(targetEntity, SCR_AILookAction.PRIO_ENEMY_TARGET);
75  }
76  }
77 
78  //--------------------------------------------------------------------------------------------------
79  protected void CreateAttackActionForTarget(notnull SCR_AIUtilityComponent utility, notnull BaseTarget target, BaseTarget prevTarget)
80  {
81  #ifdef AI_DEBUG
82  AddDebugMessage(utility, "CreateAttackActionForTarget()");
83  #endif
84 
85  IEntity targetEntity = target.GetTargetEntity();
86  if (!targetEntity)
87  return;
88 
89  // Create new attack behavior
90  auto behavior = new SCR_AIAttackBehavior(utility, null, target, prevTarget);
91 
92  // AddAction must be used here, not AddActionIfMissing!
93  utility.AddAction(behavior);
94 
95  // If passenger and not in turret, dismount vehicle
96  if (!utility.m_AIInfo.HasUnitState(EUnitState.IN_TURRET))
97  utility.WrapBehaviorOutsideOfVehicle(behavior);
98  }
99 
100  //--------------------------------------------------------------------------------------------------
102  protected void ReportPreviousTarget(notnull SCR_AIUtilityComponent utility, notnull BaseTarget prevTarget, BaseTarget newTarget)
103  {
104  #ifdef AI_DEBUG
105  AddDebugMessage(utility, "ReportPreviousTarget()");
106  #endif
107 
108  IEntity targetEntity = prevTarget.GetTargetEntity();
109  ETargetCategory targetCategory = prevTarget.GetTargetCategory();
110  DamageManagerComponent damageMgr = prevTarget.GetDamageManagerComponent();
111 
112  if (targetCategory == ETargetCategory.FRIENDLY)
113  {
114  #ifdef AI_DEBUG
115  AddDebugMessage(utility, " Target is now friendly");
116  #endif
117  }
118  else if (!targetEntity)
119  {
120  #ifdef AI_DEBUG
121  AddDebugMessage(utility, " Target entity is null, not reporting");
122  #endif
123  }
124  else if (prevTarget.IsDisarmed() || (damageMgr && damageMgr.IsDestroyed()))
125  {
126  // Target is destroyed or unconscious/disarmed (we pretend it's destroyed)
127  #ifdef AI_DEBUG
128  AddDebugMessage(utility, " Target is destroyed or disarmed");
129  #endif
130 
131  // Report target destroyed
132  if (!utility.m_CommsHandler.CanBypass())
133  {
134  SCR_AITalkRequest rq = new SCR_AITalkRequest(ECommunicationType.REPORT_TARGET_DOWN, null, vector.Zero, 0, transmitIfNoReceivers: false, transmitIfPassenger: false, preset: SCR_EAITalkRequestPreset.IRRELEVANT_IMMEDIATE);
135  utility.m_CommsHandler.AddRequest(rq);
136  }
137  }
138  else if (!newTarget &&
139  (prevTarget.GetTimeSinceSeen() > SCR_AICombatComponent.TARGET_MAX_LAST_SEEN) &&
140  (prevTarget.GetUnitType() & utility.m_CombatComponent.GetUnitTypesCanAttack() != 0)) // We switched from this target not because we can't attack it any more
141  {
142  // We haven't seen the target for too long
143  #ifdef AI_DEBUG
144  AddDebugMessage(utility, string.Format(" Target is lost, time since seen: %1", prevTarget.GetTimeSinceSeen()));
145  #endif
146 
147  // Report target lost
148  if (!utility.m_CommsHandler.CanBypass())
149  {
150  SCR_AITalkRequest rq = new SCR_AITalkRequest(ECommunicationType.REPORT_TARGET_LOST, null, vector.Zero, 0, transmitIfNoReceivers: false, transmitIfPassenger: false, preset: SCR_EAITalkRequestPreset.IRRELEVANT_IMMEDIATE);
151  utility.m_CommsHandler.AddRequest(rq);
152  }
153  }
154  }
155 
156  #ifdef AI_DEBUG
157  protected void AddDebugMessage(notnull SCR_AIUtilityComponent utility, string str, LogLevel logLevel = LogLevel.NORMAL)
158  {
159  SCR_AIInfoBaseComponent infoComp = utility.m_AIInfo;
160  infoComp.AddDebugMessage("SCR_AITargetReaction_SelectedTargetChanged: " + str, msgType: EAIDebugMsgType.COMBAT, logLevel);
161  }
162  #endif
163 }
SCR_AILookAction
Definition: SCR_AILookAction.c:1
EAIDebugMsgType
EAIDebugMsgType
Definition: SCR_AIDebugMessage.c:1
ETargetCategory
ETargetCategory
Definition: ETargetCategory.c:12
BaseTarget
Definition: BaseTarget.c:12
SCR_AITalkRequest
void SCR_AITalkRequest(ECommunicationType type, IEntity entity, vector pos, int enumSignal, bool transmitIfNoReceivers, bool transmitIfPassenger, SCR_EAITalkRequestPreset preset)
Definition: SCR_AITalkRequest.c:37
SCR_AIAttackBehavior
Definition: SCR_AIAttackBehavior.c:1
ECommunicationType
ECommunicationType
Definition: SCR_AISoundHandling.c:1
SCR_AITargetReaction_RetreatFromEnemy
Definition: SCR_AITargetReaction.c:34
SCR_AITargetReactionBase
Definition: SCR_AITargetReaction.c:5
PerformReaction
override void PerformReaction(notnull SCR_AIUtilityComponent utility, SCR_AIMessageBase message)
Definition: SCR_AIGoalReaction.c:2
SCR_AIRetreatFromTargetBehavior
Definition: SCR_AIRetreatBehavior.c:47
DamageManagerComponent
Definition: DamageManagerComponent.c:12
EAIActionState
EAIActionState
Definition: EAIActionState.c:12
SCR_AIThreatSystem
Definition: SCR_AIThreatSystem.c:17
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
SCR_AITargetReaction_SelectedTargetChangedBase
This reaction is called every time selected target changes from anything to anything,...
Definition: SCR_AITargetReaction.c:12