(bdf4ed547) Store the last safe hull and use it if cannot find a new.

This commit is contained in:
Joonas Rikkonen
2019-05-18 17:29:56 +03:00
parent 9521f0ae2f
commit 3660df1906
2 changed files with 64 additions and 9 deletions
@@ -68,6 +68,8 @@ namespace Barotrauma
} }
} }
private Hull currentSafeHull;
private Hull previousSafeHull;
protected override void Act(float deltaTime) protected override void Act(float deltaTime)
{ {
var currentHull = character.AnimController.CurrentHull; var currentHull = character.AnimController.CurrentHull;
@@ -107,15 +109,20 @@ namespace Barotrauma
else else
{ {
searchHullTimer = SearchHullInterval; searchHullTimer = SearchHullInterval;
var bestHull = FindBestHull(); previousSafeHull = currentSafeHull;
if (bestHull != null && bestHull != currentHull) currentSafeHull = FindBestHull();
if (currentSafeHull == null)
{ {
if (goToObjective?.Target != bestHull) currentSafeHull = previousSafeHull;
}
if (currentSafeHull != null && currentSafeHull != currentHull)
{
if (goToObjective?.Target != currentSafeHull)
{ {
goToObjective = null; goToObjective = null;
} }
TryAddSubObjective(ref goToObjective, TryAddSubObjective(ref goToObjective,
constructor: () => new AIObjectiveGoTo(bestHull, character, objectiveManager, getDivingGearIfNeeded: false) constructor: () => new AIObjectiveGoTo(currentSafeHull, character, objectiveManager, getDivingGearIfNeeded: false)
{ {
// If we need diving gear, we should already have it, if possible. // If we need diving gear, we should already have it, if possible.
AllowGoingOutside = HumanAIController.HasDivingSuit(character) AllowGoingOutside = HumanAIController.HasDivingSuit(character)
@@ -179,11 +186,11 @@ namespace Barotrauma
{ {
if (hull.Submarine == null) { continue; } if (hull.Submarine == null) { continue; }
if (ignoredHulls != null && ignoredHulls.Contains(hull)) { continue; } if (ignoredHulls != null && ignoredHulls.Contains(hull)) { continue; }
if (unreachable.Contains(hull)) { continue; }
float hullSafety = 0; float hullSafety = 0;
if (character.Submarine != null && SteeringManager == PathSteering) if (character.CurrentHull != null)
{ {
// Inside or outside near the sub // Inside
if (unreachable.Contains(hull)) { continue; }
if (!character.Submarine.IsConnectedTo(hull.Submarine)) { continue; } if (!character.Submarine.IsConnectedTo(hull.Submarine)) { continue; }
hullSafety = HumanAIController.GetHullSafety(hull, character); hullSafety = HumanAIController.GetHullSafety(hull, character);
// Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally) // Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally)
@@ -212,7 +219,7 @@ namespace Barotrauma
else else
{ {
// Outside // Outside
if (hull.RoomName?.ToLowerInvariant() == "airlock") if (hull.RoomName != null && hull.RoomName.ToLowerInvariant().Contains("airlock"))
{ {
hullSafety = 100; hullSafety = 100;
} }
@@ -221,7 +228,7 @@ namespace Barotrauma
// TODO: could also target gaps that get us inside? // TODO: could also target gaps that get us inside?
foreach (Item item in Item.ItemList) foreach (Item item in Item.ItemList)
{ {
if (item.CurrentHull == hull && item.HasTag("airlock")) if (item.CurrentHull != hull && item.HasTag("airlock"))
{ {
hullSafety = 100; hullSafety = 100;
break; break;
@@ -821,6 +821,54 @@ namespace Barotrauma
VoiceSetting = voiceSetting; VoiceSetting = voiceSetting;
} }
} }
if (!SelectedContentPackages.Any())
{
var availablePackage = ContentPackage.List.FirstOrDefault(cp => cp.IsCompatible() && cp.CorePackage);
if (availablePackage != null)
{
SelectedContentPackages.Add(availablePackage);
}
}
//save to get rid of the invalid selected packages in the config file
if (missingPackagePaths.Count > 0 || incompatiblePackages.Count > 0) { SaveNewPlayerConfig(); }
}
#endregion
#region Save DefaultConfig
private void SaveNewDefaultConfig()
{
XDocument doc = new XDocument();
if (doc.Root == null)
{
doc.Add(new XElement("config"));
}
doc.Root.Add(
new XAttribute("language", TextManager.Language),
new XAttribute("masterserverurl", MasterServerUrl),
new XAttribute("autocheckupdates", AutoCheckUpdates),
new XAttribute("musicvolume", musicVolume),
new XAttribute("soundvolume", soundVolume),
new XAttribute("voicechatvolume", voiceChatVolume),
new XAttribute("verboselogging", VerboseLogging),
new XAttribute("savedebugconsolelogs", SaveDebugConsoleLogs),
new XAttribute("enablesplashscreen", EnableSplashScreen),
new XAttribute("usesteammatchmaking", useSteamMatchmaking),
new XAttribute("quickstartsub", QuickStartSubmarineName),
new XAttribute("requiresteamauthentication", requireSteamAuthentication),
new XAttribute("aimassistamount", aimAssistAmount));
if (!ShowUserStatisticsPrompt)
{
doc.Root.Add(new XAttribute("senduserstatistics", sendUserStatistics));
}
if (WasGameUpdated)
{
doc.Root.Add(new XAttribute("wasgameupdated", true));
}
useSteamMatchmaking = doc.Root.GetAttributeBool("usesteammatchmaking", useSteamMatchmaking); useSteamMatchmaking = doc.Root.GetAttributeBool("usesteammatchmaking", useSteamMatchmaking);
requireSteamAuthentication = doc.Root.GetAttributeBool("requiresteamauthentication", requireSteamAuthentication); requireSteamAuthentication = doc.Root.GetAttributeBool("requiresteamauthentication", requireSteamAuthentication);