Bunch of crew AI bugfixes/improvements:

- replacing empty oxygen tanks
- fixed characters only fixing leaks in the outer hull
- prioritizing large leaks over small ones
- fixed characters doing nothing after fixing all the leaks (and sinking to the bottom if they happen to be outside)
- more accurate welder aiming
- AIObjectiveGetItem makes the characters go to the cabinet/container an item is inside, not to the actual item (which may not be actually positioned at the container)
This commit is contained in:
Regalis
2016-03-16 17:41:59 +02:00
parent 804510b144
commit d6a57f9533
15 changed files with 228 additions and 163 deletions
@@ -29,68 +29,41 @@ namespace Barotrauma
protected override void Act(float deltaTime)
{
if (character.AnimController.CurrentHull == null) return;
currenthullSafety = OverrideCurrentHullSafety == null ?
GetHullSafety(character.AnimController.CurrentHull) : (float)OverrideCurrentHullSafety;
if (character.AnimController.CurrentHull == null || currenthullSafety > MinSafety)
{
character.AIController.SteeringManager.SteeringSeek(character.AnimController.CurrentHull.SimPosition);
character.AIController.SelectTarget(null);
goToObjective = null;
return;
}
var currentHull = character.AnimController.CurrentHull;
if (currentHull.Volume / currentHull.FullVolume > 0.5f)
currenthullSafety = OverrideCurrentHullSafety == null ?
GetHullSafety(currentHull) : (float)OverrideCurrentHullSafety;
if (currentHull != null)
{
if (!FindDivingGear(deltaTime)) return;
if (currentHull.Volume / currentHull.FullVolume > 0.5f || character.Oxygen < 80.0f)
{
if (!FindDivingGear(deltaTime)) return;
}
if (currenthullSafety > MinSafety)
{
character.AIController.SteeringManager.SteeringSeek(currentHull.SimPosition, 0.5f);
character.AIController.SelectTarget(null);
goToObjective = null;
return;
}
}
if (searchHullTimer>0.0f)
if (searchHullTimer > 0.0f)
{
searchHullTimer -= deltaTime;
//return;
}
else
{
Hull bestHull = null;
float bestValue = currenthullSafety;
foreach (Hull hull in Hull.hullList)
{
if (hull == character.AnimController.CurrentHull) continue;
if (unreachable.Contains(hull)) continue;
float hullValue = GetHullSafety(hull);
hullValue -= (float)Math.Sqrt(Math.Abs(character.Position.X- hull.Position.X));
hullValue -= (float)Math.Sqrt(Math.Abs(character.Position.Y - hull.Position.Y)*2.0f);
if (bestHull == null || hullValue > bestValue)
{
bestHull = hull;
bestValue = hullValue;
}
}
var bestHull = FindBestHull();
if (bestHull != null)
{
//var path = pathSteering.PathFinder.FindPath(character.SimPosition, bestHull.SimPosition);
//if (pathSteering.CurrentPath == null || (pathSteering.CurrentPath.NextNode==null && pathSteering.CurrentPath.Cost > path.Cost) ||
// pathSteering.CurrentPath.Unreachable || goToObjective==null)
//{
//pathSteering.SetPath(path);
goToObjective = new AIObjectiveGoTo(bestHull, character);
//}
//haracter.AIController.SelectTarget(bestHull.AiTarget);
goToObjective = new AIObjectiveGoTo(bestHull, character);
}
searchHullTimer = SearchHullInterval;
}
@@ -117,43 +90,29 @@ namespace Barotrauma
divingGearObjective.TryComplete(deltaTime);
return divingGearObjective.IsCompleted();
}
//var item = character.Inventory.FindItem("diving");
//if (item == null)
//{
// //get a diving mask/suit first
// if (!(divingGearObjective is AIObjectiveGetItem))
// {
// divingGearObjective = new AIObjectiveGetItem(character, "diving", true);
// }
//}
//else
//{
// var containedItems = item.ContainedItems;
// if (containedItems == null) return true;
private Hull FindBestHull()
{
Hull bestHull = null;
float bestValue = currenthullSafety;
// //check if there's an oxygen tank in the mask
// var oxygenTank = Array.Find(containedItems, i => i.Name == "Oxygen Tank" && i.Condition > 0.0f);
foreach (Hull hull in Hull.hullList)
{
if (hull == character.AnimController.CurrentHull || unreachable.Contains(hull)) continue;
// if (oxygenTank != null) return true;
float hullValue = GetHullSafety(hull);
hullValue -= (float)Math.Sqrt(Math.Abs(character.Position.X - hull.Position.X));
hullValue -= (float)Math.Sqrt(Math.Abs(character.Position.Y - hull.Position.Y) * 2.0f);
if (bestHull == null || hullValue > bestValue)
{
bestHull = hull;
bestValue = hullValue;
}
}
// if (!(divingGearObjective is AIObjectiveContainItem))
// {
// divingGearObjective = new AIObjectiveContainItem(character, "Oxygen Tank", item.GetComponent<ItemContainer>());
// }
//}
//if (divingGearObjective != null)
//{
// divingGearObjective.TryComplete(deltaTime);
// bool isCompleted = divingGearObjective.IsCompleted();
// if (isCompleted) divingGearObjective = null;
// return isCompleted;
//}
//return false;
return bestHull;
}
public override bool IsDuplicate(AIObjective otherObjective)
@@ -163,11 +122,15 @@ namespace Barotrauma
public override float GetPriority(Character character)
{
if (character.AnimController.CurrentHull == null) return 0.0f;
if (character.Oxygen < 80.0f)
{
return 150.0f - character.Oxygen;
}
if (character.AnimController.CurrentHull == null) return 5.0f;
currenthullSafety = GetHullSafety(character.AnimController.CurrentHull);
priority = 100.0f - currenthullSafety;
if (divingGearObjective != null && !divingGearObjective.IsCompleted()) priority += 20.0f;
return priority;
@@ -175,6 +138,8 @@ namespace Barotrauma
private float GetHullSafety(Hull hull)
{
if (hull == null) return 0.0f;
float waterPercentage = (hull.Volume / hull.FullVolume)*100.0f;
float fireAmount = 0.0f;
@@ -185,7 +150,7 @@ namespace Barotrauma
float safety = 100.0f - fireAmount;
if (waterPercentage > 30.0f && character.Oxygen<80.0f) safety -= waterPercentage;
if (waterPercentage > 30.0f && character.OxygenAvailable<=0.0f) safety -= waterPercentage;
if (hull.OxygenPercentage < 30.0f) safety -= (30.0f-hull.OxygenPercentage)*5.0f;
return safety;