(546717195) Use the AIObjectiveFightIntruders.IsValidTarget for deciding whether or not the button should flash.

This commit is contained in:
Joonas Rikkonen
2019-05-16 06:55:43 +03:00
parent 5435adc9b4
commit f38aa90847
20 changed files with 200 additions and 243 deletions
@@ -12,7 +12,7 @@ namespace Barotrauma
public override bool ForceRun => true;
// TODO: expose?
const float priorityIncrease = 25;
const float priorityIncrease = 100;
const float priorityDecrease = 10;
const float SearchHullInterval = 3.0f;
const float clearUnreachableInterval = 30;
@@ -51,8 +51,7 @@ namespace Barotrauma
return;
}
if (character.OxygenAvailable < CharacterHealth.LowOxygenThreshold) { Priority = 100; }
// TODO: no need to update every frame?
currenthullSafety = HumanAIController.GetCurrentHullSafety();
currenthullSafety = HumanAIController.CurrentHullSafety;
if (currenthullSafety > HumanAIController.HULL_SAFETY_THRESHOLD)
{
Priority -= priorityDecrease * deltaTime;
@@ -65,6 +64,7 @@ namespace Barotrauma
Priority = MathHelper.Clamp(Priority, 0, 100);
if (divingGearObjective != null && !divingGearObjective.IsCompleted() && divingGearObjective.CanBeCompleted)
{
// Boost the priority while seeking the diving gear
Priority = Math.Max(Priority, Math.Min(AIObjectiveManager.OrderPriority + 20, 100));
}
}
@@ -123,6 +123,10 @@ namespace Barotrauma
},
onAbandon: () => unreachable.Add(goToObjective.Target as Hull));
}
else
{
goToObjective = null;
}
}
if (goToObjective != null) { return; }
if (currentHull == null) { return; }
@@ -148,8 +152,8 @@ namespace Barotrauma
}
if (escapeVel != Vector2.Zero)
{
float left = HumanAIController.VisibleHulls.Min(h => h.Rect.X) + 50;
float right = HumanAIController.VisibleHulls.Max(h => h.Rect.Right) - 50;
float left = currentHull.Rect.X + 50;
float right = currentHull.Rect.Right - 50;
//only move if we haven't reached the edge of the room
if (escapeVel.X < 0 && character.Position.X > left || escapeVel.X > 0 && character.Position.X < right)
{
@@ -190,14 +194,14 @@ namespace Barotrauma
//skip the hull if the safety is already less than the best hull
//(no need to do the expensive pathfinding if we already know we're not going to choose this hull)
if (hullSafety < bestValue) { continue; }
// Each unsafe node reduces the hull safety value.
// Ignore current hull, because otherwise the would block all paths from the current hull to the target hull.
var path = PathSteering.PathFinder.FindPath(character.SimPosition, hull.SimPosition);
if (path.Unreachable)
{
unreachable.Add(hull);
continue;
}
// Each unsafe node reduces the hull safety value.
// Ignore the current hull, because otherwise we couldn't find a path out.
int unsafeNodes = path.Nodes.Count(n => n.CurrentHull != character.CurrentHull && HumanAIController.UnsafeHulls.Contains(n.CurrentHull));
hullSafety /= 1 + unsafeNodes;
// If the target is not inside a friendly submarine, considerably reduce the hull safety.
@@ -543,6 +543,32 @@ namespace Barotrauma
{
#if DEBUG
DebugConsole.ThrowError("AIObjectiveFixLeak failed - the item \"" + weldingTool + "\" has no RepairTool component but is tagged as a welding tool");
#endif
abandon = true;
return;
}
Vector2 gapDiff = Leak.WorldPosition - character.WorldPosition;
// TODO: use the collider size/reach?
if (!character.AnimController.InWater && Math.Abs(gapDiff.X) < 100 && gapDiff.Y < 0.0f && gapDiff.Y > -150)
{
HumanAIController.AnimController.Crouching = true;
}
float reach = ConvertUnits.ToSimUnits(repairTool.Range);
bool canOperate = ConvertUnits.ToSimUnits(gapDiff.Length()) < reach * 1.5f;
if (canOperate)
{
TryAddSubObjective(ref operateObjective, () => new AIObjectiveOperateItem(repairTool, character, objectiveManager, option: "", requireEquip: true, operateTarget: Leak));
}
else
{
TryAddSubObjective(ref gotoObjective, () => new AIObjectiveGoTo(ConvertUnits.ToSimUnits(GetStandPosition()), character, objectiveManager) { CloseEnough = reach * 0.75f });
}
if (subObjectives.Any()) { return; }
var repairTool = weldingTool.GetComponent<RepairTool>();
if (repairTool == null)
{
#if DEBUG
DebugConsole.ThrowError("AIObjectiveFixLeak failed - the item \"" + weldingTool + "\" has no RepairTool component but is tagged as a welding tool");
#endif
abandon = true;
return;
@@ -89,6 +89,21 @@ namespace Barotrauma
}
}
public override void Update(float deltaTime)
{
if (objectiveManager.CurrentObjective == this)
{
if (randomTimer > 0)
{
randomTimer -= deltaTime;
}
else
{
SetRandom();
}
}
}
public override bool IsCompleted() => false;
public override bool CanBeCompleted => true;
@@ -18,10 +18,26 @@ namespace Barotrauma
private Character character;
private float _waitTimer;
/// <summary>
/// When set above zero, the character will stand still doing nothing until the timer runs out. Does not affect orders.
/// When set above zero, the character will stand still doing nothing until the timer runs out. Does not affect orders, find safety or combat.
/// </summary>
public float WaitTimer;
public float WaitTimer
{
get { return _waitTimer; }
set
{
if (CurrentObjective is AIObjectiveCombat || CurrentObjective is AIObjectiveFindSafety)
{
_waitTimer = 0;
}
else
{
_waitTimer = value;
}
}
}
public AIObjective CurrentOrder { get; private set; }
public AIObjective CurrentObjective { get; private set; }
@@ -197,6 +213,7 @@ namespace Barotrauma
}
else
{
// Wait, if not swimming, climbing, or staying in a forbidden/unsafe hull.
if (character.AIController is HumanAIController humanAI && humanAI.SteeringManager != null)
{
if (!character.AnimController.InWater &&
@@ -861,6 +861,10 @@ namespace Barotrauma
{
isCompleted = true;
}
if (component.AIOperate(deltaTime, character, this))
{
isCompleted = true;
}
}
else
{
@@ -23,6 +23,12 @@ namespace Barotrauma
public AIObjectiveRescue(Character character, Character targetCharacter, AIObjectiveManager objectiveManager, float priorityModifier = 1)
: base(character, objectiveManager, priorityModifier)
{
if (targetCharacter != character)
{
// TODO: enable healing self too
abandon = true;
return;
}
this.targetCharacter = targetCharacter;
}
@@ -201,7 +207,7 @@ namespace Barotrauma
public override bool IsCompleted()
{
bool isCompleted = targetCharacter.Vitality / targetCharacter.MaxVitality > AIObjectiveRescueAll.GetVitalityThreshold(objectiveManager);
bool isCompleted = targetCharacter.Bleeding <= 0 && targetCharacter.Vitality / targetCharacter.MaxVitality > AIObjectiveRescueAll.GetVitalityThreshold(objectiveManager);
if (isCompleted)
{
character.Speak(TextManager.Get("DialogTargetHealed").Replace("[targetname]", targetCharacter.Name),
@@ -9,7 +9,7 @@ namespace Barotrauma
public override string DebugTag => "rescue all";
public override bool ForceRun => true;
private const float vitalityThreshold = 0.85f;
private const float vitalityThreshold = 0.8f;
private const float vitalityThresholdForOrders = 0.95f;
public static float GetVitalityThreshold(AIObjectiveManager manager) => manager.CurrentOrder is AIObjectiveRescueAll ? vitalityThresholdForOrders : vitalityThreshold;
@@ -35,10 +35,9 @@ namespace Barotrauma
public static bool IsValidTarget(Character target, Character character)
{
if (target == null || target.IsDead || target.Removed) { return false; }
if (target == character) { return false; } // TODO: enable healing self
if (!HumanAIController.IsFriendly(character, target)) { return false; }
if (!(character.AIController is HumanAIController humanAI)) { return false; }
if (target.Vitality / target.MaxVitality > GetVitalityThreshold(humanAI.ObjectiveManager)) { return false; }
if (target.Bleeding < 1 && target.Vitality / target.MaxVitality > GetVitalityThreshold(humanAI.ObjectiveManager)) { return false; }
if (target.Submarine == null) { return false; }
if (target.Submarine.TeamID != character.Submarine.TeamID) { return false; }
if (target.CurrentHull == null) { return false; }