public void TeleporterTriggerOnAdd(coSimDataBlock thisobj, coShapeBase teleporter)
            {
            if (teleporter["exit"] == "")
                teleporter["exit"] = "NameOfTeleporterExit";

            if (teleporter["teleporterCooldown"] == "")
                teleporter["teleporterCooldown"] = thisobj["teleporterCooldown"];

            if (teleporter["exitVelocityScale"] == "")
                teleporter["exitVelocityScale"] = thisobj["exitVelocityScale"];

            if (teleporter["reorientPlayer"] == "")
                teleporter["reorientPlayer"] = thisobj["reorientPlayer"];

            if (teleporter["oneSided"] == "")
                teleporter["oneSided"] = thisobj["oneSided"];

            if (teleporter["entranceEffect"] == "")
                teleporter["entranceEffect"] = thisobj["entranceEffect"];

            if (teleporter["exitEffect"] == "")
                teleporter["exitEffect"] = thisobj["exitEffect"];
            // We do not want to save this variable between levels, 
            // clear it out every time the teleporter is added 
            // to the scene.

            teleporter["timeOfLastTeleport"] = "";
            }
        public void ShapeBaseDoRayCast(coShapeBase shapebase, float range, uint mask)
            {
            throw new Exception("Not Implemented.");

            //I didn't implement this because rarely would you call it from the script, and it would be
            //better implemented only in csharp.
            }
 public void ProjectileDataOnCollision(coProjectileData datablock, coProjectile projectile, coShapeBase shapebase, string fad, Point3F pos, string normal)
     {
     // Apply damage to the object all shape base objects
     if (datablock["directDamage"].AsFloat() > 0)
         if ((console.getTypeMask(shapebase) & (uint) SceneObjectTypesAsUint.ShapeBaseObjectType) == (uint) SceneObjectTypesAsUint.ShapeBaseObjectType)
             ShapeBaseDamage(shapebase,projectile.ID, pos, datablock["directDamage"].AsFloat(), datablock["damageType"]);
     }
        public void DefaultTriggerOnTickTrigger(coSimDataBlock thisobj, coShapeBase trigger)
            {
            // This method is called every tickPerioMS, as long as any
            // objects intersect the trigger.

            // You can iterate through the objects in the list by using these
            // methods:
            //    %trigger.getNumObjects();
            //    %trigger.getObject(n);
            }
        public bool ShapeBaseShapeBaseUse(coShapeBase thisobj, coItemData data)
            {

            coGameConnection client = thisobj.getControllingClient();
            if (client.isObject())
                {
                double defaultfov = client.getControlCameraDefaultFov();
                double fov = client.getControlCameraFov();
                if (defaultfov != fov)
                    return false;
                }



            if (ShapeBaseShapeBaseGetInventory(thisobj, data) > 0)
                return data.call("onUse", thisobj).AsBool();

            return false;
            }
