move projectile effects into mod

This commit is contained in:
Bob
2010-07-08 16:04:18 +12:00
parent 7a738ed6af
commit bd74b29ea3
10 changed files with 19 additions and 14 deletions

View File

@@ -1,144 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Effects
{
public class BulletInfo : IProjectileInfo
{
public readonly int Speed = 1;
public readonly string Trail = null;
public readonly float Inaccuracy = 0; // pixels at maximum range
public readonly string Image = null;
public readonly bool High = false;
public readonly bool Arcing = false;
public readonly int RangeLimit = 0;
public readonly int Arm = 0;
public readonly bool Shadow = false;
public readonly bool Proximity = false;
public IEffect Create(ProjectileArgs args) { return new Bullet( this, args ); }
}
public class Bullet : IEffect
{
readonly BulletInfo Info;
readonly ProjectileArgs Args;
int t = 0;
Animation anim;
const int BaseBulletSpeed = 100; /* pixels / 40ms frame */
public Bullet(BulletInfo info, ProjectileArgs args)
{
Info = info;
Args = args;
if (info.Inaccuracy > 0)
{
var factor = ((Args.dest - Args.src).Length / Game.CellSize) / args.weapon.Range;
Args.dest += (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
}
if (Info.Image != null)
{
anim = new Animation(Info.Image, () => Traits.Util.GetFacing(Args.dest - Args.src, 0));
anim.PlayRepeating("idle");
}
}
int TotalTime() { return (Args.dest - Args.src).Length * BaseBulletSpeed / Info.Speed; }
public void Tick( World world )
{
t += 40;
if (anim != null) anim.Tick();
if (t > TotalTime()) Explode( world );
if (Info.Trail != null)
{
var at = (float)t / TotalTime();
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
var pos = float2.Lerp(Args.src, Args.dest, at) - new float2(0, altitude);
var highPos = (Info.High || Info.Arcing)
? (pos - new float2(0, (Args.dest - Args.src).Length * height * 4 * at * (1 - at)))
: pos;
world.AddFrameEndTask(w => w.Add(
new Smoke(w, highPos.ToInt2(), Info.Trail)));
}
if (!Info.High) // check for hitting a wall
{
var at = (float)t / TotalTime();
var pos = float2.Lerp(Args.src, Args.dest, at);
var cell = Traits.Util.CellContaining(pos);
if (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(cell).Any(
a => a.traits.Contains<IBlocksBullets>()))
{
Args.dest = pos.ToInt2();
Explode(world);
}
}
}
const float height = .1f;
public IEnumerable<Renderable> Render()
{
if (anim != null)
{
var at = (float)t / TotalTime();
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
var pos = float2.Lerp(Args.src, Args.dest, at) - new float2(0, altitude);
if (Info.High || Info.Arcing)
{
if (Info.Shadow)
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, "shadow");
var highPos = pos - new float2(0, (Args.dest - Args.src).Length * height * 4 * at * (1 - at));
yield return new Renderable(anim.Image, highPos - .5f * anim.Image.size, Args.firedBy.Owner.Palette);
}
else
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size,
Args.weapon.Underwater ? "shadow" : Args.firedBy.Owner.Palette);
}
}
void Explode( World world )
{
world.AddFrameEndTask(w => w.Remove(this));
Combat.DoImpacts(Args);
}
}
}

View File

@@ -1,69 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Collections.Generic;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Effects
{
public class GravityBombInfo : IProjectileInfo
{
public readonly string Image = null;
public IEffect Create(ProjectileArgs args) { return new GravityBomb(this, args); }
}
public class GravityBomb : IEffect
{
Animation anim;
int altitude;
ProjectileArgs Args;
public GravityBomb(GravityBombInfo info, ProjectileArgs args)
{
Args = args;
altitude = args.srcAltitude;
anim = new Animation(info.Image);
if (anim.HasSequence("open"))
anim.PlayThen("open", () => anim.PlayRepeating("idle"));
else
anim.PlayRepeating("idle");
}
public void Tick(World world)
{
if (--altitude <= Args.destAltitude)
{
world.AddFrameEndTask(w => w.Remove(this));
Combat.DoImpacts(Args);
}
anim.Tick();
}
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image,
Args.dest - new int2(0, altitude) - .5f * anim.Image.size, "effect");
}
}
}

View File

