public string RocketLauncherImageOnAltFire(coItem thisobj, coPlayer obj, string slot) { int currentAmmo = ShapeBaseShapeBaseGetInventory(obj, (thisobj["ammo"])); if (currentAmmo < thisobj["loadCount"].AsInt()) thisobj["loadCount"] = currentAmmo.AsString(); coProjectile projectile = null; for (int shotCount = 0; shotCount < thisobj["loadCount"].AsInt(); shotCount++) { // Decrement inventory ammo. The image's ammo state is updated // automatically by the ammo inventory hooks. ShapeBaseShapeBaseDecInventory(obj, (thisobj["ammo"]), 1); // We fire our weapon using the straight ahead aiming point of the gun // We'll need to "skew" the projectile a little bit. We start by getting // the straight ahead aiming point of the gun Point3F vec = obj.getMuzzleVector(slot.AsInt()); Random r = new Random(); TransformF matrix = new TransformF(); matrix.MPosition.x = (float) ((r.NextDouble() - .5)*2*Math.PI*0.008); matrix.MPosition.y = (float) ((r.NextDouble() - .5)*2*Math.PI*0.008); matrix.MPosition.z = (float) ((r.NextDouble() - .5)*2*Math.PI*0.008); TransformF mat = math.MatrixCreateFromEuler(matrix); // Which we'll use to alter the projectile's initial vector with TransformF muzzleVector = math.MatrixMulVector(mat, vec); // Get the player's velocity, we'll then add it to that of the projectile TransformF objectVelocity = new TransformF(obj.getVelocity()); muzzleVector = muzzleVector.vectorScale(thisobj["projectile.muzzleVelocity"].AsFloat()); objectVelocity = objectVelocity.vectorScale(thisobj["projectile.velInheritFactor"].AsFloat()); TransformF muzzleVelocity = muzzleVector + objectVelocity; Torque_Class_Helper tch = new Torque_Class_Helper(thisobj["projectileType"], ""); tch.Props.Add("dataBlock", thisobj["projectile"]); tch.Props.Add("initialVelocity", '"' + muzzleVelocity.ToString() + '"'); tch.Props.Add("initialPosition", '"' + obj.getMuzzlePoint(slot.AsInt()).AsString() + '"'); tch.Props.Add("sourceObject", obj); tch.Props.Add("sourceSlot", slot); tch.Props.Add("client", obj["client"]); projectile = tch.Create(); ((coSimSet) "MissionCleanup").pushToBack(projectile); } return projectile; }
public string RocketLauncherImageOnAltFire(string thisobj, string obj, string slot) { string currentAmmo = ShapeBaseShapeBaseGetInventory(obj, console.GetVarString(string.Format("{0}.ammo", thisobj))).AsString(); if (currentAmmo.AsInt() < console.GetVarInt(string.Format("{0}.loadCount", thisobj))) console.SetVar(string.Format("{0}.loadCount", thisobj), currentAmmo); string project = ""; for (int shotCount = 0; shotCount < console.GetVarInt(string.Format("{0}.loadCount", thisobj)); shotCount++) { // Decrement inventory ammo. The image's ammo state is updated // automatically by the ammo inventory hooks. ShapeBaseShapeBaseDecInventory(obj, console.GetVarString(string.Format("{0}.ammo", thisobj)), "1"); // We fire our weapon using the straight ahead aiming point of the gun // We'll need to "skew" the projectile a little bit. We start by getting // the straight ahead aiming point of the gun Point3F vec = ShapeBase.getMuzzleVector(obj, slot.AsInt()); Random r = new Random(); TransformF matrix = new TransformF(); matrix.MPosition.x = (float) ((r.NextDouble() - .5)*2*Math.PI*0.008); matrix.MPosition.y = (float) ((r.NextDouble() - .5)*2*Math.PI*0.008); matrix.MPosition.z = (float) ((r.NextDouble() - .5)*2*Math.PI*0.008); TransformF mat = math.MatrixCreateFromEuler(matrix); // Which we'll use to alter the projectile's initial vector with TransformF muzzleVector = math.MatrixMulVector(mat, vec); // Get the player's velocity, we'll then add it to that of the projectile TransformF objectVelocity = new TransformF(ShapeBase.getVelocity(obj)); muzzleVector = muzzleVector.vectorScale(console.GetVarFloat(string.Format("{0}.projectile.muzzleVelocity", thisobj))); objectVelocity = objectVelocity.vectorScale(console.GetVarFloat(string.Format("{0}.projectile.velInheritFactor", thisobj))); TransformF muzzleVelocity = muzzleVector + objectVelocity; Torque_Class_Helper tch = new Torque_Class_Helper(console.GetVarString(string.Format("{0}.projectileType", thisobj)), ""); tch.Props.Add("dataBlock", console.GetVarString(string.Format("{0}.projectile", thisobj))); tch.Props.Add("initialVelocity", '"' + muzzleVelocity.ToString() + '"'); tch.Props.Add("initialPosition", '"' + ShapeBase.getMuzzlePoint(obj, slot.AsInt()).ToString() + '"'); tch.Props.Add("sourceObject", obj); tch.Props.Add("sourceSlot", slot); tch.Props.Add("client", console.GetVarString(string.Format("{0}.client", obj))); project = tch.Create(m_ts).ToString(CultureInfo.InvariantCulture); SimSet.pushToBack("MissionCleanup", project); } return project; }
public void RadiusDamage(string sourceobject, string position, string radius, string damage, string damageType, string simpulse) { float impulse = (simpulse.AsFloat()); // 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.AsFloat(), (uint) SceneObjectTypesAsUint.ShapeBaseObjectType); float halfRadius = radius.AsFloat()/(float) 2.0; foreach (uint 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), (int) 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.AsString(), sourceobject, position, (((damage.AsFloat())*coverage*distScale)).AsString(), damageType); // Apply the impulse if (!impulse.AsBool()) continue; TransformF impulseVec = new TransformF(SceneObject.getWorldBoxCenter(targetObject.AsString())) - new TransformF(position); impulseVec = impulseVec.normalizeSafe(); impulseVec = impulseVec.vectorScale(impulse*distScale); ShapeBase.applyImpulse(targetObject.AsString(), new Point3F(position), impulseVec.MPosition); } }