Merge pull request #9730 from r34ch/fake-structures-detonate

Fake structures detonate to mask health difference.
This commit is contained in:
atlimit8
2015-10-25 09:12:02 -05:00
4 changed files with 61 additions and 5 deletions

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
[Desc("This actor explodes when killed.")] [Desc("This actor explodes when killed.")]
public class ExplodesInfo : ITraitInfo, IRulesetLoaded public class ExplodesInfo : ITraitInfo, IRulesetLoaded, Requires<HealthInfo>
{ {
[WeaponReference, FieldLoader.Require, Desc("Weapon to use for explosion if ammo/payload is loaded.")] [WeaponReference, FieldLoader.Require, Desc("Weapon to use for explosion if ammo/payload is loaded.")]
public readonly string Weapon = "UnitExplode"; public readonly string Weapon = "UnitExplode";
@@ -32,13 +32,16 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Chance that this actor will explode at all.")] [Desc("Chance that this actor will explode at all.")]
public readonly int Chance = 100; public readonly int Chance = 100;
[Desc("Health level at which actor will explode.")]
public readonly int DamageThreshold = 0;
[Desc("DeathType(s) to apply upon explosion.")] [Desc("DeathType(s) to apply upon explosion.")]
public readonly HashSet<string> DeathType = new HashSet<string>(); public readonly HashSet<string> DeathType = new HashSet<string>();
public WeaponInfo WeaponInfo { get; private set; } public WeaponInfo WeaponInfo { get; private set; }
public WeaponInfo EmptyWeaponInfo { get; private set; } public WeaponInfo EmptyWeaponInfo { get; private set; }
public object Create(ActorInitializer init) { return new Explodes(this); } public object Create(ActorInitializer init) { return new Explodes(this, init.Self); }
public void RulesetLoaded(Ruleset rules, ActorInfo ai) public void RulesetLoaded(Ruleset rules, ActorInfo ai)
{ {
WeaponInfo = string.IsNullOrEmpty(Weapon) ? null : rules.Weapons[Weapon.ToLowerInvariant()]; WeaponInfo = string.IsNullOrEmpty(Weapon) ? null : rules.Weapons[Weapon.ToLowerInvariant()];
@@ -46,11 +49,17 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public class Explodes : INotifyKilled public class Explodes : INotifyKilled, INotifyDamage
{ {
readonly ExplodesInfo info; readonly ExplodesInfo info;
public Explodes(ExplodesInfo info) { this.info = info; } readonly Health health;
public Explodes(ExplodesInfo info, Actor self)
{
this.info = info;
health = self.Trait<Health>();
}
public void Killed(Actor self, AttackInfo e) public void Killed(Actor self, AttackInfo e)
{ {
@@ -81,5 +90,14 @@ namespace OpenRA.Mods.Common.Traits
var useFullExplosion = self.World.SharedRandom.Next(100) <= info.LoadedChance; var useFullExplosion = self.World.SharedRandom.Next(100) <= info.LoadedChance;
return (shouldExplode && useFullExplosion) ? info.WeaponInfo : info.EmptyWeaponInfo; return (shouldExplode && useFullExplosion) ? info.WeaponInfo : info.EmptyWeaponInfo;
} }
public void Damaged(Actor self, AttackInfo e)
{
if (info.DamageThreshold == 0)
return;
if (health.HP * 100 < info.DamageThreshold * health.MaxHP)
self.World.AddFrameEndTask(w => self.Kill(e.Attacker));
}
} }
} }

View File

@@ -237,7 +237,6 @@ V19.Husk:
WithIdleOverlay: WithIdleOverlay:
StartSequence: fire-start StartSequence: fire-start
Sequence: fire-loop Sequence: fire-loop
-Health:
-Selectable: -Selectable:
-Targetable: -Targetable:
-Demolishable: -Demolishable:

View File

@@ -506,6 +506,9 @@
-GivesBuildableArea: -GivesBuildableArea:
Health: Health:
HP: 100 HP: 100
Explodes:
Weapon: Demolish
DamageThreshold: 90
RevealsShroud: RevealsShroud:
Range: 4c0 Range: 4c0
Fake: Fake:

View File

@@ -19,6 +19,10 @@ FACF:
Image: FACT Image: FACT
Valued: Valued:
Cost: 250 Cost: 250
Health:
HP: 1500
Armor:
Type: Wood
WEAF: WEAF:
Inherits: ^FakeBuilding Inherits: ^FakeBuilding
@@ -43,6 +47,10 @@ WEAF:
Sequence: build-top Sequence: build-top
Valued: Valued:
Cost: 200 Cost: 200
Health:
HP: 1500
Armor:
Type: Wood
SYRF: SYRF:
Inherits: ^FakeBuilding Inherits: ^FakeBuilding
@@ -68,6 +76,10 @@ SYRF:
Image: SYRD Image: SYRD
Valued: Valued:
Cost: 100 Cost: 100
Health:
HP: 1000
Armor:
Type: Light
EditorTilesetFilter: EditorTilesetFilter:
ExcludeTilesets: INTERIOR ExcludeTilesets: INTERIOR
@@ -95,6 +107,10 @@ SPEF:
Image: SPEN Image: SPEN
Valued: Valued:
Cost: 100 Cost: 100
Health:
HP: 1000
Armor:
Type: Light
EditorTilesetFilter: EditorTilesetFilter:
ExcludeTilesets: INTERIOR ExcludeTilesets: INTERIOR
@@ -119,6 +135,10 @@ DOMF:
Image: DOME Image: DOME
Valued: Valued:
Cost: 180 Cost: 180
Health:
HP: 1000
Armor:
Type: Wood
RequiresPower: RequiresPower:
DisabledOverlay: DisabledOverlay:
@@ -143,6 +163,10 @@ ATEF:
Image: ATEK Image: ATEK
Valued: Valued:
Cost: 150 Cost: 150
Health:
HP: 400
Armor:
Type: Wood
RequiresPower: RequiresPower:
DisabledOverlay: DisabledOverlay:
@@ -169,6 +193,12 @@ PDOF:
HasMinibib: Yes HasMinibib: Yes
Valued: Valued:
Cost: 150 Cost: 150
Health:
HP: 1000
Armor:
Type: Wood
Explodes:
DamageThreshold: 50
RequiresPower: RequiresPower:
DisabledOverlay: DisabledOverlay:
@@ -193,6 +223,12 @@ MSLF:
Image: MSLO Image: MSLO
Valued: Valued:
Cost: 250 Cost: 250
Health:
HP: 1000
Armor:
Type: Wood
Explodes:
DamageThreshold: 50
RequiresPower: RequiresPower:
DisabledOverlay: DisabledOverlay: