Autopilot can avoid other subs, characters won't go outside in idle state
This commit is contained in:
@@ -33,12 +33,6 @@ namespace Barotrauma
|
|||||||
get { return currentTarget; }
|
get { return currentTarget; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasOutdoorsNodes
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
private set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IndoorsSteeringManager(ISteerable host, bool canOpenDoors)
|
public IndoorsSteeringManager(ISteerable host, bool canOpenDoors)
|
||||||
: base(host)
|
: base(host)
|
||||||
{
|
{
|
||||||
@@ -87,8 +81,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
currentPath = pathFinder.FindPath(pos, target);
|
currentPath = pathFinder.FindPath(pos, target);
|
||||||
|
|
||||||
HasOutdoorsNodes = currentPath.Nodes.Find(n => n.CurrentHull == null) != null;
|
|
||||||
|
|
||||||
findPathTimer = Rand.Range(1.0f,1.2f);
|
findPathTimer = Rand.Range(1.0f,1.2f);
|
||||||
|
|
||||||
return DiffToCurrentNode();
|
return DiffToCurrentNode();
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
indoorsSteering.SteeringWander();
|
indoorsSteering.SteeringWander();
|
||||||
}
|
}
|
||||||
else if (getDivingGearIfNeeded && indoorsSteering.CurrentPath != null && indoorsSteering.HasOutdoorsNodes)
|
else if (getDivingGearIfNeeded && indoorsSteering.CurrentPath != null && indoorsSteering.CurrentPath.HasOutdoorsNodes)
|
||||||
{
|
{
|
||||||
AddSubObjective(new AIObjectiveFindDivingGear(character, true));
|
AddSubObjective(new AIObjectiveFindDivingGear(character, true));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,9 +54,12 @@ namespace Barotrauma
|
|||||||
newTargetTimer -= deltaTime;
|
newTargetTimer -= deltaTime;
|
||||||
|
|
||||||
|
|
||||||
//wander randomly if reached the end of the path or the target is unreachable
|
//wander randomly
|
||||||
|
// - if reached the end of the path
|
||||||
|
// - if the target is unreachable
|
||||||
|
// - if the path requires going outside
|
||||||
if (pathSteering==null || (pathSteering.CurrentPath != null &&
|
if (pathSteering==null || (pathSteering.CurrentPath != null &&
|
||||||
(pathSteering.CurrentPath.NextNode == null || pathSteering.CurrentPath.Unreachable)))
|
(pathSteering.CurrentPath.NextNode == null || pathSteering.CurrentPath.Unreachable || pathSteering.CurrentPath.HasOutdoorsNodes)))
|
||||||
{
|
{
|
||||||
//steer away from edges of the hull
|
//steer away from edges of the hull
|
||||||
if (character.AnimController.CurrentHull!=null)
|
if (character.AnimController.CurrentHull!=null)
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
if (node == null) return;
|
if (node == null) return;
|
||||||
nodes.Add(node);
|
nodes.Add(node);
|
||||||
|
|
||||||
|
if (node.CurrentHull == null) HasOutdoorsNodes = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasOutdoorsNodes
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CurrentIndex
|
public int CurrentIndex
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ namespace Barotrauma.Tutorials
|
|||||||
infoBox = CreateInfoFrame("The green rectangle in the middle is the submarine, and the flickering shapes outside it are the walls of an underwater cavern. "
|
infoBox = CreateInfoFrame("The green rectangle in the middle is the submarine, and the flickering shapes outside it are the walls of an underwater cavern. "
|
||||||
+ "Try moving the submarine by clicking somewhere on the monitor and dragging the pointer to the direction you want to go to.");
|
+ "Try moving the submarine by clicking somewhere on the monitor and dragging the pointer to the direction you want to go to.");
|
||||||
|
|
||||||
while (steering.CurrTargetVelocity == Vector2.Zero && steering.CurrTargetVelocity.Length() < 50.0f)
|
while (steering.TargetVelocity == Vector2.Zero && steering.TargetVelocity.Length() < 50.0f)
|
||||||
{
|
{
|
||||||
yield return CoroutineStatus.Running;
|
yield return CoroutineStatus.Running;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector2 TargetVelocity
|
public Vector2 TargetVelocity
|
||||||
{
|
{
|
||||||
get { return targetVelocity;}
|
get { return targetVelocity;}
|
||||||
set
|
set
|
||||||
@@ -92,11 +92,6 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2 CurrTargetVelocity
|
|
||||||
{
|
|
||||||
get { return targetVelocity; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public SteeringPath SteeringPath
|
public SteeringPath SteeringPath
|
||||||
{
|
{
|
||||||
get { return steeringPath; }
|
get { return steeringPath; }
|
||||||
@@ -259,6 +254,25 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
SteerTowardsPosition(steeringPath.CurrentNode.WorldPosition);
|
SteerTowardsPosition(steeringPath.CurrentNode.WorldPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (Submarine sub in Submarine.Loaded)
|
||||||
|
{
|
||||||
|
if (sub == item.Submarine) continue;
|
||||||
|
|
||||||
|
float thisSize = Math.Max(item.Submarine.Borders.Width, item.Submarine.Borders.Height);
|
||||||
|
float otherSize = Math.Max(sub.Borders.Width, sub.Borders.Height);
|
||||||
|
|
||||||
|
Vector2 diff = sub.WorldPosition - item.Submarine.WorldPosition;
|
||||||
|
|
||||||
|
float dist = diff == Vector2.Zero ? 0.0f : diff.Length();
|
||||||
|
|
||||||
|
if (dist > thisSize + otherSize) continue;
|
||||||
|
|
||||||
|
diff = Vector2.Normalize(diff);
|
||||||
|
|
||||||
|
TargetVelocity = Vector2.Lerp(-diff * 100.0f, TargetVelocity, (dist / (thisSize + otherSize)) - 0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SteerTowardsPosition(Vector2 worldPosition)
|
private void SteerTowardsPosition(Vector2 worldPosition)
|
||||||
@@ -275,7 +289,7 @@ namespace Barotrauma.Items.Components
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
targetVelocity = targetSpeed/5.0f;
|
TargetVelocity = targetSpeed/5.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user