.Trait[OrDefault]<Trait> => .Info.Traits.Get[OrDefault]<TraitInfo> where applicable
This commit is contained in:
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
class Bridge : IRender, INotifyDamageStateChanged
|
||||
{
|
||||
readonly Building building;
|
||||
readonly BuildingInfo building;
|
||||
readonly Bridge[] neighbours = new Bridge[2];
|
||||
readonly BridgeHut[] huts = new BridgeHut[2]; // Huts before this / first & after this / last
|
||||
readonly Health health;
|
||||
@@ -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.Trait<Building>();
|
||||
building = self.Info.Traits.Get<BuildingInfo>();
|
||||
}
|
||||
|
||||
public Bridge Neighbour(int direction) { return neighbours[direction]; }
|
||||
@@ -173,7 +173,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
IRenderable[] TemplateRenderables(WorldRenderer wr, PaletteReference palette, ushort template)
|
||||
{
|
||||
var offset = FootprintUtils.CenterOffset(self.World, building.Info).Y + 1024;
|
||||
var offset = FootprintUtils.CenterOffset(self.World, building).Y + 1024;
|
||||
|
||||
return footprint.Select(c => (IRenderable)(new SpriteRenderable(
|
||||
wr.Theater.TileSprite(new TerrainTile(template, c.Value)),
|
||||
|
||||
@@ -31,22 +31,22 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
world.ActorAdded += a =>
|
||||
{
|
||||
var b = a.TraitOrDefault<Building>();
|
||||
var b = a.Info.Traits.GetOrDefault<BuildingInfo>();
|
||||
if (b == null)
|
||||
return;
|
||||
|
||||
foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b.Info, a.Location))
|
||||
foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b, a.Location))
|
||||
if (influence.Contains(u) && influence[u] == null)
|
||||
influence[u] = a;
|
||||
};
|
||||
|
||||
world.ActorRemoved += a =>
|
||||
{
|
||||
var b = a.TraitOrDefault<Building>();
|
||||
var b = a.Info.Traits.GetOrDefault<BuildingInfo>();
|
||||
if (b == null)
|
||||
return;
|
||||
|
||||
foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b.Info, a.Location))
|
||||
foreach (var u in FootprintUtils.Tiles(map.Rules, a.Info.Name, b, a.Location))
|
||||
if (influence.Contains(u) && influence[u] == a)
|
||||
influence[u] = null;
|
||||
};
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool CanBeTargetedBy(Actor captor, Player owner)
|
||||
{
|
||||
var c = captor.TraitOrDefault<Captures>();
|
||||
var c = captor.Info.Traits.GetOrDefault<CapturesInfo>();
|
||||
if (c == null)
|
||||
return false;
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (playerRelationship == Stance.Neutral && !AllowNeutral)
|
||||
return false;
|
||||
|
||||
if (!c.Info.CaptureTypes.Contains(Type))
|
||||
if (!c.CaptureTypes.Contains(Type))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -26,15 +26,15 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
readonly DeveloperMode devMode;
|
||||
|
||||
readonly HealthInfo healthInfo;
|
||||
Lazy<AttackBase> attack;
|
||||
Lazy<BodyOrientation> coords;
|
||||
Lazy<Health> health;
|
||||
|
||||
public CombatDebugOverlay(Actor self)
|
||||
{
|
||||
healthInfo = self.Info.Traits.GetOrDefault<HealthInfo>();
|
||||
attack = Exts.Lazy(() => self.TraitOrDefault<AttackBase>());
|
||||
coords = Exts.Lazy(() => self.Trait<BodyOrientation>());
|
||||
health = Exts.Lazy(() => self.TraitOrDefault<Health>());
|
||||
|
||||
var localPlayer = self.World.LocalPlayer;
|
||||
devMode = localPlayer != null ? localPlayer.PlayerActor.Trait<DeveloperMode>() : null;
|
||||
@@ -45,8 +45,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (devMode == null || !devMode.ShowCombatGeometry)
|
||||
return;
|
||||
|
||||
if (health.Value != null)
|
||||
wr.DrawRangeCircle(self.CenterPosition, health.Value.Info.Radius, Color.Red);
|
||||
if (healthInfo != null)
|
||||
wr.DrawRangeCircle(self.CenterPosition, healthInfo.Radius, Color.Red);
|
||||
|
||||
// No armaments to draw
|
||||
if (attack.Value == null)
|
||||
@@ -96,11 +96,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (devMode == null || !devMode.ShowCombatGeometry || e.Damage == 0)
|
||||
return;
|
||||
|
||||
var health = self.TraitOrDefault<Health>();
|
||||
if (health == null)
|
||||
if (healthInfo == null)
|
||||
return;
|
||||
|
||||
var damageText = "{0} ({1}%)".F(-e.Damage, e.Damage * 100 / health.MaxHP);
|
||||
var maxHP = healthInfo.HP > 0 ? healthInfo.HP : 1;
|
||||
var damageText = "{0} ({1}%)".F(-e.Damage, e.Damage * 100 / maxHP);
|
||||
|
||||
self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, damageText, 30)));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public bool CanBeTargetedBy(Actor captor, Player owner)
|
||||
{
|
||||
var c = captor.TraitOrDefault<ExternalCaptures>();
|
||||
var c = captor.Info.Traits.GetOrDefault<ExternalCapturesInfo>();
|
||||
if (c == null)
|
||||
return false;
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (playerRelationship == Stance.Neutral && !AllowNeutral)
|
||||
return false;
|
||||
|
||||
if (!c.Info.CaptureTypes.Contains(Type))
|
||||
if (!c.CaptureTypes.Contains(Type))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
IExplodeModifier, IOrderVoice, ISpeedModifier, ISync, INotifyCreated,
|
||||
INotifyResourceClaimLost, INotifyIdle, INotifyBlockingMove, INotifyBuildComplete
|
||||
{
|
||||
readonly HarvesterInfo info;
|
||||
public readonly HarvesterInfo Info;
|
||||
readonly Mobile mobile;
|
||||
Dictionary<ResourceTypeInfo, int> contents = new Dictionary<ResourceTypeInfo, int>();
|
||||
bool idleSmart = true;
|
||||
@@ -92,20 +92,20 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public Harvester(Actor self, HarvesterInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
Info = info;
|
||||
mobile = self.Trait<Mobile>();
|
||||
self.QueueActivity(new CallFunc(() => ChooseNewProc(self, null)));
|
||||
}
|
||||
|
||||
public void Created(Actor self)
|
||||
{
|
||||
if (info.SearchOnCreation)
|
||||
if (Info.SearchOnCreation)
|
||||
self.QueueActivity(new FindResources(self));
|
||||
}
|
||||
|
||||
public void BuildingComplete(Actor self)
|
||||
{
|
||||
if (info.SearchOnCreation)
|
||||
if (Info.SearchOnCreation)
|
||||
self.QueueActivity(new FindResources(self));
|
||||
}
|
||||
|
||||
@@ -151,8 +151,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
bool IsAcceptableProcType(Actor proc)
|
||||
{
|
||||
return info.DeliveryBuildings.Count == 0 ||
|
||||
info.DeliveryBuildings.Contains(proc.Info.Name);
|
||||
return Info.DeliveryBuildings.Count == 0 ||
|
||||
Info.DeliveryBuildings.Contains(proc.Info.Name);
|
||||
}
|
||||
|
||||
public Actor ClosestProc(Actor self, Actor ignore)
|
||||
@@ -192,9 +192,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool IsFull { get { return contents.Values.Sum() == info.Capacity; } }
|
||||
public bool IsFull { get { return contents.Values.Sum() == Info.Capacity; } }
|
||||
public bool IsEmpty { get { return contents.Values.Sum() == 0; } }
|
||||
public int Fullness { get { return contents.Values.Sum() * 100 / info.Capacity; } }
|
||||
public int Fullness { get { return contents.Values.Sum() * 100 / Info.Capacity; } }
|
||||
|
||||
public void AcceptResource(ResourceType type)
|
||||
{
|
||||
@@ -212,7 +212,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (self.Location == deliveryLoc)
|
||||
{
|
||||
// Get out of the way:
|
||||
var unblockCell = LastHarvestedCell ?? (deliveryLoc + info.UnblockCell);
|
||||
var unblockCell = LastHarvestedCell ?? (deliveryLoc + Info.UnblockCell);
|
||||
var moveTo = mobile.NearestMoveableCell(unblockCell, 1, 5);
|
||||
self.QueueActivity(mobile.MoveTo(moveTo, 1));
|
||||
self.SetTargetLine(Target.FromCell(self.World, moveTo), Color.Gray, false);
|
||||
@@ -287,7 +287,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (--contents[type] == 0)
|
||||
contents.Remove(type);
|
||||
|
||||
currentUnloadTicks = info.UnloadTicksPerBale;
|
||||
currentUnloadTicks = Info.UnloadTicksPerBale;
|
||||
}
|
||||
|
||||
return contents.Count == 0;
|
||||
@@ -318,10 +318,10 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public string VoicePhraseForOrder(Actor self, Order order)
|
||||
{
|
||||
if (order.OrderString == "Harvest")
|
||||
return info.HarvestVoice;
|
||||
return Info.HarvestVoice;
|
||||
|
||||
if (order.OrderString == "Deliver" && !IsEmpty)
|
||||
return info.DeliverVoice;
|
||||
return Info.DeliverVoice;
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -421,7 +421,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
PipType GetPipAt(int i)
|
||||
{
|
||||
var n = i * info.Capacity / info.PipCount;
|
||||
var n = i * Info.Capacity / Info.PipCount;
|
||||
|
||||
foreach (var rt in contents)
|
||||
if (n < rt.Value)
|
||||
@@ -434,7 +434,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<PipType> GetPips(Actor self)
|
||||
{
|
||||
var numPips = info.PipCount;
|
||||
var numPips = Info.PipCount;
|
||||
|
||||
for (var i = 0; i < numPips; i++)
|
||||
yield return GetPipAt(i);
|
||||
@@ -444,7 +444,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public int GetSpeedModifier()
|
||||
{
|
||||
return 100 - (100 - info.FullyLoadedSpeed) * contents.Values.Sum() / info.Capacity;
|
||||
return 100 - (100 - Info.FullyLoadedSpeed) * contents.Values.Sum() / Info.Capacity;
|
||||
}
|
||||
|
||||
class HarvestOrderTargeter : IOrderTargeter
|
||||
|
||||
@@ -15,22 +15,11 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("Actor can capture ProximityCapturable actors.")]
|
||||
public class ProximityCaptorInfo : ITraitInfo
|
||||
public class ProximityCaptorInfo : TraitInfo<ProximityCaptor>
|
||||
{
|
||||
[FieldLoader.Require]
|
||||
public readonly HashSet<string> Types = new HashSet<string>();
|
||||
public object Create(ActorInitializer init) { return new ProximityCaptor(this); }
|
||||
}
|
||||
|
||||
public class ProximityCaptor
|
||||
{
|
||||
public readonly ProximityCaptorInfo Info;
|
||||
|
||||
public ProximityCaptor(ProximityCaptorInfo info) { Info = info; }
|
||||
|
||||
public bool HasAny(IEnumerable<string> typesList)
|
||||
{
|
||||
return Info.Types.Overlaps(typesList);
|
||||
}
|
||||
}
|
||||
public class ProximityCaptor { }
|
||||
}
|
||||
|
||||
@@ -105,8 +105,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
bool CanBeCapturedBy(Actor a)
|
||||
{
|
||||
var pc = a.TraitOrDefault<ProximityCaptor>();
|
||||
return pc != null && pc.HasAny(Info.CaptorTypes);
|
||||
var pc = a.Info.Traits.GetOrDefault<ProximityCaptorInfo>();
|
||||
return pc != null && pc.Types.Overlaps(Info.CaptorTypes);
|
||||
}
|
||||
|
||||
IEnumerable<Actor> UnitsInRange()
|
||||
|
||||
@@ -12,24 +12,14 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public class WithDockingAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>, Requires<HarvesterInfo>
|
||||
public class WithDockingAnimationInfo : TraitInfo<WithDockingAnimation>, Requires<WithSpriteBodyInfo>, Requires<HarvesterInfo>
|
||||
{
|
||||
[Desc("Displayed when docking to refinery.")]
|
||||
[SequenceReference] public readonly string DockSequence = "dock";
|
||||
|
||||
[Desc("Looped while unloading at refinery.")]
|
||||
[SequenceReference] public readonly string DockLoopSequence = "dock-loop";
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithDockingAnimation(init, this); }
|
||||
}
|
||||
|
||||
public class WithDockingAnimation
|
||||
{
|
||||
public readonly WithDockingAnimationInfo Info;
|
||||
|
||||
public WithDockingAnimation(ActorInitializer init, WithDockingAnimationInfo info)
|
||||
{
|
||||
Info = info;
|
||||
}
|
||||
}
|
||||
public class WithDockingAnimation { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user