remove ref to Game.world in Combat
This commit is contained in:
@@ -47,8 +47,11 @@ namespace OpenRA.Mods.RA
|
|||||||
public List<Weapon> Weapons = new List<Weapon>();
|
public List<Weapon> Weapons = new List<Weapon>();
|
||||||
public List<Turret> Turrets = new List<Turret>();
|
public List<Turret> Turrets = new List<Turret>();
|
||||||
|
|
||||||
|
readonly Actor self;
|
||||||
|
|
||||||
public AttackBase(Actor self)
|
public AttackBase(Actor self)
|
||||||
{
|
{
|
||||||
|
this.self = self;
|
||||||
var info = self.Info.Traits.Get<AttackBaseInfo>();
|
var info = self.Info.Traits.Get<AttackBaseInfo>();
|
||||||
|
|
||||||
Turrets.Add(new Turret(info.PrimaryOffset));
|
Turrets.Add(new Turret(info.PrimaryOffset));
|
||||||
@@ -127,7 +130,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (w.Info.MinRange * w.Info.MinRange * Game.CellSize * Game.CellSize >
|
if (w.Info.MinRange * w.Info.MinRange * Game.CellSize * Game.CellSize >
|
||||||
(target.CenterLocation - self.CenterLocation).LengthSquared) return false;
|
(target.CenterLocation - self.CenterLocation).LengthSquared) return false;
|
||||||
|
|
||||||
if (!w.IsValidAgainst(target)) return false;
|
if (!w.IsValidAgainst(self.World, target)) return false;
|
||||||
|
|
||||||
var barrel = w.Barrels[w.Burst % w.Barrels.Length];
|
var barrel = w.Barrels[w.Burst % w.Barrels.Length];
|
||||||
var destMove = target.IsActor ? target.Actor.TraitOrDefault<IMove>() : null;
|
var destMove = target.IsActor ? target.Actor.TraitOrDefault<IMove>() : null;
|
||||||
@@ -243,10 +246,10 @@ namespace OpenRA.Mods.RA
|
|||||||
Math.Max(0, (int)weapon.Info.Range)));
|
Math.Max(0, (int)weapon.Info.Range)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasAnyValidWeapons(Target t) { return Weapons.Any(w => w.IsValidAgainst(t)); }
|
public bool HasAnyValidWeapons(Target t) { return Weapons.Any(w => w.IsValidAgainst(self.World, t)); }
|
||||||
public float GetMaximumRange() { return Weapons.Max(w => w.Info.Range); }
|
public float GetMaximumRange() { return Weapons.Max(w => w.Info.Range); }
|
||||||
|
|
||||||
public Weapon ChooseWeaponForTarget(Target t) { return Weapons.FirstOrDefault(w => w.IsValidAgainst(t)); }
|
public Weapon ChooseWeaponForTarget(Target t) { return Weapons.FirstOrDefault(w => w.IsValidAgainst(self.World, t)); }
|
||||||
|
|
||||||
class AttackOrderTargeter : IOrderTargeter
|
class AttackOrderTargeter : IOrderTargeter
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ namespace OpenRA.Mods.RA
|
|||||||
static float GetDamageToInflict(Actor target, ProjectileArgs args, WarheadInfo warhead, float modifier)
|
static float GetDamageToInflict(Actor target, ProjectileArgs args, WarheadInfo warhead, float modifier)
|
||||||
{
|
{
|
||||||
// don't hit air units with splash from ground explosions, etc
|
// don't hit air units with splash from ground explosions, etc
|
||||||
if (!WeaponValidForTarget(args.weapon, Target.FromActor(target))) return 0f;
|
if (!WeaponValidForTarget(args.weapon, target)) return 0f;
|
||||||
|
|
||||||
var selectable = target.Info.Traits.GetOrDefault<SelectableInfo>();
|
var selectable = target.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||||
var radius = selectable != null ? selectable.Radius : 0;
|
var radius = selectable != null ? selectable.Radius : 0;
|
||||||
@@ -161,24 +161,25 @@ namespace OpenRA.Mods.RA
|
|||||||
return (float)(rawDamage * multiplier);
|
return (float)(rawDamage * multiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool WeaponValidForTarget(WeaponInfo weapon, Target target)
|
public static bool WeaponValidForTarget(WeaponInfo weapon, Actor target)
|
||||||
{
|
{
|
||||||
// todo: fix this properly.
|
var targetable = target.TraitOrDefault<ITargetable>();
|
||||||
if (!target.IsValid) return false;
|
|
||||||
if (!target.IsActor) return weapon.ValidTargets.Contains("Ground") // hack!
|
|
||||||
|| (weapon.ValidTargets.Contains("Water") &&
|
|
||||||
Game.world.GetTerrainType(Util.CellContaining(target.CenterLocation)) == "Water"); // even bigger hack!
|
|
||||||
|
|
||||||
var targetable = target.Actor.TraitOrDefault<ITargetable>();
|
|
||||||
if (targetable == null || !weapon.ValidTargets.Intersect(targetable.TargetTypes).Any())
|
if (targetable == null || !weapon.ValidTargets.Intersect(targetable.TargetTypes).Any())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (weapon.Warheads.All( w => w.EffectivenessAgainst(target.Actor) <= 0))
|
if (weapon.Warheads.All( w => w.EffectivenessAgainst(target) <= 0))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool WeaponValidForTarget( WeaponInfo weapon, World world, int2 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;
|
||||||
|
}
|
||||||
|
|
||||||
static float2 GetRecoil(Actor self, float recoil)
|
static float2 GetRecoil(Actor self, float recoil)
|
||||||
{
|
{
|
||||||
var abInfo = self.Info.Traits.GetOrDefault<AttackBaseInfo>();
|
var abInfo = self.Info.Traits.GetOrDefault<AttackBaseInfo>();
|
||||||
|
|||||||
@@ -72,9 +72,12 @@ namespace OpenRA.Mods.RA
|
|||||||
Turret.Recoil = Math.Max(0f, Turret.Recoil - .2f);
|
Turret.Recoil = Math.Max(0f, Turret.Recoil - .2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsValidAgainst(Target target)
|
public bool IsValidAgainst(World world, Target target)
|
||||||
{
|
{
|
||||||
return Combat.WeaponValidForTarget(Info, target);
|
if( target.IsActor )
|
||||||
|
return Combat.WeaponValidForTarget( Info, target.Actor );
|
||||||
|
else
|
||||||
|
return Combat.WeaponValidForTarget( Info, world, Util.CellContaining( target.CenterLocation ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FiredShot()
|
public void FiredShot()
|
||||||
|
|||||||
Reference in New Issue
Block a user