impose the hack on WALLs, not everything-else

This commit is contained in:
Chris Forbes
2010-03-27 10:05:01 +13:00
parent dd6f61a29f
commit faa8f54e7c
6 changed files with 33 additions and 41 deletions

View File

@@ -146,23 +146,35 @@ namespace OpenRA
if (Health <= 0) if (Health <= 0)
return DamageState.Dead; return DamageState.Dead;
if (Health < this.GetMaxHP() * Rules.General.ConditionRed)
return DamageState.Quarter;
if (Health < this.GetMaxHP() * Rules.General.ConditionYellow) if (Health < this.GetMaxHP() * Rules.General.ConditionYellow)
return DamageState.Half; return DamageState.Half;
if (Health < this.GetMaxHP() * 0.75)
return DamageState.ThreeQuarter;
return DamageState.Normal; return DamageState.Normal;
} }
public ExtendedDamageState GetExtendedDamageState()
{
if (Health <= 0)
return ExtendedDamageState.Dead;
if (Health < this.GetMaxHP() * Rules.General.ConditionRed)
return ExtendedDamageState.Quarter;
if (Health < this.GetMaxHP() * Rules.General.ConditionYellow)
return ExtendedDamageState.Half;
if (Health < this.GetMaxHP() * 0.75)
return ExtendedDamageState.ThreeQuarter;
return ExtendedDamageState.Normal;
}
public void InflictDamage(Actor attacker, int damage, WarheadInfo warhead) public void InflictDamage(Actor attacker, int damage, WarheadInfo warhead)
{ {
if (IsDead) return; /* overkill! don't count extra hits as more kills! */ if (IsDead) return; /* overkill! don't count extra hits as more kills! */
var oldState = GetDamageState(); var oldState = GetDamageState();
var oldExtendedState = GetExtendedDamageState();
/* apply the damage modifiers, if we have any. */ /* apply the damage modifiers, if we have any. */
damage = (int)traits.WithInterface<IDamageModifier>().Aggregate( damage = (int)traits.WithInterface<IDamageModifier>().Aggregate(
@@ -184,6 +196,7 @@ namespace OpenRA
if (Health > maxHP) Health = maxHP; if (Health > maxHP) Health = maxHP;
var newState = GetDamageState(); var newState = GetDamageState();
var newExtendedState = GetExtendedDamageState();
foreach (var nd in traits.WithInterface<INotifyDamage>()) foreach (var nd in traits.WithInterface<INotifyDamage>())
nd.Damaged(this, new AttackInfo nd.Damaged(this, new AttackInfo
@@ -192,6 +205,8 @@ namespace OpenRA
Damage = damage, Damage = damage,
DamageState = newState, DamageState = newState,
DamageStateChanged = newState != oldState, DamageStateChanged = newState != oldState,
ExtendedDamageState = newExtendedState,
ExtendedDamageStateChanged = newExtendedState != oldExtendedState,
Warhead = warhead Warhead = warhead
}); });
} }

View File

@@ -28,6 +28,8 @@ namespace OpenRA.Traits
public WarheadInfo Warhead; public WarheadInfo Warhead;
public int Damage; public int Damage;
public DamageState DamageState; public DamageState DamageState;
public ExtendedDamageState ExtendedDamageState; // for 3,4-state stuff
public bool DamageStateChanged; public bool DamageStateChanged;
public bool ExtendedDamageStateChanged;
} }
} }

View File

@@ -144,28 +144,9 @@ namespace OpenRA.Traits
return b != null && b.self.IsInWorld && b.self.Info.Traits.Get<BridgeInfo>().Long; return b != null && b.self.IsInWorld && b.self.Info.Traits.Get<BridgeInfo>().Long;
} }
// HACK because paul broke the world with his extended damage states... :(
static DamageState MapDamageState(DamageState ds)
{
switch (ds)
{
case DamageState.Normal:
case DamageState.ThreeQuarter:
return DamageState.Normal;
case DamageState.Half:
case DamageState.Quarter:
return DamageState.Half;
case DamageState.Dead:
default:
return DamageState.Dead;
}
}
void UpdateState() void UpdateState()
{ {
var ds = MapDamageState(self.GetDamageState()); var ds = self.GetDamageState();
if (!self.Info.Traits.Get<BridgeInfo>().Long) if (!self.Info.Traits.Get<BridgeInfo>().Long)
{ {
state = (int)ds; state = (int)ds;

View File

@@ -44,22 +44,22 @@ namespace OpenRA.Traits
public override void Damaged(Actor self, AttackInfo e) public override void Damaged(Actor self, AttackInfo e)
{ {
if (!e.DamageStateChanged) return; if (!e.ExtendedDamageStateChanged) return;
switch (e.DamageState) switch (e.ExtendedDamageState)
{ {
case DamageState.Normal: case ExtendedDamageState.Normal:
seqName = "idle"; seqName = "idle";
break; break;
case DamageState.ThreeQuarter: case ExtendedDamageState.ThreeQuarter:
if (damageStates >= 4) if (damageStates >= 4)
seqName = "minor-damaged-idle"; seqName = "minor-damaged-idle";
break; break;
case DamageState.Half: case ExtendedDamageState.Half:
seqName = "damaged-idle"; seqName = "damaged-idle";
Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound); Sound.Play(self.Info.Traits.Get<BuildingInfo>().DamagedSound);
break; break;
case DamageState.Quarter: case ExtendedDamageState.Quarter:
if (damageStates >= 3) if (damageStates >= 3)
{ {
seqName = "critical-idle"; seqName = "critical-idle";

View File

@@ -27,7 +27,8 @@ using OpenRA.Traits.Activities;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
public enum DamageState { Normal, ThreeQuarter, Half, Quarter, Dead }; public enum DamageState { Normal, Half, Dead };
public enum ExtendedDamageState { Normal, ThreeQuarter, Half, Quarter, Dead };
// depends on the order of pips in WorldRenderer.cs! // depends on the order of pips in WorldRenderer.cs!
public enum PipType { Transparent, Green, Yellow, Red, Gray }; public enum PipType { Transparent, Green, Yellow, Red, Gray };

View File

@@ -18,13 +18,6 @@
*/ */
#endregion #endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Effects;
using OpenRA.GameRules;
using OpenRA.Traits.Activities;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
public class WallInfo : StatelessTraitInfo<Wall> {} public class WallInfo : StatelessTraitInfo<Wall> {}