1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
10 public static List<AITarget>
List =
new List<AITarget>();
17 if (entity !=
null && entity.
Removed) {
return null; }
22 private float soundRange;
23 private float sightRange;
30 public bool Static {
get;
private set; }
36 get {
return soundRange; }
39 if (
float.IsNaN(value))
41 DebugConsole.ThrowError(
"Attempted to set the SoundRange of an AITarget to NaN.\n" + Environment.StackTrace.CleanupStackTrace());
54 get {
return sightRange; }
57 if (
float.IsNaN(value))
59 DebugConsole.ThrowError(
"Attempted to set the SightRange of an AITarget to NaN.\n" + Environment.StackTrace.CleanupStackTrace());
62 sightRange = MathHelper.Clamp(value, MinSightRange, MaxSightRange);
70 private float sectorRad = MathHelper.TwoPi;
73 get {
return MathHelper.ToDegrees(sectorRad); }
74 set { sectorRad = MathHelper.ToRadians(value); }
77 private Vector2 sectorDir;
80 get {
return sectorDir; }
83 if (!MathUtils.IsValid(value))
85 string errorMsg =
"Invalid AITarget sector direction (" + value +
")\n" + Environment.StackTrace.CleanupStackTrace();
86 DebugConsole.ThrowError(errorMsg);
87 GameAnalyticsManager.AddErrorEventOnce(
"AITarget.SectorDir:" + entity?.ToString(), GameAnalyticsManager.ErrorSeverity.Error, errorMsg);
103 private bool inDetectable;
118 inDetectable = value;
153 if (entity ==
null || entity.
Removed)
156 DebugConsole.ThrowError(
"Attempted to access a removed AITarget\n" + Environment.StackTrace.CleanupStackTrace());
158 GameAnalyticsManager.AddErrorEventOnce(
"AITarget.WorldPosition:EntityRemoved",
159 GameAnalyticsManager.ErrorSeverity.Error,
160 "Attempted to access a removed AITarget\n" + Environment.StackTrace.CleanupStackTrace());
172 if (entity ==
null || entity.
Removed)
175 DebugConsole.ThrowError(
"Attempted to access a removed AITarget\n" + Environment.StackTrace.CleanupStackTrace());
177 GameAnalyticsManager.AddErrorEventOnce(
"AITarget.WorldPosition:EntityRemoved",
178 GameAnalyticsManager.ErrorSeverity.Error,
179 "Attempted to access a removed AITarget\n" + Environment.StackTrace.CleanupStackTrace());
193 if (
Entity ==
null) {
return true; }
203 SightRange = element.GetAttributeFloat(
"sightrange", 0.0f);
204 SoundRange = element.GetAttributeFloat(
"soundrange", 0.0f);
205 MinSightRange = element.GetAttributeFloat(
"minsightrange", 0f);
206 MinSoundRange = element.GetAttributeFloat(
"minsoundrange", 0f);
207 MaxSightRange = element.GetAttributeFloat(
"maxsightrange",
SightRange);
219 string label = element.GetAttributeString(
"sonarlabel",
"");
246 if (sightRange <= 0 && soundRange <= 0)
279 return sectorRad < MathHelper.TwoPi;
286 return Math.Abs(MathUtils.GetShortestAngle(MathUtils.VectorToAngle(diff), MathUtils.VectorToAngle(sectorDir))) <= sectorRad * 0.5f;
AITarget(Entity e, XElement element)
double InDetectableSetTime
void DecreaseSoundRange(float deltaTime, float speed=1)
bool NeedsUpdate
Does the AI target do something that requires Update() to be called (e.g. static targets don't need t...
float FadeOutTime
How long does it take for the ai target to fade out if not kept alive.
Identifier SonarIconIdentifier
void IncreaseSoundRange(float deltaTime, float speed=1)
void IncreaseSightRange(float deltaTime, float speed=1)
static List< AITarget > List
bool ShouldBeIgnored()
Is some condition met (e.g. entity null, indetectable, outside level) that prevents anyone from detec...
void DecreaseSightRange(float deltaTime, float speed=1)
LocalizedString SonarLabel
bool IsWithinSector(Vector2 worldPosition)
bool InDetectable
Should be reset to false each frame and kept indetectable by e.g. a status effect.
void Update(float deltaTime)
virtual Vector2 WorldPosition
virtual Vector2 SimPosition
static bool IsPositionAboveLevel(Vector2 worldPosition)
Is the position above the upper boundary of the level ("outside bounds", where nothing should be able...
LocalizedString Fallback(LocalizedString fallback, bool useDefaultLanguageIfFound=true)
Use this text instead if the original text cannot be found.