diff options
Merge branch 'bigmerge' of ssh://3dhosting.de/var/git/careminster into bigmerge
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC')
3 files changed, 18 insertions, 83 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 4f831a4..253fdee 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 2fdeeab..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/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index 246bc34..49c06bc 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs | |||
@@ -132,11 +132,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
132 | UUID attAssetId = TestHelpers.ParseTail(0x3); | 132 | UUID attAssetId = TestHelpers.ParseTail(0x3); |
133 | string attName = "att"; | 133 | string attName = "att"; |
134 | 134 | ||
135 | UserInventoryHelpers.CreateInventoryItem( | 135 | UserInventoryHelpers.CreateInventoryItem(scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); |
136 | scene, attName, attItemId, attAssetId, sp.UUID, InventoryType.Object); | ||
137 | 136 | ||
138 | am.RezSingleAttachmentFromInventory( | 137 | am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); |
139 | sp.ControllingClient, attItemId, (uint)AttachmentPoint.Chest); | ||
140 | 138 | ||
141 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | 139 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); |
142 | UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance); | 140 | UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance); |
@@ -182,18 +180,21 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
182 | scene.Update(); | 180 | scene.Update(); |
183 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | 181 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
184 | 182 | ||
185 | Vector3 targetPos = startPos + new Vector3(0, 0, 10); | 183 | Vector3 targetPos = startPos + new Vector3(0, 10, 0); |
186 | npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false); | 184 | npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false); |
187 | 185 | ||
188 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | 186 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
187 | //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f))); | ||
188 | Assert.That( | ||
189 | npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0.7071068f, 0.7071068f), 0.000001)); | ||
189 | 190 | ||
190 | scene.Update(); | 191 | scene.Update(); |
191 | 192 | ||
192 | // We should really check the exact figure. | 193 | // We should really check the exact figure. |
193 | Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X)); | 194 | Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X)); |
194 | Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y)); | 195 | Assert.That(npc.AbsolutePosition.Y, Is.GreaterThan(startPos.Y)); |
195 | Assert.That(npc.AbsolutePosition.Z, Is.GreaterThan(startPos.Z)); | 196 | Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z)); |
196 | Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.Z)); | 197 | Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.X)); |
197 | 198 | ||
198 | for (int i = 0; i < 10; i++) | 199 | for (int i = 0; i < 10; i++) |
199 | scene.Update(); | 200 | scene.Update(); |
@@ -208,6 +209,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
208 | targetPos = startPos + new Vector3(10, 0, 0); | 209 | targetPos = startPos + new Vector3(10, 0, 0); |
209 | npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false); | 210 | npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false); |
210 | 211 | ||
212 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | ||
213 | // Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0, 1))); | ||
214 | Assert.That( | ||
215 | npc.Rotation, new QuaternionToleranceConstraint(new Quaternion(0, 0, 0, 1), 0.000001)); | ||
216 | |||
211 | scene.Update(); | 217 | scene.Update(); |
212 | 218 | ||
213 | // We should really check the exact figure. | 219 | // We should really check the exact figure. |