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:
Regalis
2016-03-12 21:35:08 +02:00
parent c99f94b1de
commit d713874bd6
11 changed files with 113 additions and 104 deletions
+3 -3
View File
@@ -12,7 +12,7 @@
<sound file="door.ogg" type="OnUse" range="500.0"/> <sound file="door.ogg" type="OnUse" range="500.0"/>
</Door> </Door>
<AiTarget sightrange="5000.0"/> <AiTarget sightrange="500.0"/>
<fixrequirement name="Mechanical repairs"> <fixrequirement name="Mechanical repairs">
<skill name="Construction" level="40"/> <skill name="Construction" level="40"/>
@@ -40,7 +40,7 @@
<sound file="door.ogg" type="OnUse" range="500.0"/> <sound file="door.ogg" type="OnUse" range="500.0"/>
</Door> </Door>
<AiTarget sightrange="5000.0"/> <AiTarget sightrange="500.0"/>
<fixrequirement name="Mechanical repairs"> <fixrequirement name="Mechanical repairs">
<skill name="Construction" level="40"/> <skill name="Construction" level="40"/>
@@ -68,7 +68,7 @@
<sound file="door.ogg" type="OnUse" range="500.0"/> <sound file="door.ogg" type="OnUse" range="500.0"/>
</Door> </Door>
<AiTarget sightrange="5000.0"/> <AiTarget sightrange="500.0"/>
<fixrequirement name="Mechanical repairs"> <fixrequirement name="Mechanical repairs">
<skill name="Construction" level="40"/> <skill name="Construction" level="40"/>
+29 -9
View File
@@ -1,30 +1,31 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Barotrauma namespace Barotrauma
{ {
class AITarget class AITarget
{ {
public static bool ShowAITargets;
public static List<AITarget> List = new List<AITarget>(); public static List<AITarget> List = new List<AITarget>();
public Entity Entity; public Entity Entity;
protected float soundRange; private float soundRange;
protected float sightRange; private float sightRange;
public float SoundRange public float SoundRange
{ {
get get { return soundRange; }
{ set { soundRange = Math.Max(value, 0.0f); }
return soundRange;
}
set { soundRange = value; }
} }
public float SightRange public float SightRange
{ {
get { return sightRange; } get { return sightRange; }
set { sightRange = value; } set { sightRange = Math.Max(value, 0.0f); }
} }
public Vector2 WorldPosition public Vector2 WorldPosition
@@ -48,5 +49,24 @@ namespace Barotrauma
List.Remove(this); 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 //check visibility from the new position of RefLimb to the new position of this limb
Vector2 movePos = limb.SimPosition + moveAmount; 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; limb.body.TargetPosition = Vector2.Zero;
} }
correctionMovement = targetMovement; correctionMovement = Vector2.Zero;
return; return;
} }
else
if (inWater)
{ {
if (targetMovement.LengthSquared() > 0.01f)
if (inWater)
{ {
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 else
{ {
//clamp the magnitude of the correction movement between 0.5f - 5.0f refLimb.body.LinearVelocity = Vector2.Lerp(
Vector2 newCorrectionMovement = Vector2.Normalize(diff) * MathHelper.Clamp(dist * 2.0f, 0.5f, 5.0f); refLimb.LinearVelocity,
Vector2.Normalize(diff) * MathHelper.Clamp(dist, 0.0f, 5.0f),
//heading in the right direction -> use the ''normal'' movement if it's faster than correctionMovement 0.2f);
//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;
} }
} }
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) if (resetAll)
{ {
@@ -886,7 +870,6 @@ namespace Barotrauma
if (this is HumanoidAnimController) if (this is HumanoidAnimController)
{ {
foreach (Limb limb in Limbs) foreach (Limb limb in Limbs)
{ {
if (limb != refLimb) limb.body.TargetPosition = limb.body.SimPosition + diff; if (limb != refLimb) limb.body.TargetPosition = limb.body.SimPosition + diff;
@@ -898,19 +881,8 @@ namespace Barotrauma
} }
else else
{ {
SetPosition(refLimb.body.TargetPosition); 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;
//}
} }
} }
+8 -12
View File
@@ -362,6 +362,11 @@ namespace Barotrauma
get { return AnimController.RefLimb.Position; } get { return AnimController.RefLimb.Position; }
} }
public override Vector2 DrawPosition
{
get { return AnimController.RefLimb.body.DrawPosition; }
}
public delegate void OnDeathHandler(Character character, CauseOfDeath causeOfDeath); public delegate void OnDeathHandler(Character character, CauseOfDeath causeOfDeath);
public OnDeathHandler OnDeath; public OnDeathHandler OnDeath;
@@ -1058,18 +1063,7 @@ namespace Barotrauma
aiTarget.SightRange = 0.0f; aiTarget.SightRange = 0.0f;
//distance is approximated based on the mass of the Character aiTarget.SightRange = Mass*10.0f + AnimController.RefLimb.LinearVelocity.Length()*500.0f;
//(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;
}
} }
public void Draw(SpriteBatch spriteBatch) public void Draw(SpriteBatch spriteBatch)
@@ -1112,6 +1106,8 @@ namespace Barotrauma
if (GameMain.DebugDraw) if (GameMain.DebugDraw)
{ {
AnimController.DebugDraw(spriteBatch); AnimController.DebugDraw(spriteBatch);
if (aiTarget != null) aiTarget.Draw(spriteBatch);
} }
if (isDead) return; if (isDead) return;
+5
View File
@@ -421,6 +421,11 @@ namespace Barotrauma
//Ragdoll.DebugDraw = !Ragdoll.DebugDraw; //Ragdoll.DebugDraw = !Ragdoll.DebugDraw;
GameMain.DebugDraw = !GameMain.DebugDraw; GameMain.DebugDraw = !GameMain.DebugDraw;
break; break;
case "drawaitargets":
case "showaitargets":
AITarget.ShowAITargets = !AITarget.ShowAITargets;
break;
case "sendrandomdata": case "sendrandomdata":
int messageCount = 1; int messageCount = 1;
@@ -88,6 +88,11 @@ namespace Barotrauma.Items.Components
Submarine.Loaded.ApplyForce(currForce); Submarine.Loaded.ApplyForce(currForce);
if (item.CurrentHull != null)
{
item.CurrentHull.AiTarget.SoundRange = Math.Max(currForce.Length(), item.CurrentHull.AiTarget.SoundRange);
}
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
GameMain.ParticleManager.CreateParticle("bubbles", item.WorldPosition - (Vector2.UnitX * item.Rect.Width/2), GameMain.ParticleManager.CreateParticle("bubbles", item.WorldPosition - (Vector2.UnitX * item.Rect.Width/2),
@@ -12,8 +12,6 @@ namespace Barotrauma.Items.Components
{ {
class Radar : Powered class Radar : Powered
{ {
const float displayScale = 0.015f;
private float range; private float range;
private float pingState; private float pingState;
@@ -22,11 +20,14 @@ namespace Barotrauma.Items.Components
private GUITickBox isActiveTickBox; private GUITickBox isActiveTickBox;
[HasDefaultValue(0.0f, false)] private List<RadarBlip> radarBlips;
private float prevPingRadius;
[HasDefaultValue(10000.0f, false)]
public float Range public float Range
{ {
get { return ConvertUnits.ToDisplayUnits(range); } get { return range; }
set { range = ConvertUnits.ToSimUnits(value); } set { range = MathHelper.Clamp(value, 0.0f, 100000.0f); }
} }
public Radar(Item item, XElement element) public Radar(Item item, XElement element)
@@ -72,12 +73,14 @@ namespace Barotrauma.Items.Components
if (voltage >= minVoltage) if (voltage >= minVoltage)
{ {
pingState = (pingState + deltaTime * 0.5f); pingState = pingState + deltaTime * 0.5f;
if (pingState>1.0f) if (pingState>1.0f)
{ {
item.Use(deltaTime, null); item.Use(deltaTime);
pingState = 0.0f; pingState = 0.0f;
} }
if (item.CurrentHull != null) item.CurrentHull.AiTarget.SoundRange = Math.Max(Range * pingState, item.CurrentHull.AiTarget.SoundRange);
} }
else else
{ {
@@ -89,7 +92,7 @@ namespace Barotrauma.Items.Components
public override bool Use(float deltaTime, Character character = null) public override bool Use(float deltaTime, Character character = null)
{ {
return (pingState > 1.0f); return pingState > 1.0f;
} }
public override void DrawHUD(SpriteBatch spriteBatch, Character character) public override void DrawHUD(SpriteBatch spriteBatch, Character character)
@@ -104,9 +107,6 @@ namespace Barotrauma.Items.Components
DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2)); DrawRadar(spriteBatch, new Rectangle((int)GuiFrame.Center.X - radius, (int)GuiFrame.Center.Y - radius, radius * 2, radius * 2));
} }
private List<RadarBlip> radarBlips;
private float prevPingRadius;
private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect) private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect)
{ {
Vector2 center = new Vector2(rect.Center.X, rect.Center.Y); Vector2 center = new Vector2(rect.Center.X, rect.Center.Y);
@@ -116,9 +116,11 @@ namespace Barotrauma.Items.Components
float pingRadius = (rect.Width / 2) * pingState; float pingRadius = (rect.Width / 2) * pingState;
pingCircle.Draw(spriteBatch, center, Color.White * (1.0f-pingState), 0.0f, (rect.Width/pingCircle.size.X)*pingState); pingCircle.Draw(spriteBatch, center, Color.White * (1.0f-pingState), 0.0f, (rect.Width/pingCircle.size.X)*pingState);
float radius = rect.Width / 2.0f; float radius = rect.Width / 2.0f;
float displayScale = radius/range;
float simScale = 1.5f; float simScale = 1.5f;
if (Level.Loaded != null) if (Level.Loaded != null)
@@ -276,8 +278,9 @@ namespace Barotrauma.Items.Components
private void DrawBlip(SpriteBatch spriteBatch, RadarBlip blip, Vector2 center, Color color, float radius) private void DrawBlip(SpriteBatch spriteBatch, RadarBlip blip, Vector2 center, Color color, float radius)
{ {
float displayScale = radius / range;
Vector2 pos = (blip.Position-item.WorldPosition) * displayScale; Vector2 pos = (blip.Position - item.WorldPosition) * displayScale;
pos.Y = -pos.Y; pos.Y = -pos.Y;
if (pos.Length() > radius) if (pos.Length() > radius)
@@ -307,7 +307,7 @@ namespace Barotrauma.Items.Components
if (item.CurrentHull != null) if (item.CurrentHull != null)
{ {
//the sound can be heard from 20 000 display units away when everything running at 100% //the sound can be heard from 20 000 display units away when everything running at 100%
item.CurrentHull.SoundRange = (coolingRate + fissionRate) * 100; item.CurrentHull.SoundRange = Math.Max((coolingRate + fissionRate) * 100, item.CurrentHull.AiTarget.SoundRange);
} }
UpdateGraph(deltaTime); UpdateGraph(deltaTime);
+9 -5
View File
@@ -24,7 +24,7 @@ namespace Barotrauma
class Item : MapEntity, IDamageable, IPropertyObject class Item : MapEntity, IDamageable, IPropertyObject
{ {
public static List<Item> ItemList = new List<Item>(); public static List<Item> ItemList = new List<Item>();
protected ItemPrefab prefab; private ItemPrefab prefab;
public static ItemSpawner Spawner = new ItemSpawner(); public static ItemSpawner Spawner = new ItemSpawner();
public static ItemRemover Remover = new ItemRemover(); public static ItemRemover Remover = new ItemRemover();
@@ -439,14 +439,14 @@ namespace Barotrauma
new Rectangle( new Rectangle(
WorldRect.X + trigger.X, WorldRect.X + trigger.X,
WorldRect.Y + trigger.Y, WorldRect.Y + trigger.Y,
(trigger.Width == 0) ? (int)Rect.Width : trigger.Width, (trigger.Width == 0) ? Rect.Width : trigger.Width,
(trigger.Height == 0) ? (int)Rect.Height : trigger.Height) (trigger.Height == 0) ? Rect.Height : trigger.Height)
: :
new Rectangle( new Rectangle(
Rect.X + trigger.X, Rect.X + trigger.X,
Rect.Y + trigger.Y, Rect.Y + trigger.Y,
(trigger.Width == 0) ? (int)Rect.Width : trigger.Width, (trigger.Width == 0) ? Rect.Width : trigger.Width,
(trigger.Height == 0) ? (int)Rect.Height : trigger.Height); (trigger.Height == 0) ? Rect.Height : trigger.Height);
} }
/// <summary> /// <summary>
@@ -732,6 +732,8 @@ namespace Barotrauma
foreach (ItemComponent component in components) component.Draw(spriteBatch, editing); foreach (ItemComponent component in components) component.Draw(spriteBatch, editing);
if (GameMain.DebugDraw && aiTarget!=null) aiTarget.Draw(spriteBatch);
if (!editing || (body != null && !body.Enabled)) if (!editing || (body != null && !body.Enabled))
{ {
isHighlighted = false; isHighlighted = false;
@@ -1500,6 +1502,8 @@ namespace Barotrauma
break; break;
case NetworkEventType.PhysicsBodyPosition: case NetworkEventType.PhysicsBodyPosition:
if (body != null) body.ReadNetworkData(message, sendingTime); if (body != null) body.ReadNetworkData(message, sendingTime);
FindHull();
break; break;
case NetworkEventType.ItemFixed: case NetworkEventType.ItemFixed:
+1 -1
View File
@@ -59,7 +59,7 @@ namespace Barotrauma
get { return Submarine == null ? Position : Submarine.Position + Position; } get { return Submarine == null ? Position : Submarine.Position + Position; }
} }
public Vector2 DrawPosition public virtual Vector2 DrawPosition
{ {
get { return Submarine == null ? Position : Submarine.DrawPosition + Position; } get { return Submarine == null ? Position : Submarine.DrawPosition + Position; }
} }
+5 -1
View File
@@ -201,7 +201,6 @@ namespace Barotrauma
surface = rect.Y - rect.Height; surface = rect.Y - rect.Height;
aiTarget = new AITarget(this); aiTarget = new AITarget(this);
aiTarget.SightRange = (rect.Width + rect.Height)*5.0f;
hullList.Add(this); hullList.Add(this);
@@ -353,6 +352,9 @@ namespace Barotrauma
FireSource.UpdateAll(fireSources, deltaTime); FireSource.UpdateAll(fireSources, deltaTime);
aiTarget.SightRange = Submarine == null ? 0.0f : Submarine.Velocity.Length() * 500.0f;
aiTarget.SoundRange -= deltaTime*1000.0f;
float strongestFlow = 0.0f; float strongestFlow = 0.0f;
foreach (Gap gap in ConnectedGaps) foreach (Gap gap in ConnectedGaps)
{ {
@@ -496,6 +498,8 @@ namespace Barotrauma
if (!editing && !GameMain.DebugDraw) return; if (!editing && !GameMain.DebugDraw) return;
if (aiTarget != null) aiTarget.Draw(spriteBatch);
Rectangle drawRect = Rectangle drawRect =
Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height); Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height);