Tweaked AITarget ranges: now it's possible to evade some monsters by stopping the sub and/or turning off noisy devices, AITarget ranges can be made visible by entering "ShowAITargets" in the console, misc cleanup
This commit is contained in:
@@ -1,30 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class AITarget
|
||||
{
|
||||
public static bool ShowAITargets;
|
||||
|
||||
public static List<AITarget> List = new List<AITarget>();
|
||||
|
||||
public Entity Entity;
|
||||
|
||||
protected float soundRange;
|
||||
protected float sightRange;
|
||||
private float soundRange;
|
||||
private float sightRange;
|
||||
|
||||
public float SoundRange
|
||||
{
|
||||
get
|
||||
{
|
||||
return soundRange;
|
||||
}
|
||||
set { soundRange = value; }
|
||||
get { return soundRange; }
|
||||
set { soundRange = Math.Max(value, 0.0f); }
|
||||
}
|
||||
|
||||
public float SightRange
|
||||
{
|
||||
get { return sightRange; }
|
||||
set { sightRange = value; }
|
||||
set { sightRange = Math.Max(value, 0.0f); }
|
||||
}
|
||||
|
||||
public Vector2 WorldPosition
|
||||
@@ -48,5 +49,24 @@ namespace Barotrauma
|
||||
List.Remove(this);
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
{
|
||||
if (!ShowAITargets) return;
|
||||
|
||||
var rangeSprite = GUI.SubmarineIcon;
|
||||
|
||||
if (soundRange > 0.0f)
|
||||
rangeSprite.Draw(spriteBatch,
|
||||
new Vector2(WorldPosition.X, -WorldPosition.Y),
|
||||
Color.Cyan * 0.1f, rangeSprite.Origin,
|
||||
0.0f, soundRange / rangeSprite.size.X);
|
||||
|
||||
if (sightRange > 0.0f)
|
||||
rangeSprite.Draw(spriteBatch,
|
||||
new Vector2(WorldPosition.X, -WorldPosition.Y),
|
||||
Color.Orange * 0.1f, rangeSprite.Origin,
|
||||
0.0f, sightRange / rangeSprite.size.X);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,7 +736,7 @@ namespace Barotrauma
|
||||
//check visibility from the new position of RefLimb to the new position of this limb
|
||||
Vector2 movePos = limb.SimPosition + moveAmount;
|
||||
|
||||
TrySetLimbPosition(limb, simPosition, movePos);
|
||||
TrySetLimbPosition(limb, simPosition, movePos, lerp);
|
||||
|
||||
|
||||
}
|
||||
@@ -825,60 +825,44 @@ namespace Barotrauma
|
||||
limb.body.TargetPosition = Vector2.Zero;
|
||||
}
|
||||
|
||||
correctionMovement = targetMovement;
|
||||
correctionMovement = Vector2.Zero;
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
||||
|
||||
if (inWater)
|
||||
{
|
||||
|
||||
|
||||
if (inWater)
|
||||
if (targetMovement.LengthSquared() > 0.01f)
|
||||
{
|
||||
if (targetMovement.LengthSquared() > 0.01f)
|
||||
{
|
||||
correctionMovement =
|
||||
Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f), 0.2f);
|
||||
correctionMovement =
|
||||
Vector2.Lerp(targetMovement, Vector2.Normalize(diff) * MathHelper.Clamp(dist * 5.0f, 0.1f, 5.0f), 0.2f);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
refLimb.body.LinearVelocity = Vector2.Lerp(
|
||||
refLimb.LinearVelocity,
|
||||
Vector2.Normalize(diff) * MathHelper.Clamp(dist, 0.0f, 5.0f),
|
||||
0.2f);
|
||||
|
||||
//foreach (Limb limb in Limbs)
|
||||
//{
|
||||
// //if (limb.body.TargetPosition == Vector2.Zero) continue;
|
||||
// // Vector2.Lerp(limb.LinearVelocity, Vector2.Normalize(diff) * MathHelper.Clamp(dist, 0.0f, 1.0f))
|
||||
// limb.body.LinearVelocity = Vector2.Lerp(
|
||||
// limb.LinearVelocity,
|
||||
// Vector2.Normalize(diff) * MathHelper.Clamp(dist, 0.0f, 5.0f),
|
||||
// 0.2f);
|
||||
|
||||
// //limb.body.TargetVelocity .SetTransform(limb.SimPosition + Vector2.Normalize(diff) * 0.1f, limb.Rotation);
|
||||
//}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//clamp the magnitude of the correction movement between 0.5f - 5.0f
|
||||
Vector2 newCorrectionMovement = Vector2.Normalize(diff) * MathHelper.Clamp(dist * 2.0f, 0.5f, 5.0f);
|
||||
|
||||
//heading in the right direction -> use the ''normal'' movement if it's faster than correctionMovement
|
||||
//i.e. the character is close to the targetposition but the character is still running
|
||||
if (Math.Sign(targetMovement.X) == Math.Sign(newCorrectionMovement.X))
|
||||
{
|
||||
newCorrectionMovement.X = Math.Max(Math.Abs(targetMovement.X), Math.Abs(newCorrectionMovement.X)) * Math.Sign(targetMovement.X);
|
||||
}
|
||||
|
||||
//newCorrectionMovement.X = Math.Max(newCorrectionMovement.X, 0.5f) * Math.Sign(newCorrectionMovement.X);
|
||||
|
||||
correctionMovement = Vector2.Lerp(correctionMovement, newCorrectionMovement, 0.5f);
|
||||
|
||||
if (Math.Abs(correctionMovement.Y) < 0.1f) correctionMovement.Y = 0.0f;
|
||||
refLimb.body.LinearVelocity = Vector2.Lerp(
|
||||
refLimb.LinearVelocity,
|
||||
Vector2.Normalize(diff) * MathHelper.Clamp(dist, 0.0f, 5.0f),
|
||||
0.2f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//clamp the magnitude of the correction movement between 0.5f - 5.0f
|
||||
Vector2 newCorrectionMovement = Vector2.Normalize(diff) * MathHelper.Clamp(dist * 2.0f, 0.5f, 5.0f);
|
||||
|
||||
//heading in the right direction -> use the ''normal'' movement if it's faster than correctionMovement
|
||||
//i.e. the character is close to the targetposition but the character is still running
|
||||
if (Math.Sign(targetMovement.X) == Math.Sign(newCorrectionMovement.X))
|
||||
{
|
||||
newCorrectionMovement.X = Math.Max(Math.Abs(targetMovement.X), Math.Abs(newCorrectionMovement.X)) * Math.Sign(targetMovement.X);
|
||||
}
|
||||
|
||||
correctionMovement = Vector2.Lerp(correctionMovement, newCorrectionMovement, 0.5f);
|
||||
|
||||
if (Math.Abs(correctionMovement.Y) < 0.1f) correctionMovement.Y = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
if (resetAll)
|
||||
{
|
||||
@@ -886,7 +870,6 @@ namespace Barotrauma
|
||||
|
||||
if (this is HumanoidAnimController)
|
||||
{
|
||||
|
||||
foreach (Limb limb in Limbs)
|
||||
{
|
||||
if (limb != refLimb) limb.body.TargetPosition = limb.body.SimPosition + diff;
|
||||
@@ -898,19 +881,8 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
SetPosition(refLimb.body.TargetPosition);
|
||||
|
||||
}
|
||||
|
||||
//if (character is AICharacter) SetRotation(refLimb.body.TargetRotation);
|
||||
|
||||
|
||||
//foreach (Limb limb in Limbs)
|
||||
//{
|
||||
// limb.body.LinearVelocity = Vector2.Zero;
|
||||
// limb.body.AngularVelocity = 0.0f;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -362,6 +362,11 @@ namespace Barotrauma
|
||||
get { return AnimController.RefLimb.Position; }
|
||||
}
|
||||
|
||||
public override Vector2 DrawPosition
|
||||
{
|
||||
get { return AnimController.RefLimb.body.DrawPosition; }
|
||||
}
|
||||
|
||||
public delegate void OnDeathHandler(Character character, CauseOfDeath causeOfDeath);
|
||||
public OnDeathHandler OnDeath;
|
||||
|
||||
@@ -1058,18 +1063,7 @@ namespace Barotrauma
|
||||
|
||||
aiTarget.SightRange = 0.0f;
|
||||
|
||||
//distance is approximated based on the mass of the Character
|
||||
//(which corresponds to size because all the characters have the same limb density)
|
||||
foreach (Limb limb in AnimController.Limbs)
|
||||
{
|
||||
aiTarget.SightRange += limb.Mass * 1000.0f;
|
||||
}
|
||||
//the faster the Character is moving, the easier it is to see it
|
||||
Limb torso = AnimController.GetLimb(LimbType.Torso);
|
||||
if (torso !=null)
|
||||
{
|
||||
aiTarget.SightRange += torso.LinearVelocity.Length() * 500.0f;
|
||||
}
|
||||
aiTarget.SightRange = Mass*10.0f + AnimController.RefLimb.LinearVelocity.Length()*500.0f;
|
||||
}
|
||||
|
||||
public void Draw(SpriteBatch spriteBatch)
|
||||
@@ -1112,6 +1106,8 @@ namespace Barotrauma
|
||||
if (GameMain.DebugDraw)
|
||||
{
|
||||
AnimController.DebugDraw(spriteBatch);
|
||||
|
||||
if (aiTarget != null) aiTarget.Draw(spriteBatch);
|
||||
}
|
||||
|
||||
if (isDead) return;
|
||||
|
||||
Reference in New Issue
Block a user