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; public readonly string PrimaryWeapon = null;
[WeaponReference] [WeaponReference]
public readonly string SecondaryWeapon = null; 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[] PrimaryLocalOffset = { };
public readonly int[] SecondaryLocalOffset = { }; public readonly int[] SecondaryLocalOffset = { };
public readonly int[] PrimaryOffset = { 0, 0 }; public readonly int[] PrimaryOffset = { 0, 0 };
@@ -62,17 +65,17 @@ namespace OpenRA.Mods.RA
this.self = self; this.self = self;
var info = self.Info.Traits.Get<AttackBaseInfo>(); 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) if (info.SecondaryOffset != null)
Turrets.Add(new Turret(info.SecondaryOffset)); Turrets.Add(new Turret(info.SecondaryOffset, info.SecondaryRecoilRecovery));
if (info.PrimaryWeapon != null) if (info.PrimaryWeapon != null)
Weapons.Add(new Weapon(info.PrimaryWeapon, Weapons.Add(new Weapon(info.PrimaryWeapon,
Turrets[0], info.PrimaryLocalOffset)); Turrets[0], info.PrimaryLocalOffset, info.PrimaryRecoil));
if (info.SecondaryWeapon != null) if (info.SecondaryWeapon != null)
Weapons.Add(new Weapon(info.SecondaryWeapon, 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) 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) static float2 GetRecoil(Actor self, float recoil)
{ {
var abInfo = self.Info.Traits.GetOrDefault<AttackBaseInfo>(); if (!self.HasTrait<RenderUnitTurreted>())
if (abInfo == null || abInfo.Recoil == 0) return float2.Zero; return float2.Zero;
var rut = self.TraitOrDefault<RenderUnitTurreted>();
if (rut == null) return float2.Zero;
var facing = self.Trait<Turreted>().turretFacing; 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); return Util.RotateVectorByFacing(localRecoil, facing, .7f);
} }

View File

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

View File

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

View File

@@ -158,7 +158,10 @@ CA:
SecondaryOffset: 0,-17,0,-2 SecondaryOffset: 0,-17,0,-2
PrimaryLocalOffset: -4,-5,0,0,0, 4,-5,0,0,0 PrimaryLocalOffset: -4,-5,0,0,0, 4,-5,0,0,0
SecondaryLocalOffset: -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: Selectable:
Bounds: 44,44 Bounds: 44,44
RenderUnitTurreted: RenderUnitTurreted:

View File

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