Add ActorInfo.TraitInfo[OrDefault]<T>() requiring ITraitIfo types
This commit is contained in:
@@ -103,7 +103,7 @@ namespace OpenRA
|
||||
|
||||
bounds = Exts.Lazy(() =>
|
||||
{
|
||||
var si = Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
var si = Info.TraitInfoOrDefault<SelectableInfo>();
|
||||
var size = (si != null && si.Bounds != null) ? new int2(si.Bounds[0], si.Bounds[1]) :
|
||||
TraitsImplementing<IAutoSelectionSize>().Select(x => x.SelectionSize(this)).FirstOrDefault();
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace OpenRA
|
||||
|
||||
visualBounds = Exts.Lazy(() =>
|
||||
{
|
||||
var sd = Info.Traits.GetOrDefault<ISelectionDecorationsInfo>();
|
||||
var sd = Info.TraitInfoOrDefault<ISelectionDecorationsInfo>();
|
||||
if (sd == null || sd.SelectionBoxBounds == null)
|
||||
return bounds.Value;
|
||||
|
||||
|
||||
@@ -185,5 +185,7 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
public bool HasTraitInfo<T>() where T : ITraitInfo { return Traits.Contains<T>(); }
|
||||
public T TraitInfo<T>() where T : ITraitInfo { return Traits.Get<T>(); }
|
||||
public T TraitInfoOrDefault<T>() where T : ITraitInfo { return Traits.GetOrDefault<T>(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public static int SelectionPriority(this ActorInfo a)
|
||||
{
|
||||
var selectableInfo = a.Traits.GetOrDefault<SelectableInfo>();
|
||||
var selectableInfo = a.TraitInfoOrDefault<SelectableInfo>();
|
||||
return selectableInfo != null ? selectableInfo.Priority : int.MinValue;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public static int SelectionPriority(this Actor a)
|
||||
{
|
||||
var basePriority = a.Info.Traits.Get<SelectableInfo>().Priority;
|
||||
var basePriority = a.Info.TraitInfo<SelectableInfo>().Priority;
|
||||
var lp = a.World.LocalPlayer;
|
||||
|
||||
if (a.Owner == lp || lp == null)
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace OpenRA
|
||||
if (actor.Owner != world.LocalPlayer || !actor.IsInWorld)
|
||||
continue;
|
||||
|
||||
var selectable = actor.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
var selectable = actor.Info.TraitInfoOrDefault<SelectableInfo>();
|
||||
if (selectable == null || !actor.HasVoice(selectable.Voice))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public interface ISeedableResource { void Seed(Actor self); }
|
||||
|
||||
public interface ISelectionDecorationsInfo
|
||||
public interface ISelectionDecorationsInfo : ITraitInfo
|
||||
{
|
||||
int[] SelectionBoxBounds { get; }
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
if (!self.IsInWorld || self.IsDead)
|
||||
return;
|
||||
|
||||
var altitude = self.World.Map.Rules.Actors[actorType].Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||
var altitude = self.World.Map.Rules.Actors[actorType].TraitInfo<PlaneInfo>().CruiseAltitude;
|
||||
var actor = w.CreateActor(actorType, new TypeDictionary
|
||||
{
|
||||
new CenterPositionInit(w.Map.CenterOfCell(startPos) + new WVec(WDist.Zero, WDist.Zero, altitude)),
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
protected float RelativeSpeed(IEnumerable<Actor> own, IEnumerable<Actor> enemy)
|
||||
{
|
||||
return RelativeValue(own, enemy, 100, Average<MobileInfo>, (Actor a) => a.Info.Traits.Get<MobileInfo>().Speed);
|
||||
return RelativeValue(own, enemy, 100, Average<MobileInfo>, (Actor a) => a.Info.TraitInfo<MobileInfo>().Speed);
|
||||
}
|
||||
|
||||
protected static float RelativeValue(IEnumerable<Actor> own, IEnumerable<Actor> enemy, float normalizeByValue,
|
||||
|
||||
@@ -433,7 +433,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
// For mods like RA (number of building must match the number of aircraft)
|
||||
bool HasAdequateAirUnitReloadBuildings(ActorInfo actorInfo)
|
||||
{
|
||||
var aircraftInfo = actorInfo.Traits.GetOrDefault<AircraftInfo>();
|
||||
var aircraftInfo = actorInfo.TraitInfoOrDefault<AircraftInfo>();
|
||||
if (aircraftInfo == null)
|
||||
return true;
|
||||
|
||||
@@ -453,7 +453,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
CPos defenseCenter;
|
||||
public CPos? ChooseBuildLocation(string actorType, bool distanceToBaseIsImportant, BuildingType type)
|
||||
{
|
||||
var bi = Map.Rules.Actors[actorType].Traits.GetOrDefault<BuildingInfo>();
|
||||
var bi = Map.Rules.Actors[actorType].TraitInfoOrDefault<BuildingInfo>();
|
||||
if (bi == null)
|
||||
return null;
|
||||
|
||||
@@ -657,8 +657,8 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
CPos FindNextResource(Actor self)
|
||||
{
|
||||
var harvInfo = self.Info.Traits.Get<HarvesterInfo>();
|
||||
var mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||
var harvInfo = self.Info.TraitInfo<HarvesterInfo>();
|
||||
var mobileInfo = self.Info.TraitInfo<MobileInfo>();
|
||||
var passable = (uint)mobileInfo.GetMovementClass(World.TileSet);
|
||||
|
||||
var path = pathfinder.FindPath(
|
||||
@@ -807,7 +807,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
{
|
||||
var buildings = self.World.ActorsWithTrait<RallyPoint>()
|
||||
.Where(rp => rp.Actor.Owner == Player &&
|
||||
!IsRallyPointValid(rp.Trait.Location, rp.Actor.Info.Traits.GetOrDefault<BuildingInfo>())).ToArray();
|
||||
!IsRallyPointValid(rp.Trait.Location, rp.Actor.Info.TraitInfoOrDefault<BuildingInfo>())).ToArray();
|
||||
|
||||
foreach (var a in buildings)
|
||||
QueueOrder(new Order("SetRallyPoint", a.Actor, false) { TargetLocation = ChooseRallyLocationNear(a.Actor), SuppressVisualFeedback = true });
|
||||
@@ -817,7 +817,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
CPos ChooseRallyLocationNear(Actor producer)
|
||||
{
|
||||
var possibleRallyPoints = Map.FindTilesInCircle(producer.Location, Info.RallyPointScanRadius)
|
||||
.Where(c => IsRallyPointValid(c, producer.Info.Traits.GetOrDefault<BuildingInfo>()));
|
||||
.Where(c => IsRallyPointValid(c, producer.Info.TraitInfoOrDefault<BuildingInfo>()));
|
||||
|
||||
if (!possibleRallyPoints.Any())
|
||||
{
|
||||
@@ -863,7 +863,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
if (mcv.IsMoving())
|
||||
continue;
|
||||
|
||||
var factType = mcv.Info.Traits.Get<TransformsInfo>().IntoActor;
|
||||
var factType = mcv.Info.TraitInfo<TransformsInfo>().IntoActor;
|
||||
var desiredLocation = ChooseBuildLocation(factType, false, BuildingType.Building);
|
||||
if (desiredLocation == null)
|
||||
continue;
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.AI
|
||||
switch (TargetMetric)
|
||||
{
|
||||
case DecisionMetric.Value:
|
||||
var valueInfo = a.Info.Traits.GetOrDefault<ValuedInfo>();
|
||||
var valueInfo = a.Info.TraitInfoOrDefault<ValuedInfo>();
|
||||
return (valueInfo != null) ? valueInfo.Cost * Attractiveness : 0;
|
||||
|
||||
case DecisionMetric.Health:
|
||||
|
||||
@@ -28,12 +28,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
this.dest = dest;
|
||||
plane = self.Trait<Plane>();
|
||||
planeInfo = self.Info.Traits.Get<PlaneInfo>();
|
||||
planeInfo = self.Info.TraitInfo<PlaneInfo>();
|
||||
}
|
||||
|
||||
public static Actor ChooseAirfield(Actor self, bool unreservedOnly)
|
||||
{
|
||||
var rearmBuildings = self.Info.Traits.Get<PlaneInfo>().RearmBuildings;
|
||||
var rearmBuildings = self.Info.TraitInfo<PlaneInfo>().RearmBuildings;
|
||||
return self.World.ActorsWithTrait<Reservable>()
|
||||
.Where(a => a.Actor.Owner == self.Owner)
|
||||
.Where(a => rearmBuildings.Contains(a.Actor.Info.Name)
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
actor = target;
|
||||
building = actor.TraitOrDefault<Building>();
|
||||
capturesInfo = self.Info.Traits.Get<CapturesInfo>();
|
||||
capturesInfo = self.Info.TraitInfo<CapturesInfo>();
|
||||
capturable = target.Trait<Capturable>();
|
||||
health = actor.Trait<Health>();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
{
|
||||
this.target = target;
|
||||
capturable = target.Actor.Trait<ExternalCapturable>();
|
||||
capturesInfo = self.Info.Traits.Get<ExternalCapturesInfo>();
|
||||
capturesInfo = self.Info.TraitInfo<ExternalCapturesInfo>();
|
||||
mobile = self.Trait<Mobile>();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public FindResources(Actor self)
|
||||
{
|
||||
harv = self.Trait<Harvester>();
|
||||
harvInfo = self.Info.Traits.Get<HarvesterInfo>();
|
||||
harvInfo = self.Info.TraitInfo<HarvesterInfo>();
|
||||
mobile = self.Trait<Mobile>();
|
||||
mobileInfo = self.Info.Traits.Get<MobileInfo>();
|
||||
mobileInfo = self.Info.TraitInfo<MobileInfo>();
|
||||
resLayer = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
|
||||
pathFinder = self.World.WorldActor.Trait<IPathFinder>();
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public HarvestResource(Actor self)
|
||||
{
|
||||
harv = self.Trait<Harvester>();
|
||||
harvInfo = self.Info.Traits.Get<HarvesterInfo>();
|
||||
harvInfo = self.Info.TraitInfo<HarvesterInfo>();
|
||||
facing = self.Trait<IFacing>();
|
||||
territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>();
|
||||
resLayer = self.World.WorldActor.Trait<ResourceLayer>();
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
pos = self.TraitOrDefault<IPositionable>();
|
||||
|
||||
// Parachutable trait is a prerequisite for running this activity
|
||||
para = self.Info.Traits.Get<ParachutableInfo>();
|
||||
para = self.Info.TraitInfo<ParachutableInfo>();
|
||||
fallVector = new WVec(0, 0, para.FallRate);
|
||||
this.dropPosition = dropPosition;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Repair(Actor host)
|
||||
{
|
||||
this.host = host;
|
||||
repairsUnits = host.Info.Traits.Get<RepairsUnitsInfo>();
|
||||
repairsUnits = host.Info.TraitInfo<RepairsUnitsInfo>();
|
||||
}
|
||||
|
||||
public override Activity Tick(Actor self)
|
||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
if (remainingTicks == 0)
|
||||
{
|
||||
var unitCost = self.Info.Traits.Get<ValuedInfo>().Cost;
|
||||
var unitCost = self.Info.TraitInfo<ValuedInfo>().Cost;
|
||||
var hpToRepair = repairsUnits.HpPerStep;
|
||||
var cost = Math.Max(1, (hpToRepair * unitCost * repairsUnits.ValuePercentage) / (health.MaxHP * 100));
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
public Sell(Actor self)
|
||||
{
|
||||
health = self.TraitOrDefault<Health>();
|
||||
sellableInfo = self.Info.Traits.Get<SellableInfo>();
|
||||
sellableInfo = self.Info.TraitInfo<SellableInfo>();
|
||||
playerResources = self.Owner.PlayerActor.Trait<PlayerResources>();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Activities
|
||||
: base(self, refinery, dockAngle, isDragRequired, dragOffset, dragLength)
|
||||
{
|
||||
wsb = self.Trait<WithSpriteBody>();
|
||||
wda = self.Info.Traits.Get<WithDockingAnimationInfo>();
|
||||
wda = self.Info.TraitInfo<WithDockingAnimationInfo>();
|
||||
}
|
||||
|
||||
public override Activity OnStateDock(Actor self)
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
preview.GetScale = () => worldRenderer.Viewport.Zoom;
|
||||
preview.IsVisible = () => editorWidget.CurrentBrush == this;
|
||||
|
||||
var buildingInfo = actor.Traits.GetOrDefault<BuildingInfo>();
|
||||
var buildingInfo = actor.TraitInfoOrDefault<BuildingInfo>();
|
||||
if (buildingInfo != null)
|
||||
{
|
||||
locationOffset = -FootprintUtils.AdjustForBuildingSize(buildingInfo);
|
||||
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
td.Add(new FactionInit(owner.Faction));
|
||||
preview.SetPreview(actor, td);
|
||||
|
||||
var ios = actor.Traits.GetOrDefault<IOccupySpaceInfo>();
|
||||
var ios = actor.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||
if (ios != null)
|
||||
footprint = ios.OccupiedCells(actor, CPos.Zero)
|
||||
.Select(c => c.Key - CPos.Zero)
|
||||
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
cell += locationOffset;
|
||||
newActorReference.Add(new LocationInit(cell));
|
||||
|
||||
var ios = Actor.Traits.GetOrDefault<IOccupySpaceInfo>();
|
||||
var ios = Actor.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||
if (ios != null && ios.SharesCell)
|
||||
{
|
||||
var subcell = editorLayer.FreeSubCellAt(cell);
|
||||
|
||||
@@ -33,10 +33,10 @@ namespace OpenRA.Mods.Common.Lint
|
||||
emitError("Actor type `{0}` defines multiple default visibility types!".F(actorInfo.Key));
|
||||
else
|
||||
{
|
||||
var vis = actorInfo.Value.Traits.GetOrDefault<HiddenUnderShroudInfo>();
|
||||
var vis = actorInfo.Value.TraitInfoOrDefault<HiddenUnderShroudInfo>();
|
||||
if (vis != null && vis.Type == VisibilityType.Footprint)
|
||||
{
|
||||
var ios = actorInfo.Value.Traits.GetOrDefault<IOccupySpaceInfo>();
|
||||
var ios = actorInfo.Value.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||
if (ios == null)
|
||||
emitError("Actor type `{0}` defines VisibilityType.Footprint in `{1}` but has no IOccupySpace traits!".F(actorInfo.Key, vis.GetType()));
|
||||
else if (!ios.OccupiedCells(actorInfo.Value, CPos.Zero).Any())
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
if (actorInfo.Key.StartsWith("^"))
|
||||
continue;
|
||||
|
||||
var ios = actorInfo.Value.Traits.GetOrDefault<IOccupySpaceInfo>();
|
||||
var ios = actorInfo.Value.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||
foreach (var rsi in actorInfo.Value.Traits.WithInterface<RevealsShroudInfo>())
|
||||
{
|
||||
if (rsi.Type == VisibilityType.CenterPosition)
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Lint
|
||||
// TODO: this check is case insensitive while the real check in-game is not
|
||||
foreach (var i in rules.Actors)
|
||||
{
|
||||
var bi = i.Value.Traits.GetOrDefault<BuildableInfo>();
|
||||
var bi = i.Value.TraitInfoOrDefault<BuildableInfo>();
|
||||
if (bi != null)
|
||||
foreach (var prereq in bi.Prerequisites)
|
||||
if (!prereq.StartsWith("~disabled"))
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
public PlaceBuildingOrderGenerator(ProductionQueue queue, string name)
|
||||
{
|
||||
producer = queue.Actor;
|
||||
placeBuildingInfo = producer.Owner.PlayerActor.Info.Traits.Get<PlaceBuildingInfo>();
|
||||
placeBuildingInfo = producer.Owner.PlayerActor.Info.TraitInfo<PlaceBuildingInfo>();
|
||||
building = name;
|
||||
|
||||
// Clear selection if using Left-Click Orders
|
||||
@@ -46,9 +46,9 @@ namespace OpenRA.Mods.Common.Orders
|
||||
var tileset = producer.World.TileSet.Id.ToLowerInvariant();
|
||||
|
||||
var info = map.Rules.Actors[building];
|
||||
buildingInfo = info.Traits.Get<BuildingInfo>();
|
||||
buildingInfo = info.TraitInfo<BuildingInfo>();
|
||||
|
||||
var buildableInfo = info.Traits.Get<BuildableInfo>();
|
||||
var buildableInfo = info.TraitInfo<BuildableInfo>();
|
||||
var mostLikelyProducer = queue.MostLikelyProducer();
|
||||
faction = buildableInfo.ForceFaction
|
||||
?? (mostLikelyProducer.Trait != null ? mostLikelyProducer.Trait.Faction : producer.Owner.Faction.InternalName);
|
||||
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
var orderType = "PlaceBuilding";
|
||||
var topLeft = xy - FootprintUtils.AdjustForBuildingSize(buildingInfo);
|
||||
|
||||
var plugInfo = world.Map.Rules.Actors[building].Traits.GetOrDefault<PlugInfo>();
|
||||
var plugInfo = world.Map.Rules.Actors[building].TraitInfoOrDefault<PlugInfo>();
|
||||
if (plugInfo != null)
|
||||
{
|
||||
orderType = "PlacePlug";
|
||||
@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common.Orders
|
||||
|
||||
var cells = new Dictionary<CPos, bool>();
|
||||
|
||||
var plugInfo = rules.Actors[building].Traits.GetOrDefault<PlugInfo>();
|
||||
var plugInfo = rules.Actors[building].TraitInfoOrDefault<PlugInfo>();
|
||||
if (plugInfo != null)
|
||||
{
|
||||
if (buildingInfo.Dimensions.X != 1 || buildingInfo.Dimensions.Y != 1)
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
if (!Context.World.Map.Rules.Actors.TryGetValue(type, out ai))
|
||||
throw new LuaException("Unknown actor type '{0}'".F(type));
|
||||
|
||||
var pi = ai.Traits.GetOrDefault<ICruiseAltitudeInfo>();
|
||||
var pi = ai.TraitInfoOrDefault<ICruiseAltitudeInfo>();
|
||||
return pi != null ? pi.GetCruiseAltitude().Length : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
|
||||
if (entryLocation.HasValue)
|
||||
{
|
||||
var pi = ai.Traits.GetOrDefault<AircraftInfo>();
|
||||
var pi = ai.TraitInfoOrDefault<AircraftInfo>();
|
||||
initDict.Add(new CenterPositionInit(owner.World.Map.CenterOfCell(entryLocation.Value) + new WVec(0, 0, pi != null ? pi.CruiseAltitude.Length : 0)));
|
||||
initDict.Add(new LocationInit(entryLocation.Value));
|
||||
}
|
||||
@@ -137,7 +137,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
}
|
||||
else
|
||||
{
|
||||
var heli = transport.Info.Traits.GetOrDefault<HelicopterInfo>();
|
||||
var heli = transport.Info.TraitInfoOrDefault<HelicopterInfo>();
|
||||
if (heli != null)
|
||||
{
|
||||
transport.QueueActivity(new Turn(transport, heli.InitialFacing));
|
||||
|
||||
@@ -26,15 +26,15 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public CaptureProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
normalInfo = Self.Info.Traits.GetOrDefault<CapturesInfo>();
|
||||
externalInfo = Self.Info.Traits.GetOrDefault<ExternalCapturesInfo>();
|
||||
normalInfo = Self.Info.TraitInfoOrDefault<CapturesInfo>();
|
||||
externalInfo = Self.Info.TraitInfoOrDefault<ExternalCapturesInfo>();
|
||||
}
|
||||
|
||||
[Desc("Captures the target actor.")]
|
||||
public void Capture(Actor target)
|
||||
{
|
||||
var normalCapturable = target.Info.Traits.GetOrDefault<CapturableInfo>();
|
||||
var externalCapturable = target.Info.Traits.GetOrDefault<ExternalCapturableInfo>();
|
||||
var normalCapturable = target.Info.TraitInfoOrDefault<CapturableInfo>();
|
||||
var externalCapturable = target.Info.TraitInfoOrDefault<ExternalCapturableInfo>();
|
||||
|
||||
if (normalInfo != null && normalCapturable != null && normalInfo.CaptureTypes.Contains(normalCapturable.Type))
|
||||
Self.QueueActivity(new CaptureActor(Self, target));
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public DemolitionProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
info = Self.Info.Traits.Get<C4DemolitionInfo>();
|
||||
info = Self.Info.TraitInfo<C4DemolitionInfo>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
BuildableInfo GetBuildableInfo(string actorType)
|
||||
{
|
||||
var ri = Self.World.Map.Rules.Actors[actorType];
|
||||
var bi = ri.Traits.GetOrDefault<BuildableInfo>();
|
||||
var bi = ri.TraitInfoOrDefault<BuildableInfo>();
|
||||
|
||||
if (bi == null)
|
||||
throw new LuaException("Actor of type {0} cannot be produced".F(actorType));
|
||||
@@ -267,7 +267,7 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
BuildableInfo GetBuildableInfo(string actorType)
|
||||
{
|
||||
var ri = Player.World.Map.Rules.Actors[actorType];
|
||||
var bi = ri.Traits.GetOrDefault<BuildableInfo>();
|
||||
var bi = ri.TraitInfoOrDefault<BuildableInfo>();
|
||||
|
||||
if (bi == null)
|
||||
throw new LuaException("Actor of type {0} cannot be produced".F(actorType));
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return WVec.Zero;
|
||||
|
||||
return self.World.FindActorsInCircle(self.CenterPosition, info.IdealSeparation)
|
||||
.Where(a => !a.IsDead && a.Info.HasTraitInfo<AircraftInfo>() && a.Info.Traits.Get<AircraftInfo>().CruiseAltitude == info.CruiseAltitude)
|
||||
.Where(a => !a.IsDead && a.Info.HasTraitInfo<AircraftInfo>() && a.Info.TraitInfo<AircraftInfo>().CruiseAltitude == info.CruiseAltitude)
|
||||
.Select(GetRepulsionForce)
|
||||
.Aggregate(WVec.Zero, (a, b) => a + b);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (info.QuantizedFacings >= 0)
|
||||
return info.QuantizedFacings;
|
||||
|
||||
var qboi = self.Info.Traits.GetOrDefault<IQuantizeBodyOrientationInfo>();
|
||||
var qboi = self.Info.TraitInfoOrDefault<IQuantizeBodyOrientationInfo>();
|
||||
|
||||
// If a sprite actor has neither custom QuantizedFacings nor a trait implementing IQuantizeBodyOrientationInfo, throw
|
||||
if (qboi == null)
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (Palette != null)
|
||||
p = init.WorldRenderer.Palette(Palette);
|
||||
|
||||
var bi = init.Actor.Traits.Get<BuildingInfo>();
|
||||
var bi = init.Actor.TraitInfo<BuildingInfo>();
|
||||
|
||||
var width = bi.Dimensions.X;
|
||||
var bibOffset = bi.Dimensions.Y - 1;
|
||||
@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
this.info = info;
|
||||
rs = self.Trait<RenderSprites>();
|
||||
bi = self.Info.Traits.Get<BuildingInfo>();
|
||||
bi = self.Info.TraitInfo<BuildingInfo>();
|
||||
}
|
||||
|
||||
public void AddedToWorld(Actor self)
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.info = info;
|
||||
type = self.Info.Name;
|
||||
isDangling = new Lazy<bool>(() => huts[0] == huts[1] && (neighbours[0] == null || neighbours[1] == null));
|
||||
building = self.Info.Traits.Get<BuildingInfo>();
|
||||
building = self.Info.TraitInfo<BuildingInfo>();
|
||||
}
|
||||
|
||||
public Bridge Neighbour(int direction) { return neighbours[direction]; }
|
||||
|
||||
@@ -64,8 +64,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
|
||||
var buildingMaxBounds = Dimensions;
|
||||
var buildingTraits = world.Map.Rules.Actors[buildingName].Traits;
|
||||
if (buildingTraits.Contains<BibInfo>() && !buildingTraits.Get<BibInfo>().HasMinibib)
|
||||
var bibInfo = world.Map.Rules.Actors[buildingName].TraitInfoOrDefault<BibInfo>();
|
||||
if (bibInfo != null && !bibInfo.HasMinibib)
|
||||
buildingMaxBounds += new CVec(0, 1);
|
||||
|
||||
var scanStart = world.Map.Clamp(topLeft - new CVec(Adjacent, Adjacent));
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
world.ActorAdded += a =>
|
||||
{
|
||||
var b = a.Info.Traits.GetOrDefault<BuildingInfo>();
|
||||
var b = a.Info.TraitInfoOrDefault<BuildingInfo>();
|
||||
if (b == null)
|
||||
return;
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
world.ActorRemoved += a =>
|
||||
{
|
||||
var b = a.Info.Traits.GetOrDefault<BuildingInfo>();
|
||||
var b = a.Info.TraitInfoOrDefault<BuildingInfo>();
|
||||
if (b == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public static IEnumerable<CPos> GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi)
|
||||
{
|
||||
var lbi = world.Map.Rules.Actors[name].Traits.Get<LineBuildInfo>();
|
||||
var lbi = world.Map.Rules.Actors[name].TraitInfo<LineBuildInfo>();
|
||||
var topLeft = location; // 1x1 assumption!
|
||||
|
||||
if (world.IsCellBuildable(topLeft, bi))
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Cell contains an actor. Is it the type we want?
|
||||
if (world.ActorsWithTrait<LineBuildNode>().Any(a =>
|
||||
(a.Actor.Location == cell &&
|
||||
a.Actor.Info.Traits.Get<LineBuildNodeInfo>()
|
||||
a.Actor.Info.TraitInfo<LineBuildNodeInfo>()
|
||||
.Types.Overlaps(lbi.NodeTypes))))
|
||||
dirs[d] = i; // Cell contains actor of correct type
|
||||
else
|
||||
|
||||
@@ -22,8 +22,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));
|
||||
|
||||
var buildingTraits = rules.Actors[name].Traits;
|
||||
if (buildingTraits.Contains<BibInfo>() && !buildingTraits.Get<BibInfo>().HasMinibib)
|
||||
var bibInfo = rules.Actors[name].TraitInfoOrDefault<BibInfo>();
|
||||
if (bibInfo != null && !bibInfo.HasMinibib)
|
||||
{
|
||||
dim += new CVec(0, 1);
|
||||
footprint = footprint.Concat(new char[dim.X]);
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public static IEnumerable<CPos> Tiles(Actor a)
|
||||
{
|
||||
return Tiles(a.World.Map.Rules, a.Info.Name, a.Info.Traits.Get<BuildingInfo>(), a.Location);
|
||||
return Tiles(a.World.Map.Rules, a.Info.Name, a.Info.TraitInfo<BuildingInfo>(), a.Location);
|
||||
}
|
||||
|
||||
public static IEnumerable<CPos> UnpathableTiles(string name, BuildingInfo buildingInfo, CPos position)
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// TODO: THIS IS SHIT
|
||||
// Cancel existing primaries
|
||||
foreach (var p in self.Info.Traits.Get<ProductionInfo>().Produces)
|
||||
foreach (var p in self.Info.TraitInfo<ProductionInfo>().Produces)
|
||||
{
|
||||
var productionType = p; // benign closure hazard
|
||||
foreach (var b in self.World
|
||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.Where(a =>
|
||||
a.Actor.Owner == self.Owner &&
|
||||
a.Trait.IsPrimary &&
|
||||
a.Actor.Info.Traits.Get<ProductionInfo>().Produces.Contains(productionType)))
|
||||
a.Actor.Info.TraitInfo<ProductionInfo>().Produces.Contains(productionType)))
|
||||
b.Trait.SetPrimaryProducer(b.Actor, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool CanBeTargetedBy(Actor captor, Player owner)
|
||||
{
|
||||
var c = captor.Info.Traits.GetOrDefault<CapturesInfo>();
|
||||
var c = captor.Info.TraitInfoOrDefault<CapturesInfo>();
|
||||
if (c == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
var c = target.Info.Traits.GetOrDefault<CapturableInfo>();
|
||||
var c = target.Info.TraitInfoOrDefault<CapturableInfo>();
|
||||
if (c == null || !c.CanBeTargetedBy(self, target.Owner))
|
||||
{
|
||||
cursor = "enter-blocked";
|
||||
@@ -109,14 +109,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
var c = target.Info.Traits.GetOrDefault<CapturableInfo>();
|
||||
var c = target.Info.TraitInfoOrDefault<CapturableInfo>();
|
||||
if (c == null || !c.CanBeTargetedBy(self, target.Owner))
|
||||
{
|
||||
cursor = "enter-blocked";
|
||||
return false;
|
||||
}
|
||||
|
||||
var health = target.Info.Traits.GetOrDefault<HealthInfo>();
|
||||
var health = target.Info.TraitInfoOrDefault<HealthInfo>();
|
||||
var lowEnoughHealth = target.HP <= c.CaptureThreshold * health.HP;
|
||||
|
||||
cursor = !sabotage || lowEnoughHealth || target.Owner.NonCombatant
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
helicopter = self.TraitOrDefault<Helicopter>();
|
||||
}
|
||||
|
||||
static int GetWeight(Actor a) { return a.Info.Traits.Get<PassengerInfo>().Weight; }
|
||||
static int GetWeight(Actor a) { return a.Info.TraitInfo<PassengerInfo>().Weight; }
|
||||
|
||||
public IEnumerable<IOrderTargeter> Orders
|
||||
{
|
||||
@@ -268,7 +268,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var c in cargo)
|
||||
{
|
||||
var pi = c.Info.Traits.Get<PassengerInfo>();
|
||||
var pi = c.Info.TraitInfo<PassengerInfo>();
|
||||
if (n < pi.Weight)
|
||||
return pi.PipType;
|
||||
else
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public CombatDebugOverlay(Actor self)
|
||||
{
|
||||
healthInfo = self.Info.Traits.GetOrDefault<HealthInfo>();
|
||||
healthInfo = self.Info.TraitInfoOrDefault<HealthInfo>();
|
||||
attack = Exts.Lazy(() => self.TraitOrDefault<AttackBase>());
|
||||
coords = Exts.Lazy(() => self.Trait<BodyOrientation>());
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var collector = landedOn.FirstOrDefault(a =>
|
||||
{
|
||||
// Mobile is (currently) the only trait that supports crushing
|
||||
var mi = a.Info.Traits.GetOrDefault<MobileInfo>();
|
||||
var mi = a.Info.TraitInfoOrDefault<MobileInfo>();
|
||||
if (mi == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Restrict duplicate count to a maximum value
|
||||
if (info.MaxDuplicateValue > 0)
|
||||
{
|
||||
var vi = collector.Info.Traits.GetOrDefault<ValuedInfo>();
|
||||
var vi = collector.Info.TraitInfoOrDefault<ValuedInfo>();
|
||||
if (vi != null && vi.Cost > 0)
|
||||
duplicates = Math.Min(duplicates, info.MaxDuplicateValue / vi.Cost);
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
IEnumerable<CPos> GetSuitableCells(CPos near, string unitName)
|
||||
{
|
||||
var mi = self.World.Map.Rules.Actors[unitName].Traits.Get<MobileInfo>();
|
||||
var mi = self.World.Map.Rules.Actors[unitName].TraitInfo<MobileInfo>();
|
||||
|
||||
for (var i = -1; i < 2; i++)
|
||||
for (var j = -1; j < 2; j++)
|
||||
|
||||
@@ -26,11 +26,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public static int GetBuildTime(this ActorInfo a)
|
||||
{
|
||||
var csv = a.Traits.GetOrDefault<CustomBuildTimeValueInfo>();
|
||||
var csv = a.TraitInfoOrDefault<CustomBuildTimeValueInfo>();
|
||||
if (csv != null)
|
||||
return csv.Value;
|
||||
|
||||
var cost = a.HasTraitInfo<ValuedInfo>() ? a.Traits.Get<ValuedInfo>().Cost : 0;
|
||||
var cost = a.HasTraitInfo<ValuedInfo>() ? a.TraitInfo<ValuedInfo>().Cost : 0;
|
||||
var time = cost
|
||||
* (25 * 60) /* frames per min */
|
||||
/ 1000;
|
||||
|
||||
@@ -25,10 +25,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public static int GetSellValue(this Actor a)
|
||||
{
|
||||
var csv = a.Info.Traits.GetOrDefault<CustomSellValueInfo>();
|
||||
var csv = a.Info.TraitInfoOrDefault<CustomSellValueInfo>();
|
||||
if (csv != null) return csv.Value;
|
||||
|
||||
var valued = a.Info.Traits.GetOrDefault<ValuedInfo>();
|
||||
var valued = a.Info.TraitInfoOrDefault<ValuedInfo>();
|
||||
if (valued != null) return valued.Cost;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -51,8 +51,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (!correctFaction)
|
||||
return;
|
||||
|
||||
var csv = self.Info.Traits.GetOrDefault<CustomSellValueInfo>();
|
||||
var valued = self.Info.Traits.GetOrDefault<ValuedInfo>();
|
||||
var csv = self.Info.TraitInfoOrDefault<CustomSellValueInfo>();
|
||||
var valued = self.Info.TraitInfoOrDefault<ValuedInfo>();
|
||||
var cost = csv != null ? csv.Value : (valued != null ? valued.Cost : 0);
|
||||
|
||||
var health = self.TraitOrDefault<Health>();
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
dudesValue /= 100;
|
||||
|
||||
var eligibleLocations = FootprintUtils.Tiles(self).ToList();
|
||||
var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].Traits.Get<ValuedInfo>().Cost }).ToList();
|
||||
var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].TraitInfo<ValuedInfo>().Cost }).ToList();
|
||||
|
||||
while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue))
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool CanBeTargetedBy(Actor captor, Player owner)
|
||||
{
|
||||
var c = captor.Info.Traits.GetOrDefault<ExternalCapturesInfo>();
|
||||
var c = captor.Info.TraitInfoOrDefault<ExternalCapturesInfo>();
|
||||
if (c == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (frozen == null)
|
||||
return false;
|
||||
|
||||
var ci = frozen.Info.Traits.GetOrDefault<ExternalCapturableInfo>();
|
||||
var ci = frozen.Info.TraitInfoOrDefault<ExternalCapturableInfo>();
|
||||
return ci != null && ci.CanBeTargetedBy(self, frozen.Owner);
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
var c = target.Info.Traits.GetOrDefault<ExternalCapturableInfo>();
|
||||
var c = target.Info.TraitInfoOrDefault<ExternalCapturableInfo>();
|
||||
|
||||
var canTargetActor = c != null && c.CanBeTargetedBy(self, target.Owner);
|
||||
cursor = canTargetActor ? "ability" : "move-blocked";
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
MaxLevel = info.Upgrades.Count;
|
||||
|
||||
var cost = self.Info.Traits.Get<ValuedInfo>().Cost;
|
||||
var cost = self.Info.TraitInfo<ValuedInfo>().Cost;
|
||||
foreach (var kv in info.Upgrades)
|
||||
nextLevel.Add(Pair.New(kv.Key * cost, kv.Value));
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
static int GetMultiplier(Actor self)
|
||||
{
|
||||
// returns 100's as 1, so as to keep accuracy for longer.
|
||||
var info = self.Info.Traits.Get<GivesBountyInfo>();
|
||||
var info = self.Info.TraitInfo<GivesBountyInfo>();
|
||||
var gainsExp = self.TraitOrDefault<GainsExperience>();
|
||||
if (gainsExp == null)
|
||||
return 100;
|
||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
var info = self.Info.Traits.Get<GivesBountyInfo>();
|
||||
var info = self.Info.TraitInfo<GivesBountyInfo>();
|
||||
|
||||
if (e.Attacker == null || e.Attacker.Disposed) return;
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (e.Attacker == null || e.Attacker.Disposed || (!info.FriendlyFire && e.Attacker.Owner.Stances[self.Owner] == Stance.Ally))
|
||||
return;
|
||||
|
||||
var valued = self.Info.Traits.GetOrDefault<ValuedInfo>();
|
||||
var valued = self.Info.TraitInfoOrDefault<ValuedInfo>();
|
||||
|
||||
// Default experience is 100 times our value
|
||||
var exp = info.Experience >= 0
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
self.SetTargetLine(target, Color.Yellow);
|
||||
|
||||
var range = WDist.FromCells(target.Actor.Info.Traits.Get<GuardableInfo>().Range);
|
||||
var range = WDist.FromCells(target.Actor.Info.TraitInfo<GuardableInfo>().Range);
|
||||
self.QueueActivity(false, new AttackMoveActivity(self, self.Trait<IMove>().MoveFollow(self, target, WDist.Zero, range)));
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
// Start a search from each refinery's delivery location:
|
||||
List<CPos> path;
|
||||
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||
var mi = self.Info.TraitInfo<MobileInfo>();
|
||||
using (var search = PathSearch.FromPoints(self.World, mi, self, refs.Values.Select(r => r.Location), self.Location, false)
|
||||
.WithCustomCost(loc =>
|
||||
{
|
||||
@@ -469,7 +469,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return false;
|
||||
|
||||
var res = self.World.WorldActor.Trait<ResourceLayer>().GetRenderedResource(location);
|
||||
var info = self.Info.Traits.Get<HarvesterInfo>();
|
||||
var info = self.Info.TraitInfo<HarvesterInfo>();
|
||||
|
||||
if (res == null || !info.Resources.Contains(res.Info.Name))
|
||||
return false;
|
||||
|
||||
@@ -138,7 +138,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
bool IsCorrectCargoType(Actor target)
|
||||
{
|
||||
var ci = target.Info.Traits.Get<CargoInfo>();
|
||||
var ci = target.Info.TraitInfo<CargoInfo>();
|
||||
return ci.Types.Contains(Info.CargoType);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var exitLocation = CPos.Zero;
|
||||
var target = Target.Invalid;
|
||||
|
||||
var bi = producee.Traits.GetOrDefault<BuildableInfo>();
|
||||
var bi = producee.TraitInfoOrDefault<BuildableInfo>();
|
||||
if (bi != null && bi.ForceFaction != null)
|
||||
factionVariant = bi.ForceFaction;
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var spawn = self.CenterPosition + exitinfo.SpawnOffset;
|
||||
var to = self.World.Map.CenterOfCell(exit);
|
||||
|
||||
var fi = producee.Traits.GetOrDefault<IFacingInfo>();
|
||||
var fi = producee.TraitInfoOrDefault<IFacingInfo>();
|
||||
var initialFacing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, fi == null ? 0 : fi.GetInitialFacing()) : exitinfo.Facing;
|
||||
|
||||
exitLocation = rp.Value != null ? rp.Value.Location : exit;
|
||||
@@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
static bool CanUseExit(Actor self, ActorInfo producee, ExitInfo s)
|
||||
{
|
||||
var mobileInfo = producee.Traits.GetOrDefault<MobileInfo>();
|
||||
var mobileInfo = producee.TraitInfoOrDefault<MobileInfo>();
|
||||
|
||||
self.NotifyBlocker(self.Location + s.ExitCell);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (self.IsDisabled()) return false;
|
||||
|
||||
var isJammed = self.World.ActorsWithTrait<JamsRadar>().Any(a => a.Actor.Owner.Stances[self.Owner] != Stance.Ally
|
||||
&& (self.Location - a.Actor.Location).Length <= a.Actor.Info.Traits.Get<JamsRadarInfo>().Range);
|
||||
&& (self.Location - a.Actor.Location).Length <= a.Actor.Info.TraitInfo<JamsRadarInfo>().Range);
|
||||
|
||||
return !isJammed;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
bool CanBeCapturedBy(Actor a)
|
||||
{
|
||||
var pc = a.Info.Traits.GetOrDefault<ProximityCaptorInfo>();
|
||||
var pc = a.Info.TraitInfoOrDefault<ProximityCaptorInfo>();
|
||||
return pc != null && pc.Types.Overlaps(Info.CaptorTypes);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (string.IsNullOrEmpty(Sequence))
|
||||
throw new InvalidOperationException("Actor " + ai.Name + " is missing sequence to quantize facings from.");
|
||||
|
||||
var rsi = ai.Traits.Get<RenderSpritesInfo>();
|
||||
var rsi = ai.TraitInfo<RenderSpritesInfo>();
|
||||
return sequenceProvider.GetSequence(rsi.GetImage(ai, sequenceProvider, race), Sequence).Facings;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
if (queue == null)
|
||||
{
|
||||
var type = info.ProductionType ?? self.Trait<Production>().Info.Produces.First();
|
||||
var type = info.ProductionType ?? self.Info.TraitInfo<ProductionInfo>().Produces.First();
|
||||
|
||||
// Per-actor queue
|
||||
// Note: this includes disabled queues, as each bar must bind to exactly one queue.
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var a in w.ActorsWithTrait<RenderRangeCircle>())
|
||||
if (a.Actor.Owner.IsAlliedWith(w.RenderPlayer))
|
||||
if (a.Actor.Info.Traits.Get<RenderRangeCircleInfo>().RangeCircleType == RangeCircleType)
|
||||
if (a.Actor.Info.TraitInfo<RenderRangeCircleInfo>().RangeCircleType == RangeCircleType)
|
||||
foreach (var r in a.Trait.RenderAfterWorld(wr))
|
||||
yield return r;
|
||||
}
|
||||
|
||||
@@ -52,14 +52,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var palette = init.WorldRenderer.Palette(Palette ?? PlayerPalette + ownerName);
|
||||
|
||||
var facings = 0;
|
||||
var body = init.Actor.Traits.GetOrDefault<BodyOrientationInfo>();
|
||||
var body = init.Actor.TraitInfoOrDefault<BodyOrientationInfo>();
|
||||
if (body != null)
|
||||
{
|
||||
facings = body.QuantizedFacings;
|
||||
|
||||
if (facings == -1)
|
||||
{
|
||||
var qbo = init.Actor.Traits.GetOrDefault<IQuantizeBodyOrientationInfo>();
|
||||
var qbo = init.Actor.TraitInfoOrDefault<IQuantizeBodyOrientationInfo>();
|
||||
facings = qbo != null ? qbo.QuantizedBodyFacings(init.Actor, sequenceProvider, faction) : 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,17 +47,17 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public virtual IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
|
||||
{
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var faction = init.Get<FactionInit, string>();
|
||||
var ownerName = init.Get<OwnerInit>().PlayerName;
|
||||
var sequenceProvider = init.World.Map.SequenceProvider;
|
||||
var image = Image ?? init.Actor.Name;
|
||||
var facings = body.QuantizedFacings == -1 ?
|
||||
init.Actor.Traits.Get<IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(init.Actor, sequenceProvider, faction) :
|
||||
init.Actor.TraitInfo<IQuantizeBodyOrientationInfo>().QuantizedBodyFacings(init.Actor, sequenceProvider, faction) :
|
||||
body.QuantizedFacings;
|
||||
var palette = init.WorldRenderer.Palette(Palette ?? PlayerPalette + ownerName);
|
||||
|
||||
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>();
|
||||
var ifacing = init.Actor.TraitInfoOrDefault<IFacingInfo>();
|
||||
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
||||
var orientation = WRot.FromFacing(facing);
|
||||
var components = init.Actor.Traits.WithInterface<IRenderActorPreviewVoxelsInfo>()
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (UpgradeMinEnabledLevel > 0)
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var armament = init.Actor.Traits.WithInterface<ArmamentInfo>()
|
||||
.First(a => a.Name == Armament);
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public WithBuildingExplosion(Actor self, WithBuildingExplosionInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
buildingInfo = self.Info.Traits.Get<BuildingInfo>();
|
||||
buildingInfo = self.Info.TraitInfo<BuildingInfo>();
|
||||
}
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>();
|
||||
var ifacing = init.Actor.TraitInfoOrDefault<IFacingInfo>();
|
||||
var facing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
||||
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (Palette != null)
|
||||
p = init.WorldRenderer.Palette(Palette);
|
||||
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var facing = 0;
|
||||
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>();
|
||||
var ifacing = init.Actor.TraitInfoOrDefault<IFacingInfo>();
|
||||
if (ifacing != null)
|
||||
facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing();
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var anim = new Animation(init.World, image);
|
||||
anim.PlayThen(OpeningSequence, () => anim.PlayRepeating(Sequence));
|
||||
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
|
||||
var orientation = body.QuantizeOrientation(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing)), facings);
|
||||
var offset = body.LocalToWorld(Offset.Rotate(orientation));
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var anim = new Animation(init.World, image, () => 0);
|
||||
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);
|
||||
|
||||
var bi = init.Actor.Traits.Get<BuildingInfo>();
|
||||
var bi = init.Actor.TraitInfo<BuildingInfo>();
|
||||
var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512; // Additional 512 units move from center -> top of cell
|
||||
yield return new SpriteActorPreview(anim, WVec.Zero, offset, p, rs.Scale);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
door.PlayFetchDirection(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.Sequence),
|
||||
() => desiredFrame - door.CurrentFrame);
|
||||
|
||||
var buildingInfo = self.Info.Traits.Get<BuildingInfo>();
|
||||
var buildingInfo = self.Info.TraitInfo<BuildingInfo>();
|
||||
|
||||
var offset = FootprintUtils.CenterOffset(self.World, buildingInfo).Y + 512;
|
||||
renderSprites.Add(new AnimationWithOffset(door, null, () => !buildComplete, offset));
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var body = self.Trait<BodyOrientation>();
|
||||
|
||||
buildComplete = !self.Info.HasTraitInfo<BuildingInfo>(); // always render instantly for units
|
||||
production = self.Info.Traits.Get<ProductionInfo>();
|
||||
production = self.Info.TraitInfo<ProductionInfo>();
|
||||
|
||||
overlay = new Animation(self.World, rs.GetImage(self));
|
||||
overlay.PlayRepeating(info.Sequence);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||
{
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
|
||||
var anim = new Animation(init.World, image, () => facing);
|
||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||
|
||||
@@ -39,11 +39,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (UpgradeMinEnabledLevel > 0)
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
.First(tt => tt.Turret == Turret);
|
||||
|
||||
var ifacing = init.Actor.Traits.GetOrDefault<IFacingInfo>();
|
||||
var ifacing = init.Actor.TraitInfoOrDefault<IFacingInfo>();
|
||||
var bodyFacing = ifacing != null ? init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : ifacing.GetInitialFacing() : 0;
|
||||
var turretFacing = init.Contains<TurretFacingInit>() ? init.Get<TurretFacingInit, int>() : t.InitialFacing;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (UpgradeMinEnabledLevel > 0)
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var armament = init.Actor.Traits.WithInterface<ArmamentInfo>()
|
||||
.First(a => a.Name == Armament);
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<VoxelAnimation> RenderPreviewVoxels(ActorPreviewInitializer init, RenderVoxelsInfo rv, string image, WRot orientation, int facings, PaletteReference p)
|
||||
{
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var voxel = VoxelProvider.GetVoxel(image, "idle");
|
||||
var bodyOrientation = new[] { body.QuantizeOrientation(orientation, facings) };
|
||||
yield return new VoxelAnimation(voxel, () => WVec.Zero,
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
() => IsTraitDisabled, () => 0));
|
||||
|
||||
// Selection size
|
||||
var rvi = self.Info.Traits.Get<RenderVoxelsInfo>();
|
||||
var rvi = self.Info.TraitInfo<RenderVoxelsInfo>();
|
||||
var s = (int)(rvi.Scale * voxel.Size.Aggregate(Math.Max));
|
||||
size = new int2(s, s);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (UpgradeMinEnabledLevel > 0)
|
||||
yield break;
|
||||
|
||||
var body = init.Actor.Traits.Get<BodyOrientationInfo>();
|
||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||
var t = init.Actor.Traits.WithInterface<TurretedInfo>()
|
||||
.First(tt => tt.Turret == Turret);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var haveNeighbour = false;
|
||||
foreach (var n in kv.Value)
|
||||
{
|
||||
var rb = init.World.Map.Rules.Actors[n].Traits.GetOrDefault<WithWallSpriteBodyInfo>();
|
||||
var rb = init.World.Map.Rules.Actors[n].TraitInfoOrDefault<WithWallSpriteBodyInfo>();
|
||||
if (rb != null && rb.Type == Type)
|
||||
{
|
||||
haveNeighbour = true;
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (randomize)
|
||||
attackFacing = Util.QuantizeFacing(self.World.SharedRandom.Next(256), info.QuantizedFacings) * (256 / info.QuantizedFacings);
|
||||
|
||||
var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude.Length;
|
||||
var altitude = self.World.Map.Rules.Actors[info.UnitType].TraitInfo<PlaneInfo>().CruiseAltitude.Length;
|
||||
var attackRotation = WRot.FromFacing(attackFacing);
|
||||
var delta = new WVec(0, -1024, 0).Rotate(attackRotation);
|
||||
target = target + new WVec(0, 0, altitude);
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
self = init.Self;
|
||||
this.info = info;
|
||||
buildingInfo = self.World.Map.Rules.Actors[info.IntoActor].Traits.GetOrDefault<BuildingInfo>();
|
||||
buildingInfo = self.World.Map.Rules.Actors[info.IntoActor].TraitInfoOrDefault<BuildingInfo>();
|
||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var a in self.World.Map.Rules.Actors.Values)
|
||||
{
|
||||
var uwc = a.Traits.GetOrDefault<ProducibleWithLevelInfo>();
|
||||
var uwc = a.TraitInfoOrDefault<ProducibleWithLevelInfo>();
|
||||
if (uwc != null)
|
||||
ttc.Add(MakeKey(a.Name), uwc.Prerequisites, 0, this);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Build a list of templates that should be overlayed with bridges
|
||||
foreach (var bridge in info.Bridges)
|
||||
{
|
||||
var bi = w.Map.Rules.Actors[bridge].Traits.Get<BridgeInfo>();
|
||||
var bi = w.Map.Rules.Actors[bridge].TraitInfo<BridgeInfo>();
|
||||
foreach (var template in bi.Templates)
|
||||
bridgeTypes.Add(template.First, Pair.New(bridge, template.Second));
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var dropFacing = Util.QuantizeFacing(self.World.SharedRandom.Next(256), info.QuantizedFacings) * (256 / info.QuantizedFacings);
|
||||
var delta = new WVec(0, -1024, 0).Rotate(WRot.FromFacing(dropFacing));
|
||||
|
||||
var altitude = self.World.Map.Rules.Actors[info.DeliveryAircraft].Traits.Get<PlaneInfo>().CruiseAltitude.Length;
|
||||
var altitude = self.World.Map.Rules.Actors[info.DeliveryAircraft].TraitInfo<PlaneInfo>().CruiseAltitude.Length;
|
||||
var target = self.World.Map.CenterOfCell(p) + new WVec(0, 0, altitude);
|
||||
var startEdge = target - (self.World.Map.DistanceToEdge(target, -delta) + info.Cordon).Length * delta / 1024;
|
||||
var finishEdge = target + (self.World.Map.DistanceToEdge(target, delta) + info.Cordon).Length * delta / 1024;
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
domainIndexes = new Dictionary<uint, MovementClassDomainIndex>();
|
||||
var movementClasses =
|
||||
world.Map.Rules.Actors.Where(ai => ai.Value.HasTraitInfo<MobileInfo>())
|
||||
.Select(ai => (uint)ai.Value.Traits.Get<MobileInfo>().GetMovementClass(world.TileSet)).Distinct();
|
||||
.Select(ai => (uint)ai.Value.TraitInfo<MobileInfo>().GetMovementClass(world.TileSet)).Distinct();
|
||||
|
||||
foreach (var mc in movementClasses)
|
||||
domainIndexes[mc] = new MovementClassDomainIndex(world, mc);
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
CenterPosition = PreviewPosition(world, actor.InitDict);
|
||||
|
||||
var location = actor.InitDict.Get<LocationInit>().Value(worldRenderer.World);
|
||||
var ios = Info.Traits.GetOrDefault<IOccupySpaceInfo>();
|
||||
var ios = Info.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||
|
||||
var subCellInit = actor.InitDict.GetOrDefault<SubCellInit>();
|
||||
var subCell = subCellInit != null ? subCellInit.Value(worldRenderer.World) : SubCell.Any;
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Footprint = new ReadOnlyDictionary<CPos, SubCell>(footprint);
|
||||
}
|
||||
|
||||
var tooltip = Info.Traits.GetOrDefault<TooltipInfo>();
|
||||
var tooltip = Info.TraitInfoOrDefault<TooltipInfo>();
|
||||
Tooltip = tooltip == null ? ID + ": " + Info.Name : ID + ": " + tooltip.Name + " (" + Info.Name + ")";
|
||||
|
||||
GeneratePreviews();
|
||||
@@ -143,7 +143,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var subCellInit = actor.InitDict.GetOrDefault<SubCellInit>();
|
||||
var subCell = subCellInit != null ? subCellInit.Value(worldRenderer.World) : SubCell.Any;
|
||||
|
||||
var buildingInfo = Info.Traits.GetOrDefault<BuildingInfo>();
|
||||
var buildingInfo = Info.TraitInfoOrDefault<BuildingInfo>();
|
||||
if (buildingInfo != null)
|
||||
offset = FootprintUtils.CenterOffset(world, buildingInfo);
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public List<CPos> FindUnitPath(CPos source, CPos target, Actor self)
|
||||
{
|
||||
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||
var mi = self.Info.TraitInfo<MobileInfo>();
|
||||
|
||||
// If a water-land transition is required, bail early
|
||||
var domainIndex = world.WorldActor.TraitOrDefault<DomainIndex>();
|
||||
@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public List<CPos> FindUnitPathToRange(CPos source, SubCell srcSub, WPos target, WDist range, Actor self)
|
||||
{
|
||||
var mi = self.Info.Traits.Get<MobileInfo>();
|
||||
var mi = self.Info.TraitInfo<MobileInfo>();
|
||||
var targetCell = world.Map.CellContaining(target);
|
||||
|
||||
// Correct for SubCell offset
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
foreach (var s in unitGroup.SupportActors)
|
||||
{
|
||||
var mi = w.Map.Rules.Actors[s.ToLowerInvariant()].Traits.Get<MobileInfo>();
|
||||
var mi = w.Map.Rules.Actors[s.ToLowerInvariant()].TraitInfo<MobileInfo>();
|
||||
var validCells = supportSpawnCells.Where(c => mi.CanEnterCell(w, null, c));
|
||||
if (!validCells.Any())
|
||||
throw new InvalidOperationException("No cells available to spawn starting unit {0}".F(s));
|
||||
|
||||
@@ -40,14 +40,14 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
||||
Game.ModData = new ModData(srcMod);
|
||||
GlobalFileSystem.LoadFromManifest(Game.ModData.Manifest);
|
||||
var srcRules = Game.ModData.RulesetCache.Load();
|
||||
var srcPaletteInfo = srcRules.Actors["player"].Traits.Get<PlayerColorPaletteInfo>();
|
||||
var srcPaletteInfo = srcRules.Actors["player"].TraitInfo<PlayerColorPaletteInfo>();
|
||||
var srcRemapIndex = srcPaletteInfo.RemapIndex;
|
||||
|
||||
var destMod = args[2].Split(':')[0];
|
||||
Game.ModData = new ModData(destMod);
|
||||
GlobalFileSystem.LoadFromManifest(Game.ModData.Manifest);
|
||||
var destRules = Game.ModData.RulesetCache.Load();
|
||||
var destPaletteInfo = destRules.Actors["player"].Traits.Get<PlayerColorPaletteInfo>();
|
||||
var destPaletteInfo = destRules.Actors["player"].TraitInfo<PlayerColorPaletteInfo>();
|
||||
var destRemapIndex = destPaletteInfo.RemapIndex;
|
||||
var shadowIndex = new int[] { };
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
{
|
||||
foreach (var unit in world.ActorMap.GetUnitsAt(cell))
|
||||
{
|
||||
var healthInfo = unit.Info.Traits.GetOrDefault<HealthInfo>();
|
||||
var healthInfo = unit.Info.TraitInfoOrDefault<HealthInfo>();
|
||||
if (healthInfo == null)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
|
||||
public override void DoImpact(Actor victim, Actor firedBy, IEnumerable<int> damageModifiers)
|
||||
{
|
||||
var healthInfo = victim.Info.Traits.GetOrDefault<HealthInfo>();
|
||||
var healthInfo = victim.Info.TraitInfoOrDefault<HealthInfo>();
|
||||
if (healthInfo == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Warheads
|
||||
continue;
|
||||
|
||||
var localModifiers = damageModifiers;
|
||||
var healthInfo = victim.Info.Traits.GetOrDefault<HealthInfo>();
|
||||
var healthInfo = victim.Info.TraitInfoOrDefault<HealthInfo>();
|
||||
if (healthInfo != null)
|
||||
{
|
||||
var distance = Math.Max(0, (victim.CenterPosition - pos).Length - healthInfo.Radius.Length);
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (!actor.HasTraitInfo<IRenderActorPreviewInfo>())
|
||||
continue;
|
||||
|
||||
var filter = actor.Traits.GetOrDefault<EditorTilesetFilterInfo>();
|
||||
var filter = actor.TraitInfoOrDefault<EditorTilesetFilterInfo>();
|
||||
if (filter != null)
|
||||
{
|
||||
if (filter.ExcludeTilesets != null && filter.ExcludeTilesets.Contains(world.TileSet.Id))
|
||||
@@ -136,7 +136,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
item.Bounds.Height = preview.Bounds.Height + 2 * preview.Bounds.Y;
|
||||
item.IsVisible = () => true;
|
||||
|
||||
var tooltip = actor.Traits.GetOrDefault<TooltipInfo>();
|
||||
var tooltip = actor.TraitInfoOrDefault<TooltipInfo>();
|
||||
item.GetTooltipText = () => tooltip == null ? actor.Name : tooltip.Name + " (" + actor.Name + ")";
|
||||
|
||||
panel.AddChild(item);
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
var playerWidgets = Game.LoadWidget(world, "PLAYER_WIDGETS", playerRoot, new WidgetArgs());
|
||||
var sidebarTicker = playerWidgets.Get<LogicTickerWidget>("SIDEBAR_TICKER");
|
||||
var objectives = world.LocalPlayer.PlayerActor.Info.Traits.GetOrDefault<MissionObjectivesInfo>();
|
||||
var objectives = world.LocalPlayer.PlayerActor.Info.TraitInfoOrDefault<MissionObjectivesInfo>();
|
||||
|
||||
sidebarTicker.OnTick = () =>
|
||||
{
|
||||
|
||||
@@ -54,9 +54,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (actor == null || actor == lastActor)
|
||||
return;
|
||||
|
||||
var tooltip = actor.Traits.Get<TooltipInfo>();
|
||||
var buildable = actor.Traits.Get<BuildableInfo>();
|
||||
var cost = actor.Traits.Get<ValuedInfo>().Cost;
|
||||
var tooltip = actor.TraitInfo<TooltipInfo>();
|
||||
var buildable = actor.TraitInfo<BuildableInfo>();
|
||||
var cost = actor.TraitInfo<ValuedInfo>().Cost;
|
||||
|
||||
nameLabel.GetText = () => tooltip.Name;
|
||||
|
||||
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai) && ai.HasTraitInfo<TooltipInfo>())
|
||||
return ai.Traits.Get<TooltipInfo>().Name;
|
||||
return ai.TraitInfo<TooltipInfo>().Name;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -438,7 +438,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Map.Map.Options.StartingCash.HasValue ? "Not Available" : "${0}".F(orderManager.LobbyInfo.GlobalSettings.StartingCash);
|
||||
startingCash.OnMouseDown = _ =>
|
||||
{
|
||||
var options = modRules.Actors["player"].Traits.Get<PlayerResourcesInfo>().SelectableCash.Select(c => new DropDownOption
|
||||
var options = modRules.Actors["player"].TraitInfo<PlayerResourcesInfo>().SelectableCash.Select(c => new DropDownOption
|
||||
{
|
||||
Title = "${0}".F(c),
|
||||
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.StartingCash == c,
|
||||
@@ -689,7 +689,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
orderManager.IssueOrder(Order.Command("state {0}".F(Session.ClientState.NotReady)));
|
||||
|
||||
// Restore default starting cash if the last map set it to something invalid
|
||||
var pri = modRules.Actors["player"].Traits.Get<PlayerResourcesInfo>();
|
||||
var pri = modRules.Actors["player"].TraitInfo<PlayerResourcesInfo>();
|
||||
if (!Map.Map.Options.StartingCash.HasValue && !pri.SelectableCash.Contains(orderManager.LobbyInfo.GlobalSettings.StartingCash))
|
||||
orderManager.IssueOrder(Order.Command("startingcash {0}".F(pri.DefaultCash)));
|
||||
}
|
||||
|
||||
@@ -72,10 +72,10 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
if (actor == null)
|
||||
continue;
|
||||
|
||||
var rsi = actor.Traits.Get<RenderSpritesInfo>();
|
||||
var rsi = actor.TraitInfo<RenderSpritesInfo>();
|
||||
var icon = new Animation(world, rsi.GetImage(actor, world.Map.SequenceProvider, faction));
|
||||
icon.Play(actor.Traits.Get<TooltipInfo>().Icon);
|
||||
var bi = actor.Traits.Get<BuildableInfo>();
|
||||
icon.Play(actor.TraitInfo<TooltipInfo>().Icon);
|
||||
var bi = actor.TraitInfo<BuildableInfo>();
|
||||
var location = new float2(RenderBounds.Location) + new float2(queue.i * (IconWidth + IconSpacing), 0);
|
||||
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer.Palette(bi.IconPalette), 0.5f);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user