Skip to content

Commit

Permalink
Merge pull request OpenRA#8586 from atlimit8/UpgradeManagerAfterIUpgr…
Browse files Browse the repository at this point in the history
…adables

UpgradeManager after IUpgradables
  • Loading branch information
Mailaender committed Jun 28, 2015
2 parents 7616fd1 + a9908bf commit f65df39
Show file tree
Hide file tree
Showing 26 changed files with 53 additions and 46 deletions.
4 changes: 2 additions & 2 deletions OpenRA.Mods.Cnc/Traits/PoisonedByTiberium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

namespace OpenRA.Mods.Cnc.Traits
{
class PoisonedByTiberiumInfo : UpgradableTraitInfo, ITraitInfo
class PoisonedByTiberiumInfo : UpgradableTraitInfo
{
[WeaponReference] public readonly string Weapon = "Tiberium";
public readonly string[] Resources = { "Tiberium", "BlueTiberium" };

public object Create(ActorInitializer init) { return new PoisonedByTiberium(this); }
public override object Create(ActorInitializer init) { return new PoisonedByTiberium(this); }
}

class PoisonedByTiberium : UpgradableTrait<PoisonedByTiberiumInfo>, ITick, ISync
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Armament.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Barrel
}

[Desc("Allows you to attach weapons to the unit (use @IdentifierSuffix for > 1)")]
public class ArmamentInfo : UpgradableTraitInfo, ITraitInfo, Requires<AttackBaseInfo>
public class ArmamentInfo : UpgradableTraitInfo, Requires<AttackBaseInfo>
{
public readonly string Name = "primary";

Expand Down Expand Up @@ -62,7 +62,7 @@ public class ArmamentInfo : UpgradableTraitInfo, ITraitInfo, Requires<AttackBase
[Desc("Use multiple muzzle images if non-zero")]
public readonly int MuzzleSplitFacings = 0;

public object Create(ActorInitializer init) { return new Armament(init.Self, this); }
public override object Create(ActorInitializer init) { return new Armament(init.Self, this); }
}

public class Armament : UpgradableTrait<ArmamentInfo>, ITick, IExplodeModifier
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Attack/AttackBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public abstract class AttackBaseInfo : UpgradableTraitInfo, ITraitInfo

[VoiceReference] public readonly string Voice = "Action";

public abstract object Create(ActorInitializer init);
public override abstract object Create(ActorInitializer init);
}

public abstract class AttackBase : UpgradableTrait<AttackBaseInfo>, IIssueOrder, IResolveOrder, IOrderVoice, ISync
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Buildings/RepairableBuilding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Building can be repaired by the repair button.")]
public class RepairableBuildingInfo : UpgradableTraitInfo, ITraitInfo, Requires<HealthInfo>
public class RepairableBuildingInfo : UpgradableTraitInfo, Requires<HealthInfo>
{
public readonly int RepairPercent = 20;
public readonly int RepairInterval = 24;
Expand All @@ -34,7 +34,7 @@ public class RepairableBuildingInfo : UpgradableTraitInfo, ITraitInfo, Requires<
[Desc("Suffixed by the interal repairing player name.")]
public readonly string IndicatorPalettePrefix = "player";

public object Create(ActorInitializer init) { return new RepairableBuilding(init.Self, this); }
public override object Create(ActorInitializer init) { return new RepairableBuilding(init.Self, this); }
}

public class RepairableBuilding : UpgradableTrait<RepairableBuildingInfo>, ITick
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Cloak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("This unit can cloak and uncloak in specific situations.")]
public class CloakInfo : UpgradableTraitInfo, ITraitInfo
public class CloakInfo : UpgradableTraitInfo
{
[Desc("Measured in game ticks.")]
public readonly int InitialDelay = 10;
Expand All @@ -38,7 +38,7 @@ public class CloakInfo : UpgradableTraitInfo, ITraitInfo

public readonly string[] CloakTypes = { "Cloak" };

public object Create(ActorInitializer init) { return new Cloak(init.Self, this); }
public override object Create(ActorInitializer init) { return new Cloak(init.Self, this); }
}

public class Cloak : UpgradableTrait<CloakInfo>, IRenderModifier, INotifyDamageStateChanged, INotifyAttack, ITick, IVisibilityModifier, IRadarColorModifier
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/DetectCloaked.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Actor can reveal Cloak actors in a specified range.")]
public class DetectCloakedInfo : UpgradableTraitInfo, ITraitInfo
public class DetectCloakedInfo : UpgradableTraitInfo
{
[Desc("Specific cloak classifications I can reveal.")]
public readonly string[] CloakTypes = { "Cloak" };

[Desc("Measured in cells.")]
public readonly int Range = 5;

public object Create(ActorInitializer init) { return new DetectCloaked(this); }
public override object Create(ActorInitializer init) { return new DetectCloaked(this); }
}

