homing weapons more or less work now
This commit is contained in:
@@ -94,7 +94,7 @@ namespace OpenRa.Game
|
||||
|
||||
public bool IsDead { get { return Health <= 0; } }
|
||||
|
||||
public void InflictDamage(Actor attacker, Bullet inflictor, int damage)
|
||||
public void InflictDamage(Actor attacker, int damage)
|
||||
{
|
||||
/* todo: auto-retaliate, etc */
|
||||
/* todo: death sequence for infantry based on inflictor */
|
||||
|
||||
54
OpenRa.Game/Combat.cs
Normal file
54
OpenRa.Game/Combat.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Game.GameRules;
|
||||
using OpenRa.Game.Effects;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
static class Combat /* some utility bits that are shared between various things */
|
||||
{
|
||||
public static void DoImpact(int2 loc, int2 visualLoc,
|
||||
WeaponInfo weapon, ProjectileInfo projectile, WarheadInfo warhead, Actor firedBy)
|
||||
{
|
||||
var targetTile = ((1f / Game.CellSize) * loc.ToFloat2()).ToInt2();
|
||||
|
||||
var isWater = Game.IsWater(targetTile);
|
||||
var hitWater = Game.IsCellBuildable(targetTile, UnitMovementType.Float);
|
||||
|
||||
if (warhead.Explosion != 0)
|
||||
Game.world.AddFrameEndTask(
|
||||
w => w.Add(new Explosion(visualLoc, warhead.Explosion, hitWater)));
|
||||
|
||||
var impactSound = warhead.ImpactSound;
|
||||
if (hitWater && warhead.WaterImpactSound != null)
|
||||
impactSound = warhead.WaterImpactSound;
|
||||
if (impactSound != null) Sound.Play(impactSound + ".aud");
|
||||
|
||||
if (!isWater) Smudge.AddSmudge(targetTile, warhead);
|
||||
if (warhead.Ore) Ore.Destroy(targetTile.X, targetTile.Y);
|
||||
|
||||
var maxSpread = GetMaximumSpread(weapon, warhead);
|
||||
var hitActors = Game.FindUnitsInCircle(loc, maxSpread);
|
||||
|
||||
foreach (var victim in hitActors)
|
||||
victim.InflictDamage(firedBy, (int)GetDamageToInflict(victim, loc, weapon, warhead));
|
||||
}
|
||||
|
||||
static float GetMaximumSpread(WeaponInfo weapon, WarheadInfo warhead)
|
||||
{
|
||||
return (int)(warhead.Spread * Math.Log(weapon.Damage, 2));
|
||||
}
|
||||
|
||||
static float GetDamageToInflict(Actor target, int2 loc, WeaponInfo weapon, WarheadInfo warhead)
|
||||
{
|
||||
/* todo: some things can't be damaged AT ALL by certain weapons! */
|
||||
var distance = (target.CenterLocation - loc).Length;
|
||||
var rawDamage = weapon.Damage * (float)Math.Exp(-distance / warhead.Spread);
|
||||
var multiplier = warhead.EffectivenessAgainst(target.Info.Armor);
|
||||
|
||||
return rawDamage * multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,11 @@ using System.Collections.Generic;
|
||||
using OpenRa.Game.GameRules;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game
|
||||
namespace OpenRa.Game.Effects
|
||||
{
|
||||
class Bullet : IEffect
|
||||
{
|
||||
public Player Owner { get; private set; }
|
||||
readonly Player Owner;
|
||||
readonly Actor FiredBy;
|
||||
readonly WeaponInfo Weapon;
|
||||
readonly ProjectileInfo Projectile;
|
||||
@@ -40,10 +40,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
anim = new Animation(Projectile.Image);
|
||||
if (Projectile.Rotates)
|
||||
anim.PlayFetchIndex("idle",
|
||||
() => Traits.Util.QuantizeFacing(
|
||||
Traits.Util.GetFacing((dest - src).ToFloat2(), 0),
|
||||
anim.CurrentSequence.Length));
|
||||
Traits.Util.PlayFacing(anim, "idle", () => Traits.Util.GetFacing((dest - src).ToFloat2(), 0));
|
||||
else
|
||||
anim.PlayRepeating("idle");
|
||||
}
|
||||
@@ -61,36 +58,10 @@ namespace OpenRa.Game
|
||||
if (t > TotalTime()) /* remove finished bullets */
|
||||
{
|
||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
||||
DoImpact();
|
||||
Combat.DoImpact(Dest, VisualDest, Weapon, Projectile, Warhead, FiredBy);
|
||||
}
|
||||
}
|
||||
|
||||
void DoImpact()
|
||||
{
|
||||
var targetTile = ((1f / Game.CellSize) * Dest.ToFloat2()).ToInt2();
|
||||
|
||||
var isWater = Game.IsWater(targetTile);
|
||||
var hitWater = Game.IsCellBuildable(targetTile, UnitMovementType.Float);
|
||||
|
||||
if (Warhead.Explosion != 0)
|
||||
Game.world.AddFrameEndTask(
|
||||
w => w.Add(new Explosion(VisualDest, Warhead.Explosion, hitWater)));
|
||||
|
||||
var impactSound = Warhead.ImpactSound;
|
||||
if (hitWater && Warhead.WaterImpactSound != null)
|
||||
impactSound = Warhead.WaterImpactSound;
|
||||
if (impactSound != null) Sound.Play(impactSound + ".aud");
|
||||
|
||||
if (!isWater) Smudge.AddSmudge(targetTile, Warhead);
|
||||
if (Warhead.Ore) Ore.Destroy(targetTile.X, targetTile.Y);
|
||||
|
||||
var maxSpread = GetMaximumSpread();
|
||||
var hitActors = Game.FindUnitsInCircle(Dest, GetMaximumSpread());
|
||||
|
||||
foreach (var victim in hitActors)
|
||||
victim.InflictDamage(FiredBy, this, (int)GetDamageToInflict(victim));
|
||||
}
|
||||
|
||||
const float height = .1f;
|
||||
|
||||
public IEnumerable<Tuple<Sprite, float2, int>> Render()
|
||||
@@ -116,20 +87,5 @@ namespace OpenRa.Game
|
||||
yield return Tuple.New(anim.Image, pos, Owner.Palette);
|
||||
}
|
||||
}
|
||||
|
||||
float GetMaximumSpread()
|
||||
{
|
||||
return (int)(Warhead.Spread * Math.Log(Weapon.Damage, 2));
|
||||
}
|
||||
|
||||
float GetDamageToInflict(Actor target)
|
||||
{
|
||||
/* todo: some things can't be damaged AT ALL by certain weapons! */
|
||||
var distance = (target.CenterLocation - Dest).Length;
|
||||
var rawDamage = Weapon.Damage * (float)Math.Exp(-distance / Warhead.Spread);
|
||||
var multiplier = Warhead.EffectivenessAgainst(target.Info.Armor);
|
||||
|
||||
return rawDamage * multiplier;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game
|
||||
namespace OpenRa.Game.Effects
|
||||
{
|
||||
class Explosion : IEffect
|
||||
{
|
||||
@@ -1,12 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game
|
||||
namespace OpenRa.Game.Effects
|
||||
{
|
||||
interface IEffect
|
||||
{
|
||||
void Tick();
|
||||
IEnumerable<Tuple<Sprite, float2, int>> Render();
|
||||
Player Owner { get; }
|
||||
}
|
||||
}
|
||||
89
OpenRa.Game/Effects/Missile.cs
Normal file
89
OpenRa.Game/Effects/Missile.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Game.Graphics;
|
||||
using OpenRa.Game.GameRules;
|
||||
|
||||
namespace OpenRa.Game.Effects
|
||||
{
|
||||
class Missile : IEffect
|
||||
{
|
||||
readonly Player Owner;
|
||||
readonly Actor FiredBy;
|
||||
readonly WeaponInfo Weapon;
|
||||
readonly ProjectileInfo Projectile;
|
||||
readonly WarheadInfo Warhead;
|
||||
float2 Pos;
|
||||
readonly Actor Target;
|
||||
readonly Animation anim;
|
||||
int Facing;
|
||||
int t;
|
||||
|
||||
public Missile(string weapon, Player owner, Actor firedBy,
|
||||
int2 src, Actor target)
|
||||
{
|
||||
Weapon = Rules.WeaponInfo[weapon];
|
||||
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
|
||||
Warhead = Rules.WarheadInfo[Weapon.Warhead];
|
||||
FiredBy = firedBy;
|
||||
Owner = owner;
|
||||
Target = target;
|
||||
Pos = src.ToFloat2();
|
||||
|
||||
/* todo: initial facing should be turret facing, or unit facing if we're not turreted */
|
||||
Facing = Traits.Util.GetFacing( Target.CenterLocation - src.ToFloat2(), 0 );
|
||||
|
||||
if (Projectile.Image != null && Projectile.Image != "none")
|
||||
{
|
||||
anim = new Animation(Projectile.Image);
|
||||
|
||||
if (Projectile.Rotates)
|
||||
Traits.Util.PlayFacing(anim, "idle", () => Facing);
|
||||
else
|
||||
anim.PlayRepeating("idle");
|
||||
}
|
||||
}
|
||||
|
||||
const int MissileCloseEnough = 7;
|
||||
const float Scale = .3f;
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
if (t == 0)
|
||||
Sound.Play(Weapon.Report + ".aud");
|
||||
|
||||
t += 40;
|
||||
|
||||
Traits.Util.TickFacing(ref Facing,
|
||||
Traits.Util.GetFacing(Target.CenterLocation - Pos, Facing),
|
||||
Projectile.ROT);
|
||||
|
||||
anim.Tick();
|
||||
|
||||
var dist = Target.CenterLocation - Pos;
|
||||
if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough || Target.IsDead)
|
||||
{
|
||||
Game.world.AddFrameEndTask(w => w.Remove(this));
|
||||
|
||||
if (t > Projectile.Arm * 40) /* don't blow up in our launcher's face! */
|
||||
Combat.DoImpact(Pos.ToInt2(), Pos.ToInt2(), Weapon, Projectile, Warhead, FiredBy);
|
||||
return;
|
||||
}
|
||||
|
||||
var move = (Scale * Weapon.Speed / dist.Length) * dist;
|
||||
Pos += move;
|
||||
|
||||
if (Projectile.Animates)
|
||||
Game.world.AddFrameEndTask(w => w.Add(new Smoke((Pos - 1.5f * move).ToInt2())));
|
||||
|
||||
// todo: running out of fuel
|
||||
// todo: turbo boost vs aircraft
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<Sprite, float2, int>> Render()
|
||||
{
|
||||
yield return Tuple.New(anim.Image, Pos - 0.5f * anim.Image.size, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
OpenRa.Game/Effects/Smoke.cs
Normal file
32
OpenRa.Game/Effects/Smoke.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using OpenRa.Game.Graphics;
|
||||
|
||||
namespace OpenRa.Game.Effects
|
||||
{
|
||||
class Smoke : IEffect
|
||||
{
|
||||
readonly int2 pos;
|
||||
readonly Animation anim = new Animation("smokey");
|
||||
|
||||
public Smoke(int2 pos)
|
||||
{
|
||||
this.pos = pos;
|
||||
anim.PlayThen("idle",
|
||||
() => Game.world.AddFrameEndTask(
|
||||
w => w.Remove(this)));
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
anim.Tick();
|
||||
}
|
||||
|
||||
public IEnumerable<Tuple<Sprite, float2, int>> Render()
|
||||
{
|
||||
yield return Tuple.New(anim.Image, pos.ToFloat2() - .5f * anim.Image.size, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using IjwFramework.Types;
|
||||
using System.Collections.Generic;
|
||||
using OpenRa.Game.Traits;
|
||||
using OpenRa.Game.Support;
|
||||
using OpenRa.Game.Effects;
|
||||
|
||||
namespace OpenRa.Game.Graphics
|
||||
{
|
||||
@@ -61,7 +62,7 @@ namespace OpenRa.Game.Graphics
|
||||
.Select(u => u.traits.Get<Traits.RenderWarFactory>()))
|
||||
DrawSpriteList(rect, a.RenderRoof(a.self));
|
||||
|
||||
foreach (IEffect e in Game.world.Effects)
|
||||
foreach (var e in Game.world.Effects)
|
||||
DrawSpriteList(rect, e.Render());
|
||||
|
||||
uiOverlay.Draw();
|
||||
|
||||
@@ -79,14 +79,17 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Chat.cs" />
|
||||
<Compile Include="Chrome.cs" />
|
||||
<Compile Include="Combat.cs" />
|
||||
<Compile Include="Effects\Smoke.cs" />
|
||||
<Compile Include="Exts.cs" />
|
||||
<Compile Include="GameRules\ActorInfo.cs" />
|
||||
<Compile Include="GameRules\GeneralInfo.cs" />
|
||||
<Compile Include="GameRules\TechTree.cs" />
|
||||
<Compile Include="GameRules\VoiceInfo.cs" />
|
||||
<Compile Include="IEffect.cs" />
|
||||
<Compile Include="Effects\IEffect.cs" />
|
||||
<Compile Include="IOrderSource.cs" />
|
||||
<Compile Include="LocalOrderSource.cs" />
|
||||
<Compile Include="Effects\Missile.cs" />
|
||||
<Compile Include="NetworkOrderSource.cs" />
|
||||
<Compile Include="OrderIO.cs" />
|
||||
<Compile Include="OrderManager.cs" />
|
||||
@@ -104,10 +107,10 @@
|
||||
<Compile Include="Traits\Activities\DeliverOre.cs" />
|
||||
<Compile Include="Traits\Activities\DeployMcv.cs" />
|
||||
<Compile Include="Actor.cs" />
|
||||
<Compile Include="Bullet.cs" />
|
||||
<Compile Include="Effects\Bullet.cs" />
|
||||
<Compile Include="Controller.cs" />
|
||||
<Compile Include="Cursor.cs" />
|
||||
<Compile Include="Explosion.cs" />
|
||||
<Compile Include="Effects\Explosion.cs" />
|
||||
<Compile Include="GameRules\FieldLoader.cs" />
|
||||
<Compile Include="GameRules\Footprint.cs" />
|
||||
<Compile Include="GameRules\InfoLoader.cs" />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using OpenRa.Game.Effects;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
@@ -63,10 +64,16 @@ namespace OpenRa.Game.Traits
|
||||
if (weapon.Range * weapon.Range < (target.Location - self.Location).LengthSquared) return false;
|
||||
|
||||
fireDelay = weapon.ROF;
|
||||
var projectile = Rules.ProjectileInfo[weapon.Projectile];
|
||||
|
||||
Game.world.Add(new Bullet(weaponName, self.Owner, self,
|
||||
self.CenterLocation.ToInt2() + Util.GetTurretPosition(self, unit, offset, 0f).ToInt2(),
|
||||
target.CenterLocation.ToInt2()));
|
||||
var firePos = self.CenterLocation.ToInt2() + Util.GetTurretPosition(self, unit, offset, 0f).ToInt2();
|
||||
|
||||
if (projectile.ROT != 0)
|
||||
Game.world.Add(new Missile(weaponName, self.Owner, self,
|
||||
firePos, target));
|
||||
else
|
||||
Game.world.Add(new Bullet(weaponName, self.Owner, self,
|
||||
firePos, target.CenterLocation.ToInt2()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRa.Game.Graphics;
|
||||
using OpenRa.Game.Effects;
|
||||
|
||||
namespace OpenRa.Game.Traits
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenRa.Game.Graphics;
|
||||
using OpenRa.Game.Traits;
|
||||
using OpenRa.Game.Effects;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
|
||||
@@ -603,4 +603,10 @@
|
||||
<unit name="mine">
|
||||
<sequence name="idle" start="0" length="1" />
|
||||
</unit>
|
||||
<unit name="dragon">
|
||||
<sequence name="idle" start="0" length="32" />
|
||||
</unit>
|
||||
<unit name="smokey">
|
||||
<sequence name="idle" start="0" length="6" />
|
||||
</unit>
|
||||
</sequences>
|
||||
@@ -9,4 +9,5 @@ s1=Multi2,mcv,600,12445,0,Guard,None
|
||||
s2=Multi1,mcv,600,12505,0,Guard,None
|
||||
s3=Multi3,mcv,600,2910,0,Guard,None
|
||||
|
||||
s4=Multi7,3tnk,600,13017,0,Guard,None
|
||||
|
||||
|
||||
@@ -99,7 +99,8 @@ Traits=Unit, Mobile, RenderUnit
|
||||
Description=Destroyer
|
||||
WaterBound=yes
|
||||
BuiltAt=syrd
|
||||
Traits=Unit, Mobile, RenderUnit
|
||||
Traits=Unit, Mobile, Turreted, AttackTurreted, RenderUnitTurreted
|
||||
PrimaryOffset=0,-8,0,-3
|
||||
[CA]
|
||||
Description=Cruiser
|
||||
WaterBound=yes
|
||||
@@ -556,7 +557,6 @@ Fireball
|
||||
|
||||
|
||||
|
||||
|
||||
[WarheadTypes]
|
||||
SA
|
||||
HE
|
||||
|
||||
Reference in New Issue
Block a user