AttackBase porting
This commit is contained in:
@@ -16,6 +16,7 @@ namespace OpenRa.Game.Traits
|
|||||||
public readonly int[] PrimaryOffset = { 0, 0 };
|
public readonly int[] PrimaryOffset = { 0, 0 };
|
||||||
public readonly int[] SecondaryOffset = null;
|
public readonly int[] SecondaryOffset = null;
|
||||||
public readonly bool MuzzleFlash = false;
|
public readonly bool MuzzleFlash = false;
|
||||||
|
public readonly int FireDelay = 0;
|
||||||
|
|
||||||
public virtual object Create(Actor self) { return new AttackBase(self); }
|
public virtual object Create(Actor self) { return new AttackBase(self); }
|
||||||
}
|
}
|
||||||
@@ -37,8 +38,10 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
public AttackBase(Actor self)
|
public AttackBase(Actor self)
|
||||||
{
|
{
|
||||||
var primaryWeapon = self.LegacyInfo.Primary != null ? Rules.WeaponInfo[self.LegacyInfo.Primary] : null;
|
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
|
||||||
var secondaryWeapon = self.LegacyInfo.Secondary != null ? Rules.WeaponInfo[self.LegacyInfo.Secondary] : null;
|
|
||||||
|
var primaryWeapon = info.PrimaryWeapon != null ? Rules.WeaponInfo[info.PrimaryWeapon] : null;
|
||||||
|
var secondaryWeapon = info.SecondaryWeapon != null ? Rules.WeaponInfo[info.SecondaryWeapon] : null;
|
||||||
|
|
||||||
primaryBurst = primaryWeapon != null ? primaryWeapon.Burst : 1;
|
primaryBurst = primaryWeapon != null ? primaryWeapon.Burst : 1;
|
||||||
secondaryBurst = secondaryWeapon != null ? secondaryWeapon.Burst : 1;
|
secondaryBurst = secondaryWeapon != null ? secondaryWeapon.Burst : 1;
|
||||||
@@ -87,19 +90,20 @@ namespace OpenRa.Game.Traits
|
|||||||
public void DoAttack(Actor self)
|
public void DoAttack(Actor self)
|
||||||
{
|
{
|
||||||
var unit = self.traits.GetOrDefault<Unit>();
|
var unit = self.traits.GetOrDefault<Unit>();
|
||||||
|
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
|
||||||
|
|
||||||
if (self.LegacyInfo.Primary != null && CheckFire(self, unit, self.LegacyInfo.Primary, ref primaryFireDelay,
|
if (info.PrimaryWeapon != null && CheckFire(self, unit, info.PrimaryWeapon, ref primaryFireDelay,
|
||||||
self.LegacyInfo.PrimaryOffset, ref primaryBurst, self.LegacyInfo.PrimaryLocalOffset))
|
info.PrimaryOffset, ref primaryBurst, info.PrimaryLocalOffset))
|
||||||
{
|
{
|
||||||
secondaryFireDelay = Math.Max(4, secondaryFireDelay);
|
secondaryFireDelay = Math.Max(4, secondaryFireDelay);
|
||||||
primaryRecoil = 1;
|
primaryRecoil = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.LegacyInfo.Secondary != null && CheckFire(self, unit, self.LegacyInfo.Secondary, ref secondaryFireDelay,
|
if (info.SecondaryWeapon != null && CheckFire(self, unit, info.SecondaryWeapon, ref secondaryFireDelay,
|
||||||
self.LegacyInfo.SecondaryOffset ?? self.LegacyInfo.PrimaryOffset, ref secondaryBurst, self.LegacyInfo.SecondaryLocalOffset))
|
info.SecondaryOffset ?? info.PrimaryOffset, ref secondaryBurst, info.SecondaryLocalOffset))
|
||||||
{
|
{
|
||||||
if (self.LegacyInfo.SecondaryOffset != null) secondaryRecoil = 1;
|
if (info.SecondaryOffset != null) secondaryRecoil = 1;
|
||||||
else primaryRecoil = 1;
|
else primaryRecoil = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -140,8 +144,9 @@ namespace OpenRa.Game.Traits
|
|||||||
var firePos = self.CenterLocation.ToInt2() + Util.GetTurretPosition(self, unit, fireOffset, 0f).ToInt2();
|
var firePos = self.CenterLocation.ToInt2() + Util.GetTurretPosition(self, unit, fireOffset, 0f).ToInt2();
|
||||||
var thisTarget = target; // closure.
|
var thisTarget = target; // closure.
|
||||||
var destUnit = thisTarget.traits.GetOrDefault<Unit>();
|
var destUnit = thisTarget.traits.GetOrDefault<Unit>();
|
||||||
|
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
|
||||||
|
|
||||||
ScheduleDelayedAction(self.LegacyInfo.FireDelay, () =>
|
ScheduleDelayedAction(info.FireDelay, () =>
|
||||||
{
|
{
|
||||||
var srcAltitude = unit != null ? unit.Altitude : 0;
|
var srcAltitude = unit != null ? unit.Altitude : 0;
|
||||||
var destAltitude = destUnit != null ? destUnit.Altitude : 0;
|
var destAltitude = destUnit != null ? destUnit.Altitude : 0;
|
||||||
@@ -175,10 +180,14 @@ namespace OpenRa.Game.Traits
|
|||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left || underCursor == null) return null;
|
if (mi.Button == MouseButton.Left || underCursor == null) return null;
|
||||||
if (self == underCursor) return null;
|
if (self == underCursor) return null;
|
||||||
var isHeal = Rules.WeaponInfo[self.LegacyInfo.Primary].Damage < 0;
|
|
||||||
|
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
|
||||||
|
var isHeal = Rules.WeaponInfo[info.PrimaryWeapon].Damage < 0;
|
||||||
if (((underCursor.Owner == self.Owner) ^ isHeal)
|
if (((underCursor.Owner == self.Owner) ^ isHeal)
|
||||||
&& !mi.Modifiers.HasModifier( Modifiers.Ctrl )) return null;
|
&& !mi.Modifiers.HasModifier( Modifiers.Ctrl )) return null;
|
||||||
|
|
||||||
if (!Combat.HasAnyValidWeapons(self, underCursor)) return null;
|
if (!Combat.HasAnyValidWeapons(self, underCursor)) return null;
|
||||||
|
|
||||||
return new Order(isHeal ? "Heal" : "Attack", self, underCursor, int2.Zero, null);
|
return new Order(isHeal ? "Heal" : "Attack", self, underCursor, int2.Zero, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,9 +207,10 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
protected virtual void QueueAttack(Actor self, Order order)
|
protected virtual void QueueAttack(Actor self, Order order)
|
||||||
{
|
{
|
||||||
|
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
|
||||||
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
|
const int RangeTolerance = 1; /* how far inside our maximum range we should try to sit */
|
||||||
/* todo: choose the appropriate weapon, when only one works against this target */
|
/* todo: choose the appropriate weapon, when only one works against this target */
|
||||||
var weapon = order.Subject.LegacyInfo.Primary ?? order.Subject.LegacyInfo.Secondary;
|
var weapon = info.PrimaryWeapon ?? info.SecondaryWeapon;
|
||||||
|
|
||||||
self.QueueActivity(new Activities.Attack(order.TargetActor,
|
self.QueueActivity(new Activities.Attack(order.TargetActor,
|
||||||
Math.Max(0, (int)Rules.WeaponInfo[weapon].Range - RangeTolerance)));
|
Math.Max(0, (int)Rules.WeaponInfo[weapon].Range - RangeTolerance)));
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ namespace RulesConverter
|
|||||||
{ "PrimaryLocalOffset", "PrimaryLocalOffset" },
|
{ "PrimaryLocalOffset", "PrimaryLocalOffset" },
|
||||||
{ "SecondaryLocalOffset", "SecondaryLocalOffset" },
|
{ "SecondaryLocalOffset", "SecondaryLocalOffset" },
|
||||||
{ "MuzzleFlash", "MuzzleFlash" }, // maybe
|
{ "MuzzleFlash", "MuzzleFlash" }, // maybe
|
||||||
{ "Recoil", "Recoil"} }
|
{ "Recoil", "Recoil"},
|
||||||
|
{ "FireDelay", "FireDelay" } }
|
||||||
},
|
},
|
||||||
|
|
||||||
{ "Production", new PL {
|
{ "Production", new PL {
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ MSUB:
|
|||||||
Speed: 5
|
Speed: 5
|
||||||
AttackBase:
|
AttackBase:
|
||||||
PrimaryWeapon: SubSCUD
|
PrimaryWeapon: SubSCUD
|
||||||
|
FireDelay: 2
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Submarine:
|
Submarine:
|
||||||
Chronoshiftable:
|
Chronoshiftable:
|
||||||
|
|||||||
4
ra.yaml
4
ra.yaml
@@ -458,6 +458,7 @@ SS:
|
|||||||
Submarine:
|
Submarine:
|
||||||
AttackBase:
|
AttackBase:
|
||||||
PrimaryWeapon: TorpTube
|
PrimaryWeapon: TorpTube
|
||||||
|
FireDelay: 2
|
||||||
Chronoshiftable:
|
Chronoshiftable:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
|
|
||||||
@@ -840,6 +841,7 @@ TSLA:
|
|||||||
RenderBuildingCharge:
|
RenderBuildingCharge:
|
||||||
AttackTurreted:
|
AttackTurreted:
|
||||||
PrimaryWeapon: TeslaZap
|
PrimaryWeapon: TeslaZap
|
||||||
|
FireDelay: 8
|
||||||
AutoTarget:
|
AutoTarget:
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
|
|
||||||
@@ -2284,6 +2286,7 @@ E2:
|
|||||||
AttackBase:
|
AttackBase:
|
||||||
PrimaryWeapon: Grenade
|
PrimaryWeapon: Grenade
|
||||||
PrimaryOffset: 0,0,0,-13
|
PrimaryOffset: 0,0,0,-13
|
||||||
|
FireDelay: 15
|
||||||
TakeCover:
|
TakeCover:
|
||||||
SquishByTank:
|
SquishByTank:
|
||||||
AutoTarget:
|
AutoTarget:
|
||||||
@@ -2337,6 +2340,7 @@ E4:
|
|||||||
AttackBase:
|
AttackBase:
|
||||||
PrimaryWeapon: Flamer
|
PrimaryWeapon: Flamer
|
||||||
PrimaryOffset: 0,0,0,-7
|
PrimaryOffset: 0,0,0,-7
|
||||||
|
FireDelay: 8
|
||||||
TakeCover:
|
TakeCover:
|
||||||
SquishByTank:
|
SquishByTank:
|
||||||
AutoTarget:
|
AutoTarget:
|
||||||
|
|||||||
Reference in New Issue
Block a user