From 22437af26af8c70c8cab3aece31cfc59595b54b4 Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Fri, 8 Jun 2012 15:48:46 +0100
Subject: *UNTESTED* fix PRIM_LINK_TARGET. Make it work on avatars, set any
 pending position change on others; don't assume m_host is in same grp that
 part (possible always is)...

---
 .../Shared/Api/Implementation/LSL_Api.cs           | 44 ++++++++++++++++++----
 1 file changed, 37 insertions(+), 7 deletions(-)

(limited to 'OpenSim')

diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index cb13855..523a6ca 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -8003,7 +8003,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
                     case (int)ScriptBaseClass.PRIM_TEXT:
                     case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                     case (int)ScriptBaseClass.PRIM_OMEGA:
-                    case (int)ScriptBaseClass.PRIM_LINK_TARGET:
                         if (remain < 3)
                             return;
                         idx += 3;
@@ -8023,6 +8022,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
 
                         idx += 7;
                         break;
+
+                    case (int)ScriptBaseClass.PRIM_LINK_TARGET:
+                        if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
+                            return;
+                        LSL_Integer new_linknumber = rules.GetLSLIntegerItem(idx++);
+                        LSL_List new_rules = rules.GetSublist(idx, -1);
+                        setLinkPrimParams((int)new_linknumber, new_rules);
+                        return;
                 }
             }
         }
@@ -8034,6 +8041,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
 
             int idx = 0;
 
+            SceneObjectGroup parentgrp = part.ParentGroup;
+
             bool positionChanged = false;
             LSL_Vector currentPosition = GetPartLocalPos(part);
 
@@ -8073,8 +8082,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
                                 return;
 
                             LSL_Rotation q = rules.GetQuaternionItem(idx++);
+                            SceneObjectPart rootPart = parentgrp.RootPart;
                             // try to let this work as in SL...
-                            if (part.ParentID == 0)
+                            if (rootPart == part)
                             {
                                 // special case: If we are root, rotate complete SOG to new rotation
                                 SetRot(part, Rot2Quaternion(q));
@@ -8083,7 +8093,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
                             {
                                 // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
                                 // sounds like sl bug that we need to replicate
-                                SceneObjectPart rootPart = part.ParentGroup.RootPart;
                                 SetRot(part, rootPart.RotationOffset * Rot2Quaternion(q));
                             }
 
@@ -8336,7 +8345,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
                                  return;
 
                              string ph = rules.Data[idx++].ToString();
-                             m_host.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));
+                             parentgrp.ScriptSetPhantomStatus(ph.Equals("1"));
 
                              break;
 
@@ -8389,7 +8398,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
                                 return;
                             string temp = rules.Data[idx++].ToString();
 
-                            m_host.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));
+                            parentgrp.ScriptSetTemporaryStatus(temp.Equals("1"));
 
                             break;
 
@@ -8442,10 +8451,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
                         case (int)ScriptBaseClass.PRIM_LINK_TARGET:
                             if (remain < 3) // setting to 3 on the basis that parsing any usage of PRIM_LINK_TARGET that has nothing following it is pointless.
                                 return;
+
+                            // do a pending position change
+                            if (positionChanged)
+                            {
+                                if (parentgrp == null)
+                                    return;
+
+                                if (parentgrp.RootPart == part)
+                                {
+
+                                    Util.FireAndForget(delegate(object x)
+                                    {
+                                        parentgrp.UpdateGroupPosition(new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z));
+                                    });
+                                }
+                                else
+                                {
+                                    part.OffsetPosition = new Vector3((float)currentPosition.x, (float)currentPosition.y, (float)currentPosition.z);
+                                    parentgrp.HasGroupChanged = true;
+                                    parentgrp.ScheduleGroupForTerseUpdate();
+                                }
+                            }
+
                             LSL_Integer new_linknumber = rules.GetLSLIntegerItem(idx++);
                             LSL_List new_rules = rules.GetSublist(idx, -1);
                             setLinkPrimParams((int)new_linknumber, new_rules);
-
                             return;
                     }
                 }
@@ -8475,7 +8506,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
 
             if (positionChanged)
             {
-                SceneObjectGroup parentgrp = part.ParentGroup;
                 if (parentgrp == null)
                     return;
 
-- 
cgit v1.1