split recoil into PrimaryRecoil/SecondaryRecoil; make recovery rate configurable per turret; #1069

This commit is contained in:
Chris Forbes
2011-08-03 19:26:08 +12:00
parent 954b0a617f
commit 54df44d43a
6 changed files with 44 additions and 27 deletions

View File

@@ -24,7 +24,10 @@ namespace OpenRA.Mods.RA
public readonly string PrimaryWeapon = null;
[WeaponReference]
public readonly string SecondaryWeapon = null;
public readonly int Recoil = 0;
public readonly int PrimaryRecoil = 0;
public readonly int SecondaryRecoil = 0;
public readonly float PrimaryRecoilRecovery = 0.2f;
public readonly float SecondaryRecoilRecovery = 0.2f;
public readonly int[] PrimaryLocalOffset = { };
public readonly int[] SecondaryLocalOffset = { };
public readonly int[] PrimaryOffset = { 0, 0 };
@@ -62,17 +65,17 @@ namespace OpenRA.Mods.RA
this.self = self;
var info = self.Info.Traits.Get<AttackBaseInfo>();
Turrets.Add(new Turret(info.PrimaryOffset));
Turrets.Add(new Turret(info.PrimaryOffset, info.PrimaryRecoilRecovery));
if (info.SecondaryOffset != null)
Turrets.Add(new Turret(info.SecondaryOffset));
Turrets.Add(new Turret(info.SecondaryOffset, info.SecondaryRecoilRecovery));
if (info.PrimaryWeapon != null)
Weapons.Add(new Weapon(info.PrimaryWeapon,
Turrets[0], info.PrimaryLocalOffset));
Turrets[0], info.PrimaryLocalOffset, info.PrimaryRecoil));
if (info.SecondaryWeapon != null)
Weapons.Add(new Weapon(info.SecondaryWeapon,
info.SecondaryOffset != null ? Turrets[1] : Turrets[0], info.SecondaryLocalOffset));
info.SecondaryOffset != null ? Turrets[1] : Turrets[0], info.SecondaryLocalOffset, info.SecondaryRecoil));
}
protected virtual bool CanAttack(Actor self, Target target)

View File

@@ -183,14 +183,11 @@ namespace OpenRA.Mods.RA
static float2 GetRecoil(Actor self, float recoil)
{
var abInfo = self.Info.Traits.GetOrDefault<AttackBaseInfo>();
if (abInfo == null || abInfo.Recoil == 0) return float2.Zero;
var rut = self.TraitOrDefault<RenderUnitTurreted>();
if (rut == null) return float2.Zero;
if (!self.HasTrait<RenderUnitTurreted>())
return float2.Zero;
var facing = self.Trait<Turreted>().turretFacing;
var localRecoil = new float2(0, recoil * abInfo.Recoil); // vector in turret-space.
var localRecoil = new float2(0, recoil); // vector in turret-space.
return Util.RotateVectorByFacing(localRecoil, facing, .7f);
}

View File

@@ -25,15 +25,19 @@ namespace OpenRA.Mods.RA
public class Turret
{
public float Recoil = 0.0f; // remaining recoil fraction
public float Recoil = 0.0f; // remaining recoil
public float RecoilRecovery = 0.2f; // recoil recovery rate
public int2 UnitSpacePosition; // where, in the unit's local space.
public int2 ScreenSpacePosition; // screen-space hack to make things line up good.
public Turret(int[] offset)
public Turret(int[] offset, float recoilRecovery)
{
ScreenSpacePosition = offset.AbsOffset().ToInt2();
UnitSpacePosition = offset.RelOffset().ToInt2();
RecoilRecovery = recoilRecovery;
}
public Turret(int[] offset) : this(offset, 0) {}
}
public class Weapon
@@ -41,15 +45,17 @@ namespace OpenRA.Mods.RA
public WeaponInfo Info;
public int FireDelay = 0; // time (in frames) until the weapon can fire again
public int Burst = 0; // burst counter
public int Recoil = 0;
public Barrel[] Barrels; // where projectiles are spawned, in local turret space.
public Turret Turret; // where this weapon is mounted -- possibly shared
public Weapon(string weaponName, Turret turret, int[] localOffset)
public Weapon(string weaponName, Turret turret, int[] localOffset, int recoil)
{
Info = Rules.Weapons[weaponName.ToLowerInvariant()];
Burst = Info.Burst;
Turret = turret;
Recoil = recoil;
var barrels = new List<Barrel>();
for (var i = 0; i < localOffset.Length / 5; i++)
@@ -72,7 +78,7 @@ namespace OpenRA.Mods.RA
public void Tick()
{
if (FireDelay > 0) --FireDelay;
Turret.Recoil = Math.Max(0f, Turret.Recoil - .2f);
Turret.Recoil = Math.Max(0f, Turret.Recoil - Turret.RecoilRecovery);
}
public bool IsValidAgainst(World world, Target target)
@@ -85,7 +91,7 @@ namespace OpenRA.Mods.RA
public void FiredShot()
{
Turret.Recoil = 1;
Turret.Recoil = this.Recoil;
if (--Burst > 0)
FireDelay = Info.BurstDelay;