Change WeaponInfo.EffectivenessAgainst to take ActorInfo.

This commit is contained in:
Paul Chote
2013-08-08 19:57:21 +12:00
parent ff98fb0cdf
commit fa517b8787
2 changed files with 11 additions and 8 deletions

View File

@@ -48,12 +48,15 @@ namespace OpenRA.GameRules
[Desc("Whether we should prevent prone response for infantry.")] [Desc("Whether we should prevent prone response for infantry.")]
public readonly bool PreventProne = false; public readonly bool PreventProne = false;
public float EffectivenessAgainst(Actor self) public float EffectivenessAgainst(ActorInfo ai)
{ {
var health = self.Info.Traits.GetOrDefault<HealthInfo>(); var health = ai.Traits.GetOrDefault<HealthInfo>();
if (health == null) return 0f; if (health == null)
var armor = self.Info.Traits.GetOrDefault<ArmorInfo>(); return 0f;
if (armor == null || armor.Type == null) return 1;
var armor = ai.Traits.GetOrDefault<ArmorInfo>();
if (armor == null || armor.Type == null)
return 1;
float versus; float versus;
return Versus.TryGetValue(armor.Type, out versus) ? versus : 1; return Versus.TryGetValue(armor.Type, out versus) ? versus : 1;
@@ -140,7 +143,7 @@ namespace OpenRA.GameRules
if (targetable == null || !ValidTargets.Intersect(targetable.TargetTypes).Any()) if (targetable == null || !ValidTargets.Intersect(targetable.TargetTypes).Any())
return false; return false;
if (Warheads.All(w => w.EffectivenessAgainst(a) <= 0)) if (Warheads.All(w => w.EffectivenessAgainst(a.Info) <= 0))
return false; return false;
return true; return true;

View File

@@ -118,7 +118,7 @@ namespace OpenRA.Mods.RA
foreach (var t in world.FindTilesInCircle(targetTile, warhead.Size[0])) foreach (var t in world.FindTilesInCircle(targetTile, warhead.Size[0]))
foreach (var unit in world.FindActorsInBox(t, t)) foreach (var unit in world.FindActorsInBox(t, t))
unit.InflictDamage(firedBy, unit.InflictDamage(firedBy,
(int)(warhead.Damage * warhead.EffectivenessAgainst(unit)), warhead); (int)(warhead.Damage * warhead.EffectivenessAgainst(unit.Info)), warhead);
} break; } break;
} }
} }
@@ -173,7 +173,7 @@ namespace OpenRA.Mods.RA
var distance = (int)Math.Max(0, (target.CenterPosition - pos).Length * Game.CellSize / 1024 - health.Radius); var distance = (int)Math.Max(0, (target.CenterPosition - pos).Length * Game.CellSize / 1024 - health.Radius);
var falloff = (float)GetDamageFalloff(distance / warhead.Spread); var falloff = (float)GetDamageFalloff(distance / warhead.Spread);
var rawDamage = (float)(warhead.Damage * modifier * falloff); var rawDamage = (float)(warhead.Damage * modifier * falloff);
var multiplier = (float)warhead.EffectivenessAgainst(target); var multiplier = (float)warhead.EffectivenessAgainst(target.Info);
return (float)(rawDamage * multiplier); return (float)(rawDamage * multiplier);
} }