public class DetectCloaked : UpgradableTrait<DetectCloakedInfo>
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/KillsSelf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

namespace OpenRA.Mods.Common.Traits
{
class KillsSelfInfo : UpgradableTraitInfo, ITraitInfo
class KillsSelfInfo : UpgradableTraitInfo
{
[Desc("Remove the actor from the world (and destroy it) instead of killing it.")]
public readonly bool RemoveInstead = false;

public object Create(ActorInitializer init) { return new KillsSelf(this); }
public override object Create(ActorInitializer init) { return new KillsSelf(this); }
}

class KillsSelf : UpgradableTrait<KillsSelfInfo>, INotifyAddedToWorld
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Modifiers/UpgradeOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Display a colored overlay when a timed upgrade is active.")]
public class UpgradeOverlayInfo : UpgradableTraitInfo, ITraitInfo
public class UpgradeOverlayInfo : UpgradableTraitInfo
{
[Desc("Palette to use when rendering the overlay")]
public readonly string Palette = "invuln";

public object Create(ActorInitializer init) { return new UpgradeOverlay(this); }
public override object Create(ActorInitializer init) { return new UpgradeOverlay(this); }
}

public class UpgradeOverlay : UpgradableTrait<UpgradeOverlayInfo>, IRenderModifier
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Power/CanPowerDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("The player can disable the power individually on this actor.")]
public class CanPowerDownInfo : UpgradableTraitInfo, ITraitInfo, Requires<PowerInfo>
public class CanPowerDownInfo : UpgradableTraitInfo, Requires<PowerInfo>
{
[Desc("Restore power when this trait is disabled.")]
public readonly bool CancelWhenDisabled = false;
Expand All @@ -24,7 +24,7 @@ public class CanPowerDownInfo : UpgradableTraitInfo, ITraitInfo, Requires<PowerI

public readonly string IndicatorPalette = "chrome";

public object Create(ActorInitializer init) { return new CanPowerDown(init.Self, this); }
public override object Create(ActorInitializer init) { return new CanPowerDown(init.Self, this); }
}

public class CanPowerDown : UpgradableTrait<CanPowerDownInfo>, IPowerModifier, IResolveOrder, IDisable, INotifyOwnerChanged
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Power/Power.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

namespace OpenRA.Mods.Common.Traits
{
public class PowerInfo : UpgradableTraitInfo, ITraitInfo
public class PowerInfo : UpgradableTraitInfo
{
[Desc("If negative, it will drain power. If positive, it will provide power.")]
public readonly int Amount = 0;

public object Create(ActorInitializer init) { return new Power(init.Self, this); }
public override object Create(ActorInitializer init) { return new Power(init.Self, this); }
}

public class Power : UpgradableTrait<PowerInfo>, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyOwnerChanged
Expand Down
5 changes: 4 additions & 1 deletion OpenRA.Mods.Common/Traits/Render/TimedUpgradeBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TimedUpgradeBarInfo : ITraitInfo, Requires<UpgradeManagerInfo>
public object Create(ActorInitializer init) { return new TimedUpgradeBar(init.Self, this); }
}

class TimedUpgradeBar : ISelectionBar
class TimedUpgradeBar : ISelectionBar, INotifyCreated
{
readonly TimedUpgradeBarInfo info;
readonly Actor self;
Expand All @@ -36,7 +36,10 @@ public TimedUpgradeBar(Actor self, TimedUpgradeBarInfo info)
{
this.self = self;
this.info = info;
}

public void Created(Actor self)
{
self.Trait<UpgradeManager>().RegisterWatcher(info.Upgrade, Update);
}

Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Render/WithDecoration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum ReferencePoints
}

[Desc("Displays a custom animation if conditions are satisfied.")]
public class WithDecorationInfo : UpgradableTraitInfo, ITraitInfo
public class WithDecorationInfo : UpgradableTraitInfo
{
[Desc("Image used for this decoration. Defaults to the actor's type.")]
public readonly string Image = null;
Expand Down Expand Up @@ -58,7 +58,7 @@ public class WithDecorationInfo : UpgradableTraitInfo, ITraitInfo
[Desc("Should this be visible to enemy players?")]
public readonly bool ShowToEnemies = false;

public virtual object Create(ActorInitializer init) { return new WithDecoration(init.Self, this); }
public override object Create(ActorInitializer init) { return new WithDecoration(init.Self, this); }
}

