Merge pull request #12338 from reaperrr/explodes-footprint

Add footprint support to Explodes, remove WithBuildingExplosion
This commit is contained in:
Oliver Brakmann
2016-12-10 20:17:15 +01:00
committed by GitHub
18 changed files with 115 additions and 118 deletions

View File

@@ -419,7 +419,6 @@
<Compile Include="Traits\Render\SupportPowerChargeBar.cs" /> <Compile Include="Traits\Render\SupportPowerChargeBar.cs" />
<Compile Include="Traits\Render\TimedConditionBar.cs" /> <Compile Include="Traits\Render\TimedConditionBar.cs" />
<Compile Include="Traits\Render\WithSpriteBarrel.cs" /> <Compile Include="Traits\Render\WithSpriteBarrel.cs" />
<Compile Include="Traits\Render\WithBuildingExplosion.cs" />
<Compile Include="Traits\Render\WithAttackAnimation.cs" /> <Compile Include="Traits\Render\WithAttackAnimation.cs" />
<Compile Include="Traits\Render\WithAttackOverlay.cs" /> <Compile Include="Traits\Render\WithAttackOverlay.cs" />
<Compile Include="Traits\Render\WithMoveAnimation.cs" /> <Compile Include="Traits\Render\WithMoveAnimation.cs" />

View File

@@ -17,16 +17,18 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public enum ExplosionType { Footprint, CenterPosition }
[Desc("This actor explodes when killed.")] [Desc("This actor explodes when killed.")]
public class ExplodesInfo : ITraitInfo, IRulesetLoaded, Requires<HealthInfo> 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("Default weapon to use for explosion if ammo/payload is loaded.")]
public readonly string Weapon = "UnitExplode"; public readonly string Weapon = "UnitExplode";
[WeaponReference, Desc("Weapon to use for explosion if no ammo/payload is loaded.")] [WeaponReference, Desc("Fallback weapon to use for explosion if empty (no ammo/payload).")]
public readonly string EmptyWeapon = "UnitExplode"; public readonly string EmptyWeapon = "UnitExplode";
[Desc("Chance that the explosion will use Weapon if the actor has ammo/payload.")] [Desc("Chance that the explosion will use Weapon instead of EmptyWeapon when exploding, provided the actor has ammo/payload.")]
public readonly int LoadedChance = 100; public readonly int LoadedChance = 100;
[Desc("Chance that this actor will explode at all.")] [Desc("Chance that this actor will explode at all.")]
@@ -38,6 +40,10 @@ namespace OpenRA.Mods.Common.Traits
[Desc("DeathType(s) that trigger the explosion. Leave empty to always trigger an explosion.")] [Desc("DeathType(s) that trigger the explosion. Leave empty to always trigger an explosion.")]
public readonly HashSet<string> DeathTypes = new HashSet<string>(); public readonly HashSet<string> DeathTypes = new HashSet<string>();
[Desc("Possible values are CenterPosition (explosion at the actors' center) and ",
"Footprint (explosion on each occupied cell).")]
public readonly ExplosionType Type = ExplosionType.CenterPosition;
public WeaponInfo WeaponInfo { get; private set; } public WeaponInfo WeaponInfo { get; private set; }
public WeaponInfo EmptyWeaponInfo { get; private set; } public WeaponInfo EmptyWeaponInfo { get; private set; }
@@ -49,11 +55,11 @@ namespace OpenRA.Mods.Common.Traits
} }
} }
public class Explodes : INotifyKilled, INotifyDamage public class Explodes : INotifyKilled, INotifyDamage, INotifyCreated
{ {
readonly ExplodesInfo info; readonly ExplodesInfo info;
readonly Health health; readonly Health health;
BuildingInfo buildingInfo;
public Explodes(ExplodesInfo info, Actor self) public Explodes(ExplodesInfo info, Actor self)
{ {
@@ -61,7 +67,12 @@ namespace OpenRA.Mods.Common.Traits
health = self.Trait<Health>(); health = self.Trait<Health>();
} }
public void Killed(Actor self, AttackInfo e) void INotifyCreated.Created(Actor self)
{
buildingInfo = self.Info.TraitInfoOrDefault<BuildingInfo>();
}
void INotifyKilled.Killed(Actor self, AttackInfo e)
{ {
if (!self.IsInWorld) if (!self.IsInWorld)
return; return;
@@ -79,6 +90,15 @@ namespace OpenRA.Mods.Common.Traits
if (weapon.Report != null && weapon.Report.Any()) if (weapon.Report != null && weapon.Report.Any())
Game.Sound.Play(weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition); Game.Sound.Play(weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition);
if (info.Type == ExplosionType.Footprint && buildingInfo != null)
{
var cells = FootprintUtils.UnpathableTiles(self.Info.Name, buildingInfo, self.Location);
foreach (var c in cells)
weapon.Impact(Target.FromPos(self.World.Map.CenterOfCell(c)), e.Attacker, Enumerable.Empty<int>());
return;
}
// Use .FromPos since this actor is killed. Cannot use Target.FromActor // Use .FromPos since this actor is killed. Cannot use Target.FromActor
weapon.Impact(Target.FromPos(self.CenterPosition), e.Attacker, Enumerable.Empty<int>()); weapon.Impact(Target.FromPos(self.CenterPosition), e.Attacker, Enumerable.Empty<int>());
} }
@@ -90,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits
return (shouldExplode && useFullExplosion) ? info.WeaponInfo : info.EmptyWeaponInfo; return (shouldExplode && useFullExplosion) ? info.WeaponInfo : info.EmptyWeaponInfo;
} }
public void Damaged(Actor self, AttackInfo e) void INotifyDamage.Damaged(Actor self, AttackInfo e)
{ {
if (info.DamageThreshold == 0) if (info.DamageThreshold == 0)
return; return;

View File

@@ -15,8 +15,6 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public enum VisibilityType { Footprint, CenterPosition, GroundPosition }
[Desc("The actor stays invisible under the shroud.")] [Desc("The actor stays invisible under the shroud.")]
public class HiddenUnderShroudInfo : ITraitInfo, IDefaultVisibilityInfo public class HiddenUnderShroudInfo : ITraitInfo, IDefaultVisibilityInfo
{ {

View File

@@ -1,64 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2016 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion
using System.Collections.Generic;
using OpenRA.Effects;
using OpenRA.Mods.Common.Effects;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits.Render
{
[Desc("Display explosions over the building footprint when it is destroyed.")]
class WithBuildingExplosionInfo : ITraitInfo, Requires<BuildingInfo>
{
[Desc("'Image' where Sequences are looked up.")]
public readonly string Image = "explosion";
[Desc("Explosion sequence names to use.")]
[SequenceReference("Image")] public readonly string[] Sequences = { "building" };
[Desc("Delay the explosions by this many ticks.")]
public readonly int Delay = 0;
[Desc("Custom palette name.")]
[PaletteReference] public readonly string Palette = "effect";
public object Create(ActorInitializer init) { return new WithBuildingExplosion(init.Self, this); }
}
class WithBuildingExplosion : INotifyKilled
{
readonly WithBuildingExplosionInfo info;
readonly BuildingInfo buildingInfo;
public WithBuildingExplosion(Actor self, WithBuildingExplosionInfo info)
{
this.info = info;
buildingInfo = self.Info.TraitInfo<BuildingInfo>();
}
public void Killed(Actor self, AttackInfo e)
{
var cells = FootprintUtils.UnpathableTiles(self.Info.Name, buildingInfo, self.Location);
if (info.Delay > 0)
self.World.AddFrameEndTask(w => w.Add(new DelayedAction(info.Delay, () => SpawnExplosions(self.World, cells))));
else
SpawnExplosions(self.World, cells);
}
void SpawnExplosions(World world, IEnumerable<CPos> cells)
{
foreach (var c in cells)
world.AddFrameEndTask(w => w.Add(new SpriteEffect(w.Map.CenterOfCell(c), w, info.Image, info.Sequences.Random(w.SharedRandom), info.Palette)));
}
}
}

View File

@@ -19,6 +19,8 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
{ {
public enum VisibilityType { Footprint, CenterPosition, GroundPosition }
public enum AttackDelayType { Preparation, Attack } public enum AttackDelayType { Preparation, Attack }
public interface IQuantizeBodyOrientationInfo : ITraitInfo public interface IQuantizeBodyOrientationInfo : ITraitInfo

View File

@@ -542,6 +542,19 @@ namespace OpenRA.Mods.Common.UtilityCommands
RenameNodeKey(node, "LegacyBridgeLayer"); RenameNodeKey(node, "LegacyBridgeLayer");
} }
// Removed WithBuildingExplosion
if (engineVersion < 20161210)
{
if (node.Key == "WithBuildingExplosion")
{
node.Value.Nodes.Add(new MiniYamlNode("Type", "Footprint"));
node.Value.Nodes.Add(new MiniYamlNode("Weapon", "UnitExplodeSmall"));
node.Key = "Explodes";
Console.WriteLine("The trait WithBuildingExplosion has been removed and superseded by additional 'Explodes' functionality.");
Console.WriteLine("If you need a delayed building explosion, use 'Explodes' with 'Type: Footprint' and a cosmetic weapon with warhead delay.");
}
}
UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1); UpgradeActorRules(modData, engineVersion, ref node.Value.Nodes, node, depth + 1);
} }

View File

@@ -563,9 +563,10 @@
DamagedSounds: xplos.aud DamagedSounds: xplos.aud
DestroyedSounds: crumble.aud DestroyedSounds: crumble.aud
WithSpriteBody: WithSpriteBody:
WithBuildingExplosion: Explodes:
Sequences: building, building_napalm, med_frag, poof, small_building Type: Footprint
Delay: 1 Weapon: BuildingExplode
EmptyWeapon: BuildingExplode
CaptureNotification: CaptureNotification:
Notification: BuildingCaptured Notification: BuildingCaptured
NewOwnerVoice: no NewOwnerVoice: no
@@ -650,7 +651,7 @@
-SelectionDecorations: -SelectionDecorations:
Tooltip: Tooltip:
GenericName: Field GenericName: Field
-WithBuildingExplosion: -Explodes:
-Targetable: -Targetable:
-Demolishable: -Demolishable:
RenderSprites: RenderSprites:

View File

@@ -81,6 +81,14 @@ GrenadierExplode:
Warhead@3Smu: LeaveSmudge Warhead@3Smu: LeaveSmudge
SmudgeType: Crater SmudgeType: Crater
BuildingExplode:
Warhead@1Eff: CreateEffect
Explosions: building, building_napalm, med_frag, poof, small_building
Delay: 1
Warhead@2Smu: LeaveSmudge
SmudgeType: Crater
Delay: 1
Napalm.Crate: Napalm.Crate:
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 170 Spread: 170

View File

@@ -332,8 +332,10 @@
DamagedSounds: EXPLSML1.WAV DamagedSounds: EXPLSML1.WAV
DestroyedSounds: EXPLHG1.WAV DestroyedSounds: EXPLHG1.WAV
WithSpriteBody: WithSpriteBody:
WithBuildingExplosion: Explodes:
Sequences: building, self_destruct, large_explosion Type: Footprint
Weapon: BuildingExplode
EmptyWeapon: BuildingExplode
RepairableBuilding: RepairableBuilding:
PlayerExperience: 25 PlayerExperience: 25
EmitInfantryOnSell: EmitInfantryOnSell:

View File

@@ -186,6 +186,10 @@ UnitExplodeLarge:
Explosions: large_explosion Explosions: large_explosion
ImpactSounds: EXPLLG2.WAV ImpactSounds: EXPLLG2.WAV
BuildingExplode:
Warhead@1Eff: CreateEffect
Explosions: building, self_destruct, large_explosion
grenade: grenade:
ReloadDelay: 50 ReloadDelay: 50
Range: 4c0 Range: 4c0

View File

@@ -106,8 +106,6 @@ HOSP:
WithDeathAnimation: WithDeathAnimation:
DeathSequence: dead DeathSequence: dead
UseDeathTypeSuffix: false UseDeathTypeSuffix: false
WithBuildingExplosion:
Delay: 1
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
GpsDot: GpsDot:
String: Hospital String: Hospital
@@ -330,8 +328,6 @@ MISS:
WithDeathAnimation: WithDeathAnimation:
DeathSequence: dead DeathSequence: dead
UseDeathTypeSuffix: false UseDeathTypeSuffix: false
WithBuildingExplosion:
Delay: 1
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
BIO: BIO:
@@ -349,8 +345,6 @@ BIO:
WithDeathAnimation: WithDeathAnimation:
DeathSequence: dead DeathSequence: dead
UseDeathTypeSuffix: false UseDeathTypeSuffix: false
WithBuildingExplosion:
Delay: 1
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
GpsDot: GpsDot:
String: Biohazard String: Biohazard

View File

@@ -494,8 +494,10 @@
DamagedSounds: kaboom1.aud DamagedSounds: kaboom1.aud
DestroyedSounds: kaboom22.aud DestroyedSounds: kaboom22.aud
WithSpriteBody: WithSpriteBody:
WithBuildingExplosion: Explodes:
Sequences: building, building_napalm, large_explosion, self_destruct, large_napalm Type: Footprint
Weapon: BuildingExplode
EmptyWeapon: BuildingExplode
CaptureNotification: CaptureNotification:
ShakeOnDeath: ShakeOnDeath:
ProximityCaptor: ProximityCaptor:
@@ -546,6 +548,9 @@
-AcceptsSupplies: -AcceptsSupplies:
DrawLineToTarget: DrawLineToTarget:
RenderRangeCircle: RenderRangeCircle:
Explodes:
Weapon: SmallBuildingExplode
EmptyWeapon: SmallBuildingExplode
^Wall: ^Wall:
Inherits@1: ^ExistsInWorld Inherits@1: ^ExistsInWorld

View File

@@ -84,8 +84,9 @@ GAP:
Amount: -60 Amount: -60
MustBeDestroyed: MustBeDestroyed:
RequiredForShortGame: false RequiredForShortGame: false
WithBuildingExplosion: Explodes:
Sequences: building, building_napalm, large_explosion, self_destruct Weapon: SmallBuildingExplode
EmptyWeapon: SmallBuildingExplode
SPEN: SPEN:
Inherits: ^Building Inherits: ^Building
@@ -434,8 +435,6 @@ TSLA:
DetectCloaked: DetectCloaked:
Range: 8c0 Range: 8c0
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
WithBuildingExplosion:
Sequences: building, building_napalm, large_explosion, self_destruct
AGUN: AGUN:
Inherits: ^Defense Inherits: ^Defense
@@ -482,8 +481,6 @@ AGUN:
Amount: -50 Amount: -50
DetectCloaked: DetectCloaked:
Range: 6c0 Range: 6c0
WithBuildingExplosion:
Sequences: building, building_napalm, large_explosion, self_destruct
BodyOrientation: BodyOrientation:
UseClassicFacingFudge: True UseClassicFacingFudge: True
@@ -566,8 +563,6 @@ PBOX:
Amount: -15 Amount: -15
DetectCloaked: DetectCloaked:
Range: 6c0 Range: 6c0
WithBuildingExplosion:
Sequences: building, building_napalm, large_explosion, self_destruct
HBOX: HBOX:
Inherits: ^Defense Inherits: ^Defense
@@ -614,8 +609,6 @@ HBOX:
Power: Power:
Amount: -15 Amount: -15
-MustBeDestroyed: -MustBeDestroyed:
WithBuildingExplosion:
Sequences: building, building_napalm, large_explosion, self_destruct
GUN: GUN:
Inherits: ^Defense Inherits: ^Defense
@@ -652,8 +645,6 @@ GUN:
Amount: -40 Amount: -40
DetectCloaked: DetectCloaked:
Range: 7c0 Range: 7c0
WithBuildingExplosion:
Sequences: building, building_napalm, large_explosion, self_destruct
BodyOrientation: BodyOrientation:
UseClassicFacingFudge: True UseClassicFacingFudge: True
@@ -692,8 +683,9 @@ FTUR:
DetectCloaked: DetectCloaked:
Range: 6c0 Range: 6c0
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
WithBuildingExplosion: Explodes:
Sequences: building, building_napalm, large_explosion, self_destruct Weapon: BuildingExplode
EmptyWeapon: BuildingExplode
SAM: SAM:
Inherits: ^Defense Inherits: ^Defense
@@ -950,8 +942,6 @@ FACT:
WithDeathAnimation: WithDeathAnimation:
DeathSequence: dead DeathSequence: dead
UseDeathTypeSuffix: false UseDeathTypeSuffix: false
WithBuildingExplosion:
Delay: 1
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
PROC: PROC:
@@ -1004,8 +994,6 @@ PROC:
WithDeathAnimation: WithDeathAnimation:
DeathSequence: dead DeathSequence: dead
UseDeathTypeSuffix: false UseDeathTypeSuffix: false
WithBuildingExplosion:
Delay: 1
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
SILO: SILO:
@@ -1036,8 +1024,9 @@ SILO:
-EmitInfantryOnSell: -EmitInfantryOnSell:
Power: Power:
Amount: -10 Amount: -10
WithBuildingExplosion: Explodes:
Sequences: building, building_napalm, large_explosion, self_destruct Weapon: SmallBuildingExplode
EmptyWeapon: SmallBuildingExplode
HPAD: HPAD:
Inherits: ^Building Inherits: ^Building
@@ -1267,8 +1256,6 @@ POWR:
WithDeathAnimation: WithDeathAnimation:
DeathSequence: dead DeathSequence: dead
UseDeathTypeSuffix: false UseDeathTypeSuffix: false
WithBuildingExplosion:
Delay: 1
APWR: APWR:
Inherits: ^Building Inherits: ^Building
@@ -1308,8 +1295,6 @@ APWR:
WithDeathAnimation: WithDeathAnimation:
DeathSequence: dead DeathSequence: dead
UseDeathTypeSuffix: false UseDeathTypeSuffix: false
WithBuildingExplosion:
Delay: 1
STEK: STEK:
Inherits: ^ScienceBuilding Inherits: ^ScienceBuilding
@@ -1448,8 +1433,6 @@ KENN:
Power: Power:
Amount: -10 Amount: -10
ProvidesPrerequisite@buildingname: ProvidesPrerequisite@buildingname:
WithBuildingExplosion:
Sequences: building, building_napalm, large_explosion, self_destruct
WithDecoration@primary: WithDecoration@primary:
RequiresSelection: true RequiresSelection: true
Image: pips Image: pips

View File

@@ -212,12 +212,16 @@ UnitExplodeSmall:
SmudgeType: Crater SmudgeType: Crater
InvalidTargets: Structure, Wall, Trees InvalidTargets: Structure, Wall, Trees
# Used to panic civilians which are emitted from a killed CivBuilding
CivBuildingExplosion: CivBuildingExplosion:
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage # Used to panic civilians which are emitted from a killed CivBuilding
Spread: 64 Spread: 64
Damage: 1 Damage: 1
Delay: 1 Delay: 1
Warhead@2Eff: CreateEffect
Explosions: building, building_napalm, large_explosion, self_destruct
Warhead@3Smu: LeaveSmudge
SmudgeType: Crater
InvalidTargets: Wall, Trees
ArtilleryExplode: ArtilleryExplode:
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
@@ -245,6 +249,20 @@ V2Explode:
Inherits: SCUD Inherits: SCUD
-Report: -Report:
BuildingExplode:
Warhead@1Eff: CreateEffect
Explosions: building, building_napalm, large_explosion, self_destruct, large_napalm
Warhead@2Smu: LeaveSmudge
SmudgeType: Crater
InvalidTargets: Wall, Trees
SmallBuildingExplode:
Warhead@1Eff: CreateEffect
Explosions: building, building_napalm, large_explosion, self_destruct
Warhead@2Smu: LeaveSmudge
SmudgeType: Crater
InvalidTargets: Wall, Trees
BarrelExplode: BarrelExplode:
Warhead@1Dam: SpreadDamage Warhead@1Dam: SpreadDamage
Spread: 426 Spread: 426

View File

@@ -14,6 +14,7 @@ CABHUT:
TargetTypes: C4 TargetTypes: C4
-SelectionDecorations: -SelectionDecorations:
-Demolishable: -Demolishable:
-Explodes:
^LowBridgeRamp: ^LowBridgeRamp:
AlwaysVisible: AlwaysVisible:

View File

@@ -126,8 +126,10 @@
DamagedSounds: expnew01.aud DamagedSounds: expnew01.aud
DestroyedSounds: crmble2.aud DestroyedSounds: crmble2.aud
WithSpriteBody: WithSpriteBody:
WithBuildingExplosion: Explodes:
Sequences: building, large_bang, large_brnl, verylarge_clsn, large_tumu Weapon: BuildingExplosions
EmptyWeapon: BuildingExplosions
Type: Footprint
EngineerRepairable: EngineerRepairable:
ShakeOnDeath: ShakeOnDeath:
AcceptsSupplies: AcceptsSupplies:

View File

@@ -107,6 +107,8 @@ PROC:
FactionImages: FactionImages:
gdi: proc.gdi gdi: proc.gdi
nod: proc.nod nod: proc.nod
Explodes:
Weapon: TiberiumExplosion
GASILO: GASILO:
Inherits: ^Building Inherits: ^Building
@@ -150,6 +152,8 @@ GASILO:
Amount: -10 Amount: -10
SelectionDecorations: SelectionDecorations:
VisualBounds: 80, 48, -5, 0 VisualBounds: 80, 48, -5, 0
Explodes:
Weapon: TiberiumExplosion
ANYPOWER: ANYPOWER:
AlwaysVisible: AlwaysVisible:

View File

@@ -34,6 +34,13 @@ UnitExplodeSmall:
SmudgeType: SmallCrater SmudgeType: SmallCrater
InvalidTargets: Building, Wall InvalidTargets: Building, Wall
BuildingExplosions:
Warhead@1Eff: CreateEffect
Explosions: building, large_bang, large_brnl, verylarge_clsn, large_tumu
ExplosionPalette: effectalpha75
Warhead@2Smu: LeaveSmudge
SmudgeType: MediumCrater
CyborgExplode: CyborgExplode:
Warhead@1Eff: CreateEffect Warhead@1Eff: CreateEffect
Explosions: medium_bang Explosions: medium_bang