guts of Combat is on the new model

This commit is contained in:
Chris Forbes
2010-04-01 18:24:42 +13:00
parent 11121baf23
commit cefee4b1d2
4 changed files with 27 additions and 43 deletions

View File

@@ -29,56 +29,44 @@ namespace OpenRA
{
static class Combat /* some utility bits that are shared between various things */
{
public static void DoImpact(int2 loc, int2 visualLoc,
WeaponInfo weapon, ProjectileInfo projectile, WarheadInfo warhead, Actor firedBy)
static string GetImpactSound(WarheadInfo warhead, bool isWater)
{
DoImpact(loc, visualLoc, weapon, projectile, warhead, firedBy, false);
if (isWater && warhead.WaterImpactSound != null)
return warhead.WaterImpactSound + ".aud";
if (warhead.ImpactSound != null)
return warhead.ImpactSound + ".aud";
return null;
}
public static void DoImpact(int2 loc, int2 visualLoc,
WeaponInfo weapon, ProjectileInfo projectile, WarheadInfo warhead, Actor firedBy, bool nukeDamage)
public static void DoImpact(WarheadInfo warhead, ProjectileArgs args, int2 visualLocation)
{
var world = firedBy.World;
var world = args.firedBy.World;
var targetTile = ((1f / Game.CellSize) * args.dest.ToFloat2()).ToInt2();
var isWater = world.GetTerrainType(targetTile) == TerrainType.Water;
var targetTile = ((1f / Game.CellSize) * loc.ToFloat2()).ToInt2();
var isWater = (Game.world.GetTerrainType(targetTile) == TerrainType.Water);
if (warhead.Explosion != 0)
world.AddFrameEndTask(
w => w.Add(new Explosion(w, visualLoc, warhead.Explosion, isWater)));
w => w.Add(new Explosion(w, visualLocation, warhead.Explosion, isWater)));
var impactSound = warhead.ImpactSound;
if (isWater && warhead.WaterImpactSound != null)
impactSound = warhead.WaterImpactSound;
if (impactSound != null) Sound.Play(impactSound + ".aud");
Sound.Play(GetImpactSound(warhead, isWater));
if (!isWater) world.Map.AddSmudge(targetTile, warhead);
if (warhead.Ore)
world.WorldActor.traits.Get<ResourceLayer>().Destroy(targetTile);
var firepowerModifier = firedBy.traits
var firepowerModifier = args.firedBy.traits
.WithInterface<IFirepowerModifier>()
.Select(a => a.GetFirepowerModifier())
.Product();
var maxSpread = GetMaximumSpread(weapon, warhead, firepowerModifier);
var hitActors = world.FindUnitsInCircle(loc, maxSpread);
foreach (var victim in hitActors)
victim.InflictDamage(firedBy,
(int)GetDamageToInflict(victim, loc, weapon, warhead, firepowerModifier), warhead);
var maxSpread = warhead.Spread * (float)Math.Log(Math.Abs(warhead.Damage), 2);
var hitActors = world.FindUnitsInCircle(args.dest, maxSpread);
if (!nukeDamage) return;
foreach (var t in world.FindTilesInCircle(targetTile, warhead.SmudgeSize[0]))
{
var x = Util.CenterOfCell(t);
foreach (var unit in world.FindUnits(x, x))
{
unit.InflictDamage(firedBy,
(int)(weapon.Damage * warhead.EffectivenessAgainst(unit.Info.Traits.Get<OwnedActorInfo>().Armor)) / 4, warhead);
}
}
foreach (var victim in hitActors)
victim.InflictDamage(args.firedBy,
(int)GetDamageToInflict(victim, args, warhead, firepowerModifier), warhead);
}
static float GetMaximumSpread(WeaponInfo weapon, WarheadInfo warhead, float modifier)
@@ -86,13 +74,10 @@ namespace OpenRA
return (int)(warhead.Spread * Math.Log(Math.Abs(weapon.Damage * modifier), 2));
}
static float GetDamageToInflict(Actor target, int2 loc, WeaponInfo weapon, WarheadInfo warhead, float modifier)
static float GetDamageToInflict(Actor target, ProjectileArgs args, WarheadInfo warhead, float modifier)
{
if (!WeaponValidForTarget(weapon, target))
return 0f;
var distance = (target.CenterLocation - loc).Length;
var rawDamage = weapon.Damage * modifier * (float)Math.Exp(-distance / warhead.Spread);
var distance = (target.CenterLocation - args.dest).Length;
var rawDamage = warhead.Damage * modifier * (float)Math.Exp(-distance / warhead.Spread);
var multiplier = warhead.EffectivenessAgainst(target.Info.Traits.Get<OwnedActorInfo>().Armor);
return rawDamage * multiplier;
}

View File

@@ -81,8 +81,7 @@ namespace OpenRA.Effects
if (t > TotalTime()) /* remove finished bullets */
{
world.AddFrameEndTask(w => w.Remove(this));
//Combat.DoImpact(Args.dest, VisualDest - new int2( 0, Args.destAltitude ),
// Weapon, Projectile, Warhead, FiredBy);
Combat.DoImpact(Args.weapon.Warheads[0], Args, VisualDest - new int2(0, Args.destAltitude));
}
if (Info.Trail != null)

View File

@@ -117,8 +117,8 @@ namespace OpenRA.Effects
{
world.AddFrameEndTask(w => w.Remove(this));
if (t > Projectile.Arm * 40) /* don't blow up in our launcher's face! */
Combat.DoImpact(Pos.ToInt2(), Pos.ToInt2(), Weapon, Projectile, Warhead, FiredBy);
// if (t > Projectile.Arm * 40) /* don't blow up in our launcher's face! */
// Combat.DoImpact(Pos.ToInt2(), Pos.ToInt2(), Weapon, Projectile, Warhead, FiredBy);
return;
}

View File

@@ -83,7 +83,7 @@ namespace OpenRA.Effects
{
world.AddFrameEndTask(w => w.Remove(this));
var warhead = Rules.WarheadInfo[weapon.Warhead];
Combat.DoImpact(pos.ToInt2(), pos.ToInt2(), weapon, Rules.ProjectileInfo[weapon.Projectile], warhead, silo, true);
//Combat.DoImpact(pos.ToInt2(), pos.ToInt2(), weapon, Rules.ProjectileInfo[weapon.Projectile], warhead, silo, true);
world.WorldActor.traits.Get<ScreenShaker>().AddEffect(20, pos, 5);
}