From e46ec1ade231de592f344d29b645e7ac6d504359 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 20 Apr 2016 20:33:38 +0300 Subject: [PATCH] Cargo spawning bugfix, removing cargo items before saving the game (so that they won't stay in the sub after completing the mission) --- .../Content/Items/Weapons/explosives.xml | 2 +- Subsurface/Content/Items/Weapons/weapons.xml | 1 - .../AI/Objectives/AIObjectiveRescue.cs | 38 ++++++++++++++ .../AI/Objectives/AIObjectiveRescureAll.cs | 50 +++++++++++++++++++ .../Source/Events/Missions/CargoMission.cs | 18 ++++++- .../GameSession/GameModes/SinglePlayerMode.cs | 16 +----- 6 files changed, 107 insertions(+), 18 deletions(-) create mode 100644 Subsurface/Source/Characters/AI/Objectives/AIObjectiveRescue.cs create mode 100644 Subsurface/Source/Characters/AI/Objectives/AIObjectiveRescureAll.cs diff --git a/Subsurface/Content/Items/Weapons/explosives.xml b/Subsurface/Content/Items/Weapons/explosives.xml index 7d2abb29a..da77ebc2a 100644 --- a/Subsurface/Content/Items/Weapons/explosives.xml +++ b/Subsurface/Content/Items/Weapons/explosives.xml @@ -110,7 +110,7 @@ spritecolor="1.0,1.0,1.0,1.0" Tags="smallitem,chem,medical" pickdistance="150" - impacttolerance="7"> + impacttolerance="5"> diff --git a/Subsurface/Content/Items/Weapons/weapons.xml b/Subsurface/Content/Items/Weapons/weapons.xml index a50d834ad..0c47b7b24 100644 --- a/Subsurface/Content/Items/Weapons/weapons.xml +++ b/Subsurface/Content/Items/Weapons/weapons.xml @@ -171,7 +171,6 @@ name="Bike Horn" category="Equipment" pickdistance="200" - price="500" tags="weapon,smallitem" description="HONK"> diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveRescue.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveRescue.cs new file mode 100644 index 000000000..afb30c2d3 --- /dev/null +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveRescue.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; + +namespace Barotrauma +{ + class AIObjectiveRescue : AIObjective + { + private readonly Character targetCharacter; + + public AIObjectiveRescue(Character character, Character targetCharacter) + : base (character, "") + { + Debug.Assert(character != targetCharacter); + + this.targetCharacter = targetCharacter; + } + + public override bool IsDuplicate(AIObjective otherObjective) + { + AIObjectiveRescue rescueObjective = otherObjective as AIObjectiveRescue; + return rescueObjective != null && rescueObjective.targetCharacter == targetCharacter; + } + + public override float GetPriority(Character character) + { + if (targetCharacter.AnimController.CurrentHull == null) return 0.0f; + + float distance = Vector2.DistanceSquared(character.WorldPosition, targetCharacter.WorldPosition); + + return targetCharacter.IsDead ? 1000.0f / distance : 10000.0f / distance; + } + + } +} diff --git a/Subsurface/Source/Characters/AI/Objectives/AIObjectiveRescureAll.cs b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveRescureAll.cs new file mode 100644 index 000000000..a632cd62a --- /dev/null +++ b/Subsurface/Source/Characters/AI/Objectives/AIObjectiveRescureAll.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Barotrauma +{ + class AIObjectiveRescueAll : AIObjective + { + private List rescueTargets; + + public AIObjectiveRescueAll(Character character) + : base (character, "") + { + rescueTargets = new List(); + } + + public override bool IsDuplicate(AIObjective otherObjective) + { + return true; + } + + public override float GetPriority(Character character) + { + GetRescueTargets(); + + //if there are targets to rescue, the priority is slightly less + //than the priority of explicit orders given to the character + return rescueTargets.Any() ? AIObjectiveManager.OrderPriority - 5.0f : 0.0f; + } + + private void GetRescueTargets() + { + rescueTargets = Character.CharacterList.FindAll(c => + c.AIController is HumanAIController && + c != character && + (c.IsDead || c.IsUnconscious) && + c.AnimController.CurrentHull != null && + AIObjectiveFindSafety.GetHullSafety(c.AnimController.CurrentHull, c) < 50.0f); + } + + protected override void Act(float deltaTime) + { + foreach (Character target in rescueTargets) + { + AddSubObjective(new AIObjectiveRescue(character, target)); + } + } + } +} diff --git a/Subsurface/Source/Events/Missions/CargoMission.cs b/Subsurface/Source/Events/Missions/CargoMission.cs index a21a60350..722fa525c 100644 --- a/Subsurface/Source/Events/Missions/CargoMission.cs +++ b/Subsurface/Source/Events/Missions/CargoMission.cs @@ -1,4 +1,5 @@ using Barotrauma.Items.Components; +using Microsoft.Xna.Framework; using System; using System.Collections.Generic; using System.Linq; @@ -60,9 +61,22 @@ namespace Barotrauma return; } - var item = new Item(itemPrefab, cargoSpawnPos.Position, Submarine.Loaded); - items.Add(item); + var cargoRoom = cargoSpawnPos.CurrentHull; + if (cargoRoom == null) + { + DebugConsole.ThrowError("A waypoint marked as Cargo must be placed inside a room!"); + return; + } + + Vector2 position = new Vector2( + Rand.Range(cargoRoom.Rect.X + 20, cargoRoom.Rect.Right - 20, true), + cargoRoom.Rect.Y - cargoRoom.Rect.Height + 10.0f); + + var item = new Item(itemPrefab, position, cargoRoom.Submarine); + item.FindHull(); + items.Add(item); + if (parent != null) parent.Combine(item); foreach (XElement subElement in element.Elements()) diff --git a/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs b/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs index 3658d5854..0dec54830 100644 --- a/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs +++ b/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs @@ -195,6 +195,8 @@ namespace Barotrauma bool success = CrewManager.characters.Any(c => !c.IsDead); + GameMain.GameSession.EndShift(""); + if (success) { if (Submarine.Loaded.AtEndPosition) @@ -204,22 +206,8 @@ namespace Barotrauma SaveUtil.SaveGame(GameMain.GameSession.SaveFile); } - else - { - // var okButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Ok", Alignment.BottomRight, GUI.Style, summaryFrame.children[0]); - //okButton.OnClicked = (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Dequeue(); return true; }; - - // var msgBox = new GUIMessageBox("Game over", "Your entire crew has died!", new string[] { "Load game", "Quit" }); - // msgBox.Buttons[0].OnClicked += GameMain.GameSession.LoadPrevious; - // msgBox.Buttons[0].OnClicked += msgBox.Close; - // msgBox.Buttons[1].OnClicked = GameMain.LobbyScreen.QuitToMainMenu; - // msgBox.Buttons[1].OnClicked += msgBox.Close; - } - - GameMain.GameSession.EndShift(""); - if (!success) { var summaryScreen = GUIMessageBox.MessageBoxes.Peek();