Human AI improvements & fixes:

- 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).
This commit is contained in:
Joonas Rikkonen
2017-12-21 19:49:26 +02:00
parent 9ed2871ede
commit 604fc65154
17 changed files with 310 additions and 169 deletions
@@ -11,15 +11,17 @@ namespace Barotrauma
private Character character;
private AIObjective currentObjective;
private AIObjective currentOrder;
public AIObjective CurrentOrder
{
get { return currentOrder; }
}
public AIObjective CurrentObjective
{
get
{
if (currentObjective != null) return currentObjective;
return objectives.Any() ? objectives[0] : null;
}
get;
private set;
}
public AIObjectiveManager(Character character)
@@ -47,8 +49,13 @@ namespace Barotrauma
public float GetCurrentPriority(Character character)
{
if (currentObjective != null) return OrderPriority;
return (CurrentObjective == null) ? 0.0f : CurrentObjective.GetPriority(character);
if (CurrentOrder != null &&
(objectives.Count == 0 || currentOrder.GetPriority(this) > objectives[0].GetPriority(this)))
{
return CurrentOrder.GetPriority(this);
}
return objectives.Count == 0 ? 0.0f : objectives[0].GetPriority(this);
}
public void UpdateObjectives()
@@ -59,43 +66,46 @@ namespace Barotrauma
objectives = objectives.FindAll(o => !o.IsCompleted() && o.CanBeCompleted);
//sort objectives according to priority
objectives.Sort((x, y) => y.GetPriority(character).CompareTo(x.GetPriority(character)));
objectives.Sort((x, y) => y.GetPriority(this).CompareTo(x.GetPriority(this)));
}
public void DoCurrentObjective(float deltaTime)
{
if (currentObjective != null && (!objectives.Any() || objectives[0].GetPriority(character) < OrderPriority))
if (currentOrder != null && (!objectives.Any() || objectives[0].GetPriority(this) < currentOrder.GetPriority(this)))
{
currentObjective.TryComplete(deltaTime);
CurrentObjective = currentOrder;
currentOrder.TryComplete(deltaTime);
return;
}
if (!objectives.Any()) return;
objectives[0].TryComplete(deltaTime);
CurrentObjective = objectives[0];
}
public void SetOrder(Order order, string option)
{
if (order == null) return;
currentObjective = null;
currentOrder = null;
switch (order.Name.ToLowerInvariant())
{
case "follow":
currentObjective = new AIObjectiveGoTo(Character.Controlled, character, true);
currentOrder = new AIObjectiveGoTo(Character.Controlled, character, true);
break;
case "wait":
currentObjective = new AIObjectiveGoTo(character, character, true);
currentOrder = new AIObjectiveGoTo(character, character, true);
break;
case "fixleaks":
case "fix leaks":
currentObjective = new AIObjectiveFixLeaks(character);
currentOrder = new AIObjectiveFixLeaks(character);
break;
default:
if (order.TargetItem == null) return;
currentObjective = new AIObjectiveOperateItem(order.TargetItem, character, option, null, order.UseController);
currentOrder = new AIObjectiveOperateItem(order.TargetItem, character, option, false, null, order.UseController);
break;
}