Add ActorInfo.TraitInfo[OrDefault]<T>() requiring ITraitIfo types
This commit is contained in:
@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
// Find a production structure to build this actor
|
||||
var ai = self.World.Map.Rules.Actors[name];
|
||||
var bi = ai.Traits.GetOrDefault<BuildableInfo>();
|
||||
var bi = ai.TraitInfoOrDefault<BuildableInfo>();
|
||||
|
||||
// Some units may request a specific production type, which is ignored if the AllTech cheat is enabled
|
||||
var type = bi == null || developerMode.AllTech ? Info.Type : bi.BuildAtProductionType ?? Info.Type;
|
||||
@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public override int GetBuildTime(string unitString)
|
||||
{
|
||||
var ai = self.World.Map.Rules.Actors[unitString];
|
||||
var bi = ai.Traits.GetOrDefault<BuildableInfo>();
|
||||
var bi = ai.TraitInfoOrDefault<BuildableInfo>();
|
||||
if (bi == null)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<IRenderable> Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
|
||||
{
|
||||
if (!ai.Traits.Get<BuildingInfo>().RequiresBaseProvider)
|
||||
if (!ai.TraitInfo<BuildingInfo>().RequiresBaseProvider)
|
||||
yield break;
|
||||
|
||||
foreach (var a in w.ActorsWithTrait<BaseProvider>())
|
||||
@@ -75,9 +75,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var producer = queue.MostLikelyProducer();
|
||||
var faction = producer.Trait != null ? producer.Trait.Faction : self.Owner.Faction.InternalName;
|
||||
var buildingInfo = unit.Traits.Get<BuildingInfo>();
|
||||
var buildingInfo = unit.TraitInfo<BuildingInfo>();
|
||||
|
||||
var buildableInfo = unit.Traits.GetOrDefault<BuildableInfo>();
|
||||
var buildableInfo = unit.TraitInfoOrDefault<BuildableInfo>();
|
||||
if (buildableInfo != null && buildableInfo.ForceFaction != null)
|
||||
faction = buildableInfo.ForceFaction;
|
||||
|
||||
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (host == null)
|
||||
return;
|
||||
|
||||
var plugInfo = unit.Traits.GetOrDefault<PlugInfo>();
|
||||
var plugInfo = unit.TraitInfoOrDefault<PlugInfo>();
|
||||
if (plugInfo == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
if (self.Info.HasTraitInfo<ValuedInfo>())
|
||||
{
|
||||
var cost = self.Info.Traits.Get<ValuedInfo>().Cost;
|
||||
var cost = self.Info.TraitInfo<ValuedInfo>().Cost;
|
||||
attackerStats.KillsCost += cost;
|
||||
defenderStats.DeathsCost += cost;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var a in AllBuildables(Info.Type))
|
||||
{
|
||||
var bi = a.Traits.Get<BuildableInfo>();
|
||||
var bi = a.TraitInfo<BuildableInfo>();
|
||||
|
||||
produceable.Add(a, new ProductionState());
|
||||
ttc.Add(a.Name, bi.Prerequisites, bi.BuildLimit, this);
|
||||
@@ -168,7 +168,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.Where(x =>
|
||||
x.Name[0] != '^' &&
|
||||
x.HasTraitInfo<BuildableInfo>() &&
|
||||
x.Traits.Get<BuildableInfo>().Queue.Contains(category));
|
||||
x.TraitInfo<BuildableInfo>().Queue.Contains(category));
|
||||
}
|
||||
|
||||
public void PrerequisitesAvailable(string key)
|
||||
@@ -250,11 +250,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
case "StartProduction":
|
||||
{
|
||||
var unit = self.World.Map.Rules.Actors[order.TargetString];
|
||||
var bi = unit.Traits.Get<BuildableInfo>();
|
||||
var bi = unit.TraitInfo<BuildableInfo>();
|
||||
if (!bi.Queue.Contains(Info.Type))
|
||||
return; /* Not built by this queue */
|
||||
|
||||
var cost = unit.HasTraitInfo<ValuedInfo>() ? unit.Traits.Get<ValuedInfo>().Cost : 0;
|
||||
var cost = unit.HasTraitInfo<ValuedInfo>() ? unit.TraitInfo<ValuedInfo>().Cost : 0;
|
||||
var time = GetBuildTime(order.TargetString);
|
||||
|
||||
if (BuildableItems().All(b => b.Name != order.TargetString))
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void ActorChanged(Actor a)
|
||||
{
|
||||
var bi = a.Info.Traits.GetOrDefault<BuildableInfo>();
|
||||
var bi = a.Info.TraitInfoOrDefault<BuildableInfo>();
|
||||
if (a.Owner == player && (a.Info.HasTraitInfo<ITechTreePrerequisiteInfo>() || (bi != null && bi.BuildLimit > 0)))
|
||||
Update();
|
||||
}
|
||||
@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
a.Actor.IsInWorld &&
|
||||
!a.Actor.IsDead &&
|
||||
!ret.ContainsKey(a.Actor.Info.Name) &&
|
||||
a.Actor.Info.Traits.Get<BuildableInfo>().BuildLimit > 0)
|
||||
a.Actor.Info.TraitInfo<BuildableInfo>().BuildLimit > 0)
|
||||
.Do(b => ret[b.Actor.Info.Name].Add(b.Actor));
|
||||
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user