From 188220c464771e3ea4b5f7ab2c2e4136be214bf2 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 20 Apr 2016 17:22:22 +0300 Subject: [PATCH] A "suicide button" which can be used if the character is unconscious and the player doesn't want to wait for help, fixed submarine staying loaded when clicking the "load previous" button mid-round, main path waypoint generation bugfix --- Subsurface/Source/Characters/CharacterHUD.cs | 31 ++++++++++- Subsurface/Source/GameSession/GameSession.cs | 2 + Subsurface/Source/GameSession/ShiftSummary.cs | 18 ++++-- Subsurface/Source/Map/Levels/Level.cs | 55 ++++++++++++------- 4 files changed, 80 insertions(+), 26 deletions(-) diff --git a/Subsurface/Source/Characters/CharacterHUD.cs b/Subsurface/Source/Characters/CharacterHUD.cs index 26e43405c..511a3de86 100644 --- a/Subsurface/Source/Characters/CharacterHUD.cs +++ b/Subsurface/Source/Characters/CharacterHUD.cs @@ -14,6 +14,8 @@ namespace Barotrauma private static GUIButton cprButton; + private static GUIButton suicideButton; + private static GUIProgressBar drowningBar, healthBar; private static float damageOverlayTimer; @@ -36,6 +38,8 @@ namespace Barotrauma if (cprButton != null && cprButton.Visible) cprButton.Update(deltaTime); + if (GameMain.NetworkMember != null && suicideButton != null && suicideButton.Visible) suicideButton.Update(deltaTime); + if (damageOverlayTimer > 0.0f) damageOverlayTimer -= deltaTime; } @@ -144,8 +148,6 @@ namespace Barotrauma } } - - if (Screen.Selected == GameMain.EditMapScreen) return; if (character.IsUnconscious || (character.Oxygen < 80.0f && !character.IsDead)) @@ -159,6 +161,11 @@ namespace Barotrauma noiseOverlay.DrawTiled(spriteBatch, Vector2.Zero - offset, new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight) + offset, Vector2.Zero, Color.White * alpha); + + } + else + { + if (suicideButton != null) suicideButton.Visible = false; } if (damageOverlayTimer>0.0f) @@ -166,6 +173,26 @@ namespace Barotrauma damageOverlay.Draw(spriteBatch, Vector2.Zero, Color.White * damageOverlayTimer, Vector2.Zero, 0.0f, new Vector2(GameMain.GraphicsWidth / damageOverlay.size.X, GameMain.GraphicsHeight / damageOverlay.size.Y)); } + + if (character.IsUnconscious && GameMain.NetworkMember!=null) + { + if (suicideButton == null) + { + suicideButton = new GUIButton( + new Rectangle(new Point(GameMain.GraphicsWidth / 2 - 60, 20), new Point(120, 20)), "Give in", GUI.Style); + + suicideButton.ToolTip = "Let go of your character and enter spectator mode (other players will now longer be able to revive you)"; + + suicideButton.OnClicked = (button, userData) => + { + character.Kill(character.CauseOfDeath); + return true; + }; + } + + suicideButton.Visible = true; + suicideButton.Draw(spriteBatch); + } } private static void DrawStatusIcons(SpriteBatch spriteBatch, Character character) diff --git a/Subsurface/Source/GameSession/GameSession.cs b/Subsurface/Source/GameSession/GameSession.cs index a9b92112d..6f07ebbe3 100644 --- a/Subsurface/Source/GameSession/GameSession.cs +++ b/Subsurface/Source/GameSession/GameSession.cs @@ -188,6 +188,8 @@ namespace Barotrauma public bool LoadPrevious(GUIButton button, object obj) { + Submarine.Unload(); + SaveUtil.LoadGame(saveFile); GameMain.LobbyScreen.Select(); diff --git a/Subsurface/Source/GameSession/ShiftSummary.cs b/Subsurface/Source/GameSession/ShiftSummary.cs index 1575a2c13..45c13bb6a 100644 --- a/Subsurface/Source/GameSession/ShiftSummary.cs +++ b/Subsurface/Source/GameSession/ShiftSummary.cs @@ -75,8 +75,8 @@ namespace Barotrauma character.Info.Job != null ? (character.Info.Name + '\n' + "(" + character.Info.Job.Name + ")") : character.Info.Name, null); - string statusText; - Color statusColor; + string statusText = "OK"; + Color statusColor = Color.DarkGreen; if (character.IsDead) { @@ -85,8 +85,18 @@ namespace Barotrauma } else { - statusText = (character.Health / character.MaxHealth > 0.8f) ? "OK" : "Injured"; - statusColor = (character.Health / character.MaxHealth > 0.8f) ? Color.DarkGreen : Color.DarkOrange; + + if (character.IsUnconscious) + { + statusText = "Unconscious"; + statusColor = Color.DarkOrange; + } + else if (character.Health / character.MaxHealth < 0.8f) + { + statusText = "Injured"; + statusColor = Color.DarkOrange; + } + } new GUITextBlock(new Rectangle(0, 0, 0, 20), statusText, diff --git a/Subsurface/Source/Map/Levels/Level.cs b/Subsurface/Source/Map/Levels/Level.cs index 53f8c12c6..3a08b0466 100644 --- a/Subsurface/Source/Map/Levels/Level.cs +++ b/Subsurface/Source/Map/Levels/Level.cs @@ -359,9 +359,9 @@ namespace Barotrauma pathCells.AddRange(cavePathCells); - for (int j = cavePathCells.Count / 2; j < cavePathCells.Count; j+=10) + for (int j = cavePathCells.Count / 2; j < cavePathCells.Count; j += 10) { - positionsOfInterest.Add(new InterestingPosition(cavePathCells[i].Center, false)); + positionsOfInterest.Add(new InterestingPosition(cavePathCells[j].Center, false)); } } @@ -423,12 +423,12 @@ namespace Barotrauma ShaftBodies = new Body[2]; for (int i = 0; i < 2; i++) { - ShaftBodies[i] = BodyFactory.CreateRectangle(GameMain.World, 100.0f, 10.0f, 5.0f); + ShaftBodies[i] = BodyFactory.CreateRectangle(GameMain.World, 200.0f, 10.0f, 5.0f); ShaftBodies[i].BodyType = BodyType.Static; ShaftBodies[i].CollisionCategories = Physics.CollisionLevel; Vector2 shaftPos = (i == 0) ? startPosition : endPosition; - shaftPos.Y = borders.Height; + shaftPos.Y = borders.Height + 150.0f; ShaftBodies[i].SetTransform(ConvertUnits.ToSimUnits(shaftPos), 0.0f); bodies.Add(ShaftBodies[i]); @@ -489,39 +489,54 @@ namespace Barotrauma private void EnlargeMainPath(List pathCells, float minWidth) { + List wayPoints = new List(); - WayPoint newWaypoint = new WayPoint(new Rectangle((int)pathCells[0].Center.X, (int)(borders.Height + shaftHeight), 10, 10), null); + var newWaypoint = new WayPoint(new Rectangle((int)pathCells[0].Center.X, (int)(borders.Height + shaftHeight), 10, 10), null); newWaypoint.MoveWithLevel = true; + wayPoints.Add(newWaypoint); - WayPoint prevWaypoint = newWaypoint; + //WayPoint prevWaypoint = newWaypoint; for (int i = 0; i < pathCells.Count; i++) { - //clean "loops" from the path - for (int n = 0; n < i; n++) - { - if (pathCells[n] != pathCells[i]) continue; + ////clean "loops" from the path + //for (int n = 0; n < i; n++) + //{ + // if (pathCells[n] != pathCells[i]) continue; - pathCells.RemoveRange(n + 1, i - n); - break; - } - if (i >= pathCells.Count) break; + // pathCells.RemoveRange(n + 1, i - n); + // break; + //} + //if (i >= pathCells.Count) break; + + pathCells[i].CellType = CellType.Path; newWaypoint = new WayPoint(new Rectangle((int)pathCells[i].Center.X, (int)pathCells[i].Center.Y, 10, 10), null); newWaypoint.MoveWithLevel = true; - if (prevWaypoint != null) + wayPoints.Add(newWaypoint); + + wayPoints[wayPoints.Count-2].linkedTo.Add(newWaypoint); + newWaypoint.linkedTo.Add(wayPoints[wayPoints.Count - 2]); + + for (int n = 0; n < wayPoints.Count; n++) { - prevWaypoint.linkedTo.Add(newWaypoint); - newWaypoint.linkedTo.Add(prevWaypoint); + if (wayPoints[n].Position != newWaypoint.Position) continue; + + wayPoints[n].linkedTo.Add(newWaypoint); + newWaypoint.linkedTo.Add(wayPoints[n]); + + break; } - prevWaypoint = newWaypoint; + + //prevWaypoint = newWaypoint; } newWaypoint = new WayPoint(new Rectangle((int)pathCells[pathCells.Count - 1].Center.X, (int)(borders.Height + shaftHeight), 10, 10), null); newWaypoint.MoveWithLevel = true; + wayPoints.Add(newWaypoint); - prevWaypoint.linkedTo.Add(newWaypoint); - newWaypoint.linkedTo.Add(prevWaypoint); + wayPoints[wayPoints.Count - 2].linkedTo.Add(newWaypoint); + newWaypoint.linkedTo.Add(wayPoints[wayPoints.Count - 2]); if (minWidth > 0.0f) {