From d358125cac4e01194dae4b1f0bc9afc87e463f76 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Thu, 22 Sep 2011 00:16:05 +0100 Subject: Reinstate option to land an npc when it reaches a target. This is moved into ScenePresence for now as a general facility --- .../Rest/Inventory/tests/Remote.cs | 2 +- OpenSim/Framework/IClientAPI.cs | 2 +- .../Region/ClientStack/Linden/UDP/LLClientView.cs | 6 +- .../Region/Examples/SimpleModule/MyNpcCharacter.cs | 2 +- OpenSim/Region/Framework/Scenes/Scene.cs | 6 +- .../Region/Framework/Scenes/SceneObjectGroup.cs | 2 +- OpenSim/Region/Framework/Scenes/ScenePresence.cs | 11 +++- .../Scenes/Tests/ScenePresenceAutopilotTests.cs | 4 +- .../Server/IRCClientView.cs | 2 +- .../Region/OptionalModules/World/NPC/NPCAvatar.cs | 7 +-- .../Region/OptionalModules/World/NPC/NPCModule.cs | 72 +--------------------- OpenSim/Tests/Common/Mock/TestClient.cs | 2 +- 12 files changed, 28 insertions(+), 90 deletions(-) diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/tests/Remote.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/tests/Remote.cs index 1023108..b53806c 100644 --- a/OpenSim/ApplicationPlugins/Rest/Inventory/tests/Remote.cs +++ b/OpenSim/ApplicationPlugins/Rest/Inventory/tests/Remote.cs @@ -169,7 +169,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory.Tests float y = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Y]); float z = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Z]); Vector3 vector = new Vector3(x, y, z); - presence.MoveToTarget(vector, false); + presence.MoveToTarget(vector, false, false); } catch (Exception e) { diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs index 150ff1b..47e79d1 100644 --- a/OpenSim/Framework/IClientAPI.cs +++ b/OpenSim/Framework/IClientAPI.cs @@ -935,7 +935,7 @@ namespace OpenSim.Framework event ScriptReset OnScriptReset; event GetScriptRunning OnGetScriptRunning; event SetScriptRunning OnSetScriptRunning; - event Action OnAutoPilotGo; + event Action OnAutoPilotGo; event TerrainUnacked OnUnackedTerrain; event ActivateGesture OnActivateGesture; diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index b5c6742..ce2ff86 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -231,7 +231,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP public event ScriptReset OnScriptReset; public event GetScriptRunning OnGetScriptRunning; public event SetScriptRunning OnSetScriptRunning; - public event Action OnAutoPilotGo; + public event Action OnAutoPilotGo; public event TerrainUnacked OnUnackedTerrain; public event ActivateGesture OnActivateGesture; public event DeactivateGesture OnDeactivateGesture; @@ -11640,9 +11640,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP locy = Convert.ToSingle(args[1]) - (float)regionY; locz = Convert.ToSingle(args[2]); - Action handlerAutoPilotGo = OnAutoPilotGo; + Action handlerAutoPilotGo = OnAutoPilotGo; if (handlerAutoPilotGo != null) - handlerAutoPilotGo(new Vector3(locx, locy, locz), false); + handlerAutoPilotGo(new Vector3(locx, locy, locz), false, false); } /// diff --git a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs index c87790f..b0266c5 100644 --- a/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleModule/MyNpcCharacter.cs @@ -222,7 +222,7 @@ namespace OpenSim.Region.Examples.SimpleModule public event ScriptReset OnScriptReset; public event GetScriptRunning OnGetScriptRunning; public event SetScriptRunning OnSetScriptRunning; - public event Action OnAutoPilotGo; + public event Action OnAutoPilotGo; public event TerrainUnacked OnUnackedTerrain; diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 000a6ed..eadec09 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -5178,10 +5178,10 @@ namespace OpenSim.Region.Framework.Scenes 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; + if (presence.LandAtTarget) + presence.PhysicsActor.Flying = false; +// Vector3 targetPos = presence.MoveToPositionTarget; // float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y]; // if (targetPos.Z - terrainHeight < 0.2) // { diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index e7f2491..980b01f 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -1599,7 +1599,7 @@ namespace OpenSim.Region.Framework.Scenes ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); if (avatar != null) { - avatar.MoveToTarget(target, false); + avatar.MoveToTarget(target, false, false); } } else diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs index 82d9abf..a7b189b 100644 --- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs @@ -220,6 +220,11 @@ namespace OpenSim.Region.Framework.Scenes public bool MovingToTarget { get; private set; } public Vector3 MoveToPositionTarget { get; private set; } + /// + /// Controls whether an avatar automatically moving to a target will land when it gets there (if flying). + /// + public bool LandAtTarget { get; private set; } + private bool m_followCamAuto; 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 /// from start to finish. /// - public void MoveToTarget(Vector3 pos, bool noFly) + /// + /// If true and the avatar starts flying during the move then land at the target. + /// + public void MoveToTarget(Vector3 pos, bool noFly, bool landAtTarget) { m_log.DebugFormat( "[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) PhysicsActor.Flying = true; + LandAtTarget = landAtTarget; MovingToTarget = true; MoveToPositionTarget = pos; diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs index 5a85d7f..64c36ff 100644 --- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs +++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceAutopilotTests.cs @@ -85,7 +85,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); 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( @@ -110,7 +110,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests // Try a second movement startPos = sp.AbsolutePosition; 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( diff --git a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs index c413634..f6656c2 100644 --- a/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs +++ b/OpenSim/Region/OptionalModules/Agent/InternetRelayClientView/Server/IRCClientView.cs @@ -806,7 +806,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server public event ScriptReset OnScriptReset; public event GetScriptRunning OnGetScriptRunning; public event SetScriptRunning OnSetScriptRunning; - public event Action OnAutoPilotGo; + public event Action OnAutoPilotGo; public event TerrainUnacked OnUnackedTerrain; public event ActivateGesture OnActivateGesture; public event DeactivateGesture OnDeactivateGesture; diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 31e79fa..edb618e 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs @@ -37,11 +37,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC { public class NPCAvatar : IClientAPI { - /// - /// Signal whether the avatar should land when it reaches a move target - /// - public bool LandAtTarget { get; set; } - private readonly string m_firstname; private readonly string m_lastname; private readonly Vector3 m_startPos; @@ -333,7 +328,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC public event ScriptReset OnScriptReset; public event GetScriptRunning OnGetScriptRunning; public event SetScriptRunning OnSetScriptRunning; - public event Action OnAutoPilotGo; + public event Action OnAutoPilotGo; public event TerrainUnacked OnUnackedTerrain; diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 6282245..bcd9e94 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -53,78 +53,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC if (config != null && config.GetBoolean("Enabled", false)) { scene.RegisterModuleInterface(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) { + // FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect + // that directly). ScenePresence sp = scene.GetScenePresence(agentId); if (sp == null || sp.IsChildAgent) return false; @@ -218,8 +153,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); - m_avatars[agentID].LandAtTarget = landAtTarget; - sp.MoveToTarget(pos, noFly); + sp.MoveToTarget(pos, noFly, landAtTarget); return true; } diff --git a/OpenSim/Tests/Common/Mock/TestClient.cs b/OpenSim/Tests/Common/Mock/TestClient.cs index b7cefeb..71f2bf4 100644 --- a/OpenSim/Tests/Common/Mock/TestClient.cs +++ b/OpenSim/Tests/Common/Mock/TestClient.cs @@ -234,7 +234,7 @@ namespace OpenSim.Tests.Common.Mock public event ScriptReset OnScriptReset; public event GetScriptRunning OnGetScriptRunning; public event SetScriptRunning OnSetScriptRunning; - public event Action OnAutoPilotGo; + public event Action OnAutoPilotGo; public event TerrainUnacked OnUnackedTerrain; -- cgit v1.1