Remove RearmBuildings from Aircraft and Minelayer

In favor of using Rearmable trait.
This commit is contained in:
reaperrr
2018-09-27 17:50:35 +02:00
committed by Paul Chote
parent 2485029452
commit 8f1d8a67cc
19 changed files with 191 additions and 69 deletions

View File

@@ -21,17 +21,17 @@ namespace OpenRA.Mods.Common.Activities
readonly Target target;
readonly Aircraft aircraft;
readonly AttackPlane attackPlane;
readonly Rearmable rearmable;
readonly bool autoReloads;
int ticksUntilTurn;
public FlyAttack(Actor self, Target target)
{
this.target = target;
aircraft = self.Trait<Aircraft>();
attackPlane = self.TraitOrDefault<AttackPlane>();
attackPlane = self.Trait<AttackPlane>();
rearmable = self.TraitOrDefault<Rearmable>();
ticksUntilTurn = attackPlane.AttackPlaneInfo.AttackTurnDelay;
autoReloads = self.TraitsImplementing<AmmoPool>().All(p => p.AutoReloads);
}
public override Activity Tick(Actor self)
@@ -46,12 +46,11 @@ namespace OpenRA.Mods.Common.Activities
if (!target.IsValidFor(self))
return NextActivity;
// If all valid weapons have depleted their ammo and RearmBuilding is defined, return to RearmBuilding to reload and then resume the activity
if (!autoReloads && aircraft.Info.RearmBuildings.Any() && attackPlane.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
// If all valid weapons have depleted their ammo and Rearmable trait exists, return to RearmActor to reload and then resume the activity
if (rearmable != null && attackPlane.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
return ActivityUtils.SequenceActivities(new ReturnToBase(self, aircraft.Info.AbortOnResupply), this);
if (attackPlane != null)
attackPlane.DoAttack(self, target);
attackPlane.DoAttack(self, target);
if (ChildActivity == null)
{

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Activities
readonly Aircraft aircraft;
readonly AttackHeli attackHeli;
readonly bool attackOnlyVisibleTargets;
readonly bool autoReloads;
readonly Rearmable rearmable;
Target target;
bool canHideUnderFog;
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Activities
aircraft = self.Trait<Aircraft>();
attackHeli = self.Trait<AttackHeli>();
this.attackOnlyVisibleTargets = attackOnlyVisibleTargets;
autoReloads = self.TraitsImplementing<AmmoPool>().All(p => p.AutoReloads);
rearmable = self.TraitOrDefault<Rearmable>();
}
public override Activity Tick(Actor self)
@@ -74,8 +74,8 @@ namespace OpenRA.Mods.Common.Activities
return new HeliFly(self, newTarget);
}
// If all valid weapons have depleted their ammo and RearmBuilding is defined, return to RearmBuilding to reload and then resume the activity
if (!autoReloads && aircraft.Info.RearmBuildings.Any() && attackHeli.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
// If all valid weapons have depleted their ammo and Rearmable trait exists, return to RearmActor to reload and then resume the activity
if (rearmable != null && attackHeli.Armaments.All(x => x.IsTraitPaused || !x.Weapon.IsValidAgainst(target, self.World, self)))
return ActivityUtils.SequenceActivities(new HeliReturnToBase(self, aircraft.Info.AbortOnResupply), this);
var dist = targetPos - pos;

View File

@@ -20,6 +20,7 @@ namespace OpenRA.Mods.Common.Activities
{
readonly Aircraft aircraft;
readonly RepairableInfo repairableInfo;
readonly Rearmable rearmable;
readonly bool alwaysLand;
readonly bool abortOnResupply;
Actor dest;
@@ -28,6 +29,7 @@ namespace OpenRA.Mods.Common.Activities
{
aircraft = self.Trait<Aircraft>();
repairableInfo = self.Info.TraitInfoOrDefault<RepairableInfo>();
rearmable = self.TraitOrDefault<Rearmable>();
this.alwaysLand = alwaysLand;
this.abortOnResupply = abortOnResupply;
this.dest = dest;
@@ -35,9 +37,11 @@ namespace OpenRA.Mods.Common.Activities
public Actor ChooseResupplier(Actor self, bool unreservedOnly)
{
var rearmBuildings = aircraft.Info.RearmBuildings;
if (rearmable == null)
return null;
return self.World.Actors.Where(a => a.Owner == self.Owner
&& rearmBuildings.Contains(a.Info.Name)
&& rearmable.Info.RearmActors.Contains(a.Info.Name)
&& (!unreservedOnly || !Reservable.IsReserved(a)))
.ClosestTo(self);
}
@@ -119,8 +123,8 @@ namespace OpenRA.Mods.Common.Activities
if (repairableInfo != null && repairableInfo.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged)
return true;
return aircraft.Info.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing<AmmoPool>()
.Any(p => !p.AutoReloads && !p.FullAmmo());
return rearmable != null && rearmable.Info.RearmActors.Contains(dest.Info.Name)
&& rearmable.RearmableAmmoPools.Any(p => !p.FullAmmo());
}
}
}

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Mods.Common.Activities
readonly Aircraft aircraft;
readonly AircraftInfo aircraftInfo;
readonly RepairableInfo repairableInfo;
readonly Rearmable rearmable;
readonly bool alwaysLand;
readonly bool abortOnResupply;
bool isCalculated;
@@ -37,14 +38,18 @@ namespace OpenRA.Mods.Common.Activities
aircraft = self.Trait<Aircraft>();
aircraftInfo = self.Info.TraitInfo<AircraftInfo>();
repairableInfo = self.Info.TraitInfoOrDefault<RepairableInfo>();
rearmable = self.TraitOrDefault<Rearmable>();
}
public static Actor ChooseResupplier(Actor self, bool unreservedOnly)
{
var rearmBuildings = self.Info.TraitInfo<AircraftInfo>().RearmBuildings;
var rearmInfo = self.Info.TraitInfoOrDefault<RearmableInfo>();
if (rearmInfo == null)
return null;
return self.World.ActorsHavingTrait<Reservable>()
.Where(a => a.Owner == self.Owner
&& rearmBuildings.Contains(a.Info.Name)
&& rearmInfo.RearmActors.Contains(a.Info.Name)
&& (!unreservedOnly || !Reservable.IsReserved(a)))
.ClosestTo(self);
}
@@ -109,8 +114,8 @@ namespace OpenRA.Mods.Common.Activities
if (repairableInfo != null && repairableInfo.RepairBuildings.Contains(dest.Info.Name) && self.GetDamageState() != DamageState.Undamaged)
return true;
return aircraftInfo.RearmBuildings.Contains(dest.Info.Name) && self.TraitsImplementing<AmmoPool>()
.Any(p => !p.AutoReloads && !p.FullAmmo());
return rearmable != null && rearmable.Info.RearmActors.Contains(dest.Info.Name)
&& rearmable.RearmableAmmoPools.Any(p => !p.FullAmmo());
}
public override Activity Tick(Actor self)

View File

@@ -21,13 +21,13 @@ namespace OpenRA.Mods.Common.Activities
{
readonly Target host;
readonly WDist closeEnough;
readonly AmmoPool[] ammoPools;
readonly Rearmable rearmable;
public Rearm(Actor self, Actor host, WDist closeEnough)
{
this.host = Target.FromActor(host);
this.closeEnough = closeEnough;
ammoPools = self.TraitsImplementing<AmmoPool>().Where(p => !p.AutoReloads).ToArray();
rearmable = self.Trait<Rearmable>();
}
protected override void OnFirstRun(Actor self)
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Activities
// Reset the ReloadDelay to avoid any issues with early cancellation
// from previous reload attempts (explicit order, host building died, etc).
// HACK: this really shouldn't be managed from here
foreach (var pool in ammoPools)
foreach (var pool in rearmable.RearmableAmmoPools)
pool.RemainingTicks = pool.Info.ReloadDelay;
if (host.Type == TargetType.Invalid)
@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Activities
return NextActivity;
var complete = true;
foreach (var pool in ammoPools)
foreach (var pool in rearmable.RearmableAmmoPools)
{
if (!pool.FullAmmo())
{