smooth unit-movement. Doesn't look right yet, but it's getting there.

This commit is contained in:
Bob
2009-10-24 18:20:58 +13:00
parent 06e6d50735
commit d66475edcb
3 changed files with 107 additions and 62 deletions

View File

@@ -17,7 +17,7 @@ namespace OpenRa.Game
public readonly UnitInfo unitInfo;
public int2 Location;
public Player Owner;
public Player Owner;
public int Health;
public Actor( string name, int2 location, Player owner )
@@ -25,21 +25,21 @@ namespace OpenRa.Game
unitInfo = Rules.UnitInfo[ name ];
Location = location;
CenterLocation = new float2( 12, 12 ) + Game.CellSize * (float2)Location;
Owner = owner;
Health = unitInfo.Strength; /* todo: handle cases where this is not true! */
if( unitInfo.Traits != null )
{
foreach( var traitName in unitInfo.Traits )
{
var type = typeof( Traits.Mobile ).Assembly.GetType( typeof( Traits.Mobile ).Namespace + "." + traitName, true, false );
var ctor = type.GetConstructor( new[] { typeof( Actor ) } );
traits.Add( type, ctor.Invoke( new object[] { this } ) );
}
}
else
throw new InvalidOperationException( "No Actor traits for " + unitInfo.Name
+ "; add Traits= to units.ini for appropriate unit" );
Owner = owner;
Health = unitInfo.Strength; /* todo: handle cases where this is not true! */
if( unitInfo.Traits != null )
{
foreach( var traitName in unitInfo.Traits )
{
var type = typeof( Traits.Mobile ).Assembly.GetType( typeof( Traits.Mobile ).Namespace + "." + traitName, true, false );
var ctor = type.GetConstructor( new[] { typeof( Actor ) } );
traits.Add( type, ctor.Invoke( new object[] { this } ) );
}
}
else
throw new InvalidOperationException( "No Actor traits for " + unitInfo.Name
+ "; add Traits= to units.ini for appropriate unit" );
}
public Actor( TreeReference tree, TreeCache treeRenderer, int2 mapOffset )
@@ -49,8 +49,8 @@ namespace OpenRa.Game
}
public void Tick()
{
foreach (var tick in traits.WithInterface<Traits.ITick>())
{
foreach (var tick in traits.WithInterface<Traits.ITick>())
tick.Tick(this);
}
@@ -63,8 +63,8 @@ namespace OpenRa.Game
}
public Order Order( int2 xy )
{
if (Owner != Game.LocalPlayer)
{
if (Owner != Game.LocalPlayer)
return null;
return traits.WithInterface<Traits.IOrder>()
@@ -80,32 +80,32 @@ namespace OpenRa.Game
var loc = CenterLocation - 0.5f * size;
return new RectangleF(loc.X, loc.Y, size.X, size.Y);
}
}
public bool IsDead { get { return Health <= 0; } }
public void InflictDamage(Actor attacker, Bullet inflictor, int damage)
{
/* todo: auto-retaliate, etc */
/* todo: death sequence for infantry based on inflictor */
/* todo: start smoking if < conditionYellow and took damage, and not already smoking */
if (Health <= 0) return; /* overkill! don't count extra hits as more kills! */
Health -= damage;
if (Health <= 0)
{
Health = 0;
if (attacker.Owner != null)
attacker.Owner.Kills++;
Game.world.AddFrameEndTask(w => w.Remove(this));
if (Owner == Game.LocalPlayer)
Game.PlaySound("unitlst1.aud", false);
/* todo: explosion */
}
}
public bool IsDead { get { return Health <= 0; } }
public void InflictDamage(Actor attacker, Bullet inflictor, int damage)
{
/* todo: auto-retaliate, etc */
/* todo: death sequence for infantry based on inflictor */
/* todo: start smoking if < conditionYellow and took damage, and not already smoking */
if (Health <= 0) return; /* overkill! don't count extra hits as more kills! */
Health -= damage;
if (Health <= 0)
{
Health = 0;
if (attacker.Owner != null)
attacker.Owner.Kills++;
Game.world.AddFrameEndTask(w => w.Remove(this));
if (Owner == Game.LocalPlayer)
Game.PlaySound("unitlst1.aud", false);
/* todo: explosion */
}
}
}
}