Add/tweak some descriptions and streamline style/organisation of

projectile and explosion effects code
This commit is contained in:
reaperrr
2015-03-10 23:02:57 +01:00
parent 1cc900b269
commit d531d29791
5 changed files with 41 additions and 30 deletions

View File

@@ -22,19 +22,22 @@ namespace OpenRA.Mods.Common.Effects
{ {
public class BulletInfo : IProjectileInfo public class BulletInfo : IProjectileInfo
{ {
[Desc("Projectile speed in WRange / tick, two values indicate variable velocity")] [Desc("Projectile speed in WRange / tick, two values indicate variable velocity.")]
public readonly WRange[] Speed = { new WRange(17) }; public readonly WRange[] Speed = { new WRange(17) };
public readonly string Trail = null; [Desc("Maximum offset at the maximum range.")]
[Desc("Maximum offset at the maximum range")]
public readonly WRange Inaccuracy = WRange.Zero; public readonly WRange Inaccuracy = WRange.Zero;
public readonly string Image = null; public readonly string Image = null;
public readonly string Palette = "effect"; public readonly string Palette = "effect";
public readonly bool Shadow = false; public readonly bool Shadow = false;
[Desc("Trail animation.")]
public readonly string Trail = null;
[Desc("Is this blocked by actors with BlocksProjectiles trait.")] [Desc("Is this blocked by actors with BlocksProjectiles trait.")]
public readonly bool Blockable = true; public readonly bool Blockable = true;
[Desc("Arc in WAngles, two values indicate variable arc.")] [Desc("Arc in WAngles, two values indicate variable arc.")]
public readonly WAngle[] Angle = { WAngle.Zero }; public readonly WAngle[] Angle = { WAngle.Zero };
[Desc("Interval in ticks between each spawned Trail animation.")]
public readonly int TrailInterval = 2; public readonly int TrailInterval = 2;
[Desc("Delay in ticks until trail animaion is spawned.")]
public readonly int TrailDelay = 1; public readonly int TrailDelay = 1;
public readonly int ContrailLength = 0; public readonly int ContrailLength = 0;
public readonly Color ContrailColor = Color.White; public readonly Color ContrailColor = Color.White;
@@ -48,11 +51,11 @@ namespace OpenRA.Mods.Common.Effects
{ {
readonly BulletInfo info; readonly BulletInfo info;
readonly ProjectileArgs args; readonly ProjectileArgs args;
readonly Animation anim;
[Sync] readonly WAngle angle; [Sync] readonly WAngle angle;
[Sync] readonly WRange speed; [Sync] readonly WRange speed;
ContrailRenderable trail; ContrailRenderable contrail;
Animation anim;
[Sync] WPos pos, target; [Sync] WPos pos, target;
[Sync] int length; [Sync] int length;
@@ -100,7 +103,7 @@ namespace OpenRA.Mods.Common.Effects
if (info.ContrailLength > 0) if (info.ContrailLength > 0)
{ {
var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor; var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
trail = new ContrailRenderable(world, color, info.ContrailLength, info.ContrailDelay, 0); contrail = new ContrailRenderable(world, color, info.ContrailLength, info.ContrailDelay, 0);
} }
smokeTicks = info.TrailDelay; smokeTicks = info.TrailDelay;
@@ -134,7 +137,7 @@ namespace OpenRA.Mods.Common.Effects
} }
if (info.ContrailLength > 0) if (info.ContrailLength > 0)
trail.Update(pos); contrail.Update(pos);
if (ticks++ >= length || (info.Blockable && world.ActorMap if (ticks++ >= length || (info.Blockable && world.ActorMap
.GetUnitsAt(world.Map.CellContaining(pos)).Any(a => a.HasTrait<IBlocksProjectiles>()))) .GetUnitsAt(world.Map.CellContaining(pos)).Any(a => a.HasTrait<IBlocksProjectiles>())))
@@ -144,7 +147,7 @@ namespace OpenRA.Mods.Common.Effects
public IEnumerable<IRenderable> Render(WorldRenderer wr) public IEnumerable<IRenderable> Render(WorldRenderer wr)
{ {
if (info.ContrailLength > 0) if (info.ContrailLength > 0)
yield return trail; yield return contrail;
if (anim == null || ticks >= length) if (anim == null || ticks >= length)
yield break; yield break;
@@ -168,7 +171,7 @@ namespace OpenRA.Mods.Common.Effects
void Explode(World world) void Explode(World world)
{ {
if (info.ContrailLength > 0) if (info.ContrailLength > 0)
world.AddFrameEndTask(w => w.Add(new ContrailFader(pos, trail))); world.AddFrameEndTask(w => w.Add(new ContrailFader(pos, contrail)));
world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));

View File

@@ -16,11 +16,11 @@ namespace OpenRA.Mods.Common.Effects
{ {
public class Explosion : IEffect public class Explosion : IEffect
{ {
World world; readonly World world;
readonly string palette;
readonly Animation anim;
WPos pos; WPos pos;
CPos cell; CPos cell;
string palette;
Animation anim;
public Explosion(World world, WPos pos, string sequence, string palette) public Explosion(World world, WPos pos, string sequence, string palette)
{ {

View File

@@ -22,6 +22,7 @@ namespace OpenRA.Mods.Common.Effects
public readonly string Palette = "effect"; public readonly string Palette = "effect";
public readonly bool Shadow = false; public readonly bool Shadow = false;
public readonly WRange Velocity = WRange.Zero; public readonly WRange Velocity = WRange.Zero;
[Desc("Value added to velocity every tick.")]
public readonly WRange Acceleration = new WRange(15); public readonly WRange Acceleration = new WRange(15);
public IEffect Create(ProjectileArgs args) { return new GravityBomb(this, args); } public IEffect Create(ProjectileArgs args) { return new GravityBomb(this, args); }
@@ -29,11 +30,12 @@ namespace OpenRA.Mods.Common.Effects
public class GravityBomb : IEffect public class GravityBomb : IEffect
{ {
GravityBombInfo info; readonly GravityBombInfo info;
Animation anim; readonly Animation anim;
ProjectileArgs args; readonly ProjectileArgs args;
WVec velocity; [Sync] WVec velocity;
WPos pos; [Sync] WPos pos;
[Sync] WVec acceleration;
public GravityBomb(GravityBombInfo info, ProjectileArgs args) public GravityBomb(GravityBombInfo info, ProjectileArgs args)
{ {
@@ -41,6 +43,7 @@ namespace OpenRA.Mods.Common.Effects
this.args = args; this.args = args;
pos = args.Source; pos = args.Source;
velocity = new WVec(WRange.Zero, WRange.Zero, -info.Velocity); velocity = new WVec(WRange.Zero, WRange.Zero, -info.Velocity);
acceleration = new WVec(WRange.Zero, WRange.Zero, info.Acceleration);
anim = new Animation(args.SourceActor.World, info.Image); anim = new Animation(args.SourceActor.World, info.Image);
if (anim.HasSequence("open")) if (anim.HasSequence("open"))
@@ -51,7 +54,7 @@ namespace OpenRA.Mods.Common.Effects
public void Tick(World world) public void Tick(World world)
{ {
velocity -= new WVec(WRange.Zero, WRange.Zero, info.Acceleration); velocity -= acceleration;
pos += velocity; pos += velocity;
if (pos.Z <= args.PassiveTarget.Z) if (pos.Z <= args.PassiveTarget.Z)
@@ -61,6 +64,7 @@ namespace OpenRA.Mods.Common.Effects
args.Weapon.Impact(Target.FromPos(pos), args.SourceActor, args.DamageModifiers); args.Weapon.Impact(Target.FromPos(pos), args.SourceActor, args.DamageModifiers);
} }
if (anim != null)
anim.Tick(); anim.Tick();
} }

View File

@@ -39,13 +39,13 @@ namespace OpenRA.Mods.Common.Effects
class LaserZap : IEffect class LaserZap : IEffect
{ {
ProjectileArgs args; readonly ProjectileArgs args;
LaserZapInfo info; readonly LaserZapInfo info;
readonly Animation hitanim;
int ticks = 0; int ticks = 0;
Color color; Color color;
bool doneDamage; bool doneDamage;
bool animationComplete; bool animationComplete;
Animation hitanim;
WPos target; WPos target;
public LaserZap(ProjectileArgs args, LaserZapInfo info, Color color) public LaserZap(ProjectileArgs args, LaserZapInfo info, Color color)

View File

@@ -31,22 +31,25 @@ namespace OpenRA.Mods.Common.Effects
public readonly WAngle MaximumPitch = WAngle.FromDegrees(30); public readonly WAngle MaximumPitch = WAngle.FromDegrees(30);
[Desc("How many ticks before this missile is armed and can explode.")] [Desc("How many ticks before this missile is armed and can explode.")]
public readonly int Arm = 0; public readonly int Arm = 0;
public readonly string Trail = null;
[Desc("Is the missile blocked by actors with BlocksProjectiles: trait.")] [Desc("Is the missile blocked by actors with BlocksProjectiles: trait.")]
public readonly bool Blockable = true; public readonly bool Blockable = true;
[Desc("Maximum offset at the maximum range")] [Desc("Maximum offset at the maximum range")]
public readonly WRange Inaccuracy = WRange.Zero; public readonly WRange Inaccuracy = WRange.Zero;
[Desc("Probability of locking onto and following target.")] [Desc("Probability of locking onto and following target.")]
public readonly int LockOnProbability = 100; public readonly int LockOnProbability = 100;
[Desc("Explode when following the target longer than this.")]
[Desc("In n/256 per tick.")] [Desc("In n/256 per tick.")]
public readonly int RateOfTurn = 5; public readonly int RateOfTurn = 5;
[Desc("Explode when following the target longer than this many ticks.")]
public readonly int RangeLimit = 0; public readonly int RangeLimit = 0;
[Desc("Trail animation.")]
public readonly string Trail = null;
[Desc("Interval in ticks between each spawned Trail animation.")]
public readonly int TrailInterval = 2; public readonly int TrailInterval = 2;
public readonly int ContrailLength = 0; public readonly int ContrailLength = 0;
public readonly Color ContrailColor = Color.White; public readonly Color ContrailColor = Color.White;
public readonly bool ContrailUsePlayerColor = false; public readonly bool ContrailUsePlayerColor = false;
public readonly int ContrailDelay = 1; public readonly int ContrailDelay = 1;
[Desc("Should missile targeting be thrown off by nearby actors with JamsMissiles.")]
public readonly bool Jammable = true; public readonly bool Jammable = true;
[Desc("Explodes when leaving the following terrain type, e.g., Water for torpedoes.")] [Desc("Explodes when leaving the following terrain type, e.g., Water for torpedoes.")]
public readonly string BoundToTerrainType = ""; public readonly string BoundToTerrainType = "";
@@ -65,7 +68,7 @@ namespace OpenRA.Mods.Common.Effects
readonly Animation anim; readonly Animation anim;
int ticksToNextSmoke; int ticksToNextSmoke;
ContrailRenderable trail; ContrailRenderable contrail;
[Sync] WPos pos; [Sync] WPos pos;
[Sync] int facing; [Sync] int facing;
@@ -109,7 +112,7 @@ namespace OpenRA.Mods.Common.Effects
if (info.ContrailLength > 0) if (info.ContrailLength > 0)
{ {
var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor; var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
trail = new ContrailRenderable(world, color, info.ContrailLength, info.ContrailDelay, 0); contrail = new ContrailRenderable(world, color, info.ContrailLength, info.ContrailDelay, 0);
} }
} }
@@ -127,6 +130,7 @@ namespace OpenRA.Mods.Common.Effects
public void Tick(World world) public void Tick(World world)
{ {
ticks++; ticks++;
if (anim != null)
anim.Tick(); anim.Tick();
// Missile tracks target // Missile tracks target
@@ -165,7 +169,7 @@ namespace OpenRA.Mods.Common.Effects
} }
if (info.ContrailLength > 0) if (info.ContrailLength > 0)
trail.Update(pos); contrail.Update(pos);
var cell = world.Map.CellContaining(pos); var cell = world.Map.CellContaining(pos);
@@ -183,7 +187,7 @@ namespace OpenRA.Mods.Common.Effects
void Explode(World world) void Explode(World world)
{ {
if (info.ContrailLength > 0) if (info.ContrailLength > 0)
world.AddFrameEndTask(w => w.Add(new ContrailFader(pos, trail))); world.AddFrameEndTask(w => w.Add(new ContrailFader(pos, contrail)));
world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
@@ -197,7 +201,7 @@ namespace OpenRA.Mods.Common.Effects
public IEnumerable<IRenderable> Render(WorldRenderer wr) public IEnumerable<IRenderable> Render(WorldRenderer wr)
{ {
if (info.ContrailLength > 0) if (info.ContrailLength > 0)
yield return trail; yield return contrail;
if (!args.SourceActor.World.FogObscures(wr.World.Map.CellContaining(pos))) if (!args.SourceActor.World.FogObscures(wr.World.Map.CellContaining(pos)))
{ {