From ddc1311d87c0bdd707b02a0f4318c9bebc4d8a0f Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Thu, 28 Jul 2011 21:20:31 +1200 Subject: [PATCH] Make RenderUnit require IFacing; RenderSimple can be used for crates, mines, etc; fix husk facing init --- OpenRA.Game/GameRules/ActorInfo.cs | 2 +- OpenRA.Game/Traits/Render/RenderSimple.cs | 12 +++++++++--- OpenRA.Game/Traits/TraitsInterfaces.cs | 16 +++++++++------- OpenRA.Game/Traits/World/PlayerColorPalette.cs | 2 ++ OpenRA.Mods.RA/Air/Aircraft.cs | 6 +++++- OpenRA.Mods.RA/Husk.cs | 2 +- OpenRA.Mods.RA/Move/Mobile.cs | 2 +- OpenRA.Mods.RA/Render/RenderUnit.cs | 2 +- mods/cnc/rules/system.yaml | 4 ++-- mods/ra/rules/defaults.yaml | 3 ++- mods/ra/rules/system.yaml | 6 +++--- 11 files changed, 36 insertions(+), 21 deletions(-) diff --git a/OpenRA.Game/GameRules/ActorInfo.cs b/OpenRA.Game/GameRules/ActorInfo.cs index 03e4f11769..a1c7f3c48d 100644 --- a/OpenRA.Game/GameRules/ActorInfo.cs +++ b/OpenRA.Game/GameRules/ActorInfo.cs @@ -92,7 +92,7 @@ namespace OpenRA while (t.Count != 0) { var prereqs = PrerequisitesOf(t[index]); - var unsatisfied = prereqs.Where(n => !ret.Any(x => x.GetType() == n || x.GetType().IsSubclassOf(n))); + var unsatisfied = prereqs.Where(n => !ret.Any(x => x.GetType() == n || n.IsAssignableFrom(x.GetType()))); if (!unsatisfied.Any()) { ret.Add(t[index]); diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index 3836e7e747..ab50dc8096 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -14,13 +14,14 @@ using OpenRA.Graphics; namespace OpenRA.Traits { - public abstract class RenderSimpleInfo : ITraitInfo + public class RenderSimpleInfo : ITraitInfo { public readonly string Image = null; public readonly string Palette = null; public readonly string PlayerPalette = "player"; public readonly float Scale = 1f; - public abstract object Create(ActorInitializer init); + + public virtual object Create(ActorInitializer init) { return new RenderSimple(init.self); } public virtual IEnumerable RenderPreview(ActorInfo building, Player owner) { @@ -30,7 +31,7 @@ namespace OpenRA.Traits } } - public abstract class RenderSimple : IRender, ITick + public class RenderSimple : IRender, ITick { public Dictionary anims = new Dictionary(); @@ -70,6 +71,11 @@ namespace OpenRA.Traits Info = self.Info.Traits.Get(); } + public RenderSimple(Actor self) : this( self, MakeFacingFunc(self) ) + { + anim.PlayRepeating("idle"); + } + public string Palette(Player p) { return Info.Palette ?? Info.PlayerPalette + p.InternalName; } public virtual IEnumerable Render(Actor self) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 9320f9204e..c9f6b8ea35 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -132,12 +132,14 @@ namespace OpenRA.Traits public interface IMove : ITeleportable { int Altitude { get; set; } } - public interface IFacing - { - int ROT { get; } - int Facing { get; set; } - int InitialFacing { get; } - } + public interface IFacing + { + int ROT { get; } + int Facing { get; set; } + int InitialFacing { get; } + } + + public interface IFacingInfo {} /* tag interface for infoclasses whose corresponding trait has IFacing */ public interface ICrushable { @@ -181,7 +183,7 @@ namespace OpenRA.Traits public class TraitInfo : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } } - public interface Requires where T : ITraitInfo { } + public interface Requires where T : class { } public interface INotifySelection { void SelectionChanged(); } public interface IWorldLoaded { void WorldLoaded(World w); } diff --git a/OpenRA.Game/Traits/World/PlayerColorPalette.cs b/OpenRA.Game/Traits/World/PlayerColorPalette.cs index f265db256b..4a7fd863ff 100644 --- a/OpenRA.Game/Traits/World/PlayerColorPalette.cs +++ b/OpenRA.Game/Traits/World/PlayerColorPalette.cs @@ -10,6 +10,7 @@ using OpenRA.FileFormats; using OpenRA.Graphics; + namespace OpenRA.Traits { public class PlayerColorPaletteInfo : ITraitInfo @@ -25,6 +26,7 @@ namespace OpenRA.Traits { readonly Player owner; readonly PlayerColorPaletteInfo info; + public PlayerColorPalette( Player owner, PlayerColorPaletteInfo info ) { this.owner = owner; diff --git a/OpenRA.Mods.RA/Air/Aircraft.cs b/OpenRA.Mods.RA/Air/Aircraft.cs index c5bc816ab7..06777b73f8 100755 --- a/OpenRA.Mods.RA/Air/Aircraft.cs +++ b/OpenRA.Mods.RA/Air/Aircraft.cs @@ -23,6 +23,7 @@ namespace OpenRA.Mods.RA.Air { public object Create(ActorInitializer init) { return new DebugAircraftFacing(init.self); } } + public class DebugAircraftFacing : ISync { readonly Aircraft a; @@ -34,6 +35,7 @@ namespace OpenRA.Mods.RA.Air { public object Create(ActorInitializer init) { return new DebugAircraftSubPxX(init.self); } } + public class DebugAircraftSubPxX : ISync { readonly Aircraft a; @@ -45,6 +47,7 @@ namespace OpenRA.Mods.RA.Air { public object Create(ActorInitializer init) { return new DebugAircraftSubPxY(init.self); } } + public class DebugAircraftSubPxY : ISync { readonly Aircraft a; @@ -56,6 +59,7 @@ namespace OpenRA.Mods.RA.Air { public object Create(ActorInitializer init) { return new DebugAircraftAltitude(init.self); } } + public class DebugAircraftAltitude : ISync { readonly Aircraft a; @@ -63,7 +67,7 @@ namespace OpenRA.Mods.RA.Air [Sync] public int foo { get { return a.Altitude; } } } - public class AircraftInfo : ITraitInfo + public class AircraftInfo : ITraitInfo, IFacingInfo { public readonly int CruiseAltitude = 30; [ActorReference] diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index d25fcbfe63..23736981fa 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -16,7 +16,7 @@ using OpenRA.Traits.Activities; namespace OpenRA.Mods.RA { - class HuskInfo : ITraitInfo + class HuskInfo : ITraitInfo, IFacingInfo { public object Create( ActorInitializer init ) { return new Husk( init ); } } diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index c711ab30c5..e00939fa59 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -19,7 +19,7 @@ using OpenRA.Traits.Activities; namespace OpenRA.Mods.RA.Move { - public class MobileInfo : ITraitInfo + public class MobileInfo : ITraitInfo, IFacingInfo { [FieldLoader.LoadUsing("LoadSpeeds")] public readonly Dictionary TerrainSpeeds; diff --git a/OpenRA.Mods.RA/Render/RenderUnit.cs b/OpenRA.Mods.RA/Render/RenderUnit.cs index 7b0656cffe..276406c8d9 100644 --- a/OpenRA.Mods.RA/Render/RenderUnit.cs +++ b/OpenRA.Mods.RA/Render/RenderUnit.cs @@ -14,7 +14,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { - public class RenderUnitInfo : RenderSimpleInfo + public class RenderUnitInfo : RenderSimpleInfo, Requires { public override object Create(ActorInitializer init) { return new RenderUnit(init.self); } } diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index 591ddc2fbe..4dbbe78757 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -190,7 +190,7 @@ CRATE: SelectionShares: 2 NoBaseSelectionShares: 9001 Unit: mcv - RenderUnit: + RenderSimple: BelowUnits: mpspawn: @@ -199,4 +199,4 @@ mpspawn: waypoint: Waypoint: - RenderEditorOnly: \ No newline at end of file + RenderEditorOnly: diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index e5d237e64e..7d150a7f5e 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -267,11 +267,12 @@ Types:Tree ^Husk: + Husk: + RenderUnit: Health: HP: 140 Armor: Type: Heavy - Husk: Selectable: Priority: -1 HiddenUnderFog: diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index 7357c0f8cc..38d4c18949 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -205,7 +205,7 @@ MINP: AvoidFriendly: yes Health: HP: 1 - RenderUnit: + RenderSimple: BelowUnits: InvisibleToEnemy: Tooltip: @@ -220,7 +220,7 @@ MINV: AvoidFriendly: yes Health: HP: 1 - RenderUnit: + RenderSimple: BelowUnits: InvisibleToEnemy: Tooltip: @@ -283,7 +283,7 @@ CRATE: GiveUnitCrateAction@4tnk: SelectionShares: 3 Unit: 4tnk - RenderUnit: + RenderSimple: BelowUnits: ProximityCaptor: Types:Crate