From b81417ad168da1d246229aa253731d4d44c5c3b6 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 20 Jul 2016 17:13:34 +0300 Subject: [PATCH] Characters can be left behind in levels and they will stay there until the player returns, other subs visible in sonar --- Subsurface/Source/Characters/CharacterInfo.cs | 23 +++++++++-- Subsurface/Source/GameSession/CrewManager.cs | 24 ++++++++---- .../Source/Items/Components/Machines/Radar.cs | 39 ++++++++++++++----- 3 files changed, 64 insertions(+), 22 deletions(-) diff --git a/Subsurface/Source/Characters/CharacterInfo.cs b/Subsurface/Source/Characters/CharacterInfo.cs index fb0a2be65..39cdcdf3b 100644 --- a/Subsurface/Source/Characters/CharacterInfo.cs +++ b/Subsurface/Source/Characters/CharacterInfo.cs @@ -22,6 +22,8 @@ namespace Barotrauma private List pickedItems; + public ushort? HullID = null; + private Vector2[] headSpriteRange; private Gender gender; @@ -134,7 +136,7 @@ namespace Barotrauma HeadSpriteId = Rand.Range((int)headSpriteRange[genderIndex].X, (int)headSpriteRange[genderIndex].Y + 1); } - this.Job = (jobPrefab == null) ? Job.Random() : new Job(jobPrefab); + this.Job = (jobPrefab == null) ? Job.Random() : new Job(jobPrefab); if (!string.IsNullOrEmpty(name)) { @@ -294,6 +296,9 @@ namespace Barotrauma Salary = ToolBox.GetAttributeInt(element, "salary", 1000); headSpriteId = ToolBox.GetAttributeInt(element, "headspriteid", 1); StartItemsGiven = ToolBox.GetAttributeBool(element, "startitemsgiven", false); + + int hullId = ToolBox.GetAttributeInt(element, "hull", -1); + if (hullId > 0 && hullId <= ushort.MaxValue) this.HullID = (ushort)hullId; pickedItems = new List(); @@ -341,10 +346,19 @@ namespace Barotrauma new XAttribute("salary", Salary), new XAttribute("headspriteid", HeadSpriteId), new XAttribute("startitemsgiven", StartItemsGiven)); - - if (Character != null && Character.Inventory != null) + + if (Character != null) { - UpdateCharacterItems(); + if (Character.Inventory != null) + { + UpdateCharacterItems(); + } + + if (Character.AnimController.CurrentHull != null) + { + HullID = Character.AnimController.CurrentHull.ID; + charElement.Add(new XAttribute("hull", Character.AnimController.CurrentHull.ID)); + } } if (pickedItems.Count > 0) @@ -360,6 +374,7 @@ namespace Barotrauma public void Remove() { + Character = null; //if (headSprite != null) //{ // headSprite.Remove(); diff --git a/Subsurface/Source/GameSession/CrewManager.cs b/Subsurface/Source/GameSession/CrewManager.cs index c9e2e3235..77cd87a77 100644 --- a/Subsurface/Source/GameSession/CrewManager.cs +++ b/Subsurface/Source/GameSession/CrewManager.cs @@ -281,16 +281,24 @@ namespace Barotrauma for (int i = 0; i < waypoints.Length; i++) { - //WayPoint randomWayPoint = WayPoint.GetRandom(SpawnType.Human); - //Vector2 position = (randomWayPoint == null) ? Vector2.Zero : randomWayPoint.SimPosition; - - Character character = Character.Create(characterInfos[i], waypoints[i].WorldPosition); - Character.Controlled = character; + Character character; - if (character.Info!=null && !character.Info.StartItemsGiven) + if (characterInfos[i].HullID != null) { - character.GiveJobItems(waypoints[i]); - character.Info.StartItemsGiven = true; + var hull = Entity.FindEntityByID((ushort)characterInfos[i].HullID) as Hull; + if (hull == null) continue; + character = Character.Create(characterInfos[i], hull.WorldPosition); + } + else + { + character = Character.Create(characterInfos[i], waypoints[i].WorldPosition); + Character.Controlled = character; + + if (character.Info != null && !character.Info.StartItemsGiven) + { + character.GiveJobItems(waypoints[i]); + character.Info.StartItemsGiven = true; + } } AddCharacter(character); diff --git a/Subsurface/Source/Items/Components/Machines/Radar.cs b/Subsurface/Source/Items/Components/Machines/Radar.cs index b35a82a98..905c6a1b8 100644 --- a/Subsurface/Source/Items/Components/Machines/Radar.cs +++ b/Subsurface/Source/Items/Components/Machines/Radar.cs @@ -114,7 +114,7 @@ namespace Barotrauma.Items.Components private void DrawRadar(SpriteBatch spriteBatch, Rectangle rect) { - Vector2 center = new Vector2(rect.Center.X, rect.Center.Y); + Vector2 center = new Vector2(rect.X + rect.Width*0.75f, rect.Center.Y); if (!IsActive) return; @@ -173,7 +173,7 @@ namespace Barotrauma.Items.Components CreateBlipsForLine( new Vector2(item.WorldPosition.X - range, Level.Loaded.Size.Y), new Vector2(item.WorldPosition.X + range, Level.Loaded.Size.Y), - radius, displayScale, 300.0f, 1.0f); + radius, displayScale, 500.0f, 10.0f); } List cells = Level.Loaded.GetCells(item.WorldPosition, 7); @@ -254,11 +254,11 @@ namespace Barotrauma.Items.Components DrawMarker(spriteBatch, (GameMain.GameSession.Map == null) ? "Start" : GameMain.GameSession.Map.CurrentLocation.Name, - (Level.Loaded.StartPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.55f)); + (Level.Loaded.StartPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.5f)); DrawMarker(spriteBatch, (GameMain.GameSession.Map == null) ? "End" : GameMain.GameSession.Map.SelectedLocation.Name, - (Level.Loaded.EndPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.55f)); + (Level.Loaded.EndPosition - item.WorldPosition), displayScale, center, (rect.Width * 0.5f)); if (GameMain.GameSession.Mission != null) { @@ -272,6 +272,13 @@ namespace Barotrauma.Items.Components } } + foreach (Submarine sub in Submarine.Loaded) + { + if (item.Submarine == sub || sub.DockedTo.Contains(item.Submarine)) continue; + + DrawMarker(spriteBatch, sub.Name, sub.WorldPosition - item.WorldPosition, displayScale, center, (rect.Width * 0.45f)); + } + if (!GameMain.DebugDraw) return; var steering = item.GetComponent(); @@ -361,15 +368,27 @@ namespace Barotrauma.Items.Components position *= scale; position.Y = -position.Y; - - Vector2 markerPos = (dist*scale>radius) ? Vector2.Normalize(position) * radius : position; + + float textAlpha = MathHelper.Clamp(1.5f - dist / 50000.0f, 0.5f, 1.0f); + + Vector2 dir = Vector2.Normalize(position); + + Vector2 markerPos = (dist*scale>radius) ? dir * radius : position; markerPos += center; - GUI.DrawRectangle(spriteBatch, new Rectangle((int)markerPos.X, (int)markerPos.Y, 5, 5), Color.LightGreen); + markerPos.X = (int)markerPos.X; + markerPos.Y = (int)markerPos.Y; - spriteBatch.DrawString(GUI.SmallFont, label, new Vector2(markerPos.X + 10, markerPos.Y), Color.LightGreen); - spriteBatch.DrawString(GUI.SmallFont, (int)(dist * Physics.DisplayToRealWorldRatio) + " m", - new Vector2(markerPos.X + 10, markerPos.Y + 15), Color.LightGreen); + GUI.DrawRectangle(spriteBatch, new Rectangle((int)markerPos.X, (int)markerPos.Y, 5, 5), Color.LightGreen * textAlpha); + + if (dir.X < 0.0f) markerPos.X -= GUI.SmallFont.MeasureString(label).X+10; + + GUI.DrawString(spriteBatch, new Vector2(markerPos.X + 10, markerPos.Y), label, Color.LightGreen * textAlpha, Color.Black * textAlpha*0.5f, 2, GUI.SmallFont); + + GUI.DrawString(spriteBatch, new Vector2(markerPos.X + 10, markerPos.Y + 15), (int)(dist * Physics.DisplayToRealWorldRatio) + " m", + Color.LightGreen * textAlpha, + Color.Black * textAlpha, 2, GUI.SmallFont); + } protected override void RemoveComponentSpecific()