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

@@ -443,22 +443,22 @@ namespace OpenRA.Mods.Common.AI
CountBuildingByCommonName(Info.BuildingCommonNames.Barracks, Player) == 0;
}
// For mods like RA (number of building must match the number of aircraft)
// For mods like RA (number of RearmActors must match the number of aircraft)
bool HasAdequateAirUnitReloadBuildings(ActorInfo actorInfo)
{
var aircraftInfo = actorInfo.TraitInfoOrDefault<AircraftInfo>();
if (aircraftInfo == null)
return true;
// If the aircraft has at least 1 AmmoPool and defines 1 or more RearmBuildings, check if we have enough of those
var hasAmmoPool = actorInfo.TraitInfos<AmmoPoolInfo>().Any();
if (hasAmmoPool && aircraftInfo.RearmBuildings.Count > 0)
{
var countOwnAir = CountActorsWithTrait<IPositionable>(actorInfo.Name, Player);
var countBuildings = aircraftInfo.RearmBuildings.Sum(b => CountActorsWithTrait<Building>(b, Player));
if (countOwnAir >= countBuildings)
return false;
}
// If actor isn't Rearmable, it doesn't need a RearmActor to reload
var rearmableInfo = actorInfo.TraitInfoOrDefault<RearmableInfo>();
if (rearmableInfo == null)
return true;
var countOwnAir = CountActorsWithTrait<IPositionable>(actorInfo.Name, Player);
var countBuildings = rearmableInfo.RearmActors.Sum(b => CountActorsWithTrait<Building>(b, Player));
if (countOwnAir >= countBuildings)
return false;
return true;
}

View File

@@ -127,7 +127,11 @@ namespace OpenRA.Mods.Common.AI
protected static bool ReloadsAutomatically(Actor a)
{
var ammoPools = a.TraitsImplementing<AmmoPool>();
return ammoPools.All(x => x.AutoReloads);
var rearmable = a.TraitOrDefault<Rearmable>();
if (rearmable == null)
return true;
return ammoPools.All(ap => !rearmable.Info.AmmoPools.Contains(ap.Info.Name));
}
protected static bool IsRearm(Actor a)