add a simple projectile with random sequences for debris effects
This commit is contained in:
147
OpenRA.Mods.Common/Effects/Shrapnel.cs
Normal file
147
OpenRA.Mods.Common/Effects/Shrapnel.cs
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Effects;
|
||||||
|
using OpenRA.GameRules;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Graphics;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Effects
|
||||||
|
{
|
||||||
|
public class ShrapnelInfo : IProjectileInfo
|
||||||
|
{
|
||||||
|
[Desc("Projectile speed in WDist / tick, two values indicate variable velocity.")]
|
||||||
|
public readonly WDist[] Speed = { new WDist(17) };
|
||||||
|
|
||||||
|
[Desc("Image to display.")]
|
||||||
|
public readonly string Image = null;
|
||||||
|
|
||||||
|
[Desc("Loop these sequences of Image while this projectile is moving.")]
|
||||||
|
[SequenceReference("Image")] public readonly string[] Sequences = { "idle" };
|
||||||
|
|
||||||
|
[Desc("The palette used to draw this projectile.")]
|
||||||
|
public readonly string Palette = "effect";
|
||||||
|
|
||||||
|
[Desc("Does this projectile have a shadow?")]
|
||||||
|
public readonly bool Shadow = false;
|
||||||
|
|
||||||
|
[Desc("Palette to use for this projectile's shadow if Shadow is true.")]
|
||||||
|
public readonly string ShadowPalette = "shadow";
|
||||||
|
|
||||||
|
[Desc("Arc in WAngles, two values indicate variable arc.")]
|
||||||
|
public readonly WAngle[] Angle = { WAngle.Zero };
|
||||||
|
|
||||||
|
public IEffect Create(ProjectileArgs args) { return new Shrapnel(this, args); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Shrapnel : IEffect, ISync
|
||||||
|
{
|
||||||
|
readonly ShrapnelInfo info;
|
||||||
|
readonly ProjectileArgs args;
|
||||||
|
readonly Animation anim;
|
||||||
|
[Sync] readonly WAngle angle;
|
||||||
|
[Sync] readonly WDist speed;
|
||||||
|
|
||||||
|
[Sync] WPos pos, target;
|
||||||
|
[Sync] int length;
|
||||||
|
[Sync] int facing;
|
||||||
|
[Sync] int ticks;
|
||||||
|
|
||||||
|
[Sync] public Actor SourceActor { get { return args.SourceActor; } }
|
||||||
|
|
||||||
|
public Shrapnel(ShrapnelInfo info, ProjectileArgs args)
|
||||||
|
{
|
||||||
|
this.info = info;
|
||||||
|
this.args = args;
|
||||||
|
this.pos = args.Source;
|
||||||
|
|
||||||
|
var world = args.SourceActor.World;
|
||||||
|
|
||||||
|
if (info.Angle.Length > 1)
|
||||||
|
angle = new WAngle(world.SharedRandom.Next(info.Angle[0].Angle, info.Angle[1].Angle));
|
||||||
|
else
|
||||||
|
angle = info.Angle[0];
|
||||||
|
|
||||||
|
if (info.Speed.Length > 1)
|
||||||
|
speed = new WDist(world.SharedRandom.Next(info.Speed[0].Length, info.Speed[1].Length));
|
||||||
|
else
|
||||||
|
speed = info.Speed[0];
|
||||||
|
|
||||||
|
target = args.PassiveTarget;
|
||||||
|
|
||||||
|
facing = OpenRA.Traits.Util.GetFacing(target - pos, 0);
|
||||||
|
length = Math.Max((target - pos).Length / speed.Length, 1);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(info.Image))
|
||||||
|
{
|
||||||
|
anim = new Animation(world, info.Image, GetEffectiveFacing);
|
||||||
|
anim.PlayRepeating(info.Sequences.Random(world.SharedRandom));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetEffectiveFacing()
|
||||||
|
{
|
||||||
|
var at = (float)ticks / (length - 1);
|
||||||
|
var attitude = angle.Tan() * (1 - 2 * at) / (4 * 1024);
|
||||||
|
|
||||||
|
var u = (facing % 128) / 128f;
|
||||||
|
var scale = 512 * u * (1 - u);
|
||||||
|
|
||||||
|
return (int)(facing < 128
|
||||||
|
? facing - scale * attitude
|
||||||
|
: facing + scale * attitude);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick(World world)
|
||||||
|
{
|
||||||
|
if (anim != null)
|
||||||
|
anim.Tick();
|
||||||
|
|
||||||
|
pos = WPos.LerpQuadratic(args.Source, target, angle, ticks, length);
|
||||||
|
|
||||||
|
if (ticks++ >= length)
|
||||||
|
Explode(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||||
|
{
|
||||||
|
if (anim == null || ticks >= length)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
var world = args.SourceActor.World;
|
||||||
|
if (!world.FogObscures(pos))
|
||||||
|
{
|
||||||
|
if (info.Shadow)
|
||||||
|
{
|
||||||
|
var dat = world.Map.DistanceAboveTerrain(pos);
|
||||||
|
var shadowPos = pos - new WVec(0, 0, dat.Length);
|
||||||
|
foreach (var r in anim.Render(shadowPos, wr.Palette(info.ShadowPalette)))
|
||||||
|
yield return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
var palette = wr.Palette(info.Palette);
|
||||||
|
foreach (var r in anim.Render(pos, palette))
|
||||||
|
yield return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Explode(World world)
|
||||||
|
{
|
||||||
|
world.AddFrameEndTask(w => w.Remove(this));
|
||||||
|
|
||||||
|
args.Weapon.Impact(Target.FromPos(pos), args.SourceActor, args.DamageModifiers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -163,6 +163,7 @@
|
|||||||
<Compile Include="Effects\PowerdownIndicator.cs" />
|
<Compile Include="Effects\PowerdownIndicator.cs" />
|
||||||
<Compile Include="Effects\RallyPointIndicator.cs" />
|
<Compile Include="Effects\RallyPointIndicator.cs" />
|
||||||
<Compile Include="Effects\RepairIndicator.cs" />
|
<Compile Include="Effects\RepairIndicator.cs" />
|
||||||
|
<Compile Include="Effects\Shrapnel.cs" />
|
||||||
<Compile Include="Effects\Smoke.cs" />
|
<Compile Include="Effects\Smoke.cs" />
|
||||||
<Compile Include="Commands\ChatCommands.cs" />
|
<Compile Include="Commands\ChatCommands.cs" />
|
||||||
<Compile Include="Commands\DevCommands.cs" />
|
<Compile Include="Commands\DevCommands.cs" />
|
||||||
|
|||||||
@@ -695,11 +695,10 @@ Shrapnel:
|
|||||||
ReloadDelay: 60
|
ReloadDelay: 60
|
||||||
Range: 4c0
|
Range: 4c0
|
||||||
Report:
|
Report:
|
||||||
Projectile: Bullet
|
Projectile: Shrapnel
|
||||||
Speed: 50, 125
|
Speed: 50, 125
|
||||||
Blockable: false
|
Blockable: false
|
||||||
Angle: 91, 264
|
Angle: 91, 264
|
||||||
Inaccuracy: 416
|
|
||||||
Image: shrapnel
|
Image: shrapnel
|
||||||
Warhead@1Dam: SpreadDamage
|
Warhead@1Dam: SpreadDamage
|
||||||
Spread: 192
|
Spread: 192
|
||||||
|
|||||||
@@ -402,76 +402,48 @@ srock05:
|
|||||||
UseTilesetExtension: true
|
UseTilesetExtension: true
|
||||||
Offset: 0, -12
|
Offset: 0, -12
|
||||||
|
|
||||||
dbris1sm:
|
dbrissm:
|
||||||
idle:
|
1: dbris1sm
|
||||||
|
Length:*
|
||||||
|
2: dbris2sm
|
||||||
|
Length:*
|
||||||
|
3: dbris3sm
|
||||||
|
Length:*
|
||||||
|
4: dbris4sm
|
||||||
|
Length:*
|
||||||
|
5: dbris5sm
|
||||||
|
Length:*
|
||||||
|
6: dbris6sm
|
||||||
|
Length:*
|
||||||
|
7: dbris7sm
|
||||||
|
Length:*
|
||||||
|
8: dbris8sm
|
||||||
|
Length:*
|
||||||
|
9: dbris9sm
|
||||||
|
Length:*
|
||||||
|
10: dbrs10sm
|
||||||
Length:*
|
Length:*
|
||||||
|
|
||||||
dbris2sm:
|
dbrislg:
|
||||||
idle:
|
1: dbris1lg
|
||||||
Length:*
|
Length:*
|
||||||
|
2: dbris2lg
|
||||||
dbris3sm:
|
|
||||||
idle:
|
|
||||||
Length:*
|
Length:*
|
||||||
|
3: dbris3lg
|
||||||
dbris4sm:
|
|
||||||
idle:
|
|
||||||
Length:*
|
Length:*
|
||||||
|
4: dbris4lg
|
||||||
dbris5sm:
|
|
||||||
idle:
|
|
||||||
Length:*
|
Length:*
|
||||||
|
5: dbris5lg
|
||||||
dbris6sm:
|
|
||||||
idle:
|
|
||||||
Length:*
|
Length:*
|
||||||
|
6: dbris6lg
|
||||||
dbris7sm:
|
|
||||||
idle:
|
|
||||||
Length:*
|
Length:*
|
||||||
|
7: dbris7lg
|
||||||
dbris8sm:
|
|
||||||
idle:
|
|
||||||
Length:*
|
Length:*
|
||||||
|
8: dbris8lg
|
||||||
dbris9sm:
|
|
||||||
idle:
|
|
||||||
Length:*
|
Length:*
|
||||||
|
9: dbris9lg
|
||||||
dbris1lg:
|
|
||||||
idle:
|
|
||||||
Length:*
|
Length:*
|
||||||
|
10: dbrs10lg
|
||||||
dbris2lg:
|
|
||||||
idle:
|
|
||||||
Length:*
|
|
||||||
|
|
||||||
dbris3lg:
|
|
||||||
idle:
|
|
||||||
Length:*
|
|
||||||
|
|
||||||
dbris4lg:
|
|
||||||
idle:
|
|
||||||
Length:*
|
|
||||||
|
|
||||||
dbris5lg:
|
|
||||||
idle:
|
|
||||||
Length:*
|
|
||||||
|
|
||||||
dbris6lg:
|
|
||||||
idle:
|
|
||||||
Length:*
|
|
||||||
|
|
||||||
dbris7lg:
|
|
||||||
idle:
|
|
||||||
Length:*
|
|
||||||
|
|
||||||
dbris8lg:
|
|
||||||
idle:
|
|
||||||
Length:*
|
|
||||||
|
|
||||||
dbris9lg:
|
|
||||||
idle:
|
|
||||||
Length:*
|
Length:*
|
||||||
|
|
||||||
crat01:
|
crat01:
|
||||||
@@ -512,3 +484,4 @@ palet03:
|
|||||||
|
|
||||||
palet04:
|
palet04:
|
||||||
idle:
|
idle:
|
||||||
|
|
||||||
|
|||||||
@@ -48,20 +48,20 @@ SmallDebris:
|
|||||||
ReloadDelay: 60
|
ReloadDelay: 60
|
||||||
Range: 4c0
|
Range: 4c0
|
||||||
Report:
|
Report:
|
||||||
Projectile: Bullet
|
Projectile: Shrapnel
|
||||||
Speed: 50, 125
|
Speed: 50, 125
|
||||||
Blockable: false
|
|
||||||
Angle: 91, 264
|
Angle: 91, 264
|
||||||
Inaccuracy: 416
|
Image: dbrissm
|
||||||
Image: dbris1sm # TODO: add some variation
|
Sequences: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
||||||
|
Shadow: true
|
||||||
|
|
||||||
LargeDebris:
|
LargeDebris:
|
||||||
ReloadDelay: 60
|
ReloadDelay: 60
|
||||||
Range: 4c0
|
Range: 4c0
|
||||||
Report:
|
Report:
|
||||||
Projectile: Bullet
|
Projectile: Shrapnel
|
||||||
Speed: 50, 125
|
Speed: 50, 125
|
||||||
Blockable: false
|
|
||||||
Angle: 91, 264
|
Angle: 91, 264
|
||||||
Inaccuracy: 416
|
Image: dbrislg
|
||||||
Image: dbris1lg # TODO: add some variation
|
Sequences: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
|
||||||
|
Shadow: true
|
||||||
|
|||||||
Reference in New Issue
Block a user