Merge pull request #7834 from RoosterDragon/avoid-preventable-allocations
Avoid preventable allocations
This commit is contained in:
@@ -18,6 +18,8 @@ namespace OpenRA.Mods.Common.AI
|
||||
{
|
||||
abstract class AirStateBase : StateBase
|
||||
{
|
||||
static readonly string[] AirTargetTypes = new[] { "Air" };
|
||||
|
||||
protected const int MissileUnitMultiplier = 3;
|
||||
|
||||
protected static int CountAntiAirUnits(IEnumerable<Actor> units)
|
||||
@@ -34,7 +36,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
var arms = unit.TraitsImplementing<Armament>();
|
||||
foreach (var a in arms)
|
||||
{
|
||||
if (a.Weapon.ValidTargets.Contains("Air"))
|
||||
if (a.Weapon.IsValidTarget(AirTargetTypes))
|
||||
{
|
||||
missileUnitsCount++;
|
||||
break;
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
var arms = a.TraitsImplementing<Armament>();
|
||||
foreach (var arm in arms)
|
||||
if (arm.Weapon.ValidTargets.Intersect(targetable.TargetTypes).Any())
|
||||
if (arm.Weapon.IsValidTarget(targetable.TargetTypes))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
@@ -34,15 +34,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Sync]
|
||||
public int RepairersHash { get { return Repairers.Aggregate(0, (code, player) => code ^ Sync.HashPlayer(player)); } }
|
||||
public List<Player> Repairers = new List<Player>();
|
||||
public readonly List<Player> Repairers = new List<Player>();
|
||||
|
||||
readonly Health health;
|
||||
public bool RepairActive = false;
|
||||
|
||||
readonly Predicate<Player> isNotActiveAlly;
|
||||
|
||||
public RepairableBuilding(Actor self, RepairableBuildingInfo info)
|
||||
: base(info)
|
||||
{
|
||||
health = self.Trait<Health>();
|
||||
isNotActiveAlly = player => player.WinState != WinState.Undefined || player.Stances[self.Owner] != Stance.Ally;
|
||||
}
|
||||
|
||||
public void RepairBuilding(Actor self, Player player)
|
||||
@@ -81,8 +84,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
if (remainingTicks == 0)
|
||||
{
|
||||
Repairers = Repairers.Where(player => player.WinState == WinState.Undefined
|
||||
&& player.Stances[self.Owner] == Stance.Ally).ToList();
|
||||
Repairers.RemoveAll(isNotActiveAlly);
|
||||
|
||||
// If after the previous operation there's no repairers left, stop
|
||||
if (!Repairers.Any()) return;
|
||||
|
||||
Reference in New Issue
Block a user