Client LuaCsForBarotrauma
AIObjectiveExtinguishFires.cs
1 using System;
2 using System.Linq;
3 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 
7 namespace Barotrauma
8 {
10  {
11  public override Identifier Identifier { get; set; } = "extinguish fires".ToIdentifier();
12  public override bool ForceRun => true;
13  protected override bool AllowInAnySub => true;
14 
15  public AIObjectiveExtinguishFires(Character character, AIObjectiveManager objectiveManager, float priorityModifier = 1) : base(character, objectiveManager, priorityModifier) { }
16 
17  protected override bool IsValidTarget(Hull hull) => IsValidTarget(hull, character);
18 
19  protected override float GetTargetPriority() =>
20  // If any target is visible -> 100 priority
21  Targets.Any(t => t == character.CurrentHull || HumanAIController.VisibleHulls.Contains(t)) ? 100 :
22  // Else based on the fire severity
23  Targets.Sum(t => GetFireSeverity(t) * 100);
24 
28  public static float GetFireSeverity(Hull hull) => MathHelper.Lerp(0, 1, MathUtils.InverseLerp(0, 500, hull.FireSources.Sum(fs => fs.Size.X)));
29 
30  protected override IEnumerable<Hull> GetList() => Hull.HullList;
31 
32  protected override AIObjective ObjectiveConstructor(Hull target)
33  => new AIObjectiveExtinguishFire(character, target, objectiveManager, PriorityModifier);
34 
35  protected override void OnObjectiveCompleted(AIObjective objective, Hull target)
36  => HumanAIController.RemoveTargets<AIObjectiveExtinguishFires, Hull>(character, target);
37 
38  public static bool IsValidTarget(Hull hull, Character character)
39  {
40  if (hull == null) { return false; }
41  if (hull.FireSources.None()) { return false; }
42  if (hull.Submarine == null) { return false; }
43  if (character.Submarine == null) { return false; }
44  if (!character.Submarine.IsEntityFoundOnThisSub(hull, includingConnectedSubs: true)) { return false; }
45  if (hull.BallastFlora != null) { return false; }
46  foreach (var ballastFlora in MapCreatures.Behavior.BallastFloraBehavior.EntityList)
47  {
48  if (ballastFlora.Parent?.Submarine != character.Submarine) { continue; }
49  if (ballastFlora.Branches.Any(b => !b.Removed && b.Health > 0 && b.CurrentHull == hull))
50  {
51  return false;
52  }
53  }
54  return true;
55  }
56  }
57 }
IEnumerable< Hull > VisibleHulls
Returns hulls that are visible to the character, including the current hull. Note that this is not an...
override bool IsValidTarget(Hull hull)
override AIObjective ObjectiveConstructor(Hull target)
override void OnObjectiveCompleted(AIObjective objective, Hull target)
override IEnumerable< Hull > GetList()
List of all possible items of the specified type. Used for filtering the removed objectives.
AIObjectiveExtinguishFires(Character character, AIObjectiveManager objectiveManager, float priorityModifier=1)
override float GetTargetPriority()
Returns a priority value based on the current targets (e.g. high prio when there's lots of severe fir...
static float GetFireSeverity(Hull hull)
0-1 based on the horizontal size of all of the fires in the hull.
static bool IsValidTarget(Hull hull, Character character)
An objective that creates specific kinds of subobjectives for specific types of targets,...
Submarine Submarine
Definition: Entity.cs:53
static readonly List< Hull > HullList
bool IsEntityFoundOnThisSub(MapEntity entity, bool includingConnectedSubs, bool allowDifferentTeam=false, bool allowDifferentType=false)