Combat.DoExplosion now takes a Target
(needs more refactoring)
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.GameRules
|
||||
{
|
||||
@@ -55,7 +56,7 @@ namespace OpenRA.GameRules
|
||||
public int2 src;
|
||||
public int srcAltitude;
|
||||
public int facing;
|
||||
public Actor target;
|
||||
public Target target;
|
||||
public int2 dest;
|
||||
public int destAltitude;
|
||||
}
|
||||
|
||||
@@ -36,11 +36,10 @@ namespace OpenRA.Mods.Aftermath
|
||||
var unit = self.traits.GetOrDefault<Unit>();
|
||||
var info = self.Info.Traits.Get<AttackBaseInfo>();
|
||||
var altitude = unit != null ? unit.Altitude : 0;
|
||||
int2 detonateLocation = self.CenterLocation.ToInt2();
|
||||
|
||||
self.World.AddFrameEndTask( w =>
|
||||
{
|
||||
Combat.DoExplosion(self, info.PrimaryWeapon, detonateLocation, altitude);
|
||||
Combat.DoExplosion(self, info.PrimaryWeapon, Target.FromActor(self), altitude);
|
||||
var report = self.GetPrimaryWeapon().Report;
|
||||
if (report != null)
|
||||
Sound.Play(report + ".aud", self.CenterLocation);
|
||||
|
||||
@@ -18,14 +18,14 @@ namespace OpenRA.Mods.Cnc.Effects
|
||||
{
|
||||
class IonCannon : IEffect
|
||||
{
|
||||
int2 Target;
|
||||
Target target;
|
||||
Animation anim;
|
||||
Actor firedBy;
|
||||
|
||||
public IonCannon(Actor firedBy, World world, int2 location)
|
||||
{
|
||||
this.firedBy = firedBy;
|
||||
Target = location;
|
||||
target = Target.FromPos(OpenRA.Traits.Util.CenterOfCell(location));
|
||||
anim = new Animation("ionsfx");
|
||||
anim.PlayThen("idle", () => Finish(world));
|
||||
}
|
||||
@@ -35,14 +35,14 @@ namespace OpenRA.Mods.Cnc.Effects
|
||||
public IEnumerable<Renderable> Render()
|
||||
{
|
||||
yield return new Renderable(anim.Image,
|
||||
Traits.Util.CenterOfCell(Target) - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize),
|
||||
target.CenterLocation - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize),
|
||||
"effect");
|
||||
}
|
||||
|
||||
void Finish( World world )
|
||||
{
|
||||
world.AddFrameEndTask(w => w.Remove(this));
|
||||
Combat.DoExplosion(firedBy, "IonCannon", Target, 0);
|
||||
Combat.DoExplosion(firedBy, "IonCannon", target, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Cnc
|
||||
destAltitude = 0,
|
||||
facing = 0,
|
||||
firedBy = self,
|
||||
target = self,
|
||||
target = Target.FromActor(self),
|
||||
weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()]
|
||||
});
|
||||
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace OpenRA.Mods.RA
|
||||
if (self.GetCurrentActivity() is Leap) return;
|
||||
|
||||
var weapon = self.GetPrimaryWeapon();
|
||||
if (weapon.Range * weapon.Range < (target.CenterLocation - self.Location).LengthSquared) return;
|
||||
if (weapon.Range * Game.CellSize * weapon.Range * Game.CellSize
|
||||
< (target.CenterLocation - self.CenterLocation).LengthSquared) return;
|
||||
|
||||
self.CancelActivity();
|
||||
self.QueueActivity(new Leap(self, target));
|
||||
|
||||
@@ -113,16 +113,16 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoExplosion(Actor attacker, string weapontype, int2 location, int altitude)
|
||||
public static void DoExplosion(Actor attacker, string weapontype, Target _target, int altitude)
|
||||
{
|
||||
var args = new ProjectileArgs
|
||||
{
|
||||
src = location,
|
||||
dest = location,
|
||||
src = Util.CellContaining(_target.CenterLocation),
|
||||
dest = Util.CellContaining(_target.CenterLocation),
|
||||
srcAltitude = altitude,
|
||||
destAltitude = altitude,
|
||||
firedBy = attacker,
|
||||
target = null,
|
||||
target = _target,
|
||||
weapon = Rules.Weapons[ weapontype.ToLowerInvariant() ],
|
||||
facing = 0
|
||||
};
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public override void Activate(Actor collector)
|
||||
{
|
||||
Combat.DoExplosion(self, (info as ExplodeCrateActionInfo).Weapon, collector.CenterLocation.ToInt2(), 0);
|
||||
Combat.DoExplosion(self, (info as ExplodeCrateActionInfo).Weapon, Target.FromActor(collector), 0);
|
||||
base.Activate(collector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,8 +75,9 @@ namespace OpenRA.Mods.RA.Effects
|
||||
|
||||
var targetPosition = Args.target.CenterLocation + offset;
|
||||
|
||||
var targetUnit = Args.target.traits.GetOrDefault<Unit>();
|
||||
var targetAltitude = targetUnit != null ? targetUnit.Altitude : 0;
|
||||
var targetAltitude = 0;
|
||||
if (Args.target.IsActor && Args.target.Actor.traits.GetOrDefault<Unit>() != null)
|
||||
targetAltitude = Args.target.Actor.traits.GetOrDefault<Unit>().Altitude;
|
||||
Altitude += Math.Sign(targetAltitude - Altitude);
|
||||
|
||||
Traits.Util.TickFacing(ref Facing,
|
||||
@@ -86,7 +87,7 @@ namespace OpenRA.Mods.RA.Effects
|
||||
anim.Tick();
|
||||
|
||||
var dist = targetPosition - Pos;
|
||||
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Args.target.IsDead)
|
||||
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || !Args.target.IsValid )
|
||||
Explode(world);
|
||||
|
||||
var speed = Scale * Info.Speed * ((targetAltitude > 0 && Info.TurboBoost) ? 1.5f : 1f);
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.Effects
|
||||
void Explode(World world)
|
||||
{
|
||||
world.AddFrameEndTask(w => w.Remove(this));
|
||||
Combat.DoExplosion(silo.Owner.PlayerActor, weapon, pos.ToInt2(), 0);
|
||||
Combat.DoExplosion(silo.Owner.PlayerActor, weapon, Target.FromPos(pos), 0);
|
||||
world.WorldActor.traits.Get<ScreenShaker>().AddEffect(20, pos, 5);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
var unit = self.traits.GetOrDefault<Unit>();
|
||||
var altitude = unit != null ? unit.Altitude : 0;
|
||||
Combat.DoExplosion(e.Attacker, weapon,
|
||||
self.CenterLocation.ToInt2(), altitude);
|
||||
Combat.DoExplosion(e.Attacker, weapon, Target.FromActor(self), altitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA
|
||||
return;
|
||||
|
||||
var info = self.Info.Traits.Get<MineInfo>();
|
||||
Combat.DoExplosion(self, info.Weapon, crusher.CenterLocation.ToInt2(), 0);
|
||||
Combat.DoExplosion(self, info.Weapon, Target.FromActor(crusher), 0);
|
||||
self.QueueActivity(new RemoveSelf());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user