diff --git a/OpenRA.Editor/RenderUtils.cs b/OpenRA.Editor/RenderUtils.cs index 6b29709bfc..01d8fd2f0f 100644 --- a/OpenRA.Editor/RenderUtils.cs +++ b/OpenRA.Editor/RenderUtils.cs @@ -45,7 +45,7 @@ namespace OpenRA.Editor public static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, Palette p) { - var image = RenderSimple.GetImage(info); + var image = RenderSprites.GetImage(info); using (var s = FileSystem.OpenWithExts(image, tileset.Extensions)) { diff --git a/OpenRA.Mods.Cnc/RenderGunboat.cs b/OpenRA.Mods.Cnc/RenderGunboat.cs index 0b9c047c82..694f3a1a03 100644 --- a/OpenRA.Mods.Cnc/RenderGunboat.cs +++ b/OpenRA.Mods.Cnc/RenderGunboat.cs @@ -15,7 +15,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { - class RenderGunboatInfo : RenderUnitInfo + class RenderGunboatInfo : RenderSimpleInfo { public override object Create(ActorInitializer init) { return new RenderGunboat(init.self); } } @@ -26,8 +26,13 @@ namespace OpenRA.Mods.RA.Render string lastDir = "left"; string lastDamage = ""; + static Func TurretFacingFunc(Actor self) + { + return () => self.HasTrait() ? self.TraitsImplementing().First().turretFacing : 0; + } + public RenderGunboat(Actor self) - : base(self, () => self.HasTrait() ? self.TraitsImplementing().First().turretFacing : 0) + : base(self, TurretFacingFunc(self)) { facing = self.Trait(); anim.Play("left"); diff --git a/OpenRA.Mods.Cnc/WithFire.cs b/OpenRA.Mods.Cnc/WithFire.cs index d273cd23e1..1550f04196 100644 --- a/OpenRA.Mods.Cnc/WithFire.cs +++ b/OpenRA.Mods.Cnc/WithFire.cs @@ -13,7 +13,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Cnc { - class WithFireInfo : ITraitInfo, Requires + class WithFireInfo : ITraitInfo, Requires { public readonly WVec Offset = new WVec(299,-640,0); @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Cnc { public WithFire(Actor self, WithFireInfo info) { - var rs = self.Trait(); + var rs = self.Trait(); var roof = new Animation(rs.GetImage(self)); roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop")); diff --git a/OpenRA.Mods.Cnc/WithRoof.cs b/OpenRA.Mods.Cnc/WithRoof.cs index 0e22ab2b62..44eb4021da 100644 --- a/OpenRA.Mods.Cnc/WithRoof.cs +++ b/OpenRA.Mods.Cnc/WithRoof.cs @@ -13,7 +13,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Cnc { - public class WithRoofInfo : ITraitInfo, Requires + public class WithRoofInfo : ITraitInfo, Requires { public object Create(ActorInitializer init) { return new WithRoof(init.self); } } @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Cnc { public WithRoof(Actor self) { - var rs = self.Trait(); + var rs = self.Trait(); var roof = new Animation(rs.GetImage(self), () => self.Trait().Facing); roof.Play("roof"); rs.anims.Add("roof", new AnimationWithOffset(roof, null, null, 1024)); diff --git a/OpenRA.Mods.RA/Buildings/DeadBuildingState.cs b/OpenRA.Mods.RA/Buildings/DeadBuildingState.cs index 8c3792ae4c..a584fae188 100644 --- a/OpenRA.Mods.RA/Buildings/DeadBuildingState.cs +++ b/OpenRA.Mods.RA/Buildings/DeadBuildingState.cs @@ -13,7 +13,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.Cnc { - class DeadBuildingStateInfo : ITraitInfo, Requires, Requires + class DeadBuildingStateInfo : ITraitInfo, Requires, Requires { public readonly int LingerTime = 20; @@ -23,12 +23,12 @@ namespace OpenRA.Mods.Cnc class DeadBuildingState : INotifyKilled { DeadBuildingStateInfo info; - RenderSimple rs; + RenderSprites rs; public DeadBuildingState(Actor self, DeadBuildingStateInfo info) { this.info = info; - rs = self.Trait(); + rs = self.Trait(); self.Trait().RemoveOnDeath = !rs.anim.HasSequence("dead"); } diff --git a/OpenRA.Mods.RA/Burns.cs b/OpenRA.Mods.RA/Burns.cs index 2e0dd35cea..ece4d23566 100644 --- a/OpenRA.Mods.RA/Burns.cs +++ b/OpenRA.Mods.RA/Burns.cs @@ -13,7 +13,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - class BurnsInfo : ITraitInfo, Requires + class BurnsInfo : ITraitInfo, Requires { public readonly string Anim = "1"; public readonly int Damage = 1; @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA var anim = new Animation("fire", () => 0); anim.PlayRepeating(Info.Anim); - self.Trait().anims.Add("fire", + self.Trait().anims.Add("fire", new AnimationWithOffset(anim, () => info.Offset, null)); } diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index d806990f59..e1a2c87041 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -16,7 +16,7 @@ using OpenRA.Mods.RA.Buildings; namespace OpenRA.Mods.RA { - class CrateInfo : ITraitInfo, Requires + class CrateInfo : ITraitInfo, Requires { public readonly int Lifetime = 5; // Seconds public readonly string[] TerrainTypes = { }; @@ -116,7 +116,7 @@ namespace OpenRA.Mods.RA PxPosition = Util.CenterOfCell(cell); var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "land"; - var rs = self.Trait(); + var rs = self.Trait(); if (seq != rs.anim.CurrentSequence.Name) rs.anim.PlayRepeating(seq); diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs index 14e5ee2eb4..087a9076da 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render foreach (var r in p) yield return r; - var anim = new Animation(RenderSimple.GetImage(building), () => 0); + var anim = new Animation(RenderSprites.GetImage(building), () => 0); anim.PlayRepeating("idle-top"); yield return new SpriteRenderable(anim.Image, WPos.Zero + Origin, 0, pr, 1f); } diff --git a/OpenRA.Mods.RA/Render/RenderInfantry.cs b/OpenRA.Mods.RA/Render/RenderInfantry.cs index d81ab8cdf2..5103fc84d7 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantry.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantry.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA.Render public AnimationState State { get; private set; } public RenderInfantry(Actor self, RenderInfantryInfo info) - : base(self, RenderSimple.MakeFacingFunc(self)) + : base(self, MakeFacingFunc(self)) { Info = info; anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0); diff --git a/OpenRA.Mods.RA/Render/RenderUnit.cs b/OpenRA.Mods.RA/Render/RenderUnit.cs index d280ab04c1..1efdd5c6a2 100644 --- a/OpenRA.Mods.RA/Render/RenderUnit.cs +++ b/OpenRA.Mods.RA/Render/RenderUnit.cs @@ -22,10 +22,7 @@ namespace OpenRA.Mods.RA.Render public class RenderUnit : RenderSimple { public RenderUnit(Actor self) - : base(self, RenderSimple.MakeFacingFunc(self)) - { - anim.PlayRepeating("idle"); - } + : base(self) { } public void PlayCustomAnimation(Actor self, string newAnim, Action after) { diff --git a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs index 6886cf8e02..7e4cc7afc3 100644 --- a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs +++ b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs @@ -17,7 +17,7 @@ using OpenRA.Mods.RA; namespace OpenRA.Mods.RA.Render { - class WithMuzzleFlashInfo : ITraitInfo, Requires, Requires + class WithMuzzleFlashInfo : ITraitInfo, Requires, Requires { public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self); } } @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Render public WithMuzzleFlash(Actor self) { - var render = self.Trait(); + var render = self.Trait(); var facing = self.TraitOrDefault(); var arms = self.TraitsImplementing(); diff --git a/OpenRA.Mods.RA/Render/WithRotor.cs b/OpenRA.Mods.RA/Render/WithRotor.cs index eea9c0dd77..72be2a1511 100755 --- a/OpenRA.Mods.RA/Render/WithRotor.cs +++ b/OpenRA.Mods.RA/Render/WithRotor.cs @@ -14,7 +14,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { - public class WithRotorInfo : ITraitInfo, Requires + public class WithRotorInfo : ITraitInfo, Requires, Requires { [Desc("Position relative to body")] public readonly WVec Offset = WVec.Zero; @@ -28,12 +28,13 @@ namespace OpenRA.Mods.RA.Render public Animation rotorAnim; public WithRotor(Actor self, WithRotorInfo info) { - var rs = self.Trait(); + var rs = self.Trait(); + var coords = self.Trait(); rotorAnim = new Animation(rs.GetImage(self)); rotorAnim.PlayRepeating("rotor"); rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim, - () => rs.LocalToWorld(info.Offset.Rotate(rs.QuantizeOrientation(self, self.Orientation))), + () => coords.LocalToWorld(info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation))), null, p => WithTurret.ZOffsetFromCenter(self, p, 1))); } diff --git a/OpenRA.Mods.RA/Render/WithSmoke.cs b/OpenRA.Mods.RA/Render/WithSmoke.cs index c35c27dbda..d4dc2915a5 100644 --- a/OpenRA.Mods.RA/Render/WithSmoke.cs +++ b/OpenRA.Mods.RA/Render/WithSmoke.cs @@ -13,7 +13,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { - public class WithSmokeInfo : ITraitInfo, Requires + public class WithSmokeInfo : ITraitInfo, Requires { public object Create(ActorInitializer init) { return new WithSmoke(init.self); } } @@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Render public WithSmoke(Actor self) { - var rs = self.Trait(); + var rs = self.Trait(); anim = new Animation("smoke_m"); rs.anims.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking)); diff --git a/OpenRA.Mods.RA/Render/WithSpinner.cs b/OpenRA.Mods.RA/Render/WithSpinner.cs index c9a1eaf44e..939474cde0 100755 --- a/OpenRA.Mods.RA/Render/WithSpinner.cs +++ b/OpenRA.Mods.RA/Render/WithSpinner.cs @@ -14,7 +14,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { - class WithSpinnerInfo : ITraitInfo, Requires + class WithSpinnerInfo : ITraitInfo, Requires, Requires { [Desc("Sequence name to use")] public readonly string Sequence = "spinner"; @@ -29,11 +29,13 @@ namespace OpenRA.Mods.RA.Render { public WithSpinner(Actor self, WithSpinnerInfo info) { - var rs = self.Trait(); + var rs = self.Trait(); + var coords = self.Trait(); + var spinner = new Animation(rs.GetImage(self)); spinner.PlayRepeating(info.Sequence); rs.anims.Add("spinner_{0}".F(info.Sequence), new AnimationWithOffset(spinner, - () => rs.LocalToWorld(info.Offset.Rotate(rs.QuantizeOrientation(self, self.Orientation))), + () => coords.LocalToWorld(info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation))), null, p => WithTurret.ZOffsetFromCenter(self, p, 1))); } } diff --git a/OpenRA.Mods.RA/Render/WithTurret.cs b/OpenRA.Mods.RA/Render/WithTurret.cs index f802897779..3c5f68f3ac 100755 --- a/OpenRA.Mods.RA/Render/WithTurret.cs +++ b/OpenRA.Mods.RA/Render/WithTurret.cs @@ -17,7 +17,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { - class WithTurretInfo : ITraitInfo, Requires, Requires + class WithTurretInfo : ITraitInfo, Requires, Requires, Requires { [Desc("Sequence name to use")] public readonly string Sequence = "turret"; @@ -37,7 +37,8 @@ namespace OpenRA.Mods.RA.Render class WithTurret : ITick { WithTurretInfo info; - RenderSimple rs; + RenderSprites rs; + ILocalCoordinatesModel coords; AttackBase ab; Turreted t; IEnumerable arms; @@ -46,7 +47,9 @@ namespace OpenRA.Mods.RA.Render public WithTurret(Actor self, WithTurretInfo info) { this.info = info; - rs = self.Trait(); + rs = self.Trait(); + coords = self.Trait(); + ab = self.TraitOrDefault(); t = self.TraitsImplementing() .First(tt => tt.Name == info.Turret); @@ -69,9 +72,9 @@ namespace OpenRA.Mods.RA.Render var recoil = arms.Aggregate(WRange.Zero, (a,b) => a + b.Recoil); var localOffset = new WVec(-recoil, WRange.Zero, WRange.Zero); - var bodyOrientation = rs.QuantizeOrientation(self, self.Orientation); - var turretOrientation = rs.QuantizeOrientation(self, t.LocalOrientation(self)); - return t.Position(self) + rs.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation)); + var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation); + var turretOrientation = coords.QuantizeOrientation(self, t.LocalOrientation(self)); + return t.Position(self) + coords.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation)); } public void Tick(Actor self) diff --git a/OpenRA.Mods.RA/Spy.cs b/OpenRA.Mods.RA/Spy.cs index a381444d1a..aa3651c59b 100644 --- a/OpenRA.Mods.RA/Spy.cs +++ b/OpenRA.Mods.RA/Spy.cs @@ -126,7 +126,7 @@ namespace OpenRA.Mods.RA var tooltip = target.TraitsImplementing().FirstOrDefault(); disguisedAsName = tooltip.Name(); disguisedAsPlayer = tooltip.Owner(); - disguisedAsSprite = target.Trait().GetImage(target); + disguisedAsSprite = target.Trait().GetImage(target); } void DropDisguise() diff --git a/OpenRA.Mods.RA/SupportPowers/NukePower.cs b/OpenRA.Mods.RA/SupportPowers/NukePower.cs index cb7b9b5ea7..08f9448b73 100755 --- a/OpenRA.Mods.RA/SupportPowers/NukePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/NukePower.cs @@ -14,7 +14,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - class NukePowerInfo : SupportPowerInfo + class NukePowerInfo : SupportPowerInfo, Requires { [WeaponReference] public readonly string MissileWeapon = ""; @@ -25,7 +25,14 @@ namespace OpenRA.Mods.RA class NukePower : SupportPower { - public NukePower(Actor self, NukePowerInfo info) : base(self, info) { } + ILocalCoordinatesModel coords; + + public NukePower(Actor self, NukePowerInfo info) + : base(self, info) + { + coords = self.Trait(); + } + public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager) { Sound.PlayToPlayer(manager.self.Owner, Info.SelectTargetSound); @@ -42,7 +49,7 @@ namespace OpenRA.Mods.RA var rb = self.Trait(); rb.PlayCustomAnim(self, "active"); self.World.AddFrameEndTask(w => w.Add( - new NukeLaunch(self.Owner, self, npi.MissileWeapon, self.CenterPosition + rb.LocalToWorld(npi.SpawnOffset), order.TargetLocation))); + new NukeLaunch(self.Owner, self, npi.MissileWeapon, self.CenterPosition + coords.LocalToWorld(npi.SpawnOffset), order.TargetLocation))); } } } diff --git a/OpenRA.Mods.RA/ThrowsParticle.cs b/OpenRA.Mods.RA/ThrowsParticle.cs index f6bb3a3842..7e9248f1ba 100644 --- a/OpenRA.Mods.RA/ThrowsParticle.cs +++ b/OpenRA.Mods.RA/ThrowsParticle.cs @@ -15,7 +15,7 @@ using OpenRA.Traits; namespace OpenRA.Mods.RA { - class ThrowsParticleInfo : ITraitInfo, Requires + class ThrowsParticleInfo : ITraitInfo, Requires, Requires { public readonly string Anim = null; @@ -54,6 +54,7 @@ namespace OpenRA.Mods.RA var self = init.self; var rs = self.Trait(); + var coords = self.Trait(); // TODO: Carry orientation over from the parent instead of just facing var bodyFacing = init.Contains() ? init.Get() : 0; @@ -63,7 +64,7 @@ namespace OpenRA.Mods.RA var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024)); var throwOffset = new WVec((int)(Game.CosmeticRandom.Gauss1D(1)*info.ThrowRange.Range), 0, 0).Rotate(throwRotation); - initialPos = pos = info.Offset.Rotate(rs.QuantizeOrientation(self, WRot.FromFacing(bodyFacing))); + initialPos = pos = info.Offset.Rotate(coords.QuantizeOrientation(self, WRot.FromFacing(bodyFacing))); finalPos = initialPos + throwOffset; // Facing rotation