more ported bits

This commit is contained in:
Chris Forbes
2010-01-10 19:11:58 +13:00
parent e7f9023aca
commit 8e944871fa
11 changed files with 51 additions and 21 deletions

View File

@@ -15,7 +15,8 @@ namespace OpenRa.Game.Effects
public Corpse(Actor fromActor, int death)
{
anim = new Animation(fromActor.LegacyInfo.Image ?? fromActor.LegacyInfo.Name);
var info = fromActor.Info.Traits.WithInterface<RenderSimpleInfo>().First();
anim = new Animation(info.Image ?? fromActor.Info.Name);
anim.PlayThen("die{0}".F(death + 1),
() => Game.world.AddFrameEndTask(w => w.Remove(this)));

View File

@@ -10,9 +10,13 @@ namespace OpenRa.Game.GameRules
{
public readonly string Parent;
public readonly TypeDictionary Traits = new TypeDictionary();
public readonly string Name;
public NewUnitInfo( MiniYaml node )
public NewUnitInfo( string name, MiniYaml node )
{
Name = name;
// todo: make inheritance actually work
MiniYaml inherit;
if( node.Nodes.TryGetValue( "Inherits", out inherit ) )
{

View File

@@ -97,7 +97,7 @@ namespace OpenRa.Game
NewUnitInfo = new Dictionary<string, NewUnitInfo>();
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.Key.ToLowerInvariant(), kv.Value));
}
static void LoadCategories(params string[] types)

View File

@@ -15,7 +15,8 @@ namespace OpenRa.Game.Traits
float GetMaximumRange(Actor self)
{
return new[] { self.LegacyInfo.Primary, self.LegacyInfo.Secondary }
var info = self.Info.Traits.WithInterface<AttackBaseInfo>().First();
return new[] { info.PrimaryWeapon, info.SecondaryWeapon }
.Where(w => w != null)
.Max(w => Rules.WeaponInfo[w].Range);
}

View File

@@ -17,14 +17,14 @@ namespace OpenRa.Game.Traits
public LimitedAmmo(Actor self)
{
ammo = self.LegacyInfo.Ammo;
ammo = self.Info.Traits.Get<LimitedAmmoInfo>().Ammo;
this.self = self;
}
public bool HasAmmo() { return ammo > 0; }
public bool GiveAmmo()
{
if (ammo >= self.LegacyInfo.Ammo) return false;
if (ammo >= self.Info.Traits.Get<LimitedAmmoInfo>().Ammo) return false;
++ammo;
return true;
}
@@ -33,7 +33,8 @@ namespace OpenRa.Game.Traits
public IEnumerable<PipType> GetPips(Actor self)
{
return Graphics.Util.MakeArray(self.LegacyInfo.Ammo,
var maxAmmo = self.Info.Traits.Get<LimitedAmmoInfo>().Ammo;
return Graphics.Util.MakeArray(maxAmmo,
i => ammo > i ? PipType.Green : PipType.Transparent);
}
}

View File

@@ -15,8 +15,6 @@ namespace OpenRa.Game.Traits
public RenderUnitMuzzleFlash(Actor self)
: base(self)
{
if (!self.LegacyInfo.MuzzleFlash) throw new InvalidOperationException("wtf??");
var unit = self.traits.Get<Unit>();
var attack = self.traits.WithInterface<AttackBase>().First();

View File

@@ -4,6 +4,9 @@ namespace OpenRa.Game.Traits
{
class RenderUnitRotorInfo : RenderUnitInfo
{
public readonly int[] PrimaryOffset = { 0, 0 };
public readonly int[] SecondaryOffset = null;
public override object Create(Actor self) { return new RenderUnitRotor(self); }
}
@@ -15,21 +18,22 @@ namespace OpenRa.Game.Traits
: base(self)
{
var unit = self.traits.Get<Unit>();
var info = self.Info.Traits.Get<RenderUnitRotorInfo>();
rotorAnim = new Animation(self.LegacyInfo.Name);
rotorAnim = new Animation(info.Image ?? self.Info.Name);
rotorAnim.PlayRepeating("rotor");
anims.Add( "rotor_1", new AnimationWithOffset(
rotorAnim,
() => Util.GetTurretPosition( self, unit, self.LegacyInfo.RotorOffset, 0 ),
() => Util.GetTurretPosition( self, unit, info.PrimaryOffset, 0 ),
null ) );
if (self.LegacyInfo.RotorOffset2 == null) return;
if (info.SecondaryOffset == null) return;
secondRotorAnim = new Animation( self.LegacyInfo.Name );
secondRotorAnim = new Animation(info.Image ?? self.Info.Name);
secondRotorAnim.PlayRepeating( "rotor2" );
anims.Add( "rotor_2", new AnimationWithOffset(
secondRotorAnim,
() => Util.GetTurretPosition(self, unit, self.LegacyInfo.RotorOffset2, 0),
() => Util.GetTurretPosition(self, unit, info.SecondaryOffset, 0),
null ) );
}

View File

@@ -1,10 +1,12 @@
using System.Collections.Generic;
using System.Linq;
using OpenRa.Game.Graphics;
namespace OpenRa.Game.Traits
{
class RenderUnitSpinnerInfo : RenderUnitInfo
{
public readonly int[] Offset = { 0, 0 };
public override object Create(Actor self) { return new RenderUnitSpinner(self); }
}
@@ -14,12 +16,13 @@ namespace OpenRa.Game.Traits
: base(self)
{
var unit = self.traits.Get<Unit>();
var info = self.Info.Traits.Get<RenderUnitSpinnerInfo>();
var spinnerAnim = new Animation( self.LegacyInfo.Name );
var spinnerAnim = new Animation( info.Image ?? self.Info.Name );
spinnerAnim.PlayRepeating( "spinner" );
anims.Add( "spinner", new AnimationWithOffset(
spinnerAnim,
() => Util.GetTurretPosition( self, unit, self.LegacyInfo.PrimaryOffset, 0 ),
() => Util.GetTurretPosition( self, unit, info.Offset, 0 ),
null ) );
}
}

View File

@@ -1,8 +1,12 @@

using System.Linq;
namespace OpenRa.Game.Traits
{
class TurretedInfo : ITraitInfo
{
public readonly int ROT = 0;
public readonly int InitialFacing = 128;
public object Create(Actor self) { return new Turreted(self); }
}
@@ -14,13 +18,13 @@ namespace OpenRa.Game.Traits
public Turreted(Actor self)
{
turretFacing = self.LegacyInfo.InitialFacing;
turretFacing = self.Info.Traits.Get<TurretedInfo>().InitialFacing;
}
public void Tick( Actor self )
{
var df = desiredFacing ?? ( self.traits.Contains<Unit>() ? self.traits.Get<Unit>().Facing : turretFacing );
Util.TickFacing( ref turretFacing, df, self.LegacyInfo.ROT );
Util.TickFacing(ref turretFacing, df, self.Info.Traits.Get<TurretedInfo>().ROT);
}
}
}

View File

@@ -70,6 +70,17 @@ namespace RulesConverter
{ "Image", "Image" } }
},
{ "RenderUnitSpinner", new PL {
{ "Image", "Image" },
{ "Offset", "PrimaryOffset" } }
},
{ "RenderUnitRotor", new PL {
{ "Image", "Image" },
{ "PrimaryOffset", "RotorOffset" },
{ "SecondaryOffset", "RotorOffset2" } }
},
{ "Buildable", new PL {
{ "TechLevel", "TechLevel" },
{ "Tab", "$Tab" },
@@ -136,8 +147,6 @@ namespace RulesConverter
traitMap["RenderInfantry"] = traitMap["RenderBuilding"];
traitMap["RenderUnitMuzzleFlash"] = traitMap["RenderBuilding"];
traitMap["RenderUnitReload"] = traitMap["RenderBuilding"];
traitMap["RenderUnitRotor"] = traitMap["RenderBuilding"];
traitMap["RenderUnitSpinner"] = traitMap["RenderBuilding"];
traitMap["RenderUnitTurreted"] = traitMap["RenderBuilding"];
traitMap["AttackTurreted"] = traitMap["AttackBase"];

View File

@@ -175,6 +175,7 @@ MRJ:
ROT: 5
Speed: 9
RenderUnitSpinner:
Offset: 0,4,0,-6
Repairable:
Chronoshiftable:
Passenger:
@@ -202,6 +203,7 @@ MGG:
ROT: 5
Speed: 9
RenderUnitSpinner:
Offset: 0,6,0,-3
Repairable:
Chronoshiftable:
Passenger:
@@ -624,6 +626,8 @@ TRAN:
ROT: 5
Speed: 12
RenderUnitRotor:
PrimaryOffset: 0,14,0,-4
SecondaryOffset: 0,-14,0,-2
WithShadow:
Cargo:
PassengerTypes: Foot
@@ -653,6 +657,7 @@ HELI:
ROT: 4
Speed: 16
RenderUnitRotor:
PrimaryOffset: 0,0,0,-2
WithShadow:
LimitedAmmo:
Ammo: 6