aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs1401
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs8
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs24
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs341
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs13
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs115
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs53
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs46
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Helpers.cs28
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs77
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs134
13 files changed, 1487 insertions, 759 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 82de06f..17e3de1 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -59,6 +59,7 @@ using GridRegion = OpenSim.Services.Interfaces.GridRegion;
59using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo; 59using PresenceInfo = OpenSim.Services.Interfaces.PresenceInfo;
60using PrimType = OpenSim.Region.Framework.Scenes.PrimType; 60using PrimType = OpenSim.Region.Framework.Scenes.PrimType;
61using AssetLandmark = OpenSim.Framework.AssetLandmark; 61using AssetLandmark = OpenSim.Framework.AssetLandmark;
62using RegionFlags = OpenSim.Framework.RegionFlags;
62 63
63using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; 64using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
64using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; 65using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
@@ -341,7 +342,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
341 return GetLinkParts(m_host, linkType); 342 return GetLinkParts(m_host, linkType);
342 } 343 }
343 344
344 private List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType) 345 public static List<SceneObjectPart> GetLinkParts(SceneObjectPart part, int linkType)
345 { 346 {
346 List<SceneObjectPart> ret = new List<SceneObjectPart>(); 347 List<SceneObjectPart> ret = new List<SceneObjectPart>();
347 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 348 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
@@ -426,14 +427,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
426 return key; 427 return key;
427 } 428 }
428 429
429 // convert a LSL_Rotation to a Quaternion
430 public static Quaternion Rot2Quaternion(LSL_Rotation r)
431 {
432 Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
433 q.Normalize();
434 return q;
435 }
436
437 //These are the implementations of the various ll-functions used by the LSL scripts. 430 //These are the implementations of the various ll-functions used by the LSL scripts.
438 public LSL_Float llSin(double f) 431 public LSL_Float llSin(double f)
439 { 432 {
@@ -1240,9 +1233,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1240 public LSL_Float llGround(LSL_Vector offset) 1233 public LSL_Float llGround(LSL_Vector offset)
1241 { 1234 {
1242 m_host.AddScriptLPS(1); 1235 m_host.AddScriptLPS(1);
1243 Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x, 1236 Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
1244 (float)offset.y,
1245 (float)offset.z);
1246 1237
1247 //Get the slope normal. This gives us the equation of the plane tangent to the slope. 1238 //Get the slope normal. This gives us the equation of the plane tangent to the slope.
1248 LSL_Vector vsn = llGroundNormal(offset); 1239 LSL_Vector vsn = llGroundNormal(offset);
@@ -1492,31 +1483,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1492 if (part == null || part.ParentGroup.IsDeleted) 1483 if (part == null || part.ParentGroup.IsDeleted)
1493 return; 1484 return;
1494 1485
1495 if (scale.x < 0.01) 1486 // First we need to check whether or not we need to clamp the size of a physics-enabled prim
1496 scale.x = 0.01;
1497 if (scale.y < 0.01)
1498 scale.y = 0.01;
1499 if (scale.z < 0.01)
1500 scale.z = 0.01;
1501
1502 PhysicsActor pa = part.ParentGroup.RootPart.PhysActor; 1487 PhysicsActor pa = part.ParentGroup.RootPart.PhysActor;
1503
1504 if (pa != null && pa.IsPhysical) 1488 if (pa != null && pa.IsPhysical)
1505 { 1489 {
1506 if (scale.x > World.m_maxPhys) 1490 scale.x = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.x));
1507 scale.x = World.m_maxPhys; 1491 scale.y = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.y));
1508 if (scale.y > World.m_maxPhys) 1492 scale.z = Math.Max(World.m_minPhys, Math.Min(World.m_maxPhys, scale.z));
1509 scale.y = World.m_maxPhys; 1493 }
1510 if (scale.z > World.m_maxPhys) 1494 else
1511 scale.z = World.m_maxPhys; 1495 {
1496 // If not physical, then we clamp the scale to the non-physical min/max
1497 scale.x = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.x));
1498 scale.y = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.y));
1499 scale.z = Math.Max(World.m_minNonphys, Math.Min(World.m_maxNonphys, scale.z));
1512 } 1500 }
1513
1514 if (scale.x > World.m_maxNonphys)
1515 scale.x = World.m_maxNonphys;
1516 if (scale.y > World.m_maxNonphys)
1517 scale.y = World.m_maxNonphys;
1518 if (scale.z > World.m_maxNonphys)
1519 scale.z = World.m_maxNonphys;
1520 1501
1521 Vector3 tmp = part.Scale; 1502 Vector3 tmp = part.Scale;
1522 tmp.X = (float)scale.x; 1503 tmp.X = (float)scale.x;
@@ -1590,7 +1571,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1590 if (face == ScriptBaseClass.ALL_SIDES) 1571 if (face == ScriptBaseClass.ALL_SIDES)
1591 face = SceneObjectPart.ALL_SIDES; 1572 face = SceneObjectPart.ALL_SIDES;
1592 1573
1593 m_host.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); 1574 m_host.SetFaceColorAlpha(face, color, null);
1594 } 1575 }
1595 1576
1596 public void SetTexGen(SceneObjectPart part, int face,int style) 1577 public void SetTexGen(SceneObjectPart part, int face,int style)
@@ -2202,7 +2183,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2202 pos.x > (Constants.RegionSize + 10) || // return FALSE if more than 10 meters into a east-adjacent region. 2183 pos.x > (Constants.RegionSize + 10) || // return FALSE if more than 10 meters into a east-adjacent region.
2203 pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region. 2184 pos.y < -10.0 || // return FALSE if more than 10 meters into a south-adjacent region.
2204 pos.y > (Constants.RegionSize + 10) || // return FALSE if more than 10 meters into a north-adjacent region. 2185 pos.y > (Constants.RegionSize + 10) || // return FALSE if more than 10 meters into a north-adjacent region.
2205 pos.z > 4096 // return FALSE if altitude than 4096m 2186 pos.z > Constants.RegionHeight // return FALSE if altitude than 4096m
2206 ) 2187 )
2207 ) 2188 )
2208 { 2189 {
@@ -2213,14 +2194,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2213 // this could possibly be done in the above else-if block, but we're doing the check here to keep the code easier to read. 2194 // this could possibly be done in the above else-if block, but we're doing the check here to keep the code easier to read.
2214 2195
2215 Vector3 objectPos = m_host.ParentGroup.RootPart.AbsolutePosition; 2196 Vector3 objectPos = m_host.ParentGroup.RootPart.AbsolutePosition;
2216 LandData here = World.GetLandData((float)objectPos.X, (float)objectPos.Y); 2197 LandData here = World.GetLandData(objectPos);
2217 LandData there = World.GetLandData((float)pos.x, (float)pos.y); 2198 LandData there = World.GetLandData(pos);
2218 2199
2219 // we're only checking prim limits if it's moving to a different parcel under the assumption that if the object got onto the parcel without exceeding the prim limits. 2200 // we're only checking prim limits if it's moving to a different parcel under the assumption that if the object got onto the parcel without exceeding the prim limits.
2220 2201
2221 bool sameParcel = here.GlobalID == there.GlobalID; 2202 bool sameParcel = here.GlobalID == there.GlobalID;
2222 2203
2223 if (!sameParcel && !World.Permissions.CanObjectEntry(m_host.UUID, false, new Vector3((float)pos.x, (float)pos.y, (float)pos.z))) 2204 if (!sameParcel && !World.Permissions.CanRezObject(
2205 m_host.ParentGroup.PrimCount, m_host.ParentGroup.OwnerID, pos))
2224 { 2206 {
2225 return 0; 2207 return 0;
2226 } 2208 }
@@ -2279,16 +2261,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2279 if (part.ParentGroup.RootPart == part) 2261 if (part.ParentGroup.RootPart == part)
2280 { 2262 {
2281 SceneObjectGroup parent = part.ParentGroup; 2263 SceneObjectGroup parent = part.ParentGroup;
2282 Vector3 dest = new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z); 2264 if (!World.Permissions.CanObjectEntry(parent.UUID, false, (Vector3)toPos))
2283 if (!World.Permissions.CanObjectEntry(parent.UUID, false, dest))
2284 return; 2265 return;
2285 Util.FireAndForget(delegate(object x) { 2266 Util.FireAndForget(delegate(object x) {
2286 parent.UpdateGroupPosition(dest); 2267 parent.UpdateGroupPosition((Vector3)toPos);
2287 }); 2268 });
2288 } 2269 }
2289 else 2270 else
2290 { 2271 {
2291 part.OffsetPosition = new Vector3((float)toPos.x, (float)toPos.y, (float)toPos.z); 2272 part.OffsetPosition = (Vector3)toPos;
2292 SceneObjectGroup parent = part.ParentGroup; 2273 SceneObjectGroup parent = part.ParentGroup;
2293 parent.HasGroupChanged = true; 2274 parent.HasGroupChanged = true;
2294 parent.ScheduleGroupForTerseUpdate(); 2275 parent.ScheduleGroupForTerseUpdate();
@@ -2326,7 +2307,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2326 pos = part.AbsolutePosition; 2307 pos = part.AbsolutePosition;
2327 } 2308 }
2328 2309
2329 return new LSL_Vector(pos.X, pos.Y, pos.Z); 2310// m_log.DebugFormat("[LSL API]: Returning {0} in GetPartLocalPos()", pos);
2311
2312 return new LSL_Vector(pos);
2330 } 2313 }
2331 2314
2332 public void llSetRot(LSL_Rotation rot) 2315 public void llSetRot(LSL_Rotation rot)
@@ -2334,26 +2317,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2334 m_host.AddScriptLPS(1); 2317 m_host.AddScriptLPS(1);
2335 2318
2336 // try to let this work as in SL... 2319 // try to let this work as in SL...
2337 if (m_host.LinkNum < 2) 2320 if (m_host.ParentID == 0)
2338 { 2321 {
2339 // Special case: If we are root, rotate complete SOG to new 2322 // special case: If we are root, rotate complete SOG to new rotation
2340 // rotation. 2323 SetRot(m_host, rot);
2341 // We are root if the link number is 0 (single prim) or 1
2342 // (root prim). ParentID may be nonzero in attachments and
2343 // using it would cause attachments and HUDs to rotate
2344 // to the wrong positions.
2345
2346 SetRot(m_host, Rot2Quaternion(rot));
2347 } 2324 }
2348 else 2325 else
2349 { 2326 {
2350 // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask. 2327 // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
2351 SceneObjectPart rootPart; 2328 SceneObjectPart rootPart = m_host.ParentGroup.RootPart;
2352 if (m_host.ParentGroup != null) // better safe than sorry 2329 if (rootPart != null) // better safe than sorry
2353 { 2330 {
2354 rootPart = m_host.ParentGroup.RootPart; 2331 SetRot(m_host, rootPart.RotationOffset * (Quaternion)rot);
2355 if (rootPart != null)
2356 SetRot(m_host, rootPart.RotationOffset * Rot2Quaternion(rot));
2357 } 2332 }
2358 } 2333 }
2359 2334
@@ -2363,8 +2338,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2363 public void llSetLocalRot(LSL_Rotation rot) 2338 public void llSetLocalRot(LSL_Rotation rot)
2364 { 2339 {
2365 m_host.AddScriptLPS(1); 2340 m_host.AddScriptLPS(1);
2366 2341 SetRot(m_host, rot);
2367 SetRot(m_host, Rot2Quaternion(rot));
2368 ScriptSleep(200); 2342 ScriptSleep(200);
2369 } 2343 }
2370 2344
@@ -2476,7 +2450,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2476 if (local != 0) 2450 if (local != 0)
2477 force *= llGetRot(); 2451 force *= llGetRot();
2478 2452
2479 m_host.ParentGroup.RootPart.SetForce(new Vector3((float)force.x, (float)force.y, (float)force.z)); 2453 m_host.ParentGroup.RootPart.SetForce(force);
2480 } 2454 }
2481 } 2455 }
2482 2456
@@ -2488,10 +2462,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2488 2462
2489 if (!m_host.ParentGroup.IsDeleted) 2463 if (!m_host.ParentGroup.IsDeleted)
2490 { 2464 {
2491 Vector3 tmpForce = m_host.ParentGroup.RootPart.GetForce(); 2465 force = m_host.ParentGroup.RootPart.GetForce();
2492 force.x = tmpForce.X;
2493 force.y = tmpForce.Y;
2494 force.z = tmpForce.Z;
2495 } 2466 }
2496 2467
2497 return force; 2468 return force;
@@ -2500,8 +2471,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2500 public LSL_Integer llTarget(LSL_Vector position, double range) 2471 public LSL_Integer llTarget(LSL_Vector position, double range)
2501 { 2472 {
2502 m_host.AddScriptLPS(1); 2473 m_host.AddScriptLPS(1);
2503 return m_host.ParentGroup.registerTargetWaypoint( 2474 return m_host.ParentGroup.registerTargetWaypoint(position,
2504 new Vector3((float)position.x, (float)position.y, (float)position.z), (float)range); 2475 (float)range);
2505 } 2476 }
2506 2477
2507 public void llTargetRemove(int number) 2478 public void llTargetRemove(int number)
@@ -2513,8 +2484,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2513 public LSL_Integer llRotTarget(LSL_Rotation rot, double error) 2484 public LSL_Integer llRotTarget(LSL_Rotation rot, double error)
2514 { 2485 {
2515 m_host.AddScriptLPS(1); 2486 m_host.AddScriptLPS(1);
2516 return m_host.ParentGroup.registerRotTargetWaypoint( 2487 return m_host.ParentGroup.registerRotTargetWaypoint(rot, (float)error);
2517 new Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s), (float)error);
2518 } 2488 }
2519 2489
2520 public void llRotTargetRemove(int number) 2490 public void llRotTargetRemove(int number)
@@ -2526,7 +2496,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2526 public void llMoveToTarget(LSL_Vector target, double tau) 2496 public void llMoveToTarget(LSL_Vector target, double tau)
2527 { 2497 {
2528 m_host.AddScriptLPS(1); 2498 m_host.AddScriptLPS(1);
2529 m_host.MoveToTarget(new Vector3((float)target.x, (float)target.y, (float)target.z), (float)tau); 2499 m_host.MoveToTarget(target, (float)tau);
2530 } 2500 }
2531 2501
2532 public void llStopMoveToTarget() 2502 public void llStopMoveToTarget()
@@ -2539,7 +2509,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2539 { 2509 {
2540 m_host.AddScriptLPS(1); 2510 m_host.AddScriptLPS(1);
2541 //No energy force yet 2511 //No energy force yet
2542 Vector3 v = new Vector3((float)force.x, (float)force.y, (float)force.z); 2512 Vector3 v = force;
2543 if (v.Length() > 20000.0f) 2513 if (v.Length() > 20000.0f)
2544 { 2514 {
2545 v.Normalize(); 2515 v.Normalize();
@@ -2552,13 +2522,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2552 public void llApplyRotationalImpulse(LSL_Vector force, int local) 2522 public void llApplyRotationalImpulse(LSL_Vector force, int local)
2553 { 2523 {
2554 m_host.AddScriptLPS(1); 2524 m_host.AddScriptLPS(1);
2555 m_host.ParentGroup.RootPart.ApplyAngularImpulse(new Vector3((float)force.x, (float)force.y, (float)force.z), local != 0); 2525 m_host.ParentGroup.RootPart.ApplyAngularImpulse(force, local != 0);
2556 } 2526 }
2557 2527
2558 public void llSetTorque(LSL_Vector torque, int local) 2528 public void llSetTorque(LSL_Vector torque, int local)
2559 { 2529 {
2560 m_host.AddScriptLPS(1); 2530 m_host.AddScriptLPS(1);
2561 m_host.ParentGroup.RootPart.SetAngularImpulse(new Vector3((float)torque.x, (float)torque.y, (float)torque.z), local != 0); 2531 m_host.ParentGroup.RootPart.SetAngularImpulse(torque, local != 0);
2562 } 2532 }
2563 2533
2564 public LSL_Vector llGetTorque() 2534 public LSL_Vector llGetTorque()
@@ -3123,13 +3093,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3123 return; 3093 return;
3124 } 3094 }
3125 3095
3126 Vector3 llpos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
3127 Vector3 llvel = new Vector3((float)vel.x, (float)vel.y, (float)vel.z);
3128
3129 // need the magnitude later 3096 // need the magnitude later
3130 // float velmag = (float)Util.GetMagnitude(llvel); 3097 // float velmag = (float)Util.GetMagnitude(llvel);
3131 3098
3132 SceneObjectGroup new_group = World.RezObject(m_host, item, llpos, Rot2Quaternion(rot), llvel, param); 3099 SceneObjectGroup new_group = World.RezObject(m_host, item, pos, rot, vel, param);
3133 3100
3134 // If either of these are null, then there was an unknown error. 3101 // If either of these are null, then there was an unknown error.
3135 if (new_group == null) 3102 if (new_group == null)
@@ -3156,11 +3123,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3156 3123
3157 PhysicsActor pa = new_group.RootPart.PhysActor; 3124 PhysicsActor pa = new_group.RootPart.PhysActor;
3158 3125
3159 if (pa != null && pa.IsPhysical && llvel != Vector3.Zero) 3126 if (pa != null && pa.IsPhysical && (Vector3)vel != Vector3.Zero)
3160 { 3127 {
3161 float groupmass = new_group.GetMass(); 3128 float groupmass = new_group.GetMass();
3162 llvel *= -groupmass; 3129 vel *= -groupmass;
3163 llApplyImpulse(new LSL_Vector(llvel.X, llvel.Y,llvel.Z), 0); 3130 llApplyImpulse(vel, 0);
3164 } 3131 }
3165 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay) 3132 // Variable script delay? (see (http://wiki.secondlife.com/wiki/LSL_Delay)
3166 return; 3133 return;
@@ -3211,7 +3178,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3211 return; 3178 return;
3212 } 3179 }
3213 3180
3214 m_host.StartLookAt(Rot2Quaternion(r3 * r2 * r1), (float)strength, (float)damping); 3181 m_host.StartLookAt((Quaternion)(r3 * r2 * r1), (float)strength, (float)damping);
3215 } 3182 }
3216 } 3183 }
3217 3184
@@ -3637,7 +3604,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3637 } 3604 }
3638 else 3605 else
3639 { 3606 {
3640 m_host.RotLookAt(Rot2Quaternion(target), (float)strength, (float)damping); 3607 m_host.RotLookAt(target, (float)strength, (float)damping);
3641 } 3608 }
3642 } 3609 }
3643 3610
@@ -3718,7 +3685,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3718 3685
3719 protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain) 3686 protected void TargetOmega(SceneObjectPart part, LSL_Vector axis, double spinrate, double gain)
3720 { 3687 {
3721 part.UpdateAngularVelocity(new Vector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate))); 3688 part.UpdateAngularVelocity(axis * spinrate);
3722 } 3689 }
3723 3690
3724 public LSL_Integer llGetStartParameter() 3691 public LSL_Integer llGetStartParameter()
@@ -3932,7 +3899,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3932 try 3899 try
3933 { 3900 {
3934 foreach (SceneObjectPart part in parts) 3901 foreach (SceneObjectPart part in parts)
3935 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); 3902 part.SetFaceColorAlpha(face, color, null);
3936 } 3903 }
3937 finally 3904 finally
3938 { 3905 {
@@ -4364,7 +4331,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4364 World.RegionInfo.RegionName+" "+ 4331 World.RegionInfo.RegionName+" "+
4365 m_host.AbsolutePosition.ToString(), 4332 m_host.AbsolutePosition.ToString(),
4366 agentItem.ID, true, m_host.AbsolutePosition, 4333 agentItem.ID, true, m_host.AbsolutePosition,
4367 bucket); 4334 bucket, true);
4368 4335
4369 ScenePresence sp; 4336 ScenePresence sp;
4370 4337
@@ -4402,9 +4369,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4402 public void llSetText(string text, LSL_Vector color, double alpha) 4369 public void llSetText(string text, LSL_Vector color, double alpha)
4403 { 4370 {
4404 m_host.AddScriptLPS(1); 4371 m_host.AddScriptLPS(1);
4405 Vector3 av3 = new Vector3(Util.Clip((float)color.x, 0.0f, 1.0f), 4372 Vector3 av3 = Util.Clip(color, 0.0f, 1.0f);
4406 Util.Clip((float)color.y, 0.0f, 1.0f),
4407 Util.Clip((float)color.z, 0.0f, 1.0f));
4408 if (text.Length > 254) 4373 if (text.Length > 254)
4409 text = text.Remove(254); 4374 text = text.Remove(254);
4410 4375
@@ -4631,14 +4596,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4631 ScriptSleep(5000); 4596 ScriptSleep(5000);
4632 } 4597 }
4633 4598
4634 public void llTeleportAgent(string agent, string destination, LSL_Vector pos, LSL_Vector lookAt) 4599 public void llTeleportAgent(string agent, string destination, LSL_Vector targetPos, LSL_Vector targetLookAt)
4635 { 4600 {
4636 m_host.AddScriptLPS(1); 4601 m_host.AddScriptLPS(1);
4637 UUID agentId = new UUID(); 4602 UUID agentId = new UUID();
4638 4603
4639 Vector3 targetPos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
4640 Vector3 targetLookAt = new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z);
4641
4642 if (UUID.TryParse(agent, out agentId)) 4604 if (UUID.TryParse(agent, out agentId))
4643 { 4605 {
4644 ScenePresence presence = World.GetScenePresence(agentId); 4606 ScenePresence presence = World.GetScenePresence(agentId);
@@ -4667,15 +4629,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4667 } 4629 }
4668 } 4630 }
4669 4631
4670 public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector pos, LSL_Vector lookAt) 4632 public void llTeleportAgentGlobalCoords(string agent, LSL_Vector global_coords, LSL_Vector targetPos, LSL_Vector targetLookAt)
4671 { 4633 {
4672 m_host.AddScriptLPS(1); 4634 m_host.AddScriptLPS(1);
4673 UUID agentId = new UUID(); 4635 UUID agentId = new UUID();
4674 4636
4675 ulong regionHandle = Utils.UIntsToLong((uint)global_coords.x, (uint)global_coords.y); 4637 ulong regionHandle = Utils.UIntsToLong((uint)global_coords.x, (uint)global_coords.y);
4676 4638
4677 Vector3 targetPos = new Vector3((float)pos.x, (float)pos.y, (float)pos.z);
4678 Vector3 targetLookAt = new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z);
4679 if (UUID.TryParse(agent, out agentId)) 4639 if (UUID.TryParse(agent, out agentId))
4680 { 4640 {
4681 ScenePresence presence = World.GetScenePresence(agentId); 4641 ScenePresence presence = World.GetScenePresence(agentId);
@@ -4972,7 +4932,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
4972 distance_attenuation = 1f / normalized_units; 4932 distance_attenuation = 1f / normalized_units;
4973 } 4933 }
4974 4934
4975 Vector3 applied_linear_impulse = new Vector3((float)impulse.x, (float)impulse.y, (float)impulse.z); 4935 Vector3 applied_linear_impulse = impulse;
4976 { 4936 {
4977 float impulse_length = applied_linear_impulse.Length(); 4937 float impulse_length = applied_linear_impulse.Length();
4978 4938
@@ -5620,25 +5580,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5620 /// separated list. There is a space after 5580 /// separated list. There is a space after
5621 /// each comma. 5581 /// each comma.
5622 /// </summary> 5582 /// </summary>
5623
5624 public LSL_String llList2CSV(LSL_List src) 5583 public LSL_String llList2CSV(LSL_List src)
5625 { 5584 {
5626
5627 string ret = String.Empty;
5628 int x = 0;
5629
5630 m_host.AddScriptLPS(1); 5585 m_host.AddScriptLPS(1);
5631 5586
5632 if (src.Data.Length > 0) 5587 return string.Join(", ",
5633 { 5588 (new List<object>(src.Data)).ConvertAll<string>(o =>
5634 ret = src.Data[x++].ToString(); 5589 {
5635 for (; x < src.Data.Length; x++) 5590 return o.ToString();
5636 { 5591 }).ToArray());
5637 ret += ", "+src.Data[x].ToString();
5638 }
5639 }
5640
5641 return ret;
5642 } 5592 }
5643 5593
5644 /// <summary> 5594 /// <summary>
@@ -5937,27 +5887,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5937 /// Returns the index of the first occurrence of test 5887 /// Returns the index of the first occurrence of test
5938 /// in src. 5888 /// in src.
5939 /// </summary> 5889 /// </summary>
5940 5890 /// <param name="src">Source list</param>
5891 /// <param name="test">List to search for</param>
5892 /// <returns>
5893 /// The index number of the point in src where test was found if it was found.
5894 /// Otherwise returns -1
5895 /// </returns>
5941 public LSL_Integer llListFindList(LSL_List src, LSL_List test) 5896 public LSL_Integer llListFindList(LSL_List src, LSL_List test)
5942 { 5897 {
5943
5944 int index = -1; 5898 int index = -1;
5945 int length = src.Length - test.Length + 1; 5899 int length = src.Length - test.Length + 1;
5946 5900
5947 m_host.AddScriptLPS(1); 5901 m_host.AddScriptLPS(1);
5948 5902
5949 // If either list is empty, do not match 5903 // If either list is empty, do not match
5950
5951 if (src.Length != 0 && test.Length != 0) 5904 if (src.Length != 0 && test.Length != 0)
5952 { 5905 {
5953 for (int i = 0; i < length; i++) 5906 for (int i = 0; i < length; i++)
5954 { 5907 {
5955 if (src.Data[i].Equals(test.Data[0])) 5908 // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
5909 // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
5910 // and so the comparison fails even if the LSL_Integer conceptually has the same value.
5911 // Therefore, here we test Equals on both the source and destination objects.
5912 // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
5913 if (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i]))
5956 { 5914 {
5957 int j; 5915 int j;
5958 for (j = 1; j < test.Length; j++) 5916 for (j = 1; j < test.Length; j++)
5959 if (!src.Data[i+j].Equals(test.Data[j])) 5917 if (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j])))
5960 break; 5918 break;
5919
5961 if (j == test.Length) 5920 if (j == test.Length)
5962 { 5921 {
5963 index = i; 5922 index = i;
@@ -5968,19 +5927,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5968 } 5927 }
5969 5928
5970 return index; 5929 return index;
5971
5972 } 5930 }
5973 5931
5974 public LSL_String llGetObjectName() 5932 public LSL_String llGetObjectName()
5975 { 5933 {
5976 m_host.AddScriptLPS(1); 5934 m_host.AddScriptLPS(1);
5977 return m_host.Name!=null?m_host.Name:String.Empty; 5935 return m_host.Name !=null ? m_host.Name : String.Empty;
5978 } 5936 }
5979 5937
5980 public void llSetObjectName(string name) 5938 public void llSetObjectName(string name)
5981 { 5939 {
5982 m_host.AddScriptLPS(1); 5940 m_host.AddScriptLPS(1);
5983 m_host.Name = name!=null?name:String.Empty; 5941 m_host.Name = name != null ? name : String.Empty;
5984 } 5942 }
5985 5943
5986 public LSL_String llGetDate() 5944 public LSL_String llGetDate()
@@ -6311,19 +6269,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6311 m_host.AddScriptLPS(1); 6269 m_host.AddScriptLPS(1);
6312 6270
6313 List<SceneObjectPart> parts = GetLinkParts(linknumber); 6271 List<SceneObjectPart> parts = GetLinkParts(linknumber);
6314 if (parts.Count > 0) 6272
6273 try
6315 { 6274 {
6316 try 6275 foreach (SceneObjectPart part in parts)
6317 {
6318 foreach (var part in parts)
6319 {
6320 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
6321 }
6322 }
6323 finally
6324 { 6276 {
6277 SetTextureAnim(part, mode, face, sizex, sizey, start, length, rate);
6325 } 6278 }
6326 } 6279 }
6280 finally
6281 {
6282 }
6327 } 6283 }
6328 6284
6329 private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate) 6285 private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate)
@@ -6541,9 +6497,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6541 6497
6542 //Plug the x,y coordinates of the slope normal into the equation of the plane to get 6498 //Plug the x,y coordinates of the slope normal into the equation of the plane to get
6543 //the height of that point on the plane. The resulting vector gives the slope. 6499 //the height of that point on the plane. The resulting vector gives the slope.
6544 Vector3 vsl = new Vector3(); 6500 Vector3 vsl = vsn;
6545 vsl.X = (float)vsn.x;
6546 vsl.Y = (float)vsn.y;
6547 vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z)); 6501 vsl.Z = (float)(((vsn.x * vsn.x) + (vsn.y * vsn.y)) / (-1 * vsn.z));
6548 vsl.Normalize(); 6502 vsl.Normalize();
6549 //Normalization might be overkill here 6503 //Normalization might be overkill here
@@ -6554,9 +6508,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6554 public LSL_Vector llGroundNormal(LSL_Vector offset) 6508 public LSL_Vector llGroundNormal(LSL_Vector offset)
6555 { 6509 {
6556 m_host.AddScriptLPS(1); 6510 m_host.AddScriptLPS(1);
6557 Vector3 pos = m_host.GetWorldPosition() + new Vector3((float)offset.x, 6511 Vector3 pos = m_host.GetWorldPosition() + (Vector3)offset;
6558 (float)offset.y,
6559 (float)offset.z);
6560 // Clamp to valid position 6512 // Clamp to valid position
6561 if (pos.X < 0) 6513 if (pos.X < 0)
6562 pos.X = 0; 6514 pos.X = 0;
@@ -6721,7 +6673,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6721 6673
6722 List<SceneObjectPart> parts = GetLinkParts(linknumber); 6674 List<SceneObjectPart> parts = GetLinkParts(linknumber);
6723 6675
6724 foreach (var part in parts) 6676 foreach (SceneObjectPart part in parts)
6725 { 6677 {
6726 SetParticleSystem(part, rules); 6678 SetParticleSystem(part, rules);
6727 } 6679 }
@@ -6965,16 +6917,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
6965 if (m_TransferModule != null) 6917 if (m_TransferModule != null)
6966 { 6918 {
6967 byte[] bucket = new byte[] { (byte)AssetType.Folder }; 6919 byte[] bucket = new byte[] { (byte)AssetType.Folder };
6968 6920
6921 Vector3 pos = m_host.AbsolutePosition;
6922
6969 GridInstantMessage msg = new GridInstantMessage(World, 6923 GridInstantMessage msg = new GridInstantMessage(World,
6970 m_host.UUID, m_host.Name + ", an object owned by " + 6924 m_host.OwnerID, m_host.Name, destID,
6971 resolveName(m_host.OwnerID) + ",", destID,
6972 (byte)InstantMessageDialog.TaskInventoryOffered, 6925 (byte)InstantMessageDialog.TaskInventoryOffered,
6973 false, category + "\n" + m_host.Name + " is located at " + 6926 false, string.Format("'{0}'", category),
6974 World.RegionInfo.RegionName + " " + 6927// We won't go so far as to add a SLURL, but this is the format used by LL as of 2012-10-06
6975 m_host.AbsolutePosition.ToString(), 6928// false, string.Format("'{0}' ( http://slurl.com/secondlife/{1}/{2}/{3}/{4} )", category, World.Name, (int)pos.X, (int)pos.Y, (int)pos.Z),
6976 folderID, true, m_host.AbsolutePosition, 6929 folderID, false, pos,
6977 bucket); 6930 bucket, false);
6978 6931
6979 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {}); 6932 m_TransferModule.SendInstantMessage(msg, delegate(bool success) {});
6980 } 6933 }
@@ -7010,8 +6963,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7010 6963
7011 if (!m_host.ParentGroup.IsDeleted) 6964 if (!m_host.ParentGroup.IsDeleted)
7012 { 6965 {
7013 m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, 6966 m_host.ParentGroup.RootPart.SetVehicleVectorParam(param, vec);
7014 new Vector3((float)vec.x, (float)vec.y, (float)vec.z));
7015 } 6967 }
7016 } 6968 }
7017 6969
@@ -7023,7 +6975,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7023 6975
7024 if (!m_host.ParentGroup.IsDeleted) 6976 if (!m_host.ParentGroup.IsDeleted)
7025 { 6977 {
7026 m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, Rot2Quaternion(rot)); 6978 m_host.ParentGroup.RootPart.SetVehicleRotationParam(param, rot);
7027 } 6979 }
7028 } 6980 }
7029 6981
@@ -7053,8 +7005,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7053 if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0) 7005 if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
7054 rot.s = 1; // ZERO_ROTATION = 0,0,0,1 7006 rot.s = 1; // ZERO_ROTATION = 0,0,0,1
7055 7007
7056 part.SitTargetPosition = new Vector3((float)offset.x, (float)offset.y, (float)offset.z); 7008 part.SitTargetPosition = offset;
7057 part.SitTargetOrientation = Rot2Quaternion(rot); 7009 part.SitTargetOrientation = rot;
7058 part.ParentGroup.HasGroupChanged = true; 7010 part.ParentGroup.HasGroupChanged = true;
7059 } 7011 }
7060 7012
@@ -7157,13 +7109,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7157 public void llSetCameraEyeOffset(LSL_Vector offset) 7109 public void llSetCameraEyeOffset(LSL_Vector offset)
7158 { 7110 {
7159 m_host.AddScriptLPS(1); 7111 m_host.AddScriptLPS(1);
7160 m_host.SetCameraEyeOffset(new Vector3((float)offset.x, (float)offset.y, (float)offset.z)); 7112 m_host.SetCameraEyeOffset(offset);
7161 } 7113 }
7162 7114
7163 public void llSetCameraAtOffset(LSL_Vector offset) 7115 public void llSetCameraAtOffset(LSL_Vector offset)
7164 { 7116 {
7165 m_host.AddScriptLPS(1); 7117 m_host.AddScriptLPS(1);
7166 m_host.SetCameraAtOffset(new Vector3((float)offset.x, (float)offset.y, (float)offset.z)); 7118 m_host.SetCameraAtOffset(offset);
7167 } 7119 }
7168 7120
7169 public LSL_String llDumpList2String(LSL_List src, string seperator) 7121 public LSL_String llDumpList2String(LSL_List src, string seperator)
@@ -7185,7 +7137,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7185 public LSL_Integer llScriptDanger(LSL_Vector pos) 7137 public LSL_Integer llScriptDanger(LSL_Vector pos)
7186 { 7138 {
7187 m_host.AddScriptLPS(1); 7139 m_host.AddScriptLPS(1);
7188 bool result = World.ScriptDanger(m_host.LocalId, new Vector3((float)pos.x, (float)pos.y, (float)pos.z)); 7140 bool result = World.ScriptDanger(m_host.LocalId, pos);
7189 if (result) 7141 if (result)
7190 { 7142 {
7191 return 1; 7143 return 1;
@@ -7767,7 +7719,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7767 { 7719 {
7768 m_host.AddScriptLPS(1); 7720 m_host.AddScriptLPS(1);
7769 7721
7770 setLinkPrimParams(ScriptBaseClass.LINK_THIS, rules); 7722 setLinkPrimParams(ScriptBaseClass.LINK_THIS, rules, "llSetPrimitiveParams");
7771 7723
7772 ScriptSleep(200); 7724 ScriptSleep(200);
7773 } 7725 }
@@ -7776,10 +7728,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7776 { 7728 {
7777 m_host.AddScriptLPS(1); 7729 m_host.AddScriptLPS(1);
7778 7730
7779 setLinkPrimParams(linknumber, rules); 7731 setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParamsFast");
7732
7733 ScriptSleep(200);
7780 } 7734 }
7781 7735
7782 private void setLinkPrimParams(int linknumber, LSL_List rules) 7736 private void setLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
7783 { 7737 {
7784 List<object> parts = new List<object>(); 7738 List<object> parts = new List<object>();
7785 List<SceneObjectPart> prims = GetLinkParts(linknumber); 7739 List<SceneObjectPart> prims = GetLinkParts(linknumber);
@@ -7790,15 +7744,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7790 parts.Add(p); 7744 parts.Add(p);
7791 7745
7792 LSL_List remaining = null; 7746 LSL_List remaining = null;
7747 uint rulesParsed = 0;
7793 7748
7794 if (parts.Count > 0) 7749 if (parts.Count > 0)
7795 { 7750 {
7796 foreach (object part in parts) 7751 foreach (object part in parts)
7797 { 7752 {
7798 if (part is SceneObjectPart) 7753 if (part is SceneObjectPart)
7799 remaining = SetPrimParams((SceneObjectPart)part, rules); 7754 remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
7800 else 7755 else
7801 remaining = SetPrimParams((ScenePresence)part, rules); 7756 remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
7802 } 7757 }
7803 7758
7804 while ((object)remaining != null && remaining.Length > 2) 7759 while ((object)remaining != null && remaining.Length > 2)
@@ -7817,9 +7772,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7817 foreach (object part in parts) 7772 foreach (object part in parts)
7818 { 7773 {
7819 if (part is SceneObjectPart) 7774 if (part is SceneObjectPart)
7820 remaining = SetPrimParams((SceneObjectPart)part, rules); 7775 remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
7821 else 7776 else
7822 remaining = SetPrimParams((ScenePresence)part, rules); 7777 remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
7823 } 7778 }
7824 } 7779 }
7825 } 7780 }
@@ -7857,6 +7812,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7857 7812
7858 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules) 7813 public void llSetLinkPrimitiveParams(int linknumber, LSL_List rules)
7859 { 7814 {
7815 setLinkPrimParams(linknumber, rules, "llSetLinkPrimitiveParams");
7860 llSetLinkPrimitiveParamsFast(linknumber, rules); 7816 llSetLinkPrimitiveParamsFast(linknumber, rules);
7861 ScriptSleep(200); 7817 ScriptSleep(200);
7862 } 7818 }
@@ -7884,195 +7840,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
7884 return new Vector3((float)x, (float)y, (float)z); 7840 return new Vector3((float)x, (float)y, (float)z);
7885 } 7841 }
7886 7842
7887 protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules) 7843 protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
7888 {
7889 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
7890
7891 int idx = 0;
7892
7893 bool positionChanged = false;
7894 Vector3 finalPos = Vector3.Zero;
7895
7896 try
7897 {
7898 while (idx < rules.Length)
7899 {
7900 int code = rules.GetLSLIntegerItem(idx++);
7901
7902 int remain = rules.Length - idx;
7903
7904 switch (code)
7905 {
7906 case (int)ScriptBaseClass.PRIM_POSITION:
7907 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
7908 {
7909 if (remain < 1)
7910 return null;
7911
7912 LSL_Vector v;
7913 v = rules.GetVector3Item(idx++);
7914
7915 SceneObjectPart part = World.GetSceneObjectPart(av.ParentID);
7916 if (part == null)
7917 break;
7918
7919 LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION;
7920 LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR;
7921 if (part.LinkNum > 1)
7922 {
7923 localRot = GetPartLocalRot(part);
7924 localPos = GetPartLocalPos(part);
7925 }
7926
7927 v -= localPos;
7928 v /= localRot;
7929
7930 LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
7931
7932 v = v + 2 * sitOffset;
7933
7934 av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
7935 av.SendAvatarDataToAllAgents();
7936
7937 }
7938 break;
7939
7940 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
7941 case (int)ScriptBaseClass.PRIM_ROTATION:
7942 {
7943 if (remain < 1)
7944 return null;
7945
7946 LSL_Rotation r;
7947 r = rules.GetQuaternionItem(idx++);
7948
7949 SceneObjectPart part = World.GetSceneObjectPart(av.ParentID);
7950 if (part == null)
7951 break;
7952
7953 LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION;
7954 LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR;
7955
7956 if (part.LinkNum > 1)
7957 localRot = GetPartLocalRot(part);
7958
7959 r = r * llGetRootRotation() / localRot;
7960 av.Rotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
7961 av.SendAvatarDataToAllAgents();
7962 }
7963 break;
7964
7965 // parse rest doing nothing but number of parameters error check
7966 case (int)ScriptBaseClass.PRIM_SIZE:
7967 case (int)ScriptBaseClass.PRIM_MATERIAL:
7968 case (int)ScriptBaseClass.PRIM_PHANTOM:
7969 case (int)ScriptBaseClass.PRIM_PHYSICS:
7970 case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
7971 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
7972 case (int)ScriptBaseClass.PRIM_NAME:
7973 case (int)ScriptBaseClass.PRIM_DESC:
7974 if (remain < 1)
7975 return null;
7976 idx++;
7977 break;
7978
7979 case (int)ScriptBaseClass.PRIM_GLOW:
7980 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
7981 case (int)ScriptBaseClass.PRIM_TEXGEN:
7982 if (remain < 2)
7983 return null;
7984 idx += 2;
7985 break;
7986
7987 case (int)ScriptBaseClass.PRIM_TYPE:
7988 if (remain < 3)
7989 return null;
7990 code = (int)rules.GetLSLIntegerItem(idx++);
7991 remain = rules.Length - idx;
7992 switch (code)
7993 {
7994 case (int)ScriptBaseClass.PRIM_TYPE_BOX:
7995 case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
7996 case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
7997 if (remain < 6)
7998 return null;
7999 idx += 6;
8000 break;
8001
8002 case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
8003 if (remain < 5)
8004 return null;
8005 idx += 5;
8006 break;
8007
8008 case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
8009 case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
8010 case (int)ScriptBaseClass.PRIM_TYPE_RING:
8011 if (remain < 11)
8012 return null;
8013 idx += 11;
8014 break;
8015
8016 case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
8017 if (remain < 2)
8018 return null;
8019 idx += 2;
8020 break;
8021 }
8022 break;
8023
8024 case (int)ScriptBaseClass.PRIM_COLOR:
8025 case (int)ScriptBaseClass.PRIM_TEXT:
8026 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
8027 case (int)ScriptBaseClass.PRIM_OMEGA:
8028 if (remain < 3)
8029 return null;
8030 idx += 3;
8031 break;
8032
8033 case (int)ScriptBaseClass.PRIM_TEXTURE:
8034 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
8035 case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
8036 if (remain < 5)
8037 return null;
8038 idx += 5;
8039 break;
8040
8041 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
8042 if (remain < 7)
8043 return null;
8044
8045 idx += 7;
8046 break;
8047
8048 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
8049 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
8050 return null;
8051
8052 return rules.GetSublist(idx, -1);
8053 }
8054 }
8055 }
8056
8057 finally
8058 {
8059 if (positionChanged)
8060 {
8061 av.OffsetPosition = finalPos;
8062// av.SendAvatarDataToAllAgents();
8063 av.SendTerseUpdateToAllClients();
8064 positionChanged = false;
8065 }
8066 }
8067 return null;
8068 }
8069
8070 protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules)
8071 { 7844 {
8072 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) 7845 if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
8073 return null; 7846 return null;
8074 7847
8075 int idx = 0; 7848 int idx = 0;
7849 int idxStart = 0;
8076 7850
8077 SceneObjectGroup parentgrp = part.ParentGroup; 7851 SceneObjectGroup parentgrp = part.ParentGroup;
8078 7852
@@ -8083,9 +7857,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8083 { 7857 {
8084 while (idx < rules.Length) 7858 while (idx < rules.Length)
8085 { 7859 {
7860 ++rulesParsed;
8086 int code = rules.GetLSLIntegerItem(idx++); 7861 int code = rules.GetLSLIntegerItem(idx++);
8087 7862
8088 int remain = rules.Length - idx; 7863 int remain = rules.Length - idx;
7864 idxStart = idx;
8089 7865
8090 int face; 7866 int face;
8091 LSL_Vector v; 7867 LSL_Vector v;
@@ -8115,18 +7891,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8115 return null; 7891 return null;
8116 7892
8117 LSL_Rotation q = rules.GetQuaternionItem(idx++); 7893 LSL_Rotation q = rules.GetQuaternionItem(idx++);
8118 SceneObjectPart rootPart = parentgrp.RootPart;
8119 // try to let this work as in SL... 7894 // try to let this work as in SL...
8120 if (rootPart == part) 7895 if (part.ParentID == 0)
8121 { 7896 {
8122 // special case: If we are root, rotate complete SOG to new rotation 7897 // special case: If we are root, rotate complete SOG to new rotation
8123 SetRot(part, Rot2Quaternion(q)); 7898 SetRot(part, q);
8124 } 7899 }
8125 else 7900 else
8126 { 7901 {
8127 // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask. 7902 // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
8128 // sounds like sl bug that we need to replicate 7903 SceneObjectPart rootPart = part.ParentGroup.RootPart;
8129 SetRot(part, rootPart.RotationOffset * Rot2Quaternion(q)); 7904 SetRot(part, rootPart.RotationOffset * (Quaternion)q);
8130 } 7905 }
8131 7906
8132 break; 7907 break;
@@ -8300,8 +8075,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8300 LSL_Vector color=rules.GetVector3Item(idx++); 8075 LSL_Vector color=rules.GetVector3Item(idx++);
8301 double alpha=(double)rules.GetLSLFloatItem(idx++); 8076 double alpha=(double)rules.GetLSLFloatItem(idx++);
8302 8077
8303 part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face); 8078 part.SetFaceColorAlpha(face, color, alpha);
8304 SetAlpha(part, alpha, face);
8305 8079
8306 break; 8080 break;
8307 8081
@@ -8449,9 +8223,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8449 string primText = rules.GetLSLStringItem(idx++); 8223 string primText = rules.GetLSLStringItem(idx++);
8450 LSL_Vector primTextColor = rules.GetVector3Item(idx++); 8224 LSL_Vector primTextColor = rules.GetVector3Item(idx++);
8451 LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++); 8225 LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++);
8452 Vector3 av3 = new Vector3(Util.Clip((float)primTextColor.x, 0.0f, 1.0f), 8226 Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
8453 Util.Clip((float)primTextColor.y, 0.0f, 1.0f),
8454 Util.Clip((float)primTextColor.z, 0.0f, 1.0f));
8455 part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f)); 8227 part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));
8456 8228
8457 break; 8229 break;
@@ -8470,8 +8242,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8470 case (int)ScriptBaseClass.PRIM_ROT_LOCAL: 8242 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
8471 if (remain < 1) 8243 if (remain < 1)
8472 return null; 8244 return null;
8473 LSL_Rotation lr = rules.GetQuaternionItem(idx++); 8245 SetRot(part, rules.GetQuaternionItem(idx++));
8474 SetRot(part, Rot2Quaternion(lr));
8475 break; 8246 break;
8476 case (int)ScriptBaseClass.PRIM_OMEGA: 8247 case (int)ScriptBaseClass.PRIM_OMEGA:
8477 if (remain < 3) 8248 if (remain < 3)
@@ -8481,7 +8252,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8481 LSL_Float gain = rules.GetLSLFloatItem(idx++); 8252 LSL_Float gain = rules.GetLSLFloatItem(idx++);
8482 TargetOmega(part, axis, (double)spinrate, (double)gain); 8253 TargetOmega(part, axis, (double)spinrate, (double)gain);
8483 break; 8254 break;
8484 8255 case (int)ScriptBaseClass.PRIM_SLICE:
8256 if (remain < 1)
8257 return null;
8258 LSL_Vector slice = rules.GetVector3Item(idx++);
8259 part.UpdateSlice((float)slice.x, (float)slice.y);
8260 break;
8485 case (int)ScriptBaseClass.PRIM_LINK_TARGET: 8261 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
8486 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless. 8262 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
8487 return null; 8263 return null;
@@ -8490,6 +8266,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8490 } 8266 }
8491 } 8267 }
8492 } 8268 }
8269 catch (InvalidCastException e)
8270 {
8271 ShoutError(string.Format(
8272 "{0} error running rule #{1}: arg #{2} ",
8273 originFunc, rulesParsed, idx - idxStart) + e.Message);
8274 }
8493 finally 8275 finally
8494 { 8276 {
8495 if (positionChanged) 8277 if (positionChanged)
@@ -8498,12 +8280,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8498 { 8280 {
8499 SceneObjectGroup parent = part.ParentGroup; 8281 SceneObjectGroup parent = part.ParentGroup;
8500 Util.FireAndForget(delegate(object x) { 8282 Util.FireAndForget(delegate(object x) {
8501 parent.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z)); 8283 parent.UpdateGroupPosition(currentPosition);
8502 }); 8284 });
8503 } 8285 }
8504 else 8286 else
8505 { 8287 {
8506 part.OffsetPosition = new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z); 8288 part.OffsetPosition = currentPosition;
8507 SceneObjectGroup parent = part.ParentGroup; 8289 SceneObjectGroup parent = part.ParentGroup;
8508 parent.HasGroupChanged = true; 8290 parent.HasGroupChanged = true;
8509 parent.ScheduleGroupForTerseUpdate(); 8291 parent.ScheduleGroupForTerseUpdate();
@@ -8881,7 +8663,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8881 public LSL_List llGetPrimitiveParams(LSL_List rules) 8663 public LSL_List llGetPrimitiveParams(LSL_List rules)
8882 { 8664 {
8883 m_host.AddScriptLPS(1); 8665 m_host.AddScriptLPS(1);
8884 return GetLinkPrimitiveParams(m_host, rules); 8666
8667 LSL_List result = new LSL_List();
8668
8669 LSL_List remaining = GetPrimParams(m_host, rules, ref result);
8670
8671 while (remaining != null && remaining.Length > 2)
8672 {
8673 int linknumber = remaining.GetLSLIntegerItem(0);
8674 rules = remaining.GetSublist(1, -1);
8675 List<SceneObjectPart> parts = GetLinkParts(linknumber);
8676
8677 foreach (SceneObjectPart part in parts)
8678 remaining = GetPrimParams(part, rules, ref result);
8679 }
8680
8681 return result;
8885 } 8682 }
8886 8683
8887 public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules) 8684 public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
@@ -8891,294 +8688,39 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
8891 // acording to SL wiki this must indicate a single link number or link_root or link_this. 8688 // acording to SL wiki this must indicate a single link number or link_root or link_this.
8892 // keep other options as before 8689 // keep other options as before
8893 8690
8894 List<SceneObjectPart> parts = GetLinkParts(linknumber); 8691 List<SceneObjectPart> parts;
8895 List<ScenePresence> avatars = GetLinkAvatars(linknumber); 8692 List<ScenePresence> avatars;
8896 8693
8897 LSL_List res = new LSL_List(); 8694 LSL_List res = new LSL_List();
8695 LSL_List remaining = null;
8898 8696
8899 if (parts.Count > 0) 8697 while (rules.Length > 0)
8900 { 8698 {
8901 foreach (var part in parts) 8699 parts = GetLinkParts(linknumber);
8700 avatars = GetLinkAvatars(linknumber);
8701
8702 remaining = null;
8703 foreach (SceneObjectPart part in parts)
8902 { 8704 {
8903 LSL_List partRes = GetLinkPrimitiveParams(part, rules); 8705 remaining = GetPrimParams(part, rules, ref res);
8904 res += partRes;
8905 } 8706 }
8906 }
8907 if (avatars.Count > 0)
8908 {
8909 foreach (ScenePresence avatar in avatars) 8707 foreach (ScenePresence avatar in avatars)
8910 { 8708 {
8911 LSL_List avaRes = GetLinkPrimitiveParams(avatar, rules); 8709 remaining = GetPrimParams(avatar, rules, ref res);
8912 res += avaRes;
8913 } 8710 }
8914 }
8915 return res;
8916 }
8917
8918 public LSL_List GetLinkPrimitiveParams(ScenePresence avatar, LSL_List rules)
8919 {
8920 // avatars case
8921 // replies as SL wiki
8922
8923 LSL_List res = new LSL_List();
8924// SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
8925 SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??
8926
8927 int idx = 0;
8928 while (idx < rules.Length)
8929 {
8930 int code = (int)rules.GetLSLIntegerItem(idx++);
8931 int remain = rules.Length - idx;
8932 8711
8933 switch (code) 8712 if (remaining != null && remaining.Length > 0)
8934 { 8713 {
8935 case (int)ScriptBaseClass.PRIM_MATERIAL: 8714 linknumber = remaining.GetLSLIntegerItem(0);
8936 res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh)); 8715 rules = remaining.GetSublist(1, -1);
8937 break;
8938
8939 case (int)ScriptBaseClass.PRIM_PHYSICS:
8940 res.Add(new LSL_Integer(0));
8941 break;
8942
8943 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
8944 res.Add(new LSL_Integer(0));
8945 break;
8946
8947 case (int)ScriptBaseClass.PRIM_PHANTOM:
8948 res.Add(new LSL_Integer(0));
8949 break;
8950
8951 case (int)ScriptBaseClass.PRIM_POSITION:
8952
8953 Vector3 pos = avatar.OffsetPosition;
8954
8955 Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
8956 pos -= sitOffset;
8957
8958 if( sitPart != null)
8959 pos = sitPart.GetWorldPosition() + pos * sitPart.GetWorldRotation();
8960
8961 res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
8962 break;
8963
8964 case (int)ScriptBaseClass.PRIM_SIZE:
8965 // as in llGetAgentSize above
8966 res.Add(new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight));
8967 break;
8968
8969 case (int)ScriptBaseClass.PRIM_ROTATION:
8970 Quaternion rot = avatar.Rotation;
8971 if (sitPart != null)
8972 {
8973 rot = sitPart.GetWorldRotation() * rot; // apply sit part world rotation
8974 }
8975
8976 res.Add(new LSL_Rotation (rot.X, rot.Y, rot.Z, rot.W));
8977 break;
8978
8979 case (int)ScriptBaseClass.PRIM_TYPE:
8980 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
8981 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
8982 res.Add(new LSL_Vector(0f,1.0f,0f));
8983 res.Add(new LSL_Float(0.0f));
8984 res.Add(new LSL_Vector(0, 0, 0));
8985 res.Add(new LSL_Vector(1.0f,1.0f,0f));
8986 res.Add(new LSL_Vector(0, 0, 0));
8987 break;
8988
8989 case (int)ScriptBaseClass.PRIM_TEXTURE:
8990 if (remain < 1)
8991 return res;
8992
8993 int face = (int)rules.GetLSLIntegerItem(idx++);
8994 if (face == ScriptBaseClass.ALL_SIDES)
8995 {
8996 for (face = 0; face < 21; face++)
8997 {
8998 res.Add(new LSL_String(""));
8999 res.Add(new LSL_Vector(0,0,0));
9000 res.Add(new LSL_Vector(0,0,0));
9001 res.Add(new LSL_Float(0.0));
9002 }
9003 }
9004 else
9005 {
9006 if (face >= 0 && face < 21)
9007 {
9008 res.Add(new LSL_String(""));
9009 res.Add(new LSL_Vector(0,0,0));
9010 res.Add(new LSL_Vector(0,0,0));
9011 res.Add(new LSL_Float(0.0));
9012 }
9013 }
9014 break;
9015
9016 case (int)ScriptBaseClass.PRIM_COLOR:
9017 if (remain < 1)
9018 return res;
9019
9020 face = (int)rules.GetLSLIntegerItem(idx++);
9021
9022 if (face == ScriptBaseClass.ALL_SIDES)
9023 {
9024 for (face = 0; face < 21; face++)
9025 {
9026 res.Add(new LSL_Vector(0,0,0));
9027 res.Add(new LSL_Float(0));
9028 }
9029 }
9030 else
9031 {
9032 res.Add(new LSL_Vector(0,0,0));
9033 res.Add(new LSL_Float(0));
9034 }
9035 break;
9036
9037 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
9038 if (remain < 1)
9039 return res;
9040 face = (int)rules.GetLSLIntegerItem(idx++);
9041
9042 if (face == ScriptBaseClass.ALL_SIDES)
9043 {
9044 for (face = 0; face < 21; face++)
9045 {
9046 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
9047 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
9048 }
9049 }
9050 else
9051 {
9052 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
9053 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
9054 }
9055 break;
9056
9057 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
9058 if (remain < 1)
9059 return res;
9060 face = (int)rules.GetLSLIntegerItem(idx++);
9061
9062 if (face == ScriptBaseClass.ALL_SIDES)
9063 {
9064 for (face = 0; face < 21; face++)
9065 {
9066 res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
9067 }
9068 }
9069 else
9070 {
9071 res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
9072 }
9073 break;
9074
9075 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
9076 res.Add(new LSL_Integer(0));
9077 res.Add(new LSL_Integer(0));// softness
9078 res.Add(new LSL_Float(0.0f)); // gravity
9079 res.Add(new LSL_Float(0.0f)); // friction
9080 res.Add(new LSL_Float(0.0f)); // wind
9081 res.Add(new LSL_Float(0.0f)); // tension
9082 res.Add(new LSL_Vector(0f,0f,0f));
9083 break;
9084
9085 case (int)ScriptBaseClass.PRIM_TEXGEN:
9086 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
9087 if (remain < 1)
9088 return res;
9089 face = (int)rules.GetLSLIntegerItem(idx++);
9090
9091 if (face == ScriptBaseClass.ALL_SIDES)
9092 {
9093 for (face = 0; face < 21; face++)
9094 {
9095 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
9096 }
9097 }
9098 else
9099 {
9100 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
9101 }
9102 break;
9103
9104 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
9105 res.Add(new LSL_Integer(0));
9106 res.Add(new LSL_Vector(0f,0f,0f));
9107 res.Add(new LSL_Float(0f)); // intensity
9108 res.Add(new LSL_Float(0f)); // radius
9109 res.Add(new LSL_Float(0f)); // falloff
9110 break;
9111
9112 case (int)ScriptBaseClass.PRIM_GLOW:
9113 if (remain < 1)
9114 return res;
9115 face = (int)rules.GetLSLIntegerItem(idx++);
9116
9117 if (face == ScriptBaseClass.ALL_SIDES)
9118 {
9119 for (face = 0; face < 21; face++)
9120 {
9121 res.Add(new LSL_Float(0f));
9122 }
9123 }
9124 else
9125 {
9126 res.Add(new LSL_Float(0f));
9127 }
9128 break;
9129
9130 case (int)ScriptBaseClass.PRIM_TEXT:
9131 res.Add(new LSL_String(""));
9132 res.Add(new LSL_Vector(0f,0f,0f));
9133 res.Add(new LSL_Float(1.0f));
9134 break;
9135
9136 case (int)ScriptBaseClass.PRIM_NAME:
9137 res.Add(new LSL_String(avatar.Name));
9138 break;
9139
9140 case (int)ScriptBaseClass.PRIM_DESC:
9141 res.Add(new LSL_String(""));
9142 break;
9143
9144 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
9145 Quaternion lrot = avatar.Rotation;
9146
9147 if (sitPart != null && sitPart != sitPart.ParentGroup.RootPart)
9148 {
9149 lrot = sitPart.RotationOffset * lrot; // apply sit part rotation offset
9150 }
9151 res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
9152 break;
9153
9154 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
9155 Vector3 lpos = avatar.OffsetPosition; // pos relative to sit part
9156 Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
9157 lpos -= lsitOffset;
9158
9159 if (sitPart != null && sitPart != sitPart.ParentGroup.RootPart)
9160 {
9161 lpos = sitPart.OffsetPosition + (lpos * sitPart.RotationOffset); // make it relative to root prim
9162 }
9163 res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
9164 break;
9165
9166 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
9167 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
9168 return res;
9169 LSL_Integer new_linknumber = rules.GetLSLIntegerItem(idx++);
9170 LSL_List new_rules = rules.GetSublist(idx, -1);
9171
9172 res += llGetLinkPrimitiveParams((int)new_linknumber, new_rules);
9173 return res;
9174 } 8716 }
9175 } 8717 }
8718
9176 return res; 8719 return res;
9177 } 8720 }
9178 8721
9179 public LSL_List GetLinkPrimitiveParams(SceneObjectPart part, LSL_List rules) 8722 public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
9180 { 8723 {
9181 LSL_List res = new LSL_List();
9182 int idx=0; 8724 int idx=0;
9183 while (idx < rules.Length) 8725 while (idx < rules.Length)
9184 { 8726 {
@@ -9316,7 +8858,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9316 8858
9317 case (int)ScriptBaseClass.PRIM_TEXTURE: 8859 case (int)ScriptBaseClass.PRIM_TEXTURE:
9318 if (remain < 1) 8860 if (remain < 1)
9319 return res; 8861 return null;
9320 8862
9321 int face = (int)rules.GetLSLIntegerItem(idx++); 8863 int face = (int)rules.GetLSLIntegerItem(idx++);
9322 Primitive.TextureEntry tex = part.Shape.Textures; 8864 Primitive.TextureEntry tex = part.Shape.Textures;
@@ -9356,7 +8898,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9356 8898
9357 case (int)ScriptBaseClass.PRIM_COLOR: 8899 case (int)ScriptBaseClass.PRIM_COLOR:
9358 if (remain < 1) 8900 if (remain < 1)
9359 return res; 8901 return null;
9360 8902
9361 face=(int)rules.GetLSLIntegerItem(idx++); 8903 face=(int)rules.GetLSLIntegerItem(idx++);
9362 8904
@@ -9385,7 +8927,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9385 8927
9386 case (int)ScriptBaseClass.PRIM_BUMP_SHINY: 8928 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
9387 if (remain < 1) 8929 if (remain < 1)
9388 return res; 8930 return null;
8931
9389 face = (int)rules.GetLSLIntegerItem(idx++); 8932 face = (int)rules.GetLSLIntegerItem(idx++);
9390 8933
9391 tex = part.Shape.Textures; 8934 tex = part.Shape.Textures;
@@ -9441,7 +8984,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9441 8984
9442 case (int)ScriptBaseClass.PRIM_FULLBRIGHT: 8985 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
9443 if (remain < 1) 8986 if (remain < 1)
9444 return res; 8987 return null;
8988
9445 face = (int)rules.GetLSLIntegerItem(idx++); 8989 face = (int)rules.GetLSLIntegerItem(idx++);
9446 8990
9447 tex = part.Shape.Textures; 8991 tex = part.Shape.Textures;
@@ -9495,7 +9039,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9495 case (int)ScriptBaseClass.PRIM_TEXGEN: 9039 case (int)ScriptBaseClass.PRIM_TEXGEN:
9496 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR) 9040 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
9497 if (remain < 1) 9041 if (remain < 1)
9498 return res; 9042 return null;
9043
9499 face = (int)rules.GetLSLIntegerItem(idx++); 9044 face = (int)rules.GetLSLIntegerItem(idx++);
9500 9045
9501 tex = part.Shape.Textures; 9046 tex = part.Shape.Textures;
@@ -9543,7 +9088,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9543 9088
9544 case (int)ScriptBaseClass.PRIM_GLOW: 9089 case (int)ScriptBaseClass.PRIM_GLOW:
9545 if (remain < 1) 9090 if (remain < 1)
9546 return res; 9091 return null;
9092
9547 face = (int)rules.GetLSLIntegerItem(idx++); 9093 face = (int)rules.GetLSLIntegerItem(idx++);
9548 9094
9549 tex = part.Shape.Textures; 9095 tex = part.Shape.Textures;
@@ -9587,18 +9133,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
9587 case (int)ScriptBaseClass.PRIM_POS_LOCAL: 9133 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
9588 res.Add(new LSL_Vector(GetPartLocalPos(part))); 9134 res.Add(new LSL_Vector(GetPartLocalPos(part)));
9589 break; 9135 break;
9590 9136 case (int)ScriptBaseClass.PRIM_SLICE:
9137 PrimType prim_type = part.GetPrimType();
9138 bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
9139 res.Add(new LSL_Vector(
9140 (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
9141 1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
9142 0
9143 ));
9144 break;
9591 case (int)ScriptBaseClass.PRIM_LINK_TARGET: 9145 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
9592 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless. 9146 if(remain < 3)
9593 return res; 9147 return null;
9594 LSL_Integer new_linknumber = rules.GetLSLIntegerItem(idx++); 9148
9595 LSL_List new_rules = rules.GetSublist(idx, -1); 9149 return rules.GetSublist(idx, -1);
9596 LSL_List tres = llGetLinkPrimitiveParams((int)new_linknumber, new_rules);
9597 res += tres;
9598 return res;
9599 } 9150 }
9600 } 9151 }
9601 return res; 9152
9153 return null;
9602 } 9154 }
9603 9155
9604 public LSL_List llGetPrimMediaParams(int face, LSL_List rules) 9156 public LSL_List llGetPrimMediaParams(int face, LSL_List rules)
@@ -10511,11 +10063,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10511 10063
10512 GridRegion info; 10064 GridRegion info;
10513 10065
10514 if (m_ScriptEngine.World.RegionInfo.RegionName == simulator) //Det data for this simulator? 10066 if (World.RegionInfo.RegionName == simulator)
10515 10067 info = new GridRegion(World.RegionInfo);
10516 info = new GridRegion(m_ScriptEngine.World.RegionInfo);
10517 else 10068 else
10518 info = m_ScriptEngine.World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator); 10069 info = World.GridService.GetRegionByName(m_ScriptEngine.World.RegionInfo.ScopeID, simulator);
10519 10070
10520 switch (data) 10071 switch (data)
10521 { 10072 {
@@ -10525,9 +10076,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10525 ScriptSleep(1000); 10076 ScriptSleep(1000);
10526 return UUID.Zero.ToString(); 10077 return UUID.Zero.ToString();
10527 } 10078 }
10528 if (m_ScriptEngine.World.RegionInfo.RegionName != simulator) 10079
10080 bool isHypergridRegion = false;
10081
10082 if (World.RegionInfo.RegionName != simulator && info.RegionSecret != "")
10083 {
10084 // Hypergrid is currently placing real destination region co-ords into RegionSecret.
10085 // But other code can also use this field for a genuine RegionSecret! Therefore, if
10086 // anything is present we need to disambiguate.
10087 //
10088 // FIXME: Hypergrid should be storing this data in a different field.
10089 RegionFlags regionFlags
10090 = (RegionFlags)m_ScriptEngine.World.GridService.GetRegionFlags(
10091 info.ScopeID, info.RegionID);
10092 isHypergridRegion = (regionFlags & RegionFlags.Hyperlink) != 0;
10093 }
10094
10095 if (isHypergridRegion)
10529 { 10096 {
10530 //Hypergrid Region co-ordinates
10531 uint rx = 0, ry = 0; 10097 uint rx = 0, ry = 0;
10532 Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry); 10098 Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry);
10533 10099
@@ -10538,7 +10104,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10538 } 10104 }
10539 else 10105 else
10540 { 10106 {
10541 //Local-cooridnates 10107 // Local grid co-oridnates
10542 reply = new LSL_Vector( 10108 reply = new LSL_Vector(
10543 info.RegionLocX, 10109 info.RegionLocX,
10544 info.RegionLocY, 10110 info.RegionLocY,
@@ -10992,20 +10558,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
10992 switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString())) 10558 switch ((ParcelMediaCommandEnum) Convert.ToInt32(aList.Data[i].ToString()))
10993 { 10559 {
10994 case ParcelMediaCommandEnum.Url: 10560 case ParcelMediaCommandEnum.Url:
10995 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaURL)); 10561 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaURL));
10996 break; 10562 break;
10997 case ParcelMediaCommandEnum.Desc: 10563 case ParcelMediaCommandEnum.Desc:
10998 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).Description)); 10564 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).Description));
10999 break; 10565 break;
11000 case ParcelMediaCommandEnum.Texture: 10566 case ParcelMediaCommandEnum.Texture:
11001 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaID.ToString())); 10567 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaID.ToString()));
11002 break; 10568 break;
11003 case ParcelMediaCommandEnum.Type: 10569 case ParcelMediaCommandEnum.Type:
11004 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaType)); 10570 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaType));
11005 break; 10571 break;
11006 case ParcelMediaCommandEnum.Size: 10572 case ParcelMediaCommandEnum.Size:
11007 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaWidth)); 10573 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaWidth));
11008 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y).MediaHeight)); 10574 list.Add(new LSL_String(World.GetLandData(m_host.AbsolutePosition).MediaHeight));
11009 break; 10575 break;
11010 default: 10576 default:
11011 ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url; 10577 ParcelMediaCommandEnum mediaCommandEnum = ParcelMediaCommandEnum.Url;
@@ -11175,9 +10741,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11175 ScenePresence avatar = World.GetScenePresence(detectedParams.Key); 10741 ScenePresence avatar = World.GetScenePresence(detectedParams.Key);
11176 if (avatar != null) 10742 if (avatar != null)
11177 { 10743 {
11178 avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name, simname, 10744 avatar.ControllingClient.SendScriptTeleportRequest(m_host.Name,
11179 new Vector3((float)pos.x, (float)pos.y, (float)pos.z), 10745 simname, pos, lookAt);
11180 new Vector3((float)lookAt.x, (float)lookAt.y, (float)lookAt.z));
11181 } 10746 }
11182 10747
11183 ScriptSleep(1000); 10748 ScriptSleep(1000);
@@ -11362,31 +10927,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11362 public LSL_Float llListStatistics(int operation, LSL_List src) 10927 public LSL_Float llListStatistics(int operation, LSL_List src)
11363 { 10928 {
11364 m_host.AddScriptLPS(1); 10929 m_host.AddScriptLPS(1);
11365 LSL_List nums = LSL_List.ToDoubleList(src);
11366 switch (operation) 10930 switch (operation)
11367 { 10931 {
11368 case ScriptBaseClass.LIST_STAT_RANGE: 10932 case ScriptBaseClass.LIST_STAT_RANGE:
11369 return nums.Range(); 10933 return src.Range();
11370 case ScriptBaseClass.LIST_STAT_MIN: 10934 case ScriptBaseClass.LIST_STAT_MIN:
11371 return nums.Min(); 10935 return src.Min();
11372 case ScriptBaseClass.LIST_STAT_MAX: 10936 case ScriptBaseClass.LIST_STAT_MAX:
11373 return nums.Max(); 10937 return src.Max();
11374 case ScriptBaseClass.LIST_STAT_MEAN: 10938 case ScriptBaseClass.LIST_STAT_MEAN:
11375 return nums.Mean(); 10939 return src.Mean();
11376 case ScriptBaseClass.LIST_STAT_MEDIAN: 10940 case ScriptBaseClass.LIST_STAT_MEDIAN:
11377 return nums.Median(); 10941 return LSL_List.ToDoubleList(src).Median();
11378 case ScriptBaseClass.LIST_STAT_NUM_COUNT: 10942 case ScriptBaseClass.LIST_STAT_NUM_COUNT:
11379 return nums.NumericLength(); 10943 return src.NumericLength();
11380 case ScriptBaseClass.LIST_STAT_STD_DEV: 10944 case ScriptBaseClass.LIST_STAT_STD_DEV:
11381 return nums.StdDev(); 10945 return src.StdDev();
11382 case ScriptBaseClass.LIST_STAT_SUM: 10946 case ScriptBaseClass.LIST_STAT_SUM:
11383 return nums.Sum(); 10947 return src.Sum();
11384 case ScriptBaseClass.LIST_STAT_SUM_SQUARES: 10948 case ScriptBaseClass.LIST_STAT_SUM_SQUARES:
11385 return nums.SumSqrs(); 10949 return src.SumSqrs();
11386 case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN: 10950 case ScriptBaseClass.LIST_STAT_GEOMETRIC_MEAN:
11387 return nums.GeometricMean(); 10951 return src.GeometricMean();
11388 case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN: 10952 case ScriptBaseClass.LIST_STAT_HARMONIC_MEAN:
11389 return nums.HarmonicMean(); 10953 return src.HarmonicMean();
11390 default: 10954 default:
11391 return 0.0; 10955 return 0.0;
11392 } 10956 }
@@ -11744,7 +11308,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11744 public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param) 11308 public LSL_List llGetParcelDetails(LSL_Vector pos, LSL_List param)
11745 { 11309 {
11746 m_host.AddScriptLPS(1); 11310 m_host.AddScriptLPS(1);
11747 LandData land = World.GetLandData((float)pos.x, (float)pos.y); 11311 LandData land = World.GetLandData(pos);
11748 if (land == null) 11312 if (land == null)
11749 { 11313 {
11750 return new LSL_List(0); 11314 return new LSL_List(0);
@@ -11912,13 +11476,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
11912 else 11476 else
11913 rot = obj.GetWorldRotation(); 11477 rot = obj.GetWorldRotation();
11914 11478
11915 LSL_Rotation objrot = new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W); 11479 LSL_Rotation objrot = new LSL_Rotation(rot);
11916 ret.Add(objrot); 11480 ret.Add(objrot);
11917 } 11481 }
11918 break; 11482 break;
11919 case ScriptBaseClass.OBJECT_VELOCITY: 11483 case ScriptBaseClass.OBJECT_VELOCITY:
11920 Vector3 ovel = obj.Velocity; 11484 ret.Add(new LSL_Vector(obj.Velocity));
11921 ret.Add(new LSL_Vector(ovel.X, ovel.Y, ovel.Z));
11922 break; 11485 break;
11923 case ScriptBaseClass.OBJECT_OWNER: 11486 case ScriptBaseClass.OBJECT_OWNER:
11924 ret.Add(new LSL_String(obj.OwnerID.ToString())); 11487 ret.Add(new LSL_String(obj.OwnerID.ToString()));
@@ -12131,7 +11694,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12131 return tid.ToString(); 11694 return tid.ToString();
12132 } 11695 }
12133 11696
12134 public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules) 11697 public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc)
12135 { 11698 {
12136 SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim)); 11699 SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
12137 if (obj == null) 11700 if (obj == null)
@@ -12140,28 +11703,41 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12140 if (obj.OwnerID != m_host.OwnerID) 11703 if (obj.OwnerID != m_host.OwnerID)
12141 return; 11704 return;
12142 11705
12143 LSL_List remaining = SetPrimParams(obj, rules); 11706 uint rulesParsed = 0;
11707 LSL_List remaining = SetPrimParams(obj, rules, originFunc, ref rulesParsed);
12144 11708
12145 while ((object)remaining != null && remaining.Length > 2) 11709 while ((object)remaining != null && remaining.Length > 2)
12146 { 11710 {
12147 LSL_Integer newLink = remaining.GetLSLIntegerItem(0); 11711 LSL_Integer newLink = remaining.GetLSLIntegerItem(0);
12148 LSL_List newrules = remaining.GetSublist(1, -1); 11712 LSL_List newrules = remaining.GetSublist(1, -1);
12149 foreach(SceneObjectPart part in GetLinkParts(obj, newLink)){ 11713 foreach(SceneObjectPart part in GetLinkParts(obj, newLink)){
12150 remaining = SetPrimParams(part, newrules); 11714 remaining = SetPrimParams(part, newrules, originFunc, ref rulesParsed);
12151 } 11715 }
12152 } 11716 }
12153 } 11717 }
12154 11718
12155 public LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules) 11719 public LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules)
12156 { 11720 {
12157 SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim)); 11721 SceneObjectPart obj = World.GetSceneObjectPart(new UUID(prim));
12158 if (obj == null)
12159 return new LSL_List();
12160 11722
12161 if (obj.OwnerID != m_host.OwnerID) 11723 LSL_List result = new LSL_List();
12162 return new LSL_List(); 11724
11725 if (obj != null && obj.OwnerID != m_host.OwnerID)
11726 {
11727 LSL_List remaining = GetPrimParams(obj, rules, ref result);
11728
11729 while (remaining != null && remaining.Length > 2)
11730 {
11731 int linknumber = remaining.GetLSLIntegerItem(0);
11732 rules = remaining.GetSublist(1, -1);
11733 List<SceneObjectPart> parts = GetLinkParts(linknumber);
11734
11735 foreach (SceneObjectPart part in parts)
11736 remaining = GetPrimParams(part, rules, ref result);
11737 }
11738 }
12163 11739
12164 return GetLinkPrimitiveParams(obj, rules); 11740 return result;
12165 } 11741 }
12166 11742
12167 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link) 11743 public LSL_Integer llGetLinkNumberOfSides(LSL_Integer link)
@@ -12524,8 +12100,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
12524 12100
12525 m_host.AddScriptLPS(1); 12101 m_host.AddScriptLPS(1);
12526 12102
12527 Vector3 rayStart = new Vector3((float)start.x, (float)start.y, (float)start.z); 12103 Vector3 rayStart = start;
12528 Vector3 rayEnd = new Vector3((float)end.x, (float)end.y, (float)end.z); 12104 Vector3 rayEnd = end;
12529 Vector3 dir = rayEnd - rayStart; 12105 Vector3 dir = rayEnd - rayStart;
12530 12106
12531 float dist = Vector3.Mag(dir); 12107 float dist = Vector3.Mag(dir);
@@ -13099,6 +12675,455 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13099 } 12675 }
13100 } 12676 }
13101 } 12677 }
12678
12679 protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules, string originFunc, ref uint rulesParsed)
12680 {
12681 //This is a special version of SetPrimParams to deal with avatars which are sat on the linkset.
12682
12683 int idx = 0;
12684 int idxStart = 0;
12685
12686 bool positionChanged = false;
12687 Vector3 finalPos = Vector3.Zero;
12688
12689 try
12690 {
12691 while (idx < rules.Length)
12692 {
12693 ++rulesParsed;
12694 int code = rules.GetLSLIntegerItem(idx++);
12695
12696 int remain = rules.Length - idx;
12697 idxStart = idx;
12698
12699 switch (code)
12700 {
12701 case (int)ScriptBaseClass.PRIM_POSITION:
12702 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
12703 {
12704 if (remain < 1)
12705 return null;
12706
12707 LSL_Vector v;
12708 v = rules.GetVector3Item(idx++);
12709
12710 SceneObjectPart part = World.GetSceneObjectPart(av.ParentID);
12711 if (part == null)
12712 break;
12713
12714 LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION;
12715 LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR;
12716 if (part.LinkNum > 1)
12717 {
12718 localRot = GetPartLocalRot(part);
12719 localPos = GetPartLocalPos(part);
12720 }
12721
12722 v -= localPos;
12723 v /= localRot;
12724
12725 LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);
12726
12727 v = v + 2 * sitOffset;
12728
12729 av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
12730 av.SendAvatarDataToAllAgents();
12731
12732 }
12733 break;
12734
12735 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
12736 case (int)ScriptBaseClass.PRIM_ROTATION:
12737 {
12738 if (remain < 1)
12739 return null;
12740
12741 LSL_Rotation r;
12742 r = rules.GetQuaternionItem(idx++);
12743
12744 SceneObjectPart part = World.GetSceneObjectPart(av.ParentID);
12745 if (part == null)
12746 break;
12747
12748 LSL_Rotation localRot = ScriptBaseClass.ZERO_ROTATION;
12749 LSL_Vector localPos = ScriptBaseClass.ZERO_VECTOR;
12750
12751 if (part.LinkNum > 1)
12752 localRot = GetPartLocalRot(part);
12753
12754 r = r * llGetRootRotation() / localRot;
12755 av.Rotation = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s);
12756 av.SendAvatarDataToAllAgents();
12757 }
12758 break;
12759
12760 // parse rest doing nothing but number of parameters error check
12761 case (int)ScriptBaseClass.PRIM_SIZE:
12762 case (int)ScriptBaseClass.PRIM_MATERIAL:
12763 case (int)ScriptBaseClass.PRIM_PHANTOM:
12764 case (int)ScriptBaseClass.PRIM_PHYSICS:
12765 case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
12766 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
12767 case (int)ScriptBaseClass.PRIM_NAME:
12768 case (int)ScriptBaseClass.PRIM_DESC:
12769 if (remain < 1)
12770 return null;
12771 idx++;
12772 break;
12773
12774 case (int)ScriptBaseClass.PRIM_GLOW:
12775 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
12776 case (int)ScriptBaseClass.PRIM_TEXGEN:
12777 if (remain < 2)
12778 return null;
12779 idx += 2;
12780 break;
12781
12782 case (int)ScriptBaseClass.PRIM_TYPE:
12783 if (remain < 3)
12784 return null;
12785 code = (int)rules.GetLSLIntegerItem(idx++);
12786 remain = rules.Length - idx;
12787 switch (code)
12788 {
12789 case (int)ScriptBaseClass.PRIM_TYPE_BOX:
12790 case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
12791 case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
12792 if (remain < 6)
12793 return null;
12794 idx += 6;
12795 break;
12796
12797 case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
12798 if (remain < 5)
12799 return null;
12800 idx += 5;
12801 break;
12802
12803 case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
12804 case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
12805 case (int)ScriptBaseClass.PRIM_TYPE_RING:
12806 if (remain < 11)
12807 return null;
12808 idx += 11;
12809 break;
12810
12811 case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
12812 if (remain < 2)
12813 return null;
12814 idx += 2;
12815 break;
12816 }
12817 break;
12818
12819 case (int)ScriptBaseClass.PRIM_COLOR:
12820 case (int)ScriptBaseClass.PRIM_TEXT:
12821 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
12822 case (int)ScriptBaseClass.PRIM_OMEGA:
12823 if (remain < 3)
12824 return null;
12825 idx += 3;
12826 break;
12827
12828 case (int)ScriptBaseClass.PRIM_TEXTURE:
12829 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
12830 case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
12831 if (remain < 5)
12832 return null;
12833 idx += 5;
12834 break;
12835
12836 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
12837 if (remain < 7)
12838 return null;
12839
12840 idx += 7;
12841 break;
12842
12843 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
12844 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
12845 return null;
12846
12847 return rules.GetSublist(idx, -1);
12848 }
12849 }
12850 }
12851 catch (InvalidCastException e)
12852 {
12853 ShoutError(string.Format(
12854 "{0} error running rule #{1}: arg #{2} ",
12855 originFunc, rulesParsed, idx - idxStart) + e.Message);
12856 }
12857 finally
12858 {
12859 if (positionChanged)
12860 {
12861 av.OffsetPosition = finalPos;
12862// av.SendAvatarDataToAllAgents();
12863 av.SendTerseUpdateToAllClients();
12864 positionChanged = false;
12865 }
12866 }
12867 return null;
12868 }
12869
12870 public LSL_List GetPrimParams(ScenePresence avatar, LSL_List rules, ref LSL_List res)
12871 {
12872 // avatars case
12873 // replies as SL wiki
12874
12875// SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
12876 SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??
12877
12878 int idx = 0;
12879 while (idx < rules.Length)
12880 {
12881 int code = (int)rules.GetLSLIntegerItem(idx++);
12882 int remain = rules.Length - idx;
12883
12884 switch (code)
12885 {
12886 case (int)ScriptBaseClass.PRIM_MATERIAL:
12887 res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh));
12888 break;
12889
12890 case (int)ScriptBaseClass.PRIM_PHYSICS:
12891 res.Add(new LSL_Integer(0));
12892 break;
12893
12894 case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
12895 res.Add(new LSL_Integer(0));
12896 break;
12897
12898 case (int)ScriptBaseClass.PRIM_PHANTOM:
12899 res.Add(new LSL_Integer(0));
12900 break;
12901
12902 case (int)ScriptBaseClass.PRIM_POSITION:
12903
12904 Vector3 pos = avatar.OffsetPosition;
12905
12906 Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
12907 pos -= sitOffset;
12908
12909 if( sitPart != null)
12910 pos = sitPart.GetWorldPosition() + pos * sitPart.GetWorldRotation();
12911
12912 res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
12913 break;
12914
12915 case (int)ScriptBaseClass.PRIM_SIZE:
12916 // as in llGetAgentSize above
12917 res.Add(new LSL_Vector(0.45f, 0.6f, avatar.Appearance.AvatarHeight));
12918 break;
12919
12920 case (int)ScriptBaseClass.PRIM_ROTATION:
12921 Quaternion rot = avatar.Rotation;
12922 if (sitPart != null)
12923 {
12924 rot = sitPart.GetWorldRotation() * rot; // apply sit part world rotation
12925 }
12926
12927 res.Add(new LSL_Rotation (rot.X, rot.Y, rot.Z, rot.W));
12928 break;
12929
12930 case (int)ScriptBaseClass.PRIM_TYPE:
12931 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
12932 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
12933 res.Add(new LSL_Vector(0f,1.0f,0f));
12934 res.Add(new LSL_Float(0.0f));
12935 res.Add(new LSL_Vector(0, 0, 0));
12936 res.Add(new LSL_Vector(1.0f,1.0f,0f));
12937 res.Add(new LSL_Vector(0, 0, 0));
12938 break;
12939
12940 case (int)ScriptBaseClass.PRIM_TEXTURE:
12941 if (remain < 1)
12942 return null;
12943
12944 int face = (int)rules.GetLSLIntegerItem(idx++);
12945 if (face == ScriptBaseClass.ALL_SIDES)
12946 {
12947 for (face = 0; face < 21; face++)
12948 {
12949 res.Add(new LSL_String(""));
12950 res.Add(new LSL_Vector(0,0,0));
12951 res.Add(new LSL_Vector(0,0,0));
12952 res.Add(new LSL_Float(0.0));
12953 }
12954 }
12955 else
12956 {
12957 if (face >= 0 && face < 21)
12958 {
12959 res.Add(new LSL_String(""));
12960 res.Add(new LSL_Vector(0,0,0));
12961 res.Add(new LSL_Vector(0,0,0));
12962 res.Add(new LSL_Float(0.0));
12963 }
12964 }
12965 break;
12966
12967 case (int)ScriptBaseClass.PRIM_COLOR:
12968 if (remain < 1)
12969 return null;
12970
12971 face = (int)rules.GetLSLIntegerItem(idx++);
12972
12973 if (face == ScriptBaseClass.ALL_SIDES)
12974 {
12975 for (face = 0; face < 21; face++)
12976 {
12977 res.Add(new LSL_Vector(0,0,0));
12978 res.Add(new LSL_Float(0));
12979 }
12980 }
12981 else
12982 {
12983 res.Add(new LSL_Vector(0,0,0));
12984 res.Add(new LSL_Float(0));
12985 }
12986 break;
12987
12988 case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
12989 if (remain < 1)
12990 return null;
12991 face = (int)rules.GetLSLIntegerItem(idx++);
12992
12993 if (face == ScriptBaseClass.ALL_SIDES)
12994 {
12995 for (face = 0; face < 21; face++)
12996 {
12997 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
12998 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
12999 }
13000 }
13001 else
13002 {
13003 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
13004 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
13005 }
13006 break;
13007
13008 case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
13009 if (remain < 1)
13010 return null;
13011 face = (int)rules.GetLSLIntegerItem(idx++);
13012
13013 if (face == ScriptBaseClass.ALL_SIDES)
13014 {
13015 for (face = 0; face < 21; face++)
13016 {
13017 res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
13018 }
13019 }
13020 else
13021 {
13022 res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
13023 }
13024 break;
13025
13026 case (int)ScriptBaseClass.PRIM_FLEXIBLE:
13027 res.Add(new LSL_Integer(0));
13028 res.Add(new LSL_Integer(0));// softness
13029 res.Add(new LSL_Float(0.0f)); // gravity
13030 res.Add(new LSL_Float(0.0f)); // friction
13031 res.Add(new LSL_Float(0.0f)); // wind
13032 res.Add(new LSL_Float(0.0f)); // tension
13033 res.Add(new LSL_Vector(0f,0f,0f));
13034 break;
13035
13036 case (int)ScriptBaseClass.PRIM_TEXGEN:
13037 // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
13038 if (remain < 1)
13039 return null;
13040 face = (int)rules.GetLSLIntegerItem(idx++);
13041
13042 if (face == ScriptBaseClass.ALL_SIDES)
13043 {
13044 for (face = 0; face < 21; face++)
13045 {
13046 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
13047 }
13048 }
13049 else
13050 {
13051 res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
13052 }
13053 break;
13054
13055 case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
13056 res.Add(new LSL_Integer(0));
13057 res.Add(new LSL_Vector(0f,0f,0f));
13058 res.Add(new LSL_Float(0f)); // intensity
13059 res.Add(new LSL_Float(0f)); // radius
13060 res.Add(new LSL_Float(0f)); // falloff
13061 break;
13062
13063 case (int)ScriptBaseClass.PRIM_GLOW:
13064 if (remain < 1)
13065 return null;
13066 face = (int)rules.GetLSLIntegerItem(idx++);
13067
13068 if (face == ScriptBaseClass.ALL_SIDES)
13069 {
13070 for (face = 0; face < 21; face++)
13071 {
13072 res.Add(new LSL_Float(0f));
13073 }
13074 }
13075 else
13076 {
13077 res.Add(new LSL_Float(0f));
13078 }
13079 break;
13080
13081 case (int)ScriptBaseClass.PRIM_TEXT:
13082 res.Add(new LSL_String(""));
13083 res.Add(new LSL_Vector(0f,0f,0f));
13084 res.Add(new LSL_Float(1.0f));
13085 break;
13086
13087 case (int)ScriptBaseClass.PRIM_NAME:
13088 res.Add(new LSL_String(avatar.Name));
13089 break;
13090
13091 case (int)ScriptBaseClass.PRIM_DESC:
13092 res.Add(new LSL_String(""));
13093 break;
13094
13095 case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
13096 Quaternion lrot = avatar.Rotation;
13097
13098 if (sitPart != null && sitPart != sitPart.ParentGroup.RootPart)
13099 {
13100 lrot = sitPart.RotationOffset * lrot; // apply sit part rotation offset
13101 }
13102 res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
13103 break;
13104
13105 case (int)ScriptBaseClass.PRIM_POS_LOCAL:
13106 Vector3 lpos = avatar.OffsetPosition; // pos relative to sit part
13107 Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
13108 lpos -= lsitOffset;
13109
13110 if (sitPart != null && sitPart != sitPart.ParentGroup.RootPart)
13111 {
13112 lpos = sitPart.OffsetPosition + (lpos * sitPart.RotationOffset); // make it relative to root prim
13113 }
13114 res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
13115 break;
13116
13117 case (int)ScriptBaseClass.PRIM_LINK_TARGET:
13118 if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
13119 return null;
13120
13121 return rules.GetSublist(idx, -1);
13122 }
13123 }
13124
13125 return null;
13126 }
13102 } 13127 }
13103 13128
13104 public class NotecardCache 13129 public class NotecardCache
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
index 795de80..ceb4660 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LS_Api.cs
@@ -304,7 +304,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
304 case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY: 304 case (int)ScriptBaseClass.WL_CLOUD_DETAIL_XY_DENSITY:
305 idx++; 305 idx++;
306 iV = rules.GetVector3Item(idx); 306 iV = rules.GetVector3Item(idx);
307 wl.cloudDetailXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); 307 wl.cloudDetailXYDensity = iV;
308 break; 308 break;
309 case (int)ScriptBaseClass.WL_CLOUD_SCALE: 309 case (int)ScriptBaseClass.WL_CLOUD_SCALE:
310 idx++; 310 idx++;
@@ -329,7 +329,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
329 case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY: 329 case (int)ScriptBaseClass.WL_CLOUD_XY_DENSITY:
330 idx++; 330 idx++;
331 iV = rules.GetVector3Item(idx); 331 iV = rules.GetVector3Item(idx);
332 wl.cloudXYDensity = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); 332 wl.cloudXYDensity = iV;
333 break; 333 break;
334 case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER: 334 case (int)ScriptBaseClass.WL_DENSITY_MULTIPLIER:
335 idx++; 335 idx++;
@@ -384,7 +384,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
384 case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE: 384 case (int)ScriptBaseClass.WL_REFLECTION_WAVELET_SCALE:
385 idx++; 385 idx++;
386 iV = rules.GetVector3Item(idx); 386 iV = rules.GetVector3Item(idx);
387 wl.reflectionWaveletScale = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); 387 wl.reflectionWaveletScale = iV;
388 break; 388 break;
389 case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE: 389 case (int)ScriptBaseClass.WL_REFRACT_SCALE_ABOVE:
390 idx++; 390 idx++;
@@ -422,7 +422,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
422 case (int)ScriptBaseClass.WL_WATER_COLOR: 422 case (int)ScriptBaseClass.WL_WATER_COLOR:
423 idx++; 423 idx++;
424 iV = rules.GetVector3Item(idx); 424 iV = rules.GetVector3Item(idx);
425 wl.waterColor = new Vector3((float)iV.x, (float)iV.y, (float)iV.z); 425 wl.waterColor = iV;
426 break; 426 break;
427 case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT: 427 case (int)ScriptBaseClass.WL_WATER_FOG_DENSITY_EXPONENT:
428 idx++; 428 idx++;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index 7844c75..6809c09 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -254,7 +254,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
254 254
255 object[] convertedParms = new object[parms.Length]; 255 object[] convertedParms = new object[parms.Length];
256 for (int i = 0; i < parms.Length; i++) 256 for (int i = 0; i < parms.Length; i++)
257 convertedParms[i] = ConvertFromLSL(parms[i],signature[i]); 257 convertedParms[i] = ConvertFromLSL(parms[i],signature[i], fname);
258 258
259 // now call the function, the contract with the function is that it will always return 259 // now call the function, the contract with the function is that it will always return
260 // non-null but don't trust it completely 260 // non-null but don't trust it completely
@@ -294,7 +294,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
294 294
295 /// <summary> 295 /// <summary>
296 /// </summary> 296 /// </summary>
297 protected object ConvertFromLSL(object lslparm, Type type) 297 protected object ConvertFromLSL(object lslparm, Type type, string fname)
298 { 298 {
299 // ---------- String ---------- 299 // ---------- String ----------
300 if (lslparm is LSL_String) 300 if (lslparm is LSL_String)
@@ -310,7 +310,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
310 // ---------- Integer ---------- 310 // ---------- Integer ----------
311 else if (lslparm is LSL_Integer) 311 else if (lslparm is LSL_Integer)
312 { 312 {
313 if (type == typeof(int)) 313 if (type == typeof(int) || type == typeof(float))
314 return (int)(LSL_Integer)lslparm; 314 return (int)(LSL_Integer)lslparm;
315 } 315 }
316 316
@@ -333,8 +333,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
333 { 333 {
334 if (type == typeof(OpenMetaverse.Quaternion)) 334 if (type == typeof(OpenMetaverse.Quaternion))
335 { 335 {
336 LSL_Rotation rot = (LSL_Rotation)lslparm; 336 return (OpenMetaverse.Quaternion)((LSL_Rotation)lslparm);
337 return new OpenMetaverse.Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s);
338 } 337 }
339 } 338 }
340 339
@@ -343,8 +342,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
343 { 342 {
344 if (type == typeof(OpenMetaverse.Vector3)) 343 if (type == typeof(OpenMetaverse.Vector3))
345 { 344 {
346 LSL_Vector vect = (LSL_Vector)lslparm; 345 return (OpenMetaverse.Vector3)((LSL_Vector)lslparm);
347 return new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z);
348 } 346 }
349 } 347 }
350 348
@@ -367,23 +365,23 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
367 result[i] = new UUID((LSL_Key)plist[i]); 365 result[i] = new UUID((LSL_Key)plist[i]);
368 else if (plist[i] is LSL_Rotation) 366 else if (plist[i] is LSL_Rotation)
369 { 367 {
370 LSL_Rotation rot = (LSL_Rotation)plist[i]; 368 result[i] = (OpenMetaverse.Quaternion)(
371 result[i] = new OpenMetaverse.Quaternion((float)rot.x,(float)rot.y,(float)rot.z,(float)rot.s); 369 (LSL_Rotation)plist[i]);
372 } 370 }
373 else if (plist[i] is LSL_Vector) 371 else if (plist[i] is LSL_Vector)
374 { 372 {
375 LSL_Vector vect = (LSL_Vector)plist[i]; 373 result[i] = (OpenMetaverse.Vector3)(
376 result[i] = new OpenMetaverse.Vector3((float)vect.x,(float)vect.y,(float)vect.z); 374 (LSL_Vector)plist[i]);
377 } 375 }
378 else 376 else
379 MODError("unknown LSL list element type"); 377 MODError(String.Format("{0}: unknown LSL list element type", fname));
380 } 378 }
381 379
382 return result; 380 return result;
383 } 381 }
384 } 382 }
385 383
386 MODError(String.Format("parameter type mismatch; expecting {0}",type.Name)); 384 MODError(String.Format("{1}: parameter type mismatch; expecting {0}",type.Name, fname));
387 return null; 385 return null;
388 } 386 }
389 387
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 80111f9..17277d7 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -141,6 +141,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
141 internal bool m_debuggerSafe = false; 141 internal bool m_debuggerSafe = false;
142 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); 142 internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
143 143
144 protected IUrlModule m_UrlModule = null;
145
144 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item) 146 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, TaskInventoryItem item)
145 { 147 {
146 m_ScriptEngine = ScriptEngine; 148 m_ScriptEngine = ScriptEngine;
@@ -148,6 +150,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
148 m_item = item; 150 m_item = item;
149 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false); 151 m_debuggerSafe = m_ScriptEngine.Config.GetBoolean("DebuggerSafe", false);
150 152
153 m_UrlModule = m_ScriptEngine.World.RequestModuleInterface<IUrlModule>();
154
151 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false)) 155 if (m_ScriptEngine.Config.GetBoolean("AllowOSFunctions", false))
152 m_OSFunctionsEnabled = true; 156 m_OSFunctionsEnabled = true;
153 157
@@ -782,10 +786,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
782 786
783 // We will launch the teleport on a new thread so that when the script threads are terminated 787 // We will launch the teleport on a new thread so that when the script threads are terminated
784 // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. 788 // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
785 Util.FireAndForget( 789 Util.FireAndForget(o => World.RequestTeleportLocation(
786 o => World.RequestTeleportLocation(presence.ControllingClient, regionName, 790 presence.ControllingClient, regionName, position,
787 new Vector3((float)position.x, (float)position.y, (float)position.z), 791 lookat, (uint)TPFlags.ViaLocation));
788 new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation));
789 792
790 ScriptSleep(5000); 793 ScriptSleep(5000);
791 794
@@ -828,10 +831,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
828 831
829 // We will launch the teleport on a new thread so that when the script threads are terminated 832 // We will launch the teleport on a new thread so that when the script threads are terminated
830 // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. 833 // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting.
831 Util.FireAndForget( 834 Util.FireAndForget(o => World.RequestTeleportLocation(
832 o => World.RequestTeleportLocation(presence.ControllingClient, regionHandle, 835 presence.ControllingClient, regionHandle,
833 new Vector3((float)position.x, (float)position.y, (float)position.z), 836 position, lookat, (uint)TPFlags.ViaLocation));
834 new Vector3((float)lookat.x, (float)lookat.y, (float)lookat.z), (uint)TPFlags.ViaLocation));
835 837
836 ScriptSleep(5000); 838 ScriptSleep(5000);
837 839
@@ -1680,6 +1682,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1680 return; 1682 return;
1681 } 1683 }
1682 1684
1685 MessageObject(objUUID, message);
1686 }
1687
1688 private void MessageObject(UUID objUUID, string message)
1689 {
1683 object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) }; 1690 object[] resobj = new object[] { new LSL_Types.LSLString(m_host.UUID.ToString()), new LSL_Types.LSLString(message) };
1684 1691
1685 SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID); 1692 SceneObjectPart sceneOP = World.GetSceneObjectPart(objUUID);
@@ -2259,11 +2266,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2259 CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams"); 2266 CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
2260 m_host.AddScriptLPS(1); 2267 m_host.AddScriptLPS(1);
2261 InitLSL(); 2268 InitLSL();
2269 // One needs to cast m_LSL_Api because we're using functions not
2270 // on the ILSL_Api interface.
2271 LSL_Api LSL_Api = (LSL_Api)m_LSL_Api;
2262 LSL_List retVal = new LSL_List(); 2272 LSL_List retVal = new LSL_List();
2263 List<SceneObjectPart> parts = ((LSL_Api)m_LSL_Api).GetLinkParts(linknumber); 2273 LSL_List remaining = null;
2274 List<SceneObjectPart> parts = LSL_Api.GetLinkParts(linknumber);
2264 foreach (SceneObjectPart part in parts) 2275 foreach (SceneObjectPart part in parts)
2265 { 2276 {
2266 retVal += ((LSL_Api)m_LSL_Api).GetLinkPrimitiveParams(part, rules); 2277 remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
2278 }
2279
2280 while (remaining != null && remaining.Length > 2)
2281 {
2282 linknumber = remaining.GetLSLIntegerItem(0);
2283 rules = remaining.GetSublist(1, -1);
2284 parts = LSL_Api.GetLinkParts(linknumber);
2285
2286 foreach (SceneObjectPart part in parts)
2287 remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
2267 } 2288 }
2268 return retVal; 2289 return retVal;
2269 } 2290 }
@@ -2362,7 +2383,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2362 ownerID = m_host.OwnerID; 2383 ownerID = m_host.OwnerID;
2363 UUID x = module.CreateNPC(firstname, 2384 UUID x = module.CreateNPC(firstname,
2364 lastname, 2385 lastname,
2365 new Vector3((float) position.x, (float) position.y, (float) position.z), 2386 position,
2366 ownerID, 2387 ownerID,
2367 senseAsAgent, 2388 senseAsAgent,
2368 World, 2389 World,
@@ -2485,7 +2506,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2485 return new LSL_Vector(0, 0, 0); 2506 return new LSL_Vector(0, 0, 0);
2486 } 2507 }
2487 2508
2488 public void osNpcMoveTo(LSL_Key npc, LSL_Vector position) 2509 public void osNpcMoveTo(LSL_Key npc, LSL_Vector pos)
2489 { 2510 {
2490 CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); 2511 CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo");
2491 m_host.AddScriptLPS(1); 2512 m_host.AddScriptLPS(1);
@@ -2500,7 +2521,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2500 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 2521 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2501 return; 2522 return;
2502 2523
2503 Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z);
2504 module.MoveToTarget(npcId, World, pos, false, true, false); 2524 module.MoveToTarget(npcId, World, pos, false, true, false);
2505 } 2525 }
2506 } 2526 }
@@ -2520,11 +2540,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2520 if (!module.CheckPermissions(npcId, m_host.OwnerID)) 2540 if (!module.CheckPermissions(npcId, m_host.OwnerID))
2521 return; 2541 return;
2522 2542
2523 Vector3 pos = new Vector3((float)target.x, (float)target.y, (float)target.z);
2524 module.MoveToTarget( 2543 module.MoveToTarget(
2525 new UUID(npc.m_string), 2544 new UUID(npc.m_string),
2526 World, 2545 World,
2527 pos, 2546 target,
2528 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0, 2547 (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0,
2529 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0, 2548 (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0,
2530 (options & ScriptBaseClass.OS_NPC_RUNNING) != 0); 2549 (options & ScriptBaseClass.OS_NPC_RUNNING) != 0);
@@ -2576,7 +2595,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2576 ScenePresence sp = World.GetScenePresence(npcId); 2595 ScenePresence sp = World.GetScenePresence(npcId);
2577 2596
2578 if (sp != null) 2597 if (sp != null)
2579 sp.Rotation = LSL_Api.Rot2Quaternion(rotation); 2598 sp.Rotation = rotation;
2580 } 2599 }
2581 } 2600 }
2582 2601
@@ -2936,7 +2955,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2936 avatar.SpeedModifier = (float)SpeedModifier; 2955 avatar.SpeedModifier = (float)SpeedModifier;
2937 } 2956 }
2938 2957
2939 public void osKickAvatar(string FirstName,string SurName,string alert) 2958 public void osKickAvatar(string FirstName, string SurName, string alert)
2940 { 2959 {
2941 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); 2960 CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar");
2942 m_host.AddScriptLPS(1); 2961 m_host.AddScriptLPS(1);
@@ -2950,10 +2969,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2950 sp.ControllingClient.Kick(alert); 2969 sp.ControllingClient.Kick(alert);
2951 2970
2952 // ...and close on our side 2971 // ...and close on our side
2953 sp.Scene.IncomingCloseAgent(sp.UUID); 2972 sp.Scene.IncomingCloseAgent(sp.UUID, false);
2954 } 2973 }
2955 }); 2974 });
2956 } 2975 }
2976
2977 public LSL_Float osGetHealth(string avatar)
2978 {
2979 CheckThreatLevel(ThreatLevel.None, "osGetHealth");
2980 m_host.AddScriptLPS(1);
2981
2982 LSL_Float health = new LSL_Float(-1);
2983 ScenePresence presence = World.GetScenePresence(new UUID(avatar));
2984 if (presence != null) health = presence.Health;
2985 return health;
2986 }
2957 2987
2958 public void osCauseDamage(string avatar, double damage) 2988 public void osCauseDamage(string avatar, double damage)
2959 { 2989 {
@@ -2966,7 +2996,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2966 ScenePresence presence = World.GetScenePresence(avatarId); 2996 ScenePresence presence = World.GetScenePresence(avatarId);
2967 if (presence != null) 2997 if (presence != null)
2968 { 2998 {
2969 LandData land = World.GetLandData((float)pos.X, (float)pos.Y); 2999 LandData land = World.GetLandData(pos);
2970 if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage) 3000 if ((land.Flags & (uint)ParcelFlags.AllowDamage) == (uint)ParcelFlags.AllowDamage)
2971 { 3001 {
2972 float health = presence.Health; 3002 float health = presence.Health;
@@ -3013,7 +3043,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3013 m_host.AddScriptLPS(1); 3043 m_host.AddScriptLPS(1);
3014 InitLSL(); 3044 InitLSL();
3015 3045
3016 return m_LSL_Api.GetLinkPrimitiveParamsEx(prim, rules); 3046 return m_LSL_Api.GetPrimitiveParamsEx(prim, rules);
3017 } 3047 }
3018 3048
3019 public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules) 3049 public void osSetPrimitiveParams(LSL_Key prim, LSL_List rules)
@@ -3022,7 +3052,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3022 m_host.AddScriptLPS(1); 3052 m_host.AddScriptLPS(1);
3023 InitLSL(); 3053 InitLSL();
3024 3054
3025 m_LSL_Api.SetPrimitiveParamsEx(prim, rules); 3055 m_LSL_Api.SetPrimitiveParamsEx(prim, rules, "osSetPrimitiveParams");
3026 } 3056 }
3027 3057
3028 /// <summary> 3058 /// <summary>
@@ -3254,6 +3284,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3254 } 3284 }
3255 } 3285 }
3256 3286
3287 #region Attachment commands
3288
3257 public void osForceAttachToAvatar(int attachmentPoint) 3289 public void osForceAttachToAvatar(int attachmentPoint)
3258 { 3290 {
3259 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar"); 3291 CheckThreatLevel(ThreatLevel.High, "osForceAttachToAvatar");
@@ -3343,6 +3375,175 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3343 ((LSL_Api)m_LSL_Api).DetachFromAvatar(); 3375 ((LSL_Api)m_LSL_Api).DetachFromAvatar();
3344 } 3376 }
3345 3377
3378 public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
3379 {
3380 CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments");
3381
3382 m_host.AddScriptLPS(1);
3383
3384 UUID targetUUID;
3385 ScenePresence target;
3386 LSL_List resp = new LSL_List();
3387
3388 if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
3389 {
3390 foreach (object point in attachmentPoints.Data)
3391 {
3392 LSL_Integer ipoint = new LSL_Integer(
3393 (point is LSL_Integer || point is int || point is uint) ?
3394 (int)point :
3395 0
3396 );
3397 resp.Add(ipoint);
3398 if (ipoint == 0)
3399 {
3400 // indicates zero attachments
3401 resp.Add(new LSL_Integer(0));
3402 }
3403 else
3404 {
3405 // gets the number of attachments on the attachment point
3406 resp.Add(new LSL_Integer(target.GetAttachments((uint)ipoint).Count));
3407 }
3408 }
3409 }
3410
3411 return resp;
3412 }
3413
3414 public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int options)
3415 {
3416 CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments");
3417 m_host.AddScriptLPS(1);
3418
3419 UUID targetUUID;
3420 ScenePresence target;
3421
3422 if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target))
3423 {
3424 List<int> aps = new List<int>();
3425 foreach (object point in attachmentPoints.Data)
3426 {
3427 int ipoint;
3428 if (int.TryParse(point.ToString(), out ipoint))
3429 {
3430 aps.Add(ipoint);
3431 }
3432 }
3433
3434 List<SceneObjectGroup> attachments = new List<SceneObjectGroup>();
3435
3436 bool msgAll = aps.Contains(ScriptBaseClass.OS_ATTACH_MSG_ALL);
3437 bool invertPoints = (options & ScriptBaseClass.OS_ATTACH_MSG_INVERT_POINTS) != 0;
3438
3439 if (msgAll && invertPoints)
3440 {
3441 return;
3442 }
3443 else if (msgAll || invertPoints)
3444 {
3445 attachments = target.GetAttachments();
3446 }
3447 else
3448 {
3449 foreach (int point in aps)
3450 {
3451 if (point > 0)
3452 {
3453 attachments.AddRange(target.GetAttachments((uint)point));
3454 }
3455 }
3456 }
3457
3458 // if we have no attachments at this point, exit now
3459 if (attachments.Count == 0)
3460 {
3461 return;
3462 }
3463
3464 List<SceneObjectGroup> ignoreThese = new List<SceneObjectGroup>();
3465
3466 if (invertPoints)
3467 {
3468 foreach (SceneObjectGroup attachment in attachments)
3469 {
3470 if (aps.Contains((int)attachment.AttachmentPoint))
3471 {
3472 ignoreThese.Add(attachment);
3473 }
3474 }
3475 }
3476
3477 foreach (SceneObjectGroup attachment in ignoreThese)
3478 {
3479 attachments.Remove(attachment);
3480 }
3481 ignoreThese.Clear();
3482
3483 // if inverting removed all attachments to check, exit now
3484 if (attachments.Count < 1)
3485 {
3486 return;
3487 }
3488
3489 if ((options & ScriptBaseClass.OS_ATTACH_MSG_OBJECT_CREATOR) != 0)
3490 {
3491 foreach (SceneObjectGroup attachment in attachments)
3492 {
3493 if (attachment.RootPart.CreatorID != m_host.CreatorID)
3494 {
3495 ignoreThese.Add(attachment);
3496 }
3497 }
3498
3499 foreach (SceneObjectGroup attachment in ignoreThese)
3500 {
3501 attachments.Remove(attachment);
3502 }
3503 ignoreThese.Clear();
3504
3505 // if filtering by same object creator removed all
3506 // attachments to check, exit now
3507 if (attachments.Count == 0)
3508 {
3509 return;
3510 }
3511 }
3512
3513 if ((options & ScriptBaseClass.OS_ATTACH_MSG_SCRIPT_CREATOR) != 0)
3514 {
3515 foreach (SceneObjectGroup attachment in attachments)
3516 {
3517 if (attachment.RootPart.CreatorID != m_item.CreatorID)
3518 {
3519 ignoreThese.Add(attachment);
3520 }
3521 }
3522
3523 foreach (SceneObjectGroup attachment in ignoreThese)
3524 {
3525 attachments.Remove(attachment);
3526 }
3527 ignoreThese.Clear();
3528
3529 // if filtering by object creator must match originating
3530 // script creator removed all attachments to check,
3531 // exit now
3532 if (attachments.Count == 0)
3533 {
3534 return;
3535 }
3536 }
3537
3538 foreach (SceneObjectGroup attachment in attachments)
3539 {
3540 MessageObject(attachment.RootPart.UUID, message);
3541 }
3542 }
3543 }
3544
3545 #endregion
3546
3346 /// <summary> 3547 /// <summary>
3347 /// Checks if thing is a UUID. 3548 /// Checks if thing is a UUID.
3348 /// </summary> 3549 /// </summary>
@@ -3392,5 +3593,103 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3392 3593
3393 return new LSL_Key(m_host.ParentGroup.FromPartID.ToString()); 3594 return new LSL_Key(m_host.ParentGroup.FromPartID.ToString());
3394 } 3595 }
3596
3597 /// <summary>
3598 /// Sets the response type for an HTTP request/response
3599 /// </summary>
3600 /// <returns></returns>
3601 public void osSetContentType(LSL_Key id, string type)
3602 {
3603 CheckThreatLevel(ThreatLevel.High, "osSetContentType");
3604
3605 if (m_UrlModule != null)
3606 m_UrlModule.HttpContentType(new UUID(id),type);
3607 }
3608
3609 /// Shout an error if the object owner did not grant the script the specified permissions.
3610 /// </summary>
3611 /// <param name="perms"></param>
3612 /// <returns>boolean indicating whether an error was shouted.</returns>
3613 protected bool ShoutErrorOnLackingOwnerPerms(int perms, string errorPrefix)
3614 {
3615 m_host.AddScriptLPS(1);
3616 bool fail = false;
3617 if (m_item.PermsGranter != m_host.OwnerID)
3618 {
3619 fail = true;
3620 OSSLShoutError(string.Format("{0}. Permissions not granted to owner.", errorPrefix));
3621 }
3622 else if ((m_item.PermsMask & perms) == 0)
3623 {
3624 fail = true;
3625 OSSLShoutError(string.Format("{0}. Permissions not granted.", errorPrefix));
3626 }
3627
3628 return fail;
3629 }
3630
3631 protected void DropAttachment(bool checkPerms)
3632 {
3633 if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
3634 {
3635 return;
3636 }
3637
3638 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3639 ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
3640
3641 if (attachmentsModule != null && sp != null)
3642 {
3643 attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId);
3644 }
3645 }
3646
3647 protected void DropAttachmentAt(bool checkPerms, LSL_Vector pos, LSL_Rotation rot)
3648 {
3649 if (checkPerms && ShoutErrorOnLackingOwnerPerms(ScriptBaseClass.PERMISSION_ATTACH, "Cannot drop attachment"))
3650 {
3651 return;
3652 }
3653
3654 IAttachmentsModule attachmentsModule = m_ScriptEngine.World.AttachmentsModule;
3655 ScenePresence sp = attachmentsModule == null ? null : m_host.ParentGroup.Scene.GetScenePresence(m_host.ParentGroup.OwnerID);
3656
3657 if (attachmentsModule != null && sp != null)
3658 {
3659 attachmentsModule.DetachSingleAttachmentToGround(sp, m_host.ParentGroup.LocalId, pos, rot);
3660 }
3661 }
3662
3663 public void osDropAttachment()
3664 {
3665 CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachment");
3666 m_host.AddScriptLPS(1);
3667
3668 DropAttachment(true);
3669 }
3670
3671 public void osForceDropAttachment()
3672 {
3673 CheckThreatLevel(ThreatLevel.High, "osForceDropAttachment");
3674 m_host.AddScriptLPS(1);
3675
3676 DropAttachment(false);
3677 }
3678
3679 public void osDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
3680 {
3681 CheckThreatLevel(ThreatLevel.Moderate, "osDropAttachmentAt");
3682 m_host.AddScriptLPS(1);
3683
3684 DropAttachmentAt(true, pos, rot);
3685 }
3686
3687 public void osForceDropAttachmentAt(LSL_Vector pos, LSL_Rotation rot)
3688 {
3689 CheckThreatLevel(ThreatLevel.High, "osForceDropAttachmentAt");
3690 m_host.AddScriptLPS(1);
3691
3692 DropAttachmentAt(false, pos, rot);
3693 }
3395 } 3694 }
3396} 3695}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
index 678f9d5..4dd795d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs
@@ -352,7 +352,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
352 q = avatar.Rotation; 352 q = avatar.Rotation;
353 } 353 }
354 354
355 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 355 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q);
356 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); 356 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
357 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); 357 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
358 358
@@ -429,9 +429,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
429 try 429 try
430 { 430 {
431 Vector3 diff = toRegionPos - fromRegionPos; 431 Vector3 diff = toRegionPos - fromRegionPos;
432 LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z); 432 double dot = LSL_Types.Vector3.Dot(forward_dir, diff);
433 double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir); 433 double mag_obj = LSL_Types.Vector3.Mag(diff);
434 double mag_obj = LSL_Types.Vector3.Mag(obj_dir);
435 ang_obj = Math.Acos(dot / (mag_fwd * mag_obj)); 434 ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
436 } 435 }
437 catch 436 catch
@@ -483,7 +482,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
483 q = avatar.Rotation; 482 q = avatar.Rotation;
484 } 483 }
485 484
486 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W); 485 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q);
487 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r); 486 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
488 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir); 487 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
489 bool attached = (SensePoint.ParentGroup.AttachmentPoint != 0); 488 bool attached = (SensePoint.ParentGroup.AttachmentPoint != 0);
@@ -564,8 +563,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
564 double ang_obj = 0; 563 double ang_obj = 0;
565 try 564 try
566 { 565 {
567 Vector3 diff = toRegionPos - fromRegionPos; 566 LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(
568 LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z); 567 toRegionPos - fromRegionPos);
569 double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir); 568 double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir);
570 double mag_obj = LSL_Types.Vector3.Mag(obj_dir); 569 double mag_obj = LSL_Types.Vector3.Mag(obj_dir);
571 ang_obj = Math.Acos(dot / (mag_fwd * mag_obj)); 570 ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
index af35258..05c20f9 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -429,8 +429,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
429 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link); 429 LSL_Integer llGetLinkNumberOfSides(LSL_Integer link);
430 void llSetPhysicsMaterial(int material_bits, float material_gravity_modifier, float material_restitution, float material_friction, float material_density); 430 void llSetPhysicsMaterial(int material_bits, float material_gravity_modifier, float material_restitution, float material_friction, float material_density);
431 431
432 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules); 432 void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc);
433 LSL_List GetLinkPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
434 void llSetKeyframedMotion(LSL_List frames, LSL_List options); 433 void llSetKeyframedMotion(LSL_List frames, LSL_List options);
434 LSL_List GetPrimitiveParamsEx(LSL_Key prim, LSL_List rules);
435 } 435 }
436} 436}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 8c34ed3..b1fbed5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -40,16 +40,75 @@ using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
40 40
41namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces 41namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
42{ 42{
43 /// <summary>
44 /// To permit region owners to enable the extended scripting functionality
45 /// of OSSL, without allowing malicious scripts to access potentially
46 /// troublesome functions, each OSSL function is assigned a threat level,
47 /// and access to the functions is granted or denied based on a default
48 /// threshold set in OpenSim.ini (which can be overridden for individual
49 /// functions on a case-by-case basis)
50 /// </summary>
43 public enum ThreatLevel 51 public enum ThreatLevel
44 { 52 {
53 // Not documented, presumably means permanently disabled ?
45 NoAccess = -1, 54 NoAccess = -1,
55
56 /// <summary>
57 /// Function is no threat at all. It doesn't constitute a threat to
58 /// either users or the system and has no known side effects.
59 /// </summary>
46 None = 0, 60 None = 0,
61
62 /// <summary>
63 /// Abuse of this command can cause a nuisance to the region operator,
64 /// such as log message spew.
65 /// </summary>
47 Nuisance = 1, 66 Nuisance = 1,
67
68 /// <summary>
69 /// Extreme levels of abuse of this function can cause impaired
70 /// functioning of the region, or very gullible users can be tricked
71 /// into experiencing harmless effects.
72 /// </summary>
48 VeryLow = 2, 73 VeryLow = 2,
74
75 /// <summary>
76 /// Intentional abuse can cause crashes or malfunction under certain
77 /// circumstances, which can be easily rectified; or certain users can
78 /// be tricked into certain situations in an avoidable manner.
79 /// </summary>
49 Low = 3, 80 Low = 3,
81
82 /// <summary>
83 /// Intentional abuse can cause denial of service and crashes with
84 /// potential of data or state loss; or trusting users can be tricked
85 /// into embarrassing or uncomfortable situations.
86 /// </summary>
50 Moderate = 4, 87 Moderate = 4,
88
89 /// <summary>
90 /// Casual abuse can cause impaired functionality or temporary denial
91 /// of service conditions. Intentional abuse can easily cause crashes
92 /// with potential data loss, or can be used to trick experienced and
93 /// cautious users into unwanted situations, or changes global data
94 /// permanently and without undo ability.
95 /// </summary>
51 High = 5, 96 High = 5,
97
98 /// <summary>
99 /// Even normal use may, depending on the number of instances, or
100 /// frequency of use, result in severe service impairment or crash
101 /// with loss of data, or can be used to cause unwanted or harmful
102 /// effects on users without giving the user a means to avoid it.
103 /// </summary>
52 VeryHigh = 6, 104 VeryHigh = 6,
105
106 /// <summary>
107 /// Even casual use is a danger to region stability, or function allows
108 /// console or OS command execution, or function allows taking money
109 /// without consent, or allows deletion or modification of user data,
110 /// or allows the compromise of sensitive data by design.
111 /// </summary>
53 Severe = 7 112 Severe = 7
54 }; 113 };
55 114
@@ -98,7 +157,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
98 void osAvatarPlayAnimation(string avatar, string animation); 157 void osAvatarPlayAnimation(string avatar, string animation);
99 void osAvatarStopAnimation(string avatar, string animation); 158 void osAvatarStopAnimation(string avatar, string animation);
100 159
101 // Attachment commands 160 #region Attachment commands
102 161
103 /// <summary> 162 /// <summary>
104 /// Attach the object containing this script to the avatar that owns it without asking for PERMISSION_ATTACH 163 /// Attach the object containing this script to the avatar that owns it without asking for PERMISSION_ATTACH
@@ -133,6 +192,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
133 /// <remarks>Nothing happens if the object is not attached.</remarks> 192 /// <remarks>Nothing happens if the object is not attached.</remarks>
134 void osForceDetachFromAvatar(); 193 void osForceDetachFromAvatar();
135 194
195 /// <summary>
196 /// Returns a strided list of the specified attachment points and the number of attachments on those points.
197 /// </summary>
198 /// <param name="avatar">avatar UUID</param>
199 /// <param name="attachmentPoints">list of ATTACH_* constants</param>
200 /// <returns></returns>
201 LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints);
202
203 /// <summary>
204 /// Sends a specified message to the specified avatar's attachments on
205 /// the specified attachment points.
206 /// </summary>
207 /// <remarks>
208 /// Behaves as osMessageObject(), without the sending script needing to know the attachment keys in advance.
209 /// </remarks>
210 /// <param name="avatar">avatar UUID</param>
211 /// <param name="message">message string</param>
212 /// <param name="attachmentPoints">list of ATTACH_* constants, or -1 for all attachments. If -1 is specified and OS_ATTACH_MSG_INVERT_POINTS is present in flags, no action is taken.</param>
213 /// <param name="flags">flags further constraining the attachments to deliver the message to.</param>
214 void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int flags);
215
216 #endregion
217
136 //texture draw functions 218 //texture draw functions
137 string osMovePen(string drawList, int x, int y); 219 string osMovePen(string drawList, int x, int y);
138 string osDrawLine(string drawList, int startX, int startY, int endX, int endY); 220 string osDrawLine(string drawList, int startX, int startY, int endX, int endY);
@@ -258,6 +340,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
258 int osGetSimulatorMemory(); 340 int osGetSimulatorMemory();
259 void osKickAvatar(string FirstName,string SurName,string alert); 341 void osKickAvatar(string FirstName,string SurName,string alert);
260 void osSetSpeed(string UUID, LSL_Float SpeedModifier); 342 void osSetSpeed(string UUID, LSL_Float SpeedModifier);
343 LSL_Float osGetHealth(string avatar);
261 void osCauseHealing(string avatar, double healing); 344 void osCauseHealing(string avatar, double healing);
262 void osCauseDamage(string avatar, double damage); 345 void osCauseDamage(string avatar, double damage);
263 LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules); 346 LSL_List osGetPrimitiveParams(LSL_Key prim, LSL_List rules);
@@ -305,5 +388,35 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
305 /// </summary> 388 /// </summary>
306 /// <returns>Rezzing object key or NULL_KEY if rezzed by agent or otherwise unknown.</returns> 389 /// <returns>Rezzing object key or NULL_KEY if rezzed by agent or otherwise unknown.</returns>
307 LSL_Key osGetRezzingObject(); 390 LSL_Key osGetRezzingObject();
391
392 /// <summary>
393 /// Sets the response type for an HTTP request/response
394 /// </summary>
395 /// <returns></returns>
396 void osSetContentType(LSL_Key id, string type);
397
398 /// <summary>
399 /// Attempts to drop an attachment to the ground
400 /// </summary>
401 void osDropAttachment();
402
403 /// <summary>
404 /// Attempts to drop an attachment to the ground while bypassing the script permissions
405 /// </summary>
406 void osForceDropAttachment();
407
408 /// <summary>
409 /// Attempts to drop an attachment at the specified coordinates.
410 /// </summary>
411 /// <param name="pos"></param>
412 /// <param name="rot"></param>
413 void osDropAttachmentAt(vector pos, rotation rot);
414
415 /// <summary>
416 /// Attempts to drop an attachment at the specified coordinates while bypassing the script permissions
417 /// </summary>
418 /// <param name="pos"></param>
419 /// <param name="rot"></param>
420 void osForceDropAttachmentAt(vector pos, rotation rot);
308 } 421 }
309} 422}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index f989cc6..c788407 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -237,6 +237,58 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
237 public const int ATTACH_HUD_BOTTOM = 37; 237 public const int ATTACH_HUD_BOTTOM = 37;
238 public const int ATTACH_HUD_BOTTOM_RIGHT = 38; 238 public const int ATTACH_HUD_BOTTOM_RIGHT = 38;
239 239
240 #region osMessageAttachments constants
241
242 /// <summary>
243 /// Instructs osMessageAttachements to send the message to attachments
244 /// on every point.
245 /// </summary>
246 /// <remarks>
247 /// One might expect this to be named OS_ATTACH_ALL, but then one might
248 /// also expect functions designed to attach or detach or get
249 /// attachments to work with it too. Attaching a no-copy item to
250 /// many attachments could be dangerous.
251 /// when combined with OS_ATTACH_MSG_INVERT_POINTS, will prevent the
252 /// message from being sent.
253 /// if combined with OS_ATTACH_MSG_OBJECT_CREATOR or
254 /// OS_ATTACH_MSG_SCRIPT_CREATOR, could result in no message being
255 /// sent- this is expected behaviour.
256 /// </remarks>
257 public const int OS_ATTACH_MSG_ALL = -65535;
258
259 /// <summary>
260 /// Instructs osMessageAttachements to invert how the attachment points
261 /// list should be treated (e.g. go from inclusive operation to
262 /// exclusive operation).
263 /// </summary>
264 /// <remarks>
265 /// This might be used if you want to deliver a message to one set of
266 /// attachments and a different message to everything else. With
267 /// this flag, you only need to build one explicit list for both calls.
268 /// </remarks>
269 public const int OS_ATTACH_MSG_INVERT_POINTS = 1;
270
271 /// <summary>
272 /// Instructs osMessageAttachments to only send the message to
273 /// attachments with a CreatorID that matches the host object CreatorID
274 /// </summary>
275 /// <remarks>
276 /// This would be used if distributed in an object vendor/updater server.
277 /// </remarks>
278 public const int OS_ATTACH_MSG_OBJECT_CREATOR = 2;
279
280 /// <summary>
281 /// Instructs osMessageAttachments to only send the message to
282 /// attachments with a CreatorID that matches the sending script CreatorID
283 /// </summary>
284 /// <remarks>
285 /// This might be used if the script is distributed independently of a
286 /// containing object.
287 /// </remarks>
288 public const int OS_ATTACH_MSG_SCRIPT_CREATOR = 4;
289
290 #endregion
291
240 public const int LAND_LEVEL = 0; 292 public const int LAND_LEVEL = 0;
241 public const int LAND_RAISE = 1; 293 public const int LAND_RAISE = 1;
242 public const int LAND_LOWER = 2; 294 public const int LAND_LOWER = 2;
@@ -329,6 +381,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
329 public const int PRIM_OMEGA = 32; 381 public const int PRIM_OMEGA = 32;
330 public const int PRIM_POS_LOCAL = 33; 382 public const int PRIM_POS_LOCAL = 33;
331 public const int PRIM_LINK_TARGET = 34; 383 public const int PRIM_LINK_TARGET = 34;
384 public const int PRIM_SLICE = 35;
332 public const int PRIM_TEXGEN_DEFAULT = 0; 385 public const int PRIM_TEXGEN_DEFAULT = 0;
333 public const int PRIM_TEXGEN_PLANAR = 1; 386 public const int PRIM_TEXGEN_PLANAR = 1;
334 387
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 94405d2..dee1b28 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -289,7 +289,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
289 m_OSSL_Functions.osAvatarStopAnimation(avatar, animation); 289 m_OSSL_Functions.osAvatarStopAnimation(avatar, animation);
290 } 290 }
291 291
292 // Avatar functions 292 #region Attachment commands
293 293
294 public void osForceAttachToAvatar(int attachmentPoint) 294 public void osForceAttachToAvatar(int attachmentPoint)
295 { 295 {
@@ -311,6 +311,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
311 m_OSSL_Functions.osForceDetachFromAvatar(); 311 m_OSSL_Functions.osForceDetachFromAvatar();
312 } 312 }
313 313
314 public LSL_List osGetNumberOfAttachments(LSL_Key avatar, LSL_List attachmentPoints)
315 {
316 return m_OSSL_Functions.osGetNumberOfAttachments(avatar, attachmentPoints);
317 }
318
319 public void osMessageAttachments(LSL_Key avatar, string message, LSL_List attachmentPoints, int flags)
320 {
321 m_OSSL_Functions.osMessageAttachments(avatar, message, attachmentPoints, flags);
322 }
323
324 #endregion
325
314 // Texture Draw functions 326 // Texture Draw functions
315 327
316 public string osMovePen(string drawList, int x, int y) 328 public string osMovePen(string drawList, int x, int y)
@@ -865,7 +877,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
865 { 877 {
866 m_OSSL_Functions.osSetSpeed(UUID, SpeedModifier); 878 m_OSSL_Functions.osSetSpeed(UUID, SpeedModifier);
867 } 879 }
868 880
881 public LSL_Float osGetHealth(string avatar)
882 {
883 return m_OSSL_Functions.osGetHealth(avatar);
884 }
885
869 public void osCauseDamage(string avatar, double damage) 886 public void osCauseDamage(string avatar, double damage)
870 { 887 {
871 m_OSSL_Functions.osCauseDamage(avatar, damage); 888 m_OSSL_Functions.osCauseDamage(avatar, damage);
@@ -950,5 +967,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
950 { 967 {
951 return m_OSSL_Functions.osGetRezzingObject(); 968 return m_OSSL_Functions.osGetRezzingObject();
952 } 969 }
970
971 public void osSetContentType(LSL_Key id, string type)
972 {
973 m_OSSL_Functions.osSetContentType(id,type);
974 }
975
976 public void osDropAttachment()
977 {
978 m_OSSL_Functions.osDropAttachment();
979 }
980
981 public void osForceDropAttachment()
982 {
983 m_OSSL_Functions.osForceDropAttachment();
984 }
985
986 public void osDropAttachmentAt(vector pos, rotation rot)
987 {
988 m_OSSL_Functions.osDropAttachmentAt(pos, rot);
989 }
990
991 public void osForceDropAttachmentAt(vector pos, rotation rot)
992 {
993 m_OSSL_Functions.osForceDropAttachmentAt(pos, rot);
994 }
953 } 995 }
954} 996}
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
index 17a0d69..03be2ab 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
@@ -546,6 +546,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
546 "OpenSim.Region.ScriptEngine.Shared.dll")); 546 "OpenSim.Region.ScriptEngine.Shared.dll"));
547 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, 547 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
548 "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll")); 548 "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll"));
549 parameters.ReferencedAssemblies.Add(Path.Combine(rootPath,
550 "OpenMetaverseTypes.dll"));
549 551
550 if (lang == enumCompileType.yp) 552 if (lang == enumCompileType.yp)
551 { 553 {
diff --git a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
index 9e5fb24..22804f5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Helpers.cs
@@ -164,11 +164,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
164 else 164 else
165 { 165 {
166 // Set the values from the touch data provided by the client 166 // Set the values from the touch data provided by the client
167 touchST = new LSL_Types.Vector3(value.STCoord.X, value.STCoord.Y, value.STCoord.Z); 167 touchST = new LSL_Types.Vector3(value.STCoord);
168 touchUV = new LSL_Types.Vector3(value.UVCoord.X, value.UVCoord.Y, value.UVCoord.Z); 168 touchUV = new LSL_Types.Vector3(value.UVCoord);
169 touchNormal = new LSL_Types.Vector3(value.Normal.X, value.Normal.Y, value.Normal.Z); 169 touchNormal = new LSL_Types.Vector3(value.Normal);
170 touchBinormal = new LSL_Types.Vector3(value.Binormal.X, value.Binormal.Y, value.Binormal.Z); 170 touchBinormal = new LSL_Types.Vector3(value.Binormal);
171 touchPos = new LSL_Types.Vector3(value.Position.X, value.Position.Y, value.Position.Z); 171 touchPos = new LSL_Types.Vector3(value.Position);
172 touchFace = value.FaceIndex; 172 touchFace = value.FaceIndex;
173 } 173 }
174 } 174 }
@@ -189,19 +189,13 @@ namespace OpenSim.Region.ScriptEngine.Shared
189 Country = account.UserCountry; 189 Country = account.UserCountry;
190 190
191 Owner = Key; 191 Owner = Key;
192 Position = new LSL_Types.Vector3( 192 Position = new LSL_Types.Vector3(presence.AbsolutePosition);
193 presence.AbsolutePosition.X,
194 presence.AbsolutePosition.Y,
195 presence.AbsolutePosition.Z);
196 Rotation = new LSL_Types.Quaternion( 193 Rotation = new LSL_Types.Quaternion(
197 presence.Rotation.X, 194 presence.Rotation.X,
198 presence.Rotation.Y, 195 presence.Rotation.Y,
199 presence.Rotation.Z, 196 presence.Rotation.Z,
200 presence.Rotation.W); 197 presence.Rotation.W);
201 Velocity = new LSL_Types.Vector3( 198 Velocity = new LSL_Types.Vector3(presence.Velocity);
202 presence.Velocity.X,
203 presence.Velocity.Y,
204 presence.Velocity.Z);
205 199
206 Type = 0x01; // Avatar 200 Type = 0x01; // Avatar
207 if (presence.PresenceType == PresenceType.Npc) 201 if (presence.PresenceType == PresenceType.Npc)
@@ -254,16 +248,12 @@ namespace OpenSim.Region.ScriptEngine.Shared
254 } 248 }
255 } 249 }
256 250
257 Position = new LSL_Types.Vector3(part.AbsolutePosition.X, 251 Position = new LSL_Types.Vector3(part.AbsolutePosition);
258 part.AbsolutePosition.Y,
259 part.AbsolutePosition.Z);
260 252
261 Quaternion wr = part.ParentGroup.GroupRotation; 253 Quaternion wr = part.ParentGroup.GroupRotation;
262 Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W); 254 Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W);
263 255
264 Velocity = new LSL_Types.Vector3(part.Velocity.X, 256 Velocity = new LSL_Types.Vector3(part.Velocity);
265 part.Velocity.Y,
266 part.Velocity.Z);
267 } 257 }
268 } 258 }
269 259
diff --git a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
index 8adf4c5..c9c4753 100644
--- a/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/LSL_Types.cs
@@ -31,6 +31,11 @@ using System.Globalization;
31using System.Text.RegularExpressions; 31using System.Text.RegularExpressions;
32using OpenSim.Framework; 32using OpenSim.Framework;
33 33
34using OpenMetaverse;
35using OMV_Vector3 = OpenMetaverse.Vector3;
36using OMV_Vector3d = OpenMetaverse.Vector3d;
37using OMV_Quaternion = OpenMetaverse.Quaternion;
38
34namespace OpenSim.Region.ScriptEngine.Shared 39namespace OpenSim.Region.ScriptEngine.Shared
35{ 40{
36 [Serializable] 41 [Serializable]
@@ -54,6 +59,20 @@ namespace OpenSim.Region.ScriptEngine.Shared
54 z = (float)vector.z; 59 z = (float)vector.z;
55 } 60 }
56 61
62 public Vector3(OMV_Vector3 vector)
63 {
64 x = vector.X;
65 y = vector.Y;
66 z = vector.Z;
67 }
68
69 public Vector3(OMV_Vector3d vector)
70 {
71 x = vector.X;
72 y = vector.Y;
73 z = vector.Z;
74 }
75
57 public Vector3(double X, double Y, double Z) 76 public Vector3(double X, double Y, double Z)
58 { 77 {
59 x = X; 78 x = X;
@@ -109,6 +128,26 @@ namespace OpenSim.Region.ScriptEngine.Shared
109 return new list(new object[] { vec }); 128 return new list(new object[] { vec });
110 } 129 }
111 130
131 public static implicit operator OMV_Vector3(Vector3 vec)
132 {
133 return new OMV_Vector3((float)vec.x, (float)vec.y, (float)vec.z);
134 }
135
136 public static implicit operator Vector3(OMV_Vector3 vec)
137 {
138 return new Vector3(vec);
139 }
140
141 public static implicit operator OMV_Vector3d(Vector3 vec)
142 {
143 return new OMV_Vector3d(vec.x, vec.y, vec.z);
144 }
145
146 public static implicit operator Vector3(OMV_Vector3d vec)
147 {
148 return new Vector3(vec);
149 }
150
112 public static bool operator ==(Vector3 lhs, Vector3 rhs) 151 public static bool operator ==(Vector3 lhs, Vector3 rhs)
113 { 152 {
114 return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z); 153 return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
@@ -322,6 +361,14 @@ namespace OpenSim.Region.ScriptEngine.Shared
322 s = 1; 361 s = 1;
323 } 362 }
324 363
364 public Quaternion(OMV_Quaternion rot)
365 {
366 x = rot.X;
367 y = rot.Y;
368 z = rot.Z;
369 s = rot.W;
370 }
371
325 #endregion 372 #endregion
326 373
327 #region Overriders 374 #region Overriders
@@ -368,6 +415,21 @@ namespace OpenSim.Region.ScriptEngine.Shared
368 return new list(new object[] { r }); 415 return new list(new object[] { r });
369 } 416 }
370 417
418 public static implicit operator OMV_Quaternion(Quaternion rot)
419 {
420 // LSL quaternions can normalize to 0, normal Quaternions can't.
421 if (rot.s == 0 && rot.x == 0 && rot.y == 0 && rot.z == 0)
422 rot.z = 1; // ZERO_ROTATION = 0,0,0,1
423 OMV_Quaternion omvrot = new OMV_Quaternion((float)rot.x, (float)rot.y, (float)rot.z, (float)rot.s);
424 omvrot.Normalize();
425 return omvrot;
426 }
427
428 public static implicit operator Quaternion(OMV_Quaternion rot)
429 {
430 return new Quaternion(rot);
431 }
432
371 public static bool operator ==(Quaternion lhs, Quaternion rhs) 433 public static bool operator ==(Quaternion lhs, Quaternion rhs)
372 { 434 {
373 // Return true if the fields match: 435 // Return true if the fields match:
@@ -562,12 +624,23 @@ namespace OpenSim.Region.ScriptEngine.Shared
562 else if (m_data[itemIndex] is LSL_Types.LSLString) 624 else if (m_data[itemIndex] is LSL_Types.LSLString)
563 return new LSLInteger(m_data[itemIndex].ToString()); 625 return new LSLInteger(m_data[itemIndex].ToString());
564 else 626 else
565 throw new InvalidCastException(); 627 throw new InvalidCastException(string.Format(
628 "{0} expected but {1} given",
629 typeof(LSL_Types.LSLInteger).Name,
630 m_data[itemIndex] != null ?
631 m_data[itemIndex].GetType().Name : "null"));
566 } 632 }
567 633
568 public LSL_Types.Vector3 GetVector3Item(int itemIndex) 634 public LSL_Types.Vector3 GetVector3Item(int itemIndex)
569 { 635 {
570 return (LSL_Types.Vector3)m_data[itemIndex]; 636 if(m_data[itemIndex] is LSL_Types.Vector3)
637 return (LSL_Types.Vector3)m_data[itemIndex];
638 else
639 throw new InvalidCastException(string.Format(
640 "{0} expected but {1} given",
641 typeof(LSL_Types.Vector3).Name,
642 m_data[itemIndex] != null ?
643 m_data[itemIndex].GetType().Name : "null"));
571 } 644 }
572 645
573 public LSL_Types.Quaternion GetQuaternionItem(int itemIndex) 646 public LSL_Types.Quaternion GetQuaternionItem(int itemIndex)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs
new file mode 100644
index 0000000..dd23be8
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs
@@ -0,0 +1,134 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using NUnit.Framework;
31using OpenSim.Framework;
32using OpenSim.Tests.Common;
33using OpenSim.Region.ScriptEngine.Shared;
34using OpenSim.Region.Framework.Scenes;
35using Nini.Config;
36using OpenSim.Region.ScriptEngine.Shared.Api;
37using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
38using OpenMetaverse;
39using OpenSim.Tests.Common.Mock;
40
41using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
42using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
43using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
44using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
45
46namespace OpenSim.Region.ScriptEngine.Shared.Tests
47{
48 [TestFixture]
49 public class LSL_ApiListTests
50 {
51 private LSL_Api m_lslApi;
52
53 [SetUp]
54 public void SetUp()
55 {
56 IConfigSource initConfigSource = new IniConfigSource();
57 IConfig config = initConfigSource.AddConfig("XEngine");
58 config.Set("Enabled", "true");
59
60 Scene scene = new SceneHelpers().SetupScene();
61 SceneObjectPart part = SceneHelpers.AddSceneObject(scene).RootPart;
62
63 XEngine.XEngine engine = new XEngine.XEngine();
64 engine.Initialise(initConfigSource);
65 engine.AddRegion(scene);
66
67 m_lslApi = new LSL_Api();
68 m_lslApi.Initialize(engine, part, null);
69 }
70
71 [Test]
72 public void TestllListFindList()
73 {
74 TestHelpers.InMethod();
75
76 LSL_List src = new LSL_List(new LSL_Integer(1), new LSL_Integer(2), new LSL_Integer(3));
77
78 {
79 // Test for a single item that should be found
80 int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(4)));
81 Assert.That(result, Is.EqualTo(-1));
82 }
83
84 {
85 // Test for a single item that should be found
86 int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(2)));
87 Assert.That(result, Is.EqualTo(1));
88 }
89
90 {
91 // Test for a constant that should be found
92 int result = m_lslApi.llListFindList(src, new LSL_List(ScriptBaseClass.AGENT));
93 Assert.That(result, Is.EqualTo(0));
94 }
95
96 {
97 // Test for a list that should be found
98 int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(2), new LSL_Integer(3)));
99 Assert.That(result, Is.EqualTo(1));
100 }
101
102 {
103 // Test for a single item not in the list
104 int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(4)));
105 Assert.That(result, Is.EqualTo(-1));
106 }
107
108 {
109 // Test for something that should not be cast
110 int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_String("4")));
111 Assert.That(result, Is.EqualTo(-1));
112 }
113
114 {
115 // Test for a list not in the list
116 int result
117 = m_lslApi.llListFindList(
118 src, new LSL_List(new LSL_Integer(2), new LSL_Integer(3), new LSL_Integer(4)));
119 Assert.That(result, Is.EqualTo(-1));
120 }
121
122 {
123 LSL_List srcWithConstants
124 = new LSL_List(new LSL_Integer(3), ScriptBaseClass.AGENT, ScriptBaseClass.OS_NPC_LAND_AT_TARGET);
125
126 // Test for constants that appears in the source list that should be found
127 int result
128 = m_lslApi.llListFindList(srcWithConstants, new LSL_List(new LSL_Integer(1), new LSL_Integer(2)));
129
130 Assert.That(result, Is.EqualTo(1));
131 }
132 }
133 }
134 } \ No newline at end of file