Example #1
0
        /// <summary>
        /// illListReplaceList removes the sub-list defined by the inclusive indices
        /// start and end and inserts the src list in its place. The inclusive
        /// nature of the indices means that at least one element must be deleted
        /// if the indices are within the bounds of the existing list. I.e. 2,2
        /// will remove the element at index 2 and replace it with the source
        /// list. Both indices may be negative, with the usual interpretation. An
        /// interesting case is where end is lower than start. As these indices
        /// bound the list to be removed, then 0->end, and start->lim are removed
        /// and the source list is added as a suffix.
        /// </summary>

        public LSL_List llListReplaceList(LSL_List dest, LSL_List src, int start, int end)
        {
            LSL_List pref = null;

            m_host.AddScriptLPS(1);

            // Note that although we have normalized, both
            // indices could still be negative.
            if (start < 0)
            {
                start = start+dest.Length;
            }

            if (end < 0)
            {
                end = end+dest.Length;
            }
            // The comventional case, remove a sequence starting with
            // start and ending with end. And then insert the source
            // list.
            if (start <= end)
            {
                // If greater than zero, then there is going to be a
                // surviving prefix. Otherwise the inclusive nature
                // of the indices mean that we're going to add the
                // source list as a prefix.
                if (start > 0)
                {
                    pref = dest.GetSublist(0,start-1);
                    // Only add a suffix if there is something
                    // beyond the end index (it's inclusive too).
                    if (end + 1 < dest.Length)
                    {
                        return pref + src + dest.GetSublist(end + 1, -1);
                    }
                    else
                    {
                        return pref + src;
                    }
                }
                // If start is less than or equal to zero, then
                // the new list is simply a prefix. We still need to
                // figure out any necessary surgery to the destination
                // based upon end. Note that if end exceeds the upper
                // bound in this case, the entire destination list
                // is removed.
                else
                {
                    if (end + 1 < dest.Length)
                    {
                        return src + dest.GetSublist(end + 1, -1);
                    }
                    else
                    {
                        return src;
                    }
                }
            }
            // Finally, if start > end, we strip away a prefix and
            // a suffix, to leave the list that sits <between> ens
            // and start, and then tag on the src list. AT least
            // that's my interpretation. We can get sublist to do
            // this for us. Note that one, or both of the indices
            // might have been negative.
            else
            {
                return dest.GetSublist(end + 1, start - 1) + src;
            }
        }
Example #2
0
        /// <summary>
        /// Get the primitive parameters of a linked prim.
        /// </summary>
        /// <remarks>
        /// Threat level is 'Low' because certain users could possibly be tricked into
        /// dropping an unverified script into one of their own objects, which could
        /// then gather the physical construction details of the object and transmit it
        /// to an unscrupulous third party, thus permitting unauthorized duplication of
        /// the object's form.
        /// </remarks>
        /// <param name="linknumber"></param>
        /// <param name="rules"></param>
        /// <returns></returns>
        public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
        {
            CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams");
            m_host.AddScriptLPS(1);
            InitLSL();
            // One needs to cast m_LSL_Api because we're using functions not
            // on the ILSL_Api interface.
            LSL_Api LSL_Api = (LSL_Api)m_LSL_Api;
            LSL_List retVal = new LSL_List();
            LSL_List remaining = new LSL_List();
            List<SceneObjectPart> parts = LSL_Api.GetLinkParts(linknumber);
            foreach (SceneObjectPart part in parts)
            {
                remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
            }

            while (remaining.Length > 2)
            {
                linknumber = remaining.GetLSLIntegerItem(0);
                rules = remaining.GetSublist(1, -1);
                parts = LSL_Api.GetLinkParts(linknumber);

                foreach (SceneObjectPart part in parts)
                    remaining = LSL_Api.GetPrimParams(part, rules, ref retVal);
            }
            return retVal;
        }
Example #3
0
        /// <summary>
        /// Insert the list identified by <src> into the
        /// list designated by <dest> such that the first
        /// new element has the index specified by <index>
        /// </summary>

        public LSL_List llListInsertList(LSL_List dest, LSL_List src, int index)
        {

            LSL_List pref = null;
            LSL_List suff = null;

            m_host.AddScriptLPS(1);

            if (index < 0)
            {
                index = index+dest.Length;
                if (index < 0)
                {
                    index = 0;
                }
            }

            if (index != 0)
            {
                pref = dest.GetSublist(0,index-1);
                if (index < dest.Length)
                {
                    suff = dest.GetSublist(index,-1);
                    return pref + src + suff;
                }
                else
                {
                    return pref + src;
                }
            }
            else
            {
                if (index < dest.Length)
                {
                    suff = dest.GetSublist(index,-1);
                    return src + suff;
                }
                else
                {
                    return src;
                }
            }

        }
