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;

View File

@@ -291,7 +291,8 @@ LTNK:
ROT: 5
AttackTurreted:
PrimaryWeapon: 70mm
Recoil: 2
PrimaryRecoil: 2
PrimaryRecoilRecovery: 0.4
PrimaryLocalOffset: 0,3,0,-2,0
RenderUnitTurreted:
AutoTarget:
@@ -325,7 +326,8 @@ MTNK:
ROT: 5
AttackTurreted:
PrimaryWeapon: 120mm
Recoil: 3
PrimaryRecoil: 3
PrimaryRecoilRecovery: 0.6
PrimaryLocalOffset: 0,0,0,-1,0
RenderUnitTurreted:
AutoTarget:
@@ -365,7 +367,9 @@ HTNK:
SecondaryWeapon: MammothMissiles
PrimaryLocalOffset: -5,-5,0,-10,0, 5,-5,0,-10,0
SecondaryLocalOffset: -9,2,0,0,25, 9,2,0,0,-25
Recoil: 4
PrimaryRecoil: 4
SecondaryRecoil: 1
PrimaryRecoilRecovery: 1
RenderUnitTurreted:
AutoTarget:
SelfHealing:
@@ -404,7 +408,6 @@ MSAM:
PrimaryWeapon: 227mm
PrimaryOffset: 0,6,0,-3
PrimaryLocalOffset: 3,-5,0,0,0, -3,-5,0,0,0
Recoil: 0
RenderUnitTurretedAim:
AutoTarget:
LeavesHusk:
@@ -438,7 +441,6 @@ MLRS:
PrimaryOffset: 0,3,0,-3
PrimaryLocalOffset: -4,0,0,0,0
SecondaryLocalOffset: 4,0,0,0,0
Recoil: 0
AlignIdleTurrets: true
RenderUnitTurretedAim:
AutoTarget:

View File

@@ -158,7 +158,10 @@ CA:
SecondaryOffset: 0,-17,0,-2
PrimaryLocalOffset: -4,-5,0,0,0, 4,-5,0,0,0
SecondaryLocalOffset: -4,-5,0,0,0, 4,-5,0,0,0
Recoil: 4
PrimaryRecoil: 4
SecondaryRecoil: 4
PrimaryRecoilRecovery: 0.8
SecondaryRecoilRecovery: 0.8
Selectable:
Bounds: 44,44
RenderUnitTurreted:

View File

@@ -49,7 +49,8 @@ V2RL:
ROT: 5
AttackTurreted:
PrimaryWeapon: 25mm
Recoil: 2
PrimaryRecoil: 2
PrimaryRecoilRecovery: 0.5
RenderUnitTurreted:
AutoTarget:
Explodes:
@@ -82,7 +83,8 @@ V2RL:
ROT: 5
AttackTurreted:
PrimaryWeapon: 90mm
Recoil: 3
PrimaryRecoil: 3
PrimaryRecoilRecovery: 0.9
RenderUnitTurreted:
AutoTarget:
Explodes:
@@ -117,7 +119,9 @@ V2RL:
ROT: 5
AttackTurreted:
PrimaryWeapon: 105mm
Recoil: 3
PrimaryRecoil: 3
PrimaryRecoilRecovery: 0.9
PrimaryLocalOffset: 2,0,0,0,0, -2,0,0,0,0
RenderUnitTurreted:
AutoTarget:
Explodes:
@@ -155,7 +159,9 @@ V2RL:
SecondaryWeapon: MammothTusk
PrimaryLocalOffset: -4,-5,0,0,0, 4,-5,0,0,0
SecondaryLocalOffset: -7,2,0,0,25, 7,2,0,0,-25
Recoil: 4
PrimaryRecoil: 4
PrimaryRecoilRecovery: 0.7
SecondaryRecoil: 1
RenderUnitTurreted:
AutoTarget:
Explodes:
@@ -544,7 +550,7 @@ FTRK:
AttackTurreted:
PrimaryWeapon: FLAK-23
PrimaryOffset: 0,5,0,-4
Recoil: 2
PrimaryRecoil: 2
RenderUnitTurreted:
AutoTarget:
Explodes: