Convert ProjectileArgs to world coords.
This commit is contained in:
@@ -74,8 +74,6 @@ namespace OpenRA.GameRules
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public enum DamageModel
|
public enum DamageModel
|
||||||
{
|
{
|
||||||
Normal, // classic RA damage model: point actors, distance-based falloff
|
Normal, // classic RA damage model: point actors, distance-based falloff
|
||||||
@@ -85,14 +83,12 @@ namespace OpenRA.GameRules
|
|||||||
public class ProjectileArgs
|
public class ProjectileArgs
|
||||||
{
|
{
|
||||||
public WeaponInfo weapon;
|
public WeaponInfo weapon;
|
||||||
public Actor firedBy;
|
|
||||||
public PPos src;
|
|
||||||
public int srcAltitude;
|
|
||||||
public int facing;
|
|
||||||
public Target target;
|
|
||||||
public PPos dest;
|
|
||||||
public int destAltitude;
|
|
||||||
public float firepowerModifier = 1.0f;
|
public float firepowerModifier = 1.0f;
|
||||||
|
public int facing;
|
||||||
|
public WPos source;
|
||||||
|
public Actor sourceActor;
|
||||||
|
public WPos passiveTarget;
|
||||||
|
public Target guidedTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IProjectileInfo { IEffect Create(ProjectileArgs args); }
|
public interface IProjectileInfo { IEffect Create(ProjectileArgs args); }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
@@ -121,26 +121,20 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
var barrel = Barrels[Burst % Barrels.Length];
|
var barrel = Barrels[Burst % Barrels.Length];
|
||||||
var muzzlePosition = self.CenterPosition + MuzzleOffset(self, barrel);
|
var muzzlePosition = self.CenterPosition + MuzzleOffset(self, barrel);
|
||||||
var legacyMuzzlePosition = PPos.FromWPos(muzzlePosition);
|
|
||||||
var legacyMuzzleAltitude = Game.CellSize*muzzlePosition.Z/1024;
|
|
||||||
var legacyFacing = MuzzleOrientation(self, barrel).Yaw.Angle / 4;
|
var legacyFacing = MuzzleOrientation(self, barrel).Yaw.Angle / 4;
|
||||||
|
|
||||||
var args = new ProjectileArgs
|
var args = new ProjectileArgs
|
||||||
{
|
{
|
||||||
weapon = Weapon,
|
weapon = Weapon,
|
||||||
firedBy = self,
|
|
||||||
target = target,
|
|
||||||
src = legacyMuzzlePosition,
|
|
||||||
srcAltitude = legacyMuzzleAltitude,
|
|
||||||
|
|
||||||
dest = PPos.FromWPos(target.CenterPosition),
|
|
||||||
destAltitude = target.CenterPosition.Z * Game.CellSize / 1024,
|
|
||||||
|
|
||||||
facing = legacyFacing,
|
facing = legacyFacing,
|
||||||
|
|
||||||
firepowerModifier = self.TraitsImplementing<IFirepowerModifier>()
|
firepowerModifier = self.TraitsImplementing<IFirepowerModifier>()
|
||||||
.Select(a => a.GetFirepowerModifier())
|
.Select(a => a.GetFirepowerModifier())
|
||||||
.Product()
|
.Product(),
|
||||||
|
|
||||||
|
source = muzzlePosition,
|
||||||
|
sourceActor = self,
|
||||||
|
passiveTarget = target.CenterPosition,
|
||||||
|
guidedTarget = target
|
||||||
};
|
};
|
||||||
|
|
||||||
attack.ScheduleDelayedAction(Info.FireDelay, () =>
|
attack.ScheduleDelayedAction(Info.FireDelay, () =>
|
||||||
|
|||||||
@@ -56,17 +56,15 @@ namespace OpenRA.Mods.RA
|
|||||||
var weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
|
var weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
|
||||||
dropDelay = weapon.ROF;
|
dropDelay = weapon.ROF;
|
||||||
|
|
||||||
var centerLocation = PPos.FromWPos(self.CenterPosition);
|
var pos = self.CenterPosition;
|
||||||
var altitude = self.CenterPosition.Z * Game.CellSize / 1024;
|
|
||||||
var args = new ProjectileArgs
|
var args = new ProjectileArgs
|
||||||
{
|
{
|
||||||
srcAltitude = altitude,
|
weapon = weapon,
|
||||||
destAltitude = 0,
|
|
||||||
src = centerLocation,
|
|
||||||
dest = centerLocation,
|
|
||||||
facing = self.Trait<IFacing>().Facing,
|
facing = self.Trait<IFacing>().Facing,
|
||||||
firedBy = self,
|
|
||||||
weapon = weapon
|
source = pos,
|
||||||
|
sourceActor = self,
|
||||||
|
passiveTarget = pos - new WVec(0, 0, pos.Z)
|
||||||
};
|
};
|
||||||
|
|
||||||
self.World.Add(args.weapon.Projectile.Create(args));
|
self.World.Add(args.weapon.Projectile.Create(args));
|
||||||
|
|||||||
@@ -32,23 +32,21 @@ namespace OpenRA.Mods.RA
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DoImpact(WarheadInfo warhead, ProjectileArgs args)
|
public static void DoImpact(WPos pos, WarheadInfo warhead, WeaponInfo weapon, Actor firedBy, float firepowerModifier)
|
||||||
{
|
{
|
||||||
var world = args.firedBy.World;
|
var world = firedBy.World;
|
||||||
var targetTile = args.dest.ToCPos();
|
var targetTile = pos.ToCPos();
|
||||||
|
|
||||||
if (!world.Map.IsInMap(targetTile))
|
if (!world.Map.IsInMap(targetTile))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var isWater = args.destAltitude == 0 && world.GetTerrainInfo(targetTile).IsWater;
|
var isWater = pos.Z == 0 && world.GetTerrainInfo(targetTile).IsWater;
|
||||||
var explosionType = isWater ? warhead.WaterExplosion : warhead.Explosion;
|
var explosionType = isWater ? warhead.WaterExplosion : warhead.Explosion;
|
||||||
|
|
||||||
var dest = args.dest.ToWPos(args.destAltitude);
|
|
||||||
if (explosionType != null)
|
if (explosionType != null)
|
||||||
world.AddFrameEndTask(
|
world.AddFrameEndTask(w => w.Add(new Explosion(w, pos, explosionType)));
|
||||||
w => w.Add(new Explosion(w, dest, explosionType)));
|
|
||||||
|
|
||||||
Sound.Play(GetImpactSound(warhead, isWater), dest);
|
Sound.Play(GetImpactSound(warhead, isWater), pos);
|
||||||
|
|
||||||
var smudgeLayers = world.WorldActor.TraitsImplementing<SmudgeLayer>().ToDictionary(x => x.Info.Type);
|
var smudgeLayers = world.WorldActor.TraitsImplementing<SmudgeLayer>().ToDictionary(x => x.Info.Type);
|
||||||
|
|
||||||
@@ -106,12 +104,12 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
var maxSpread = warhead.Spread * (float)Math.Log(Math.Abs(warhead.Damage), 2);
|
var maxSpread = warhead.Spread * (float)Math.Log(Math.Abs(warhead.Damage), 2);
|
||||||
var range = new WRange((int)maxSpread * 1024 / Game.CellSize);
|
var range = new WRange((int)maxSpread * 1024 / Game.CellSize);
|
||||||
var hitActors = world.FindActorsInCircle(args.dest.ToWPos(0), range);
|
var hitActors = world.FindActorsInCircle(pos, range);
|
||||||
|
|
||||||
foreach (var victim in hitActors)
|
foreach (var victim in hitActors)
|
||||||
{
|
{
|
||||||
var damage = (int)GetDamageToInflict(victim, args, warhead, args.firepowerModifier);
|
var damage = (int)GetDamageToInflict(pos, victim, warhead, weapon, firepowerModifier);
|
||||||
victim.InflictDamage(args.firedBy, damage, warhead);
|
victim.InflictDamage(firedBy, damage, warhead);
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
@@ -119,23 +117,22 @@ 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(args.firedBy,
|
unit.InflictDamage(firedBy,
|
||||||
(int)(warhead.Damage * warhead.EffectivenessAgainst(unit)), warhead);
|
(int)(warhead.Damage * warhead.EffectivenessAgainst(unit)), warhead);
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DoImpacts(ProjectileArgs args)
|
public static void DoImpacts(WPos pos, Actor firedBy, WeaponInfo weapon, float damageModifier)
|
||||||
{
|
{
|
||||||
foreach (var warhead in args.weapon.Warheads)
|
foreach (var wh in weapon.Warheads)
|
||||||
{
|
{
|
||||||
// NOTE(jsd): Fixed access to modified closure bug!
|
var warhead = wh;
|
||||||
var warheadClosed = warhead;
|
Action a = () => DoImpact(pos, warhead, weapon, firedBy, damageModifier);
|
||||||
|
|
||||||
Action a = () => DoImpact(warheadClosed, args);
|
|
||||||
if (warhead.Delay > 0)
|
if (warhead.Delay > 0)
|
||||||
args.firedBy.World.AddFrameEndTask(
|
firedBy.World.AddFrameEndTask(
|
||||||
w => w.Add(new DelayedAction(warheadClosed.Delay, a)));
|
w => w.Add(new DelayedAction(warhead.Delay, a)));
|
||||||
else
|
else
|
||||||
a();
|
a();
|
||||||
}
|
}
|
||||||
@@ -143,24 +140,11 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public static void DoExplosion(Actor attacker, string weapontype, WPos pos)
|
public static void DoExplosion(Actor attacker, string weapontype, WPos pos)
|
||||||
{
|
{
|
||||||
var pxPos = PPos.FromWPos(pos);
|
var weapon = Rules.Weapons[weapontype.ToLowerInvariant()];
|
||||||
var altitude = pos.Z * Game.CellSize / 1024;
|
if (weapon.Report != null && weapon.Report.Any())
|
||||||
var args = new ProjectileArgs
|
Sound.Play(weapon.Report.Random(attacker.World.SharedRandom), pos);
|
||||||
{
|
|
||||||
src = pxPos,
|
|
||||||
dest = pxPos,
|
|
||||||
srcAltitude = altitude,
|
|
||||||
destAltitude = altitude,
|
|
||||||
firedBy = attacker,
|
|
||||||
target = Target.FromPos(pos),
|
|
||||||
weapon = Rules.Weapons[weapontype.ToLowerInvariant()],
|
|
||||||
facing = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
if (args.weapon.Report != null && args.weapon.Report.Any())
|
DoImpacts(pos, attacker, weapon, 1f);
|
||||||
Sound.Play(args.weapon.Report.Random(attacker.World.SharedRandom), pos);
|
|
||||||
|
|
||||||
DoImpacts(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static readonly float[] falloff =
|
static readonly float[] falloff =
|
||||||
@@ -177,16 +161,16 @@ namespace OpenRA.Mods.RA
|
|||||||
return (falloff[u] * (1 - t)) + (falloff[u + 1] * t);
|
return (falloff[u] * (1 - t)) + (falloff[u + 1] * t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float GetDamageToInflict(Actor target, ProjectileArgs args, WarheadInfo warhead, float modifier)
|
static float GetDamageToInflict(WPos pos, Actor target, WarheadInfo warhead, WeaponInfo weapon, 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 (!args.weapon.IsValidAgainst(target))
|
if (!weapon.IsValidAgainst(target))
|
||||||
return 0f;
|
return 0f;
|
||||||
|
|
||||||
var health = target.Info.Traits.GetOrDefault<HealthInfo>();
|
var health = target.Info.Traits.GetOrDefault<HealthInfo>();
|
||||||
if( health == null ) return 0f;
|
if( health == null ) return 0f;
|
||||||
|
|
||||||
var distance = (int)Math.Max(0, (target.CenterLocation - args.dest).Length - 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);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
@@ -46,6 +46,8 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
{
|
{
|
||||||
readonly BulletInfo Info;
|
readonly BulletInfo Info;
|
||||||
readonly ProjectileArgs Args;
|
readonly ProjectileArgs Args;
|
||||||
|
PPos src, dest;
|
||||||
|
int srcAltitude, destAltitude;
|
||||||
|
|
||||||
int t = 0;
|
int t = 0;
|
||||||
Animation anim;
|
Animation anim;
|
||||||
@@ -58,11 +60,17 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
Info = info;
|
Info = info;
|
||||||
Args = args;
|
Args = args;
|
||||||
|
|
||||||
|
src = PPos.FromWPos(args.source);
|
||||||
|
srcAltitude = args.source.Z * Game.CellSize / 1024;
|
||||||
|
|
||||||
|
dest = PPos.FromWPos(args.passiveTarget);
|
||||||
|
destAltitude = args.passiveTarget.Z * Game.CellSize / 1024;
|
||||||
|
|
||||||
if (info.Inaccuracy > 0)
|
if (info.Inaccuracy > 0)
|
||||||
{
|
{
|
||||||
var factor = ((Args.dest - Args.src).ToCVec().Length) / args.weapon.Range;
|
var factor = ((dest - src).ToCVec().Length) / args.weapon.Range;
|
||||||
Args.dest += (PVecInt) (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
|
dest += (PVecInt) (info.Inaccuracy * factor * args.sourceActor.World.SharedRandom.Gauss2D(2)).ToInt2();
|
||||||
Log.Write("debug", "Bullet with Inaccuracy; factor: #{0}; Projectile dest: {1}", factor, Args.dest);
|
Log.Write("debug", "Bullet with Inaccuracy; factor: #{0}; Projectile dest: {1}", factor, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Info.Image != null)
|
if (Info.Image != null)
|
||||||
@@ -73,17 +81,17 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
|
|
||||||
if (Info.ContrailLength > 0)
|
if (Info.ContrailLength > 0)
|
||||||
{
|
{
|
||||||
var color = Info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.firedBy) : Info.ContrailColor;
|
var color = Info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.sourceActor) : Info.ContrailColor;
|
||||||
Trail = new ContrailRenderable(args.firedBy.World, color, Info.ContrailLength, Info.ContrailDelay, 0);
|
Trail = new ContrailRenderable(args.sourceActor.World, color, Info.ContrailLength, Info.ContrailDelay, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int TotalTime() { return (Args.dest - Args.src).Length * BaseBulletSpeed / Info.Speed; }
|
int TotalTime() { return (dest - src).Length * BaseBulletSpeed / Info.Speed; }
|
||||||
|
|
||||||
float GetAltitude()
|
float GetAltitude()
|
||||||
{
|
{
|
||||||
var at = (float)t / TotalTime();
|
var at = (float)t / TotalTime();
|
||||||
return (Args.dest - Args.src).Length * Info.Angle * 4 * at * (1 - at);
|
return (dest - src).Length * Info.Angle * 4 * at * (1 - at);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetEffectiveFacing()
|
int GetEffectiveFacing()
|
||||||
@@ -91,7 +99,7 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
var at = (float)t / TotalTime();
|
var at = (float)t / TotalTime();
|
||||||
var attitude = Info.Angle * (1 - 2 * at);
|
var attitude = Info.Angle * (1 - 2 * at);
|
||||||
|
|
||||||
var rawFacing = Traits.Util.GetFacing(Args.dest - Args.src, 0);
|
var rawFacing = Traits.Util.GetFacing(dest - src, 0);
|
||||||
var u = (rawFacing % 128) / 128f;
|
var u = (rawFacing % 128) / 128f;
|
||||||
var scale = 512 * u * (1 - u);
|
var scale = 512 * u * (1 - u);
|
||||||
|
|
||||||
@@ -112,8 +120,8 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
|
|
||||||
{
|
{
|
||||||
var at = (float)t / TotalTime();
|
var at = (float)t / TotalTime();
|
||||||
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
|
var altitude = float2.Lerp(srcAltitude, destAltitude, at);
|
||||||
var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at) - new float2(0, altitude);
|
var pos = float2.Lerp(src.ToFloat2(), dest.ToFloat2(), at) - new float2(0, altitude);
|
||||||
|
|
||||||
var highPos = (Info.High || Info.Angle > 0)
|
var highPos = (Info.High || Info.Angle > 0)
|
||||||
? (pos - new float2(0, GetAltitude()))
|
? (pos - new float2(0, GetAltitude()))
|
||||||
@@ -136,13 +144,13 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
if (!Info.High) // check for hitting a wall
|
if (!Info.High) // check for hitting a wall
|
||||||
{
|
{
|
||||||
var at = (float)t / TotalTime();
|
var at = (float)t / TotalTime();
|
||||||
var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at);
|
var pos = float2.Lerp(src.ToFloat2(), dest.ToFloat2(), at);
|
||||||
var cell = ((PPos) pos.ToInt2()).ToCPos();
|
var cell = ((PPos) pos.ToInt2()).ToCPos();
|
||||||
|
|
||||||
if (world.ActorMap.GetUnitsAt(cell).Any(
|
if (world.ActorMap.GetUnitsAt(cell).Any(
|
||||||
a => a.HasTrait<IBlocksBullets>()))
|
a => a.HasTrait<IBlocksBullets>()))
|
||||||
{
|
{
|
||||||
Args.dest = (PPos) pos.ToInt2();
|
dest = (PPos) pos.ToInt2();
|
||||||
Explode(world);
|
Explode(world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,11 +167,11 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
{
|
{
|
||||||
var at = (float)t / TotalTime();
|
var at = (float)t / TotalTime();
|
||||||
|
|
||||||
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
|
var altitude = float2.Lerp(srcAltitude, destAltitude, at);
|
||||||
var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at) - new float2(0, altitude);
|
var pos = float2.Lerp(src.ToFloat2(), dest.ToFloat2(), at) - new float2(0, altitude);
|
||||||
|
|
||||||
var cell = ((PPos)pos.ToInt2()).ToCPos();
|
var cell = ((PPos)pos.ToInt2()).ToCPos();
|
||||||
if (!Args.firedBy.World.FogObscures(cell))
|
if (!Args.sourceActor.World.FogObscures(cell))
|
||||||
{
|
{
|
||||||
if (Info.High || Info.Angle > 0)
|
if (Info.High || Info.Angle > 0)
|
||||||
{
|
{
|
||||||
@@ -184,7 +192,7 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
void Explode( World world )
|
void Explode( World world )
|
||||||
{
|
{
|
||||||
world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
Combat.DoImpacts(Args);
|
Combat.DoImpacts(dest.ToWPos(destAltitude), Args.sourceActor, Args.weapon, Args.firepowerModifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
@@ -25,13 +25,16 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
public class GravityBomb : IEffect
|
public class GravityBomb : IEffect
|
||||||
{
|
{
|
||||||
Animation anim;
|
Animation anim;
|
||||||
int altitude;
|
int2 dest;
|
||||||
|
int altitude, destAltitude;
|
||||||
ProjectileArgs Args;
|
ProjectileArgs Args;
|
||||||
|
|
||||||
public GravityBomb(GravityBombInfo info, ProjectileArgs args)
|
public GravityBomb(GravityBombInfo info, ProjectileArgs args)
|
||||||
{
|
{
|
||||||
Args = args;
|
Args = args;
|
||||||
altitude = args.srcAltitude;
|
altitude = args.source.Z * Game.CellSize / 1024;
|
||||||
|
destAltitude = args.passiveTarget.Z * Game.CellSize / 1024;
|
||||||
|
dest = PPos.FromWPos(args.passiveTarget).ToInt2();
|
||||||
|
|
||||||
anim = new Animation(info.Image);
|
anim = new Animation(info.Image);
|
||||||
if (anim.HasSequence("open"))
|
if (anim.HasSequence("open"))
|
||||||
@@ -42,10 +45,10 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
|
|
||||||
public void Tick(World world)
|
public void Tick(World world)
|
||||||
{
|
{
|
||||||
if (--altitude <= Args.destAltitude)
|
if (--altitude <= destAltitude)
|
||||||
{
|
{
|
||||||
world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
Combat.DoImpacts(Args);
|
Combat.DoImpacts(Args.passiveTarget, Args.sourceActor, Args.weapon, Args.firepowerModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
anim.Tick();
|
anim.Tick();
|
||||||
@@ -53,8 +56,8 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
var pos = Args.dest.ToInt2() - new int2(0, altitude) - .5f * anim.Image.size;
|
var pos = dest - new int2(0, altitude) - .5f * anim.Image.size;
|
||||||
yield return new SpriteRenderable(anim.Image, pos, wr.Palette("effect"), Args.dest.Y);
|
yield return new SpriteRenderable(anim.Image, pos, wr.Palette("effect"), dest.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using OpenRA.Effects;
|
using OpenRA.Effects;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.FileFormats;
|
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Effects
|
namespace OpenRA.Mods.RA.Effects
|
||||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
|
|
||||||
public IEffect Create(ProjectileArgs args)
|
public IEffect Create(ProjectileArgs args)
|
||||||
{
|
{
|
||||||
var c = UsePlayerColor ? args.firedBy.Owner.Color.RGB : Color;
|
var c = UsePlayerColor ? args.sourceActor.Owner.Color.RGB : Color;
|
||||||
return new LaserZap(args, this, c);
|
return new LaserZap(args, this, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,13 +41,16 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
int ticks = 0;
|
int ticks = 0;
|
||||||
Color color;
|
Color color;
|
||||||
bool doneDamage;
|
bool doneDamage;
|
||||||
|
bool animationComplete;
|
||||||
Animation hitanim;
|
Animation hitanim;
|
||||||
|
WPos target;
|
||||||
|
|
||||||
public LaserZap(ProjectileArgs args, LaserZapInfo info, Color color)
|
public LaserZap(ProjectileArgs args, LaserZapInfo info, Color color)
|
||||||
{
|
{
|
||||||
this.args = args;
|
this.args = args;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.target = args.passiveTarget;
|
||||||
|
|
||||||
if (info.HitAnim != null)
|
if (info.HitAnim != null)
|
||||||
this.hitanim = new Animation(info.HitAnim);
|
this.hitanim = new Animation(info.HitAnim);
|
||||||
@@ -56,23 +59,22 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
public void Tick(World world)
|
public void Tick(World world)
|
||||||
{
|
{
|
||||||
// Beam tracks target
|
// Beam tracks target
|
||||||
if (args.target.IsValid)
|
if (args.guidedTarget.IsValid)
|
||||||
args.dest = args.target.CenterLocation;
|
target = args.guidedTarget.CenterPosition;
|
||||||
|
|
||||||
if (!doneDamage)
|
if (!doneDamage)
|
||||||
{
|
{
|
||||||
if (hitanim != null)
|
if (hitanim != null)
|
||||||
hitanim.PlayThen("idle",
|
hitanim.PlayThen("idle", () => animationComplete = true);
|
||||||
() => world.AddFrameEndTask(w => w.Remove(this)));
|
|
||||||
Combat.DoImpacts(args);
|
Combat.DoImpacts(target, args.sourceActor, args.weapon, args.firepowerModifier);
|
||||||
doneDamage = true;
|
doneDamage = true;
|
||||||
}
|
}
|
||||||
++ticks;
|
|
||||||
|
|
||||||
if (hitanim != null)
|
if (hitanim != null)
|
||||||
hitanim.Tick();
|
hitanim.Tick();
|
||||||
else
|
|
||||||
if (ticks >= info.BeamDuration)
|
if (++ticks >= info.BeamDuration && animationComplete)
|
||||||
world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,19 +82,13 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
{
|
{
|
||||||
if (ticks < info.BeamDuration)
|
if (ticks < info.BeamDuration)
|
||||||
{
|
{
|
||||||
var src = new PPos(args.src.X, args.src.Y).ToWPos(args.srcAltitude);
|
|
||||||
var dest = new PPos(args.dest.X, args.dest.Y).ToWPos(args.destAltitude);
|
|
||||||
var rc = Color.FromArgb((info.BeamDuration - ticks) * 255 / info.BeamDuration, color);
|
var rc = Color.FromArgb((info.BeamDuration - ticks) * 255 / info.BeamDuration, color);
|
||||||
|
yield return new BeamRenderable(args.source, 0, target - args.source, info.BeamWidth, rc);
|
||||||
yield return new BeamRenderable(src, 0, dest - src, info.BeamWidth, rc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hitanim != null)
|
if (hitanim != null)
|
||||||
yield return new SpriteRenderable(hitanim.Image, args.dest.ToFloat2(),
|
foreach (var r in hitanim.Render(target, wr.Palette("effect")))
|
||||||
wr.Palette("effect"), (int)args.dest.Y);
|
yield return r;
|
||||||
|
|
||||||
if (ticks >= info.BeamDuration)
|
|
||||||
yield break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
@@ -54,6 +54,8 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
PVecInt offset;
|
PVecInt offset;
|
||||||
public PSubPos SubPxPosition;
|
public PSubPos SubPxPosition;
|
||||||
public PPos PxPosition { get { return SubPxPosition.ToPPos(); } }
|
public PPos PxPosition { get { return SubPxPosition.ToPPos(); } }
|
||||||
|
PPos target;
|
||||||
|
int targetAltitude;
|
||||||
|
|
||||||
readonly Animation anim;
|
readonly Animation anim;
|
||||||
int Facing;
|
int Facing;
|
||||||
@@ -66,12 +68,15 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
Info = info;
|
Info = info;
|
||||||
Args = args;
|
Args = args;
|
||||||
|
|
||||||
SubPxPosition = Args.src.ToPSubPos();
|
SubPxPosition = PPos.FromWPos(Args.source).ToPSubPos();
|
||||||
Altitude = Args.srcAltitude;
|
Altitude = args.source.Z * Game.CellSize / 1024;
|
||||||
Facing = Args.facing;
|
Facing = Args.facing;
|
||||||
|
|
||||||
|
target = PPos.FromWPos(Args.passiveTarget);
|
||||||
|
targetAltitude = args.passiveTarget.Z * Game.CellSize / 1024;
|
||||||
|
|
||||||
if (info.Inaccuracy > 0)
|
if (info.Inaccuracy > 0)
|
||||||
offset = (PVecInt)(info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
|
offset = (PVecInt)(info.Inaccuracy * args.sourceActor.World.SharedRandom.Gauss2D(2)).ToInt2();
|
||||||
|
|
||||||
if (Info.Image != null)
|
if (Info.Image != null)
|
||||||
{
|
{
|
||||||
@@ -81,8 +86,8 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
|
|
||||||
if (Info.ContrailLength > 0)
|
if (Info.ContrailLength > 0)
|
||||||
{
|
{
|
||||||
var color = Info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.firedBy) : Info.ContrailColor;
|
var color = Info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.sourceActor) : Info.ContrailColor;
|
||||||
Trail = new ContrailRenderable(args.firedBy.World, color, Info.ContrailLength, Info.ContrailDelay, 0);
|
Trail = new ContrailRenderable(args.sourceActor.World, color, Info.ContrailLength, Info.ContrailDelay, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,25 +99,27 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
{
|
{
|
||||||
t += 40;
|
t += 40;
|
||||||
|
|
||||||
|
// Missile tracks target
|
||||||
|
if (Args.guidedTarget.IsValid)
|
||||||
|
{
|
||||||
|
target = PPos.FromWPos(Args.guidedTarget.CenterPosition);
|
||||||
|
targetAltitude = Args.guidedTarget.CenterPosition.Z * Game.CellSize / 1024;
|
||||||
|
}
|
||||||
|
|
||||||
// In pixels
|
// In pixels
|
||||||
var dist = Args.target.CenterLocation + offset - PxPosition;
|
var dist = target + offset - PxPosition;
|
||||||
|
|
||||||
var targetAltitude = 0;
|
|
||||||
if (Args.target.IsValid)
|
|
||||||
targetAltitude = Args.target.CenterPosition.Z * Game.CellSize / 1024;
|
|
||||||
|
|
||||||
var jammed = Info.Jammable && world.ActorsWithTrait<JamsMissiles>().Any(tp =>
|
var jammed = Info.Jammable && world.ActorsWithTrait<JamsMissiles>().Any(tp =>
|
||||||
(tp.Actor.CenterLocation - PxPosition).ToCVec().Length <= tp.Trait.Range
|
(tp.Actor.CenterLocation - PxPosition).ToCVec().Length <= tp.Trait.Range
|
||||||
|
|
||||||
&& (tp.Actor.Owner.Stances[Args.firedBy.Owner] != Stance.Ally
|
&& (tp.Actor.Owner.Stances[Args.sourceActor.Owner] != Stance.Ally
|
||||||
|| (tp.Actor.Owner.Stances[Args.firedBy.Owner] == Stance.Ally && tp.Trait.AlliedMissiles))
|
|| (tp.Actor.Owner.Stances[Args.sourceActor.Owner] == Stance.Ally && tp.Trait.AlliedMissiles))
|
||||||
|
|
||||||
&& world.SharedRandom.Next(100 / tp.Trait.Chance) == 0);
|
&& world.SharedRandom.Next(100 / tp.Trait.Chance) == 0);
|
||||||
|
|
||||||
if (!jammed)
|
if (!jammed)
|
||||||
{
|
{
|
||||||
Altitude += Math.Sign(targetAltitude - Altitude);
|
Altitude += Math.Sign(targetAltitude - Altitude);
|
||||||
if (Args.target.IsValid)
|
if (Args.guidedTarget.IsValid)
|
||||||
Facing = Traits.Util.TickFacing(Facing,
|
Facing = Traits.Util.TickFacing(Facing,
|
||||||
Traits.Util.GetFacing(dist, Facing),
|
Traits.Util.GetFacing(dist, Facing),
|
||||||
Info.ROT);
|
Info.ROT);
|
||||||
@@ -127,7 +134,7 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
|
|
||||||
anim.Tick();
|
anim.Tick();
|
||||||
|
|
||||||
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough && Args.target.IsValid)
|
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough)
|
||||||
Explode(world);
|
Explode(world);
|
||||||
|
|
||||||
// TODO: Replace this with a lookup table
|
// TODO: Replace this with a lookup table
|
||||||
@@ -168,9 +175,8 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
void Explode(World world)
|
void Explode(World world)
|
||||||
{
|
{
|
||||||
world.AddFrameEndTask(w => w.Remove(this));
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
Args.dest = PxPosition;
|
|
||||||
if (t > Info.Arm * 40) /* don't blow up in our launcher's face! */
|
if (t > Info.Arm * 40) /* don't blow up in our launcher's face! */
|
||||||
Combat.DoImpacts(Args);
|
Combat.DoImpacts(PxPosition.ToWPos(Altitude), Args.sourceActor, Args.weapon, Args.firepowerModifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||||
@@ -178,7 +184,7 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
if (Info.ContrailLength > 0)
|
if (Info.ContrailLength > 0)
|
||||||
yield return Trail;
|
yield return Trail;
|
||||||
|
|
||||||
if (!Args.firedBy.World.FogObscures(PxPosition.ToCPos()))
|
if (!Args.sourceActor.World.FogObscures(PxPosition.ToCPos()))
|
||||||
yield return new SpriteRenderable(anim.Image, PxPosition.ToFloat2() - new float2(0, Altitude),
|
yield return new SpriteRenderable(anim.Image, PxPosition.ToFloat2() - new float2(0, Altitude),
|
||||||
wr.Palette(Args.weapon.Underwater ? "shadow" : "effect"), PxPosition.Y);
|
wr.Palette(Args.weapon.Underwater ? "shadow" : "effect"), PxPosition.Y);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
@@ -46,13 +46,14 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
var bright = SequenceProvider.GetSequence(Info.Image, "bright");
|
var bright = SequenceProvider.GetSequence(Info.Image, "bright");
|
||||||
var dim = SequenceProvider.GetSequence(Info.Image, "dim");
|
var dim = SequenceProvider.GetSequence(Info.Image, "dim");
|
||||||
|
|
||||||
var src = new PPos(Args.src.X, Args.src.Y - Args.srcAltitude);
|
var source = wr.ScreenPosition(Args.source);
|
||||||
var dest = new PPos(Args.dest.X, Args.dest.Y - Args.destAltitude);
|
var target = wr.ScreenPosition(Args.passiveTarget);
|
||||||
|
|
||||||
for (var n = 0; n < Info.DimZaps; n++)
|
for (var n = 0; n < Info.DimZaps; n++)
|
||||||
foreach (var z in DrawZapWandering(wr, src, dest, dim))
|
foreach (var z in DrawZapWandering(wr, source, target, dim))
|
||||||
yield return z;
|
yield return z;
|
||||||
for (var n = 0; n < Info.BrightZaps; n++)
|
for (var n = 0; n < Info.BrightZaps; n++)
|
||||||
foreach (var z in DrawZapWandering(wr, src, dest, bright))
|
foreach (var z in DrawZapWandering(wr, source, target, bright))
|
||||||
yield return z;
|
yield return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,10 +65,8 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
|
|
||||||
if (!doneDamage)
|
if (!doneDamage)
|
||||||
{
|
{
|
||||||
if (Args.target.IsValid)
|
var pos = Args.guidedTarget.IsValid ? Args.guidedTarget.CenterPosition : Args.passiveTarget;
|
||||||
Args.dest = Args.target.CenterLocation;
|
Combat.DoImpacts(pos, Args.sourceActor, Args.weapon, Args.firepowerModifier);
|
||||||
|
|
||||||
Combat.DoImpacts(Args);
|
|
||||||
doneDamage = true;
|
doneDamage = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +82,7 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
return renderables;
|
return renderables;
|
||||||
}
|
}
|
||||||
|
|
||||||
static IEnumerable<IRenderable> DrawZapWandering(WorldRenderer wr, PPos from, PPos to, Sequence s)
|
static IEnumerable<IRenderable> DrawZapWandering(WorldRenderer wr, float2 from, float2 to, Sequence s)
|
||||||
{
|
{
|
||||||
var z = float2.Zero; /* hack */
|
var z = float2.Zero; /* hack */
|
||||||
var dist = to - from;
|
var dist = to - from;
|
||||||
@@ -92,19 +91,19 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
var renderables = new List<IRenderable>();
|
var renderables = new List<IRenderable>();
|
||||||
if (Game.CosmeticRandom.Next(2) != 0)
|
if (Game.CosmeticRandom.Next(2) != 0)
|
||||||
{
|
{
|
||||||
var p1 = from.ToFloat2() + (1 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
|
var p1 = from + (1 / 3f) * dist + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
|
||||||
var p2 = from.ToFloat2() + (2 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
|
var p2 = from + (2 / 3f) * dist + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
|
||||||
|
|
||||||
renderables.AddRange(DrawZap(wr, from.ToFloat2(), p1, s, out p1));
|
renderables.AddRange(DrawZap(wr, from, p1, s, out p1));
|
||||||
renderables.AddRange(DrawZap(wr, p1, p2, s, out p2));
|
renderables.AddRange(DrawZap(wr, p1, p2, s, out p2));
|
||||||
renderables.AddRange(DrawZap(wr, p2, to.ToFloat2(), s, out z));
|
renderables.AddRange(DrawZap(wr, p2, to, s, out z));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var p1 = from.ToFloat2() + (1 / 2f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
|
var p1 = from + (1 / 2f) * dist + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
|
||||||
|
|
||||||
renderables.AddRange(DrawZap(wr, from.ToFloat2(), p1, s, out p1));
|
renderables.AddRange(DrawZap(wr, from, p1, s, out p1));
|
||||||
renderables.AddRange(DrawZap(wr, p1, to.ToFloat2(), s, out z));
|
renderables.AddRange(DrawZap(wr, p1, to, s, out z));
|
||||||
}
|
}
|
||||||
|
|
||||||
return renderables;
|
return renderables;
|
||||||
|
|||||||
Reference in New Issue
Block a user