diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index dfcdd8cdca..08fbaf0a17 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -143,9 +143,9 @@ namespace OpenRA OpenRA.FileFormats.Lazy Size; // note: these delegates are cached to avoid massive allocation. - Func> ApplyIRender; - Func, IRenderModifier, WorldRenderer, IEnumerable> ApplyRenderModifier; - public IEnumerable Render(WorldRenderer wr) + Func> ApplyIRender; + Func, IRenderModifier, WorldRenderer, IEnumerable> ApplyRenderModifier; + public IEnumerable Render(WorldRenderer wr) { var mods = TraitsImplementing(); var sprites = TraitsImplementing().SelectMany(x => ApplyIRender(x, wr)); diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs index 832aab7998..02e117c220 100644 --- a/OpenRA.Game/CPos.cs +++ b/OpenRA.Game/CPos.cs @@ -43,6 +43,8 @@ namespace OpenRA public int2 ToInt2() { return new int2(X, Y); } public PPos ToPPos() { return new PPos(Game.CellSize * X, Game.CellSize * Y); } + public WPos CenterPosition { get { return new WPos(1024*X + 512, 1024*Y + 512, 0); } } + public CPos Clamp(Rectangle r) { return new CPos(Math.Min(r.Right, Math.Max(X, r.Left)), diff --git a/OpenRA.Game/CVec.cs b/OpenRA.Game/CVec.cs index 31b4e3bbc5..d21a4c21ff 100644 --- a/OpenRA.Game/CVec.cs +++ b/OpenRA.Game/CVec.cs @@ -51,6 +51,7 @@ namespace OpenRA public float2 ToFloat2() { return new float2(X, Y); } public int2 ToInt2() { return new int2(X, Y); } + public WVec ToWVec() { return new WVec(X*1024, Y*1024, 0); } public CVec Clamp(Rectangle r) { diff --git a/OpenRA.Game/Effects/DelayedAction.cs b/OpenRA.Game/Effects/DelayedAction.cs index 609af16c4a..1cb1440874 100755 --- a/OpenRA.Game/Effects/DelayedAction.cs +++ b/OpenRA.Game/Effects/DelayedAction.cs @@ -32,6 +32,6 @@ namespace OpenRA.Effects world.AddFrameEndTask(w => { w.Remove(this); a(); }); } - public IEnumerable Render(WorldRenderer wr) { yield break; } + public IEnumerable Render(WorldRenderer wr) { yield break; } } } diff --git a/OpenRA.Game/Effects/FlashTarget.cs b/OpenRA.Game/Effects/FlashTarget.cs index c8c422d791..a3fffc49b8 100755 --- a/OpenRA.Game/Effects/FlashTarget.cs +++ b/OpenRA.Game/Effects/FlashTarget.cs @@ -33,7 +33,7 @@ namespace OpenRA.Effects world.AddFrameEndTask(w => w.Remove(this)); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (!target.IsInWorld) yield break; diff --git a/OpenRA.Game/Effects/IEffect.cs b/OpenRA.Game/Effects/IEffect.cs index 5bab9cfcf3..33d4ada440 100755 --- a/OpenRA.Game/Effects/IEffect.cs +++ b/OpenRA.Game/Effects/IEffect.cs @@ -17,6 +17,6 @@ namespace OpenRA.Effects public interface IEffect { void Tick(World world); - IEnumerable Render(WorldRenderer r); + IEnumerable Render(WorldRenderer r); } } diff --git a/OpenRA.Game/Graphics/AnimationWithOffset.cs b/OpenRA.Game/Graphics/AnimationWithOffset.cs index 8691c91c6e..338fbcf956 100644 --- a/OpenRA.Game/Graphics/AnimationWithOffset.cs +++ b/OpenRA.Game/Graphics/AnimationWithOffset.cs @@ -15,36 +15,43 @@ namespace OpenRA.Graphics { public class AnimationWithOffset { - public Animation Animation; - public Func OffsetFunc; - public Func DisableFunc; - public int ZOffset; + public readonly Animation Animation; + public readonly Func OffsetFunc; + public readonly Func DisableFunc; + public readonly Func ZOffset; - public AnimationWithOffset(Animation a) - : this(a, null, null) - { - } + public AnimationWithOffset(Animation a, Func offset, Func disable) + : this(a, offset, disable, null) { } - public AnimationWithOffset(Animation a, Func o, Func d) + public AnimationWithOffset(Animation a, Func offset, Func disable, int zOffset) + : this(a, offset, disable, _ => zOffset) { } + + public AnimationWithOffset(Animation a, Func offset, Func disable, Func zOffset) { this.Animation = a; - this.OffsetFunc = o; - this.DisableFunc = d; + this.OffsetFunc = offset; + this.DisableFunc = disable; + this.ZOffset = zOffset; } - public Renderable Image(Actor self, WorldRenderer wr, PaletteReference pal) + public IRenderable Image(Actor self, WorldRenderer wr, PaletteReference pal) { - var p = self.CenterLocation; - var loc = p.ToFloat2() - 0.5f * Animation.Image.size - + (OffsetFunc != null ? OffsetFunc(wr) : float2.Zero); - var r = new Renderable(Animation.Image, loc, pal, p.Y); + return Image(self, wr, pal, 1f); + } - return ZOffset != 0 ? r.WithZOffset(ZOffset) : r; + public IRenderable Image(Actor self, WorldRenderer wr, PaletteReference pal, float scale) + { + var p = self.CenterPosition; + if (OffsetFunc != null) + p += OffsetFunc(); + + var z = (ZOffset != null) ? ZOffset(p) : 0; + return new SpriteRenderable(Animation.Image, p, z, pal, scale); } public static implicit operator AnimationWithOffset(Animation a) { - return new AnimationWithOffset(a); + return new AnimationWithOffset(a, null, null, null); } } } diff --git a/OpenRA.Game/Graphics/Renderable.cs b/OpenRA.Game/Graphics/Renderable.cs new file mode 100644 index 0000000000..d8e247431f --- /dev/null +++ b/OpenRA.Game/Graphics/Renderable.cs @@ -0,0 +1,94 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 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 System.Collections.Generic; +using System.Drawing; + +namespace OpenRA.Graphics +{ + public class RenderableComparer : IComparer + { + WorldRenderer wr; + public RenderableComparer(WorldRenderer wr) + { + this.wr = wr; + } + + public int Compare(IRenderable x, IRenderable y) + { + var xOrder = wr.ScreenZPosition(x.Pos, x.ZOffset); + var yOrder = wr.ScreenZPosition(y.Pos, y.ZOffset); + return xOrder.CompareTo(yOrder); + } + } + + public interface IRenderable + { + WPos Pos { get; } + float Scale { get; } + PaletteReference Palette { get; } + int ZOffset { get; } + + IRenderable WithScale(float newScale); + IRenderable WithPalette(PaletteReference newPalette); + IRenderable WithZOffset(int newOffset); + IRenderable WithPos(WPos pos); + void Render(WorldRenderer wr); + WVec Size(WorldRenderer wr); + } + + public struct SpriteRenderable : IRenderable + { + readonly Sprite sprite; + readonly WPos pos; + readonly int zOffset; + readonly PaletteReference palette; + readonly float scale; + readonly float2 pxCenter; + + public SpriteRenderable(Sprite sprite, WPos pos, int zOffset, PaletteReference palette, float scale) + : this(sprite, pos, zOffset, palette, scale, 0.5f*scale*sprite.size) {} + + public SpriteRenderable(Sprite sprite, WPos pos, int zOffset, PaletteReference palette, float scale, float2 pxCenter) + { + this.sprite = sprite; + this.pos = pos; + this.zOffset = zOffset; + this.palette = palette; + this.scale = scale; + this.pxCenter = pxCenter; + } + + // Provided for legacy support only - Don't use for new things! + public SpriteRenderable(Sprite sprite, float2 pos, PaletteReference palette, int z) + : this(sprite, new PPos((int)pos.X, (int)pos.Y).ToWPos(0), z, palette, 1f) { } + + public WPos Pos { get { return pos; } } + public float Scale { get { return scale; } } + public PaletteReference Palette { get { return palette; } } + public int ZOffset { get { return zOffset; } } + + public IRenderable WithScale(float newScale) { return new SpriteRenderable(sprite, pos, zOffset, palette, newScale); } + public IRenderable WithPalette(PaletteReference newPalette) { return new SpriteRenderable(sprite, pos, zOffset, newPalette, scale); } + public IRenderable WithZOffset(int newOffset) { return new SpriteRenderable(sprite, pos, newOffset, palette, scale); } + public IRenderable WithPos(WPos pos) { return new SpriteRenderable(sprite, pos, zOffset, palette, scale); } + + public void Render(WorldRenderer wr) + { + sprite.DrawAt(wr.ScreenPxPosition(pos) - pxCenter, palette.Index, scale); + } + + public WVec Size(WorldRenderer wr) + { + var size = (scale*sprite.size).ToInt2(); + return new WVec(size.X, size.Y, size.Y); + } + } +} diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index b3dd017af4..87eef096f2 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -65,30 +65,23 @@ namespace OpenRA.Graphics public PaletteReference Palette(string name) { return palettes[name]; } public void AddPalette(string name, Palette pal, bool allowModifiers) { palette.AddPalette(name, pal, allowModifiers); } - class SpriteComparer : IComparer - { - public int Compare(Renderable x, Renderable y) - { - return (x.Z + x.ZOffset).CompareTo(y.Z + y.ZOffset); - } - } - - IEnumerable SpritesToRender() + void DrawRenderables() { var bounds = Game.viewport.WorldBounds(world); - var comparer = new SpriteComparer(); + var comparer = new RenderableComparer(this); var actors = world.FindUnits( bounds.TopLeftAsCPos().ToPPos(), - bounds.BottomRightAsCPos().ToPPos() - ); + bounds.BottomRightAsCPos().ToPPos()); - var renderables = actors.SelectMany(a => a.Render(this)) - .OrderBy(r => r, comparer); + actors.SelectMany(a => a.Render(this)) + .OrderBy(r => r, comparer) + .Do(rr => rr.Render(this)); - var effects = world.Effects.SelectMany(e => e.Render(this)); - - return renderables.Concat(effects); + // Effects are drawn on top of all actors + // TODO: Allow effects to be interleaved with actors + world.Effects.SelectMany(e => e.Render(this)) + .Do(rr => rr.Render(this)); } public void Draw() @@ -104,7 +97,7 @@ namespace OpenRA.Graphics terrainRenderer.Draw(this, Game.viewport); foreach (var a in world.traitDict.ActorsWithTraitMultiple(world)) foreach (var r in a.Trait.RenderAsTerrain(this, a.Actor)) - r.Sprite.DrawAt(r.Pos, r.Palette.Index, r.Scale); + r.Render(this); foreach (var a in world.Selection.Actors) if (!a.Destroyed) @@ -116,8 +109,7 @@ namespace OpenRA.Graphics if (world.OrderGenerator != null) world.OrderGenerator.RenderBeforeWorld(this, world); - foreach (var image in SpritesToRender()) - image.Sprite.DrawAt(image.Pos, image.Palette.Index, image.Scale); + DrawRenderables(); // added for contrails foreach (var a in world.ActorsWithTrait()) @@ -222,19 +214,11 @@ namespace OpenRA.Graphics public int2 ScreenPxPosition(WPos pos) { - return new int2(Game.CellSize*pos.X/1024, Game.CellSize*(pos.Y - pos.Z)/1024); - } - public float ScreenZOffset(WPos pos) { return pos.Z*Game.CellSize/1024f; } - - public int2 ScreenPxOffset(WVec vec) - { - return new int2(Game.CellSize*vec.X/1024, Game.CellSize*(vec.Y - vec.Z)/1024); + // Round to nearest pixel + var px = ScreenPosition(pos); + return new int2((int)Math.Round(px.X), (int)Math.Round(px.Y)); } - public float[] ScreenOffset(WVec vec) - { - var c = Game.CellSize/1024f; - return new float[] {c*vec.X, c*vec.Y, c*vec.Z}; - } + public float ScreenZPosition(WPos pos, int zOffset) { return (pos.Y + pos.Z + zOffset)*Game.CellSize/1024f; } } } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index a6f99c8a59..29cf8054bf 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -224,6 +224,7 @@ + diff --git a/OpenRA.Game/Traits/Render/RenderSimple.cs b/OpenRA.Game/Traits/Render/RenderSimple.cs index eec13f8683..f26e73ea2a 100755 --- a/OpenRA.Game/Traits/Render/RenderSimple.cs +++ b/OpenRA.Game/Traits/Render/RenderSimple.cs @@ -30,15 +30,16 @@ namespace OpenRA.Traits [Desc("Number of facings for gameplay calculations. -1 indiciates auto-detection from sequence")] public readonly int QuantizedFacings = -1; + [Desc("Camera pitch the sprite was rendered with. Used to determine rotation ellipses")] public readonly WAngle CameraPitch = WAngle.FromDegrees(40); public virtual object Create(ActorInitializer init) { return new RenderSimple(init.self); } - public virtual IEnumerable RenderPreview(ActorInfo building, PaletteReference pr) + public virtual IEnumerable RenderPreview(ActorInfo ai, PaletteReference pr) { - var anim = new Animation(RenderSimple.GetImage(building), () => 0); + var anim = new Animation(RenderSimple.GetImage(ai), () => 0); anim.PlayRepeating("idle"); - yield return new Renderable(anim.Image, 0.5f * anim.Image.size * (1 - Scale), pr, 0, Scale); + yield return new SpriteRenderable(anim.Image, WPos.Zero, 0, pr, 1f); } } @@ -56,7 +57,8 @@ namespace OpenRA.Traits public Animation anim { get { return anims[""].Animation; } - protected set { anims[""].Animation = value; } + protected set { anims[""] = new AnimationWithOffset(value, + anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].ZOffset); } } public static string GetImage(ActorInfo actor) @@ -97,7 +99,7 @@ namespace OpenRA.Traits protected void UpdatePalette() { initializePalette = true; } public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { UpdatePalette(); } - public virtual IEnumerable Render(Actor self, WorldRenderer wr) + public virtual IEnumerable Render(Actor self, WorldRenderer wr) { if (initializePalette) { @@ -107,12 +109,7 @@ namespace OpenRA.Traits foreach (var a in anims.Values) if (a.DisableFunc == null || !a.DisableFunc()) - { - Renderable ret = a.Image(self, wr, palette); - if (Info.Scale != 1f) - ret = ret.WithScale(Info.Scale).WithPos(ret.Pos + 0.5f * ret.Sprite.size * (1 - Info.Scale)); - yield return ret; - } + yield return a.Image(self, wr, palette, Info.Scale); } public int2 SelectionSize(Actor self) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 30d6c152d2..0fb4bb2de7 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -35,7 +35,7 @@ namespace OpenRA.Traits public interface ITick { void Tick(Actor self); } public interface ITickRender { void TickRender(WorldRenderer wr, Actor self); } - public interface IRender { IEnumerable Render(Actor self, WorldRenderer wr); } + public interface IRender { IEnumerable Render(Actor self, WorldRenderer wr); } public interface IAutoSelectionSize { int2 SelectionSize(Actor self); } public interface IIssueOrder @@ -116,7 +116,7 @@ namespace OpenRA.Traits } public interface INotifyAttack { void Attacking(Actor self, Target target); } - public interface IRenderModifier { IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r); } + public interface IRenderModifier { IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r); } public interface IDamageModifier { float GetDamageModifier(Actor attacker, WarheadInfo warhead); } public interface ISpeedModifier { decimal GetSpeedModifier(); } public interface IFirepowerModifier { float GetFirepowerModifier(); } @@ -152,37 +152,6 @@ namespace OpenRA.Traits bool CrushableBy(string[] crushClasses, Player owner); } - public struct Renderable - { - public readonly Sprite Sprite; - public readonly float2 Pos; - public readonly PaletteReference Palette; - public readonly int Z; - public readonly int ZOffset; - public float Scale; - - public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z, int zOffset, float scale) - { - Sprite = sprite; - Pos = pos; - Palette = palette; - Z = z; - ZOffset = zOffset; - Scale = scale; /* default */ - } - - public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z) - : this(sprite, pos, palette, z, 0, 1f) { } - - public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z, float scale) - : this(sprite, pos, palette, z, 0, scale) { } - - public Renderable WithScale(float newScale) { return new Renderable(Sprite, Pos, Palette, Z, ZOffset, newScale); } - public Renderable WithPalette(PaletteReference newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset, Scale); } - public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, Z, newOffset, Scale); } - public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, Z, ZOffset, Scale); } - } - public interface ITraitInfo { object Create(ActorInitializer init); } public class TraitInfo : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } } @@ -210,7 +179,7 @@ namespace OpenRA.Traits public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr); } public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); } - public interface IRenderAsTerrain { IEnumerable RenderAsTerrain(WorldRenderer wr, Actor self); } + public interface IRenderAsTerrain { IEnumerable RenderAsTerrain(WorldRenderer wr, Actor self); } public interface ILocalCoordinatesModel { WVec LocalToWorld(WVec vec); diff --git a/OpenRA.Mods.Cnc/Effects/IonCannon.cs b/OpenRA.Mods.Cnc/Effects/IonCannon.cs index df9ae17f00..697efece23 100644 --- a/OpenRA.Mods.Cnc/Effects/IonCannon.cs +++ b/OpenRA.Mods.Cnc/Effects/IonCannon.cs @@ -32,10 +32,10 @@ namespace OpenRA.Mods.Cnc.Effects public void Tick(World world) { anim.Tick(); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(anim.Image, - target.CenterLocation.ToFloat2() - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize), + yield return new SpriteRenderable(anim.Image, + target.CenterLocation.ToFloat2() - new float2(0, 0.5f*anim.Image.size.Y - Game.CellSize), wr.Palette("effect"), (int)target.CenterLocation.Y); } diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index 710b030414..4a6755178c 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -86,7 +86,7 @@ - + diff --git a/OpenRA.Mods.Cnc/RenderBuildingRefinery.cs b/OpenRA.Mods.Cnc/RenderBuildingRefinery.cs index 819f02cf53..fe21c3322b 100755 --- a/OpenRA.Mods.Cnc/RenderBuildingRefinery.cs +++ b/OpenRA.Mods.Cnc/RenderBuildingRefinery.cs @@ -18,7 +18,9 @@ namespace OpenRA.Mods.Cnc { class RenderBuildingRefineryInfo : RenderBuildingInfo { - public override object Create(ActorInitializer init) { return new RenderBuildingRefinery( init, this ); } + public readonly WVec Offset = new WVec(1365, 896, 0); + + public override object Create(ActorInitializer init) { return new RenderBuildingRefinery(init, this); } } class RenderBuildingRefinery : RenderBuilding, INotifyBuildComplete, INotifySold, INotifyCapture @@ -27,7 +29,7 @@ namespace OpenRA.Mods.Cnc PlayerResources playerResources; bool buildComplete; - public RenderBuildingRefinery(ActorInitializer init, RenderBuildingInfo info) + public RenderBuildingRefinery(ActorInitializer init, RenderBuildingRefineryInfo info) : base(init, info) { playerResources = init.self.Owner.PlayerActor.Trait(); @@ -38,9 +40,7 @@ namespace OpenRA.Mods.Cnc ? (59 * playerResources.Ore) / (10 * playerResources.OreCapacity) : 0); - var offset = new float2(-32,-21); - anims.Add("lights", new AnimationWithOffset( lights, wr => offset, () => !buildComplete ) - { ZOffset = 24 }); + anims.Add("lights", new AnimationWithOffset(lights, () => info.Offset, () => !buildComplete, 1024)); } public void BuildingComplete( Actor self ) diff --git a/OpenRA.Mods.Cnc/RenderCargo.cs b/OpenRA.Mods.Cnc/RenderCargo.cs deleted file mode 100644 index 86b96d7e0b..0000000000 --- a/OpenRA.Mods.Cnc/RenderCargo.cs +++ /dev/null @@ -1,64 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 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 System.Collections.Generic; -using System.Linq; -using OpenRA.Mods.RA; -using OpenRA.Graphics; -using OpenRA.Traits; - -namespace OpenRA.Mods.Cnc -{ - public class RenderCargoInfo : ITraitInfo, Requires - { - /* altitude of the cargo, relative to us. -ve is underneath us */ - public readonly int RelativeAltitude = 0; - public readonly string[] PassengerTypes; - - public object Create(ActorInitializer init) { return new RenderCargo(init.self, this); } - } - - public class RenderCargo : IRenderModifier - { - Cargo cargo; - IFacing facing; - IMove move; - RenderCargoInfo Info; - - public RenderCargo(Actor self, RenderCargoInfo info) - { - cargo = self.Trait(); - facing = self.TraitOrDefault(); - move = self.Trait(); - Info = info; - } - - public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) - { - foreach (var c in cargo.Passengers) - { - c.Trait().SetPxPosition( c, move.PxPosition ); - - var cargoFacing = c.TraitOrDefault(); - if (facing != null && cargoFacing != null) - cargoFacing.Facing = facing.Facing; - } - - var visiblePassengers = (Info.PassengerTypes != null && Info.PassengerTypes.Length > 0) - ? cargo.Passengers.Where(p => - Info.PassengerTypes.Contains(p.Trait().info.CargoType)) - : cargo.Passengers; - - return r.Concat(visiblePassengers.SelectMany(a => a.Render(wr)) - .Select(a => a.WithPos(a.Pos - new float2(0, Info.RelativeAltitude)) - .WithZOffset(a.ZOffset + Info.RelativeAltitude))); - } - } -} \ No newline at end of file diff --git a/OpenRA.Mods.Cnc/RenderGunboat.cs b/OpenRA.Mods.Cnc/RenderGunboat.cs index 9bb6be9d3d..0b9c047c82 100644 --- a/OpenRA.Mods.Cnc/RenderGunboat.cs +++ b/OpenRA.Mods.Cnc/RenderGunboat.cs @@ -34,8 +34,12 @@ namespace OpenRA.Mods.RA.Render var wake = new Animation(anim.Name); wake.Play("left-wake"); - Func offset = wr => new float2(((anims["wake"].Animation.CurrentSequence.Name == "left-wake") ? 1 : -1),2); - anims.Add( "wake", new AnimationWithOffset( wake, offset, () => false ) { ZOffset = -2 } ); + + var leftOffset = new WVec(43, 86, 0); + var rightOffset = new WVec(-43, 86, 0); + anims.Add("wake", new AnimationWithOffset(wake, + () => anims["wake"].Animation.CurrentSequence.Name == "left-wake" ? leftOffset : rightOffset, + () => false, -87)); } public override void Tick(Actor self) diff --git a/OpenRA.Mods.Cnc/WithCargo.cs b/OpenRA.Mods.Cnc/WithCargo.cs new file mode 100644 index 0000000000..906e00db52 --- /dev/null +++ b/OpenRA.Mods.Cnc/WithCargo.cs @@ -0,0 +1,78 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 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 System; +using System.Collections.Generic; +using System.Linq; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Mods.RA; +using OpenRA.Traits; + +namespace OpenRA.Mods.Cnc +{ + public class WithCargoInfo : ITraitInfo, Requires, Requires + { + [Desc("Cargo position relative to turret or body. (forward, right, up) triples")] + public readonly WRange[] LocalOffset = {}; + public readonly string[] DisplayTypes = {}; + + public object Create(ActorInitializer init) { return new WithCargo(init.self, this); } + } + + public class WithCargo : IRenderModifier + { + Cargo cargo; + IFacing facing; + WithCargoInfo Info; + WVec[] positions; + ILocalCoordinatesModel coords; + + public WithCargo(Actor self, WithCargoInfo info) + { + cargo = self.Trait(); + facing = self.TraitOrDefault(); + Info = info; + + coords = self.Trait(); + + if (info.LocalOffset.Length % 3 != 0) + throw new InvalidOperationException("Invalid LocalOffset array length"); + + positions = new WVec[info.LocalOffset.Length / 3]; + for (var i = 0; i < info.LocalOffset.Length / 3; i++) + positions[i] = new WVec(info.LocalOffset[3*i], info.LocalOffset[3*i + 1], info.LocalOffset[3*i + 2]); + } + + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + { + foreach (var rr in r) + yield return rr; + + var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation); + var pos = self.CenterPosition; + int i = 0; + foreach (var c in cargo.Passengers) + { + var cargoFacing = c.TraitOrDefault(); + if (facing != null && cargoFacing != null) + cargoFacing.Facing = facing.Facing; + + var cargoPassenger = c.Trait(); + if (Info.DisplayTypes.Contains(cargoPassenger.info.CargoType)) + { + var offset = pos - c.CenterPosition + coords.LocalToWorld(positions[i++ % positions.Length].Rotate(bodyOrientation)); + foreach (var cr in c.Render(wr)) + yield return cr.WithPos(cr.Pos + offset).WithZOffset(1); + } + } + } + } +} \ No newline at end of file diff --git a/OpenRA.Mods.Cnc/WithFire.cs b/OpenRA.Mods.Cnc/WithFire.cs index 85ee48ca0b..d273cd23e1 100644 --- a/OpenRA.Mods.Cnc/WithFire.cs +++ b/OpenRA.Mods.Cnc/WithFire.cs @@ -15,17 +15,20 @@ namespace OpenRA.Mods.Cnc { class WithFireInfo : ITraitInfo, Requires { - public object Create(ActorInitializer init) { return new WithFire(init.self); } + public readonly WVec Offset = new WVec(299,-640,0); + + public object Create(ActorInitializer init) { return new WithFire(init.self, this); } } class WithFire { - public WithFire(Actor self) + public WithFire(Actor self, WithFireInfo info) { var rs = self.Trait(); var roof = new Animation(rs.GetImage(self)); roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop")); - rs.anims.Add( "fire", new AnimationWithOffset( roof, wr => new float2(7,-15), null ) { ZOffset = 24 } ); + + rs.anims.Add("fire", new AnimationWithOffset(roof, () => info.Offset, null, 1024)); } } } diff --git a/OpenRA.Mods.Cnc/WithRoof.cs b/OpenRA.Mods.Cnc/WithRoof.cs index 6c32d788ee..0e22ab2b62 100644 --- a/OpenRA.Mods.Cnc/WithRoof.cs +++ b/OpenRA.Mods.Cnc/WithRoof.cs @@ -25,7 +25,7 @@ namespace OpenRA.Mods.Cnc var rs = self.Trait(); var roof = new Animation(rs.GetImage(self), () => self.Trait().Facing); roof.Play("roof"); - rs.anims.Add( "roof", new AnimationWithOffset( roof ) { ZOffset = 24 } ); + rs.anims.Add("roof", new AnimationWithOffset(roof, null, null, 1024)); } } } diff --git a/OpenRA.Mods.RA/Air/EjectOnDeath.cs b/OpenRA.Mods.RA/Air/EjectOnDeath.cs index d1ed8c28da..d3824b9c2b 100644 --- a/OpenRA.Mods.RA/Air/EjectOnDeath.cs +++ b/OpenRA.Mods.RA/Air/EjectOnDeath.cs @@ -35,9 +35,7 @@ namespace OpenRA.Mods.RA if (IsSuitableCell(pilot, self.Location) && r > 100 - info.SuccessRate && aircraft.Altitude > 10 && self.Owner.WinState != WinState.Lost) { - self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, - Util.CenterOfCell(self.CenterLocation.ToCPos()), aircraft.Altitude))); - + self.World.AddFrameEndTask(w => w.Add(new Parachute(pilot, self.CenterPosition))); Sound.Play(info.ChuteSound, self.CenterLocation); } else diff --git a/OpenRA.Mods.RA/BelowUnits.cs b/OpenRA.Mods.RA/BelowUnits.cs index 4795bd7f0c..64c5c36bc2 100644 --- a/OpenRA.Mods.RA/BelowUnits.cs +++ b/OpenRA.Mods.RA/BelowUnits.cs @@ -19,9 +19,9 @@ namespace OpenRA.Mods.RA class BelowUnits : IRenderModifier { - public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { - return r.Select(a => a.WithZOffset((int) -a.Sprite.size.Y)); + return r.Select(a => a.WithZOffset(-a.Size(wr).Z)); } } } diff --git a/OpenRA.Mods.RA/Bridge.cs b/OpenRA.Mods.RA/Bridge.cs index d7fda56878..c3b4425594 100644 --- a/OpenRA.Mods.RA/Bridge.cs +++ b/OpenRA.Mods.RA/Bridge.cs @@ -142,7 +142,7 @@ namespace OpenRA.Mods.RA bool initializePalettes = true; PaletteReference terrainPalette; - public IEnumerable RenderAsTerrain(WorldRenderer wr, Actor self) + public IEnumerable RenderAsTerrain(WorldRenderer wr, Actor self) { if (initializePalettes) { @@ -151,7 +151,7 @@ namespace OpenRA.Mods.RA } foreach (var t in TileSprites[currentTemplate]) - yield return new Renderable(t.Value, t.Key.ToPPos().ToFloat2(), terrainPalette, Game.CellSize * t.Key.Y); + yield return new SpriteRenderable(t.Value, t.Key.CenterPosition, 0, terrainPalette, 1f); } void KillUnitsOnBridge() diff --git a/OpenRA.Mods.RA/Buildings/FootprintUtils.cs b/OpenRA.Mods.RA/Buildings/FootprintUtils.cs index 6808cbf94d..cddc6ac7c2 100755 --- a/OpenRA.Mods.RA/Buildings/FootprintUtils.cs +++ b/OpenRA.Mods.RA/Buildings/FootprintUtils.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Linq; +using OpenRA.FileFormats; namespace OpenRA.Mods.RA.Buildings { @@ -55,10 +56,16 @@ namespace OpenRA.Mods.RA.Buildings yield return new CVec(x, y); } - public static CVec AdjustForBuildingSize( BuildingInfo buildingInfo ) + public static CVec AdjustForBuildingSize(BuildingInfo buildingInfo) { var dim = buildingInfo.Dimensions; return new CVec(dim.X / 2, dim.Y > 1 ? (dim.Y + 1) / 2 : 0); } + + public static WVec CenterOffset(BuildingInfo buildingInfo) + { + var dim = buildingInfo.Dimensions; + return new CVec(dim.X, dim.Y).ToWVec() / 2; + } } } diff --git a/OpenRA.Mods.RA/Burns.cs b/OpenRA.Mods.RA/Burns.cs index 34c3db5528..2e0dd35cea 100644 --- a/OpenRA.Mods.RA/Burns.cs +++ b/OpenRA.Mods.RA/Burns.cs @@ -18,6 +18,7 @@ namespace OpenRA.Mods.RA public readonly string Anim = "1"; public readonly int Damage = 1; public readonly int Interval = 8; + public readonly WVec Offset = new WVec(0,0,128); public object Create(ActorInitializer init) { return new Burns(init.self, this); } } @@ -30,11 +31,11 @@ namespace OpenRA.Mods.RA public Burns(Actor self, BurnsInfo info) { Info = info; - var rs = self.Trait(); + var anim = new Animation("fire", () => 0); - anim.PlayRepeating(Info.Anim); - rs.anims.Add("fire", - new AnimationWithOffset(anim, wr => new float2(0, -3), null)); + anim.PlayRepeating(Info.Anim); + self.Trait().anims.Add("fire", + new AnimationWithOffset(anim, () => info.Offset, null)); } public void Tick(Actor self) diff --git a/OpenRA.Mods.RA/Cloak.cs b/OpenRA.Mods.RA/Cloak.cs index b5a1cf770a..81fa26ede3 100644 --- a/OpenRA.Mods.RA/Cloak.cs +++ b/OpenRA.Mods.RA/Cloak.cs @@ -66,9 +66,9 @@ namespace OpenRA.Mods.RA if (!canCloak) Uncloak(); } - static readonly Renderable[] Nothing = { }; + static readonly IRenderable[] Nothing = { }; - public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { if (remainingTime > 0) return r; diff --git a/OpenRA.Mods.RA/Effects/Bullet.cs b/OpenRA.Mods.RA/Effects/Bullet.cs index 0850180d61..5193c3bd4f 100755 --- a/OpenRA.Mods.RA/Effects/Bullet.cs +++ b/OpenRA.Mods.RA/Effects/Bullet.cs @@ -123,7 +123,7 @@ namespace OpenRA.Mods.RA.Effects if (Info.Trail != null && --ticksToNextSmoke < 0) { world.AddFrameEndTask(w => w.Add( - new Smoke(w, (PPos) highPos.ToInt2(), Info.Trail))); + new Smoke(w, ((PPos)highPos.ToInt2()).ToWPos(0), Info.Trail))); ticksToNextSmoke = Info.TrailInterval; } @@ -151,7 +151,7 @@ namespace OpenRA.Mods.RA.Effects const float height = .1f; - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (anim != null) { @@ -166,14 +166,14 @@ namespace OpenRA.Mods.RA.Effects if (Info.High || Info.Angle > 0) { if (Info.Shadow) - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, wr.Palette("shadow"), (int)pos.Y); + yield return new SpriteRenderable(anim.Image, pos, wr.Palette("shadow"), (int)pos.Y); var highPos = pos - new float2(0, GetAltitude()); - yield return new Renderable(anim.Image, highPos - .5f * anim.Image.size, wr.Palette("effect"), (int)pos.Y); + yield return new SpriteRenderable(anim.Image, highPos, wr.Palette("effect"), (int)pos.Y); } else - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, + yield return new SpriteRenderable(anim.Image, pos, wr.Palette(Args.weapon.Underwater ? "shadow" : "effect"), (int)pos.Y); } } diff --git a/OpenRA.Mods.RA/Effects/CashTick.cs b/OpenRA.Mods.RA/Effects/CashTick.cs index 77d220e453..ef84230ec2 100644 --- a/OpenRA.Mods.RA/Effects/CashTick.cs +++ b/OpenRA.Mods.RA/Effects/CashTick.cs @@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA.Effects pos -= new PVecInt(0, velocity); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { font.DrawTextWithContrast(s, Game.viewport.Zoom*(pos.ToFloat2() - Game.viewport.Location) - offset, color, Color.Black,1); yield break; diff --git a/OpenRA.Mods.RA/Effects/Corpse.cs b/OpenRA.Mods.RA/Effects/Corpse.cs index 383cc5dd26..1ed99b46ac 100644 --- a/OpenRA.Mods.RA/Effects/Corpse.cs +++ b/OpenRA.Mods.RA/Effects/Corpse.cs @@ -17,23 +17,23 @@ namespace OpenRA.Mods.RA.Effects { public class Corpse : IEffect { - readonly Animation anim; - readonly float2 pos; - readonly string paletteName; + readonly Animation Anim; + readonly WPos Pos; + readonly string PaletteName; - public Corpse(World world, float2 pos, string image, string sequence, string paletteName) + public Corpse(World world, WPos pos, string image, string sequence, string paletteName) { - this.pos = pos; - this.paletteName = paletteName; - anim = new Animation(image); - anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this))); + Pos = pos; + PaletteName = paletteName; + Anim = new Animation(image); + Anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this))); } - public void Tick(World world) { anim.Tick(); } + public void Tick(World world) { Anim.Tick(); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, wr.Palette(paletteName), (int)pos.Y); + yield return new SpriteRenderable(Anim.Image, Pos, 0, wr.Palette(PaletteName), 1f); } } } diff --git a/OpenRA.Mods.RA/Effects/CrateEffect.cs b/OpenRA.Mods.RA/Effects/CrateEffect.cs index 61b70dd326..e12c14726f 100644 --- a/OpenRA.Mods.RA/Effects/CrateEffect.cs +++ b/OpenRA.Mods.RA/Effects/CrateEffect.cs @@ -19,13 +19,6 @@ namespace OpenRA.Mods.RA.Effects { Actor a; Animation anim = new Animation("crate-effects"); - float2 offset = new float2(-4,0); - - public CrateEffect(Actor a, string seq, int2 offset) - : this(a, seq) - { - this.offset = offset; - } public CrateEffect(Actor a, string seq) { @@ -39,12 +32,11 @@ namespace OpenRA.Mods.RA.Effects anim.Tick(); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (a.IsInWorld) - yield return new Renderable(anim.Image, - a.CenterLocation.ToFloat2() - .5f * anim.Image.size + offset, - wr.Palette("effect"), (int)a.CenterLocation.Y); + yield return new SpriteRenderable(anim.Image, + a.CenterPosition, 0, wr.Palette("effect"), 1f); } } } diff --git a/OpenRA.Mods.RA/Effects/Explosion.cs b/OpenRA.Mods.RA/Effects/Explosion.cs index 942abb9a0a..7463e3c2ce 100644 --- a/OpenRA.Mods.RA/Effects/Explosion.cs +++ b/OpenRA.Mods.RA/Effects/Explosion.cs @@ -32,11 +32,10 @@ namespace OpenRA.Mods.RA.Effects public void Tick( World world ) { anim.Tick(); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(anim.Image, - pos.ToFloat2() - .5f * anim.Image.size - new int2(0,altitude), - wr.Palette("effect"), (int)pos.Y - altitude); + var p = pos.ToInt2() - new int2(0, altitude); + yield return new SpriteRenderable(anim.Image, p, wr.Palette("effect"), p.Y); } public Player Owner { get { return null; } } diff --git a/OpenRA.Mods.RA/Effects/GpsDot.cs b/OpenRA.Mods.RA/Effects/GpsDot.cs index f3cd8360bd..4f902ab399 100644 --- a/OpenRA.Mods.RA/Effects/GpsDot.cs +++ b/OpenRA.Mods.RA/Effects/GpsDot.cs @@ -77,14 +77,13 @@ namespace OpenRA.Mods.RA.Effects show = hasGps && hasDot && !dotHidden; } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (!show || self.Destroyed) yield break; - var p = self.CenterLocation; var palette = wr.Palette(info.IndicatorPalettePrefix+self.Owner.InternalName); - yield return new Renderable(anim.Image, p.ToFloat2() - 0.5f * anim.Image.size, palette, p.Y) + yield return new SpriteRenderable(anim.Image, self.CenterPosition, 0, palette, 1f) .WithScale(1.5f); } } diff --git a/OpenRA.Mods.RA/Effects/GpsSatellite.cs b/OpenRA.Mods.RA/Effects/GpsSatellite.cs index be28c34cc5..12647d5540 100644 --- a/OpenRA.Mods.RA/Effects/GpsSatellite.cs +++ b/OpenRA.Mods.RA/Effects/GpsSatellite.cs @@ -17,28 +17,29 @@ namespace OpenRA.Mods.RA.Effects { class GpsSatellite : IEffect { - readonly float heightPerTick = 10; - float2 offset; - Animation anim = new Animation("sputnik"); + float2 Origin; + WPos Pos; + Animation Anim = new Animation("sputnik"); - public GpsSatellite(float2 offset) + public GpsSatellite(WPos pos, float2 spriteOrigin) { - this.offset = offset; - anim.PlayRepeating("idle"); + Pos = pos; + Origin = spriteOrigin; + Anim.PlayRepeating("idle"); } public void Tick( World world ) { - anim.Tick(); - offset.Y -= heightPerTick; + Anim.Tick(); + Pos += new WVec(0, 0, 427); - if (offset.Y < 0) + if (Pos.Z > Pos.Y) world.AddFrameEndTask(w => w.Remove(this)); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(anim.Image,offset, wr.Palette("effect"), (int)offset.Y); + yield return new SpriteRenderable(Anim.Image, Pos, 0, wr.Palette("effect"), 1f, Origin); } } } diff --git a/OpenRA.Mods.RA/Effects/GravityBomb.cs b/OpenRA.Mods.RA/Effects/GravityBomb.cs index 090c776995..3ecedf622b 100755 --- a/OpenRA.Mods.RA/Effects/GravityBomb.cs +++ b/OpenRA.Mods.RA/Effects/GravityBomb.cs @@ -51,10 +51,10 @@ namespace OpenRA.Mods.RA.Effects anim.Tick(); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { var pos = Args.dest.ToInt2() - new int2(0, altitude) - .5f * anim.Image.size; - yield return new Renderable(anim.Image, pos, wr.Palette("effect"), Args.dest.Y); + yield return new SpriteRenderable(anim.Image, pos, wr.Palette("effect"), Args.dest.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/InvulnEffect.cs b/OpenRA.Mods.RA/Effects/InvulnEffect.cs index d16dd233a9..bd0b856fc9 100644 --- a/OpenRA.Mods.RA/Effects/InvulnEffect.cs +++ b/OpenRA.Mods.RA/Effects/InvulnEffect.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Effects world.AddFrameEndTask(w => w.Remove(this)); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (a.Destroyed) // Tick will clean up yield break; diff --git a/OpenRA.Mods.RA/Effects/LaserZap.cs b/OpenRA.Mods.RA/Effects/LaserZap.cs index 6b515fd21c..c3e0864609 100755 --- a/OpenRA.Mods.RA/Effects/LaserZap.cs +++ b/OpenRA.Mods.RA/Effects/LaserZap.cs @@ -76,11 +76,11 @@ namespace OpenRA.Mods.RA.Effects world.AddFrameEndTask(w => w.Remove(this)); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (explosion != null) - yield return new Renderable(explosion.Image, args.dest.ToFloat2() - .5f * explosion.Image.size, - wr.Palette("effect"), (int)args.dest.Y); + yield return new SpriteRenderable(explosion.Image, args.dest.ToFloat2(), + wr.Palette("effect"), (int)args.dest.Y); if (ticks >= info.BeamDuration) yield break; diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index 82af5b8151..e429148b9b 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -147,7 +147,7 @@ namespace OpenRA.Mods.RA.Effects if (--ticksToNextSmoke < 0) { - world.AddFrameEndTask(w => w.Add(new Smoke(w, sp, Info.Trail))); + world.AddFrameEndTask(w => w.Add(new Smoke(w, sp.ToWPos(0), Info.Trail))); ticksToNextSmoke = Info.TrailInterval; } } @@ -174,11 +174,11 @@ namespace OpenRA.Mods.RA.Effects Combat.DoImpacts(Args); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (!Args.firedBy.World.FogObscures(PxPosition.ToCPos())) - yield return new Renderable(anim.Image, PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude), - wr.Palette(Args.weapon.Underwater ? "shadow" : "effect"), PxPosition.Y); + yield return new SpriteRenderable(anim.Image, PxPosition.ToFloat2() - new float2(0, Altitude), + wr.Palette(Args.weapon.Underwater ? "shadow" : "effect"), PxPosition.Y); if (Trail != null) Trail.Render(wr, Args.firedBy); diff --git a/OpenRA.Mods.RA/Effects/NukeLaunch.cs b/OpenRA.Mods.RA/Effects/NukeLaunch.cs index 8b52557bca..e0c9657f8f 100755 --- a/OpenRA.Mods.RA/Effects/NukeLaunch.cs +++ b/OpenRA.Mods.RA/Effects/NukeLaunch.cs @@ -19,13 +19,12 @@ namespace OpenRA.Mods.RA.Effects { readonly Player firedBy; Animation anim; - PPos pos; + WPos pos; CPos targetLocation; - int altitude; bool goingUp = true; string weapon; - public NukeLaunch(Player firedBy, Actor silo, string weapon, PVecInt spawnOffset, CPos targetLocation) + public NukeLaunch(Player firedBy, Actor silo, string weapon, WPos launchPos, CPos targetLocation) { this.firedBy = firedBy; this.targetLocation = targetLocation; @@ -33,18 +32,14 @@ namespace OpenRA.Mods.RA.Effects anim = new Animation(weapon); anim.PlayRepeating("up"); + pos = launchPos; if (silo == null) - { - altitude = firedBy.World.Map.Bounds.Height*Game.CellSize; StartDescent(firedBy.World); - } - else - pos = silo.CenterLocation + spawnOffset; } void StartDescent(World world) { - pos = OpenRA.Traits.Util.CenterOfCell(targetLocation); + pos = targetLocation.CenterPosition + new WVec(0, 0, 1024*firedBy.World.Map.Bounds.Height); anim.PlayRepeating("down"); goingUp = false; } @@ -53,16 +48,17 @@ namespace OpenRA.Mods.RA.Effects { anim.Tick(); + var delta = new WVec(0,0,427); if (goingUp) { - altitude += 10; - if (altitude >= world.Map.Bounds.Height*Game.CellSize) + pos += delta; + if (pos.Z >= world.Map.Bounds.Height*1024) StartDescent(world); } else { - altitude -= 10; - if (altitude <= 0) + pos -= delta; + if (pos.Z <= 0) Explode(world); } } @@ -70,17 +66,16 @@ namespace OpenRA.Mods.RA.Effects void Explode(World world) { world.AddFrameEndTask(w => w.Remove(this)); - Combat.DoExplosion(firedBy.PlayerActor, weapon, pos, 0); - world.WorldActor.Trait().AddEffect(20, pos.ToFloat2(), 5); + Combat.DoExplosion(firedBy.PlayerActor, weapon, PPos.FromWPos(pos), pos.Z * Game.CellSize / 1024); + world.WorldActor.Trait().AddEffect(20, PPos.FromWPos(pos).ToFloat2(), 5); foreach (var a in world.ActorsWithTrait()) a.Trait.Enable(); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(anim.Image, pos.ToFloat2() - 0.5f * anim.Image.size - new float2(0, altitude), - wr.Palette("effect"), (int)pos.Y); + yield return new SpriteRenderable(anim.Image, pos, 0, wr.Palette("effect"), 1f); } } } diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index 57528be0ee..97ac756ce8 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -19,67 +19,64 @@ namespace OpenRA.Mods.RA.Effects public class Parachute : IEffect { readonly Animation paraAnim; - readonly PPos location; - + readonly WVec parachuteOffset; readonly Actor cargo; + WPos pos; + WVec fallRate = new WVec(0, 0, 13); - int2 offset; - float altitude; - const float fallRate = .3f; - - public Parachute(Actor cargo, PPos location, int altitude) + public Parachute(Actor cargo, WPos dropPosition) { - this.location = location; - this.altitude = altitude; this.cargo = cargo; var pai = cargo.Info.Traits.GetOrDefault(); paraAnim = new Animation(pai != null ? pai.ParachuteSprite : "parach"); paraAnim.PlayThen("open", () => paraAnim.PlayRepeating("idle")); - if (pai != null) offset = pai.Offset; + if (pai != null) + parachuteOffset = pai.Offset; - cargo.Trait().SetPxPosition(cargo, location); + // Adjust x,y to match the target subcell + cargo.Trait().SetPosition(cargo, new CPos(dropPosition)); + var cp = cargo.CenterPosition; + pos = new WPos(cp.X, cp.Y, dropPosition.Z); } public void Tick(World world) { paraAnim.Tick(); - altitude -= fallRate; + pos -= fallRate; - if (altitude <= 0) + if (pos.Z <= 0) + { world.AddFrameEndTask(w => - { - w.Remove(cargo); - w.Remove(this); - var loc = location.ToCPos(); - cargo.CancelActivity(); - cargo.Trait().SetPosition(cargo, loc); - w.Add(cargo); + { + w.Remove(this); + cargo.CancelActivity(); + w.Add(cargo); - foreach( var npl in cargo.TraitsImplementing() ) - npl.OnLanded(); - }); + foreach (var npl in cargo.TraitsImplementing()) + npl.OnLanded(); + }); + } } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { - var rc = cargo.Render(wr).Select(a => a.WithPos(a.Pos - new float2(0, altitude)) - .WithZOffset(a.ZOffset + (int)altitude)); + var rc = cargo.Render(wr); // Don't render anything if the cargo is invisible (e.g. under fog) if (!rc.Any()) yield break; + var shadow = wr.Palette("shadow"); foreach (var c in rc) { - yield return c.WithPos(location.ToFloat2() - .5f * c.Sprite.size).WithPalette(wr.Palette("shadow")).WithZOffset(0); - yield return c.WithZOffset(2); + yield return c.WithPalette(shadow).WithZOffset(-1); + yield return c.WithPos(pos); } - var pos = location.ToFloat2() - new float2(0, altitude); - yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size + offset, rc.First().Palette, 3); + yield return new SpriteRenderable(paraAnim.Image, pos + parachuteOffset, 1, rc.First().Palette, 1f); } } } diff --git a/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs b/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs index 832062d681..1dcd292bb7 100644 --- a/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs +++ b/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs @@ -34,11 +34,11 @@ namespace OpenRA.Mods.RA.Effects anim.Tick(); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (!a.Destroyed && a.Owner.IsAlliedWith(a.World.RenderPlayer)) - yield return new Renderable(anim.Image, a.CenterLocation.ToFloat2() - .5f * anim.Image.size, - wr.Palette("chrome"), (int)a.CenterLocation.Y); + yield return new SpriteRenderable(anim.Image, a.CenterPosition, 0, + wr.Palette("chrome"), 1f); } } } diff --git a/OpenRA.Mods.RA/Effects/RallyPoint.cs b/OpenRA.Mods.RA/Effects/RallyPoint.cs index 555d597bd6..6d784d12f9 100755 --- a/OpenRA.Mods.RA/Effects/RallyPoint.cs +++ b/OpenRA.Mods.RA/Effects/RallyPoint.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA.Effects } CPos cachedLocation; - public void Tick( World world ) + public void Tick(World world) { flag.Tick(); circles.Tick(); @@ -48,21 +48,15 @@ namespace OpenRA.Mods.RA.Effects world.AddFrameEndTask(w => w.Remove(this)); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (building.IsInWorld && building.Owner == building.World.LocalPlayer && building.World.Selection.Actors.Contains(building)) { - var pos = Traits.Util.CenterOfCell(rp.rallyPoint); + var pos = cachedLocation.CenterPosition; var palette = wr.Palette(palettePrefix+building.Owner.InternalName); - - yield return new Renderable(circles.Image, - pos.ToFloat2() - .5f * circles.Image.size, - palette, (int)pos.Y); - - yield return new Renderable(flag.Image, - pos.ToFloat2() + new float2(-1,-17), - palette, (int)pos.Y); + yield return new SpriteRenderable(circles.Image, pos, 0, palette, 1f); + yield return new SpriteRenderable(flag.Image, pos, 0, palette, 1f, new int2(1, 17)); } } } diff --git a/OpenRA.Mods.RA/Effects/RepairIndicator.cs b/OpenRA.Mods.RA/Effects/RepairIndicator.cs index 302e07f991..0d2fa4e8e5 100755 --- a/OpenRA.Mods.RA/Effects/RepairIndicator.cs +++ b/OpenRA.Mods.RA/Effects/RepairIndicator.cs @@ -42,13 +42,12 @@ namespace OpenRA.Mods.RA.Effects anim.Tick(); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (!building.Destroyed) { - yield return new Renderable(anim.Image, - building.CenterLocation.ToFloat2() - .5f * anim.Image.size, - wr.Palette(palettePrefix+player.InternalName), (int)building.CenterLocation.Y); + yield return new SpriteRenderable(anim.Image, building.CenterPosition, 0, + wr.Palette(palettePrefix+player.InternalName), 1f); } } } diff --git a/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs b/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs index 047f27e5ba..7c721cc5c6 100644 --- a/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs +++ b/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs @@ -19,15 +19,15 @@ namespace OpenRA.Mods.RA.Effects { int frame = 0; Animation doors = new Animation("atek"); - float2 doorOffset = new float2(-4,0); - float2 pos; + float2 doorOrigin = new float2(16,24); + WPos pos; public SatelliteLaunch(Actor a) { doors.PlayThen("active", () => a.World.AddFrameEndTask(w => w.Remove(this))); - pos = a.CenterLocation.ToFloat2() - .5f * doors.Image.size + doorOffset; + pos = a.CenterPosition; } public void Tick( World world ) @@ -35,14 +35,12 @@ namespace OpenRA.Mods.RA.Effects doors.Tick(); if (++frame == 19) - { - world.AddFrameEndTask(w => w.Add(new GpsSatellite(pos))); - } + world.AddFrameEndTask(w => w.Add(new GpsSatellite(pos, doorOrigin))); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(doors.Image, pos, wr.Palette("effect"), (int)doorOffset.Y); + yield return new SpriteRenderable(doors.Image, pos, 0, wr.Palette("effect"), 1f, doorOrigin); } } } diff --git a/OpenRA.Mods.RA/Effects/Smoke.cs b/OpenRA.Mods.RA/Effects/Smoke.cs index f82f963296..0686a91d99 100644 --- a/OpenRA.Mods.RA/Effects/Smoke.cs +++ b/OpenRA.Mods.RA/Effects/Smoke.cs @@ -17,26 +17,25 @@ namespace OpenRA.Mods.RA.Effects { public class Smoke : IEffect { - readonly PPos pos; - readonly Animation anim; + readonly WPos Pos; + readonly Animation Anim; - public Smoke(World world, PPos pos, string trail) + public Smoke(World world, WPos pos, string trail) { - this.pos = pos; - anim = new Animation(trail); - anim.PlayThen("idle", + Pos = pos; + Anim = new Animation(trail); + Anim.PlayThen("idle", () => world.AddFrameEndTask(w => w.Remove(this))); } public void Tick( World world ) { - anim.Tick(); + Anim.Tick(); } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { - yield return new Renderable(anim.Image, pos.ToFloat2() - .5f * anim.Image.size, - wr.Palette("effect"), (int)pos.Y); + yield return new SpriteRenderable(Anim.Image, Pos, 0, wr.Palette("effect"), 1f); } } } diff --git a/OpenRA.Mods.RA/Effects/TeslaZap.cs b/OpenRA.Mods.RA/Effects/TeslaZap.cs index 4df7ca777f..6b5fe75f00 100755 --- a/OpenRA.Mods.RA/Effects/TeslaZap.cs +++ b/OpenRA.Mods.RA/Effects/TeslaZap.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Effects { readonly ProjectileArgs Args; readonly TeslaZapInfo Info; - IEnumerable renderables; + IEnumerable renderables; int timeUntilRemove = 2; // # of frames bool doneDamage = false; bool initialized = false; @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Effects Info = info; } - public IEnumerable GenerateRenderables(WorldRenderer wr) + public IEnumerable GenerateRenderables(WorldRenderer wr) { var bright = SequenceProvider.GetSequence(Info.Image, "bright"); var dim = SequenceProvider.GetSequence(Info.Image, "dim"); @@ -72,7 +72,7 @@ namespace OpenRA.Mods.RA.Effects } } - public IEnumerable Render(WorldRenderer wr) + public IEnumerable Render(WorldRenderer wr) { if (!initialized) { @@ -83,13 +83,13 @@ namespace OpenRA.Mods.RA.Effects return renderables; } - static IEnumerable DrawZapWandering(WorldRenderer wr, PPos from, PPos to, Sequence s) + static IEnumerable DrawZapWandering(WorldRenderer wr, PPos from, PPos to, Sequence s) { var z = float2.Zero; /* hack */ var dist = to - from; var norm = (1f / dist.Length) * new float2(-dist.Y, dist.X); - var renderables = new List(); + var renderables = new List(); if (Game.CosmeticRandom.Next(2) != 0) { var p1 = from.ToFloat2() + (1 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm; @@ -110,12 +110,12 @@ namespace OpenRA.Mods.RA.Effects return renderables; } - static IEnumerable DrawZap(WorldRenderer wr, float2 from, float2 to, Sequence s, out float2 p) + static IEnumerable DrawZap(WorldRenderer wr, float2 from, float2 to, Sequence s, out float2 p) { var dist = to - from; var q = new float2(-dist.Y, dist.X); var c = -float2.Dot(from, q); - var rs = new List(); + var rs = new List(); var z = from; while ((to - z).X > 5 || (to - z).X < -5 || (to - z).Y > 5 || (to - z).Y < -5) @@ -123,7 +123,7 @@ namespace OpenRA.Mods.RA.Effects var step = steps.Where(t => (to - (z + new float2(t[0],t[1]))).LengthSquared < (to - z).LengthSquared ) .OrderBy(t => Math.Abs(float2.Dot(z + new float2(t[0], t[1]), q) + c)).First(); - rs.Add(new Renderable(s.GetSprite(step[4]), z + new float2(step[2], step[3]), + rs.Add(new SpriteRenderable(s.GetSprite(step[4]), z + new float2(step[2], step[3]), wr.Palette("effect"), (int)from.Y)); z += new float2(step[0], step[1]); if( rs.Count >= 1000 ) @@ -137,14 +137,14 @@ namespace OpenRA.Mods.RA.Effects static int[][] steps = new [] { - new int[] { 8, 8, -8, -8, 0 }, - new int[] { -8, -8, -16, -16, 0 }, - new int[] { 8, 0, -8, -8, 1 }, - new int[] { -8, 0, -16, -8, 1 }, - new int[] { 0, 8, -8, -8, 2 }, - new int[] { 0, -8, -8, -16, 2 }, - new int[] { -8, 8, -16, -8, 3 }, - new int[] { 8, -8, -8, -16, 3 } + new int[] { 8, 8, 4, 4, 0 }, + new int[] { -8, -8, -4, -4, 0 }, + new int[] { 8, 0, 4, 4, 1 }, + new int[] { -8, 0, -4, 4, 1 }, + new int[] { 0, 8, 4, 4, 2 }, + new int[] { 0, -8, 4, -4, 2 }, + new int[] { -8, 8, -4, 4, 3 }, + new int[] { 8, -8, 4, -4, 3 } }; } } diff --git a/OpenRA.Mods.RA/GainsExperience.cs b/OpenRA.Mods.RA/GainsExperience.cs index cf9be1c4ec..4ed7f070d7 100644 --- a/OpenRA.Mods.RA/GainsExperience.cs +++ b/OpenRA.Mods.RA/GainsExperience.cs @@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA { Level++; Sound.PlayNotification(self.Owner, "Sounds", "LevelUp", self.Owner.Country.Race); - self.World.AddFrameEndTask(w => w.Add(new CrateEffect(self, "levelup", new int2(0,-24)))); + self.World.AddFrameEndTask(w => w.Add(new CrateEffect(self, "levelup"))); } } @@ -98,7 +98,7 @@ namespace OpenRA.Mods.RA return Level > 0 ? Info.SpeedModifier[Level - 1] : 1m; } - public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { // TODO: Make this consistent with everything else that adds animations to RenderSimple. if (self.Owner.IsAlliedWith(self.World.RenderPlayer) && Level > 0) @@ -107,7 +107,7 @@ namespace OpenRA.Mods.RA return r; } - IEnumerable InnerModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + IEnumerable InnerModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { foreach (var rs in r) yield return rs; @@ -118,8 +118,8 @@ namespace OpenRA.Mods.RA yield break; var bounds = self.Bounds.Value; - yield return new Renderable(RankAnim.Image, new float2(bounds.Right - 6, bounds.Bottom - 8), - wr.Palette("effect"), self.CenterLocation.Y); + var pos = new float2(bounds.Right, bounds.Bottom - 2); + yield return new SpriteRenderable(RankAnim.Image, pos, wr.Palette("effect"), self.CenterLocation.Y); } } diff --git a/OpenRA.Mods.RA/Missions/Allies02Script.cs b/OpenRA.Mods.RA/Missions/Allies02Script.cs index 7b59828208..b752395374 100644 --- a/OpenRA.Mods.RA/Missions/Allies02Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies02Script.cs @@ -151,7 +151,7 @@ namespace OpenRA.Mods.RA.Missions if (allies1.WinState != WinState.Undefined) return; if (world.FrameNumber % 50 == 1 && chinookHusk.IsInWorld) - world.Add(new Smoke(world, chinookHusk.CenterLocation, "smoke_m")); + world.Add(new Smoke(world, chinookHusk.CenterPosition, "smoke_m")); if (world.FrameNumber == 1) { diff --git a/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs b/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs index 22b207ade7..3ec4839eaa 100644 --- a/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs +++ b/OpenRA.Mods.RA/Modifiers/FrozenUnderFog.cs @@ -24,8 +24,8 @@ namespace OpenRA.Mods.RA return byPlayer == null || Shroud.GetVisOrigins(self).Any(o => byPlayer.Shroud.IsVisible(o)); } - Renderable[] cache = { }; - public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + IRenderable[] cache = { }; + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { if (IsVisible(self, self.World.RenderPlayer)) cache = r.ToArray(); diff --git a/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs b/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs index 0686b0941a..7d098af3b8 100644 --- a/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs +++ b/OpenRA.Mods.RA/Modifiers/HiddenUnderFog.cs @@ -24,8 +24,8 @@ namespace OpenRA.Mods.RA return byPlayer == null || Shroud.GetVisOrigins(self).Any(o => byPlayer.Shroud.IsVisible(o)); } - static Renderable[] Nothing = { }; - public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + static IRenderable[] Nothing = { }; + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { return IsVisible(self, self.World.RenderPlayer) ? r : Nothing; } diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index 9289d45d02..84cb7a52b7 100755 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.RA.Orders readonly Actor Producer; readonly string Building; readonly BuildingInfo BuildingInfo; - IEnumerable preview; + IEnumerable preview; Sprite buildOk, buildBlocked; bool initialized = false; @@ -98,10 +98,9 @@ namespace OpenRA.Mods.RA.Orders initialized = true; } + var offset = (topLeft - CPos.Zero).ToWVec() + FootprintUtils.CenterOffset(BuildingInfo); foreach (var r in preview) - r.Sprite.DrawAt(topLeft.ToPPos().ToFloat2() + r.Pos, - r.Palette.Index, - r.Scale*r.Sprite.size); + r.WithPos(r.Pos + offset).Render(wr); var res = world.WorldActor.Trait(); var isCloseEnough = BuildingInfo.IsCloseEnoughToBase(world, world.LocalPlayer, Building, topLeft); diff --git a/OpenRA.Mods.RA/ParaDrop.cs b/OpenRA.Mods.RA/ParaDrop.cs index 07788b529a..9ea27934dc 100644 --- a/OpenRA.Mods.RA/ParaDrop.cs +++ b/OpenRA.Mods.RA/ParaDrop.cs @@ -52,14 +52,7 @@ namespace OpenRA.Mods.RA droppedAt.Add(self.Location); var a = cargo.Unload(self); - - var aircraft = self.Trait(); - self.World.AddFrameEndTask(w => w.Add( - new Parachute(a, - Util.CenterOfCell(self.CenterLocation.ToCPos()), - aircraft.Altitude) - )); - + self.World.AddFrameEndTask(w => w.Add(new Parachute(a, self.CenterPosition))); Sound.Play(info.ChuteSound, self.CenterLocation); } } diff --git a/OpenRA.Mods.RA/ParachuteAttachment.cs b/OpenRA.Mods.RA/ParachuteAttachment.cs index 3e1882fd79..f6850ebc9e 100644 --- a/OpenRA.Mods.RA/ParachuteAttachment.cs +++ b/OpenRA.Mods.RA/ParachuteAttachment.cs @@ -15,7 +15,7 @@ namespace OpenRA.Mods.RA class ParachuteAttachmentInfo : TraitInfo { public readonly string ParachuteSprite = "parach"; - public readonly int2 Offset = new int2(0,0); + public readonly WVec Offset = WVec.Zero; } class ParachuteAttachment {} diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index f1e969fe16..7fd16390df 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; using System.Linq; +using OpenRA.FileFormats; using OpenRA.Graphics; using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Effects; @@ -22,13 +23,14 @@ namespace OpenRA.Mods.RA.Render public class RenderBuildingInfo : RenderSimpleInfo, Requires, IPlaceBuildingDecoration { public readonly bool HasMakeAnimation = true; - public readonly float2 Origin = float2.Zero; + + [Desc("Artwork offset in world (not local) coordinates")] + public readonly WVec Origin = WVec.Zero; public override object Create(ActorInitializer init) { return new RenderBuilding(init, this);} - public override IEnumerable RenderPreview(ActorInfo building, PaletteReference pr) + public override IEnumerable RenderPreview(ActorInfo building, PaletteReference pr) { - return base.RenderPreview(building, pr) - .Select(a => a.WithPos(a.Pos + building.Traits.Get().Origin)); + return base.RenderPreview(building, pr).Select(a => a.WithPos(a.Pos + Origin)); } public void Render(WorldRenderer wr, World w, ActorInfo ai, PPos centerLocation) @@ -63,12 +65,12 @@ namespace OpenRA.Mods.RA.Render self.QueueActivity(new CallFunc(() => Complete(self))); } - public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { var disabled = self.IsDisabled(); foreach (var a in r) { - var ret = a.WithPos(a.Pos - Info.Origin); + var ret = a.WithPos(a.Pos + Info.Origin); yield return ret; if (disabled) yield return ret.WithPalette(wr.Palette("disabled")).WithZOffset(1); diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs index aba2eb45cb..14e5ee2eb4 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; using OpenRA.Traits; +using OpenRA.Mods.RA.Buildings; namespace OpenRA.Mods.RA.Render { @@ -20,12 +21,12 @@ namespace OpenRA.Mods.RA.Render public override object Create(ActorInitializer init) { return new RenderBuildingWarFactory( init, this ); } /* get around unverifiability */ - IEnumerable BaseBuildingPreview(ActorInfo building, PaletteReference pr) + IEnumerable BaseBuildingPreview(ActorInfo building, PaletteReference pr) { return base.RenderPreview(building, pr); } - public override IEnumerable RenderPreview(ActorInfo building, PaletteReference pr) + public override IEnumerable RenderPreview(ActorInfo building, PaletteReference pr) { var p = BaseBuildingPreview(building, pr); foreach (var r in p) @@ -33,9 +34,7 @@ namespace OpenRA.Mods.RA.Render var anim = new Animation(RenderSimple.GetImage(building), () => 0); anim.PlayRepeating("idle-top"); - var rb = building.Traits.Get(); - yield return new Renderable(anim.Image, rb.Origin + 0.5f*anim.Image.size*(1 - Scale), - pr, 0, Scale); + yield return new SpriteRenderable(anim.Image, WPos.Zero + Origin, 0, pr, 1f); } } @@ -50,9 +49,10 @@ namespace OpenRA.Mods.RA.Render : base(init, info) { roof = new Animation(GetImage(init.self)); - var offset = new AnimationWithOffset( roof ) { ZOffset = 24 }; - offset.DisableFunc = () => !buildComplete; - anims.Add("roof", offset); + + var bi = init.self.Info.Traits.Get(); + anims.Add("roof", new AnimationWithOffset(roof, null, + () => !buildComplete, FootprintUtils.CenterOffset(bi).Y)); } public void BuildingComplete( Actor self ) diff --git a/OpenRA.Mods.RA/Render/RenderEditorOnly.cs b/OpenRA.Mods.RA/Render/RenderEditorOnly.cs index 4f2825fb8a..a6bbfdc0cd 100644 --- a/OpenRA.Mods.RA/Render/RenderEditorOnly.cs +++ b/OpenRA.Mods.RA/Render/RenderEditorOnly.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA.Render { public RenderEditorOnly(Actor self) : base(self, () => 0) { } - static readonly Renderable[] Nothing = { }; - public override IEnumerable Render(Actor self, WorldRenderer wr) { return Nothing; } + static readonly IRenderable[] Nothing = { }; + public override IEnumerable Render(Actor self, WorldRenderer wr) { return Nothing; } } } diff --git a/OpenRA.Mods.RA/Render/RenderInfantry.cs b/OpenRA.Mods.RA/Render/RenderInfantry.cs index a0d7df1b9b..d81ab8cdf2 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantry.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantry.cs @@ -132,7 +132,7 @@ namespace OpenRA.Mods.RA.Render self.World.AddFrameEndTask(w => { if (!self.Destroyed) - w.Add(new Corpse(w, self.CenterLocation.ToFloat2(), GetImage(self), + w.Add(new Corpse(w, self.CenterPosition, GetImage(self), sequence, Info.PlayerPalette+self.Owner.InternalName)); }); } diff --git a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs index 07282bfaf8..6886cf8e02 100644 --- a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs +++ b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs @@ -45,10 +45,10 @@ namespace OpenRA.Mods.RA.Render var muzzleFlash = new Animation(render.GetImage(self), getFacing); muzzleFlash.Play("muzzle"); - muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new AnimationWithOffset( - muzzleFlash, - wr => wr.ScreenPxOffset(a.MuzzleOffset(self, barrel)), - () => !isShowing)); + muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), + new AnimationWithOffset(muzzleFlash, + () => a.MuzzleOffset(self, barrel), + () => !isShowing)); } } @@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA.Render mf.Animation.PlayThen("muzzle", () => isShowing = false); } - public IEnumerable Render(Actor self, WorldRenderer wr) + public IEnumerable Render(Actor self, WorldRenderer wr) { foreach (var a in muzzleFlashes.Values) if (a.DisableFunc == null || !a.DisableFunc()) diff --git a/OpenRA.Mods.RA/Render/WithRotor.cs b/OpenRA.Mods.RA/Render/WithRotor.cs index 7a5c6a0bb0..eea9c0dd77 100755 --- a/OpenRA.Mods.RA/Render/WithRotor.cs +++ b/OpenRA.Mods.RA/Render/WithRotor.cs @@ -32,10 +32,9 @@ namespace OpenRA.Mods.RA.Render rotorAnim = new Animation(rs.GetImage(self)); rotorAnim.PlayRepeating("rotor"); - rs.anims.Add(info.Id, new AnimationWithOffset( - rotorAnim, - wr => wr.ScreenPxOffset(rs.LocalToWorld(info.Offset.Rotate(rs.QuantizeOrientation(self, self.Orientation)))), - null ) { ZOffset = 1 } ); + rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim, + () => rs.LocalToWorld(info.Offset.Rotate(rs.QuantizeOrientation(self, self.Orientation))), + null, p => WithTurret.ZOffsetFromCenter(self, p, 1))); } public void Tick(Actor self) diff --git a/OpenRA.Mods.RA/Render/WithShadow.cs b/OpenRA.Mods.RA/Render/WithShadow.cs index 76ddf84515..a6e265921f 100644 --- a/OpenRA.Mods.RA/Render/WithShadow.cs +++ b/OpenRA.Mods.RA/Render/WithShadow.cs @@ -22,17 +22,19 @@ namespace OpenRA.Mods.RA.Render class WithShadow : IRenderModifier { - public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) + public IEnumerable ModifyRender(Actor self, WorldRenderer wr, IEnumerable r) { var move = self.Trait(); /* rude hack */ var visualOffset = ((move is Helicopter || move is Mobile) && move.Altitude > 0) - ? Math.Abs((self.ActorID + Game.LocalTick) / 5 % 4 - 1) - 1 : 0; + ? (int)Math.Abs((self.ActorID + Game.LocalTick) / 5 % 4 - 1) - 1 : 0; - var shadowSprites = r.Select(a => a.WithPalette(wr.Palette("shadow"))); - var flyingSprites = (move.Altitude <= 0) ? r - : r.Select(a => a.WithPos(a.Pos - new float2(0, move.Altitude + visualOffset)).WithZOffset(move.Altitude + a.ZOffset)); + var shadowSprites = r.Select(a => a.WithPalette(wr.Palette("shadow")) + .WithPos(a.Pos - new WVec(0, 0, a.Pos.Z)).WithZOffset(a.ZOffset + a.Pos.Z)); + + var flyingSprites = (move.Altitude <= 0) ? r : + r.Select(a => a.WithPos(a.Pos - new WVec(0,0,43*visualOffset))); return shadowSprites.Concat(flyingSprites); } diff --git a/OpenRA.Mods.RA/Render/WithSmoke.cs b/OpenRA.Mods.RA/Render/WithSmoke.cs index 11d82e807e..c35c27dbda 100644 --- a/OpenRA.Mods.RA/Render/WithSmoke.cs +++ b/OpenRA.Mods.RA/Render/WithSmoke.cs @@ -28,8 +28,7 @@ namespace OpenRA.Mods.RA.Render var rs = self.Trait(); anim = new Animation("smoke_m"); - rs.anims.Add("smoke", new AnimationWithOffset( - anim, null, () => !isSmoking)); + rs.anims.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking)); } public void Damaged(Actor self, AttackInfo e) diff --git a/OpenRA.Mods.RA/Render/WithSpinner.cs b/OpenRA.Mods.RA/Render/WithSpinner.cs index c6b3cf4770..c9a1eaf44e 100755 --- a/OpenRA.Mods.RA/Render/WithSpinner.cs +++ b/OpenRA.Mods.RA/Render/WithSpinner.cs @@ -32,10 +32,9 @@ namespace OpenRA.Mods.RA.Render var rs = self.Trait(); var spinner = new Animation(rs.GetImage(self)); spinner.PlayRepeating(info.Sequence); - rs.anims.Add("spinner_{0}".F(info.Sequence), new AnimationWithOffset( - spinner, - wr => wr.ScreenPxOffset(rs.LocalToWorld(info.Offset.Rotate(rs.QuantizeOrientation(self, self.Orientation)))), - null ) { ZOffset = 1 } ); + rs.anims.Add("spinner_{0}".F(info.Sequence), new AnimationWithOffset(spinner, + () => rs.LocalToWorld(info.Offset.Rotate(rs.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 18cbb24d7e..b0981325ce 100755 --- a/OpenRA.Mods.RA/Render/WithTurret.cs +++ b/OpenRA.Mods.RA/Render/WithTurret.cs @@ -53,20 +53,16 @@ namespace OpenRA.Mods.RA.Render anim = new Animation(rs.GetImage(self), () => t.turretFacing); anim.Play(info.Sequence); rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset( - anim, - wr => TurretPosition(self, wr), - null) { ZOffset = 1 }); + anim, () => TurretOffset(self), null, p => ZOffsetFromCenter(self, p, 1))); } - int2 TurretPosition(Actor self, WorldRenderer wr) + WVec TurretOffset(Actor self) { 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)); - var worldPos = t.Position(self) + rs.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation)); - - return wr.ScreenPxOffset(worldPos); + return t.Position(self) + rs.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation)); } public void Tick(Actor self) @@ -77,5 +73,11 @@ namespace OpenRA.Mods.RA.Render var sequence = ab.IsAttacking ? info.AimSequence : info.Sequence; rs.anims["turret_{0}".F(info.Turret)].Animation.ReplaceAnim(sequence); } + + static public int ZOffsetFromCenter(Actor self, WPos pos, int offset) + { + var delta = self.CenterPosition - pos; + return delta.Y + delta.Z + offset; + } } } diff --git a/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs b/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs index ff4d3972d5..fcb5c871fc 100644 --- a/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs +++ b/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA !self.World.FogObscures(new CPos(position))) { var offset = info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation)); - var pos = PPos.FromWPosHackZ(position + coords.LocalToWorld(offset)); + var pos = position + coords.LocalToWorld(offset); self.World.AddFrameEndTask(w => w.Add(new Smoke(w, pos, info.Sprite))); } diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index 22aa83c5df..a6b76c1fc8 100755 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -242,23 +242,22 @@ namespace OpenRA.Mods.RA // Unit previews foreach (var unit in power.UnitsInRange(sourceLocation)) { - if (manager.self.Owner.Shroud.IsTargetable(unit)) { - var targetCell = unit.Location + (xy - sourceLocation); + var offset = (xy - sourceLocation).ToWVec(); + if (manager.self.Owner.Shroud.IsTargetable(unit)) foreach (var r in unit.Render(wr)) - r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location).ToFloat2() + Traits.Util.CenterOfCell(targetCell).ToFloat2(), - r.Palette.Index, - r.Scale*r.Sprite.size); - } + r.WithPos(r.Pos + offset).Render(wr); } // Unit tiles foreach (var unit in power.UnitsInRange(sourceLocation)) { - if (manager.self.Owner.Shroud.IsTargetable(unit)) { + if (manager.self.Owner.Shroud.IsTargetable(unit)) + { var targetCell = unit.Location + (xy - sourceLocation); - var canEnter = ((manager.self.Owner.Shroud.IsExplored(targetCell) || manager.self.Owner.HasFogVisibility())&& unit.Trait().CanChronoshiftTo(unit,targetCell)); + var canEnter = ((manager.self.Owner.Shroud.IsExplored(targetCell) || manager.self.Owner.HasFogVisibility()) && + unit.Trait().CanChronoshiftTo(unit,targetCell)); var tile = canEnter ? validTile : invalidTile; - tile.DrawAt( wr, targetCell.ToPPos().ToFloat2(), "terrain" ); + tile.DrawAt(wr, targetCell.ToPPos().ToFloat2(), "terrain"); } } } diff --git a/OpenRA.Mods.RA/SupportPowers/NukePower.cs b/OpenRA.Mods.RA/SupportPowers/NukePower.cs index 633dced27a..cb7b9b5ea7 100755 --- a/OpenRA.Mods.RA/SupportPowers/NukePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/NukePower.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA { [WeaponReference] public readonly string MissileWeapon = ""; - public readonly int2 SpawnOffset = int2.Zero; + public readonly WVec SpawnOffset = WVec.Zero; public override object Create(ActorInitializer init) { return new NukePower(init.self, this); } } @@ -39,10 +39,10 @@ namespace OpenRA.Mods.RA Sound.Play(Info.LaunchSound); var npi = Info as NukePowerInfo; - - self.Trait().PlayCustomAnim(self, "active"); + var rb = self.Trait(); + rb.PlayCustomAnim(self, "active"); self.World.AddFrameEndTask(w => w.Add( - new NukeLaunch(self.Owner, self, npi.MissileWeapon, (PVecInt)npi.SpawnOffset, order.TargetLocation))); + new NukeLaunch(self.Owner, self, npi.MissileWeapon, self.CenterPosition + rb.LocalToWorld(npi.SpawnOffset), order.TargetLocation))); } } } diff --git a/OpenRA.Mods.RA/ThrowsParticle.cs b/OpenRA.Mods.RA/ThrowsParticle.cs index 55dca13b3f..f6bb3a3842 100644 --- a/OpenRA.Mods.RA/ThrowsParticle.cs +++ b/OpenRA.Mods.RA/ThrowsParticle.cs @@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA var anim = new Animation(rs.GetImage(self), () => (int)facing); anim.PlayRepeating(info.Anim); - rs.anims.Add(info.Anim, new AnimationWithOffset(anim, wr => wr.ScreenPxOffset(pos), null)); + rs.anims.Add(info.Anim, new AnimationWithOffset(anim, () => pos, null)); } public void Tick(Actor self) diff --git a/OpenRA.Mods.RA/World/SmudgeLayer.cs b/OpenRA.Mods.RA/World/SmudgeLayer.cs index 61b62ef802..98ac1bbb25 100755 --- a/OpenRA.Mods.RA/World/SmudgeLayer.cs +++ b/OpenRA.Mods.RA/World/SmudgeLayer.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA public void AddSmudge(CPos loc) { if (Game.CosmeticRandom.Next(0,100) <= Info.SmokePercentage) - world.AddFrameEndTask(w => w.Add(new Smoke(w, Traits.Util.CenterOfCell(loc), Info.SmokeType))); + world.AddFrameEndTask(w => w.Add(new Smoke(w, loc.CenterPosition, Info.SmokeType))); // No smudge; create a new one if (!tiles.ContainsKey(loc)) diff --git a/mods/cnc/rules/ships.yaml b/mods/cnc/rules/ships.yaml index 1c32716775..de7e133560 100644 --- a/mods/cnc/rules/ships.yaml +++ b/mods/cnc/rules/ships.yaml @@ -56,7 +56,9 @@ LST: Range: 7 RenderUnit: WithRoof: - RenderCargo: + WithCargo: + DisplayTypes: Infantry, Vehicle + LocalOffset: 0,0,0, -390,-256,0, 390,-256,0, -390,256,0, 390,256,0 -Selectable: Cargo: Types: Infantry, Vehicle diff --git a/mods/d2k/rules/aircraft.yaml b/mods/d2k/rules/aircraft.yaml index fbc47f7fd2..9abb1c113c 100644 --- a/mods/d2k/rules/aircraft.yaml +++ b/mods/d2k/rules/aircraft.yaml @@ -21,8 +21,8 @@ RearmBuildings: starporta,starporto,starporth MinimalLandAltitude: 25 RenderUnit: - RenderCargo: - RelativeAltitude: 20 + WithCargo: + LocalOffset: 0,0,-854 WithShadow: Cargo: Types: Vehicle diff --git a/mods/d2k/rules/harkonnen.yaml b/mods/d2k/rules/harkonnen.yaml index c770778be2..3438615f23 100644 --- a/mods/d2k/rules/harkonnen.yaml +++ b/mods/d2k/rules/harkonnen.yaml @@ -73,7 +73,7 @@ PALACEH: SelectTargetSound: LaunchSound: MissileWeapon: atomic - SpawnOffset: 28,12 + SpawnOffset:-512,1c171,0 CanPowerDown: RequiresPower: SupportPowerChargeBar: diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index 9ec3d9b5ab..790802e87c 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -116,7 +116,7 @@ GpsDot: String:Infantry ParachuteAttachment: - Offset: 0,-10 + Offset: 0,0,427 CrushableInfantry: CrushSound: squishy2.aud RepairableNear: diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index 1d11b87df7..e7a4e9200f 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -34,7 +34,7 @@ MSLO: SelectTargetSound: slcttgt1.aud LaunchSound: alaunch1.aud MissileWeapon: atomic - SpawnOffset: 10,0 + SpawnOffset: 0,427,0 CanPowerDown: RequiresPower: SupportPowerChargeBar: diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index bbd09b3e22..2aefff50d9 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -667,7 +667,7 @@ FTRK: Range: 4 Turreted: ROT: 5 - Offset: -300,0,300 + Offset: -298,0,298 Armament: Weapon: FLAK-23 Recoil: 85