allows delaying of fire action
This commit is contained in:
@@ -49,6 +49,7 @@ namespace OpenRa.Game.GameRules
|
|||||||
public readonly int SelectionPriority = 10;
|
public readonly int SelectionPriority = 10;
|
||||||
public readonly int InitialFacing = 128;
|
public readonly int InitialFacing = 128;
|
||||||
public readonly bool Selectable = true;
|
public readonly bool Selectable = true;
|
||||||
|
public readonly int FireDelay = 0;
|
||||||
|
|
||||||
public UnitInfo(string name) { Name = name; }
|
public UnitInfo(string name) { Name = name; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using OpenRa.Game.Effects;
|
using OpenRa.Game.Effects;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using IjwFramework.Types;
|
||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
@@ -35,6 +38,8 @@ namespace OpenRa.Game.Traits
|
|||||||
return (primaryFireDelay > 0) || (secondaryFireDelay > 0);
|
return (primaryFireDelay > 0) || (secondaryFireDelay > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Pair<int, Action>> delayedActions = new List<Pair<int, Action>>();
|
||||||
|
|
||||||
public virtual void Tick(Actor self)
|
public virtual void Tick(Actor self)
|
||||||
{
|
{
|
||||||
if (primaryFireDelay > 0) --primaryFireDelay;
|
if (primaryFireDelay > 0) --primaryFireDelay;
|
||||||
@@ -44,6 +49,23 @@ namespace OpenRa.Game.Traits
|
|||||||
secondaryRecoil = Math.Max(0f, secondaryRecoil - .2f);
|
secondaryRecoil = Math.Max(0f, secondaryRecoil - .2f);
|
||||||
|
|
||||||
if (target != null && target.IsDead) target = null; /* he's dead, jim. */
|
if (target != null && target.IsDead) target = null; /* he's dead, jim. */
|
||||||
|
|
||||||
|
for (var i = 0; i < delayedActions.Count; i++)
|
||||||
|
{
|
||||||
|
var x = delayedActions[i];
|
||||||
|
if (--x.First <= 0)
|
||||||
|
x.Second();
|
||||||
|
delayedActions[i] = x;
|
||||||
|
}
|
||||||
|
delayedActions.RemoveAll(a => a.First <= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScheduleDelayedAction(int t, Action a)
|
||||||
|
{
|
||||||
|
if (t > 0)
|
||||||
|
delayedActions.Add(Pair.New(t, a));
|
||||||
|
else
|
||||||
|
a();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoAttack(Actor self)
|
public void DoAttack(Actor self)
|
||||||
@@ -83,19 +105,20 @@ namespace OpenRa.Game.Traits
|
|||||||
burst = weapon.Burst;
|
burst = weapon.Burst;
|
||||||
}
|
}
|
||||||
|
|
||||||
var projectile = Rules.ProjectileInfo[weapon.Projectile];
|
|
||||||
|
|
||||||
var firePos = self.CenterLocation.ToInt2() + Util.GetTurretPosition(self, unit, offset, 0f).ToInt2();
|
var firePos = self.CenterLocation.ToInt2() + Util.GetTurretPosition(self, unit, offset, 0f).ToInt2();
|
||||||
|
var thisTarget = target;
|
||||||
if (projectile.ROT != 0)
|
ScheduleDelayedAction(self.Info.FireDelay, () =>
|
||||||
|
{
|
||||||
|
if (Rules.ProjectileInfo[weapon.Projectile].ROT != 0)
|
||||||
Game.world.Add(new Missile(weaponName, self.Owner, self,
|
Game.world.Add(new Missile(weaponName, self.Owner, self,
|
||||||
firePos, target));
|
firePos, thisTarget));
|
||||||
else
|
else
|
||||||
Game.world.Add(new Bullet(weaponName, self.Owner, self,
|
Game.world.Add(new Bullet(weaponName, self.Owner, self,
|
||||||
firePos, target.CenterLocation.ToInt2()));
|
firePos, thisTarget.CenterLocation.ToInt2()));
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(weapon.Report))
|
if (!string.IsNullOrEmpty(weapon.Report))
|
||||||
Sound.Play(weapon.Report + ".aud");
|
Sound.Play(weapon.Report + ".aud");
|
||||||
|
});
|
||||||
|
|
||||||
foreach (var na in self.traits.WithInterface<INotifyAttack>())
|
foreach (var na in self.traits.WithInterface<INotifyAttack>())
|
||||||
na.Attacking(self);
|
na.Attacking(self);
|
||||||
|
|||||||
@@ -469,6 +469,7 @@ SquadSize=3
|
|||||||
[E2]
|
[E2]
|
||||||
Description=Grenadier
|
Description=Grenadier
|
||||||
Traits=Unit, Mobile, RenderInfantry, AttackBase
|
Traits=Unit, Mobile, RenderInfantry, AttackBase
|
||||||
|
FireDelay=15
|
||||||
[E3]
|
[E3]
|
||||||
Description=Rocket Soldier
|
Description=Rocket Soldier
|
||||||
Traits=Unit, Mobile, RenderInfantry, AttackBase
|
Traits=Unit, Mobile, RenderInfantry, AttackBase
|
||||||
|
|||||||
Reference in New Issue
Block a user