guts of Combat is on the new model
This commit is contained in:
@@ -29,56 +29,44 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
static class Combat /* some utility bits that are shared between various things */
|
static class Combat /* some utility bits that are shared between various things */
|
||||||
{
|
{
|
||||||
public static void DoImpact(int2 loc, int2 visualLoc,
|
static string GetImpactSound(WarheadInfo warhead, bool isWater)
|
||||||
WeaponInfo weapon, ProjectileInfo projectile, WarheadInfo warhead, Actor firedBy)
|
|
||||||
{
|
{
|
||||||
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,
|
public static void DoImpact(WarheadInfo warhead, ProjectileArgs args, int2 visualLocation)
|
||||||
WeaponInfo weapon, ProjectileInfo projectile, WarheadInfo warhead, Actor firedBy, bool nukeDamage)
|
|
||||||
{
|
{
|
||||||
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)
|
if (warhead.Explosion != 0)
|
||||||
world.AddFrameEndTask(
|
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;
|
Sound.Play(GetImpactSound(warhead, isWater));
|
||||||
if (isWater && warhead.WaterImpactSound != null)
|
|
||||||
impactSound = warhead.WaterImpactSound;
|
|
||||||
if (impactSound != null) Sound.Play(impactSound + ".aud");
|
|
||||||
|
|
||||||
if (!isWater) world.Map.AddSmudge(targetTile, warhead);
|
if (!isWater) world.Map.AddSmudge(targetTile, warhead);
|
||||||
if (warhead.Ore)
|
if (warhead.Ore)
|
||||||
world.WorldActor.traits.Get<ResourceLayer>().Destroy(targetTile);
|
world.WorldActor.traits.Get<ResourceLayer>().Destroy(targetTile);
|
||||||
|
|
||||||
var firepowerModifier = firedBy.traits
|
var firepowerModifier = args.firedBy.traits
|
||||||
.WithInterface<IFirepowerModifier>()
|
.WithInterface<IFirepowerModifier>()
|
||||||
.Select(a => a.GetFirepowerModifier())
|
.Select(a => a.GetFirepowerModifier())
|
||||||
.Product();
|
.Product();
|
||||||
|
|
||||||
var maxSpread = GetMaximumSpread(weapon, warhead, firepowerModifier);
|
var maxSpread = warhead.Spread * (float)Math.Log(Math.Abs(warhead.Damage), 2);
|
||||||
var hitActors = world.FindUnitsInCircle(loc, maxSpread);
|
var hitActors = world.FindUnitsInCircle(args.dest, maxSpread);
|
||||||
|
|
||||||
foreach (var victim in hitActors)
|
|
||||||
victim.InflictDamage(firedBy,
|
|
||||||
(int)GetDamageToInflict(victim, loc, weapon, warhead, firepowerModifier), warhead);
|
|
||||||
|
|
||||||
if (!nukeDamage) return;
|
foreach (var victim in hitActors)
|
||||||
foreach (var t in world.FindTilesInCircle(targetTile, warhead.SmudgeSize[0]))
|
victim.InflictDamage(args.firedBy,
|
||||||
{
|
(int)GetDamageToInflict(victim, args, warhead, firepowerModifier), warhead);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static float GetMaximumSpread(WeaponInfo weapon, WarheadInfo warhead, float modifier)
|
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));
|
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))
|
var distance = (target.CenterLocation - args.dest).Length;
|
||||||
return 0f;
|
var rawDamage = warhead.Damage * modifier * (float)Math.Exp(-distance / warhead.Spread);
|
||||||
|
|
||||||
var distance = (target.CenterLocation - loc).Length;
|
|
||||||
var rawDamage = weapon.Damage * modifier * (float)Math.Exp(-distance / warhead.Spread);
|
|
||||||
var multiplier = warhead.EffectivenessAgainst(target.Info.Traits.Get<OwnedActorInfo>().Armor);
|
var multiplier = warhead.EffectivenessAgainst(target.Info.Traits.Get<OwnedActorInfo>().Armor);
|
||||||
return rawDamage * multiplier;
|
return rawDamage * multiplier;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,8 +81,7 @@ namespace OpenRA.Effects
|
|||||||
if (t > TotalTime()) /* remove finished bullets */
|
if (t > TotalTime()) /* remove finished bullets */
|
||||||
{
|
{
|
||||||
world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
//Combat.DoImpact(Args.dest, VisualDest - new int2( 0, Args.destAltitude ),
|
Combat.DoImpact(Args.weapon.Warheads[0], Args, VisualDest - new int2(0, Args.destAltitude));
|
||||||
// Weapon, Projectile, Warhead, FiredBy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Info.Trail != null)
|
if (Info.Trail != null)
|
||||||
|
|||||||
@@ -117,8 +117,8 @@ namespace OpenRA.Effects
|
|||||||
{
|
{
|
||||||
world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
|
|
||||||
if (t > Projectile.Arm * 40) /* don't blow up in our launcher's face! */
|
// if (t > Projectile.Arm * 40) /* don't blow up in our launcher's face! */
|
||||||
Combat.DoImpact(Pos.ToInt2(), Pos.ToInt2(), Weapon, Projectile, Warhead, FiredBy);
|
// Combat.DoImpact(Pos.ToInt2(), Pos.ToInt2(), Weapon, Projectile, Warhead, FiredBy);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ namespace OpenRA.Effects
|
|||||||
{
|
{
|
||||||
world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
var warhead = Rules.WarheadInfo[weapon.Warhead];
|
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);
|
world.WorldActor.traits.Get<ScreenShaker>().AddEffect(20, pos, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user