- doors aren't ignored when checking visibility during waypoint generation or when finding a starting node for a path

- AICharacter will mark their path unreachable if their path is blocked by a door they cant open (may happen if someone closes the door after calculating the path)
- fixed exception when creating a Steering component when there's no active GameSession (i.e. in the editor)
This commit is contained in:
Regalis
2016-10-27 21:18:45 +03:00
parent 81ed90abf4
commit 48c07cfce5
6 changed files with 36 additions and 14 deletions
@@ -185,6 +185,11 @@ namespace Barotrauma
new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y), new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y),
new Vector2(pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.Y), new Vector2(pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i - 1].DrawPosition.Y),
Color.LightGreen); Color.LightGreen);
spriteBatch.DrawString(GUI.SmallFont,
pathSteering.CurrentPath.Nodes[i].ID.ToString(),
new Vector2(pathSteering.CurrentPath.Nodes[i].DrawPosition.X, -pathSteering.CurrentPath.Nodes[i].DrawPosition.Y - 10),
Color.LightGreen);
} }
} }
} }
@@ -258,6 +258,12 @@ namespace Barotrauma
if (closestButton != null) if (closestButton != null)
{ {
if (!closestButton.HasRequiredItems(character, false) && shouldBeOpen)
{
currentPath.Unreachable = true;
return;
}
closestButton.Item.Pick(character, false, true); closestButton.Item.Pick(character, false, true);
break; break;
} }
@@ -172,7 +172,12 @@ namespace Barotrauma
start, node.Waypoint.SimPosition, null, start, node.Waypoint.SimPosition, null,
Physics.CollisionWall | Physics.CollisionLevel | Physics.CollisionStairs | Physics.CollisionPlatform); Physics.CollisionWall | Physics.CollisionLevel | Physics.CollisionStairs | Physics.CollisionPlatform);
if (body != null && body.UserData is Structure && !((Structure)body.UserData).IsPlatform) continue; if (body != null)
{
if (body.UserData is Structure && !((Structure)body.UserData).IsPlatform) continue;
if (body.UserData is Item && body.FixtureList[0].CollisionCategories.HasFlag(Physics.CollisionWall)) continue;
}
} }
closestDist = dist; closestDist = dist;
@@ -123,14 +123,14 @@ namespace Barotrauma.Items.Components
levelStartTickBox = new GUITickBox( levelStartTickBox = new GUITickBox(
new Rectangle(5, 70, 15, 15), new Rectangle(5, 70, 15, 15),
ToolBox.LimitString(GameMain.GameSession.StartLocation.Name, 20), GameMain.GameSession == null ? "" : ToolBox.LimitString(GameMain.GameSession.StartLocation.Name, 20),
Alignment.TopLeft, GUI.SmallFont, GuiFrame); Alignment.TopLeft, GUI.SmallFont, GuiFrame);
levelStartTickBox.Enabled = false; levelStartTickBox.Enabled = false;
levelStartTickBox.OnSelected = SelectDestination; levelStartTickBox.OnSelected = SelectDestination;
levelEndTickBox = new GUITickBox( levelEndTickBox = new GUITickBox(
new Rectangle(5, 90, 15, 15), new Rectangle(5, 90, 15, 15),
ToolBox.LimitString(GameMain.GameSession.EndLocation.Name, 20), GameMain.GameSession == null ? "" : ToolBox.LimitString(GameMain.GameSession.StartLocation.Name, 20),
Alignment.TopLeft, GUI.SmallFont, GuiFrame); Alignment.TopLeft, GUI.SmallFont, GuiFrame);
levelEndTickBox.Enabled = false; levelEndTickBox.Enabled = false;
levelEndTickBox.OnSelected = SelectDestination; levelEndTickBox.OnSelected = SelectDestination;
+16 -10
View File
@@ -437,11 +437,11 @@ namespace Barotrauma
WayPoint[] stairPoints = new WayPoint[2]; WayPoint[] stairPoints = new WayPoint[2];
stairPoints[0] = new WayPoint( stairPoints[0] = new WayPoint(
new Vector2(stairs.Rect.X - 75.0f, new Vector2(stairs.Rect.X - 32.0f,
stairs.Rect.Y - (stairs.StairDirection == Direction.Left ? 80 : stairs.Rect.Height) + heightFromFloor), SpawnType.Path, submarine); stairs.Rect.Y - (stairs.StairDirection == Direction.Left ? 80 : stairs.Rect.Height) + heightFromFloor), SpawnType.Path, submarine);
stairPoints[1] = new WayPoint( stairPoints[1] = new WayPoint(
new Vector2(stairs.Rect.Right + 75.0f, new Vector2(stairs.Rect.Right + 32.0f,
stairs.Rect.Y - (stairs.StairDirection == Direction.Left ? stairs.Rect.Height : 80) + heightFromFloor), SpawnType.Path, submarine); stairs.Rect.Y - (stairs.StairDirection == Direction.Left ? stairs.Rect.Height : 80) + heightFromFloor), SpawnType.Path, submarine);
for (int i = 0; i < 2; i++ ) for (int i = 0; i < 2; i++ )
@@ -536,11 +536,11 @@ namespace Barotrauma
//ladderPoints[0].ConnectTo(ladderPoints[1]); //ladderPoints[0].ConnectTo(ladderPoints[1]);
} }
foreach (Gap gap in Gap.GapList) foreach (Gap gap in Gap.GapList)
{ {
if (!gap.isHorizontal) continue; if (!gap.isHorizontal) continue;
//too small to walk through //too small to walk through
if (gap.Rect.Height < 150.0f) continue; if (gap.Rect.Height < 150.0f) continue;
@@ -550,9 +550,15 @@ namespace Barotrauma
for (int dir = -1; dir <= 1; dir += 2) for (int dir = -1; dir <= 1; dir += 2)
{ {
float tolerance = gap.IsRoomToRoom ? 50.0f : outSideWaypointInterval / 2.0f; float tolerance = gap.IsRoomToRoom ? 50.0f : outSideWaypointInterval / 2.0f;
WayPoint closest = wayPoint.FindClosest(dir, true, new Vector2(-tolerance, tolerance));
if (closest == null) continue; WayPoint closest = wayPoint.FindClosest(
wayPoint.ConnectTo(closest); dir, true, new Vector2(-tolerance, tolerance),
gap.ConnectedDoor == null ? null : gap.ConnectedDoor.Body.FarseerBody);
if (closest != null)
{
wayPoint.ConnectTo(closest);
}
} }
} }
@@ -582,7 +588,7 @@ namespace Barotrauma
} }
} }
private WayPoint FindClosest(int dir, bool horizontalSearch, Vector2 tolerance) private WayPoint FindClosest(int dir, bool horizontalSearch, Vector2 tolerance, Body ignoredBody = null)
{ {
if (dir != -1 && dir != 1) return null; if (dir != -1 && dir != 1) return null;
@@ -614,9 +620,9 @@ namespace Barotrauma
if (closest == null || dist < closestDist) if (closest == null || dist < closestDist)
{ {
var body = Submarine.CheckVisibility(SimPosition, wp.SimPosition, true); var body = Submarine.CheckVisibility(SimPosition, wp.SimPosition, true);
if (body != null) if (body != null && body != ignoredBody && !(body.UserData is Submarine))
{ {
if (body.UserData is Structure) continue; if (body.UserData is Structure || body.FixtureList[0].CollisionCategories.HasFlag(Physics.CollisionWall)) continue;
} }
closestDist = dist; closestDist = dist;
+1 -1
View File
@@ -231,7 +231,7 @@ namespace Barotrauma
public PhysicsBody(Body farseerBody) public PhysicsBody(Body farseerBody)
{ {
body = farseerBody; body = farseerBody;
body.UserData = this; if (body.UserData == null) body.UserData = this;
LastSentPosition = body.Position; LastSentPosition = body.Position;