diff --git a/Barotrauma/BarotraumaClient/ClientSource/Characters/AI/AITarget.cs b/Barotrauma/BarotraumaClient/ClientSource/Characters/AI/AITarget.cs index dd4b2855ea..fd56614f64 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Characters/AI/AITarget.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Characters/AI/AITarget.cs @@ -57,6 +57,10 @@ public void Draw(SpriteBatch spriteBatch) } color = Color.CadetBlue; } + else if (Entity is Submarine) + { + color = Color.WhiteSmoke; + } else { //color = Color.WhiteSmoke; diff --git a/Barotrauma/BarotraumaClient/ClientSource/Screens/GameScreen.cs b/Barotrauma/BarotraumaClient/ClientSource/Screens/GameScreen.cs index 7eeb3526e1..e606be414a 100644 --- a/Barotrauma/BarotraumaClient/ClientSource/Screens/GameScreen.cs +++ b/Barotrauma/BarotraumaClient/ClientSource/Screens/GameScreen.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Linq; using System.Transactions; +using Barotrauma.Items.Components; namespace Barotrauma { @@ -511,6 +512,7 @@ void DrawCharacters(bool deformed, bool firstPass) { MapEntity.MapEntityList.ForEach(me => me.AiTarget?.Draw(spriteBatch)); Character.CharacterList.ForEach(c => c.AiTarget?.Draw(spriteBatch)); + Sonar.SonarList.ForEach(s => s.SubAiTarget?.Draw(spriteBatch)); if (GameMain.GameSession?.EventManager != null) { GameMain.GameSession.EventManager.DebugDraw(spriteBatch); diff --git a/Barotrauma/BarotraumaShared/SharedSource/Characters/AI/EnemyAIController.cs b/Barotrauma/BarotraumaShared/SharedSource/Characters/AI/EnemyAIController.cs index 5e7fd8e8c4..365b1de90d 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Characters/AI/EnemyAIController.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Characters/AI/EnemyAIController.cs @@ -486,6 +486,10 @@ private IEnumerable GetTargetingTags(AITarget aiTarget) } } } + else if (aiTarget.Entity is Submarine) + { + _targetingTags.Add(Tags.Sonar); + } else if (aiTarget.Entity is Structure) { _targetingTags.Add(Tags.Wall); @@ -1261,6 +1265,10 @@ private void UpdateAttack(float deltaTime) attackSimPos = Character.Submarine == wallTarget.Structure.Submarine ? wallTarget.Position : attackWorldPos; attackSimPos = ConvertUnits.ToSimUnits(attackSimPos); } + else if (SelectedAiTarget.Entity is Submarine) + { + attackSimPos = ConvertUnits.ToSimUnits(attackWorldPos); + } else { attackSimPos = Character.GetRelativeSimPosition(SelectedAiTarget.Entity); @@ -3412,7 +3420,7 @@ public void UpdateTargets() } } - if (Character.Submarine == null && aiTarget.Entity?.Submarine != null && targetCharacter == null) + if (Character.Submarine == null && aiTarget.Entity is Submarine || aiTarget.Entity?.Submarine != null && targetCharacter == null) { if (matchingTargetParams.PrioritizeSubCenter || matchingTargetParams.AttackPattern is AttackPattern.Circle or AttackPattern.Sweep) { diff --git a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Sonar.cs b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Sonar.cs index bfd4aaafe1..c1ee257703 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Sonar.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Items/Components/Machines/Sonar.cs @@ -61,6 +61,8 @@ private class ActivePing private int activePingsCount; // currently active ping index on the above list private int currentPingIndex = -1; + // if using submarine as the center for the ping, this is the submarine's AITarget + public AITarget SubAiTarget { get; private set; } private const float MinZoom = 1.0f, MaxZoom = 4.0f; private float zoom = 1.0f; @@ -87,9 +89,10 @@ public float Range set { range = MathHelper.Clamp(value, 0.0f, 100000.0f); - if (item?.AiTarget != null && item.AiTarget.MaxSoundRange <= 0) + AITarget aiTarget = item.Submarine?.AiTarget != null && item.body == null ? item.Submarine.AiTarget : item.AiTarget; + if (aiTarget != null && aiTarget.MaxSoundRange <= 0) { - item.AiTarget.MaxSoundRange = range; + aiTarget.MaxSoundRange = range; } } } @@ -187,6 +190,11 @@ public override void Update(float deltaTime, Camera cam) connectedTransducers.RemoveAll(t => t.DisconnectTimer <= 0.0f); } + if (SubAiTarget != null && SubAiTarget.NeedsUpdate) + { + SubAiTarget.Update(deltaTime); + } + for (var pingIndex = 0; pingIndex < activePingsCount; ++pingIndex) { activePings[pingIndex].State += deltaTime * PingFrequency; @@ -259,7 +267,12 @@ private IEnumerable GetAITargets() { if (!UseTransducers) { - if (item.AiTarget != null) { yield return item.AiTarget; } + if (item.Submarine != null && item.body == null) + { + SubAiTarget ??= new AITarget(item.Submarine); + yield return SubAiTarget; + } + else if (item.AiTarget != null) { yield return item.AiTarget; } } else {