Cargo spawning bugfix, removing cargo items before saving the game (so that they won't stay in the sub after completing the mission)

This commit is contained in:
Regalis
2016-04-20 20:33:38 +03:00
parent de2af7f973
commit e46ec1ade2
6 changed files with 107 additions and 18 deletions

View File

@@ -110,7 +110,7 @@
spritecolor="1.0,1.0,1.0,1.0"
Tags="smallitem,chem,medical"
pickdistance="150"
impacttolerance="7">
impacttolerance="5">
<Sprite texture ="Content/Items/Medical/med.png" sourcerect="24,16,8,16" depth="0.6"/>

View File

@@ -171,7 +171,6 @@
name="Bike Horn"
category="Equipment"
pickdistance="200"
price="500"
tags="weapon,smallitem"
description="HONK">

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Barotrauma
{
class AIObjectiveRescueAll : AIObjective
{
private List<Character> rescueTargets;
public AIObjectiveRescueAll(Character character)
: base (character, "")
{
rescueTargets = new List<Character>();
}
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));
}
}
}
}

View File

@@ -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())

View File

@@ -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();