(1ac786058) AIObjectiveRescueAll now inherits AIObjectiveLoop. Implement reporting on rescue targets. Fix reporting not checking that the targets were in the current hull.
This commit is contained in:
+27
-45
@@ -1,67 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Barotrauma.Extensions;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
// TODO: Refactor using AIObjectiveLoop class.
|
||||
class AIObjectiveRescueAll : AIObjective
|
||||
class AIObjectiveRescueAll : AIObjectiveLoop<Character>
|
||||
{
|
||||
public override string DebugTag => "rescue all";
|
||||
|
||||
//only treat characters whose vitality is below this (0.8 = 80% of max vitality)
|
||||
public const float VitalityThreshold = 0.8f;
|
||||
|
||||
private List<Character> rescueTargets;
|
||||
|
||||
public AIObjectiveRescueAll(Character character, AIObjectiveManager objectiveManager, float priorityModifier = 1) : base(character, objectiveManager, priorityModifier)
|
||||
public AIObjectiveRescueAll(Character character, AIObjectiveManager objectiveManager, float priorityModifier = 1)
|
||||
: base(character, objectiveManager, priorityModifier) { }
|
||||
|
||||
public override bool IsDuplicate(AIObjective otherObjective) => otherObjective is AIObjectiveRescueAll;
|
||||
|
||||
protected override void FindTargets()
|
||||
{
|
||||
rescueTargets = new List<Character>();
|
||||
base.FindTargets();
|
||||
if (targets.None() && objectiveManager.CurrentOrder == this)
|
||||
{
|
||||
character.Speak(TextManager.Get("DialogNoRescueTargets"), null, 3.0f, "norescuetargets", 30.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsDuplicate(AIObjective otherObjective)
|
||||
protected override bool Filter(Character target)
|
||||
{
|
||||
if (target == null || target.IsDead || target.Removed) { return false; }
|
||||
if (target == character) { return false; }
|
||||
if (target.Submarine != character.Submarine) { return false; }
|
||||
if (target.CurrentHull == null && character.Submarine != null) { return false; }
|
||||
if (target.Vitality / target.MaxVitality > VitalityThreshold) { return false; }
|
||||
if (HumanAIController == null || !HumanAIController.IsFriendly(target)) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
public override float GetPriority()
|
||||
protected override IEnumerable<Character> GetList() => Character.CharacterList;
|
||||
|
||||
protected override AIObjective ObjectiveConstructor(Character target) => new AIObjectiveRescue(character, target, objectiveManager, PriorityModifier);
|
||||
|
||||
protected override float TargetEvaluation()
|
||||
{
|
||||
// TODO: review
|
||||
if (character.Submarine == null) { return 0; }
|
||||
GetRescueTargets();
|
||||
if (!rescueTargets.Any()) { return 0.0f; }
|
||||
|
||||
if (objectiveManager.CurrentOrder == this)
|
||||
{
|
||||
return AIObjectiveManager.OrderPriority;
|
||||
}
|
||||
|
||||
//if there are targets to rescue, the priority is slightly less
|
||||
//than the priority of explicit orders given to the character
|
||||
return AIObjectiveManager.OrderPriority - 5.0f;
|
||||
// TODO: sorting criteria
|
||||
return 100;
|
||||
}
|
||||
|
||||
private void GetRescueTargets()
|
||||
{
|
||||
rescueTargets = Character.CharacterList.FindAll(c =>
|
||||
c.AIController is HumanAIController &&
|
||||
c.TeamID == character.TeamID &&
|
||||
c != character &&
|
||||
!c.IsDead &&
|
||||
HumanAIController.IsFriendly(c) &&
|
||||
c.Vitality / c.MaxVitality < VitalityThreshold);
|
||||
}
|
||||
|
||||
protected override void Act(float deltaTime)
|
||||
{
|
||||
foreach (Character target in rescueTargets)
|
||||
{
|
||||
AddSubObjective(new AIObjectiveRescue(character, target, objectiveManager));
|
||||
}
|
||||
}
|
||||
|
||||
public override bool IsCompleted() => false;
|
||||
public override bool CanBeCompleted => true;
|
||||
|
||||
public override bool IsLoop { get => true; set => throw new System.Exception("Trying to set the value for IsLoop from: " + System.Environment.StackTrace); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user