Example #4
0
        protected void SetPrimParams(SceneObjectPart part, LSL_List rules)
        {
            int idx = 0;

            bool positionChanged = false;
            LSL_Vector currentPosition = GetPartLocalPos(part);

            try
            {
                while (idx < rules.Length)
                {
                    int code = rules.GetLSLIntegerItem(idx++);

                    int remain = rules.Length - idx;

                    int face;
                    LSL_Vector v;

                    switch (code)
                    {
                        case (int)ScriptBaseClass.PRIM_POSITION:
                        case (int)ScriptBaseClass.PRIM_POS_LOCAL:
                            if (remain < 1)
                                return;

                            v=rules.GetVector3Item(idx++);
                            positionChanged = true;
                            currentPosition = GetSetPosTarget(part, v, currentPosition);

                            break;
                        case (int)ScriptBaseClass.PRIM_SIZE:
                            if (remain < 1)
                                return;

                            v=rules.GetVector3Item(idx++);
                            SetScale(part, v);

                            break;
                        case (int)ScriptBaseClass.PRIM_ROTATION:
                            if (remain < 1)
                                return;

                            LSL_Rotation q = rules.GetQuaternionItem(idx++);
                            // try to let this work as in SL...
                            if (part.ParentID == 0)
                            {
                                // special case: If we are root, rotate complete SOG to new rotation
                                SetRot(part, Rot2Quaternion(q));
                            }
                            else
                            {
                                // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
                                SceneObjectPart rootPart = part.ParentGroup.RootPart;
                                SetRot(part, rootPart.RotationOffset * Rot2Quaternion(q));
                            }

                            break;

                        case (int)ScriptBaseClass.PRIM_TYPE:
                            if (remain < 3)
                                return;

                            code = (int)rules.GetLSLIntegerItem(idx++);

                            remain = rules.Length - idx;
                            float hollow;
                            LSL_Vector twist;
                            LSL_Vector taper_b;
                            LSL_Vector topshear;
                            float revolutions;
                            float radiusoffset;
                            float skew;
                            LSL_Vector holesize;
                            LSL_Vector profilecut;

                            switch (code)
                            {
                                case (int)ScriptBaseClass.PRIM_TYPE_BOX:
                                    if (remain < 6)
                                        return;

                                    face = (int)rules.GetLSLIntegerItem(idx++);
                                    v = rules.GetVector3Item(idx++); // cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);

                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
                                        (byte)ProfileShape.Square, (byte)Extrusion.Straight);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
                                    if (remain < 6)
                                        return;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); // cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
                                        (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
                                    if (remain < 6)
                                        return;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); //cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
                                        (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
                                    if (remain < 5)
                                        return;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); // cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++); // dimple
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
                                        (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
                                    if (remain < 11)
                                        return;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); //cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    holesize = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);
                                    profilecut = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++); // taper_a
                                    revolutions = (float)rules.GetLSLFloatItem(idx++);
                                    radiusoffset = (float)rules.GetLSLFloatItem(idx++);
                                    skew = (float)rules.GetLSLFloatItem(idx++);
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
                                        revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
                                    if (remain < 11)
                                        return;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); //cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    holesize = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);
                                    profilecut = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++); // taper_a
                                    revolutions = (float)rules.GetLSLFloatItem(idx++);
                                    radiusoffset = (float)rules.GetLSLFloatItem(idx++);
                                    skew = (float)rules.GetLSLFloatItem(idx++);
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
                                        revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_RING:
                                    if (remain < 11)
                                        return;

                                    face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    v = rules.GetVector3Item(idx++); //cut
                                    hollow = (float)rules.GetLSLFloatItem(idx++);
                                    twist = rules.GetVector3Item(idx++);
                                    holesize = rules.GetVector3Item(idx++);
                                    topshear = rules.GetVector3Item(idx++);
                                    profilecut = rules.GetVector3Item(idx++);
                                    taper_b = rules.GetVector3Item(idx++); // taper_a
                                    revolutions = (float)rules.GetLSLFloatItem(idx++);
                                    radiusoffset = (float)rules.GetLSLFloatItem(idx++);
                                    skew = (float)rules.GetLSLFloatItem(idx++);
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
                                        revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
                                    if (remain < 2)
                                        return;

                                    string map = rules.Data[idx++].ToString();
                                    face = (int)rules.GetLSLIntegerItem(idx++); // type
                                    SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
                                    break;
                            }

                            break;

                        case (int)ScriptBaseClass.PRIM_TEXTURE:
                            if (remain < 5)
                                return;

                            face=(int)rules.GetLSLIntegerItem(idx++);
                            string tex=rules.Data[idx++].ToString();
                            LSL_Vector repeats=rules.GetVector3Item(idx++);
                            LSL_Vector offsets=rules.GetVector3Item(idx++);
                            double rotation=(double)rules.GetLSLFloatItem(idx++);

                            SetTexture(part, tex, face);
                            ScaleTexture(part, repeats.x, repeats.y, face);
                            OffsetTexture(part, offsets.x, offsets.y, face);
                            RotateTexture(part, rotation, face);

                            break;

                        case (int)ScriptBaseClass.PRIM_COLOR:
                            if (remain < 3)
                                return;

                            face=(int)rules.GetLSLIntegerItem(idx++);
                            LSL_Vector color=rules.GetVector3Item(idx++);
                            double alpha=(double)rules.GetLSLFloatItem(idx++);

                            part.SetFaceColor(new Vector3((float)color.x, (float)color.y, (float)color.z), face);
                            SetAlpha(part, alpha, face);

                            break;

                        case (int)ScriptBaseClass.PRIM_FLEXIBLE:
                            if (remain < 7)
                                return;

                            bool flexi = rules.GetLSLIntegerItem(idx++);
                            int softness = rules.GetLSLIntegerItem(idx++);
                            float gravity = (float)rules.GetLSLFloatItem(idx++);
                            float friction = (float)rules.GetLSLFloatItem(idx++);
                            float wind = (float)rules.GetLSLFloatItem(idx++);
                            float tension = (float)rules.GetLSLFloatItem(idx++);
                            LSL_Vector force = rules.GetVector3Item(idx++);

                            SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);

                            break;

                        case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
                            if (remain < 5)
                                return;
                            bool light = rules.GetLSLIntegerItem(idx++);
                            LSL_Vector lightcolor = rules.GetVector3Item(idx++);
                            float intensity = (float)rules.GetLSLFloatItem(idx++);
                            float radius = (float)rules.GetLSLFloatItem(idx++);
                            float falloff = (float)rules.GetLSLFloatItem(idx++);

                            SetPointLight(part, light, lightcolor, intensity, radius, falloff);

                            break;

                        case (int)ScriptBaseClass.PRIM_GLOW:
                            if (remain < 2)
                                return;
                            face = rules.GetLSLIntegerItem(idx++);
                            float glow = (float)rules.GetLSLFloatItem(idx++);

                            SetGlow(part, face, glow);

                            break;

                        case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                            if (remain < 3)
                                return;
                            face = (int)rules.GetLSLIntegerItem(idx++);
                            int shiny = (int)rules.GetLSLIntegerItem(idx++);
                            Bumpiness bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);

                            SetShiny(part, face, shiny, bump);

                            break;

                         case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
                             if (remain < 2)
                                 return;
                             face = rules.GetLSLIntegerItem(idx++);
                             bool st = rules.GetLSLIntegerItem(idx++);
                             SetFullBright(part, face , st);
                             break;

                         case (int)ScriptBaseClass.PRIM_MATERIAL:
                             if (remain < 1)
                                 return;
                             int mat = rules.GetLSLIntegerItem(idx++);
                             if (mat < 0 || mat > 7)
                                 return;

                             part.Material = Convert.ToByte(mat);
                             break;

                         case (int)ScriptBaseClass.PRIM_PHANTOM:
                             if (remain < 1)
                                 return;

                             string ph = rules.Data[idx++].ToString();
                             m_host.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));

                             break;

                         case (int)ScriptBaseClass.PRIM_PHYSICS:
                            if (remain < 1)
                                 return;
                             string phy = rules.Data[idx++].ToString();
                             bool physics;

                             if (phy.Equals("1"))
                                 physics = true;
                             else
                                 physics = false;

                             part.ScriptSetPhysicsStatus(physics);
                             break;

                        case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
                            if (remain < 1)
                                return;
                            string temp = rules.Data[idx++].ToString();

                            m_host.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));

                            break;

                        case (int)ScriptBaseClass.PRIM_TEXGEN:
                            if (remain < 2)
                                return;
                                //face,type
                            face = rules.GetLSLIntegerItem(idx++);
                            int style = rules.GetLSLIntegerItem(idx++);
                            SetTexGen(part, face, style);
                            break;
                        case (int)ScriptBaseClass.PRIM_TEXT:
                            if (remain < 3)
                                return;
                            string primText = rules.GetLSLStringItem(idx++);
                            LSL_Vector primTextColor = rules.GetVector3Item(idx++);
                            LSL_Float primTextAlpha = rules.GetLSLFloatItem(idx++);
                            Vector3 av3 = new Vector3(Util.Clip((float)primTextColor.x, 0.0f, 1.0f),
                                          Util.Clip((float)primTextColor.y, 0.0f, 1.0f),
                                          Util.Clip((float)primTextColor.z, 0.0f, 1.0f));
                            part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));

                            break;
                        case (int)ScriptBaseClass.PRIM_NAME:
                            if (remain < 1)
                                return;
                            string primName = rules.GetLSLStringItem(idx++);
                            part.Name = primName;
                            break;
                        case (int)ScriptBaseClass.PRIM_DESC:
                            if (remain < 1)
                                return;
                            string primDesc = rules.GetLSLStringItem(idx++);
                            part.Description = primDesc;
                            break;
                        case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
                            if (remain < 1)
                                return;
                            LSL_Rotation lr = rules.GetQuaternionItem(idx++);
                            SetRot(part, Rot2Quaternion(lr));
                            break;
                        case (int)ScriptBaseClass.PRIM_OMEGA:
                            if (remain < 3)
                                return;
                            LSL_Vector axis = rules.GetVector3Item(idx++);
                            LSL_Float spinrate = rules.GetLSLFloatItem(idx++);
                            LSL_Float gain = rules.GetLSLFloatItem(idx++);
                            TargetOmega(part, axis, (double)spinrate, (double)gain);
                            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;
                    }
                }
            }
            finally
            {
                if (positionChanged)
                {
                    if (part.ParentGroup.RootPart == part)
                    {
                        SceneObjectGroup parent = part.ParentGroup;
                        parent.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);
                        SceneObjectGroup parent = part.ParentGroup;
                        parent.HasGroupChanged = true;
                        parent.ScheduleGroupForTerseUpdate();
                    }
                }
            }
        }
