(e0d673b0d) Test: Don't calculate the distance to the buttons when seeking path. Instead, check the distance when checking the doors. Allows the bots to access the Remora ballast through the door where the button is a bit farther from the door than usually.

This commit is contained in:
Joonas Rikkonen
2019-05-16 05:42:51 +03:00
parent 828150e0ae
commit de2246fe57
85 changed files with 1955 additions and 1760 deletions
@@ -1,62 +1,44 @@
using System.Linq;
using System.Collections.Generic;
using Barotrauma.Extensions;
using Microsoft.Xna.Framework;
namespace Barotrauma
{
class AIObjectiveExtinguishFires : AIObjective
class AIObjectiveExtinguishFires : AIObjectiveLoop<Hull>
{
public override string DebugTag => "extinguish fires";
public override bool ForceRun => true;
public override bool KeepDivingGearOn => true;
private Dictionary<Hull, AIObjectiveExtinguishFire> extinguishObjectives = new Dictionary<Hull, AIObjectiveExtinguishFire>();
public AIObjectiveExtinguishFires(Character character, AIObjectiveManager objectiveManager, float priorityModifier = 1) : base(character, objectiveManager, priorityModifier) { }
public AIObjectiveExtinguishFires(Character character) : base(character, "") { }
public override float GetPriority(AIObjectiveManager objectiveManager)
protected override void FindTargets()
{
if (character.Submarine == null) { return 0; }
int fireCount = character.Submarine.GetHulls(true).Sum(h => h.FireSources.Count);
if (objectiveManager.CurrentOrder == this && fireCount > 0)
base.FindTargets();
if (targets.None() && objectiveManager.CurrentOrder == this)
{
return AIObjectiveManager.OrderPriority;
character.Speak(TextManager.Get("DialogNoFire"), null, 3.0f, "nofire", 30.0f);
}
return MathHelper.Clamp(fireCount * 20, 0, 100);
}
public override bool IsCompleted() => false;
public override bool CanBeCompleted => true;
protected override bool Filter(Hull hull) => IsValidTarget(hull, character);
public override bool IsDuplicate(AIObjective otherObjective)
{
return otherObjective is AIObjectiveExtinguishFires;
}
protected override float TargetEvaluation() => objectiveManager.CurrentObjective == this ? 100 : targets.Sum(t => GetFireSeverity(t));
protected override void Act(float deltaTime)
public static float GetFireSeverity(Hull hull) => hull.FireSources.Sum(fs => fs.Size.X);
public override bool IsDuplicate(AIObjective otherObjective) => otherObjective is AIObjectiveExtinguishFires;
protected override IEnumerable<Hull> GetList() => Hull.hullList;
protected override AIObjective ObjectiveConstructor(Hull target) => new AIObjectiveExtinguishFire(character, target, objectiveManager, PriorityModifier);
public static bool IsValidTarget(Hull hull, Character character)
{
SyncRemovedObjectives(extinguishObjectives, Hull.hullList);
if (character.Submarine == null) { return; }
foreach (Hull hull in Hull.hullList)
{
if (hull.FireSources.None()) { continue; }
if (hull.Submarine == null) { continue; }
if (hull.Submarine.TeamID != character.TeamID) { continue; }
// If the character is inside, only take connected hulls into account.
if (character.Submarine != null && !character.Submarine.IsEntityFoundOnThisSub(hull, true)) { continue; }
if (!extinguishObjectives.TryGetValue(hull, out AIObjectiveExtinguishFire objective))
{
objective = new AIObjectiveExtinguishFire(character, hull);
extinguishObjectives.Add(hull, objective);
AddSubObjective(objective);
}
}
if (extinguishObjectives.None())
{
character?.Speak(TextManager.Get("DialogNoFire"), null, 3.0f, "nofire", 30.0f);
}
if (hull == null) { return false; }
if (hull.FireSources.None()) { return false; }
if (hull.Submarine == null) { return false; }
if (hull.Submarine.TeamID != character.TeamID) { return false; }
if (character.Submarine != null && !character.Submarine.IsEntityFoundOnThisSub(hull, true)) { return false; }
return true;
}
}
}