Harvester uses pips to show load

This commit is contained in:
unknown
2009-12-18 15:19:01 -08:00
19 changed files with 149 additions and 67 deletions

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
class AttackInfo
{
public Actor Attacker;
public WarheadInfo Warhead;
public int Damage;
public DamageState DamageState;
public bool DamageStateChanged;
}
}

View File

@@ -3,7 +3,7 @@ using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
class AttackTurreted : AttackBase
class AttackTurreted : AttackBase, INotifyBuildComplete
{
public AttackTurreted( Actor self ) : base(self) { self.traits.Get<Turreted>(); }
@@ -13,6 +13,9 @@ namespace OpenRa.Game.Traits
if( !CanAttack( self ) ) return;
if (self.traits.Contains<Building>() && !buildComplete)
return; /* base defenses can't do anything until they finish building !*/
var turreted = self.traits.Get<Turreted>();
turreted.desiredFacing = Util.GetFacing( target.CenterLocation - self.CenterLocation, turreted.turretFacing );
if( turreted.desiredFacing != turreted.turretFacing )
@@ -38,5 +41,8 @@ namespace OpenRa.Game.Traits
Math.Max( 0, (int)Rules.WeaponInfo[ weapon ].Range - RangeTolerance ) ) );
self.traits.Get<AttackTurreted>().target = order.TargetActor;
}
bool buildComplete = false;
public void BuildingComplete(Actor self) { buildComplete = true; }
}
}

View File

@@ -2,7 +2,7 @@
namespace OpenRa.Game.Traits
{
class Building : ITick
class Building : ITick, INotifyDamage
{
public readonly BuildingInfo unitInfo;
@@ -19,5 +19,11 @@ namespace OpenRa.Game.Traits
first = false;
}
public void Damaged(Actor self, AttackInfo e)
{
if (e.DamageState == DamageState.Dead)
Sound.Play("kaboom22.aud");
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits
{
class Explodes : INotifyDamage
{
public Explodes(Actor self) {}
public void Damaged(Actor self, AttackInfo e)
{
if (self.IsDead)
{
Game.world.AddFrameEndTask(
w => w.Add(new Bullet("UnitExplode", e.Attacker.Owner, e.Attacker,
self.CenterLocation.ToInt2(), self.CenterLocation.ToInt2())));
}
}
}
}

View File

@@ -1,6 +1,7 @@
namespace OpenRa.Game.Traits
using System.Drawing;
namespace OpenRa.Game.Traits
{
class Harvester : IOrder
class Harvester : IOrder, IPips
{
public int oreCarried = 0; /* sum of these must not exceed capacity */
public int gemsCarried = 0;
@@ -53,5 +54,14 @@
self.QueueActivity( new Traits.Activities.DeliverOre( order.TargetActor ) );
}
}
public Color GetBorderColor() { return Color.Black; }
public int GetPipCount() { return 7; }
public Color GetColorForPip(int index)
{
if ((oreCarried + gemsCarried)*1.0f/Rules.General.BailCount* GetPipCount() < index + 1)
return Color.Transparent;
return Color.LimeGreen;
}
}
}

View File

