- Replaced item name comparisons with Prefab.NameMatches (-> item names can be changed without breaking the AIs). - Having an AIObjective set as the current order of the character doesn't automatically cause it to have a high priority. For example, the order to fix leaks has a low priority if there are no leaks to fix. - AIObjectiveFixLeaks makes sure the character is wearing a diving suit before going to fix a leak. The characters used to run in and out of flooded rooms because the AIObjectiveFindSafety objective would become active as soon as the character entered the room, causing the character to run out, and then immediately run back because they are no longer in immediate danger of drowning, making the FixLeaks objective the most high-priority one. - Characters attempt to find a room with no water in AIObjectiveIdle even if the character is wearing a diving suit. - AIObjectiveFindSafety considers flooded rooms dangerous even if the character is wearing a diving suit (-> the character attempts to go into a more dry room instead of happily idling in the flooded one). - Distance to a hull doesn't decrease its desirability nearly as much in AIObjectiveFindSafety (-> fixes characters not bothering to move into a non-flooded room if it's far away). - AIObjectiveOperateItem makes sure the item is equipped before using it (-> characters can't weld leaks with the welder in their inventory).
76 lines
2.0 KiB
C#
76 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Barotrauma
|
|
{
|
|
abstract class AIObjective
|
|
{
|
|
protected readonly List<AIObjective> subObjectives;
|
|
protected float priority;
|
|
protected readonly Character character;
|
|
protected string option;
|
|
|
|
public virtual bool CanBeCompleted
|
|
{
|
|
get { return true; }
|
|
}
|
|
|
|
public string Option
|
|
{
|
|
get { return option; }
|
|
}
|
|
|
|
public AIObjective(Character character, string option)
|
|
{
|
|
subObjectives = new List<AIObjective>();
|
|
this.character = character;
|
|
this.option = option;
|
|
|
|
#if DEBUG
|
|
IsDuplicate(null);
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// makes the character act according to the objective, or according to any subobjectives that
|
|
/// need to be completed before this one
|
|
/// </summary>
|
|
public void TryComplete(float deltaTime)
|
|
{
|
|
subObjectives.RemoveAll(s => s.IsCompleted() || !s.CanBeCompleted);
|
|
|
|
foreach (AIObjective objective in subObjectives)
|
|
{
|
|
objective.TryComplete(deltaTime);
|
|
return;
|
|
}
|
|
|
|
Act(deltaTime);
|
|
}
|
|
|
|
public void AddSubObjective(AIObjective objective)
|
|
{
|
|
if (subObjectives.Any(o => o.IsDuplicate(objective))) return;
|
|
|
|
subObjectives.Add(objective);
|
|
}
|
|
|
|
public AIObjective GetCurrentSubObjective()
|
|
{
|
|
AIObjective currentSubObjective = this;
|
|
while (currentSubObjective.subObjectives.Count > 0)
|
|
{
|
|
currentSubObjective = subObjectives[0];
|
|
}
|
|
return currentSubObjective;
|
|
}
|
|
|
|
protected abstract void Act(float deltaTime);
|
|
|
|
public abstract bool IsCompleted();
|
|
public abstract float GetPriority(AIObjectiveManager objectiveManager);
|
|
public abstract bool IsDuplicate(AIObjective otherObjective);
|
|
}
|
|
}
|