aboutsummaryrefslogtreecommitdiffstatshomepage
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
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
-rw-r--r--OpenSim/Region/Framework/Interfaces/INPCModule.cs5
-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
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs11
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs1
7 files changed, 44 insertions, 17 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/INPCModule.cs b/OpenSim/Region/Framework/Interfaces/INPCModule.cs
index 06296c9..08b973d 100644
--- a/OpenSim/Region/Framework/Interfaces/INPCModule.cs
+++ b/OpenSim/Region/Framework/Interfaces/INPCModule.cs
@@ -71,8 +71,11 @@ namespace OpenSim.Region.Framework.Interfaces
71 /// If true, then the avatar will attempt to walk to the location even if it's up in the air. 71 /// If true, then the avatar will attempt to walk to the location even if it's up in the air.
72 /// This is to allow walking on prims. 72 /// This is to allow walking on prims.
73 /// </param> 73 /// </param>
74 /// <param name="landAtTarget">
75 /// If true and the avatar is flying when it reaches the target, land.
76 /// </param>
74 /// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns> 77 /// <returns>True if the operation succeeded, false if there was no such agent or the agent was not an NPC</returns>
75 bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly); 78 bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget);
76 79
77 /// <summary> 80 /// <summary>
78 /// Stop the NPC's current movement. 81 /// Stop the NPC's current movement.
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
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 4f461ad..ecf5983 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -305,10 +305,12 @@ namespace OpenSim.Region.Physics.OdePlugin
305 { 305 {
306 m_iscolliding = true; 306 m_iscolliding = true;
307 } 307 }
308
308 if (m_wascolliding != m_iscolliding) 309 if (m_wascolliding != m_iscolliding)
309 { 310 {
310 //base.SendCollisionUpdate(new CollisionEventUpdate()); 311 //base.SendCollisionUpdate(new CollisionEventUpdate());
311 } 312 }
313
312 m_wascolliding = m_iscolliding; 314 m_wascolliding = m_iscolliding;
313 } 315 }
314 } 316 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 9b5d8d9..f83304b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -2209,11 +2209,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2209 if (module != null) 2209 if (module != null)
2210 { 2210 {
2211 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); 2211 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
2212 module.MoveToTarget(new UUID(npc.m_string), World, pos, false); 2212 module.MoveToTarget(new UUID(npc.m_string), World, pos, false, true);
2213 } 2213 }
2214 } 2214 }
2215 2215
2216 public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector position, int noFly) 2216 public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector position, int moveParams)
2217 { 2217 {
2218 CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget"); 2218 CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget");
2219 2219
@@ -2221,7 +2221,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2221 if (module != null) 2221 if (module != null)
2222 { 2222 {
2223 Vector3 pos = new Vector3((float)position.x, (float)position.y, (float)position.z); 2223 Vector3 pos = new Vector3((float)position.x, (float)position.y, (float)position.z);
2224 module.MoveToTarget(new UUID(npc.m_string), World, pos, noFly != 0); 2224 module.MoveToTarget(
2225 new UUID(npc.m_string),
2226 World,
2227 pos,
2228 (moveParams & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
2229 (moveParams & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0);
2225 } 2230 }
2226 } 2231 }
2227 2232
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index 9ed894c..e82c281 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -594,6 +594,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
594 // Constants for osNpc* functions 594 // Constants for osNpc* functions
595 public const int OS_NPC_FLY = 0; 595 public const int OS_NPC_FLY = 0;
596 public const int OS_NPC_NO_FLY = 1; 596 public const int OS_NPC_NO_FLY = 1;
597 public const int OS_NPC_LAND_AT_TARGET = 2;
597 598
598 public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED"; 599 public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED";
599 public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED"; 600 public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED";