(48ce3248e) Improve wall targeting and fix releasing the target when latched on to a wall.

This commit is contained in:
Joonas Rikkonen
2019-04-29 21:06:11 +03:00
parent 205f808f84
commit 4023fab047
2 changed files with 41 additions and 8 deletions
@@ -493,7 +493,7 @@ namespace Barotrauma
} }
else else
{ {
if (!IsProperlyLatchedOnSub) if (!IsLatchedOnSub)
{ {
UpdateWallTarget(); UpdateWallTarget();
} }
@@ -552,7 +552,7 @@ namespace Barotrauma
{ {
WallSection section = wallTarget.Structure.GetSection(wallTarget.SectionIndex); WallSection section = wallTarget.Structure.GetSection(wallTarget.SectionIndex);
Vector2 targetPos = wallTarget.Structure.SectionPosition(wallTarget.SectionIndex, true); Vector2 targetPos = wallTarget.Structure.SectionPosition(wallTarget.SectionIndex, true);
if (section?.gap != null && section.gap.IsRoomToRoom && SteerThroughGap(wallTarget.Structure, section, targetPos, deltaTime)) if (section?.gap != null && SteerThroughGap(wallTarget.Structure, section, targetPos, deltaTime))
{ {
return; return;
} }
@@ -1045,6 +1045,7 @@ namespace Barotrauma
#endregion #endregion
#region Targeting #region Targeting
private bool IsLatchedOnSub => LatchOntoAI != null && LatchOntoAI.IsAttachedToSub;
private bool IsProperlyLatchedOnSub => LatchOntoAI != null && LatchOntoAI.IsAttachedToSub && SelectedAiTarget?.Entity == wallTarget?.Structure; private bool IsProperlyLatchedOnSub => LatchOntoAI != null && LatchOntoAI.IsAttachedToSub && SelectedAiTarget?.Entity == wallTarget?.Structure;
@@ -1053,12 +1054,33 @@ namespace Barotrauma
//sight/hearing range //sight/hearing range
public AITarget UpdateTargets(Character character, out TargetingPriority priority) public AITarget UpdateTargets(Character character, out TargetingPriority priority)
{ {
if (IsProperlyLatchedOnSub) if (IsLatchedOnSub)
{ {
// If attached to a valid target, just keep the target. var wall = SelectedAiTarget.Entity as Structure;
// Priority not used in this case. // The target is not a wall or it's not the same as we are attached to -> release
priority = null; bool releaseTarget = wall == null || !wall.Bodies.Contains(LatchOntoAI.AttachJoints[0].BodyB);
return SelectedAiTarget; if (!releaseTarget)
{
for (int i = 0; i < wall.Sections.Length; i++)
{
if (CanPassThroughHole(wall, i))
{
releaseTarget = true;
}
}
}
if (releaseTarget)
{
SelectedAiTarget = null;
LatchOntoAI.DeattachFromBody();
}
else if (SelectedAiTarget.Entity == wallTarget?.Structure)
{
// If attached to a valid target, just keep the target.
// Priority not used in this case.
priority = null;
return SelectedAiTarget;
}
} }
AITarget newTarget = null; AITarget newTarget = null;
priority = null; priority = null;
@@ -1141,7 +1163,7 @@ namespace Barotrauma
else if (target.Entity != null) else if (target.Entity != null)
{ {
//skip the target if it's a room and the character is already inside a sub //skip the target if it's a room and the character is already inside a sub
if (character.CurrentHull != null && target.Entity is Hull) continue; if (character.CurrentHull != null && target.Entity is Hull) { continue; }
Door door = null; Door door = null;
if (target.Entity is Item item) if (target.Entity is Item item)
@@ -1170,6 +1192,13 @@ namespace Barotrauma
// Ignore structures that doesn't have a body (not walls) // Ignore structures that doesn't have a body (not walls)
continue; continue;
} }
if (s.IsPlatform)
{
continue;
}
float wallMaxHealth = 400; // Anything more than this is ignored -> 200 = 1
// Prefer weaker targets.
valueModifier = MathHelper.Lerp(2, 0, MathHelper.Clamp(s.Health / wallMaxHealth, 0, 1));
// Ignore walls when inside. // Ignore walls when inside.
valueModifier = character.CurrentHull == null ? 1 : 0; valueModifier = character.CurrentHull == null ? 1 : 0;
if (aggressiveBoarding) if (aggressiveBoarding)
@@ -2559,6 +2559,10 @@ namespace Barotrauma
GameMain.GameSession?.CrewManager?.RemoveCharacter(this); GameMain.GameSession?.CrewManager?.RemoveCharacter(this);
#endif #endif
#if CLIENT
GameMain.GameSession?.CrewManager?.RemoveCharacter(this);
#endif
#if CLIENT #if CLIENT
GameMain.GameSession?.CrewManager?.RemoveCharacter(this); GameMain.GameSession?.CrewManager?.RemoveCharacter(this);
#endif #endif