diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 46885f17b3..20ff3898b5 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -72,6 +72,7 @@ namespace OpenRA.Traits public interface INotifyKilled { void Killed(Actor self, AttackInfo e); } public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); } public interface INotifyBuildComplete { void BuildingComplete(Actor self); } + public interface INotifyBuildingPlaced { void BuildingPlaced(Actor self); } public interface INotifyProduction { void UnitProduced(Actor self, Actor other, CPos exit); } public interface INotifyOwnerChanged { void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner); } public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } diff --git a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj index f843ab85c6..3fa3718043 100644 --- a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj +++ b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj @@ -82,6 +82,7 @@ + diff --git a/OpenRA.Mods.D2k/Render/WithBuildingPlacedOverlayInfo.cs b/OpenRA.Mods.D2k/Render/WithBuildingPlacedOverlayInfo.cs new file mode 100644 index 0000000000..ed4ad54b83 --- /dev/null +++ b/OpenRA.Mods.D2k/Render/WithBuildingPlacedOverlayInfo.cs @@ -0,0 +1,70 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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. For more information, + * see COPYING. + */ +#endregion + +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Traits; +using OpenRA.Mods.RA.Buildings; + +namespace OpenRA.Mods.RA.Render +{ + public class WithBuildingPlacedOverlayInfo : ITraitInfo, Requires, Requires + { + [Desc("Sequence name to use")] + public readonly string Sequence = "crane-overlay"; + + [Desc("Position relative to body")] + public readonly WVec Offset = WVec.Zero; + + public object Create(ActorInitializer init) { return new WithBuildingPlacedOverlay(init.self, this); } + } + + public class WithBuildingPlacedOverlay : INotifyBuildComplete, INotifySold, INotifyDamageStateChanged, INotifyBuildingPlaced + { + Animation overlay; + bool buildComplete; + + public WithBuildingPlacedOverlay(Actor self, WithBuildingPlacedOverlayInfo info) + { + var rs = self.Trait(); + var body = self.Trait(); + + buildComplete = !self.HasTrait(); // always render instantly for units + + overlay = new Animation(rs.GetImage(self)); + overlay.Play(info.Sequence); + rs.anims.Add("crane_overlay_{0}".F(info.Sequence), + new AnimationWithOffset(overlay, + () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), + () => !buildComplete)); + } + + public void BuildingComplete(Actor self) + { + buildComplete = true; + } + + public void Sold(Actor self) { } + public void Selling(Actor self) + { + buildComplete = false; + } + + public void DamageStateChanged(Actor self, AttackInfo e) + { + overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name)); + } + + public void BuildingPlaced(Actor self) + { + overlay.Play(overlay.CurrentSequence.Name); + } + } +} \ No newline at end of file diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 2d55d9f16b..4c538e05da 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -495,6 +495,7 @@ + diff --git a/OpenRA.Mods.RA/Player/PlaceBuilding.cs b/OpenRA.Mods.RA/Player/PlaceBuilding.cs index 5a0cb331ab..9625c33aa5 100755 --- a/OpenRA.Mods.RA/Player/PlaceBuilding.cs +++ b/OpenRA.Mods.RA/Player/PlaceBuilding.cs @@ -16,7 +16,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - class PlaceBuildingInfo : TraitInfo {} + class PlaceBuildingInfo : TraitInfo { } class PlaceBuilding : IResolveOrder { @@ -50,8 +50,8 @@ namespace OpenRA.Mods.RA { var building = w.CreateActor(order.TargetString, new TypeDictionary { - new LocationInit( t ), - new OwnerInit( order.Player ), + new LocationInit(t), + new OwnerInit(order.Player), }); if (playSounds) @@ -70,14 +70,14 @@ namespace OpenRA.Mods.RA var building = w.CreateActor(order.TargetString, new TypeDictionary { - new LocationInit( order.TargetLocation ), - new OwnerInit( order.Player ), + new LocationInit(order.TargetLocation), + new OwnerInit(order.Player), }); foreach (var s in buildingInfo.BuildSounds) Sound.PlayToPlayer(order.Player, s, building.CenterPosition); } - PlayBuildAnim( self, unit ); + PlayBuildAnim(self, unit); queue.FinishProduction(); @@ -98,21 +98,24 @@ namespace OpenRA.Mods.RA } // finds a construction yard (or equivalent) and runs its "build" animation. - static void PlayBuildAnim( Actor self, ActorInfo unit ) + static void PlayBuildAnim(Actor self, ActorInfo unit) { var bi = unit.Traits.GetOrDefault(); if (bi == null) return; var producers = self.World.ActorsWithTrait() - .Where( x => x.Actor.Owner == self.Owner - && x.Actor.Info.Traits.Get().Produces.Contains( bi.Queue ) ) + .Where(x => x.Actor.Owner == self.Owner + && x.Actor.Info.Traits.Get().Produces.Contains(bi.Queue)) .ToList(); - var producer = producers.Where( x => x.Actor.IsPrimaryBuilding() ).Concat( producers ) + var producer = producers.Where(x => x.Actor.IsPrimaryBuilding()).Concat(producers) .FirstOrDefault(); - if( producer.Actor != null ) - producer.Actor.Trait().PlayCustomAnim( producer.Actor, "build" ); + if (producer.Actor == null) + return; + + foreach (var nbp in producer.Actor.TraitsImplementing()) + nbp.BuildingPlaced(producer.Actor); } static int GetNumBuildables(Player p) diff --git a/OpenRA.Mods.RA/Render/WithBuildingPlacedAnimation.cs b/OpenRA.Mods.RA/Render/WithBuildingPlacedAnimation.cs new file mode 100644 index 0000000000..71c997ab02 --- /dev/null +++ b/OpenRA.Mods.RA/Render/WithBuildingPlacedAnimation.cs @@ -0,0 +1,41 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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. For more information, + * see COPYING. + */ +#endregion + +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Render +{ + public class WithBuildingPlacedAnimationInfo : ITraitInfo, Requires + { + [Desc("Sequence name to use")] + public readonly string Sequence = "build"; + + public object Create(ActorInitializer init) { return new WithBuildingPlacedAnimation(init.self, this); } + } + + public class WithBuildingPlacedAnimation : INotifyBuildingPlaced + { + WithBuildingPlacedAnimationInfo info; + RenderSimple renderSimple; + + public WithBuildingPlacedAnimation(Actor self, WithBuildingPlacedAnimationInfo info) + { + this.info = info; + renderSimple = self.Trait(); + } + + public void BuildingPlaced(Actor self) + { + renderSimple.PlayCustomAnim(self, info.Sequence); + } + } +} \ No newline at end of file diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index 08f8cd27a4..99aa87c9ca 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -48,6 +48,7 @@ FACT: BaseProvider: Cooldown: 75 Range: 14 + WithBuildingPlacedAnimation: NUKE: Inherits: ^BaseBuilding diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index 43df20ad46..35b25f2fd2 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -73,6 +73,7 @@ CONCRETEB: ProductionBar: ProvidesCustomPrerequisite: Prerequisite: Conyard + WithBuildingPlacedOverlay: ^POWER: Inherits: ^Building diff --git a/mods/d2k/sequences/structures.yaml b/mods/d2k/sequences/structures.yaml index e33614a649..f92d6b34a7 100644 --- a/mods/d2k/sequences/structures.yaml +++ b/mods/d2k/sequences/structures.yaml @@ -183,14 +183,16 @@ conyarda: damaged-idle: DATA Start: 2560 Offset: -48,64 -# build: DATA # TODO: overlay -# Start: 4436 -# Length: 14 -# Offset: -48,64 -# damaged-build: DATA # TODO: overlay -# Start: 4436 -# Length: 14 -# Offset: -48,64 + crane-overlay: DATA + Start: 4436 + Length: 14 + Offset: -48,64 + Tick: 80 + damaged-crane-overlay: DATA + Start: 4436 + Length: 14 + Offset: -48,64 + Tick: 80 bib: BLOXBASE Frames: 611, 612, 613, 631, 632, 633 Length: 6 @@ -771,14 +773,16 @@ conyardh: damaged-idle: DATA Start: 2720 Offset: -48,64 -# build: DATA # TODO: overlay -# Start: 4450 -# Length: 14 -# Offset: -48,64 -# damaged-build: DATA # TODO: overlay -# Start: 4450 -# Length: 14 -# Offset: -48,64 + crane-overlay: DATA + Start: 4450 + Length: 14 + Offset: -48,64 + Tick: 80 + damaged-crane-overlay: DATA + Start: 4450 + Length: 14 + Offset: -48,64 + Tick: 80 bib: BLOXBASE Frames: 611, 612, 613, 631, 632, 633 Length: 6 @@ -1169,14 +1173,16 @@ conyardo: damaged-idle: DATA Start: 2880 Offset: -48,64 -# build: DATA # TODO: overlay -# Start: 4464 -# Length: 14 -# Offset: -48,64 -# damaged-build: DATA # TODO: overlay -# Start: 4464 -# Length: 14 -# Offset: -48,64 + crane-overlay: DATA + Start: 4464 + Length: 14 + Offset: -48,64 + Tick: 80 + damaged-crane-overlay: DATA + Start: 4464 + Length: 14 + Offset: -48,64 + Tick: 80 bib: BLOXBASE Frames: 611, 612, 613, 631, 632, 633 Length: 6 @@ -1675,14 +1681,16 @@ conyardc: # TODO: unused damaged-idle: DATA Start: 3007 Offset: -48,64 -# build: DATA # TODO: overlay -# Start: 4478 -# Length: 14 -# Offset: -48,64 -# damaged-build: DATA # TODO: overlay -# Start: 4478 -# Length: 14 -# Offset: -48,64 + crane-overlay: DATA + Start: 4478 + Length: 14 + Offset: -48,64 + Tick: 80 + damaged-crane-overlay: DATA + Start: 4478 + Length: 14 + Offset: -48,64 + Tick: 80 bib: BLOXBASE Frames: 611, 612, 613, 631, 632, 633 Length: 6 diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index d31607dcfc..d6747e24cd 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -817,6 +817,7 @@ FACT: DeadBuildingState: BaseProvider: Range: 16 + WithBuildingPlacedAnimation: PROC: Inherits: ^Building diff --git a/mods/ts/mod.yaml b/mods/ts/mod.yaml index 1c899c455a..d87b20f569 100644 --- a/mods/ts/mod.yaml +++ b/mods/ts/mod.yaml @@ -91,6 +91,7 @@ Chrome: Assemblies: mods/ra/OpenRA.Mods.RA.dll + mods/d2k/OpenRA.Mods.D2k.dll mods/ts/OpenRA.Mods.TS.dll ChromeLayout: diff --git a/mods/ts/rules/structures.yaml b/mods/ts/rules/structures.yaml index adac71c289..13f2b71f5e 100644 --- a/mods/ts/rules/structures.yaml +++ b/mods/ts/rules/structures.yaml @@ -40,6 +40,7 @@ GACNST: Sequence: idle-side WithIdleOverlay@FRONT: Sequence: idle-front + WithBuildingPlacedOverlay: GAPOWR: Inherits: ^Building diff --git a/mods/ts/sequences/structures.yaml b/mods/ts/sequences/structures.yaml index ede205e187..c7d9f00f60 100644 --- a/mods/ts/sequences/structures.yaml +++ b/mods/ts/sequences/structures.yaml @@ -12,12 +12,15 @@ gacnst: Start: 0 Length: 24 ShadowStart: 24 - build-front: gtcnst_d # TODO: needs a render overlay trait + crane-overlay: gtcnst_d Start: 0 Length: 20 - damaged-build-front: gtcnst_d # TODO: needs a render overlay trait + damaged-crane-overlay: gtcnst_d Start: 0 Length: 20 + critical-crane-overlay: gtcnst_d + Start: 20 + Length: 20 idle-top: gtcnst_c Start: 0 Length: 15