2 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
13 private bool usingEscapeBehavior, isSteeringThroughGap;
23 DebugConsole.AddSafeError(
"Error with a Return objective: no suitable return target found");
27 Submarine GetReturnTarget(IEnumerable<Submarine> subs)
31 foreach (var sub
in subs)
33 if (sub ==
null) {
continue; }
34 if (sub.TeamID != requiredTeamID) {
continue; }
55 protected override void Act(
float deltaTime)
62 bool shouldUseEscapeBehavior =
false;
68 shouldUseEscapeBehavior =
true;
69 if (!usingEscapeBehavior)
82 if (moveInsideObjective ==
null)
84 Hull targetHull =
null;
87 if (!d.Docked) {
continue; }
88 if (d.DockingTarget ==
null) {
continue; }
90 targetHull = d.Item.CurrentHull;
93 if (targetHull !=
null && !targetHull.IsAirlock)
96 float closestDist = 0;
102 float dist = Vector2.DistanceSquared(targetHull.Position, hull.
Position);
103 if (airlock ==
null || closestDist <= 0 || dist < closestDist)
112 targetHull = airlock;
115 if (targetHull !=
null)
117 RemoveSubObjective(ref moveOutsideObjective);
118 TryAddSubObjective(ref moveInsideObjective,
121 AllowGoingOutside =
true,
122 endNodeFilter = n => n.Waypoint.Submarine == targetHull.Submarine
124 onCompleted: () => RemoveSubObjective(ref moveInsideObjective),
125 onAbandon: () =>
Abandon =
true);
130 DebugConsole.ThrowError(
"Error with a Return objective: no suitable target for 'moveInsideObjective'");
141 else if (!isSteeringThroughGap && moveOutsideObjective ==
null)
143 Hull targetHull =
null;
144 float targetDistanceSquared =
float.MaxValue;
145 bool targetIsAirlock =
false;
149 if(hullIsAirlock || (!targetIsAirlock && hull.LeadsOutside(
character)))
152 if (targetHull ==
null || distanceSquared < targetDistanceSquared)
155 targetDistanceSquared = distanceSquared;
156 targetIsAirlock = hullIsAirlock;
160 if (targetHull !=
null)
162 RemoveSubObjective(ref moveInsideObjective);
163 TryAddSubObjective(ref moveOutsideObjective,
166 AllowGoingOutside =
true
168 onCompleted: () => RemoveSubObjective(ref moveOutsideObjective),
169 onAbandon: () =>
Abandon =
true);
174 DebugConsole.ThrowError(
"Error with a Return objective: no suitable target for 'moveOutsideObjective'");
178 usingEscapeBehavior = shouldUseEscapeBehavior;
202 moveInsideObjective =
null;
203 moveOutsideObjective =
null;
204 usingEscapeBehavior =
false;
205 isSteeringThroughGap =
false;
215 string msg = TextManager.Get(
"dialogcannotreturn").Value;
216 if (!msg.IsNullOrEmpty())
218 character.
Speak(msg, identifier:
"dialogcannotreturn".ToIdentifier(), minDurationBetweenSimilar: 5.0f);
bool IsCurrentPathUnreachable
float Priority
Final priority value after all calculations.
readonly Character character
readonly AIObjectiveManager objectiveManager
const float LowestOrderPriority
Maximum priority of an order given to the character (rightmost order in the crew list)
AIObjective CurrentObjective
Includes orders.
AIObjective?? CurrentOrder
The AIObjective in CurrentOrders with the highest AIObjective.Priority
float GetOrderPriority(AIObjective objective)
bool IsOrder(AIObjective objective)
override float GetPriority()
override bool AllowOutsideSubmarine
override bool AllowInAnySub
override void OnAbandon()
override bool CheckObjectiveSpecific()
Should return whether the objective is completed or not.
AIObjectiveReturn(Character character, Character orderGiver, AIObjectiveManager objectiveManager, float priorityModifier=1.0f)
override void Act(float deltaTime)
override Identifier Identifier
void Speak(string message, ChatMessageType? messageType=null, float delay=0.0f, Identifier identifier=default, float minDurationBetweenSimilar=0.0f)
virtual Vector2 WorldPosition
static readonly List< Hull > HullList
override bool Escape(float deltaTime)
override Vector2 Position
readonly Dictionary< Submarine, DockingPort > ConnectedDockingPorts
Submarine(SubmarineInfo info, bool showErrorMessages=true, Func< Submarine, List< MapEntity >> loadEntities=null, IdRemap linkedRemap=null)
static readonly Submarine[] MainSubs
static List< Submarine > Loaded
bool IsConnectedTo(Submarine otherSub)
Returns true if the sub is same as the other, or connected to it via docking ports.
List< Hull > GetHulls(bool alsoFromConnectedSubs)