diff --git a/OpenRA.Game/ObjectCreator.cs b/OpenRA.Game/ObjectCreator.cs index 51b8fc2ae1..e98043ac67 100755 --- a/OpenRA.Game/ObjectCreator.cs +++ b/OpenRA.Game/ObjectCreator.cs @@ -82,7 +82,15 @@ namespace OpenRA a[ i ] = args[ key ]; } return ctor.Invoke( a ); - } + } + + public IEnumerable GetTypesImplementing() + { + var it = typeof(T); + return ModAssemblies.Select( ma => ma.First ).Distinct() + .SelectMany(ma => ma.GetTypes() + .Where(t => t != it && it.IsAssignableFrom(t))); + } [AttributeUsage( AttributeTargets.Parameter )] public class ParamAttribute : Attribute diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 77e96b28bb..d3e259241e 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -13,229 +13,236 @@ using System.Drawing; using OpenRA.FileFormats; using OpenRA.GameRules; using OpenRA.Graphics; -using OpenRA.Network; - -namespace OpenRA.Traits -{ - // depends on the order of pips in WorldRenderer.cs! - public enum PipType { Transparent, Green, Yellow, Red, Gray }; - public enum TagType { None, Fake, Primary }; - public enum Stance { Enemy, Neutral, Ally }; - - public class AttackInfo - { - public Actor Attacker; - public WarheadInfo Warhead; - public int Damage; - public DamageState DamageState; - public DamageState PreviousDamageState; - public bool DamageStateChanged; - public int PreviousHealth; - public int Health; - } - - public interface ITick { void Tick(Actor self); } - public interface IRender { IEnumerable Render(Actor self); } - - public interface IIssueOrder - { - IEnumerable Orders { get; } - Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ); - } - public interface IOrderTargeter - { - string OrderID { get; } - int OrderPriority { get; } - bool CanTargetActor( Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueue, ref string cursor ); - bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueue, bool forceMove, ref string cursor); - bool IsQueued { get; } - } - public interface IResolveOrder { void ResolveOrder(Actor self, Order order); } - public interface IValidateOrder { bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order); - } - public interface IOrderCursor { string CursorForOrder(Actor self, Order order); } - public interface IOrderVoice { string VoicePhraseForOrder(Actor self, Order order); } - public interface ICustomUnitOrderGenerator : IOrderGenerator {}; - public interface INotifySold { void Selling( Actor self ); void Sold( Actor self ); } - public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } - public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); } - public interface INotifyBuildComplete { void BuildingComplete(Actor self); } - public interface INotifyProduction { void UnitProduced(Actor self, Actor other, int2 exit); } - public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } - public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); } - public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } - public interface IStoreOre { int Capacity { get; }} - public interface IToolTip - { - string Name(); - Player Owner(); - Stance Stance(); - } - - public interface IDisable { bool Disabled { get; } } - public interface IExplodeModifier { bool ShouldExplode(Actor self); } - public interface INudge { void OnNudge(Actor self, Actor nudger); } - - public interface IRadarSignature - { - IEnumerable RadarSignatureCells(Actor self); - Color RadarSignatureColor(Actor self); - } - - public interface IVisibilityModifier { bool IsVisible(Actor self); } - public interface IRadarColorModifier { Color RadarColorOverride(Actor self); } - public interface IHasLocation - { - int2 PxPosition { get; } - } - - public enum SubCell - { - FullCell, - TopLeft, - TopRight, - Center, - BottomLeft, - BottomRight - } - - public interface IOccupySpace : IHasLocation - { - int2 TopLeft { get; } - IEnumerable> OccupiedCells(); - } - - public static class IOccupySpaceExts - { - public static int2 NearestCellTo( this IOccupySpace ios, int2 other ) - { - var nearest = ios.TopLeft; - var nearestDistance = int.MaxValue; - foreach( var cell in ios.OccupiedCells() ) - { - var dist = ( other - cell.First ).LengthSquared; - if( dist < nearestDistance ) - { - nearest = cell.First; - nearestDistance = dist; - } - } - return nearest; - } - } - - public interface INotifyAttack { void Attacking(Actor self, Target target); } - public interface IRenderModifier { IEnumerable ModifyRender(Actor self, IEnumerable r); } - public interface IDamageModifier { float GetDamageModifier(Actor attacker, WarheadInfo warhead); } - public interface ISpeedModifier { decimal GetSpeedModifier(); } - public interface IFirepowerModifier { float GetFirepowerModifier(); } - public interface ISelectionColorModifier { Color GetSelectionColorModifier(Actor self, Color defaultColor); } - public interface IPalette { void InitPalette( WorldRenderer wr ); } - public interface IPaletteModifier { void AdjustPalette(Dictionary b); } - public interface IPips { IEnumerable GetPips(Actor self); } - public interface ITags { IEnumerable GetTags(); } - public interface ISelectionBar { float GetValue(); Color GetColor(); } - - public interface ITeleportable : IHasLocation /* crap name! */ - { - bool CanEnterCell(int2 location); - void SetPosition(Actor self, int2 cell); - void SetPxPosition(Actor self, int2 px); - void AdjustPxPosition(Actor self, int2 px); /* works like SetPxPosition, but visual only */ - } - - public interface IMove : ITeleportable - { - int Altitude { get; set; } - } - - public interface IFacing - { - int ROT { get; } - int Facing { get; set; } - int InitialFacing { get; } - } - - public interface ICrushable - { - void OnCrush(Actor crusher); - IEnumerable CrushClasses { get; } - } - - public struct Renderable - { - public readonly Sprite Sprite; - public readonly float2 Pos; - public readonly string Palette; - public readonly int Z; - public readonly int ZOffset; - public float Scale; - - public Renderable(Sprite sprite, float2 pos, string palette, int z, int zOffset, float scale) - { - Sprite = sprite; - Pos = pos; - Palette = palette; - Z = z; - ZOffset = zOffset; - Scale = scale; /* default */ - } - - public Renderable(Sprite sprite, float2 pos, string palette, int z) - : this(sprite, pos, palette, z, 0, 1f) { } - - public Renderable(Sprite sprite, float2 pos, string palette, int z, float scale) - : this(sprite, pos, palette, z, 0, scale) { } - - public Renderable WithScale(float newScale) { return new Renderable(Sprite, Pos, Palette, Z, ZOffset, newScale); } - public Renderable WithPalette(string newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset, Scale); } - public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, Z, newOffset, Scale); } - public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, Z, ZOffset, Scale); } - } - - public interface ITraitInfo { object Create(ActorInitializer init); } - - public class TraitInfo : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } } - - public interface ITraitPrerequisite where T : ITraitInfo { } - - public interface INotifySelection { void SelectionChanged(); } - public interface IWorldLoaded { void WorldLoaded(World w); } - public interface ICreatePlayers { void CreatePlayers(World w); } - - public interface IBotInfo { string Name { get; } } - public interface IBot - { - void Activate(Player p); - IBotInfo Info { get; } - } - - public interface IActivity - { - IActivity Tick(Actor self); - void Cancel(Actor self); - void Queue(IActivity activity); - IEnumerable GetCurrentPath(); - } - - public interface IRenderOverlay { void Render( WorldRenderer wr ); } - public interface INotifyIdle { void TickIdle(Actor self); } - - public interface IBlocksBullets { } - - public interface IPostRender { void RenderAfterWorld(WorldRenderer wr, Actor self); } - - public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr, Actor self); } - public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); } - public interface IRenderAsTerrain { IEnumerable RenderAsTerrain(Actor self); } - - public interface ITargetable - { - string[] TargetTypes { get; } - IEnumerable TargetableCells( Actor self ); - bool TargetableBy(Actor self, Actor byActor); - } - - public interface INotifyStanceChanged { void StanceChanged(Actor self, Player a, Player b, - Stance oldStance, Stance newStance); } +using OpenRA.Network; +using System; + +namespace OpenRA.Traits +{ + // depends on the order of pips in WorldRenderer.cs! + public enum PipType { Transparent, Green, Yellow, Red, Gray }; + public enum TagType { None, Fake, Primary }; + public enum Stance { Enemy, Neutral, Ally }; + + public class AttackInfo + { + public Actor Attacker; + public WarheadInfo Warhead; + public int Damage; + public DamageState DamageState; + public DamageState PreviousDamageState; + public bool DamageStateChanged; + public int PreviousHealth; + public int Health; + } + + public interface ITick { void Tick(Actor self); } + public interface IRender { IEnumerable Render(Actor self); } + + public interface IIssueOrder + { + IEnumerable Orders { get; } + Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued); + } + + public interface IOrderTargeter + { + string OrderID { get; } + int OrderPriority { get; } + bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueue, ref string cursor); + bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueue, bool forceMove, ref string cursor); + bool IsQueued { get; } + } + + public interface IResolveOrder { void ResolveOrder(Actor self, Order order); } + public interface IValidateOrder { bool OrderValidation(OrderManager orderManager, World world, int clientId, Order order); } + public interface IOrderCursor { string CursorForOrder(Actor self, Order order); } + public interface IOrderVoice { string VoicePhraseForOrder(Actor self, Order order); } + public interface ICustomUnitOrderGenerator : IOrderGenerator { }; + public interface INotifySold { void Selling(Actor self); void Sold(Actor self); } + public interface INotifyDamage { void Damaged(Actor self, AttackInfo e); } + public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); } + public interface INotifyBuildComplete { void BuildingComplete(Actor self); } + public interface INotifyProduction { void UnitProduced(Actor self, Actor other, int2 exit); } + public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } + public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); } + public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } + public interface IStoreOre { int Capacity { get; } } + public interface IToolTip + { + string Name(); + Player Owner(); + Stance Stance(); + } + + public interface IDisable { bool Disabled { get; } } + public interface IExplodeModifier { bool ShouldExplode(Actor self); } + public interface INudge { void OnNudge(Actor self, Actor nudger); } + + public interface IRadarSignature + { + IEnumerable RadarSignatureCells(Actor self); + Color RadarSignatureColor(Actor self); + } + + public interface IVisibilityModifier { bool IsVisible(Actor self); } + public interface IRadarColorModifier { Color RadarColorOverride(Actor self); } + public interface IHasLocation + { + int2 PxPosition { get; } + } + + public enum SubCell + { + FullCell, + TopLeft, + TopRight, + Center, + BottomLeft, + BottomRight + } + + public interface IOccupySpace : IHasLocation + { + int2 TopLeft { get; } + IEnumerable> OccupiedCells(); + } + + public static class IOccupySpaceExts + { + public static int2 NearestCellTo(this IOccupySpace ios, int2 other) + { + var nearest = ios.TopLeft; + var nearestDistance = int.MaxValue; + foreach (var cell in ios.OccupiedCells()) + { + var dist = (other - cell.First).LengthSquared; + if (dist < nearestDistance) + { + nearest = cell.First; + nearestDistance = dist; + } + } + return nearest; + } + } + + public interface INotifyAttack { void Attacking(Actor self, Target target); } + public interface IRenderModifier { IEnumerable ModifyRender(Actor self, IEnumerable r); } + public interface IDamageModifier { float GetDamageModifier(Actor attacker, WarheadInfo warhead); } + public interface ISpeedModifier { decimal GetSpeedModifier(); } + public interface IFirepowerModifier { float GetFirepowerModifier(); } + public interface ISelectionColorModifier { Color GetSelectionColorModifier(Actor self, Color defaultColor); } + public interface IPalette { void InitPalette(WorldRenderer wr); } + public interface IPaletteModifier { void AdjustPalette(Dictionary b); } + public interface IPips { IEnumerable GetPips(Actor self); } + public interface ITags { IEnumerable GetTags(); } + public interface ISelectionBar { float GetValue(); Color GetColor(); } + + public interface ITeleportable : IHasLocation /* crap name! */ + { + bool CanEnterCell(int2 location); + void SetPosition(Actor self, int2 cell); + void SetPxPosition(Actor self, int2 px); + void AdjustPxPosition(Actor self, int2 px); /* works like SetPxPosition, but visual only */ + } + + public interface IMove : ITeleportable + { + int Altitude { get; set; } + } + + public interface IFacing + { + int ROT { get; } + int Facing { get; set; } + int InitialFacing { get; } + } + + public interface ICrushable + { + void OnCrush(Actor crusher); + IEnumerable CrushClasses { get; } + } + + public struct Renderable + { + public readonly Sprite Sprite; + public readonly float2 Pos; + public readonly string Palette; + public readonly int Z; + public readonly int ZOffset; + public float Scale; + + public Renderable(Sprite sprite, float2 pos, string palette, int z, int zOffset, float scale) + { + Sprite = sprite; + Pos = pos; + Palette = palette; + Z = z; + ZOffset = zOffset; + Scale = scale; /* default */ + } + + public Renderable(Sprite sprite, float2 pos, string palette, int z) + : this(sprite, pos, palette, z, 0, 1f) { } + + public Renderable(Sprite sprite, float2 pos, string palette, int z, float scale) + : this(sprite, pos, palette, z, 0, scale) { } + + public Renderable WithScale(float newScale) { return new Renderable(Sprite, Pos, Palette, Z, ZOffset, newScale); } + public Renderable WithPalette(string newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset, Scale); } + public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, Z, newOffset, Scale); } + public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, Z, ZOffset, Scale); } + } + + public interface ITraitInfo { object Create(ActorInitializer init); } + + public class TraitInfo : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } } + + public interface ITraitPrerequisite where T : ITraitInfo { } + + public interface INotifySelection { void SelectionChanged(); } + public interface IWorldLoaded { void WorldLoaded(World w); } + public interface ICreatePlayers { void CreatePlayers(World w); } + + public interface IBotInfo { string Name { get; } } + public interface IBot + { + void Activate(Player p); + IBotInfo Info { get; } + } + + public interface IActivity + { + IActivity Tick(Actor self); + void Cancel(Actor self); + void Queue(IActivity activity); + IEnumerable GetCurrentPath(); + } + + public interface IRenderOverlay { void Render(WorldRenderer wr); } + public interface INotifyIdle { void TickIdle(Actor self); } + + public interface IBlocksBullets { } + + public interface IPostRender { void RenderAfterWorld(WorldRenderer wr, Actor self); } + + public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr, Actor self); } + public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); } + public interface IRenderAsTerrain { IEnumerable RenderAsTerrain(Actor self); } + + public interface ITargetable + { + string[] TargetTypes { get; } + IEnumerable TargetableCells(Actor self); + bool TargetableBy(Actor self, Actor byActor); + } + + public interface INotifyStanceChanged + { + void StanceChanged(Actor self, Player a, Player b, + Stance oldStance, Stance newStance); + } + + public interface ILintPass { void Run(Action emitError); } } diff --git a/OpenRA.Mods.RA/Lint/LintBuildablePrerequisites.cs b/OpenRA.Mods.RA/Lint/LintBuildablePrerequisites.cs new file mode 100644 index 0000000000..1578c25699 --- /dev/null +++ b/OpenRA.Mods.RA/Lint/LintBuildablePrerequisites.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + class LintBuildablePrerequisites : ILintPass + { + public void Run(Action emitError) + { + emitError("Hello World"); + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 8c81333d8c..bb2c2a5109 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -1,4 +1,4 @@ - + Debug @@ -63,6 +63,7 @@ + diff --git a/RALint/RALint.cs b/RALint/RALint.cs index 4d2c10d066..0bbba2643d 100644 --- a/RALint/RALint.cs +++ b/RALint/RALint.cs @@ -29,7 +29,8 @@ namespace RALint } static int Main(string[] args) - { + { + Console.WriteLine("This is teh sucks"); try { // bind some nonfatal error handling into FieldLoader, so we don't just *explode*. @@ -42,7 +43,18 @@ namespace RALint foreach (var actorInfo in Rules.Info) foreach (var traitInfo in actorInfo.Value.Traits.WithInterface()) - CheckTrait(actorInfo.Value, traitInfo); + CheckTrait(actorInfo.Value, traitInfo); + + foreach (var customPassType in Game.modData.ObjectCreator + .GetTypesImplementing()) + { + var customPass = (ILintPass)Game.modData.ObjectCreator + .CreateBasic(customPassType); + + Console.WriteLine("CustomPass: {0}".F(customPassType.ToString())); + + customPass.Run(EmitError); + } if (errors > 0) {