diff --git a/OpenRA.FileFormats/PlayerColorRemap.cs b/OpenRA.FileFormats/PlayerColorRemap.cs old mode 100644 new mode 100755 index 44acb62f51..4a76ffbe74 --- a/OpenRA.FileFormats/PlayerColorRemap.cs +++ b/OpenRA.FileFormats/PlayerColorRemap.cs @@ -32,7 +32,7 @@ namespace OpenRA.FileFormats .ToDictionary(u => u.First, u => u.Second); } - static Color ColorLerp(float t, Color c1, Color c2) + public static Color ColorLerp(float t, Color c1, Color c2) { return Color.FromArgb(255, (int)(t * c2.R + (1 - t) * c1.R), diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index f5b4828603..f516180c2a 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -105,6 +105,12 @@ namespace OpenRA.Graphics image.Sprite.DrawAt( image.Pos, this.GetPaletteIndex( image.Palette ) ); uiOverlay.Draw(this, world); + // added for contrails + foreach (var a in world.Actors) + if (!a.Destroyed) + foreach (var t in a.TraitsImplementing()) + t.RenderAfterWorld(this, a); + if (world.OrderGenerator != null) world.OrderGenerator.RenderAfterWorld(this, world); diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs old mode 100644 new mode 100755 index 78964dbcac..d7440bf5a3 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -185,6 +185,8 @@ namespace OpenRA.Traits public interface IBlocksBullets { } + public interface IPostRender { void RenderAfterWorld(WorldRenderer wr, Actor self); } + public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr, Actor self); } public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); } diff --git a/OpenRA.Mods.RA/Effects/Contrail.cs b/OpenRA.Mods.RA/Effects/Contrail.cs new file mode 100755 index 0000000000..c8f4b2cd44 --- /dev/null +++ b/OpenRA.Mods.RA/Effects/Contrail.cs @@ -0,0 +1,109 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 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 LICENSE. + */ +#endregion + +using System.Collections.Generic; +using OpenRA.Graphics; +using OpenRA.Traits; +using System.Drawing; +using OpenRA.FileFormats; + +namespace OpenRA.Mods.RA +{ + class ContrailInfo : ITraitInfo + { + public readonly int[] ContrailOffset = {0, 0}; + + public readonly int TrailLength = 20; + public readonly int[] TrailColor = null; + + public object Create(ActorInitializer init) { return new Contrail(init.self, this); } + } + + class Contrail : ITick, IPostRender + { + private ContrailInfo Info = null; + + private List positions = new List(); + + private Turret ContrailTurret = null; + + private int TrailLength = 0; + private Color TrailColor = Color.White; + + public Contrail(Actor self, ContrailInfo info) + { + Info = info; + + ContrailTurret = new Turret(Info.ContrailOffset); + + TrailLength = Info.TrailLength; + + // if no color specified or wrong format, blend with owner color + if (Info.TrailColor == null || Info.TrailColor.Length != 4) + { + var ownerColor = Color.FromArgb(255, self.Owner.Color); + TrailColor = PlayerColorRemap.ColorLerp(0.5f, ownerColor, Color.White); + } + else + { + // otherwise, blend with specified color + var blendColor = Color.FromArgb(255, Info.TrailColor[1].Clamp(0, 255), + Info.TrailColor[2].Clamp(0, 255), Info.TrailColor[3].Clamp(0, 255)); + TrailColor = PlayerColorRemap.ColorLerp(0.5f, blendColor, Color.White); + } + } + + public void Tick(Actor self) + { + var facing = self.Trait(); + var altitude = new float2(0, self.Trait().Altitude); + + float2 pos = self.CenterLocation - Combat.GetTurretPosition(self, facing, ContrailTurret) - altitude; + + positions.Add(pos); + + if (positions.Count >= TrailLength) + { + positions.RemoveAt(0); + } + } + + public void RenderAfterWorld(WorldRenderer wr, Actor self) + { + Color trailStart = TrailColor; + Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R, + trailStart.G, trailStart.B); + + for (int i = positions.Count - 1; i >= 1; --i) + { + var conPos = positions[i]; + var nextPos = positions[i - 1]; + ShroudRenderer shroud = null; + + // LocalPlayer is null on shellmap + if (self.World.LocalPlayer != null) + { + shroud = self.World.LocalPlayer.Shroud; + } + + if (shroud == null || + shroud.IsVisible(OpenRA.Traits.Util.CellContaining(conPos)) || + shroud.IsVisible(OpenRA.Traits.Util.CellContaining(nextPos))) + { + Game.Renderer.LineRenderer.DrawLine(conPos, nextPos, trailStart, trailEnd); + + trailStart = trailEnd; + trailEnd = Color.FromArgb(trailStart.A - 255 / positions.Count, trailStart.R, + trailStart.G, trailStart.B); + } + } + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 371f8b924c..0d956ad228 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.30729 + 9.0.21022 2.0 {4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E} Library @@ -89,6 +89,7 @@ + diff --git a/mods/ra/rules/vehicles.yaml b/mods/ra/rules/vehicles.yaml index 5780e85300..b94b4c4a6c 100644 --- a/mods/ra/rules/vehicles.yaml +++ b/mods/ra/rules/vehicles.yaml @@ -19,6 +19,10 @@ BADR: -GainsExperience: Tooltip: Name: Badger + Contrail@1: + ContrailOffset: 11, -11 + Contrail@2: + ContrailOffset: -11, -11 BADR.bomber: CarpetBomb: @@ -42,6 +46,10 @@ BADR.bomber: -GainsExperience: Tooltip: Name: Badger + Contrail@1: + ContrailOffset: 11, -11 + Contrail@2: + ContrailOffset: -11, -11 V2RL: Inherits: ^Vehicle @@ -707,6 +715,10 @@ MIG: ReturnOnIdle: Selectable: Bounds: 44,40,0,0 + Contrail@1: + ContrailOffset: 16,-14 + Contrail@2: + ContrailOffset: -16,-14 YAK: Inherits: ^Plane @@ -745,6 +757,8 @@ YAK: IronCurtainable: ReturnOnIdle: WithMuzzleFlash: + Contrail: + ContrailOffset: 0, -20 TRAN: Inherits: ^Plane @@ -776,7 +790,7 @@ TRAN: WithShadow: Cargo: Types: Infantry - Passengers: 5 + Passengers: 5 IronCurtainable: FallsToEarth: @@ -873,6 +887,10 @@ U2: IronCurtainable: -Selectable: -GainsExperience: + Contrail@1: + ContrailOffset: 16, -17 + Contrail@2: + ContrailOffset: -16, -17 1TNK.Husk: Inherits: ^Husk