@@ -65,9 +65,12 @@ namespace OpenRa.Game.Traits
yield return Tuple.New(anim.Image, 24f * (float2)self.Location, pal);
}
public virtual void Damaged(Actor self, DamageState state)
public virtual void Damaged(Actor self, AttackInfo e)
{
switch( state )
if (!e.DamageStateChanged)
return;
switch( e.DamageState )
{
case DamageState.Normal:
anim.ReplaceAnim("idle");

View File

@@ -14,9 +14,11 @@ namespace OpenRa.Game.Traits
anim.PlayFacing(a, () => self.traits.Get<Turreted>().turretFacing);
}
public override void Damaged(Actor self, DamageState ds)
public override void Damaged(Actor self, AttackInfo e)
{
switch (ds)
if (!e.DamageStateChanged) return;
switch (e.DamageState)
{
case DamageState.Normal:
PlayTurretAnim(self, "idle");

View File

@@ -51,11 +51,12 @@ namespace OpenRa.Game.Traits
roof.PlayThen(prefix + "build-top", () => isOpen = true);
}
public override void Damaged(Actor self, DamageState ds)
public override void Damaged(Actor self, AttackInfo e)
{
base.Damaged(self, ds);
base.Damaged(self, e);
switch (ds)
if (!e.DamageStateChanged) return;
switch (e.DamageState)
{
case DamageState.Normal:
prefix = "";

View File

@@ -8,7 +8,7 @@ using OpenRa.Game.Effects;
namespace OpenRa.Game.Traits
{
class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamageEx
class RenderInfantry : RenderSimple, INotifyAttack, INotifyDamage
{
public RenderInfantry(Actor self)
: base(self)
@@ -75,12 +75,10 @@ namespace OpenRa.Game.Traits
yield return Util.Centered(self, anim.Image, self.CenterLocation);
}
public void Damaged(Actor self, int damage, WarheadInfo warhead)
public void Damaged(Actor self, AttackInfo e)
{
if (self.Health <= 0)
Game.world.AddFrameEndTask(w => w.Add(new Corpse(self, warhead.InfDeath)));
if (e.DamageState == DamageState.Dead)
Game.world.AddFrameEndTask(w => w.Add(new Corpse(self, e.Warhead.InfDeath)));
}
public void Damaged(Actor self, DamageState ds) {}
}
}

View File

@@ -5,7 +5,7 @@ using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
class RenderUnit : RenderSimple, INotifyDamageEx
class RenderUnit : RenderSimple, INotifyDamage
{
public RenderUnit(Actor self)
: base(self)
@@ -33,24 +33,20 @@ namespace OpenRa.Game.Traits
}
bool isSmoking;
DamageState currentDs;
Animation smoke;
public void Damaged(Actor self, DamageState ds) { currentDs = ds; }
public void Damaged(Actor self, int damage, WarheadInfo warhead)
public void Damaged(Actor self, AttackInfo e)
{
if (currentDs != DamageState.Half) return;
if (!isSmoking)
{
isSmoking = true;
smoke.PlayThen("idle",
() => smoke.PlayThen("loop",
() => smoke.PlayBackwardsThen("end",
() => isSmoking = false)));
}
}
if (e.DamageState != DamageState.Half) return;
if (isSmoking) return;
isSmoking = true;
smoke.PlayThen("idle",
() => smoke.PlayThen("loop",
() => smoke.PlayBackwardsThen("end",
() => isSmoking = false)));
}
public override void Tick(Actor self)
{
base.Tick(self);

View File

@@ -7,7 +7,7 @@ using OpenRa.Game.GameRules;
namespace OpenRa.Game.Traits
{
// infantry prone behavior
class TakeCover : ITick, INotifyDamageEx, IDamageModifier, ISpeedModifier
class TakeCover : ITick, INotifyDamage, IDamageModifier, ISpeedModifier
{
const int defaultProneTime = 100; /* ticks, =4s */
const float proneDamage = .5f;
@@ -19,9 +19,10 @@ namespace OpenRa.Game.Traits
public TakeCover(Actor self) {}
public void Damaged(Actor self, int damage, WarheadInfo warhead)
public void Damaged(Actor self, AttackInfo e)
{
remainingProneTime = defaultProneTime;
if (e.Damage > 0) /* fix to allow healing via `damage` */
remainingProneTime = defaultProneTime;
}
public void Tick(Actor self)

View File

@@ -9,8 +9,7 @@ namespace OpenRa.Game.Traits
interface ITick { void Tick(Actor self); }
interface IRender { IEnumerable<Tuple<Sprite, float2, int>> Render(Actor self); }
interface INotifyDamage { void Damaged(Actor self, DamageState ds); }
interface INotifyDamageEx { void Damaged(Actor self, int damage, WarheadInfo warhead); }
interface INotifyDamage { void Damaged(Actor self, AttackInfo e); }
interface INotifyBuildComplete { void BuildingComplete (Actor self); }
interface IOrder
{

View File

@@ -1,11 +1,18 @@
namespace OpenRa.Game.Traits
{
class Unit
class Unit : INotifyDamage
{
public int Facing;
public int Altitude;
public Unit( Actor self ) { }
public void Damaged(Actor self, AttackInfo e)
{
if (e.DamageState == DamageState.Dead)
if (self.Owner == Game.LocalPlayer)
Sound.Play("unitlst1.aud");
}
}
}