diff --git a/Subsurface/Content/Items/Door/doors.xml b/Subsurface/Content/Items/Door/doors.xml index 8a0a70afb..f2687090a 100644 --- a/Subsurface/Content/Items/Door/doors.xml +++ b/Subsurface/Content/Items/Door/doors.xml @@ -12,7 +12,7 @@ - + @@ -40,7 +40,7 @@ - + @@ -68,7 +68,7 @@ - + diff --git a/Subsurface/Source/Characters/AI/AITarget.cs b/Subsurface/Source/Characters/AI/AITarget.cs index 868468704..e6bcd2574 100644 --- a/Subsurface/Source/Characters/AI/AITarget.cs +++ b/Subsurface/Source/Characters/AI/AITarget.cs @@ -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 List = new List(); 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); + } + } } diff --git a/Subsurface/Source/Characters/Animation/Ragdoll.cs b/Subsurface/Source/Characters/Animation/Ragdoll.cs index 11851c8ed..f058eecd9 100644 --- a/Subsurface/Source/Characters/Animation/Ragdoll.cs +++ b/Subsurface/Source/Characters/Animation/Ragdoll.cs @@ -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; - //} } } diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 139bc8a1a..733b1ef9b 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -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; diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 97242b3f2..8dbdbb72a 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -421,6 +421,11 @@ namespace Barotrauma //Ragdoll.DebugDraw = !Ragdoll.DebugDraw; GameMain.DebugDraw = !GameMain.DebugDraw; break; + + case "drawaitargets": + case "showaitargets": + AITarget.ShowAITargets = !AITarget.ShowAITargets; + break; case "sendrandomdata": int messageCount = 1; diff --git a/Subsurface/Source/Items/Components/Machines/Engine.cs b/Subsurface/Source/Items/Components/Machines/Engine.cs index 75338d2e1..40388ff05 100644 --- a/Subsurface/Source/Items/Components/Machines/Engine.cs +++ b/Subsurface/Source/Items/Components/Machines/Engine.cs @@ -88,6 +88,11 @@ namespace Barotrauma.Items.Components 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++) { GameMain.ParticleManager.CreateParticle("bubbles", item.WorldPosition - (Vector2.UnitX * item.Rect.Width/2), diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index d0a66de69..b08beee6a 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -12,8 +12,6 @@ namespace Barotrauma.Items.Components { class Radar : Powered { - const float displayScale = 0.015f; - private float range; private float pingState; @@ -22,11 +20,14 @@ namespace Barotrauma.Items.Components private GUITickBox isActiveTickBox; - [HasDefaultValue(0.0f, false)] + private List radarBlips; + private float prevPingRadius; + + [HasDefaultValue(10000.0f, false)] public float Range { - get { return ConvertUnits.ToDisplayUnits(range); } - set { range = ConvertUnits.ToSimUnits(value); } + get { return range; } + set { range = MathHelper.Clamp(value, 0.0f, 100000.0f); } } public Radar(Item item, XElement element) @@ -72,12 +73,14 @@ namespace Barotrauma.Items.Components if (voltage >= minVoltage) { - pingState = (pingState + deltaTime * 0.5f); + pingState = pingState + deltaTime * 0.5f; if (pingState>1.0f) { - item.Use(deltaTime, null); + item.Use(deltaTime); pingState = 0.0f; } + + if (item.CurrentHull != null) item.CurrentHull.AiTarget.SoundRange = Math.Max(Range * pingState, item.CurrentHull.AiTarget.SoundRange); } else { @@ -89,7 +92,7 @@ namespace Barotrauma.Items.Components 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) @@ -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)); } - private List radarBlips; - private float prevPingRadius; - private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect) { Vector2 center = new Vector2(rect.Center.X, rect.Center.Y); @@ -116,8 +116,10 @@ namespace Barotrauma.Items.Components float pingRadius = (rect.Width / 2) * 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 displayScale = radius/range; + float simScale = 1.5f; @@ -276,8 +278,9 @@ namespace Barotrauma.Items.Components private void DrawBlip(SpriteBatch spriteBatch, RadarBlip blip, Vector2 center, Color color, float radius) { - - Vector2 pos = (blip.Position-item.WorldPosition) * displayScale; + float displayScale = radius / range; + + Vector2 pos = (blip.Position - item.WorldPosition) * displayScale; pos.Y = -pos.Y; if (pos.Length() > radius) diff --git a/Subsurface/Source/Items/Components/Machines/Reactor.cs b/Subsurface/Source/Items/Components/Machines/Reactor.cs index 3c4fab541..991e82829 100644 --- a/Subsurface/Source/Items/Components/Machines/Reactor.cs +++ b/Subsurface/Source/Items/Components/Machines/Reactor.cs @@ -158,7 +158,7 @@ namespace Barotrauma.Items.Components shutDownTemp = 500.0f; powerPerTemp = 1.0f; - + IsActive = true; var button = new GUIButton(new Rectangle(410, 70, 40, 40), "-", GUI.Style, GuiFrame); @@ -307,7 +307,7 @@ namespace Barotrauma.Items.Components if (item.CurrentHull != null) { //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); diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 82399fae4..f9c21b3ae 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -24,7 +24,7 @@ namespace Barotrauma class Item : MapEntity, IDamageable, IPropertyObject { public static List ItemList = new List(); - protected ItemPrefab prefab; + private ItemPrefab prefab; public static ItemSpawner Spawner = new ItemSpawner(); public static ItemRemover Remover = new ItemRemover(); @@ -439,14 +439,14 @@ namespace Barotrauma new Rectangle( WorldRect.X + trigger.X, WorldRect.Y + trigger.Y, - (trigger.Width == 0) ? (int)Rect.Width : trigger.Width, - (trigger.Height == 0) ? (int)Rect.Height : trigger.Height) + (trigger.Width == 0) ? Rect.Width : trigger.Width, + (trigger.Height == 0) ? Rect.Height : trigger.Height) : new Rectangle( Rect.X + trigger.X, Rect.Y + trigger.Y, - (trigger.Width == 0) ? (int)Rect.Width : trigger.Width, - (trigger.Height == 0) ? (int)Rect.Height : trigger.Height); + (trigger.Width == 0) ? Rect.Width : trigger.Width, + (trigger.Height == 0) ? Rect.Height : trigger.Height); } /// @@ -731,6 +731,8 @@ namespace Barotrauma } foreach (ItemComponent component in components) component.Draw(spriteBatch, editing); + + if (GameMain.DebugDraw && aiTarget!=null) aiTarget.Draw(spriteBatch); if (!editing || (body != null && !body.Enabled)) { @@ -1500,6 +1502,8 @@ namespace Barotrauma break; case NetworkEventType.PhysicsBodyPosition: if (body != null) body.ReadNetworkData(message, sendingTime); + + FindHull(); break; case NetworkEventType.ItemFixed: diff --git a/Subsurface/Source/Map/Entity.cs b/Subsurface/Source/Map/Entity.cs index b63650196..cad366b60 100644 --- a/Subsurface/Source/Map/Entity.cs +++ b/Subsurface/Source/Map/Entity.cs @@ -59,7 +59,7 @@ namespace Barotrauma get { return Submarine == null ? Position : Submarine.Position + Position; } } - public Vector2 DrawPosition + public virtual Vector2 DrawPosition { get { return Submarine == null ? Position : Submarine.DrawPosition + Position; } } diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index f2f811137..5c7f15cdd 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -201,7 +201,6 @@ namespace Barotrauma surface = rect.Y - rect.Height; aiTarget = new AITarget(this); - aiTarget.SightRange = (rect.Width + rect.Height)*5.0f; hullList.Add(this); @@ -353,6 +352,9 @@ namespace Barotrauma FireSource.UpdateAll(fireSources, deltaTime); + aiTarget.SightRange = Submarine == null ? 0.0f : Submarine.Velocity.Length() * 500.0f; + aiTarget.SoundRange -= deltaTime*1000.0f; + float strongestFlow = 0.0f; foreach (Gap gap in ConnectedGaps) { @@ -495,6 +497,8 @@ namespace Barotrauma if (!ShowHulls && !GameMain.DebugDraw) return; if (!editing && !GameMain.DebugDraw) return; + + if (aiTarget != null) aiTarget.Draw(spriteBatch); Rectangle drawRect = Submarine == null ? rect : new Rectangle((int)(Submarine.DrawPosition.X + rect.X), (int)(Submarine.DrawPosition.Y + rect.Y), rect.Width, rect.Height);