public void ShapeBaseDamage(coShapeBase shapebase, coShapeBase sourceobject, Point3F position, float damage, string damagetype)
            {
            // All damage applied by one object to another should go through this method.
            // This function is provided to allow objects some chance of overriding or
            // processing damage values and types.  As opposed to having weapons call
            // ShapeBase::applyDamage directly. Damage is redirected to the datablock,
            // this is standard procedure for many built in callbacks.


            if (shapebase.isObject())
                {
                coShapeBaseData datablock = shapebase.getDataBlock();
                datablock.call("damage", shapebase, position.AsString(), sourceobject, damage.AsString(), damagetype);
                }
            }
        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");
            }
        public int ShapeBaseShapeBaseMaxInventory(coShapeBase thisobj, coItemData data)
            {
            if (data.isField("clip"))
                return data["maxInventory"].AsInt();

            return (( coSimDataBlock)thisobj.getDataBlock())["maxInv[" + data.getName() + "]"].AsInt();
            }
        public int ShapeBaseShapeBaseSetInventory(coShapeBase thisobj, coItemData data, int value = 0)
            {
            if (thisobj == "")
                return 0;
            int max = 0;


            max = ShapeBaseShapeBaseMaxInventory(thisobj, data);
            if (value > max)
                value = max;

            int amount = thisobj["inv[" + data.getName() + "]"].AsInt();


            if (amount != value)
                {
                thisobj["inv[" + data.getName() + "]"] = value.AsString();


                if (console.isMethodInNamespace(data, "onInventory"))
                    data.call("onInventory", thisobj, value.AsString());

                //string datablock = console.getDatablock(thisobj).AsString();

                if (console.isObject((( coSimDataBlock)thisobj.getDataBlock())) && console.isMethodInNamespace((( coSimDataBlock)thisobj.getDataBlock()), "onInventory"))
                    (( coSimDataBlock)thisobj.getDataBlock()).call("onInventory", data, value.AsString());
                }
            return value;
            }
Example #5
0
        public void ArmorOnCollision(coPlayerData datablock, coPlayer player, coShapeBase col)
            {
            if (player.getState() == "Dead")
                return;
            // Try and pickup all items
            if (col.getClassName() == "Item")
                {
                player.call("pickup", col);
                return;
                }
            //AI are not allowed to drive they are lousey drivers....
            coGameConnection client = player["client"];

            if (!client.isObject())
                return;
            //Mount Vehicle.
            if ((console.getTypeMask(col) & (UInt32)SceneObjectTypesAsUint.GameBaseObjectType) != (UInt32)SceneObjectTypesAsUint.GameBaseObjectType)
                return;
            coVehicleData db = col.getDataBlock();
            if (((db.getClassName() == "WheeledVehicleData") || player["mountVehicle"].AsBool() || player.getState() == "Move" || col["mountable"].AsBool()))
                return;
            // Only mount drivers for now.
            ((coGameConnection)player["client"]).setFirstPerson(false);
            // For this specific example, only one person can fit
            // into a vehicle
            int mount = col.getMountNodeObject(0);
            if (mount > 0)
                return;
            // For this specific FPS Example, always mount the player to node 0
            col.mountObject(player, 0, new TransformF(true));
            player["mVehicle"] = col;
            }