aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-08-10 23:56:19 +0100
committerJustin Clark-Casey (justincc)2011-08-10 23:56:19 +0100
commit7f499ff3f386d57bcd81ebb3f58f110011100604 (patch)
treebab34762e4a9cb9e739df591360cec3405bb4e57 /OpenSim/Region/OptionalModules/World
parentfly and no fly constants for osNpcMoveToTarget() (diff)
downloadopensim-SC_OLD-7f499ff3f386d57bcd81ebb3f58f110011100604.zip
opensim-SC_OLD-7f499ff3f386d57bcd81ebb3f58f110011100604.tar.gz
opensim-SC_OLD-7f499ff3f386d57bcd81ebb3f58f110011100604.tar.bz2
opensim-SC_OLD-7f499ff3f386d57bcd81ebb3f58f110011100604.tar.xz
Add a OS_NPC_LAND_AT_TARGET option to osMoveToTarget()
Default for this function is now not to automatically land. This allows better control by scripts when an avatar is going to be landing on a prim rather than the ground. Stopping the avatar involves faking a collision, to avoid the pid controller making it overshoot. A better approach would be to gradually slow the avatar as we near the target
Diffstat (limited to 'OpenSim/Region/OptionalModules/World')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs5
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs33
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs4
3 files changed, 29 insertions, 13 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
index cfd692d..d63c2a6 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
@@ -37,6 +37,11 @@ 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
40 private readonly string m_firstname; 45 private readonly string m_firstname;
41 private readonly string m_lastname; 46 private readonly string m_lastname;
42 private readonly Vector3 m_startPos; 47 private readonly Vector3 m_startPos;
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index d0b5a94..f38af46 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -75,19 +75,25 @@ namespace OpenSim.Region.OptionalModules.World.NPC
75 // We are close enough to the target 75 // We are close enough to the target
76 m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0}", presence.Name); 76 m_log.DebugFormat("[NPC MODULE]: Stopping movement of npc {0}", presence.Name);
77 77
78 presence.Velocity = Vector3.Zero;
79 presence.AbsolutePosition = presence.MoveToPositionTarget;
80 presence.ResetMoveToTarget();
81
78 if (presence.PhysicsActor.Flying) 82 if (presence.PhysicsActor.Flying)
79 { 83 {
80 Vector3 targetPos = presence.MoveToPositionTarget; 84 for (int i = 0; i < 5; i++)
81 float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y]; 85 presence.PhysicsActor.IsColliding = true;
82 if (targetPos.Z - terrainHeight < 0.2) 86
83 { 87// Vector3 targetPos = presence.MoveToPositionTarget;
88 if (m_avatars[presence.UUID].LandAtTarget)
84 presence.PhysicsActor.Flying = false; 89 presence.PhysicsActor.Flying = false;
85 }
86 }
87 90
88 presence.Velocity = Vector3.Zero; 91// float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y];
89 presence.AbsolutePosition = presence.MoveToPositionTarget; 92// if (targetPos.Z - terrainHeight < 0.2)
90 presence.ResetMoveToTarget(); 93// {
94// presence.PhysicsActor.Flying = false;
95// }
96 }
91 97
92 // FIXME: This doesn't work 98 // FIXME: This doesn't work
93 if (presence.PhysicsActor.Flying) 99 if (presence.PhysicsActor.Flying)
@@ -217,7 +223,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
217 return npcAvatar.AgentId; 223 return npcAvatar.AgentId;
218 } 224 }
219 225
220 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly) 226 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget)
221 { 227 {
222 lock (m_avatars) 228 lock (m_avatars)
223 { 229 {
@@ -227,8 +233,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
227 scene.TryGetScenePresence(agentID, out sp); 233 scene.TryGetScenePresence(agentID, out sp);
228 234
229 m_log.DebugFormat( 235 m_log.DebugFormat(
230 "[NPC MODULE]: Moving {0} to {1} in {2}", sp.Name, pos, scene.RegionInfo.RegionName); 236 "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
237 sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget);
231 238
239 m_avatars[agentID].LandAtTarget = landAtTarget;
232 sp.MoveToTarget(pos, noFly); 240 sp.MoveToTarget(pos, noFly);
233 241
234 return true; 242 return true;
@@ -263,6 +271,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC
263 { 271 {
264 if (m_avatars.ContainsKey(agentID)) 272 if (m_avatars.ContainsKey(agentID))
265 { 273 {
274 ScenePresence sp;
275 scene.TryGetScenePresence(agentID, out sp);
276
266 m_avatars[agentID].Say(text); 277 m_avatars[agentID].Say(text);
267 278
268 return true; 279 return true;
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
index 81497d5..d220fab 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
@@ -113,7 +113,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
113 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); 113 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
114 114
115 Vector3 targetPos = startPos + new Vector3(0, 0, 10); 115 Vector3 targetPos = startPos + new Vector3(0, 0, 10);
116 npcModule.MoveToTarget(npc.UUID, scene, targetPos, false); 116 npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false);
117 117
118 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); 118 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
119 119
@@ -135,7 +135,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
135 // Try a second movement 135 // Try a second movement
136 startPos = npc.AbsolutePosition; 136 startPos = npc.AbsolutePosition;
137 targetPos = startPos + new Vector3(10, 0, 0); 137 targetPos = startPos + new Vector3(10, 0, 0);
138 npcModule.MoveToTarget(npc.UUID, scene, targetPos, false); 138 npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false);
139 139
140 scene.Update(); 140 scene.Update();
141 141