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