public class WithDecoration : UpgradableTrait<WithDecorationInfo>, IRender
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Render/WithIdleOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Renders a decorative animation on units and buildings.")]
public class WithIdleOverlayInfo : UpgradableTraitInfo, ITraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
public class WithIdleOverlayInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
{
[Desc("Sequence name to use")]
[SequenceReference] public readonly string Sequence = "idle-overlay";
Expand All @@ -33,7 +33,7 @@ public class WithIdleOverlayInfo : UpgradableTraitInfo, ITraitInfo, IRenderActor

public readonly bool PauseOnLowPower = false;

public object Create(ActorInitializer init) { return new WithIdleOverlay(init.Self, this); }
public override object Create(ActorInitializer init) { return new WithIdleOverlay(init.Self, this); }

public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Render/WithInfantryBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace OpenRA.Mods.Common.Traits
{
public class WithInfantryBodyInfo : UpgradableTraitInfo, ITraitInfo, IQuantizeBodyOrientationInfo, IRenderActorPreviewSpritesInfo,
public class WithInfantryBodyInfo : UpgradableTraitInfo, IQuantizeBodyOrientationInfo, IRenderActorPreviewSpritesInfo,
Requires<IMoveInfo>, Requires<RenderSpritesInfo>
{
public readonly int MinIdleWaitTicks = 30;
Expand All @@ -27,7 +27,7 @@ public class WithInfantryBodyInfo : UpgradableTraitInfo, ITraitInfo, IQuantizeBo
[SequenceReference] public readonly string[] IdleSequences = { };
[SequenceReference] public readonly string[] StandSequences = { "stand" };

public virtual object Create(ActorInitializer init) { return new WithInfantryBody(init, this); }
public override object Create(ActorInitializer init) { return new WithInfantryBody(init, this); }

public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Render/WithMuzzleFlash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Renders the MuzzleSequence from the Armament trait.")]
class WithMuzzleFlashInfo : UpgradableTraitInfo, ITraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>, Requires<ArmamentInfo>
class WithMuzzleFlashInfo : UpgradableTraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>, Requires<ArmamentInfo>
{
[Desc("Ignore the weapon position, and always draw relative to the center of the actor")]
public readonly bool IgnoreOffset = false;

public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.Self, this); }
public override object Create(ActorInitializer init) { return new WithMuzzleFlash(init.Self, this); }
}

class WithMuzzleFlash : UpgradableTrait<WithMuzzleFlashInfo>, INotifyAttack, IRender, ITick
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Render/WithSpriteBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Default trait for rendering sprite-based actors.")]
public class WithSpriteBodyInfo : UpgradableTraitInfo, ITraitInfo, IRenderActorPreviewSpritesInfo, IQuantizeBodyOrientationInfo,
public class WithSpriteBodyInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo, IQuantizeBodyOrientationInfo,
Requires<RenderSpritesInfo>
{
[Desc("Animation to play when the actor is created.")]
Expand All @@ -26,7 +26,7 @@ public class WithSpriteBodyInfo : UpgradableTraitInfo, ITraitInfo, IRenderActorP
[Desc("Animation to play when the actor is idle.")]
[SequenceReference] public readonly string Sequence = "idle";

public virtual object Create(ActorInitializer init) { return new WithSpriteBody(init, this); }
public override object Create(ActorInitializer init) { return new WithSpriteBody(init, this); }

public virtual IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Render/WithTurret.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Renders turrets for units with the Turreted trait.")]
public class WithTurretInfo : UpgradableTraitInfo, ITraitInfo, IRenderActorPreviewSpritesInfo,
public class WithTurretInfo : UpgradableTraitInfo, IRenderActorPreviewSpritesInfo,
Requires<RenderSpritesInfo>, Requires<TurretedInfo>, Requires<IBodyOrientationInfo>
{
[Desc("Sequence name to use")]
Expand All @@ -32,7 +32,7 @@ public class WithTurretInfo : UpgradableTraitInfo, ITraitInfo, IRenderActorPrevi
[Desc("Render recoil")]
public readonly bool Recoils = true;

public object Create(ActorInitializer init) { return new WithTurret(init.Self, this); }
public override object Create(ActorInitializer init) { return new WithTurret(init.Self, this); }

public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/SelfHealing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Attach this to actors which should be able to regenerate their health points.")]
class SelfHealingInfo : UpgradableTraitInfo, ITraitInfo, Requires<HealthInfo>
class SelfHealingInfo : UpgradableTraitInfo, Requires<HealthInfo>
{
public readonly int Step = 5;
public readonly int Ticks = 5;
public readonly float HealIfBelow = .5f;
public readonly int DamageCooldown = 0;

public virtual object Create(ActorInitializer init) { return new SelfHealing(init.Self, this); }
public override object Create(ActorInitializer init) { return new SelfHealing(init.Self, this); }
}

class SelfHealing : UpgradableTrait<SelfHealingInfo>, ITick, INotifyDamage
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Sellable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Actor can be sold")]
public class SellableInfo : UpgradableTraitInfo, ITraitInfo
public class SellableInfo : UpgradableTraitInfo
{
public readonly int RefundPercent = 50;
public readonly string[] SellSounds = { };

public object Create(ActorInitializer init) { return new Sellable(init.Self, this); }
public override object Create(ActorInitializer init) { return new Sellable(init.Self, this); }
}

public class Sellable : UpgradableTrait<SellableInfo>, IResolveOrder, IProvideTooltipInfo
Expand Down
3 changes: 1 addition & 2 deletions OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace OpenRA.Mods.Common.Traits
{
public abstract class SupportPowerInfo : UpgradableTraitInfo, ITraitInfo
public abstract class SupportPowerInfo : UpgradableTraitInfo
{
[Desc("Measured in seconds.")]
public readonly int ChargeTime = 0;
Expand Down Expand Up @@ -54,7 +54,6 @@ public abstract class SupportPowerInfo : UpgradableTraitInfo, ITraitInfo
public readonly int RadarPingDuration = 5 * 25;

public readonly string OrderName;
public abstract object Create(ActorInitializer init);

public SupportPowerInfo() { OrderName = GetType().Name + "Order"; }
}
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.Common/Traits/Upgrades/DisableUpgrade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

namespace OpenRA.Mods.Common.Traits
{
public class DisableUpgradeInfo : UpgradableTraitInfo, ITraitInfo
public class DisableUpgradeInfo : UpgradableTraitInfo
{
public object Create(ActorInitializer init) { return new DisableUpgrade(this); }
public override object Create(ActorInitializer init) { return new DisableUpgrade(this); }
}

public class DisableUpgrade : UpgradableTrait<DisableUpgradeInfo>, IDisable, IDisableMove
Expand Down
4 changes: 3 additions & 1 deletion OpenRA.Mods.Common/Traits/Upgrades/UpgradableTrait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace OpenRA.Mods.Common.Traits
{
/// <summary>Use as base class for *Info to subclass of UpgradableTrait. (See UpgradableTrait.)</summary>
public abstract class UpgradableTraitInfo
public abstract class UpgradableTraitInfo : IUpgradableInfo
{
[UpgradeUsedReference]
[Desc("The upgrade types which can enable or disable this trait.")]
Expand All @@ -32,6 +32,8 @@ public abstract class UpgradableTraitInfo

[Desc("The maximum upgrade level that this trait will accept.")]
public readonly int UpgradeMaxAcceptedLevel = 1;

public abstract object Create(ActorInitializer init);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Traits/Upgrades/UpgradeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace OpenRA.Mods.Common.Traits
{
[Desc("Attach this to a unit to enable dynamic upgrades by warheads, experience, crates, support powers, etc.")]
public class UpgradeManagerInfo : ITraitInfo
public class UpgradeManagerInfo : ITraitInfo, Requires<IUpgradableInfo>
{
public object Create(ActorInitializer init) { return new UpgradeManager(init); }
}
Expand Down
3 changes: 3 additions & 0 deletions OpenRA.Mods.Common/TraitsInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public interface IUpgradable
void UpgradeLevelChanged(Actor self, string type, int oldLevel, int newLevel);
}

// Implement to construct before UpgradeManager
public interface IUpgradableInfo : ITraitInfo { }

public interface INotifyHarvesterAction
{
void MovingToResources(Actor self, CPos targetCell, Activity next);
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.D2k/Traits/AttractsWorms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace OpenRA.Mods.D2k.Traits
{
[Desc("This actor makes noise, which causes them to be targeted by actors with the Sandworm trait.")]
public class AttractsWormsInfo : UpgradableTraitInfo, ITraitInfo
public class AttractsWormsInfo : UpgradableTraitInfo
{
[Desc("How much noise this actor produces.")]
public readonly int Intensity = 0;
Expand All @@ -28,7 +28,7 @@ public class AttractsWormsInfo : UpgradableTraitInfo, ITraitInfo
[Desc("Ranges at which each Falloff step is defined. Overrides Spread.")]
public WRange[] Range = null;

public object Create(ActorInitializer init) { return new AttractsWorms(init, this); }
public override object Create(ActorInitializer init) { return new AttractsWorms(init, this); }
}

public class AttractsWorms : UpgradableTrait<AttractsWormsInfo>
Expand Down
Loading

0 comments on commit f65df39

Please sign in to comment.