Make RenderUnit require IFacing; RenderSimple can be used for crates, mines, etc; fix husk facing init

This commit is contained in:
Chris Forbes
2011-07-28 21:20:31 +12:00
parent 7044d81a40
commit ddc1311d87
11 changed files with 36 additions and 21 deletions

View File

@@ -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]);

View File

@@ -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<Renderable> 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<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
@@ -70,6 +71,11 @@ namespace OpenRA.Traits
Info = self.Info.Traits.Get<RenderSimpleInfo>();
}
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<Renderable> Render(Actor self)

View File

@@ -139,6 +139,8 @@ namespace OpenRA.Traits
int InitialFacing { get; }
}
public interface IFacingInfo {} /* tag interface for infoclasses whose corresponding trait has IFacing */
public interface ICrushable
{
void OnCrush(Actor crusher);
@@ -181,7 +183,7 @@ namespace OpenRA.Traits
public class TraitInfo<T> : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } }
public interface Requires<T> where T : ITraitInfo { }
public interface Requires<T> where T : class { }
public interface INotifySelection { void SelectionChanged(); }
public interface IWorldLoaded { void WorldLoaded(World w); }

View File

@@ -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;

View File

@@ -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]

View File

@@ -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 ); }
}

View File

@@ -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<string, TerrainInfo> TerrainSpeeds;

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render
{
public class RenderUnitInfo : RenderSimpleInfo
public class RenderUnitInfo : RenderSimpleInfo, Requires<IFacingInfo>
{
public override object Create(ActorInitializer init) { return new RenderUnit(init.self); }
}

View File

@@ -190,7 +190,7 @@ CRATE:
SelectionShares: 2
NoBaseSelectionShares: 9001
Unit: mcv
RenderUnit:
RenderSimple:
BelowUnits:
mpspawn:

View File

@@ -267,11 +267,12 @@
Types:Tree
^Husk:
Husk:
RenderUnit:
Health:
HP: 140
Armor:
Type: Heavy
Husk:
Selectable:
Priority: -1
HiddenUnderFog:

View File

@@ -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