diff options
author | Justin Clark-Casey (justincc) | 2011-09-22 00:16:05 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-09-22 00:16:05 +0100 |
commit | d358125cac4e01194dae4b1f0bc9afc87e463f76 (patch) | |
tree | 28e06b311c9bd1621e94305aa9da6b32eef8502c | |
parent | Move code which handles NPC movement into Scene so that this can also be used... (diff) | |
download | opensim-SC-d358125cac4e01194dae4b1f0bc9afc87e463f76.zip opensim-SC-d358125cac4e01194dae4b1f0bc9afc87e463f76.tar.gz opensim-SC-d358125cac4e01194dae4b1f0bc9afc87e463f76.tar.bz2 opensim-SC-d358125cac4e01194dae4b1f0bc9afc87e463f76.tar.xz |
Reinstate option to land an npc when it reaches a target.
This is moved into ScenePresence for now as a general facility
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 | |||
169 | float y = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Y]); | 169 | float y = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Y]); |
170 | float z = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Z]); | 170 | float z = Convert.ToSingle(rdata.Parameters[PARM_MOVE_Z]); |
171 | Vector3 vector = new Vector3(x, y, z); | 171 | Vector3 vector = new Vector3(x, y, z); |
172 | presence.MoveToTarget(vector, false); | 172 | presence.MoveToTarget(vector, false, false); |
173 | } | 173 | } |
174 | catch (Exception e) | 174 | catch (Exception e) |
175 | { | 175 | { |
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 | |||
935 | event ScriptReset OnScriptReset; | 935 | event ScriptReset OnScriptReset; |
936 | event GetScriptRunning OnGetScriptRunning; | 936 | event GetScriptRunning OnGetScriptRunning; |
937 | event SetScriptRunning OnSetScriptRunning; | 937 | event SetScriptRunning OnSetScriptRunning; |
938 | event Action<Vector3, bool> OnAutoPilotGo; | 938 | event Action<Vector3, bool, bool> OnAutoPilotGo; |
939 | 939 | ||
940 | event TerrainUnacked OnUnackedTerrain; | 940 | event TerrainUnacked OnUnackedTerrain; |
941 | event ActivateGesture OnActivateGesture; | 941 | 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 | |||
231 | public event ScriptReset OnScriptReset; | 231 | public event ScriptReset OnScriptReset; |
232 | public event GetScriptRunning OnGetScriptRunning; | 232 | public event GetScriptRunning OnGetScriptRunning; |
233 | public event SetScriptRunning OnSetScriptRunning; | 233 | public event SetScriptRunning OnSetScriptRunning; |
234 | public event Action<Vector3, bool> OnAutoPilotGo; | 234 | public event Action<Vector3, bool, bool> OnAutoPilotGo; |
235 | public event TerrainUnacked OnUnackedTerrain; | 235 | public event TerrainUnacked OnUnackedTerrain; |
236 | public event ActivateGesture OnActivateGesture; | 236 | public event ActivateGesture OnActivateGesture; |
237 | public event DeactivateGesture OnDeactivateGesture; | 237 | public event DeactivateGesture OnDeactivateGesture; |
@@ -11640,9 +11640,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
11640 | locy = Convert.ToSingle(args[1]) - (float)regionY; | 11640 | locy = Convert.ToSingle(args[1]) - (float)regionY; |
11641 | locz = Convert.ToSingle(args[2]); | 11641 | locz = Convert.ToSingle(args[2]); |
11642 | 11642 | ||
11643 | Action<Vector3, bool> handlerAutoPilotGo = OnAutoPilotGo; | 11643 | Action<Vector3, bool, bool> handlerAutoPilotGo = OnAutoPilotGo; |
11644 | if (handlerAutoPilotGo != null) | 11644 | if (handlerAutoPilotGo != null) |
11645 | handlerAutoPilotGo(new Vector3(locx, locy, locz), false); | 11645 | handlerAutoPilotGo(new Vector3(locx, locy, locz), false, false); |
11646 | } | 11646 | } |
11647 | 11647 | ||
11648 | /// <summary> | 11648 | /// <summary> |
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 | |||
222 | public event ScriptReset OnScriptReset; | 222 | public event ScriptReset OnScriptReset; |
223 | public event GetScriptRunning OnGetScriptRunning; | 223 | public event GetScriptRunning OnGetScriptRunning; |
224 | public event SetScriptRunning OnSetScriptRunning; | 224 | public event SetScriptRunning OnSetScriptRunning; |
225 | public event Action<Vector3, bool> OnAutoPilotGo; | 225 | public event Action<Vector3, bool, bool> OnAutoPilotGo; |
226 | 226 | ||
227 | public event TerrainUnacked OnUnackedTerrain; | 227 | public event TerrainUnacked OnUnackedTerrain; |
228 | 228 | ||
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 | |||
5178 | for (int i = 0; i < 5; i++) | 5178 | for (int i = 0; i < 5; i++) |
5179 | presence.PhysicsActor.IsColliding = true; | 5179 | presence.PhysicsActor.IsColliding = true; |
5180 | 5180 | ||
5181 | // Vector3 targetPos = presence.MoveToPositionTarget; | 5181 | if (presence.LandAtTarget) |
5182 | // if (m_avatars[presence.UUID].LandAtTarget) | 5182 | presence.PhysicsActor.Flying = false; |
5183 | // presence.PhysicsActor.Flying = false; | ||
5184 | 5183 | ||
5184 | // Vector3 targetPos = presence.MoveToPositionTarget; | ||
5185 | // float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y]; | 5185 | // float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y]; |
5186 | // if (targetPos.Z - terrainHeight < 0.2) | 5186 | // if (targetPos.Z - terrainHeight < 0.2) |
5187 | // { | 5187 | // { |
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 | |||
1599 | ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); | 1599 | ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); |
1600 | if (avatar != null) | 1600 | if (avatar != null) |
1601 | { | 1601 | { |
1602 | avatar.MoveToTarget(target, false); | 1602 | avatar.MoveToTarget(target, false, false); |
1603 | } | 1603 | } |
1604 | } | 1604 | } |
1605 | else | 1605 | 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 | |||
220 | public bool MovingToTarget { get; private set; } | 220 | public bool MovingToTarget { get; private set; } |
221 | public Vector3 MoveToPositionTarget { get; private set; } | 221 | public Vector3 MoveToPositionTarget { get; private set; } |
222 | 222 | ||
223 | /// <summary> | ||
224 | /// Controls whether an avatar automatically moving to a target will land when it gets there (if flying). | ||
225 | /// </summary> | ||
226 | public bool LandAtTarget { get; private set; } | ||
227 | |||
223 | private bool m_followCamAuto; | 228 | private bool m_followCamAuto; |
224 | 229 | ||
225 | private int m_movementUpdateCount; | 230 | private int m_movementUpdateCount; |
@@ -1681,7 +1686,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
1681 | /// This is to allow movement to targets that are known to be on an elevated platform with a continuous path | 1686 | /// This is to allow movement to targets that are known to be on an elevated platform with a continuous path |
1682 | /// from start to finish. | 1687 | /// from start to finish. |
1683 | /// </param> | 1688 | /// </param> |
1684 | public void MoveToTarget(Vector3 pos, bool noFly) | 1689 | /// <param name="landAtTarget"> |
1690 | /// If true and the avatar starts flying during the move then land at the target. | ||
1691 | /// </param> | ||
1692 | public void MoveToTarget(Vector3 pos, bool noFly, bool landAtTarget) | ||
1685 | { | 1693 | { |
1686 | m_log.DebugFormat( | 1694 | m_log.DebugFormat( |
1687 | "[SCENE PRESENCE]: Avatar {0} received request to move to position {1} in {2}", | 1695 | "[SCENE PRESENCE]: Avatar {0} received request to move to position {1} in {2}", |
@@ -1720,6 +1728,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
1720 | else if (pos.Z > terrainHeight) | 1728 | else if (pos.Z > terrainHeight) |
1721 | PhysicsActor.Flying = true; | 1729 | PhysicsActor.Flying = true; |
1722 | 1730 | ||
1731 | LandAtTarget = landAtTarget; | ||
1723 | MovingToTarget = true; | 1732 | MovingToTarget = true; |
1724 | MoveToPositionTarget = pos; | 1733 | MoveToPositionTarget = pos; |
1725 | 1734 | ||
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 | |||
85 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); | 85 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); |
86 | 86 | ||
87 | Vector3 targetPos = startPos + new Vector3(0, 10, 0); | 87 | Vector3 targetPos = startPos + new Vector3(0, 10, 0); |
88 | sp.MoveToTarget(targetPos, false); | 88 | sp.MoveToTarget(targetPos, false, false); |
89 | 89 | ||
90 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); | 90 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); |
91 | Assert.That( | 91 | Assert.That( |
@@ -110,7 +110,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests | |||
110 | // Try a second movement | 110 | // Try a second movement |
111 | startPos = sp.AbsolutePosition; | 111 | startPos = sp.AbsolutePosition; |
112 | targetPos = startPos + new Vector3(10, 0, 0); | 112 | targetPos = startPos + new Vector3(10, 0, 0); |
113 | sp.MoveToTarget(targetPos, false); | 113 | sp.MoveToTarget(targetPos, false, false); |
114 | 114 | ||
115 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); | 115 | Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos)); |
116 | Assert.That( | 116 | 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 | |||
806 | public event ScriptReset OnScriptReset; | 806 | public event ScriptReset OnScriptReset; |
807 | public event GetScriptRunning OnGetScriptRunning; | 807 | public event GetScriptRunning OnGetScriptRunning; |
808 | public event SetScriptRunning OnSetScriptRunning; | 808 | public event SetScriptRunning OnSetScriptRunning; |
809 | public event Action<Vector3, bool> OnAutoPilotGo; | 809 | public event Action<Vector3, bool, bool> OnAutoPilotGo; |
810 | public event TerrainUnacked OnUnackedTerrain; | 810 | public event TerrainUnacked OnUnackedTerrain; |
811 | public event ActivateGesture OnActivateGesture; | 811 | public event ActivateGesture OnActivateGesture; |
812 | public event DeactivateGesture OnDeactivateGesture; | 812 | 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 | |||
37 | { | 37 | { |
38 | public class NPCAvatar : IClientAPI | 38 | public class NPCAvatar : IClientAPI |
39 | { | 39 | { |
40 | /// <summary> | ||
41 | /// Signal whether the avatar should land when it reaches a move target | ||
42 | /// </summary> | ||
43 | public bool LandAtTarget { get; set; } | ||
44 | |||
45 | private readonly string m_firstname; | 40 | private readonly string m_firstname; |
46 | private readonly string m_lastname; | 41 | private readonly string m_lastname; |
47 | private readonly Vector3 m_startPos; | 42 | private readonly Vector3 m_startPos; |
@@ -333,7 +328,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
333 | public event ScriptReset OnScriptReset; | 328 | public event ScriptReset OnScriptReset; |
334 | public event GetScriptRunning OnGetScriptRunning; | 329 | public event GetScriptRunning OnGetScriptRunning; |
335 | public event SetScriptRunning OnSetScriptRunning; | 330 | public event SetScriptRunning OnSetScriptRunning; |
336 | public event Action<Vector3, bool> OnAutoPilotGo; | 331 | public event Action<Vector3, bool, bool> OnAutoPilotGo; |
337 | 332 | ||
338 | public event TerrainUnacked OnUnackedTerrain; | 333 | public event TerrainUnacked OnUnackedTerrain; |
339 | 334 | ||
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 | |||
53 | if (config != null && config.GetBoolean("Enabled", false)) | 53 | if (config != null && config.GetBoolean("Enabled", false)) |
54 | { | 54 | { |
55 | scene.RegisterModuleInterface<INPCModule>(this); | 55 | scene.RegisterModuleInterface<INPCModule>(this); |
56 | // scene.EventManager.OnSignificantClientMovement += HandleOnSignificantClientMovement; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | public void HandleOnSignificantClientMovement(ScenePresence presence) | ||
61 | { | ||
62 | lock (m_avatars) | ||
63 | { | ||
64 | if (m_avatars.ContainsKey(presence.UUID) && presence.MovingToTarget) | ||
65 | { | ||
66 | double distanceToTarget = Util.GetDistanceTo(presence.AbsolutePosition, presence.MoveToPositionTarget); | ||
67 | // m_log.DebugFormat( | ||
68 | // "[NPC MODULE]: Abs pos of {0} is {1}, target {2}, distance {3}", | ||
69 | // presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget, distanceToTarget); | ||
70 | |||
71 | // Check the error term of the current position in relation to the target position | ||
72 | if (distanceToTarget <= ScenePresence.SIGNIFICANT_MOVEMENT) | ||
73 | { | ||
74 | // We are close enough to the target | ||
75 | m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0}", presence.Name); | ||
76 | |||
77 | presence.Velocity = Vector3.Zero; | ||
78 | presence.AbsolutePosition = presence.MoveToPositionTarget; | ||
79 | presence.ResetMoveToTarget(); | ||
80 | |||
81 | if (presence.PhysicsActor.Flying) | ||
82 | { | ||
83 | // A horrible hack to stop the NPC dead in its tracks rather than having them overshoot | ||
84 | // the target if flying. | ||
85 | // We really need to be more subtle (slow the avatar as it approaches the target) or at | ||
86 | // least be able to set collision status once, rather than 5 times to give it enough | ||
87 | // weighting so that that PhysicsActor thinks it really is colliding. | ||
88 | for (int i = 0; i < 5; i++) | ||
89 | presence.PhysicsActor.IsColliding = true; | ||
90 | |||
91 | // Vector3 targetPos = presence.MoveToPositionTarget; | ||
92 | if (m_avatars[presence.UUID].LandAtTarget) | ||
93 | presence.PhysicsActor.Flying = false; | ||
94 | |||
95 | // float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y]; | ||
96 | // if (targetPos.Z - terrainHeight < 0.2) | ||
97 | // { | ||
98 | // presence.PhysicsActor.Flying = false; | ||
99 | // } | ||
100 | } | ||
101 | |||
102 | // m_log.DebugFormat( | ||
103 | // "[NPC MODULE]: AgentControlFlags {0}, MovementFlag {1} for {2}", | ||
104 | // presence.AgentControlFlags, presence.MovementFlag, presence.Name); | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | // m_log.DebugFormat( | ||
109 | // "[NPC MODULE]: Updating npc {0} at {1} for next movement to {2}", | ||
110 | // presence.Name, presence.AbsolutePosition, presence.MoveToPositionTarget); | ||
111 | |||
112 | Vector3 agent_control_v3 = new Vector3(); | ||
113 | presence.HandleMoveToTargetUpdate(ref agent_control_v3); | ||
114 | presence.AddNewMovement(agent_control_v3); | ||
115 | } | ||
116 | // | ||
117 | //// presence.DoMoveToPositionUpdate((0, presence.MoveToPositionTarget, null); | ||
118 | |||
119 | // | ||
120 | // | ||
121 | |||
122 | } | ||
123 | } | 56 | } |
124 | } | 57 | } |
125 | 58 | ||
126 | public bool IsNPC(UUID agentId, Scene scene) | 59 | public bool IsNPC(UUID agentId, Scene scene) |
127 | { | 60 | { |
61 | // FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect | ||
62 | // that directly). | ||
128 | ScenePresence sp = scene.GetScenePresence(agentId); | 63 | ScenePresence sp = scene.GetScenePresence(agentId); |
129 | if (sp == null || sp.IsChildAgent) | 64 | if (sp == null || sp.IsChildAgent) |
130 | return false; | 65 | return false; |
@@ -218,8 +153,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
218 | "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", | 153 | "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", |
219 | sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); | 154 | sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); |
220 | 155 | ||
221 | m_avatars[agentID].LandAtTarget = landAtTarget; | 156 | sp.MoveToTarget(pos, noFly, landAtTarget); |
222 | sp.MoveToTarget(pos, noFly); | ||
223 | 157 | ||
224 | return true; | 158 | return true; |
225 | } | 159 | } |
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 | |||
234 | public event ScriptReset OnScriptReset; | 234 | public event ScriptReset OnScriptReset; |
235 | public event GetScriptRunning OnGetScriptRunning; | 235 | public event GetScriptRunning OnGetScriptRunning; |
236 | public event SetScriptRunning OnSetScriptRunning; | 236 | public event SetScriptRunning OnSetScriptRunning; |
237 | public event Action<Vector3, bool> OnAutoPilotGo; | 237 | public event Action<Vector3, bool, bool> OnAutoPilotGo; |
238 | 238 | ||
239 | public event TerrainUnacked OnUnackedTerrain; | 239 | public event TerrainUnacked OnUnackedTerrain; |
240 | 240 | ||