Example #5
0
        public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
        {
            int idx = 0;
            while (idx < rules.Length)
            {
                int code = (int)rules.GetLSLIntegerItem(idx++);
                int remain = rules.Length - idx;

                switch (code)
                {
                    case (int)ScriptBaseClass.PRIM_MATERIAL:
                        res.Add(new LSL_Integer(part.Material));
                        break;

                    case (int)ScriptBaseClass.PRIM_PHYSICS:
                        if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Physics) != 0)
                            res.Add(new LSL_Integer(1));
                        else
                            res.Add(new LSL_Integer(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
                        if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) != 0)
                            res.Add(new LSL_Integer(1));
                        else
                            res.Add(new LSL_Integer(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_PHANTOM:
                        if ((part.GetEffectiveObjectFlags() & (uint)PrimFlags.Phantom) != 0)
                            res.Add(new LSL_Integer(1));
                        else
                            res.Add(new LSL_Integer(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_POSITION:
                        LSL_Vector v = new LSL_Vector(part.AbsolutePosition);

                        // For some reason, the part.AbsolutePosition.* values do not change if the
                        // linkset is rotated; they always reflect the child prim's world position
                        // as though the linkset is unrotated. This is incompatible behavior with SL's
                        // implementation, so will break scripts imported from there (not to mention it
                        // makes it more difficult to determine a child prim's actual inworld position).
                        if (!part.IsRoot)
                        {
                            LSL_Vector rootPos = new LSL_Vector(m_host.ParentGroup.AbsolutePosition);
                            v = ((v - rootPos) * llGetRootRotation()) + rootPos;
                        }

                        res.Add(v);
                        break;

                    case (int)ScriptBaseClass.PRIM_SIZE:
                        res.Add(new LSL_Vector(part.Scale));
                        break;

                    case (int)ScriptBaseClass.PRIM_ROTATION:
                        res.Add(GetPartRot(part));
                        break;

                    case (int)ScriptBaseClass.PRIM_TYPE:
                        // implementing box
                        PrimitiveBaseShape Shape = part.Shape;
                        int primType = (int)part.GetPrimType();
                        res.Add(new LSL_Integer(primType));
                        double topshearx = (double)(sbyte)Shape.PathShearX / 100.0; // Fix negative values for PathShearX
                        double topsheary = (double)(sbyte)Shape.PathShearY / 100.0; // and PathShearY.
                        switch (primType)
                        {
                            case ScriptBaseClass.PRIM_TYPE_BOX:
                            case ScriptBaseClass.PRIM_TYPE_CYLINDER:
                            case ScriptBaseClass.PRIM_TYPE_PRISM:
                                res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0);    // Isolate hole shape nibble.
                                res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
                                res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
                                res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
                                res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));
                                res.Add(new LSL_Vector(topshearx, topsheary, 0));
                                break;

                            case ScriptBaseClass.PRIM_TYPE_SPHERE:
                                res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0);    // Isolate hole shape nibble.
                                res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));
                                res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));
                                res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));
                                res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));
                                break;

                            case ScriptBaseClass.PRIM_TYPE_SCULPT:
                                res.Add(new LSL_String(Shape.SculptTexture.ToString()));
                                res.Add(new LSL_Integer(Shape.SculptType));
                                break;

                            case ScriptBaseClass.PRIM_TYPE_RING:
                            case ScriptBaseClass.PRIM_TYPE_TUBE:
                            case ScriptBaseClass.PRIM_TYPE_TORUS:
                                // holeshape
                                res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0);    // Isolate hole shape nibble.

                                // cut
                                res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0));

                                // hollow
                                res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0));

                                // twist
                                res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0));

                                // vector holesize
                                res.Add(new LSL_Vector(1 - (Shape.PathScaleX / 100.0 - 1), 1 - (Shape.PathScaleY / 100.0 - 1), 0));

                                // vector topshear
                                res.Add(new LSL_Vector(topshearx, topsheary, 0));

                                // vector profilecut
                                res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0));

                                // vector tapera
                                res.Add(new LSL_Vector(Shape.PathTaperX / 100.0, Shape.PathTaperY / 100.0, 0));

                                // float revolutions
                                res.Add(new LSL_Float(Math.Round(Shape.PathRevolutions * 0.015d, 2, MidpointRounding.AwayFromZero)) + 1.0d);
                                // Slightly inaccurate, because an unsigned byte is being used to represent
                                // the entire range of floating-point values from 1.0 through 4.0 (which is how
                                // SL does it).
                                //
                                // Using these formulas to store and retrieve PathRevolutions, it is not
                                // possible to use all values between 1.00 and 4.00. For instance, you can't
                                // represent 1.10. You can represent 1.09 and 1.11, but not 1.10. So, if you
                                // use llSetPrimitiveParams to set revolutions to 1.10 and then retreive them
                                // with llGetPrimitiveParams, you'll retrieve 1.09. You can also see a similar
                                // behavior in the viewer as you cannot set 1.10. The viewer jumps to 1.11.
                                // In SL, llSetPrimitveParams and llGetPrimitiveParams can set and get a value
                                // such as 1.10. So, SL must store and retreive the actual user input rather
                                // than only storing the encoded value.

                                // float radiusoffset
                                res.Add(new LSL_Float(Shape.PathRadiusOffset / 100.0));

                                // float skew
                                res.Add(new LSL_Float(Shape.PathSkew / 100.0));
                                break;
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXTURE:
                        if (remain < 1)
                            return null;

                        int face = (int)rules.GetLSLIntegerItem(idx++);
                        Primitive.TextureEntry tex = part.Shape.Textures;
                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0 ; face < GetNumberOfSides(part); face++)
                            {
                                Primitive.TextureEntryFace texface = tex.GetFace((uint)face);

                                res.Add(new LSL_String(texface.TextureID.ToString()));
                                res.Add(new LSL_Vector(texface.RepeatU,
                                                       texface.RepeatV,
                                                       0));
                                res.Add(new LSL_Vector(texface.OffsetU,
                                                       texface.OffsetV,
                                                       0));
                                res.Add(new LSL_Float(texface.Rotation));
                            }
                        }
                        else
                        {
                            if (face >= 0 && face < GetNumberOfSides(part))
                            {
                                Primitive.TextureEntryFace texface = tex.GetFace((uint)face);

                                res.Add(new LSL_String(texface.TextureID.ToString()));
                                res.Add(new LSL_Vector(texface.RepeatU,
                                                       texface.RepeatV,
                                                       0));
                                res.Add(new LSL_Vector(texface.OffsetU,
                                                       texface.OffsetV,
                                                       0));
                                res.Add(new LSL_Float(texface.Rotation));
                            }
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_COLOR:
                        if (remain < 1)
                            return null;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        tex = part.Shape.Textures;
                        Color4 texcolor;
                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0 ; face < GetNumberOfSides(part); face++)
                            {
                                texcolor = tex.GetFace((uint)face).RGBA;
                                res.Add(new LSL_Vector(texcolor.R,
                                                       texcolor.G,
                                                       texcolor.B));
                                res.Add(new LSL_Float(texcolor.A));
                            }
                        }
                        else
                        {
                            texcolor = tex.GetFace((uint)face).RGBA;
                            res.Add(new LSL_Vector(texcolor.R,
                                                   texcolor.G,
                                                   texcolor.B));
                            res.Add(new LSL_Float(texcolor.A));
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                        if (remain < 1)
                            return null;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        tex = part.Shape.Textures;
                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0; face < GetNumberOfSides(part); face++)
                            {
                                Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                                // Convert Shininess to PRIM_SHINY_*
                                res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
                                // PRIM_BUMP_*
                                res.Add(new LSL_Integer((int)texface.Bump));
                            }
                        }
                        else
                        {
                            if (face >= 0 && face < GetNumberOfSides(part))
                            {
                                Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                                // Convert Shininess to PRIM_SHINY_*
                                res.Add(new LSL_Integer((uint)texface.Shiny >> 6));
                                // PRIM_BUMP_*
                                res.Add(new LSL_Integer((int)texface.Bump));
                            }
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);

                        tex = part.Shape.Textures;
                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0; face < GetNumberOfSides(part); face++)
                            {
                                Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                                res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
                            }
                        }
                        else
                        {
                            if (face >= 0 && face < GetNumberOfSides(part))
                            {
                                Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                                res.Add(new LSL_Integer(texface.Fullbright ? 1 : 0));
                            }
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_FLEXIBLE:
                        PrimitiveBaseShape shape = part.Shape;

                        if (shape.FlexiEntry)
                            res.Add(new LSL_Integer(1));              // active
                        else
                            res.Add(new LSL_Integer(0));
                        res.Add(new LSL_Integer(shape.FlexiSoftness));// softness
                        res.Add(new LSL_Float(shape.FlexiGravity));   // gravity
                        res.Add(new LSL_Float(shape.FlexiDrag));      // friction
                        res.Add(new LSL_Float(shape.FlexiWind));      // wind
                        res.Add(new LSL_Float(shape.FlexiTension));   // tension
                        res.Add(new LSL_Vector(shape.FlexiForceX,       // force
                                               shape.FlexiForceY,
                                               shape.FlexiForceZ));
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXGEN:
                        if (remain < 1)
                            return null;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        tex = part.Shape.Textures;
                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0; face < GetNumberOfSides(part); face++)
                            {
                                MappingType texgen = tex.GetFace((uint)face).TexMapType;
                                // Convert MappingType to PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR etc.
                                res.Add(new LSL_Integer((uint)texgen >> 1));
                            }
                        }
                        else
                        {
                            if (face >= 0 && face < GetNumberOfSides(part))
                            {
                                MappingType texgen = tex.GetFace((uint)face).TexMapType;
                                res.Add(new LSL_Integer((uint)texgen >> 1));
                            }
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
                        shape = part.Shape;

                        if (shape.LightEntry)
                            res.Add(new LSL_Integer(1));              // active
                        else
                            res.Add(new LSL_Integer(0));
                        res.Add(new LSL_Vector(shape.LightColorR,       // color
                                               shape.LightColorG,
                                               shape.LightColorB));
                        res.Add(new LSL_Float(shape.LightIntensity)); // intensity
                        res.Add(new LSL_Float(shape.LightRadius));    // radius
                        res.Add(new LSL_Float(shape.LightFalloff));   // falloff
                        break;

                    case (int)ScriptBaseClass.PRIM_GLOW:
                        if (remain < 1)
                            return null;

                        face=(int)rules.GetLSLIntegerItem(idx++);

                        tex = part.Shape.Textures;
                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0; face < GetNumberOfSides(part); face++)
                            {
                                Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                                res.Add(new LSL_Float(texface.Glow));
                            }
                        }
                        else
                        {
                            if (face >= 0 && face < GetNumberOfSides(part))
                            {
                                Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
                                res.Add(new LSL_Float(texface.Glow));
                            }
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXT:
                        Color4 textColor = part.GetTextColor();
                        res.Add(new LSL_String(part.Text));
                        res.Add(new LSL_Vector(textColor.R,
                                               textColor.G,
                                               textColor.B));
                        res.Add(new LSL_Float(textColor.A));
                        break;
                    case (int)ScriptBaseClass.PRIM_NAME:
                        res.Add(new LSL_String(part.Name));
                        break;
                    case (int)ScriptBaseClass.PRIM_DESC:
                        res.Add(new LSL_String(part.Description));
                        break;
                    case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
                        res.Add(new LSL_Rotation(part.RotationOffset));
                        break;
                    case (int)ScriptBaseClass.PRIM_POS_LOCAL:
                        res.Add(new LSL_Vector(GetPartLocalPos(part)));
                        break;
                    case (int)ScriptBaseClass.PRIM_SLICE:
                        PrimType prim_type = part.GetPrimType();
                        bool useProfileBeginEnd = (prim_type == PrimType.SPHERE || prim_type == PrimType.TORUS || prim_type == PrimType.TUBE || prim_type == PrimType.RING);
                        res.Add(new LSL_Vector(
                            (useProfileBeginEnd ? part.Shape.ProfileBegin : part.Shape.PathBegin) / 50000.0,
                            1 - (useProfileBeginEnd ? part.Shape.ProfileEnd : part.Shape.PathEnd) / 50000.0,
                            0
                        ));
                        break;
                    case (int)ScriptBaseClass.PRIM_LINK_TARGET:

                        // TODO: Should be issuing a runtime script warning in this case.
                        if (remain < 2)
                            return null;

                        return rules.GetSublist(idx, -1);
                }
            }

            return null;
        }
Example #6
0
 public LSL_List llList2List(LSL_List src, int start, int end)
 {
     m_host.AddScriptLPS(1);
     return src.GetSublist(start, end);
 }
Example #7
0
        protected LSL_List SetAgentParams(ScenePresence sp, LSL_List rules, string originFunc, ref uint rulesParsed)
        {
            int idx = 0;
            int idxStart = 0;

            try
            {
                while (idx < rules.Length)
                {
                    ++rulesParsed;
                    int code = rules.GetLSLIntegerItem(idx++);

                    int remain = rules.Length - idx;
                    idxStart = idx;

                    switch (code)
                    {
                        case ScriptBaseClass.PRIM_POSITION:
                        case ScriptBaseClass.PRIM_POS_LOCAL:
                            if (remain < 1)
                                return new LSL_List();

                            try
                            {
                                sp.OffsetPosition = rules.GetVector3Item(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                if (code == ScriptBaseClass.PRIM_POSITION)
                                {
                                    Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
                                }
                                else
                                {
                                    Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
                                }
                                return new LSL_List();
                            }
                            break;

                        case ScriptBaseClass.PRIM_ROTATION:                       
                            if (remain < 1)
                                return new LSL_List();

                            Quaternion inRot;

                            try
                            {
                                inRot = rules.GetQuaternionItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }

                            SceneObjectPart parentPart = sp.ParentPart;

                            if (parentPart != null)
                                sp.Rotation = m_host.GetWorldRotation() * inRot;

                            break;

                        case ScriptBaseClass.PRIM_ROT_LOCAL:
                            if (remain < 1)
                                return new LSL_List();

                            try
                            {
                                sp.Rotation = rules.GetQuaternionItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }

                            break;

                        case ScriptBaseClass.PRIM_TYPE:
                            Error(originFunc, "PRIM_TYPE disallowed on agent");
                            return new LSL_List();

                        case ScriptBaseClass.PRIM_OMEGA:
                            Error(originFunc, "PRIM_OMEGA disallowed on agent");
                            return new LSL_List();

                        case 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 new LSL_List();

                            return rules.GetSublist(idx, -1);

                        default:
                            Error(originFunc,
                                string.Format("Error running rule #{0} on agent: arg #{1} - disallowed on agent", rulesParsed, idx - idxStart));
                            return new LSL_List();
                    }
                }
            }
            catch (InvalidCastException e)
            {
                Error(
                    originFunc, 
                    string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
            }

            return new LSL_List();
        }
Example #8
0
        /// <summary>
        /// Gets params for a seated avatar in a linkset.
        /// </summary>
        /// <returns></returns>
        /// <param name='sp'></param>
        /// <param name='rules'></param>
        /// <param name='res'></param>
        public LSL_List GetAgentParams(ScenePresence sp, LSL_List rules, ref LSL_List res)
        {
            int idx = 0;
            while (idx < rules.Length)
            {
                int code = (int)rules.GetLSLIntegerItem(idx++);
                int remain = rules.Length-idx;

                switch (code)
                {
                    case (int)ScriptBaseClass.PRIM_MATERIAL:
                        res.Add(new LSL_Integer(ScriptBaseClass.PRIM_MATERIAL_FLESH));
                        break;

                    case (int)ScriptBaseClass.PRIM_PHYSICS:
                        res.Add(ScriptBaseClass.FALSE);
                        break;

                    case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
                        res.Add(ScriptBaseClass.FALSE);
                        break;

                    case (int)ScriptBaseClass.PRIM_PHANTOM:
                        res.Add(ScriptBaseClass.FALSE);
                        break;

                    case (int)ScriptBaseClass.PRIM_POSITION:
                        res.Add(new LSL_Vector(sp.AbsolutePosition));
                        break;

                    case (int)ScriptBaseClass.PRIM_SIZE:
                        res.Add(GetAgentSize(sp));
                        break;

                    case (int)ScriptBaseClass.PRIM_ROTATION:
                        res.Add(sp.GetWorldRotation());
                        break;

                    case (int)ScriptBaseClass.PRIM_TYPE:
                        res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
                        res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
                        res.Add(new LSL_Vector(0, 1, 0));
                        res.Add(new LSL_Float(0));
                        res.Add(new LSL_Vector(0, 0, 0));
                        res.Add(new LSL_Vector(1, 1, 0));
                        res.Add(new LSL_Vector(0, 0, 0));
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXTURE:
                        if (remain < 1)
                            return null;

                        int face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(new LSL_String(""));
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        res.Add(new LSL_Float(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_COLOR:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        res.Add(new LSL_Float(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(ScriptBaseClass.PRIM_SHINY_NONE);
                        res.Add(ScriptBaseClass.PRIM_BUMP_NONE);
                        break;

                    case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(ScriptBaseClass.FALSE);
                        break;

                    case (int)ScriptBaseClass.PRIM_FLEXIBLE:
                        res.Add(ScriptBaseClass.FALSE);
                        res.Add(new LSL_Integer(0));
                        res.Add(new LSL_Float(0));
                        res.Add(new LSL_Float(0));
                        res.Add(new LSL_Float(0));
                        res.Add(new LSL_Float(0));
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXGEN:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(ScriptBaseClass.PRIM_TEXGEN_DEFAULT);
                        break;

                    case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
                        res.Add(ScriptBaseClass.FALSE);
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        break;

                    case (int)ScriptBaseClass.PRIM_GLOW:
                        if (remain < 1)
                            return null;

                        face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face > 21)
                            break;

                        res.Add(new LSL_Float(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXT:
                        res.Add(new LSL_String(""));
                        res.Add(ScriptBaseClass.ZERO_VECTOR);
                        res.Add(new LSL_Float(1));
                        break;

                    case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
                        res.Add(new LSL_Rotation(sp.Rotation));
                        break;

                    case (int)ScriptBaseClass.PRIM_POS_LOCAL:
                        res.Add(new LSL_Vector(sp.OffsetPosition));
                        break;

                    case (int)ScriptBaseClass.PRIM_SLICE:
                        res.Add(new LSL_Vector(0, 1, 0));
                        break;

                    case (int)ScriptBaseClass.PRIM_LINK_TARGET:
                        if(remain < 3)
                            return null;

                        return rules.GetSublist(idx, -1);
                }
            }

            return null;
        }
Example #9
0
        protected void SetEntityParams(List<ISceneEntity> entities, LSL_List rules, string originFunc)
        {
            LSL_List remaining = new LSL_List();
            uint rulesParsed = 0;

            foreach (ISceneEntity entity in entities)
            {
                if (entity is SceneObjectPart)
                    remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
                else
                    remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
            }

            while (remaining.Length > 2)
            {
                int linknumber;
                try
                {
                    linknumber = remaining.GetLSLIntegerItem(0);
                }
                catch(InvalidCastException)
                {
                    Error(originFunc, string.Format("Error running rule #{0} -> PRIM_LINK_TARGET: parameter 2 must be integer", rulesParsed));
                    return;
                }

                rules = remaining.GetSublist(1, -1);
                entities = GetLinkEntities(linknumber);

                foreach (ISceneEntity entity in entities)
                {
                    if (entity is SceneObjectPart)
                        remaining = SetPrimParams((SceneObjectPart)entity, rules, originFunc, ref rulesParsed);
                    else
                        remaining = SetAgentParams((ScenePresence)entity, rules, originFunc, ref rulesParsed);
                }
            }
        }
Example #10
0
        protected LSL_List SetPrimParams(SceneObjectPart part, LSL_List rules, string originFunc, ref uint rulesParsed)
        {
            int idx = 0;
            int idxStart = 0;

            bool positionChanged = false;
            LSL_Vector currentPosition = GetPartLocalPos(part);

            try
            {
                while (idx < rules.Length)
                {
                    ++rulesParsed;
                    int code = rules.GetLSLIntegerItem(idx++);

                    int remain = rules.Length - idx;
                    idxStart = idx;

                    int face;
                    LSL_Vector v;

                    switch (code)
                    {
                        case ScriptBaseClass.PRIM_POSITION:
                        case ScriptBaseClass.PRIM_POS_LOCAL:
                            if (remain < 1)
                                return new LSL_List();

                            try
                            {
                                v = rules.GetVector3Item(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                if(code == ScriptBaseClass.PRIM_POSITION)
                                    Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POSITION: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
                                else
                                    Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POS_LOCAL: arg #{1} - parameter 1 must be vector", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            positionChanged = true;
                            currentPosition = GetSetPosTarget(part, v, currentPosition);

                            break;
                        case ScriptBaseClass.PRIM_SIZE:
                            if (remain < 1)
                                return new LSL_List();

                            v=rules.GetVector3Item(idx++);
                            SetScale(part, v);

                            break;
                        case ScriptBaseClass.PRIM_ROTATION:
                            if (remain < 1)
                                return new LSL_List();
                            LSL_Rotation q;
                            try
                            {
                                q = rules.GetQuaternionItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROTATION: arg #{1} - parameter 1 must be rotation", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            // try to let this work as in SL...
                            if (part.ParentID == 0)
                            {
                                // special case: If we are root, rotate complete SOG to new rotation
                                SetRot(part, q);
                            }
                            else
                            {
                                // we are a child. The rotation values will be set to the one of root modified by rot, as in SL. Don't ask.
                                SceneObjectPart rootPart = part.ParentGroup.RootPart;
                                SetRot(part, rootPart.RotationOffset * (Quaternion)q);
                            }

                            break;

                        case ScriptBaseClass.PRIM_TYPE:
                            if (remain < 3)
                                return new LSL_List();

                            try
                            {
                                code = (int)rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE: arg #{1} - parameter 1 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }

                            remain = rules.Length - idx;
                            float hollow;
                            LSL_Vector twist;
                            LSL_Vector taper_b;
                            LSL_Vector topshear;
                            float revolutions;
                            float radiusoffset;
                            float skew;
                            LSL_Vector holesize;
                            LSL_Vector profilecut;

                            switch (code)
                            {
                                case ScriptBaseClass.PRIM_TYPE_BOX:
                                    if (remain < 6)
                                        return new LSL_List();

                                    try
                                    {
                                        face = (int)rules.GetLSLIntegerItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        v = rules.GetVector3Item(idx++); // cut
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        hollow = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        twist = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 5 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        taper_b = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        topshear = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_BOX: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }

                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
                                        (byte)ProfileShape.Square, (byte)Extrusion.Straight);
                                    break;

                                case ScriptBaseClass.PRIM_TYPE_CYLINDER:
                                    if (remain < 6)
                                        return new LSL_List();

                                    try
                                    {
                                        face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        v = rules.GetVector3Item(idx++); // cut
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        hollow = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        twist = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        taper_b = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        topshear = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_CYLINDER: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
                                        (byte)ProfileShape.Circle, (byte)Extrusion.Straight);
                                    break;

                                case ScriptBaseClass.PRIM_TYPE_PRISM:
                                    if (remain < 6)
                                        return new LSL_List();

                                    try
                                    {
                                        face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        v = rules.GetVector3Item(idx++); //cut
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        hollow = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        twist = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        taper_b = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        topshear = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_PRISM: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b, topshear,
                                        (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Straight);
                                    break;

                                case ScriptBaseClass.PRIM_TYPE_SPHERE:
                                    if (remain < 5)
                                        return new LSL_List();

                                    try
                                    {
                                        face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        v = rules.GetVector3Item(idx++); // cut
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        hollow = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        twist = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        taper_b = rules.GetVector3Item(idx++); // dimple
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SPHERE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, taper_b,
                                        (byte)ProfileShape.HalfCircle, (byte)Extrusion.Curve1);
                                    break;

                                case ScriptBaseClass.PRIM_TYPE_TORUS:
                                    if (remain < 11)
                                        return new LSL_List();

                                    try
                                    {
                                        face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        v = rules.GetVector3Item(idx++); //cut
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        hollow = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        twist = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        holesize = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        topshear = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        profilecut = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        taper_b = rules.GetVector3Item(idx++); // taper_a
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        revolutions = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        radiusoffset = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        skew = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TORUS: arg #{1} - parameter 13 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
                                        revolutions, radiusoffset, skew, (byte)ProfileShape.Circle, (byte)Extrusion.Curve1);
                                    break;

                                case ScriptBaseClass.PRIM_TYPE_TUBE:
                                    if (remain < 11)
                                        return new LSL_List();

                                    try
                                    {
                                        face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        v = rules.GetVector3Item(idx++); //cut
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        hollow = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        twist = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        holesize = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        topshear = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        profilecut = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        taper_b = rules.GetVector3Item(idx++); // taper_a
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        revolutions = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        radiusoffset = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        skew = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_TUBE: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
                                        revolutions, radiusoffset, skew, (byte)ProfileShape.Square, (byte)Extrusion.Curve1);
                                    break;

                                case ScriptBaseClass.PRIM_TYPE_RING:
                                    if (remain < 11)
                                        return new LSL_List();

                                    try
                                    {
                                        face = (int)rules.GetLSLIntegerItem(idx++); // holeshape
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        v = rules.GetVector3Item(idx++); //cut
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        hollow = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        twist = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 6 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        holesize = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 7 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        topshear = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        profilecut = rules.GetVector3Item(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 9 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        taper_b = rules.GetVector3Item(idx++); // taper_a
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 10 must be vector", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        revolutions = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 11 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        radiusoffset = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 12 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    try
                                    {
                                        skew = (float)rules.GetLSLFloatItem(idx++);
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_RING: arg #{1} - parameter 13 must be float", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    SetPrimitiveShapeParams(part, face, v, hollow, twist, holesize, topshear, profilecut, taper_b,
                                        revolutions, radiusoffset, skew, (byte)ProfileShape.EquilateralTriangle, (byte)Extrusion.Curve1);
                                    break;

                                case ScriptBaseClass.PRIM_TYPE_SCULPT:
                                    if (remain < 2)
                                        return new LSL_List();

                                    string map = rules.Data[idx++].ToString();
                                    try
                                    {
                                        face = (int)rules.GetLSLIntegerItem(idx++); // type
                                    }
                                    catch(InvalidCastException)
                                    {
                                        Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TYPE, PRIM_TYPE_SCULPT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
                                        return new LSL_List();
                                    }
                                    SetPrimitiveShapeParams(part, map, face, (byte)Extrusion.Curve1);
                                    break;
                            }

                            break;

                        case ScriptBaseClass.PRIM_TEXTURE:
                            if (remain < 5)
                                return new LSL_List();

                            face=(int)rules.GetLSLIntegerItem(idx++);
                            string tex;
                            LSL_Vector repeats;
                            LSL_Vector offsets;
                            double rotation;

                            tex = rules.Data[idx++].ToString();
                            try
                            {
                                repeats = rules.GetVector3Item(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                offsets = rules.GetVector3Item(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 4 must be vector", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                rotation = (double)rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXTURE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }

                            SetTexture(part, tex, face);
                            ScaleTexture(part, repeats.x, repeats.y, face);
                            OffsetTexture(part, offsets.x, offsets.y, face);
                            RotateTexture(part, rotation, face);

                            break;

                        case ScriptBaseClass.PRIM_COLOR:
                            if (remain < 3)
                                return new LSL_List();

                            LSL_Vector color;
                            double alpha;

                            try
                            {
                                face = (int)rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                color = rules.GetVector3Item(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                alpha = (double)rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_COLOR: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }

                            part.SetFaceColorAlpha(face, color, alpha);

                            break;

                        case ScriptBaseClass.PRIM_FLEXIBLE:
                            if (remain < 7)
                                return new LSL_List();
                            bool flexi;
                            int softness;
                            float gravity;
                            float friction;
                            float wind;
                            float tension;
                            LSL_Vector force;

                            try
                            {
                                flexi = rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                softness = rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                gravity = (float)rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                friction = (float)rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                wind = (float)rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                tension = (float)rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 7 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                force = rules.GetVector3Item(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FLEXIBLE: arg #{1} - parameter 8 must be vector", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }

                            SetFlexi(part, flexi, softness, gravity, friction, wind, tension, force);

                            break;

                        case ScriptBaseClass.PRIM_POINT_LIGHT:
                            if (remain < 5)
                                return new LSL_List();
                            bool light;
                            LSL_Vector lightcolor;
                            float intensity;
                            float radius;
                            float falloff;

                            try
                            {
                                light = rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                lightcolor = rules.GetVector3Item(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                intensity = (float)rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                radius = (float)rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 5 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                falloff = (float)rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_POINT_LIGHT: arg #{1} - parameter 6 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }

                            SetPointLight(part, light, lightcolor, intensity, radius, falloff);

                            break;

                        case ScriptBaseClass.PRIM_GLOW:
                            if (remain < 2)
                                return new LSL_List();

                            float glow;

                            try
                            {
                                face = rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                glow = (float)rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_GLOW: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }

                            SetGlow(part, face, glow);

                            break;

                        case ScriptBaseClass.PRIM_BUMP_SHINY:
                            if (remain < 3)
                                return new LSL_List();

                            int shiny;
                            Bumpiness bump;

                            try
                            {
                                face = (int)rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                shiny = (int)rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                bump = (Bumpiness)(int)rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_BUMP_SHINY: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }

                            SetShiny(part, face, shiny, bump);

                            break;

                        case ScriptBaseClass.PRIM_FULLBRIGHT:
                            if (remain < 2)
                                return new LSL_List();
                            bool st;

                            try
                            {
                                face = rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                               Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
                               return new LSL_List();
                            }
                            try
                            {
                                st = rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_FULLBRIGHT: arg #{1} - parameter 4 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            SetFullBright(part, face , st);
                            break;

                        case ScriptBaseClass.PRIM_MATERIAL:
                            if (remain < 1)
                                return new LSL_List();
                            int mat;

                            try
                            {
                                mat = rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                               Error(originFunc, string.Format("Error running rule #{0} -> PRIM_MATERIAL: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
                               return new LSL_List();
                            }
                            if (mat < 0 || mat > 7)
                                return new LSL_List();

                            part.Material = Convert.ToByte(mat);
                            break;

                        case ScriptBaseClass.PRIM_PHANTOM:
                            if (remain < 1)
                                return new LSL_List();

                            string ph = rules.Data[idx++].ToString();
                            part.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1"));

                            break;

                        case ScriptBaseClass.PRIM_PHYSICS:
                           if (remain < 1)
                                return new LSL_List();
                            string phy = rules.Data[idx++].ToString();
                            part.ScriptSetPhysicsStatus(phy.Equals("1"));
                            break;

                        case ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
                            if (remain < 1)
                                return new LSL_List();

                            int shape_type;

                            try
                            {
                                shape_type = rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_PHYSICS_SHAPE_TYPE: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }

                            ExtraPhysicsData physdata = new ExtraPhysicsData();
                            physdata.Density = part.Density;
                            physdata.Bounce = part.Restitution;
                            physdata.GravitationModifier = part.GravityModifier;
                            physdata.PhysShapeType = (PhysShapeType)shape_type;

                            part.UpdateExtraPhysics(physdata);

                            break;

                        case ScriptBaseClass.PRIM_TEMP_ON_REZ:
                            if (remain < 1)
                                return new LSL_List();
                            string temp = rules.Data[idx++].ToString();

                            part.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1"));

                            break;

                        case ScriptBaseClass.PRIM_TEXGEN:
                            if (remain < 2)
                                return new LSL_List();
                                //face,type
                            int style;

                            try
                            {
                                face = rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                               Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 2 must be integer", rulesParsed, idx - idxStart - 1));
                               return new LSL_List();
                            }
                            try
                            {
                                style = rules.GetLSLIntegerItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                               Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXGEN: arg #{1} - parameter 3 must be integer", rulesParsed, idx - idxStart - 1));
                               return new LSL_List();
                            }
                            SetTexGen(part, face, style);
                            break;
                        case ScriptBaseClass.PRIM_TEXT:
                            if (remain < 3)
                                return new LSL_List();
                            string primText;
                            LSL_Vector primTextColor;
                            LSL_Float primTextAlpha;

                            try
                            {
                                primText = rules.GetLSLStringItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                               Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
                               return new LSL_List();
                            }
                            try
                            {
                                primTextColor = rules.GetVector3Item(idx++);
                            }
                            catch(InvalidCastException)
                            {
                               Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 3 must be vector", rulesParsed, idx - idxStart - 1));
                               return new LSL_List();
                            }
                            try
                            {
                                primTextAlpha = rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                               Error(originFunc, string.Format("Error running rule #{0} -> PRIM_TEXT: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
                               return new LSL_List();
                            }
                            Vector3 av3 = Util.Clip(primTextColor, 0.0f, 1.0f);
                            part.SetText(primText, av3, Util.Clip((float)primTextAlpha, 0.0f, 1.0f));

                            break;

                        case ScriptBaseClass.PRIM_NAME:
                            if (remain < 1)
                                return new LSL_List();
                            try
                            {
                                string primName = rules.GetLSLStringItem(idx++);
                                part.Name = primName;
                            }
                            catch(InvalidCastException)
                            {
                               Error(originFunc, string.Format("Error running rule #{0} -> PRIM_NAME: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
                               return new LSL_List();
                            }
                            break;
                        case ScriptBaseClass.PRIM_DESC:
                            if (remain < 1)
                                return new LSL_List();
                            try
                            {
                                string primDesc = rules.GetLSLStringItem(idx++);
                                part.Description = primDesc;
                            }
                            catch(InvalidCastException)
                            {
                               Error(originFunc, string.Format("Error running rule #{0} -> PRIM_DESC: arg #{1} - parameter 2 must be string", rulesParsed, idx - idxStart - 1));
                               return new LSL_List();
                            }
                            break;
                        case ScriptBaseClass.PRIM_ROT_LOCAL:
                            if (remain < 1)
                                return new LSL_List();
                            LSL_Rotation rot;
                            try
                            {
                                rot = rules.GetQuaternionItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                               Error(originFunc, string.Format("Error running rule #{0} -> PRIM_ROT_LOCAL: arg #{1} - parameter 2 must be rotation", rulesParsed, idx - idxStart - 1));
                               return new LSL_List();
                            }
                            SetRot(part, rot);
                            break;

                        case ScriptBaseClass.PRIM_OMEGA:
                            if (remain < 3)
                                return new LSL_List();
                            LSL_Vector axis;
                            LSL_Float spinrate;
                            LSL_Float gain;

                            try
                            {
                                axis = rules.GetVector3Item(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                spinrate = rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 3 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            try
                            {
                                gain = rules.GetLSLFloatItem(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_OMEGA: arg #{1} - parameter 4 must be float", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            TargetOmega(part, axis, (double)spinrate, (double)gain);
                            break;

                        case ScriptBaseClass.PRIM_SLICE:
                            if (remain < 1)
                                return new LSL_List();
                            LSL_Vector slice;
                            try
                            {
                                slice = rules.GetVector3Item(idx++);
                            }
                            catch(InvalidCastException)
                            {
                                Error(originFunc, string.Format("Error running rule #{0} -> PRIM_SLICE: arg #{1} - parameter 2 must be vector", rulesParsed, idx - idxStart - 1));
                                return new LSL_List();
                            }
                            part.UpdateSlice((float)slice.x, (float)slice.y);
                            break;

                        case 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 new LSL_List();

                            return rules.GetSublist(idx, -1);

                        default:
                            Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - unsupported parameter", rulesParsed, idx - idxStart));
                            return new LSL_List();
                    }
                }
            }
            catch (InvalidCastException e)
            {
                Error(originFunc, string.Format("Error running rule #{0}: arg #{1} - ", rulesParsed, idx - idxStart) + e.Message);
            }
            finally
            {
                if (positionChanged)
                {
                    if (part.ParentGroup.RootPart == part)
                    {
                        SceneObjectGroup parent = part.ParentGroup;
                        parent.UpdateGroupPosition(currentPosition);
                    }
                    else
                    {
                        part.OffsetPosition = currentPosition;
                        SceneObjectGroup parent = part.ParentGroup;
                        parent.HasGroupChanged = true;
                        parent.ScheduleGroupForTerseUpdate();
                    }
                }
            }

            return new LSL_List();
        }
Example #11
0
        private void SetLinkPrimParams(int linknumber, LSL_List rules, string originFunc)
        {
            List<object> parts = new List<object>();
            List<SceneObjectPart> prims = GetLinkParts(linknumber);
            List<ScenePresence> avatars = GetLinkAvatars(linknumber);
            foreach (SceneObjectPart p in prims)
                parts.Add(p);
            foreach (ScenePresence p in avatars)
                parts.Add(p);

            LSL_List remaining = new LSL_List();
            uint rulesParsed = 0;

            if (parts.Count > 0)
            {
                foreach (object part in parts)
                {
                    if (part is SceneObjectPart)
                        remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
                    else
                        remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
                }

                while (remaining.Length > 2)
                {
                    linknumber = remaining.GetLSLIntegerItem(0);
                    rules = remaining.GetSublist(1, -1);
                    parts.Clear();
                    prims = GetLinkParts(linknumber);
                    avatars = GetLinkAvatars(linknumber);
                    foreach (SceneObjectPart p in prims)
                        parts.Add(p);
                    foreach (ScenePresence p in avatars)
                        parts.Add(p);

                    remaining = new LSL_List();
                    foreach (object part in parts)
                    {
                        if (part is SceneObjectPart)
                            remaining = SetPrimParams((SceneObjectPart)part, rules, originFunc, ref rulesParsed);
                        else
                            remaining = SetPrimParams((ScenePresence)part, rules, originFunc, ref rulesParsed);
                    }
                }
            }
        }
Example #12
0
        public LSL_List GetPrimParams(ScenePresence avatar, LSL_List rules, ref LSL_List res)
        {
            // avatars case
            // replies as SL wiki

//            SceneObjectPart sitPart = avatar.ParentPart; // most likelly it will be needed
            SceneObjectPart sitPart = World.GetSceneObjectPart(avatar.ParentID); // maybe better do this expensive search for it in case it's gone??

            int idx = 0;
            while (idx < rules.Length)
            {
                int code = (int)rules.GetLSLIntegerItem(idx++);
                int remain = rules.Length - idx;

                switch (code)
                {
                    case (int)ScriptBaseClass.PRIM_MATERIAL:
                        res.Add(new LSL_Integer((int)SOPMaterialData.SopMaterial.Flesh));
                        break;

                    case (int)ScriptBaseClass.PRIM_PHYSICS:
                            res.Add(new LSL_Integer(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
                            res.Add(new LSL_Integer(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_PHANTOM:
                            res.Add(new LSL_Integer(0));
                        break;

                    case (int)ScriptBaseClass.PRIM_POSITION:
                        Vector3 pos;

                        if (sitPart.ParentGroup.RootPart != null)
                        {
                            pos = avatar.OffsetPosition;

                            if(!avatar.LegacySitOffsets)
                            {
                                Vector3 sitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f *2.0f);
                                pos -= sitOffset;
                            }

                            SceneObjectPart sitroot = sitPart.ParentGroup.RootPart;
                            pos = sitroot.AbsolutePosition + pos * sitroot.GetWorldRotation();
                        }
                        else
                            pos = avatar.AbsolutePosition;     

                        res.Add(new LSL_Vector(pos.X,pos.Y,pos.Z));
                        break;

                    case (int)ScriptBaseClass.PRIM_SIZE:
                        Vector3 s = avatar.Appearance.AvatarSize;
                        res.Add(new LSL_Vector(s.X, s.Y, s.Z));

                        break;

                    case (int)ScriptBaseClass.PRIM_ROTATION:
                        res.Add(new LSL_Rotation(avatar.GetWorldRotation()));
                        break;

                    case (int)ScriptBaseClass.PRIM_TYPE:
                        res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TYPE_BOX));
                        res.Add(new LSL_Integer(ScriptBaseClass.PRIM_HOLE_DEFAULT));
                        res.Add(new LSL_Vector(0f,1.0f,0f));
                        res.Add(new LSL_Float(0.0f));
                        res.Add(new LSL_Vector(0, 0, 0));
                        res.Add(new LSL_Vector(1.0f,1.0f,0f));
                        res.Add(new LSL_Vector(0, 0, 0));
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXTURE:
                        if (remain < 1)
                            return new LSL_List();

                        int face = (int)rules.GetLSLIntegerItem(idx++);
                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0; face < 21; face++)
                            {
                                res.Add(new LSL_String(""));
                                res.Add(new LSL_Vector(0,0,0));
                                res.Add(new LSL_Vector(0,0,0));
                                res.Add(new LSL_Float(0.0));
                            }
                        }
                        else
                        {
                            if (face >= 0 && face < 21)
                            {
                                res.Add(new LSL_String(""));
                                res.Add(new LSL_Vector(0,0,0));
                                res.Add(new LSL_Vector(0,0,0));
                                res.Add(new LSL_Float(0.0));
                            }
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_COLOR:
                        if (remain < 1)
                            return new LSL_List();

                        face = (int)rules.GetLSLIntegerItem(idx++);

                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0; face < 21; face++)
                            {
                                res.Add(new LSL_Vector(0,0,0));
                                res.Add(new LSL_Float(0));
                            }
                        }
                        else
                        {
                                res.Add(new LSL_Vector(0,0,0));
                                res.Add(new LSL_Float(0));
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                        if (remain < 1)
                            return new LSL_List();
                        face = (int)rules.GetLSLIntegerItem(idx++);

                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0; face < 21; face++)
                            {
                                res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
                                res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
                            }
                        }
                        else
                        {
                                res.Add(new LSL_Integer(ScriptBaseClass.PRIM_SHINY_NONE));
                                res.Add(new LSL_Integer(ScriptBaseClass.PRIM_BUMP_NONE));
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
                        if (remain < 1)
                            return new LSL_List();
                        face = (int)rules.GetLSLIntegerItem(idx++);

                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0; face < 21; face++)
                            {
                                res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
                            }
                        }
                        else
                        {
                                res.Add(new LSL_Integer(ScriptBaseClass.FALSE));
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_FLEXIBLE:
                        res.Add(new LSL_Integer(0));
                        res.Add(new LSL_Integer(0));// softness
                        res.Add(new LSL_Float(0.0f));   // gravity
                        res.Add(new LSL_Float(0.0f));      // friction
                        res.Add(new LSL_Float(0.0f));      // wind
                        res.Add(new LSL_Float(0.0f));   // tension
                        res.Add(new LSL_Vector(0f,0f,0f));
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXGEN:
                        // (PRIM_TEXGEN_DEFAULT, PRIM_TEXGEN_PLANAR)
                        if (remain < 1)
                            return new LSL_List();
                        face = (int)rules.GetLSLIntegerItem(idx++);

                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0; face < 21; face++)
                            {
                                    res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
                            }
                        }
                        else
                        {
                                res.Add(new LSL_Integer(ScriptBaseClass.PRIM_TEXGEN_DEFAULT));
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
                        res.Add(new LSL_Integer(0));
                        res.Add(new LSL_Vector(0f,0f,0f));
                        res.Add(new LSL_Float(0f)); // intensity
                        res.Add(new LSL_Float(0f));    // radius
                        res.Add(new LSL_Float(0f));   // falloff
                        break;

                    case (int)ScriptBaseClass.PRIM_GLOW:
                        if (remain < 1)
                            return new LSL_List();
                        face = (int)rules.GetLSLIntegerItem(idx++);

                        if (face == ScriptBaseClass.ALL_SIDES)
                        {
                            for (face = 0; face < 21; face++)
                            {
                                res.Add(new LSL_Float(0f));
                            }
                        }
                        else
                        {
                                res.Add(new LSL_Float(0f));
                        }
                        break;

                    case (int)ScriptBaseClass.PRIM_TEXT:
                        res.Add(new LSL_String(""));
                        res.Add(new LSL_Vector(0f,0f,0f));
                        res.Add(new LSL_Float(1.0f));
                        break;

                    case (int)ScriptBaseClass.PRIM_NAME:
                        res.Add(new LSL_String(avatar.Name));
                        break;

                    case (int)ScriptBaseClass.PRIM_DESC:
                        res.Add(new LSL_String(""));
                        break;

                    case (int)ScriptBaseClass.PRIM_ROT_LOCAL:                      
                        Quaternion lrot = avatar.Rotation;
                        res.Add(new LSL_Rotation(lrot.X, lrot.Y, lrot.Z, lrot.W));
                        break;

                    case (int)ScriptBaseClass.PRIM_POS_LOCAL:
                        Vector3 lpos = avatar.OffsetPosition;

                        if(!avatar.LegacySitOffsets)
                        {
                            Vector3 lsitOffset = (Zrot(avatar.Rotation)) * (avatar.Appearance.AvatarHeight * 0.02638f * 2.0f);
                            lpos -= lsitOffset;
                        }

                        res.Add(new LSL_Vector(lpos.X,lpos.Y,lpos.Z));
                        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 new LSL_List();

                        return rules.GetSublist(idx, -1);
                }
            }

            return new LSL_List();
        }
Example #13
0
        protected LSL_List SetPrimParams(ScenePresence av, LSL_List rules, string originFunc, ref uint rulesParsed)
        {
            //This is a special version of SetPrimParams to deal with avatars which are sitting on the linkset.

            int idx = 0;
            int idxStart = 0;

            bool positionChanged = false;
            try
            {
                while (idx < rules.Length)
                {
                    ++rulesParsed;
                    int code = rules.GetLSLIntegerItem(idx++);

                    int remain = rules.Length - idx;
                    idxStart = idx;

                    switch (code)
                    {
                        case (int)ScriptBaseClass.PRIM_POSITION:
                        case (int)ScriptBaseClass.PRIM_POS_LOCAL:
                            {
                                if (remain < 1)
                                    return new LSL_List();

                                LSL_Vector v;
                                v = rules.GetVector3Item(idx++);

                                if(!av.LegacySitOffsets)
                                {
                                    LSL_Vector sitOffset = (llRot2Up(new LSL_Rotation(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W)) * av.Appearance.AvatarHeight * 0.02638f);

                                    v = v + 2 * sitOffset;
                                }

                                av.OffsetPosition = new Vector3((float)v.x, (float)v.y, (float)v.z);
                                positionChanged = true;
                            }
                            break;

                        case (int)ScriptBaseClass.PRIM_ROTATION:
                            {
                                if (remain < 1)
                                    return new LSL_List();

                                Quaternion r;
                                r = rules.GetQuaternionItem(idx++);

                                av.Rotation = m_host.GetWorldRotation() * r;
                                positionChanged = true;
                            }
                            break;

                        case (int)ScriptBaseClass.PRIM_ROT_LOCAL:
                            {
                                if (remain < 1)
                                    return new LSL_List();

                                LSL_Rotation r;
                                r = rules.GetQuaternionItem(idx++);

                                av.Rotation = r;
                                positionChanged = true;
                            }
                            break;

                        // parse rest doing nothing but number of parameters error check
                        case (int)ScriptBaseClass.PRIM_SIZE:
                        case (int)ScriptBaseClass.PRIM_MATERIAL:
                        case (int)ScriptBaseClass.PRIM_PHANTOM:
                        case (int)ScriptBaseClass.PRIM_PHYSICS:
                        case (int)ScriptBaseClass.PRIM_PHYSICS_SHAPE_TYPE:
                        case (int)ScriptBaseClass.PRIM_TEMP_ON_REZ:
                        case (int)ScriptBaseClass.PRIM_NAME:
                        case (int)ScriptBaseClass.PRIM_DESC:
                            if (remain < 1)
                                return new LSL_List();
                            idx++;
                            break;

                        case (int)ScriptBaseClass.PRIM_GLOW:
                        case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
                        case (int)ScriptBaseClass.PRIM_TEXGEN:
                            if (remain < 2)
                                return new LSL_List();
                            idx += 2;
                            break;

                        case (int)ScriptBaseClass.PRIM_TYPE:
                            if (remain < 3)
                                return new LSL_List();
                            code = (int)rules.GetLSLIntegerItem(idx++);
                            remain = rules.Length - idx;
                            switch (code)
                            {
                                case (int)ScriptBaseClass.PRIM_TYPE_BOX:
                                case (int)ScriptBaseClass.PRIM_TYPE_CYLINDER:
                                case (int)ScriptBaseClass.PRIM_TYPE_PRISM:
                                    if (remain < 6)
                                        return new LSL_List();
                                    idx += 6;
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_SPHERE:
                                    if (remain < 5)
                                        return new LSL_List();
                                    idx += 5;
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_TORUS:
                                case (int)ScriptBaseClass.PRIM_TYPE_TUBE:
                                case (int)ScriptBaseClass.PRIM_TYPE_RING:
                                    if (remain < 11)
                                        return new LSL_List();
                                    idx += 11;
                                    break;

                                case (int)ScriptBaseClass.PRIM_TYPE_SCULPT:
                                    if (remain < 2)
                                        return new LSL_List();
                                    idx += 2;
                                    break;
                            }
                            break;

                        case (int)ScriptBaseClass.PRIM_COLOR:
                        case (int)ScriptBaseClass.PRIM_TEXT:
                        case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
                        case (int)ScriptBaseClass.PRIM_OMEGA:
                            if (remain < 3)
                                return new LSL_List();
                            idx += 3;
                            break;

                        case (int)ScriptBaseClass.PRIM_TEXTURE:
                        case (int)ScriptBaseClass.PRIM_POINT_LIGHT:
                        case (int)ScriptBaseClass.PRIM_PHYSICS_MATERIAL:
                            if (remain < 5)
                                return new LSL_List();
                            idx += 5;
                            break;

                        case (int)ScriptBaseClass.PRIM_FLEXIBLE:
                            if (remain < 7)
                                return new LSL_List();

                            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 new LSL_List();

                            return rules.GetSublist(idx, -1);
                    }
                }
            }
            catch (InvalidCastException e)
            {
                Error(originFunc,string.Format(
                        " error running rule #{1}: arg #{2} ",
                         rulesParsed, idx - idxStart) + e.Message);
            }
            finally
            {
                if (positionChanged)
                    av.SendTerseUpdateToAllClients();
            }
            return new LSL_List();
        }
Example #14
0
        public LSL_List llGetLinkPrimitiveParams(int linknumber, LSL_List rules)
        {
            m_host.AddScriptLPS(1);

            // acording to SL wiki this must indicate a single link number or link_root or link_this.
            // keep other options as before

            List<SceneObjectPart> parts;
            List<ScenePresence> avatars;
            
            LSL_List res = new LSL_List();
            LSL_List remaining = new LSL_List();

            while (rules.Length > 0)
            {
                parts = GetLinkParts(linknumber);
                avatars = GetLinkAvatars(linknumber);

                remaining = new LSL_List();
                foreach (SceneObjectPart part in parts)
                {
                    remaining = GetPrimParams(part, rules, ref res);
                }
                foreach (ScenePresence avatar in avatars)
                {
                    remaining = GetPrimParams(avatar, rules, ref res);
                }

                if (remaining.Length > 0)
                {
                    linknumber = remaining.GetLSLIntegerItem(0);
                    rules = remaining.GetSublist(1, -1);
                }
                else
                    break;
            }

            return res;
        }