Centralize weapon validity check into WeaponInfo.
This commit is contained in:
@@ -137,5 +137,37 @@ namespace OpenRA.GameRules
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public bool IsValidAgainst(Actor a)
|
||||
{
|
||||
var targetable = a.TraitOrDefault<ITargetable>();
|
||||
if (targetable == null || !ValidTargets.Intersect(targetable.TargetTypes).Any())
|
||||
return false;
|
||||
|
||||
if (Warheads.All(w => w.EffectivenessAgainst(a) <= 0))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsValidAgainst(Target target, World world)
|
||||
{
|
||||
if (!target.IsValid)
|
||||
return false;
|
||||
|
||||
if (target.IsActor)
|
||||
return IsValidAgainst(target.Actor);
|
||||
else
|
||||
{
|
||||
var cell = target.CenterPosition.ToCPos();
|
||||
if (ValidTargets.Contains("Ground") && world.GetTerrainType(cell) != "Water")
|
||||
return true;
|
||||
|
||||
if (ValidTargets.Contains("Water") && world.GetTerrainType(cell) == "Water")
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace OpenRA.Mods.RA
|
||||
if (target.IsInRange(self.CenterPosition, minRange))
|
||||
return;
|
||||
|
||||
if (!IsValidAgainst(self.World, target))
|
||||
if (!Weapon.IsValidAgainst(target, self.World))
|
||||
return;
|
||||
|
||||
var barrel = Barrels[Burst % Barrels.Length];
|
||||
@@ -172,14 +172,6 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsValidAgainst(World world, Target target)
|
||||
{
|
||||
if (target.IsActor)
|
||||
return Combat.WeaponValidForTarget(Weapon, target.Actor);
|
||||
else
|
||||
return Combat.WeaponValidForTarget(Weapon, world, target.CenterPosition.ToCPos());
|
||||
}
|
||||
|
||||
public bool IsReloading { get { return FireDelay > 0; } }
|
||||
|
||||
public WVec MuzzleOffset(Actor self, Barrel b)
|
||||
|
||||
@@ -139,10 +139,10 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public abstract Activity GetAttackActivity(Actor self, Target newTarget, bool allowMove);
|
||||
|
||||
public bool HasAnyValidWeapons(Target t) { return Armaments.Any(a => a.IsValidAgainst(self.World, t)); }
|
||||
public bool HasAnyValidWeapons(Target t) { return Armaments.Any(a => a.Weapon.IsValidAgainst(t, self.World)); }
|
||||
public WRange GetMaximumRange() { return new WRange((int)(1024*Armaments.Max(a => a.Weapon.Range))); }
|
||||
|
||||
public Armament ChooseArmamentForTarget(Target t) { return Armaments.FirstOrDefault(a => a.IsValidAgainst(self.World, t)); }
|
||||
public Armament ChooseArmamentForTarget(Target t) { return Armaments.FirstOrDefault(a => a.Weapon.IsValidAgainst(t, self.World)); }
|
||||
|
||||
public void AttackTarget(Target target, bool queued, bool allowMove)
|
||||
{
|
||||
|
||||
@@ -178,7 +178,8 @@ namespace OpenRA.Mods.RA
|
||||
static float GetDamageToInflict(Actor target, ProjectileArgs args, WarheadInfo warhead, float modifier)
|
||||
{
|
||||
// don't hit air units with splash from ground explosions, etc
|
||||
if (!WeaponValidForTarget(args.weapon, target)) return 0f;
|
||||
if (!args.weapon.IsValidAgainst(target))
|
||||
return 0f;
|
||||
|
||||
var health = target.Info.Traits.GetOrDefault<HealthInfo>();
|
||||
if( health == null ) return 0f;
|
||||
@@ -190,24 +191,5 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
return (float)(rawDamage * multiplier);
|
||||
}
|
||||
|
||||
public static bool WeaponValidForTarget(WeaponInfo weapon, Actor target)
|
||||
{
|
||||
var targetable = target.TraitOrDefault<ITargetable>();
|
||||
if (targetable == null || !weapon.ValidTargets.Intersect(targetable.TargetTypes).Any())
|
||||
return false;
|
||||
|
||||
if (weapon.Warheads.All( w => w.EffectivenessAgainst(target) <= 0))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool WeaponValidForTarget(WeaponInfo weapon, World world, CPos location)
|
||||
{
|
||||
if (weapon.ValidTargets.Contains("Ground") && world.GetTerrainType(location) != "Water") return true;
|
||||
if (weapon.ValidTargets.Contains("Water") && world.GetTerrainType(location) == "Water") return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user