ITraitInfo, plumbing in NewUnitInfo
This commit is contained in:
@@ -16,6 +16,15 @@ namespace OpenRa.Game.GameRules
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Load(object self, MiniYaml my)
|
||||||
|
{
|
||||||
|
foreach (var x in my.Nodes)
|
||||||
|
{
|
||||||
|
var field = self.GetType().GetField(x.Key.Trim());
|
||||||
|
field.SetValue(self, GetValue(field.FieldType, x.Value.Value.Trim()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void CheckYaml( object self, Dictionary<string, MiniYaml> d )
|
public static void CheckYaml( object self, Dictionary<string, MiniYaml> d )
|
||||||
{
|
{
|
||||||
//foreach( var x in d )
|
//foreach( var x in d )
|
||||||
|
|||||||
@@ -2,13 +2,14 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
|
using OpenRa.Game.Traits;
|
||||||
|
|
||||||
namespace OpenRa.Game.GameRules
|
namespace OpenRa.Game.GameRules
|
||||||
{
|
{
|
||||||
class NewUnitInfo
|
class NewUnitInfo
|
||||||
{
|
{
|
||||||
public readonly string Parent;
|
public readonly string Parent;
|
||||||
public readonly Dictionary<string, MiniYaml> Traits = new Dictionary<string, MiniYaml>();
|
public readonly Dictionary<string, ITraitInfo> Traits;
|
||||||
|
|
||||||
public NewUnitInfo( MiniYaml node )
|
public NewUnitInfo( MiniYaml node )
|
||||||
{
|
{
|
||||||
@@ -18,7 +19,22 @@ namespace OpenRa.Game.GameRules
|
|||||||
Parent = inherit.Value;
|
Parent = inherit.Value;
|
||||||
node.Nodes.Remove( "Inherits" );
|
node.Nodes.Remove( "Inherits" );
|
||||||
}
|
}
|
||||||
Traits = node.Nodes;
|
|
||||||
|
Traits = node.Nodes.ToDictionary(
|
||||||
|
a => a.Key,
|
||||||
|
a => LoadTraitInfo( a.Key, a.Value ));
|
||||||
|
}
|
||||||
|
|
||||||
|
static ITraitInfo LoadTraitInfo(string traitName, MiniYaml my)
|
||||||
|
{
|
||||||
|
var fullTypeName = typeof(ITraitInfo).Namespace + "." + traitName + "Info";
|
||||||
|
var info = (ITraitInfo)typeof(ITraitInfo).Assembly.CreateInstance(fullTypeName);
|
||||||
|
|
||||||
|
if (info == null)
|
||||||
|
throw new NotImplementedException("Missing traitinfo type `{0}`".F(fullTypeName));
|
||||||
|
|
||||||
|
FieldLoader.Load(info, my);
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using IjwFramework.Types;
|
using IjwFramework.Types;
|
||||||
using OpenRa.FileFormats;
|
using OpenRa.FileFormats;
|
||||||
using OpenRa.Game.GameRules;
|
using OpenRa.Game.GameRules;
|
||||||
|
using OpenRa.Game.Traits;
|
||||||
|
|
||||||
namespace OpenRa.Game
|
namespace OpenRa.Game
|
||||||
{
|
{
|
||||||
@@ -97,10 +98,6 @@ namespace OpenRa.Game
|
|||||||
NewUnitInfo = new Dictionary<string, NewUnitInfo>();
|
NewUnitInfo = new Dictionary<string, NewUnitInfo>();
|
||||||
foreach( var kv in MiniYaml.FromFile( "ra.yaml" ) )
|
foreach( var kv in MiniYaml.FromFile( "ra.yaml" ) )
|
||||||
NewUnitInfo.Add( kv.Key.ToLowerInvariant(), new NewUnitInfo( kv.Value ) );
|
NewUnitInfo.Add( kv.Key.ToLowerInvariant(), new NewUnitInfo( kv.Value ) );
|
||||||
|
|
||||||
foreach( var unit in NewUnitInfo )
|
|
||||||
foreach( var trait in unit.Value.Traits.Values )
|
|
||||||
FieldLoader.CheckYaml( UnitInfo[ unit.Key.ToLowerInvariant() ], trait.Nodes );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadCategories(params string[] types)
|
static void LoadCategories(params string[] types)
|
||||||
|
|||||||
@@ -67,16 +67,16 @@ namespace OpenRa.Game.GameRules
|
|||||||
public UnitInfo(string name) { Name = name; }
|
public UnitInfo(string name) { Name = name; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MobileInfo : UnitInfo
|
public class LegacyMobileInfo : UnitInfo
|
||||||
{
|
{
|
||||||
public readonly int Speed = 0;
|
public readonly int Speed = 0;
|
||||||
public readonly bool NoMovingFire = false;
|
public readonly bool NoMovingFire = false;
|
||||||
public readonly string Voice = "GenericVoice";
|
public readonly string Voice = "GenericVoice";
|
||||||
|
|
||||||
public MobileInfo(string name) : base(name) { }
|
public LegacyMobileInfo(string name) : base(name) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InfantryInfo : MobileInfo
|
public class InfantryInfo : LegacyMobileInfo
|
||||||
{
|
{
|
||||||
public readonly bool C4 = false;
|
public readonly bool C4 = false;
|
||||||
public readonly bool FraidyCat = false;
|
public readonly bool FraidyCat = false;
|
||||||
@@ -87,7 +87,7 @@ namespace OpenRa.Game.GameRules
|
|||||||
public InfantryInfo(string name) : base(name) { }
|
public InfantryInfo(string name) : base(name) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VehicleInfo : MobileInfo
|
public class VehicleInfo : LegacyMobileInfo
|
||||||
{
|
{
|
||||||
public readonly bool Tracked = false;
|
public readonly bool Tracked = false;
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
if (voicedUnit == null) return;
|
if (voicedUnit == null) return;
|
||||||
|
|
||||||
var mi = voicedUnit.Info as MobileInfo;
|
var mi = voicedUnit.Info as LegacyMobileInfo;
|
||||||
if (mi == null) return;
|
if (mi == null) return;
|
||||||
|
|
||||||
var vi = Rules.VoiceInfo[mi.Voice];
|
var vi = Rules.VoiceInfo[mi.Voice];
|
||||||
|
|||||||
@@ -5,6 +5,14 @@ using OpenRa.Game.GameRules;
|
|||||||
|
|
||||||
namespace OpenRa.Game.Traits
|
namespace OpenRa.Game.Traits
|
||||||
{
|
{
|
||||||
|
class MobileInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public readonly int Sight;
|
||||||
|
public readonly int ROT;
|
||||||
|
public readonly int Speed;
|
||||||
|
public object Create(Actor self) { return new Mobile(self); }
|
||||||
|
}
|
||||||
|
|
||||||
class Mobile : IIssueOrder, IResolveOrder, IOccupySpace, IMovement
|
class Mobile : IIssueOrder, IResolveOrder, IOccupySpace, IMovement
|
||||||
{
|
{
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
|
|||||||
@@ -69,4 +69,6 @@ namespace OpenRa.Game.Traits
|
|||||||
public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, newOffset); }
|
public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, newOffset); }
|
||||||
public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, ZOffset); }
|
public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, ZOffset); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ITraitInfo { object Create(Actor self); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ namespace OpenRa.Game.Traits
|
|||||||
|
|
||||||
public static float GetEffectiveSpeed(Actor self)
|
public static float GetEffectiveSpeed(Actor self)
|
||||||
{
|
{
|
||||||
var mi = self.Info as MobileInfo;
|
var mi = self.Info as LegacyMobileInfo;
|
||||||
if (mi == null) return 0f;
|
if (mi == null) return 0f;
|
||||||
|
|
||||||
var modifier = self.traits
|
var modifier = self.traits
|
||||||
|
|||||||
Reference in New Issue
Block a user