homing weapons more or less work now

This commit is contained in:
Chris Forbes
2009-12-06 21:19:02 +13:00
parent 5b970c499b
commit 3d457c397d
15 changed files with 211 additions and 61 deletions

54
OpenRa.Game/Combat.cs Normal file
View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
using OpenRa.Game.Effects;
namespace OpenRa.Game
{
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)
{
var targetTile = ((1f / Game.CellSize) * loc.ToFloat2()).ToInt2();
var isWater = Game.IsWater(targetTile);
var hitWater = Game.IsCellBuildable(targetTile, UnitMovementType.Float);
if (warhead.Explosion != 0)
Game.world.AddFrameEndTask(
w => w.Add(new Explosion(visualLoc, warhead.Explosion, hitWater)));
var impactSound = warhead.ImpactSound;
if (hitWater && warhead.WaterImpactSound != null)
impactSound = warhead.WaterImpactSound;
if (impactSound != null) Sound.Play(impactSound + ".aud");
if (!isWater) Smudge.AddSmudge(targetTile, warhead);
if (warhead.Ore) Ore.Destroy(targetTile.X, targetTile.Y);
var maxSpread = GetMaximumSpread(weapon, warhead);
var hitActors = Game.FindUnitsInCircle(loc, maxSpread);
foreach (var victim in hitActors)
victim.InflictDamage(firedBy, (int)GetDamageToInflict(victim, loc, weapon, warhead));
}
static float GetMaximumSpread(WeaponInfo weapon, WarheadInfo warhead)
{
return (int)(warhead.Spread * Math.Log(weapon.Damage, 2));
}
static float GetDamageToInflict(Actor target, int2 loc, WeaponInfo weapon, WarheadInfo warhead)
{
/* todo: some things can't be damaged AT ALL by certain weapons! */
var distance = (target.CenterLocation - loc).Length;
var rawDamage = weapon.Damage * (float)Math.Exp(-distance / warhead.Spread);
var multiplier = warhead.EffectivenessAgainst(target.Info.Armor);
return rawDamage * multiplier;
}
}
}