示例#1
0
        public static void RadiusDamage(GameBase sourceobject, Point3F position, float radius, float damage, string damageType, float impulse)
        {
            // Use the container system to iterate through all the objects
            // within our explosion radius.  We'll apply damage to all ShapeBase
            // objects.
            Dictionary<uint, float> r = tst.console.initContainerRadiusSearch(position, radius, (uint) SceneObjectTypesAsUint.ShapeBaseObjectType);
            float halfRadius = radius/(float) 2.0;
            foreach (ShapeBase targetObject in r.Keys)
                {
                // Calculate how much exposure the current object has to
                // the explosive force.  The object types listed are objects
                // that will block an explosion.  If the object is totally blocked,
                // then no damage is applied.

                UInt32 mask = (uint) SceneObjectTypesAsUint.TerrainObjectType | (uint) SceneObjectTypesAsUint.StaticShapeObjectType | (uint) SceneObjectTypesAsUint.VehicleObjectType;

                float coverage = tst.Util.calcExplosionCoverage(new Point3F(position), targetObject, mask);
                if (!coverage.AsBool())
                    continue;
                float dist = r[targetObject];
                // Calculate a distance scale for the damage and the impulse.
                // Full damage is applied to anything less than half the radius away,
                // linear scale from there.
                float distScale = (float) ((dist < halfRadius) ? 1.0 : 1 - ((dist - halfRadius)/halfRadius));
                // Apply the damage

                targetObject.damage(sourceobject, position, (((damage)*coverage*distScale)), damageType);

                // Apply the impulse
                if (!impulse.AsBool())
                    continue;
                TransformF impulseVec = new TransformF(targetObject.getWorldBoxCenter()) - new TransformF(position);
                impulseVec = impulseVec.normalizeSafe();
                impulseVec = impulseVec.vectorScale(impulse*distScale);
                targetObject.applyImpulse(new Point3F(position), impulseVec.GetPosition());
                }
        }
        public virtual TransformF PointInSpawnSphere(Player objectToSpawn, SpawnSphere spawnSphere)
        {
            bool spawnLocationFound = false;
            int attemptsToSpawn = 0;

            TransformF spherLocationP3F = new TransformF();

            while (!spawnLocationFound && attemptsToSpawn < 5)
                {
                spherLocationP3F = spawnSphere.getTransform();

                Random r = new Random();

                float angleY = (float) tMath.mDegToRad((r.NextDouble()*100)*tMath.M_2PI_F);
                float angleXZ = (float) tMath.mDegToRad((r.NextDouble()*100)*tMath.M_2PI_F);

                int radius = spawnSphere["radius"].AsInt();
                spherLocationP3F.mPositionX += (float) (Math.Cos(angleY)*Math.Sin(angleXZ)*(r.Next(radius*-1, radius)));
                spherLocationP3F.mPositionY += (float) (Math.Cos(angleXZ)*(r.Next(radius*-1, radius)));
                spawnLocationFound = true;

                // Now have to check that another object doesn't already exist at this spot.
                // Use the bounding box of the object to check if where we are about to spawn in is
                // clear.

                TransformF boundingboxsize = new TransformF(((SimDataBlock) objectToSpawn.getDataBlock())["boundingBox"]);
                float searchRadius = boundingboxsize.mPositionX;
                float boxSizeY = boundingboxsize.mPositionY;
                if (boxSizeY > searchRadius)
                    searchRadius = boxSizeY;
                List<UInt32> objectsfound = console.ContainerRadiusSearch(spherLocationP3F.GetPosition(), searchRadius, (UInt32) SceneObjectTypesAsUint.PlayerObjectType, false);
                if (objectsfound.Count > 0)
                    spawnLocationFound = false;

                attemptsToSpawn++;
                }
            if (!spawnLocationFound)
                {
                spherLocationP3F = spawnSphere.getTransform();
                console.warn("WARNING: Could not spawn player after 5 times");
                }
            return spherLocationP3F;
        }
        public static void serverCmdcarUnmountObj(GameConnection client, Player obj)
        {
            obj.unmount();
            obj.setControlObject(obj);

            TransformF ejectpos = obj.getTransform();
            ejectpos += new TransformF(0, 0, 5);
            obj.setTransform(ejectpos);

            Vehicle mvehicle = obj["mVehicle"];

            Point3F ejectvel = mvehicle.getVelocity();
            ejectvel += new Point3F(0, 0, 10);

            ejectvel = ejectvel.vectorScale(((SimDataBlock) (obj.getDataBlock()))["mass"].AsFloat());

            obj.applyImpulse(ejectpos.GetPosition(), ejectvel);
        }
示例#4
0
        public virtual void throwObject(Item 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 = ((SimDataBlock) getDataBlock())["throwForce"].AsFloat();
            if (throwforce == 0)
                throwforce = 20;

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

            Point3F eye = 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 + getVelocity();

            // Set the object's position and initial velocity

            TransformF pos = new TransformF(Util.getBoxCenter(getWorldBox()));

            obj.setTransform(pos);

            obj.applyImpulse(pos.GetPosition(), vec);

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

            obj.setCollisionTimeout(this);

            //todo Should we add this code in to destroy things after they have been thrown?
            if ((obj.getClassName() != "AITurretShape") && (obj.getClassName() != "ProximityMine"))
                obj.schedule("2000", "delete");
        }
示例#5
0
        public string tossPatch()
        {
            if (!isObject())
                return string.Empty;

            Item item = ItemData.createItem("HealthKitPatch");
            item["istemp"] = true.AsString();

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

            ((SimSet) "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 = 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 + getVelocity();

            TransformF pos = new TransformF(getWorldBox().Get_MinExtents());
            item.setTransform(pos);
            item.applyImpulse(pos.GetPosition(), vec);
            item.setCollisionTimeout(this);

            item.SchedulePop();

            return item;
        }