Beispiel #6
0
        public void TurretShapeData_OnAdd(coTurretShapeData thisobj, coShapeBase obj)
            {
            obj.setRechargeRate(thisobj["rechargeRate"].AsFloat());
            obj.setEnergyLevel(thisobj["MaxEnergy"].AsFloat());
            obj.setRepairRate(0);


            if (obj["mountable"] == "1" || obj["mountable"] == "")
                thisobj.call("isMountable", obj, true.AsString());
            else
                thisobj.call("isMountable", obj, false.AsString());

            if (thisobj["nameTag"] != "")
                obj.setShapeName(thisobj["nameTag"]);
            for (int i = 0; i < thisobj["numWeaponMountPoints"].AsInt(); i++)
                {
                ShapeBaseShapeBaseIncInventory(obj, thisobj["weapon[" + i + "]"], 1);

                coItemData weaponAmmo = thisobj["weaponAmmo[" + i + "]"];


                string weaponAmmoAmount = thisobj["weaponAmmoAmount[" + i + "]"];
                ShapeBaseShapeBaseIncInventory(obj, weaponAmmo, weaponAmmoAmount.AsInt());


                bool startLoaded = thisobj["startLoaded"].AsBool();

                obj.mountImage(thisobj["weapon[" + i + "].Image"], i, startLoaded, "");
                obj.setImageGenericTrigger(i, 0, false);
                }
            if (thisobj["enterSequence"] != "")
                {
                obj["entranceThread"] = "0";
                int et = obj["entranceThread"].AsInt();
                string es = thisobj["enterSequence"];
                obj.playThread(et, es);
                obj.pauseThread(et);
                }
            else
                {
                obj["entranceThread"] = "-1";
                }
            }
        public void RadiusDamage(coShapeBase 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 = console.initContainerRadiusSearch(new Point3F(position), radius, (uint) SceneObjectTypesAsUint.ShapeBaseObjectType);
            float halfRadius = radius/(float) 2.0;
            foreach (coPlayer 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.InteriorObjectType | (uint) SceneObjectTypesAsUint.TerrainObjectType | (uint) SceneObjectTypesAsUint.StaticShapeObjectType | (uint) SceneObjectTypesAsUint.VehicleObjectType;

                float coverage = 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
                ShapeBaseDamage(targetObject, 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.MPosition);
                }
            }
 public void ShapeBaseDataDamage(coShapeBaseData thisobj, coShapeBase obj, string position,  coShapeBase source, float amount, string damageType)
     {
     // Ignore damage by default. This empty method is here to
     // avoid console warnings.
     }
 public bool ShapeBaseShapeBaseHasAmmo(coShapeBase thisob, coItem weapon)
     {
     coItemData weaponimageammo = weapon["image.ammo"];
     if (weaponimageammo == "")
         return true;
     return ShapeBaseShapeBaseGetInventory(thisob, weaponimageammo) > 0;
     }
        public void ShapeBaseSetDamageDT(coShapeBase shapebase, float damageAmount, string damageType)
            {
            // This function is used to apply damage over time.  The damage is applied
            // at a fixed rate (50 ms).  Damage could be applied over time using the
            // built in ShapBase C++ repair functions (using a neg. repair), but this
            // has the advantage of going through the normal script channels.

            if (shapebase.getDamageState() != "Dead")
                {
                ShapeBaseDamage(shapebase, 0, new Point3F("0 0 0"), damageAmount, damageType);
                shapebase["damageSchedule"] = shapebase.schedule("50", "setDamageDt", damageAmount.AsString(), damageType).AsString();
                }
            else
                {
                shapebase["damageSchedule"] = "";
                }
            }
        public void ShapeBaseClearDamageDt(coShapeBase shapebase)
            {
            //I could think of soo much better ways of doing this... even if my grammar blows.

            if (shapebase["damageSchedule"] == "")
                return;

            Util._cancel(shapebase["damageSchedule"]);
            shapebase["damageSchedule"] = "";
            }
        public void WeaponOnPickup(coScriptObject thisobj, string obj, coShapeBase shape, int amount, int nameSpaceDepth)
            {
            int nsd = (nameSpaceDepth + 1);
            if (!console.ParentExecute(thisobj, "onPickup", nsd, new string[] { thisobj, obj, shape, amount.AsString() }).AsBool())
                return;


            AudioServerPlay3D("WeaponPickupSound", shape.getTransform());

            if (shape.getClassName() == "Player" && shape.getMountedImage(WeaponSlot) == 0)
                shape.call("use", thisobj);
            }
 public string ShapeBaseShapeBaseOnInventory(coShapeBase thisobj, coItem data, string value)
     {
     // Invoked on ShapeBase objects whenever their inventory changes
     // for the given datablock.
     return "0";
     }
        public void WeaponImageReloadAmmoClip(coItemData thisobj, coShapeBase obj, int slot)
            {
            string ammoname = ((coItemData)thisobj["ammo"]).getName();

            if (thisobj != obj.getMountedImage(slot))
                return;

            if (!thisobj.isField("clip"))
                return;
            if (ShapeBaseShapeBaseGetInventory(obj, thisobj["clip"]) > 0)
                {
                ShapeBaseShapeBaseDecInventory(obj, thisobj["clip"], 1);

                ShapeBaseShapeBaseSetInventory(obj, thisobj["ammo"], thisobj["ammo.maxInventory"].AsInt());

                obj.setImageAmmo(slot, true);
                }
            else
                {
                int amountInPocket = obj["remaining" + ((coItem)thisobj["ammo"]).getName()].AsInt();
                if (amountInPocket > 0)
                    {
                    obj["remaining" + ((coItem)thisobj["ammo"]).getName()] = "0";

                    ShapeBaseShapeBaseSetInventory(obj, thisobj["ammo"], amountInPocket);
                    obj.setImageAmmo(slot, true);
                    }
                }
            }
 public void ProximityMineDataDamage(coProximityMineData datablock, coProximityMine shapebase, TransformF position, coShapeBase source, string amount, string damageType)
     {
     // Explode if any damage is applied to the mine
     int r = 50 + (new Random().Next(0, 50));
     shapebase.schedule(r.AsString(), "explode");
     }
        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;
            }
 public bool ShapeBaseShapeBaseThrow(coShapeBase thisobj, coItemData data, int amount = 1)
     {
     bool functionresult = false;
     if (ShapeBaseShapeBaseGetInventory(thisobj, data) > 0)
         {
         coSimObject objectid = data.call("onThrow", thisobj, amount.AsString());
             {
             if (objectid != 0)
                 {
                 thisobj.call("throwObject", objectid);
                 AudioServerPlay3D("ThrowSnd", thisobj.getTransform());
                 functionresult = true;
                 }
             }
         }
     return functionresult;
     }
 public int ShapeBaseShapeBaseGetInventory(coShapeBase thisobj, coItemData data)
     {
     return thisobj.isObject() ? thisobj["inv[" + data.getName() + "]"].AsInt() : 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");
            }
 public void ShapeBaseShapeBaseClearInventory(coShapeBase thisobj)
     {
     }
        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 int ShapeBaseShapeBaseIncInventory(coShapeBase player, coItemData datablock, int amount)
            {
            int maxamount = ShapeBaseShapeBaseMaxInventory(player, datablock);

            int total = player["inv[" + datablock.getName() + "]"].AsInt();

            if (total < maxamount)
                {
                if (total + amount > maxamount)
                    {
                    amount = (maxamount - total);
                    }
                ShapeBaseShapeBaseSetInventory(player, datablock, (total + amount));
                return amount;
                }
            return 0;
            }
 public void SendMsgClientKilledMineDamage(string msgType, coGameConnection client, coShapeBase sourceClient, string damLoc)
     {
     // Customized kill message for deaths caused by proximity mines
     if (sourceClient == 0)
         MessageAll(msgType, "%1 was blown up!", client["playerName"]);
     else if (sourceClient == client)
         MessageAll(msgType, "%1 stepped on his own mine!", client["playerName"]);
     else
         MessageAll(msgType, "%1 was blown up by %2!", client["playerName"], sourceClient["playerName"]);
     }
        public int ShapeBaseShapeBaseMaxInventory(coShapeBase thisobj, coItemData data)
            {
            if (data.isField("clip"))
                return data["maxInventory"].AsInt();

            return (( coSimDataBlock)thisobj.getDataBlock())["maxInv[" + data.getName() + "]"].AsInt();
            }
 public bool ShapeBaseShapeBaseHasInventory(coShapeBase thisobj, coItemData data)
     {
     int amount = thisobj["inv[" + data.getName() + "]"].AsInt();
     return amount > 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;
            }
 public void WeaponOnInventory(coScriptObject thisobj, coShapeBase obj, int amount)
     {
     if (amount != 0 || !obj.isMethod("getMountSlot"))
         return;
     int slot = obj.getMountSlot(thisobj["image"]);
     obj.unmountImage(slot);
     }
        public int ShapeBaseShapeBaseDecInventory(coShapeBase shapebase, coItemData data, int amount = 0)
            {
            int total = shapebase["inv[" + data.getName() + "]"].AsInt();


            if (total > 0)
                {
                if (total < amount)
                    amount = total;

                ShapeBaseShapeBaseSetInventory(shapebase, data, (total - amount));
                return amount;
                }
            return 0;
            }
        public void ShapeBaseCycleWeapon(coShapeBase thisobj, string direction)
            {
            //I sure seem to retrieve "thisobj.totalCycledWeapons" alot,
            //So to save so work, I'm just gonna grab it here.
            int totalCycledWeapons = thisobj["totalCycledWeapons"].AsInt();


            // Can't cycle what we don't have
            if (totalCycledWeapons == 0)
                return;
            // Find out the index of the current weapon, if any (not all
            // available weapons may be part of the cycle)
            int currentIndex = -1;


            coItemData mountedimage = thisobj.getMountedImage(WeaponSlot);

            if (mountedimage.isObject())
                {
                string curWeapon = mountedimage["item"];
                for (int i = 0; i < totalCycledWeapons; i++)
                    {
                    if (thisobj["cycleWeapon[" + i + "]"] != curWeapon)
                        continue;
                    currentIndex = i;
                    break;
                    }
                }



            int nextIndex = 0;
            int dir = 1;
            if (currentIndex != -1)
                {
                if (direction == "prev")
                    {
                    dir = -1;
                    nextIndex = currentIndex - 1;
                    if (nextIndex < 0)
                        {
                        nextIndex = totalCycledWeapons - 1;
                        }
                    }
                else
                    {
                    nextIndex = currentIndex + 1;
                    if (nextIndex >= totalCycledWeapons)
                        {
                        nextIndex = 0;
                        }
                    }
                }
            bool found = false;
            coItemData weapon = null;
            for (int i = 0; i < totalCycledWeapons; i++)
                {
                weapon = thisobj["cycleWeapon[" + i + "]"];
                if ((weapon != 0) && (ShapeBaseShapeBaseHasInventory(thisobj, weapon)))
                    {
                    found = true;
                    break;
                    }
                nextIndex = nextIndex + dir;
                if (nextIndex < 0)
                    nextIndex = totalCycledWeapons - 1;
                else if (nextIndex >= totalCycledWeapons)
                    nextIndex = 0;
                }
            if (!found)
                return;
            weapon = thisobj["cycleWeapon[" + nextIndex + "]"];
            ShapeBaseShapeBaseUse(thisobj, weapon);
            }
 public void DefaultTriggerOnLeaveTrigger(coSimDataBlock thisobj, coShapeBase trigger, coShapeBase obj)
     {
     // This method is called whenever an object leaves the %trigger
     // area, the object is passed as %obj.
     }