diff options
author | Justin Clark-Casey (justincc) | 2012-01-28 00:00:12 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-01-28 00:00:12 +0000 |
commit | 7837c611fb483dc776b531306d3d791e8f177aab (patch) | |
tree | 01c728a0f46a209eb0267bc166f70260748f4ca8 /OpenSim | |
parent | Increment LPS script stat for OSSL functions that were not already doing this (diff) | |
download | opensim-SC_OLD-7837c611fb483dc776b531306d3d791e8f177aab.zip opensim-SC_OLD-7837c611fb483dc776b531306d3d791e8f177aab.tar.gz opensim-SC_OLD-7837c611fb483dc776b531306d3d791e8f177aab.tar.bz2 opensim-SC_OLD-7837c611fb483dc776b531306d3d791e8f177aab.tar.xz |
Add OS_NPC_SENSE_AS_AGENT option to osNpcCreate().
This allows NPCs to be sensed as agents by LSL sensors rather than as a specific NPC type (which is currently an OpenSimulator-only extension).
Wiki doc on this and other recent NPC functions will follow soon
Diffstat (limited to 'OpenSim')
7 files changed, 83 insertions, 17 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/INPCModule.cs b/OpenSim/Region/Framework/Interfaces/INPCModule.cs index b428c40..2731291 100644 --- a/OpenSim/Region/Framework/Interfaces/INPCModule.cs +++ b/OpenSim/Region/Framework/Interfaces/INPCModule.cs | |||
@@ -31,6 +31,19 @@ using OpenSim.Region.Framework.Scenes; | |||
31 | 31 | ||
32 | namespace OpenSim.Region.Framework.Interfaces | 32 | namespace OpenSim.Region.Framework.Interfaces |
33 | { | 33 | { |
34 | /// <summary> | ||
35 | /// Temporary interface. More methods to come at some point to make NPCs more object oriented rather than | ||
36 | /// controlling purely through module level interface calls (e.g. sit/stand). | ||
37 | /// </summary> | ||
38 | public interface INPC | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// Should this NPC be sensed by LSL sensors as an 'agent' (interpreted here to mean a normal user) | ||
42 | /// rather than an OpenSim specific NPC extension? | ||
43 | /// </summary> | ||
44 | bool SenseAsAgent { get; } | ||
45 | } | ||
46 | |||
34 | public interface INPCModule | 47 | public interface INPCModule |
35 | { | 48 | { |
36 | /// <summary> | 49 | /// <summary> |
@@ -39,10 +52,21 @@ namespace OpenSim.Region.Framework.Interfaces | |||
39 | /// <param name="firstname"></param> | 52 | /// <param name="firstname"></param> |
40 | /// <param name="lastname"></param> | 53 | /// <param name="lastname"></param> |
41 | /// <param name="position"></param> | 54 | /// <param name="position"></param> |
55 | /// <param name="senseAsAgent"> | ||
56 | /// Make the NPC show up as an agent on LSL sensors. The default is that they | ||
57 | /// show up as the NPC type instead, but this is currently an OpenSim-only extension. | ||
58 | /// </param> | ||
42 | /// <param name="scene"></param> | 59 | /// <param name="scene"></param> |
43 | /// <param name="appearance">The avatar appearance to use for the new NPC.</param> | 60 | /// <param name="appearance">The avatar appearance to use for the new NPC.</param> |
44 | /// <returns>The UUID of the ScenePresence created.</returns> | 61 | /// <returns>The UUID of the ScenePresence created.</returns> |
45 | UUID CreateNPC(string firstname, string lastname, Vector3 position, UUID owner, Scene scene, AvatarAppearance appearance); | 62 | UUID CreateNPC( |
63 | string firstname, | ||
64 | string lastname, | ||
65 | Vector3 position, | ||
66 | UUID owner, | ||
67 | bool senseAsAgent, | ||
68 | Scene scene, | ||
69 | AvatarAppearance appearance); | ||
46 | 70 | ||
47 | /// <summary> | 71 | /// <summary> |
48 | /// Check if the agent is an NPC. | 72 | /// Check if the agent is an NPC. |
@@ -53,6 +77,14 @@ namespace OpenSim.Region.Framework.Interfaces | |||
53 | bool IsNPC(UUID agentID, Scene scene); | 77 | bool IsNPC(UUID agentID, Scene scene); |
54 | 78 | ||
55 | /// <summary> | 79 | /// <summary> |
80 | /// Get the NPC. This is not currently complete - manipulation of NPCs still occurs through the region interface | ||
81 | /// </summary> | ||
82 | /// <param name="agentID"></param> | ||
83 | /// <param name="scene"></param> | ||
84 | /// <returns>The NPC. null if it does not exist.</returns> | ||
85 | INPC GetNPC(UUID agentID, Scene scene); | ||
86 | |||
87 | /// <summary> | ||
56 | /// Check if the caller has permission to manipulate the given NPC. | 88 | /// Check if the caller has permission to manipulate the given NPC. |
57 | /// </summary> | 89 | /// </summary> |
58 | /// <param name="npcID"></param> | 90 | /// <param name="npcID"></param> |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 6a6c4c3..6d40a92 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs | |||
@@ -31,13 +31,16 @@ using System.Net; | |||
31 | using OpenMetaverse; | 31 | using OpenMetaverse; |
32 | using OpenMetaverse.Packets; | 32 | using OpenMetaverse.Packets; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Region.Framework.Interfaces; | ||
34 | using OpenSim.Region.Framework.Scenes; | 35 | using OpenSim.Region.Framework.Scenes; |
35 | using OpenSim.Region.CoreModules.World.Estate; | 36 | using OpenSim.Region.CoreModules.World.Estate; |
36 | 37 | ||
37 | namespace OpenSim.Region.OptionalModules.World.NPC | 38 | namespace OpenSim.Region.OptionalModules.World.NPC |
38 | { | 39 | { |
39 | public class NPCAvatar : IClientAPI | 40 | public class NPCAvatar : IClientAPI, INPC |
40 | { | 41 | { |
42 | public bool SenseAsAgent { get; set; } | ||
43 | |||
41 | private readonly string m_firstname; | 44 | private readonly string m_firstname; |
42 | private readonly string m_lastname; | 45 | private readonly string m_lastname; |
43 | private readonly Vector3 m_startPos; | 46 | private readonly Vector3 m_startPos; |
@@ -45,13 +48,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
45 | private readonly Scene m_scene; | 48 | private readonly Scene m_scene; |
46 | private readonly UUID m_ownerID; | 49 | private readonly UUID m_ownerID; |
47 | 50 | ||
48 | public NPCAvatar(string firstname, string lastname, Vector3 position, UUID ownerID, Scene scene) | 51 | public NPCAvatar( |
52 | string firstname, string lastname, Vector3 position, UUID ownerID, bool senseAsAgent, Scene scene) | ||
49 | { | 53 | { |
50 | m_firstname = firstname; | 54 | m_firstname = firstname; |
51 | m_lastname = lastname; | 55 | m_lastname = lastname; |
52 | m_startPos = position; | 56 | m_startPos = position; |
53 | m_scene = scene; | 57 | m_scene = scene; |
54 | m_ownerID = ownerID; | 58 | m_ownerID = ownerID; |
59 | SenseAsAgent = senseAsAgent; | ||
55 | } | 60 | } |
56 | 61 | ||
57 | public IScene Scene | 62 | public IScene Scene |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index d90309f..3831d7a 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -109,9 +109,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
109 | } | 109 | } |
110 | 110 | ||
111 | public UUID CreateNPC( | 111 | public UUID CreateNPC( |
112 | string firstname, string lastname, Vector3 position, UUID owner, Scene scene, AvatarAppearance appearance) | 112 | string firstname, |
113 | string lastname, | ||
114 | Vector3 position, | ||
115 | UUID owner, | ||
116 | bool senseAsAgent, | ||
117 | Scene scene, | ||
118 | AvatarAppearance appearance) | ||
113 | { | 119 | { |
114 | NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, scene); | 120 | NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, senseAsAgent, scene); |
115 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); | 121 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); |
116 | 122 | ||
117 | m_log.DebugFormat( | 123 | m_log.DebugFormat( |
@@ -266,6 +272,17 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
266 | return UUID.Zero; | 272 | return UUID.Zero; |
267 | } | 273 | } |
268 | 274 | ||
275 | public INPC GetNPC(UUID agentID, Scene scene) | ||
276 | { | ||
277 | lock (m_avatars) | ||
278 | { | ||
279 | if (m_avatars.ContainsKey(agentID)) | ||
280 | return m_avatars[agentID]; | ||
281 | else | ||
282 | return null; | ||
283 | } | ||
284 | } | ||
285 | |||
269 | public bool DeleteNPC(UUID agentID, Scene scene) | 286 | public bool DeleteNPC(UUID agentID, Scene scene) |
270 | { | 287 | { |
271 | lock (m_avatars) | 288 | lock (m_avatars) |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index d21d601..d507822 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs | |||
@@ -109,7 +109,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
109 | afm.SetAppearance(sp, originalTe, null); | 109 | afm.SetAppearance(sp, originalTe, null); |
110 | 110 | ||
111 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | 111 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); |
112 | UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, scene, sp.Appearance); | 112 | UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance); |
113 | 113 | ||
114 | ScenePresence npc = scene.GetScenePresence(npcId); | 114 | ScenePresence npc = scene.GetScenePresence(npcId); |
115 | 115 | ||
@@ -129,7 +129,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
129 | 129 | ||
130 | Vector3 startPos = new Vector3(128, 128, 30); | 130 | Vector3 startPos = new Vector3(128, 128, 30); |
131 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | 131 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); |
132 | UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, scene, sp.Appearance); | 132 | UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance); |
133 | 133 | ||
134 | npcModule.DeleteNPC(npcId, scene); | 134 | npcModule.DeleteNPC(npcId, scene); |
135 | 135 | ||
@@ -157,7 +157,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
157 | am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); | 157 | am.RezSingleAttachmentFromInventory(sp, attItemId, (uint)AttachmentPoint.Chest); |
158 | 158 | ||
159 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | 159 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); |
160 | UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, scene, sp.Appearance); | 160 | UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), UUID.Zero, true, scene, sp.Appearance); |
161 | 161 | ||
162 | ScenePresence npc = scene.GetScenePresence(npcId); | 162 | ScenePresence npc = scene.GetScenePresence(npcId); |
163 | 163 | ||
@@ -189,7 +189,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
189 | 189 | ||
190 | Vector3 startPos = new Vector3(128, 128, 30); | 190 | Vector3 startPos = new Vector3(128, 128, 30); |
191 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | 191 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); |
192 | UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, scene, sp.Appearance); | 192 | UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance); |
193 | 193 | ||
194 | ScenePresence npc = scene.GetScenePresence(npcId); | 194 | ScenePresence npc = scene.GetScenePresence(npcId); |
195 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | 195 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
@@ -260,7 +260,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
260 | 260 | ||
261 | Vector3 startPos = new Vector3(128, 128, 30); | 261 | Vector3 startPos = new Vector3(128, 128, 30); |
262 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | 262 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); |
263 | UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, scene, sp.Appearance); | 263 | UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance); |
264 | 264 | ||
265 | ScenePresence npc = scene.GetScenePresence(npcId); | 265 | ScenePresence npc = scene.GetScenePresence(npcId); |
266 | SceneObjectPart part = SceneHelpers.AddSceneObject(scene); | 266 | SceneObjectPart part = SceneHelpers.AddSceneObject(scene); |
@@ -293,7 +293,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
293 | Vector3 startPos = new Vector3(1, 1, 1); | 293 | Vector3 startPos = new Vector3(1, 1, 1); |
294 | 294 | ||
295 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); | 295 | INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); |
296 | UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, scene, sp.Appearance); | 296 | UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, UUID.Zero, true, scene, sp.Appearance); |
297 | 297 | ||
298 | ScenePresence npc = scene.GetScenePresence(npcId); | 298 | ScenePresence npc = scene.GetScenePresence(npcId); |
299 | SceneObjectPart part = SceneHelpers.AddSceneObject(scene); | 299 | SceneObjectPart part = SceneHelpers.AddSceneObject(scene); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index a2f5c92..b1583eb 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -2233,7 +2233,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2233 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); | 2233 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); |
2234 | m_host.AddScriptLPS(1); | 2234 | m_host.AddScriptLPS(1); |
2235 | 2235 | ||
2236 | return NpcCreate(firstname, lastname, position, notecard, true); | 2236 | return NpcCreate(firstname, lastname, position, notecard, false, true); |
2237 | } | 2237 | } |
2238 | 2238 | ||
2239 | public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) | 2239 | public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) |
@@ -2241,10 +2241,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2241 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); | 2241 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); |
2242 | m_host.AddScriptLPS(1); | 2242 | m_host.AddScriptLPS(1); |
2243 | 2243 | ||
2244 | return NpcCreate(firstname, lastname, position, notecard, (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0); | 2244 | return NpcCreate( |
2245 | firstname, lastname, position, notecard, | ||
2246 | (options & ScriptBaseClass.OS_NPC_NOT_OWNED) == 0, | ||
2247 | (options & ScriptBaseClass.OS_NPC_SENSE_AS_AGENT) == 0); | ||
2245 | } | 2248 | } |
2246 | 2249 | ||
2247 | private LSL_Key NpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, bool owned) | 2250 | private LSL_Key NpcCreate( |
2251 | string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) | ||
2248 | { | 2252 | { |
2249 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | 2253 | INPCModule module = World.RequestModuleInterface<INPCModule>(); |
2250 | if (module != null) | 2254 | if (module != null) |
@@ -2281,7 +2285,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2281 | lastname, | 2285 | lastname, |
2282 | new Vector3((float) position.x, (float) position.y, (float) position.z), | 2286 | new Vector3((float) position.x, (float) position.y, (float) position.z), |
2283 | ownerID, | 2287 | ownerID, |
2284 | World,appearance); | 2288 | senseAsAgent, |
2289 | World, | ||
2290 | appearance); | ||
2285 | 2291 | ||
2286 | return new LSL_Key(x.ToString()); | 2292 | return new LSL_Key(x.ToString()); |
2287 | } | 2293 | } |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 8356dce..3e0e452 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs | |||
@@ -447,9 +447,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins | |||
447 | 447 | ||
448 | Action<ScenePresence> senseEntity = new Action<ScenePresence>(delegate(ScenePresence presence) | 448 | Action<ScenePresence> senseEntity = new Action<ScenePresence>(delegate(ScenePresence presence) |
449 | { | 449 | { |
450 | if ((ts.type & NPC) == 0 && presence.PresenceType == PresenceType.Npc) | 450 | if ((ts.type & NPC) == 0 |
451 | && presence.PresenceType == PresenceType.Npc | ||
452 | && !npcModule.GetNPC(presence.UUID, presence.Scene).SenseAsAgent) | ||
451 | return; | 453 | return; |
452 | if ((ts.type & AGENT) == 0 && presence.PresenceType == PresenceType.User) | 454 | |
455 | if ((ts.type & AGENT) == 0 | ||
456 | && (presence.PresenceType == PresenceType.User | ||
457 | || npcModule.GetNPC(presence.UUID, presence.Scene).SenseAsAgent)) | ||
453 | return; | 458 | return; |
454 | 459 | ||
455 | if (presence.IsDeleted || presence.IsChildAgent || presence.GodLevel > 0.0) | 460 | if (presence.IsDeleted || presence.IsChildAgent || presence.GodLevel > 0.0) |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index ab2c543..a69b4cb 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | |||
@@ -616,6 +616,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
616 | 616 | ||
617 | public const int OS_NPC_CREATOR_OWNED = 0x1; | 617 | public const int OS_NPC_CREATOR_OWNED = 0x1; |
618 | public const int OS_NPC_NOT_OWNED = 0x2; | 618 | public const int OS_NPC_NOT_OWNED = 0x2; |
619 | public const int OS_NPC_SENSE_AS_AGENT = 0x4; | ||
619 | 620 | ||
620 | public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED"; | 621 | public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED"; |
621 | public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED"; | 622 | public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED"; |