Change ActorIndex to work in terms of TraitInfo, instead of Trait.
This allows actor.Info.HasTraitInfo to be used when checking if an actor needs to be added to the index, which is a cheaper call than actor.TraitsImplementing.
This commit is contained in:
@@ -173,10 +173,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly BaseBuilderQueueManager[] builders;
|
||||
int currentBuilderIndex = 0;
|
||||
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<Building> refineryBuildings;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<Building> powerBuildings;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<Building> constructionYardBuildings;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<Building> barracksBuildings;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<BuildingInfo> refineryBuildings;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<BuildingInfo> powerBuildings;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<BuildingInfo> constructionYardBuildings;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<BuildingInfo> barracksBuildings;
|
||||
|
||||
public BaseBuilderBotModule(Actor self, BaseBuilderBotModuleInfo info)
|
||||
: base(info)
|
||||
@@ -184,10 +184,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
world = self.World;
|
||||
player = self.Owner;
|
||||
builders = new BaseBuilderQueueManager[info.BuildingQueues.Count + info.DefenseQueues.Count];
|
||||
refineryBuildings = new ActorIndex.OwnerAndNamesAndTrait<Building>(world, info.RefineryTypes, player);
|
||||
powerBuildings = new ActorIndex.OwnerAndNamesAndTrait<Building>(world, info.PowerTypes, player);
|
||||
constructionYardBuildings = new ActorIndex.OwnerAndNamesAndTrait<Building>(world, info.ConstructionYardTypes, player);
|
||||
barracksBuildings = new ActorIndex.OwnerAndNamesAndTrait<Building>(world, info.BarracksTypes, player);
|
||||
refineryBuildings = new ActorIndex.OwnerAndNamesAndTrait<BuildingInfo>(world, info.RefineryTypes, player);
|
||||
powerBuildings = new ActorIndex.OwnerAndNamesAndTrait<BuildingInfo>(world, info.PowerTypes, player);
|
||||
constructionYardBuildings = new ActorIndex.OwnerAndNamesAndTrait<BuildingInfo>(world, info.ConstructionYardTypes, player);
|
||||
barracksBuildings = new ActorIndex.OwnerAndNamesAndTrait<BuildingInfo>(world, info.BarracksTypes, player);
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Units that the bot already knows about and has given a capture order. Any unit not on this list needs to be given a new order.
|
||||
readonly List<Actor> activeCapturers = new();
|
||||
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<Captures> capturingActors;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<CapturesInfo> capturingActors;
|
||||
|
||||
public CaptureManagerBotModule(Actor self, CaptureManagerBotModuleInfo info)
|
||||
: base(info)
|
||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
maximumCaptureTargetOptions = Math.Max(1, Info.MaximumCaptureTargetOptions);
|
||||
|
||||
capturingActors = new ActorIndex.OwnerAndNamesAndTrait<Captures>(world, Info.CapturingActorTypes, player);
|
||||
capturingActors = new ActorIndex.OwnerAndNamesAndTrait<CapturesInfo>(world, Info.CapturingActorTypes, player);
|
||||
}
|
||||
|
||||
protected override void TraitEnabled(Actor self)
|
||||
|
||||
@@ -70,8 +70,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
readonly Func<Actor, bool> unitCannotBeOrdered;
|
||||
readonly Dictionary<Actor, HarvesterTraitWrapper> harvesters = new();
|
||||
readonly Stack<HarvesterTraitWrapper> harvestersNeedingOrders = new();
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<Building> refineries;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<Harvester> harvestersIndex;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<BuildingInfo> refineries;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<HarvesterInfo> harvestersIndex;
|
||||
readonly Dictionary<CPos, string> resourceTypesByCell = new();
|
||||
|
||||
IResourceLayer resourceLayer;
|
||||
@@ -85,8 +85,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
world = self.World;
|
||||
player = self.Owner;
|
||||
unitCannotBeOrdered = a => a.Owner != self.Owner || a.IsDead || !a.IsInWorld;
|
||||
refineries = new ActorIndex.OwnerAndNamesAndTrait<Building>(world, info.RefineryTypes, player);
|
||||
harvestersIndex = new ActorIndex.OwnerAndNamesAndTrait<Harvester>(world, info.HarvesterTypes, player);
|
||||
refineries = new ActorIndex.OwnerAndNamesAndTrait<BuildingInfo>(world, info.RefineryTypes, player);
|
||||
harvestersIndex = new ActorIndex.OwnerAndNamesAndTrait<HarvesterInfo>(world, info.HarvesterTypes, player);
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
|
||||
@@ -60,9 +60,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
readonly World world;
|
||||
readonly Player player;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<Transforms> mcvs;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<Building> constructionYards;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<Building> mcvFactories;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<TransformsInfo> mcvs;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<BuildingInfo> constructionYards;
|
||||
readonly ActorIndex.OwnerAndNamesAndTrait<BuildingInfo> mcvFactories;
|
||||
|
||||
IBotPositionsUpdated[] notifyPositionsUpdated;
|
||||
IBotRequestUnitProduction[] requestUnitProduction;
|
||||
@@ -76,9 +76,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
world = self.World;
|
||||
player = self.Owner;
|
||||
mcvs = new ActorIndex.OwnerAndNamesAndTrait<Transforms>(world, info.McvTypes, player);
|
||||
constructionYards = new ActorIndex.OwnerAndNamesAndTrait<Building>(world, info.ConstructionYardTypes, player);
|
||||
mcvFactories = new ActorIndex.OwnerAndNamesAndTrait<Building>(world, info.McvFactoryTypes, player);
|
||||
mcvs = new ActorIndex.OwnerAndNamesAndTrait<TransformsInfo>(world, info.McvTypes, player);
|
||||
constructionYards = new ActorIndex.OwnerAndNamesAndTrait<BuildingInfo>(world, info.ConstructionYardTypes, player);
|
||||
mcvFactories = new ActorIndex.OwnerAndNamesAndTrait<BuildingInfo>(world, info.McvFactoryTypes, player);
|
||||
}
|
||||
|
||||
protected override void Created(Actor self)
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public List<Squad> Squads = new();
|
||||
readonly Stack<Squad> squadsPendingUpdate = new();
|
||||
readonly ActorIndex.NamesAndTrait<Building> constructionYardBuildings;
|
||||
readonly ActorIndex.NamesAndTrait<BuildingInfo> constructionYardBuildings;
|
||||
|
||||
IBot bot;
|
||||
IBotPositionsUpdated[] notifyPositionsUpdated;
|
||||
@@ -146,7 +146,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Player = self.Owner;
|
||||
|
||||
unitCannotBeOrdered = a => a == null || a.Owner != Player || a.IsDead || !a.IsInWorld;
|
||||
constructionYardBuildings = new ActorIndex.NamesAndTrait<Building>(World, info.ConstructionYardTypes);
|
||||
constructionYardBuildings = new ActorIndex.NamesAndTrait<BuildingInfo>(World, info.ConstructionYardTypes);
|
||||
}
|
||||
|
||||
// Use for proactive targeting.
|
||||
|
||||
Reference in New Issue
Block a user