add try
parent
4ac5da4ee2
commit
d3d8eb1d45
|
@ -320,66 +320,72 @@ namespace OpenSim.Modules.PathFinding
|
||||||
|
|
||||||
private void generatePath(ScriptRequestData requestData)
|
private void generatePath(ScriptRequestData requestData)
|
||||||
{
|
{
|
||||||
lock (m_environments)
|
try
|
||||||
{
|
{
|
||||||
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
lock (m_environments)
|
||||||
|
|
||||||
if(_env.Start != null && _env.Target != null)
|
|
||||||
{
|
{
|
||||||
if(_env.Start.PositionX == _env.Target.PositionX && _env.Start.PositionY == _env.Target.PositionY)
|
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, "", requestData.RequestID.ToString());
|
|
||||||
|
|
||||||
GridSize _pathFindingGridSize = new GridSize(_env.Size, _env.Size);
|
if (_env.Start != null && _env.Target != null)
|
||||||
Roy_T.AStar.Primitives.Size _pathFindingCellSize = new Roy_T.AStar.Primitives.Size(Distance.FromMeters(1), Distance.FromMeters(1));
|
|
||||||
Velocity _pathFindingVelocity = Velocity.FromKilometersPerHour(11.5f);
|
|
||||||
|
|
||||||
Grid _pathFindingGrid = Grid.CreateGridWithLateralAndDiagonalConnections(_pathFindingGridSize, _pathFindingCellSize, _pathFindingVelocity);
|
|
||||||
|
|
||||||
foreach(INode _thisNode in _pathFindingGrid.GetAllNodes())
|
|
||||||
{
|
{
|
||||||
PathNode _node = _env.Nodes.Find(X => X.PositionX == (int)_thisNode.Position.X && X.PositionY == (int)_thisNode.Position.Y);
|
if (_env.Start.PositionX == _env.Target.PositionX && _env.Start.PositionY == _env.Target.PositionY)
|
||||||
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, "", requestData.RequestID.ToString());
|
||||||
|
|
||||||
if(_node == null)
|
GridSize _pathFindingGridSize = new GridSize(_env.Size, _env.Size);
|
||||||
|
Roy_T.AStar.Primitives.Size _pathFindingCellSize = new Roy_T.AStar.Primitives.Size(Distance.FromMeters(1), Distance.FromMeters(1));
|
||||||
|
Velocity _pathFindingVelocity = Velocity.FromKilometersPerHour(11.5f);
|
||||||
|
|
||||||
|
Grid _pathFindingGrid = Grid.CreateGridWithLateralAndDiagonalConnections(_pathFindingGridSize, _pathFindingCellSize, _pathFindingVelocity);
|
||||||
|
|
||||||
|
foreach (INode _thisNode in _pathFindingGrid.GetAllNodes())
|
||||||
{
|
{
|
||||||
_pathFindingGrid.DisconnectNode(new GridPosition((int)_thisNode.Position.X, (int)_thisNode.Position.Y));
|
PathNode _node = _env.Nodes.Find(X => X.PositionX == (int)_thisNode.Position.X && X.PositionY == (int)_thisNode.Position.Y);
|
||||||
_pathFindingGrid.RemoveDiagonalConnectionsIntersectingWithNode(new GridPosition((int)_thisNode.Position.X, (int)_thisNode.Position.Y));
|
|
||||||
|
if (_node == null)
|
||||||
|
{
|
||||||
|
_pathFindingGrid.DisconnectNode(new GridPosition((int)_thisNode.Position.X, (int)_thisNode.Position.Y));
|
||||||
|
_pathFindingGrid.RemoveDiagonalConnectionsIntersectingWithNode(new GridPosition((int)_thisNode.Position.X, (int)_thisNode.Position.Y));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
PathFinder pathFinder = new PathFinder();
|
PathFinder pathFinder = new PathFinder();
|
||||||
Path _pathFindingPath = pathFinder.FindPath(new GridPosition(_env.Start.PositionX, _env.Start.PositionY), new GridPosition(_env.Target.PositionX, _env.Target.PositionY), _pathFindingGrid);
|
Path _pathFindingPath = pathFinder.FindPath(new GridPosition(_env.Start.PositionX, _env.Start.PositionY), new GridPosition(_env.Target.PositionX, _env.Target.PositionY), _pathFindingGrid);
|
||||||
|
|
||||||
String _pathString = "";
|
String _pathString = "";
|
||||||
int lastX = 0;
|
int lastX = 0;
|
||||||
int lastY = 0;
|
int lastY = 0;
|
||||||
|
|
||||||
foreach (var _thisEdge in _pathFindingPath.Edges)
|
foreach (var _thisEdge in _pathFindingPath.Edges)
|
||||||
{
|
|
||||||
if(lastX != (int)_thisEdge.End.Position.X && lastY != (int)_thisEdge.End.Position.Y)
|
|
||||||
{
|
{
|
||||||
_pathString += "<" + _thisEdge.End.Position.X + ", " + _thisEdge.End.Position.Y + ", 0>;";
|
if (lastX != (int)_thisEdge.End.Position.X && lastY != (int)_thisEdge.End.Position.Y)
|
||||||
|
{
|
||||||
|
_pathString += "<" + _thisEdge.End.Position.X + ", " + _thisEdge.End.Position.Y + ", 0>;";
|
||||||
|
|
||||||
lastX = (int)_thisEdge.End.Position.X;
|
lastX = (int)_thisEdge.End.Position.X;
|
||||||
lastY = (int)_thisEdge.End.Position.Y;
|
lastY = (int)_thisEdge.End.Position.Y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_pathString += "<" + _pathFindingPath.Edges[_pathFindingPath.Edges.Count-1].End.Position.X + ", " + _pathFindingPath.Edges[_pathFindingPath.Edges.Count - 1].End.Position.Y + ", 0>;";
|
_pathString += "<" + _pathFindingPath.Edges[_pathFindingPath.Edges.Count - 1].End.Position.X + ", " + _pathFindingPath.Edges[_pathFindingPath.Edges.Count - 1].End.Position.Y + ", 0>;";
|
||||||
|
|
||||||
|
|
||||||
if (_pathFindingPath.Type == PathType.Complete)
|
if (_pathFindingPath.Type == PathType.Complete)
|
||||||
{
|
{
|
||||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, _pathString, requestData.RequestID.ToString());
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, _pathString, requestData.RequestID.ToString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19855, _pathString, requestData.RequestID.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19855, _pathString, requestData.RequestID.ToString());
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19854, "", requestData.RequestID.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}catch(Exception _error)
|
||||||
{
|
{
|
||||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19854, "", requestData.RequestID.ToString());
|
m_scriptModule.DispatchReply(requestData.ScriptID, 19860, _error.Message, requestData.RequestID.ToString());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue