コード例 #1
0
        public bool TeleporterTriggerVerifyObject(coSimDataBlock thisobj, coShapeBase obj, coSceneObject entrance, coSceneObject exit)
        {
            // Bail out early if we couldn't find an exit for this teleporter.
            if (!exit.isObject())
            {
                console.error(string.Format("Cound not find an exit for {0}", console.GetVarString(entrance + ".name")));
                return(false);
            }


            if (!obj.isMemberOfClass("Player"))
            {
                return(false);
            }

            // If the entrance is once sided, make sure the object
            // approached it from it's front.
            if (entrance["oneSided"].AsBool())
            {
                TransformF forwardvector = new TransformF(entrance.getForwardVector());

                Point3F velocity   = obj.getVelocity();
                float   dotProduct = TransformF.vectorDot(forwardvector, velocity);
                if (dotProduct > 0)
                {
                    return(false);
                }
                // If we are coming directly from another teleporter and it happens
                // to be bidirectional, We need to avoid ending sending objects through
                // an infinite loop.

                if (obj["isTeleporting"].AsBool())
                {
                    return(false);
                }
                // We only want to teleport players
                // So bail out early if we have found any
                // other object.


                if (entrance["timeOfLastTeleport"].AsInt() > 0 && entrance["teleporterCooldown"].AsInt() > 0)
                {
                    int            currentTime    = console.getSimTime();
                    int            timedifference = currentTime - entrance["timeOfLastTeleport"].AsInt();
                    coSimDataBlock db             = console.getDatablock(entrance);
                    if (timedifference <= db["teleporterCooldown"].AsInt())
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #2
0
        public void ShapeBaseShapeBaseThrowObject(coShapeBase thisobj, coItem obj)
        {
            // Throw the given object in the direction the shape is looking.
            // The force value is hardcoded according to the current default
            // object mass and mission gravity (20m/s^2).

            float throwforce = (( coSimDataBlock)thisobj.getDataBlock())["throwForce"].AsFloat();

            if (throwforce == 0)
            {
                throwforce = 20;
            }

            // Start with the shape's eye vector...

            Point3F eye = thisobj.getEyeVector();
            Point3F vec = eye.vectorScale(throwforce);

            // Add a vertical component to give the object a better arc
            double verticalForce = throwforce / 2.0;
            float  dot           = Point3F.vectorDot(new Point3F("0 0 1"), eye);

            if (dot < 0)
            {
                dot = dot * -1;
            }

            vec = vec + Point3F.vectorScale(new Point3F(string.Format("0 0 {0}", verticalForce)), 1 - dot);
            vec = vec + thisobj.getVelocity();

            // Set the object's position and initial velocity
            TransformF pos = new TransformF(Util.getBoxCenter(thisobj.getWorldBox()));

            obj.setTransform(pos);

            obj.applyImpulse(pos.MPosition, vec);

            // Since the object is thrown from the center of the shape,
            // the object needs to avoid colliding with it's thrower.

            obj.setCollisionTimeout(thisobj);


            if ((obj.getClassName() != "AITurretShape") && (obj.getClassName() != "ProximityMine"))
            {
                obj.schedule(ItemPopTime.AsString(), "delete");
            }
        }
コード例 #3
0
        public string ShapeBaseTossPatch(coShapeBase thisobj)
        {
            if (!thisobj.isObject())
            {
                return(string.Empty);
            }

            coItem item = console.Call_Classname("ItemData", "CreateItem", new[] { "HealthKitPatch" });

            item["istemp"] = true.AsString();

            item["sourceObject"] = thisobj;
            item["static"]       = false.AsString();

            (( coSimSet)"MissionCleanup").pushToBack(item);

            Random r = new Random();

            Point3F vec = new Point3F(-1 + (float)r.NextDouble() * 2, -1 * (float)r.NextDouble() * 2, (float)r.NextDouble());

            vec = vec.vecotrScale(10);
            Point3F eye = thisobj.getEyeVector();
            float   dot = new Point3F("0 0 1 ").vectorDot(eye);

            if (dot < 0)
            {
                dot = -dot;
            }

            vec = vec + new Point3F("0 0 8").vecotrScale(1 - dot);
            vec = vec + thisobj.getVelocity();

            TransformF pos = new TransformF(thisobj.getWorldBox().minExtents);

            item.setTransform(pos);
            item.applyImpulse(pos.MPosition, vec);
            item.setCollisionTimeout(thisobj);

            item.call("schedulePop");

            return(item);
        }