19 private static const float THREAT_SHOT_DROP_RATE = 0.11 * 0.001;
20 private static const float THREAT_SUPPRESSION_DROP_RATE = 0.1 * 0.001;
21 private static const float THREAT_ENDANGERED_DROP_RATE = 0.2 * 0.001;
23 private static const float BLEEDING_FIXED_INCREMENT = 0.3;
24 private static const float SUPPRESSION_BULLET_INCREMENT = 0.10;
25 private static const float ZERO_DISTANCE_SHOT_INCREMENT = 0.008;
26 private static const float DISTANT_SHOT_INCREMENT = 0.002;
27 private static const float EXPLOSION_MAX_INCREMENT = 0.6;
29 private static const float EXPLOSION_CLOSE_DISTANCE = 12;
30 static const float EXPLOSION_MAX_DISTANCE = 700;
32 private static const float ENDANGERED_INCREMENT = 0.2;
34 static const float VIGILANT_THRESHOLD = 0.05;
35 protected static const float ALERTED_THRESHOLD = 0.33;
36 static const float THREATENED_THRESHOLD = 0.66;
40 static const float ATTACK_DELAYED_THRESHOLD = 0.001;
43 private float m_fThreatTotal;
44 private float m_fThreatSuppression;
45 private float m_fThreatShotsFired;
46 private float m_fThreatIsEndangered;
47 private float m_fThreatInjury;
49 private SCR_AIUtilityComponent m_Utility;
50 private SCR_AIConfigComponent m_Config;
51 private SCR_AICombatComponent m_Combat;
52 private SCR_DamageManagerComponent m_DamageManager;
56 private EAIThreatState m_State;
66 m_Config = utility.m_ConfigComponent;
67 m_Combat = utility.m_CombatComponent;
68 m_DamageManager = SCR_DamageManagerComponent.Cast(utility.m_OwnerEntity.FindComponent(SCR_DamageManagerComponent));
77 m_DamageManager.GetOnDamageOverTimeAdded().Insert(OnDamageOverTimeAdded);
78 m_DamageManager.GetOnDamageOverTimeRemoved().Insert(OnDamageOverTimeRemoved);
88 return m_OnThreatStateChanged;
93 EAIThreatState GetState()
100 float GetThreatMeasureWithoutInjuryFactor()
102 return m_fThreatTotal - m_fThreatInjury;
107 float GetThreatMeasure()
109 return m_fThreatTotal;
123 case EAIThreatState.SAFE:
125 color = Color.FromInt(Color.GREEN);
128 case EAIThreatState.VIGILANT:
130 color = Color.FromInt(Color.DARK_GREEN);
133 case EAIThreatState.ALERTED:
135 color = Color.FromInt(Color.DARK_YELLOW);
138 case EAIThreatState.THREATENED:
140 color = Color.FromInt(Color.DARK_RED);
150 private void StateTransition(EAIThreatState newState)
155 m_OnThreatStateChanged.Invoke(
m_State, newState);
161 private void UpdateState()
163 EAIThreatState newState = EAIThreatState.SAFE;
165 if (m_fThreatTotal > THREATENED_THRESHOLD)
166 newState = EAIThreatState.THREATENED;
167 else if (m_fThreatTotal > ALERTED_THRESHOLD)
168 newState = EAIThreatState.ALERTED;
169 else if (m_fThreatTotal > VIGILANT_THRESHOLD)
170 newState = EAIThreatState.VIGILANT;
172 StateTransition(newState);
180 void Update(SCR_AIUtilityComponent utility,
float timeSlice)
183 m_fThreatSuppression -= m_fThreatSuppression * THREAT_SUPPRESSION_DROP_RATE * timeSlice;
184 m_fThreatShotsFired -= m_fThreatShotsFired * THREAT_SHOT_DROP_RATE * timeSlice;
188 if (m_Combat.GetCurrentTarget())
189 m_fThreatIsEndangered = ENDANGERED_INCREMENT;
191 m_fThreatIsEndangered -= m_fThreatIsEndangered * THREAT_ENDANGERED_DROP_RATE * timeSlice;
195 if (
m_Agent && m_Config.m_EnableDangerEvents)
199 for (; i <
m_Agent.GetDangerEventsCount(); i++)
201 AIDangerEvent dangerEvent =
m_Agent.GetDangerEvent(i);
206 AddDebugMessage(
string.Format(
"PerformDangerReaction: %1, %2", dangerEvent,
typename.EnumToString(EAIDangerEventType, dangerEvent.GetDangerType())));
209 if (m_Config.PerformDangerReaction(m_Utility, dangerEvent))
212 string message =
typename.EnumToString(EAIDangerEventType, dangerEvent.GetDangerType());
219 m_Agent.ClearDangerEvents(i+1);
223 float threatFromBehavior = 0;
224 if (utility.m_CurrentBehavior)
225 threatFromBehavior = utility.m_CurrentBehavior.m_fThreat;
227 m_fThreatTotal = Math.Clamp(threatFromBehavior + m_fThreatSuppression + m_fThreatInjury + m_fThreatShotsFired + m_fThreatIsEndangered, 0, 1);
242 m_fThreatInjury = BLEEDING_FIXED_INCREMENT;
258 void ThreatBulletImpact(
int count)
261 AddDebugMessage(
string.Format(
"ThreatBulletImpact: %1", count));
264 m_fThreatSuppression = Math.Clamp(m_fThreatSuppression + count*SUPPRESSION_BULLET_INCREMENT, 0, 1);
270 void ThreatExplosion(
float distance)
273 AddDebugMessage(
string.Format(
"ThreatExplosion: %1",
distance));
277 float increment = EXPLOSION_MAX_INCREMENT;
280 if (
distance > EXPLOSION_CLOSE_DISTANCE)
281 increment = Math.Map(
distance, EXPLOSION_CLOSE_DISTANCE, EXPLOSION_MAX_DISTANCE, EXPLOSION_MAX_INCREMENT, 0);
287 m_fThreatSuppression += increment;
294 void ThreatShotFired(
float distance,
int count)
297 AddDebugMessage(
string.Format(
"ThreatShotFired: %1, %2",
distance, count));
301 m_fThreatShotsFired = Math.Clamp(m_fThreatShotsFired + count*(DISTANT_SHOT_INCREMENT + ZERO_DISTANCE_SHOT_INCREMENT/(
distance + 1)), 0, THREATENED_THRESHOLD);
307 void ThreatProjectileFlyby(
int count)
310 AddDebugMessage(
string.Format(
"ThreatProjectileFlyby"));
313 m_fThreatSuppression = Math.Clamp(m_fThreatSuppression + count * SUPPRESSION_BULLET_INCREMENT, 0, 1);
319 void DebugPrintToWidget(TextWidget w)
322 typename.EnumToString(EAIThreatState,
m_State) +
"\n "
323 + m_fThreatTotal.ToString(1,4) +
"\n "
324 + m_fThreatSuppression.ToString(1,4) +
"\n "
325 + m_fThreatShotsFired.ToString(1,4) +
"\n "
326 + m_fThreatInjury.ToString(1,4) +
"\n "
327 + m_fThreatIsEndangered.ToString(1,4));
333 protected void AddDebugMessage(
string str)
335 m_Utility.m_AIInfo.AddDebugMessage(str, msgType:
EAIDebugMsgType.THREAT);