Reinstate option to land an npc when it reaches a target.
This is moved into ScenePresence for now as a general facilityremove-scene-viewer
parent
241e07d006
commit
d358125cac
|
@ -169,7 +169,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory.Tests
|
||||||
float y = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Y]);
|
float y = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Y]);
|
||||||
float z = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Z]);
|
float z = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Z]);
|
||||||
Vector3 vector = new Vector3(x, y, z);
|
Vector3 vector = new Vector3(x, y, z);
|
||||||
presence.MoveToTarget(vector, false);
|
presence.MoveToTarget(vector, false, false);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -935,7 +935,7 @@ namespace OpenSim.Framework
|
||||||
event ScriptReset OnScriptReset;
|
event ScriptReset OnScriptReset;
|
||||||
event GetScriptRunning OnGetScriptRunning;
|
event GetScriptRunning OnGetScriptRunning;
|
||||||
event SetScriptRunning OnSetScriptRunning;
|
event SetScriptRunning OnSetScriptRunning;
|
||||||
event Action<Vector3, bool> OnAutoPilotGo;
|
event Action<Vector3, bool, bool> OnAutoPilotGo;
|
||||||
|
|
||||||
event TerrainUnacked OnUnackedTerrain;
|
event TerrainUnacked OnUnackedTerrain;
|
||||||
event ActivateGesture OnActivateGesture;
|
event ActivateGesture OnActivateGesture;
|
||||||
|
|
|
@ -231,7 +231,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
public event ScriptReset OnScriptReset;
|
public event ScriptReset OnScriptReset;
|
||||||
public event GetScriptRunning OnGetScriptRunning;
|
public event GetScriptRunning OnGetScriptRunning;
|
||||||
public event SetScriptRunning OnSetScriptRunning;
|
public event SetScriptRunning OnSetScriptRunning;
|
||||||
public event Action<Vector3, bool> OnAutoPilotGo;
|
public event Action<Vector3, bool, bool> OnAutoPilotGo;
|
||||||
public event TerrainUnacked OnUnackedTerrain;
|
public event TerrainUnacked OnUnackedTerrain;
|
||||||
public event ActivateGesture OnActivateGesture;
|
public event ActivateGesture OnActivateGesture;
|
||||||
public event DeactivateGesture OnDeactivateGesture;
|
public event DeactivateGesture OnDeactivateGesture;
|
||||||
|
@ -11640,9 +11640,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
locy = Convert.ToSingle(args[1]) - (float)regionY;
|
locy = Convert.ToSingle(args[1]) - (float)regionY;
|
||||||
locz = Convert.ToSingle(args[2]);
|
locz = Convert.ToSingle(args[2]);
|
||||||
|
|
||||||
Action<Vector3, bool> handlerAutoPilotGo = OnAutoPilotGo;
|
Action<Vector3, bool, bool> handlerAutoPilotGo = OnAutoPilotGo;
|
||||||
if (handlerAutoPilotGo != null)
|
if (handlerAutoPilotGo != null)
|
||||||
handlerAutoPilotGo(new Vector3(locx, locy, locz), false);
|
handlerAutoPilotGo(new Vector3(locx, locy, locz), false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -222,7 +222,7 @@ namespace OpenSim.Region.Examples.SimpleModule
|
||||||
public event ScriptReset OnScriptReset;
|
public event ScriptReset OnScriptReset;
|
||||||
public event GetScriptRunning OnGetScriptRunning;
|
public event GetScriptRunning OnGetScriptRunning;
|
||||||
public event SetScriptRunning OnSetScriptRunning;
|
public event SetScriptRunning OnSetScriptRunning;
|
||||||
public event Action<Vector3, bool> OnAutoPilotGo;
|
public event Action<Vector3, bool, bool> OnAutoPilotGo;
|
||||||
|
|
||||||
public event TerrainUnacked OnUnackedTerrain;
|
public event TerrainUnacked OnUnackedTerrain;
|
||||||
|
|
||||||
|
|
|
@ -5178,10 +5178,10 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
presence.PhysicsActor.IsColliding = true;
|
presence.PhysicsActor.IsColliding = true;
|
||||||
|
|
||||||
// Vector3 targetPos = presence.MoveToPositionTarget;
|
if (presence.LandAtTarget)
|
||||||
// if (m_avatars[presence.UUID].LandAtTarget)
|
presence.PhysicsActor.Flying = false;
|
||||||
// presence.PhysicsActor.Flying = false;
|
|
||||||
|
|
||||||
|
// Vector3 targetPos = presence.MoveToPositionTarget;
|
||||||
// float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y];
|
// float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y];
|
||||||
// if (targetPos.Z - terrainHeight < 0.2)
|
// if (targetPos.Z - terrainHeight < 0.2)
|
||||||
// {
|
// {
|
||||||
|
|
|
@ -1599,7 +1599,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
|
ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar);
|
||||||
if (avatar != null)
|
if (avatar != null)
|
||||||
{
|
{
|
||||||
avatar.MoveToTarget(target, false);
|
avatar.MoveToTarget(target, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -220,6 +220,11 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
public bool MovingToTarget { get; private set; }
|
public bool MovingToTarget { get; private set; }
|
||||||
public Vector3 MoveToPositionTarget { get; private set; }
|
public Vector3 MoveToPositionTarget { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Controls whether an avatar automatically moving to a target will land when it gets there (if flying).
|
||||||
|
/// </summary>
|
||||||
|
public bool LandAtTarget { get; private set; }
|
||||||
|
|
||||||
private bool m_followCamAuto;
|
private bool m_followCamAuto;
|
||||||
|
|
||||||
private int m_movementUpdateCount;
|
private int m_movementUpdateCount;
|
||||||
|
@ -1681,7 +1686,10 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
/// This is to allow movement to targets that are known to be on an elevated platform with a continuous path
|
/// This is to allow movement to targets that are known to be on an elevated platform with a continuous path
|
||||||
/// from start to finish.
|
/// from start to finish.
|
||||||
/// </param>
|
/// </param>
|
||||||
public void MoveToTarget(Vector3 pos, bool noFly)
|
/// <param name="landAtTarget">
|
||||||
|
/// If true and the avatar starts flying during the move then land at the target.
|
||||||
|
/// </param>
|
||||||
|
public void MoveToTarget(Vector3 pos, bool noFly, bool landAtTarget)
|
||||||
{
|
{
|
||||||
m_log.DebugFormat(
|
m_log.DebugFormat(
|
||||||
"[SCENE PRESENCE]: Avatar {0} received request to move to position {1} in {2}",
|
"[SCENE PRESENCE]: Avatar {0} received request to move to position {1} in {2}",
|
||||||
|
@ -1720,6 +1728,7 @@ namespace OpenSim.Region.Framework.Scenes
|
||||||
else if (pos.Z > terrainHeight)
|
else if (pos.Z > terrainHeight)
|
||||||
PhysicsActor.Flying = true;
|
PhysicsActor.Flying = true;
|
||||||
|
|
||||||
|
LandAtTarget = landAtTarget;
|
||||||
MovingToTarget = true;
|
MovingToTarget = true;
|
||||||
MoveToPositionTarget = pos;
|
MoveToPositionTarget = pos;
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
|
||||||
Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
|
Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
|
||||||
|
|
||||||
Vector3 targetPos = startPos + new Vector3(0, 10, 0);
|
Vector3 targetPos = startPos + new Vector3(0, 10, 0);
|
||||||
sp.MoveToTarget(targetPos, false);
|
sp.MoveToTarget(targetPos, false, false);
|
||||||
|
|
||||||
Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
|
Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
|
||||||
Assert.That(
|
Assert.That(
|
||||||
|
@ -110,7 +110,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
|
||||||
// Try a second movement
|
// Try a second movement
|
||||||
startPos = sp.AbsolutePosition;
|
startPos = sp.AbsolutePosition;
|
||||||
targetPos = startPos + new Vector3(10, 0, 0);
|
targetPos = startPos + new Vector3(10, 0, 0);
|
||||||
sp.MoveToTarget(targetPos, false);
|
sp.MoveToTarget(targetPos, false, false);
|
||||||
|
|
||||||
Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
|
Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
|
||||||
Assert.That(
|
Assert.That(
|
||||||
|
|
|
@ -806,7 +806,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
|
||||||
public event ScriptReset OnScriptReset;
|
public event ScriptReset OnScriptReset;
|
||||||
public event GetScriptRunning OnGetScriptRunning;
|
public event GetScriptRunning OnGetScriptRunning;
|
||||||
public event SetScriptRunning OnSetScriptRunning;
|
public event SetScriptRunning OnSetScriptRunning;
|
||||||
public event Action<Vector3, bool> OnAutoPilotGo;
|
public event Action<Vector3, bool, bool> OnAutoPilotGo;
|
||||||
public event TerrainUnacked OnUnackedTerrain;
|
public event TerrainUnacked OnUnackedTerrain;
|
||||||
public event ActivateGesture OnActivateGesture;
|
public event ActivateGesture OnActivateGesture;
|
||||||
public event DeactivateGesture OnDeactivateGesture;
|
public event DeactivateGesture OnDeactivateGesture;
|
||||||
|
|
|
@ -37,11 +37,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||||
{
|
{
|
||||||
public class NPCAvatar : IClientAPI
|
public class NPCAvatar : IClientAPI
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Signal whether the avatar should land when it reaches a move target
|
|
||||||
/// </summary>
|
|
||||||
public bool LandAtTarget { get; set; }
|
|
||||||
|
|
||||||
private readonly string m_firstname;
|
private readonly string m_firstname;
|
||||||
private readonly string m_lastname;
|
private readonly string m_lastname;
|
||||||
private readonly Vector3 m_startPos;
|
private readonly Vector3 m_startPos;
|
||||||
|
@ -333,7 +328,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||||
public event ScriptReset OnScriptReset;
|
public event ScriptReset OnScriptReset;
|
||||||
public event GetScriptRunning OnGetScriptRunning;
|
public event GetScriptRunning OnGetScriptRunning;
|
||||||
public event SetScriptRunning OnSetScriptRunning;
|
public event SetScriptRunning OnSetScriptRunning;
|
||||||
public event Action<Vector3, bool> OnAutoPilotGo;
|
public event Action<Vector3, bool, bool> OnAutoPilotGo;
|
||||||
|
|
||||||
public event TerrainUnacked OnUnackedTerrain;
|
public event TerrainUnacked OnUnackedTerrain;
|
||||||
|
|
||||||
|
|
|
@ -53,78 +53,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||||
if (config != null && config.GetBoolean("Enabled", false))
|
if (config != null && config.GetBoolean("Enabled", false))
|
||||||
{
|
{
|
||||||
scene.RegisterModuleInterface<INPCModule>(this);
|
scene.RegisterModuleInterface<INPCModule>(this);
|
||||||
// scene.EventManager.OnSignificantClientMovement += HandleOnSignificantClientMovement;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void HandleOnSignificantClientMovement(ScenePresence presence)
|
|
||||||
{
|
|
||||||
lock (m_avatars)
|
|
||||||
{
|
|
||||||
if (m_avatars.ContainsKey(presence.UUID) && presence.MovingToTarget)
|
|
||||||
{
|
|
||||||
double distanceToTarget = Util.GetDistanceTo(presence.AbsolutePosition, presence.MoveToPositionTarget);
|
|
||||||
// m_log.DebugFormat(
|
|
||||||
// "[NPC MODULE]: Abs pos of {0} is {1}, target {2}, distance {3}",
|
|
||||||
// presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget, distanceToTarget);
|
|
||||||
|
|
||||||
// Check the error term of the current position in relation to the target position
|
|
||||||
if (distanceToTarget <= ScenePresence.SIGNIFICANT_MOVEMENT)
|
|
||||||
{
|
|
||||||
// We are close enough to the target
|
|
||||||
m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0}", presence.Name);
|
|
||||||
|
|
||||||
presence.Velocity = Vector3.Zero;
|
|
||||||
presence.AbsolutePosition = presence.MoveToPositionTarget;
|
|
||||||
presence.ResetMoveToTarget();
|
|
||||||
|
|
||||||
if (presence.PhysicsActor.Flying)
|
|
||||||
{
|
|
||||||
// A horrible hack to stop the NPC dead in its tracks rather than having them overshoot
|
|
||||||
// the target if flying.
|
|
||||||
// We really need to be more subtle (slow the avatar as it approaches the target) or at
|
|
||||||
// least be able to set collision status once, rather than 5 times to give it enough
|
|
||||||
// weighting so that that PhysicsActor thinks it really is colliding.
|
|
||||||
for (int i = 0; i < 5; i++)
|
|
||||||
presence.PhysicsActor.IsColliding = true;
|
|
||||||
|
|
||||||
// Vector3 targetPos = presence.MoveToPositionTarget;
|
|
||||||
if (m_avatars[presence.UUID].LandAtTarget)
|
|
||||||
presence.PhysicsActor.Flying = false;
|
|
||||||
|
|
||||||
// float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y];
|
|
||||||
// if (targetPos.Z - terrainHeight < 0.2)
|
|
||||||
// {
|
|
||||||
// presence.PhysicsActor.Flying = false;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// m_log.DebugFormat(
|
|
||||||
// "[NPC MODULE]: AgentControlFlags {0}, MovementFlag {1} for {2}",
|
|
||||||
// presence.AgentControlFlags, presence.MovementFlag, presence.Name);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// m_log.DebugFormat(
|
|
||||||
// "[NPC MODULE]: Updating npc {0} at {1} for next movement to {2}",
|
|
||||||
// presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget);
|
|
||||||
|
|
||||||
Vector3 agent_control_v3 = new Vector3();
|
|
||||||
presence.HandleMoveToTargetUpdate(ref agent_control_v3);
|
|
||||||
presence.AddNewMovement(agent_control_v3);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
//// presence.DoMoveToPositionUpdate((0, presence.MoveToPositionTarget, null);
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsNPC(UUID agentId, Scene scene)
|
public bool IsNPC(UUID agentId, Scene scene)
|
||||||
{
|
{
|
||||||
|
// FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect
|
||||||
|
// that directly).
|
||||||
ScenePresence sp = scene.GetScenePresence(agentId);
|
ScenePresence sp = scene.GetScenePresence(agentId);
|
||||||
if (sp == null || sp.IsChildAgent)
|
if (sp == null || sp.IsChildAgent)
|
||||||
return false;
|
return false;
|
||||||
|
@ -218,8 +153,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
|
||||||
"[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
|
"[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
|
||||||
sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget);
|
sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget);
|
||||||
|
|
||||||
m_avatars[agentID].LandAtTarget = landAtTarget;
|
sp.MoveToTarget(pos, noFly, landAtTarget);
|
||||||
sp.MoveToTarget(pos, noFly);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,7 +234,7 @@ namespace OpenSim.Tests.Common.Mock
|
||||||
public event ScriptReset OnScriptReset;
|
public event ScriptReset OnScriptReset;
|
||||||
public event GetScriptRunning OnGetScriptRunning;
|
public event GetScriptRunning OnGetScriptRunning;
|
||||||
public event SetScriptRunning OnSetScriptRunning;
|
public event SetScriptRunning OnSetScriptRunning;
|
||||||
public event Action<Vector3, bool> OnAutoPilotGo;
|
public event Action<Vector3, bool, bool> OnAutoPilotGo;
|
||||||
|
|
||||||
public event TerrainUnacked OnUnackedTerrain;
|
public event TerrainUnacked OnUnackedTerrain;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue