diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs index 88aa9edd5..c8a38af87 100644 --- a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveGoTo.cs @@ -62,10 +62,26 @@ namespace Barotrauma if (target!=null) character.AIController.SelectTarget(target.AiTarget); - character.AIController.SteeringManager.SteeringSeek( - target != null ? target.SimPosition : targetPos); - Vector2 currTargetPos = target != null ? target.SimPosition : targetPos; + Vector2 currTargetPos = Vector2.Zero; + + if (target == null) + { + currTargetPos = targetPos; + } + else + { + currTargetPos = target.SimPosition; + + //if character is outside the sub and target isn't, transform the position + if (character.Submarine == null && target.Submarine != null) + { + currTargetPos += target.Submarine.SimPosition; + } + } + + character.AIController.SteeringManager.SteeringSeek(currTargetPos); + if (Vector2.Distance(currTargetPos, character.SimPosition) < 1.0f) { character.AnimController.TargetDir = currTargetPos.X > character.SimPosition.X ? Direction.Right : Direction.Left; diff --git a/Subsurface/Source/Characters/AI/PathFinder.cs b/Subsurface/Source/Characters/AI/PathFinder.cs index 8b3ab05c3..f76c31ba4 100644 --- a/Subsurface/Source/Characters/AI/PathFinder.cs +++ b/Subsurface/Source/Characters/AI/PathFinder.cs @@ -100,12 +100,22 @@ namespace Barotrauma PathNode startNode = null; foreach (PathNode node in nodes) { - float dist = System.Math.Abs(start.X-node.Position.X)+ - System.Math.Abs(start.Y - node.Position.Y)*10.0f + - Vector2.Distance(end,node.Position)/2.0f; + Vector2 nodePos = node.Position; + + //if node waypoint is one of submarine waypoints outside the sub, transform position + if (node.Waypoint != null && node.Waypoint.Submarine != null && node.Waypoint.CurrentHull == null) + { + nodePos -= node.Waypoint.Submarine.Position; + } + + float dist = System.Math.Abs(start.X-nodePos.X)+ + System.Math.Abs(start.Y - nodePos.Y)*10.0f + + Vector2.Distance(end,nodePos)/2.0f; + if (dist NetConfig.CharacterIgnoreDistance) return false; + //if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false; message.Write(AnimController.RefLimb.SimPosition.X); message.Write(AnimController.RefLimb.SimPosition.Y); @@ -94,15 +94,15 @@ namespace Barotrauma aiController.FillNetworkData(message); return true; case NetworkEventType.EntityUpdate: - if (Submarine == null) - { - if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false; + //if (Submarine == null) + //{ + // if ((AnimController.RefLimb.SimPosition - Submarine.Loaded.SimPosition).Length() > NetConfig.CharacterIgnoreDistance) return false; - } - else - { - if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false; - } + //} + //else + //{ + // if (AnimController.RefLimb.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) return false; + //} message.Write(AnimController.TargetDir == Direction.Right); diff --git a/Subsurface/Source/Events/Quests/MonsterQuest.cs b/Subsurface/Source/Events/Quests/MonsterQuest.cs index 22cfd873d..c1c21c269 100644 --- a/Subsurface/Source/Events/Quests/MonsterQuest.cs +++ b/Subsurface/Source/Events/Quests/MonsterQuest.cs @@ -11,9 +11,11 @@ namespace Barotrauma private Character monster; + private Vector2 radarPosition; + public override Vector2 RadarPosition { - get { return monster.Position; } + get { return radarPosition; } } public MonsterMission(XElement element) @@ -27,6 +29,7 @@ namespace Barotrauma Vector2 position = level.PositionsOfInterest[Rand.Int(level.PositionsOfInterest.Count, false)]; monster = Character.Create(monsterFile, position); + radarPosition = monster.Position; } public override void Update(float deltaTime) @@ -34,6 +37,8 @@ namespace Barotrauma switch (state) { case 0: + if (monster.Enabled) radarPosition = monster.Position; + if (!monster.IsDead) return; ShowMessage(state); state = 1; diff --git a/Subsurface/Source/GameSession/CrewManager.cs b/Subsurface/Source/GameSession/CrewManager.cs index b946c5e1a..2039166b3 100644 --- a/Subsurface/Source/GameSession/CrewManager.cs +++ b/Subsurface/Source/GameSession/CrewManager.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.IO; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -225,7 +226,7 @@ namespace Barotrauma AddCharacter(character); } - if (characters.Count > 0) SelectCharacter(null, characters[0]); + if (characters.Any()) listBox.Select(0);// SelectCharacter(null, characters[0]); } public void EndShift() diff --git a/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs b/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs index 56ea00291..189e8609f 100644 --- a/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs +++ b/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs @@ -235,7 +235,7 @@ namespace Barotrauma { isRunning = false; - var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam); + var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam, 5.0f); SoundPlayer.OverrideMusicType = CrewManager.characters.Any(c => !c.IsDead) ? "endshift" : "crewdead"; diff --git a/Subsurface/Source/Map/Entity.cs b/Subsurface/Source/Map/Entity.cs index 51f3ce6dc..1b0ed6019 100644 --- a/Subsurface/Source/Map/Entity.cs +++ b/Subsurface/Source/Map/Entity.cs @@ -51,7 +51,7 @@ namespace Barotrauma get { return Vector2.Zero; } } - public Vector2 WorldPosition + public virtual Vector2 WorldPosition { get { return Submarine == null ? Position : Submarine.Position + Position; } } diff --git a/Subsurface/Source/Map/Hull.cs b/Subsurface/Source/Map/Hull.cs index a84bebfef..c1c1394fe 100644 --- a/Subsurface/Source/Map/Hull.cs +++ b/Subsurface/Source/Map/Hull.cs @@ -170,15 +170,14 @@ namespace Barotrauma InsertToList(); } - public override void OnMapLoaded() + public static void GenerateEntityGrid() { - - if (entityGrid == null) + entityGrid = new EntityGrid(Submarine.Borders, 200.0f); + + foreach (Hull hull in hullList) { - entityGrid = new EntityGrid(Submarine.Borders, 200.0f); + entityGrid.InsertEntity(hull); } - - entityGrid.InsertEntity(this); } public override bool Contains(Vector2 position) diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 0808d1021..7a6fc88ca 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -499,13 +499,14 @@ namespace Barotrauma } } + for (int i = 0; i < mapEntityList.Count; i++) + { + if (mapEntityList[i].Submarine != null) mapEntityList[i].Move(Submarine.HiddenSubPosition); + } + for (int i = 0; i " + Position + " - " + dist); if (dist > 1000.0f) { - body.SetTransform(targetSimPos, 0.0f); + body.SetTransform(ConvertUnits.ToSimUnits((Vector2)targetPosition), 0.0f); + + GameMain.GameScreen.Cam.Position = submarine.Position + Submarine.HiddenSubPosition; targetPosition = null; } else if (dist > 50.0f) { - Vector2 moveAmount = Vector2.Normalize(targetSimPos - body.Position); - moveAmount *= Math.Min(dist, 100.0f); + Vector2 moveAmount = Vector2.Normalize((Vector2)targetPosition - Position); + moveAmount *= ConvertUnits.ToSimUnits(Math.Min(dist, 100.0f)); + + System.Diagnostics.Debug.WriteLine("moveamount: "+moveAmount); body.SetTransform(body.Position + moveAmount * deltaTime, 0.0f); + + //GameMain.GameScreen.Cam.Position += ConvertUnits.ToDisplayUnits(moveAmount); } else { diff --git a/Subsurface/Source/Map/TransitionCinematic.cs b/Subsurface/Source/Map/TransitionCinematic.cs index 5e5376cf0..b7af7ef3e 100644 --- a/Subsurface/Source/Map/TransitionCinematic.cs +++ b/Subsurface/Source/Map/TransitionCinematic.cs @@ -15,8 +15,10 @@ namespace Barotrauma get; private set; } + + private float duration; - public TransitionCinematic(Submarine submarine, Camera cam) + public TransitionCinematic(Submarine submarine, Camera cam, float duration) { Vector2 targetPos = submarine.Position; @@ -29,6 +31,8 @@ namespace Barotrauma targetPos = Level.Loaded.StartPosition + Vector2.UnitY * 500.0f; } + this.duration = duration; + Running = true; CoroutineManager.StartCoroutine(UpdateTransitionCinematic(submarine, cam, targetPos)); } @@ -46,7 +50,6 @@ namespace Barotrauma Level.Loaded.ShaftBodies[1].Enabled = false; cam.TargetPos = Vector2.Zero; - float duration = 5.0f; float timer = 0.0f; while (timer < duration) diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index ca740db60..d7c74bf06 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -80,6 +80,8 @@ namespace Barotrauma InsertToList(); WayPointList.Add(this); + + currentHull = Hull.FindHull(WorldPosition); } public override void Draw(SpriteBatch spriteBatch, bool editing, bool back=true) @@ -472,7 +474,7 @@ namespace Barotrauma public override void OnMapLoaded() { - currentHull = Hull.FindHull(WorldPosition); + currentHull = Hull.FindHull(WorldPosition, currentHull); } public override XElement Save(XDocument doc) diff --git a/Subsurface/Source/Networking/GameClient.cs b/Subsurface/Source/Networking/GameClient.cs index 3d3e15c38..55dd52e89 100644 --- a/Subsurface/Source/Networking/GameClient.cs +++ b/Subsurface/Source/Networking/GameClient.cs @@ -596,27 +596,51 @@ namespace Barotrauma.Networking Character.Controlled = null; GameMain.LightManager.LosEnabled = false; + float endPreviewLength = 10.0f; - DateTime endTime = DateTime.Now + new TimeSpan(0,0,0,0,(int)(1000.0f*endPreviewLength)); + var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam, endPreviewLength); + float secondsLeft = endPreviewLength; do { - secondsLeft = (float)(endTime - DateTime.Now).TotalSeconds; + secondsLeft -= CoroutineManager.DeltaTime; - float camAngle = (float)((DateTime.Now - endTime).TotalSeconds / endPreviewLength) * MathHelper.TwoPi; - Vector2 offset = (new Vector2( - (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f), - (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f))); + //float camAngle = (float)((DateTime.Now - endTime).TotalSeconds / endPreviewLength) * MathHelper.TwoPi; + //Vector2 offset = (new Vector2( + // (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f), + // (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f))); - GameMain.GameScreen.Cam.TargetPos = Submarine.Loaded.DrawPosition + offset * 0.8f; + //GameMain.GameScreen.Cam.TargetPos = Submarine.Loaded.Position + offset * 0.8f; //Game1.GameScreen.Cam.MoveCamera((float)deltaTime); messageBox.Text = endMessage + "\nReturning to lobby in " + (int)secondsLeft + " s"; + yield return CoroutineStatus.Running; } while (secondsLeft > 0.0f); + //float endPreviewLength = 10.0f; + + //DateTime endTime = DateTime.Now + new TimeSpan(0,0,0,0,(int)(1000.0f*endPreviewLength)); + //float secondsLeft = endPreviewLength; + + //do + //{ + // secondsLeft = (float)(endTime - DateTime.Now).TotalSeconds; + + // float camAngle = (float)((DateTime.Now - endTime).TotalSeconds / endPreviewLength) * MathHelper.TwoPi; + // Vector2 offset = (new Vector2( + // (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f), + // (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f))); + + // GameMain.GameScreen.Cam.TargetPos = Submarine.Loaded.DrawPosition + offset * 0.8f; + // //Game1.GameScreen.Cam.MoveCamera((float)deltaTime); + + // messageBox.Text = endMessage + "\nReturning to lobby in " + (int)secondsLeft + " s"; + // yield return CoroutineStatus.Running; + //} while (secondsLeft > 0.0f); + messageBox.Close(null,null); Submarine.Unload(); diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 18cdf275b..c0e98f219 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -288,7 +288,9 @@ namespace Barotrauma.Networking { if (!(c is AICharacter) || c.IsDead) continue; - if (c.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) continue; + Vector2 diff = Submarine.Loaded.WorldPosition - c.WorldPosition; + + if (FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) > NetConfig.CharacterIgnoreDistance) continue; new NetworkEvent(NetworkEventType.EntityUpdate, c.ID, false); } @@ -318,7 +320,12 @@ namespace Barotrauma.Networking { if (c.IsDead) continue; - if (c is AICharacter && c.SimPosition.Length() > NetConfig.CharacterIgnoreDistance) continue; + if (c is AICharacter) + { + Vector2 diff = c.WorldPosition - Submarine.Loaded.WorldPosition; + + if (FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) > NetConfig.CharacterIgnoreDistance) continue; + } new NetworkEvent(NetworkEventType.ImportantEntityUpdate, c.ID, false); } @@ -870,19 +877,20 @@ namespace Barotrauma.Networking float endPreviewLength = 10.0f; - DateTime endTime = DateTime.Now + new TimeSpan(0, 0, 0, 0, (int)(1000.0f * endPreviewLength)); + var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam, endPreviewLength); + float secondsLeft = endPreviewLength; do { - secondsLeft = (float)(endTime - DateTime.Now).TotalSeconds; + secondsLeft -= CoroutineManager.DeltaTime; - float camAngle = (float)((DateTime.Now - endTime).TotalSeconds / endPreviewLength) * MathHelper.TwoPi; - Vector2 offset = (new Vector2( - (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f), - (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f))); + //float camAngle = (float)((DateTime.Now - endTime).TotalSeconds / endPreviewLength) * MathHelper.TwoPi; + //Vector2 offset = (new Vector2( + // (float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f), + // (float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f))); - GameMain.GameScreen.Cam.TargetPos = Submarine.Loaded.Position + offset * 0.8f; + //GameMain.GameScreen.Cam.TargetPos = Submarine.Loaded.Position + offset * 0.8f; //Game1.GameScreen.Cam.MoveCamera((float)deltaTime); messageBox.Text = endMessage + "\nReturning to lobby in " + (int)secondsLeft + " s"; diff --git a/Subsurface/Source/Networking/NetworkMember.cs b/Subsurface/Source/Networking/NetworkMember.cs index 10395e611..8e2b01754 100644 --- a/Subsurface/Source/Networking/NetworkMember.cs +++ b/Subsurface/Source/Networking/NetworkMember.cs @@ -206,6 +206,8 @@ namespace Barotrauma.Networking { inGameHUD.Update(deltaTime); + GameMain.GameSession.CrewManager.Update(deltaTime); + //if (crewFrameOpen) crewFrame.Update(deltaTime); if (Character.Controlled == null || Character.Controlled.IsDead) @@ -233,6 +235,8 @@ namespace Barotrauma.Networking { if (!gameStarted || Screen.Selected != GameMain.GameScreen) return; + GameMain.GameSession.CrewManager.Draw(spriteBatch); + inGameHUD.Draw(spriteBatch); } diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index eb1deec25..4f23039e9 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