@@ -1,83 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using OpenRA.GameRules;
using OpenRA.Traits;
namespace OpenRA.Effects
{
class LaserZapInfo : IProjectileInfo
{
public readonly int BeamRadius = 1;
public readonly bool UsePlayerColor = false;
public IEffect Create(ProjectileArgs args)
{
Color c = UsePlayerColor ? args.firedBy.Owner.Color : Color.Red;
return new LaserZap(args, BeamRadius, c);
}
}
class LaserZap : IEffect
{
ProjectileArgs args;
readonly int radius;
int timeUntilRemove = 10; // # of frames
int totalTime = 10;
Color color;
bool doneDamage = false;
public LaserZap(ProjectileArgs args, int radius, Color color)
{
this.args = args;
this.color = color;
this.radius = radius;
}
public void Tick(World world)
{
if (timeUntilRemove <= 0)
world.AddFrameEndTask(w => w.Remove(this));
--timeUntilRemove;
if (!doneDamage)
{
Combat.DoImpacts(args);
doneDamage = true;
}
}
public IEnumerable<Renderable> Render()
{
int alpha = (int)((1-(float)(totalTime-timeUntilRemove)/totalTime)*255);
Color rc = Color.FromArgb(alpha,color);
float2 unit = 1.0f/(args.src - args.dest).Length*(args.src - args.dest).ToFloat2();
float2 norm = new float2(-unit.Y, unit.X);
for (int i = -radius; i < radius; i++)
Game.world.WorldRenderer.lineRenderer.DrawLine(args.src + i * norm, args.dest + i * norm, rc, rc);
yield break;
}
}
}

View File

@@ -1,137 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Effects
{
class MissileInfo : IProjectileInfo
{
public readonly int Speed = 1;
public readonly int Arm = 0;
public readonly bool High = false;
public readonly bool Shadow = true;
public readonly bool Proximity = false;
public readonly string Trail = null;
public readonly float Inaccuracy = 0;
public readonly string Image = null;
public readonly int ROT = 5;
public readonly int RangeLimit = 0;
public readonly bool TurboBoost = false;
public IEffect Create(ProjectileArgs args) { return new Missile( this, args ); }
}
class Missile : IEffect
{
readonly MissileInfo Info;
readonly ProjectileArgs Args;
int2 offset;
float2 Pos;
readonly Animation anim;
int Facing;
int t;
int Altitude;
public Missile(MissileInfo info, ProjectileArgs args)
{
Info = info;
Args = args;
Pos = Args.src;
Altitude = Args.srcAltitude;
Facing = Args.facing;
if (info.Inaccuracy > 0)
offset = (info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
if (Info.Image != null)
{
anim = new Animation(Info.Image, () => Facing);
anim.PlayRepeating("idle");
}
}
const int MissileCloseEnough = 7;
const float Scale = .2f;
public void Tick( World world )
{
t += 40;
var targetPosition = Args.target.CenterLocation + offset;
var targetUnit = Args.target.traits.GetOrDefault<Unit>();
var targetAltitude = targetUnit != null ? targetUnit.Altitude : 0;
Altitude += Math.Sign(targetAltitude - Altitude);
Traits.Util.TickFacing(ref Facing,
Traits.Util.GetFacing(targetPosition - Pos, Facing),
Info.ROT);
anim.Tick();
var dist = targetPosition - Pos;
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Args.target.IsDead)
Explode(world);
var speed = Scale * Info.Speed * ((targetAltitude > 0 && Info.TurboBoost) ? 1.5f : 1f);
var angle = Facing / 128f * Math.PI;
var move = speed * -float2.FromAngle((float)angle);
Pos += move;
if (Info.Trail != null)
world.AddFrameEndTask(w => w.Add(
new Smoke(w, (Pos - 1.5f * move - new int2(0, Altitude)).ToInt2(), Info.Trail)));
if (Info.RangeLimit != 0 && t > Info.RangeLimit * 40)
Explode(world);
if (!Info.High) // check for hitting a wall
{
var cell = Traits.Util.CellContaining(Pos);
if (world.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt(cell).Any(
a => a.traits.Contains<IBlocksBullets>()))
Explode(world);
}
}
void Explode(World world)
{
world.AddFrameEndTask(w => w.Remove(this));
Args.dest = Pos.ToInt2();
if (t > Info.Arm * 40) /* don't blow up in our launcher's face! */
Combat.DoImpacts(Args);
}
public IEnumerable<Renderable> Render()
{
yield return new Renderable(anim.Image, Pos - 0.5f * anim.Image.size - new float2(0, Altitude), "effect");
}
}
}

View File

