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
{
[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 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 string Image = null;
public readonly string Palette = "effect";
public readonly bool Shadow = false;
[Desc("Trail animation.")]
public readonly string Trail = null;
[Desc("Is this blocked by actors with BlocksProjectiles trait.")]
public readonly bool Blockable = true;
[Desc("Arc in WAngles, two values indicate variable arc.")]
public readonly WAngle[] Angle = { WAngle.Zero };
[Desc("Interval in ticks between each spawned Trail animation.")]
public readonly int TrailInterval = 2;
[Desc("Delay in ticks until trail animaion is spawned.")]
public readonly int TrailDelay = 1;
public readonly int ContrailLength = 0;
public readonly Color ContrailColor = Color.White;
@@ -48,11 +51,11 @@ namespace OpenRA.Mods.Common.Effects
{
readonly BulletInfo info;
readonly ProjectileArgs args;
readonly Animation anim;
[Sync] readonly WAngle angle;
[Sync] readonly WRange speed;
ContrailRenderable trail;
Animation anim;
ContrailRenderable contrail;
[Sync] WPos pos, target;
[Sync] int length;
@@ -100,7 +103,7 @@ namespace OpenRA.Mods.Common.Effects
if (info.ContrailLength > 0)
{
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;
@@ -134,7 +137,7 @@ namespace OpenRA.Mods.Common.Effects
}
if (info.ContrailLength > 0)
trail.Update(pos);
contrail.Update(pos);
if (ticks++ >= length || (info.Blockable && world.ActorMap
.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)
{
if (info.ContrailLength > 0)
yield return trail;
yield return contrail;
if (anim == null || ticks >= length)
yield break;
@@ -168,7 +171,7 @@ namespace OpenRA.Mods.Common.Effects
void Explode(World world)
{
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));

View File

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

View File

@@ -39,13 +39,13 @@ namespace OpenRA.Mods.Common.Effects
class LaserZap : IEffect
{
ProjectileArgs args;
LaserZapInfo info;
readonly ProjectileArgs args;
readonly LaserZapInfo info;
readonly Animation hitanim;
int ticks = 0;
Color color;
bool doneDamage;
bool animationComplete;
Animation hitanim;
WPos target;
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);
[Desc("How many ticks before this missile is armed and can explode.")]
public readonly int Arm = 0;
public readonly string Trail = null;
[Desc("Is the missile blocked by actors with BlocksProjectiles: trait.")]
public readonly bool Blockable = true;
[Desc("Maximum offset at the maximum range")]
public readonly WRange Inaccuracy = WRange.Zero;
[Desc("Probability of locking onto and following target.")]
public readonly int LockOnProbability = 100;
[Desc("Explode when following the target longer than this.")]
[Desc("In n/256 per tick.")]
public readonly int RateOfTurn = 5;
[Desc("Explode when following the target longer than this many ticks.")]
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 ContrailLength = 0;
public readonly Color ContrailColor = Color.White;
public readonly bool ContrailUsePlayerColor = false;
public readonly int ContrailDelay = 1;
[Desc("Should missile targeting be thrown off by nearby actors with JamsMissiles.")]
public readonly bool Jammable = true;
[Desc("Explodes when leaving the following terrain type, e.g., Water for torpedoes.")]
public readonly string BoundToTerrainType = "";
@@ -65,7 +68,7 @@ namespace OpenRA.Mods.Common.Effects
readonly Animation anim;
int ticksToNextSmoke;
ContrailRenderable trail;
ContrailRenderable contrail;
[Sync] WPos pos;
[Sync] int facing;
@@ -109,7 +112,7 @@ namespace OpenRA.Mods.Common.Effects
if (info.ContrailLength > 0)
{
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,7 +130,8 @@ namespace OpenRA.Mods.Common.Effects
public void Tick(World world)
{
ticks++;
anim.Tick();
if (anim != null)
anim.Tick();
// Missile tracks target
if (args.GuidedTarget.IsValidFor(args.SourceActor) && lockOn)
@@ -165,7 +169,7 @@ namespace OpenRA.Mods.Common.Effects
}
if (info.ContrailLength > 0)
trail.Update(pos);
contrail.Update(pos);
var cell = world.Map.CellContaining(pos);
@@ -183,7 +187,7 @@ namespace OpenRA.Mods.Common.Effects
void Explode(World world)
{
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));
@@ -197,7 +201,7 @@ namespace OpenRA.Mods.Common.Effects
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
if (info.ContrailLength > 0)
yield return trail;
yield return contrail;
if (!args.SourceActor.World.FogObscures(wr.World.Map.CellContaining(pos)))
{