use try
parent
f74b953983
commit
182e7c7234
|
@ -122,6 +122,7 @@ namespace OpenSim.Modules.PathFinding
|
|||
m_scriptModule.RegisterConstant("PATH_ENV_ERR_NOT_FOUND", 19851);
|
||||
m_scriptModule.RegisterConstant("PATH_ENV_ERR_OUT_OF_RANGE", 19852);
|
||||
m_scriptModule.RegisterConstant("PATH_ENV_ERR_NOT_IN_LINE", 19853);
|
||||
m_scriptModule.RegisterConstant("PATH_ENV_ERR_UNKNOWN", 19860);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
@ -144,150 +145,185 @@ namespace OpenSim.Modules.PathFinding
|
|||
|
||||
private void generatePathEnvironment(ScriptRequestData requestData)
|
||||
{
|
||||
UUID _envID = UUID.Random();
|
||||
Environment _newEnv = new Environment(_envID.ToString(), (int)m_scene.RegionInfo.RegionSizeX);
|
||||
|
||||
lock(m_environments)
|
||||
try
|
||||
{
|
||||
m_environments.Add(_newEnv);
|
||||
}
|
||||
UUID _envID = UUID.Random();
|
||||
Environment _newEnv = new Environment(_envID.ToString(), (int)m_scene.RegionInfo.RegionSizeX);
|
||||
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, _envID.ToString(), requestData.RequestID.ToString());
|
||||
lock (m_environments)
|
||||
{
|
||||
m_environments.Add(_newEnv);
|
||||
}
|
||||
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, _envID.ToString(), requestData.RequestID.ToString());
|
||||
}
|
||||
catch(Exception _error)
|
||||
{
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19860, _error.Message, requestData.RequestID.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void keepAlivePathEnv(ScriptRequestData requestData)
|
||||
{
|
||||
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||
|
||||
if(_env != null)
|
||||
try
|
||||
{
|
||||
_env.LastTimeUsed = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, "", requestData.RequestID.ToString());
|
||||
return;
|
||||
}
|
||||
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19851, "", requestData.RequestID.ToString());
|
||||
if (_env != null)
|
||||
{
|
||||
_env.LastTimeUsed = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, "", requestData.RequestID.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19851, "", requestData.RequestID.ToString());
|
||||
}
|
||||
catch (Exception _error)
|
||||
{
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19860, _error.Message, requestData.RequestID.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void removeAllTargets(ScriptRequestData requestData)
|
||||
{
|
||||
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||
|
||||
if (_env != null)
|
||||
try
|
||||
{
|
||||
List<PathNode> _nodes = _env.Nodes.FindAll(X => X.Target == true);
|
||||
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||
|
||||
foreach(PathNode thisNode in _nodes)
|
||||
if (_env != null)
|
||||
{
|
||||
thisNode.Target = false;
|
||||
List<PathNode> _nodes = _env.Nodes.FindAll(X => X.Target == true);
|
||||
|
||||
foreach (PathNode thisNode in _nodes)
|
||||
{
|
||||
thisNode.Target = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception _error)
|
||||
{
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19860, _error.Message, requestData.RequestID.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void setPositionData(ScriptRequestData requestData, Vector3 position, int walkable, int isTarget)
|
||||
{
|
||||
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||
|
||||
if (_env != null)
|
||||
try
|
||||
{
|
||||
if (isTarget == 1)
|
||||
removeAllTargets(requestData);
|
||||
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||
|
||||
PathNode _node = _env.Nodes.Find(X => X.PositionX == (int)position.X && X.PositionY == (int)position.Y);
|
||||
|
||||
if (_node == null)
|
||||
if (_env != null)
|
||||
{
|
||||
_node = new PathNode((int)position.X, (int)position.Y, false, false);
|
||||
_env.Nodes.Add(_node);
|
||||
if (isTarget == 1)
|
||||
removeAllTargets(requestData);
|
||||
|
||||
PathNode _node = _env.Nodes.Find(X => X.PositionX == (int)position.X && X.PositionY == (int)position.Y);
|
||||
|
||||
if (_node == null)
|
||||
{
|
||||
_node = new PathNode((int)position.X, (int)position.Y, false, false);
|
||||
_env.Nodes.Add(_node);
|
||||
}
|
||||
|
||||
if (walkable == 1)
|
||||
_node.Walkable = true;
|
||||
|
||||
if (walkable == 0)
|
||||
_node.Walkable = false;
|
||||
|
||||
if (isTarget == 1)
|
||||
_node.Target = true;
|
||||
|
||||
if (isTarget == 0)
|
||||
_node.Target = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (walkable == 1)
|
||||
_node.Walkable = true;
|
||||
|
||||
if (walkable == 0)
|
||||
_node.Walkable = false;
|
||||
|
||||
if (isTarget == 1)
|
||||
_node.Target = true;
|
||||
|
||||
if (isTarget == 0)
|
||||
_node.Target = false;
|
||||
|
||||
return;
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19851, "", requestData.RequestID.ToString());
|
||||
}
|
||||
catch (Exception _error)
|
||||
{
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19860, _error.Message, requestData.RequestID.ToString());
|
||||
}
|
||||
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19851, "", requestData.RequestID.ToString());
|
||||
}
|
||||
|
||||
private void setLineData(ScriptRequestData requestData, Vector3 start, Vector3 target, int walkable)
|
||||
{
|
||||
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||
|
||||
if (_env != null)
|
||||
try
|
||||
{
|
||||
if ((int)start.X == (int)target.X || (int)start.Y == (int)target.Y)
|
||||
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||
|
||||
if (_env != null)
|
||||
{
|
||||
if ((int)start.X == (int)target.X && (int)start.Y == (int)target.Y)
|
||||
if ((int)start.X == (int)target.X || (int)start.Y == (int)target.Y)
|
||||
{
|
||||
if ((int)start.X == (int)target.X && (int)start.Y == (int)target.Y)
|
||||
{
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, "", requestData.RequestID.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 _PointA = new Vector3(0, 0, 0);
|
||||
Vector3 _PointB = new Vector3(0, 0, 0);
|
||||
|
||||
if ((int)start.X != (int)target.X)
|
||||
{
|
||||
if ((int)start.X < (int)target.X)
|
||||
{
|
||||
_PointA = start;
|
||||
_PointB = target;
|
||||
}
|
||||
|
||||
if ((int)start.X > (int)target.X)
|
||||
{
|
||||
_PointA = target;
|
||||
_PointB = start;
|
||||
}
|
||||
|
||||
while ((int)_PointA.X != _PointB.X)
|
||||
{
|
||||
setPositionData(requestData, _PointA, walkable, 0);
|
||||
_PointA.X = (int)_PointA.X + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((int)start.Y != (int)target.Y)
|
||||
{
|
||||
if ((int)start.Y < (int)target.Y)
|
||||
{
|
||||
_PointA = start;
|
||||
_PointB = target;
|
||||
}
|
||||
|
||||
if ((int)start.Y > (int)target.Y)
|
||||
{
|
||||
_PointA = target;
|
||||
_PointB = start;
|
||||
}
|
||||
|
||||
while ((int)_PointA.Y != _PointB.Y)
|
||||
{
|
||||
setPositionData(requestData, _PointA, walkable, 0);
|
||||
_PointA.Y = (int)_PointA.Y + 1;
|
||||
}
|
||||
}
|
||||
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, "", requestData.RequestID.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 _PointA = new Vector3(0, 0, 0);
|
||||
Vector3 _PointB = new Vector3(0, 0, 0);
|
||||
|
||||
if ((int)start.X != (int)target.X)
|
||||
{
|
||||
if((int)start.X < (int)target.X)
|
||||
{
|
||||
_PointA = start;
|
||||
_PointB = target;
|
||||
}
|
||||
|
||||
if ((int)start.X > (int)target.X)
|
||||
{
|
||||
_PointA = target;
|
||||
_PointB = start;
|
||||
}
|
||||
|
||||
while ((int)_PointA.X != _PointB.X)
|
||||
{
|
||||
setPositionData(requestData, _PointA, walkable, 0);
|
||||
_PointA.X = (int)_PointA.X + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((int)start.Y != (int)target.Y)
|
||||
{
|
||||
if ((int)start.Y < (int)target.Y)
|
||||
{
|
||||
_PointA = start;
|
||||
_PointB = target;
|
||||
}
|
||||
|
||||
if ((int)start.Y > (int)target.Y)
|
||||
{
|
||||
_PointA = target;
|
||||
_PointB = start;
|
||||
}
|
||||
|
||||
while ((int)_PointA.Y != _PointB.Y)
|
||||
{
|
||||
setPositionData(requestData, _PointA, walkable, 0);
|
||||
_PointA.Y = (int)_PointA.Y + 1;
|
||||
}
|
||||
}
|
||||
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19850, "", requestData.RequestID.ToString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19851, "", requestData.RequestID.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19851, "", requestData.RequestID.ToString());
|
||||
}
|
||||
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19853, "", requestData.RequestID.ToString());
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19853, "", requestData.RequestID.ToString());
|
||||
}
|
||||
catch (Exception _error)
|
||||
{
|
||||
m_scriptModule.DispatchReply(requestData.ScriptID, 19860, _error.Message, requestData.RequestID.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void generatePath(ScriptRequestData requestData)
|
||||
|
|
Loading…
Reference in New Issue