@@ -24,7 +24,7 @@ using OpenRA.Traits;
namespace OpenRA.Effects
{
class Smoke : IEffect
public class Smoke : IEffect
{
readonly int2 pos;
readonly Animation anim;

View File

@@ -1,131 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Effects
{
class TeslaZapInfo : IProjectileInfo
{
public IEffect Create(ProjectileArgs args) { return new TeslaZap( this, args ); }
}
class TeslaZap : IEffect
{
readonly ProjectileArgs Args;
int timeUntilRemove = 2; // # of frames
bool doneDamage = false;
const int numZaps = 3;
readonly List<Renderable> renderables = new List<Renderable>();
public TeslaZap(TeslaZapInfo info, ProjectileArgs args)
{
Args = args;
var bright = SequenceProvider.GetSequence("litning", "bright");
var dim = SequenceProvider.GetSequence("litning", "dim");
for (var n = 0; n < numZaps; n++)
renderables.AddRange(DrawZapWandering(args.src, args.dest, n == numZaps - 1 ? bright : dim));
}
public void Tick( World world )
{
if( timeUntilRemove <= 0 )
world.AddFrameEndTask( w => w.Remove( this ) );
--timeUntilRemove;
if (!doneDamage)
{
Combat.DoImpacts(Args);
doneDamage = true;
}
}
public IEnumerable<Renderable> Render() { return renderables; }
static IEnumerable<Renderable> DrawZapWandering(int2 from, int2 to, Sequence s)
{
var z = float2.Zero; /* hack */
var dist = to - from;
var norm = (1f / dist.Length) * new float2(-dist.Y, dist.X);
var renderables = new List<Renderable>();
if (Game.CosmeticRandom.Next(2) != 0)
{
var p1 = from + (1 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
var p2 = from + (2 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
renderables.AddRange(DrawZap(from, p1, s, out p1));
renderables.AddRange(DrawZap(p1, p2, s, out p2));
renderables.AddRange(DrawZap(p2, to, s, out z));
}
else
{
var p1 = from + (1 / 2f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm;
renderables.AddRange(DrawZap(from, p1, s, out p1));
renderables.AddRange(DrawZap(p1, to, s, out z));
}
return renderables;
}
static IEnumerable<Renderable> DrawZap(float2 from, float2 to, Sequence s, out float2 p)
{
var dist = to - from;
var q = new float2(-dist.Y, dist.X);
var c = -float2.Dot(from, q);
var rs = new List<Renderable>();
var z = from;
while ((to - z).X > 5 || (to - z).X < -5 || (to - z).Y > 5 || (to - z).Y < -5)
{
var step = steps.Where(t => (to - (z + new float2(t[0],t[1]))).LengthSquared < (to - z).LengthSquared )
.OrderBy(t => Math.Abs(float2.Dot(z + new float2(t[0], t[1]), q) + c)).First();
rs.Add(new Renderable(s.GetSprite(step[4]), z + new float2(step[2], step[3]), "effect"));
z += new float2(step[0], step[1]);
}
p = z;
return rs;
}
static int[][] steps = new []
{
new int[] { 8, 8, -8, -8, 0 },
new int[] { -8, -8, -16, -16, 0 },
new int[] { 8, 0, -8, -8, 1 },
new int[] { -8, 0, -16, -8, 1 },
new int[] { 0, 8, -8, -8, 2 },
new int[] { 0, -8, -8, -16, 2 },
new int[] { -8, 8, -16, -8, 3 },
new int[] { 8, -8, -8, -16, 3 }
};
}
}

View File

@@ -22,7 +22,7 @@ using System.Xml;
namespace OpenRA.Graphics
{
class CursorSequence
public class CursorSequence
{
readonly int start, length;

View File

@@ -27,7 +27,7 @@ using OpenRA.FileFormats;
namespace OpenRA.Graphics
{
static class SequenceProvider
public static class SequenceProvider
{
static Dictionary<string, Dictionary<string, Sequence>> units;
static Dictionary<string, CursorSequence> cursors;

View File

@@ -77,7 +77,6 @@
<ItemGroup>
<Compile Include="Chat.cs" />
<Compile Include="Chrome.cs" />
<Compile Include="Effects\GravityBomb.cs" />
<Compile Include="GameRules\WeaponInfo.cs" />
<Compile Include="Group.cs" />
<Compile Include="Orders\GenericSelectTarget.cs" />
@@ -106,11 +105,9 @@
<Compile Include="Combat.cs" />
<Compile Include="Effects\DelayedAction.cs" />
<Compile Include="Effects\FlashTarget.cs" />
<Compile Include="Effects\LaserZap.cs" />
<Compile Include="Effects\MoveFlash.cs" />
<Compile Include="Effects\RepairIndicator.cs" />
<Compile Include="Effects\Smoke.cs" />
<Compile Include="Effects\TeslaZap.cs" />
<Compile Include="Exts.cs" />
<Compile Include="GameRules\ActorInfo.cs" />
<Compile Include="GameRules\TechTree.cs" />
@@ -122,7 +119,6 @@
<Compile Include="Graphics\Minimap.cs" />
<Compile Include="Graphics\SpriteFont.cs" />
<Compile Include="Network\Connection.cs" />
<Compile Include="Effects\Missile.cs" />
<Compile Include="Network\OrderIO.cs" />
<Compile Include="Network\OrderManager.cs" />
<Compile Include="PathSearch.cs" />
@@ -143,7 +139,6 @@
<Compile Include="Traits\Activities\Attack.cs" />
<Compile Include="Traits\Activities\TransformIntoActor.cs" />
<Compile Include="Actor.cs" />
<Compile Include="Effects\Bullet.cs" />
<Compile Include="Controller.cs" />
<Compile Include="Cursor.cs" />
<Compile Include="Effects\Explosion.cs" />