Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public void Draw(SpriteBatch spriteBatch)
}
color = Color.CadetBlue;
}
else if (Entity is Submarine)
{
color = Color.WhiteSmoke;
}
else
{
//color = Color.WhiteSmoke;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics;
using System.Linq;
using System.Transactions;
using Barotrauma.Items.Components;

namespace Barotrauma
{
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ private IEnumerable<Identifier> GetTargetingTags(AITarget aiTarget)
}
}
}
else if (aiTarget.Entity is Submarine)
{
_targetingTags.Add(Tags.Sonar);
}
else if (aiTarget.Entity is Structure)
{
_targetingTags.Add(Tags.Wall);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -259,7 +267,12 @@ private IEnumerable<AITarget> 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
{
Expand Down