Contrail trait
This commit is contained in:
committed by
Chris Forbes
parent
ff7daf8727
commit
c568dfa486
2
OpenRA.FileFormats/PlayerColorRemap.cs
Normal file → Executable file
2
OpenRA.FileFormats/PlayerColorRemap.cs
Normal file → Executable file
@@ -32,7 +32,7 @@ namespace OpenRA.FileFormats
|
|||||||
.ToDictionary(u => u.First, u => u.Second);
|
.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,
|
return Color.FromArgb(255,
|
||||||
(int)(t * c2.R + (1 - t) * c1.R),
|
(int)(t * c2.R + (1 - t) * c1.R),
|
||||||
|
|||||||
@@ -105,6 +105,12 @@ namespace OpenRA.Graphics
|
|||||||
image.Sprite.DrawAt( image.Pos, this.GetPaletteIndex( image.Palette ) );
|
image.Sprite.DrawAt( image.Pos, this.GetPaletteIndex( image.Palette ) );
|
||||||
uiOverlay.Draw(this, world);
|
uiOverlay.Draw(this, world);
|
||||||
|
|
||||||
|
// added for contrails
|
||||||
|
foreach (var a in world.Actors)
|
||||||
|
if (!a.Destroyed)
|
||||||
|
foreach (var t in a.TraitsImplementing<IPostRender>())
|
||||||
|
t.RenderAfterWorld(this, a);
|
||||||
|
|
||||||
if (world.OrderGenerator != null)
|
if (world.OrderGenerator != null)
|
||||||
world.OrderGenerator.RenderAfterWorld(this, world);
|
world.OrderGenerator.RenderAfterWorld(this, world);
|
||||||
|
|
||||||
|
|||||||
2
OpenRA.Game/Traits/TraitsInterfaces.cs
Normal file → Executable file
2
OpenRA.Game/Traits/TraitsInterfaces.cs
Normal file → Executable file
@@ -185,6 +185,8 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public interface IBlocksBullets { }
|
public interface IBlocksBullets { }
|
||||||
|
|
||||||
|
public interface IPostRender { void RenderAfterWorld(WorldRenderer wr, Actor self); }
|
||||||
|
|
||||||
public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr, Actor self); }
|
public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr, Actor self); }
|
||||||
public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); }
|
public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); }
|
||||||
|
|
||||||
|
|||||||
109
OpenRA.Mods.RA/Effects/Contrail.cs
Executable file
109
OpenRA.Mods.RA/Effects/Contrail.cs
Executable file
@@ -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<float2> positions = new List<float2>();
|
||||||
|
|
||||||
|
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<IFacing>();
|
||||||
|
var altitude = new float2(0, self.Trait<IMove>().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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ProductVersion>9.0.30729</ProductVersion>
|
<ProductVersion>9.0.21022</ProductVersion>
|
||||||
<SchemaVersion>2.0</SchemaVersion>
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
<ProjectGuid>{4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}</ProjectGuid>
|
<ProjectGuid>{4A8A43B5-A9EF-4ED0-99DD-4BAB10A0DB6E}</ProjectGuid>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
@@ -89,6 +89,7 @@
|
|||||||
<Compile Include="Crates\GiveUnitCrateAction.cs" />
|
<Compile Include="Crates\GiveUnitCrateAction.cs" />
|
||||||
<Compile Include="DetectCloaked.cs" />
|
<Compile Include="DetectCloaked.cs" />
|
||||||
<Compile Include="Effects\Bullet.cs" />
|
<Compile Include="Effects\Bullet.cs" />
|
||||||
|
<Compile Include="Effects\Contrail.cs" />
|
||||||
<Compile Include="Effects\Explosion.cs" />
|
<Compile Include="Effects\Explosion.cs" />
|
||||||
<Compile Include="Effects\GravityBomb.cs" />
|
<Compile Include="Effects\GravityBomb.cs" />
|
||||||
<Compile Include="Effects\LaserZap.cs" />
|
<Compile Include="Effects\LaserZap.cs" />
|
||||||
|
|||||||
@@ -19,6 +19,10 @@ BADR:
|
|||||||
-GainsExperience:
|
-GainsExperience:
|
||||||
Tooltip:
|
Tooltip:
|
||||||
Name: Badger
|
Name: Badger
|
||||||
|
Contrail@1:
|
||||||
|
ContrailOffset: 11, -11
|
||||||
|
Contrail@2:
|
||||||
|
ContrailOffset: -11, -11
|
||||||
|
|
||||||
BADR.bomber:
|
BADR.bomber:
|
||||||
CarpetBomb:
|
CarpetBomb:
|
||||||
@@ -42,6 +46,10 @@ BADR.bomber:
|
|||||||
-GainsExperience:
|
-GainsExperience:
|
||||||
Tooltip:
|
Tooltip:
|
||||||
Name: Badger
|
Name: Badger
|
||||||
|
Contrail@1:
|
||||||
|
ContrailOffset: 11, -11
|
||||||
|
Contrail@2:
|
||||||
|
ContrailOffset: -11, -11
|
||||||
|
|
||||||
V2RL:
|
V2RL:
|
||||||
Inherits: ^Vehicle
|
Inherits: ^Vehicle
|
||||||
@@ -707,6 +715,10 @@ MIG:
|
|||||||
ReturnOnIdle:
|
ReturnOnIdle:
|
||||||
Selectable:
|
Selectable:
|
||||||
Bounds: 44,40,0,0
|
Bounds: 44,40,0,0
|
||||||
|
Contrail@1:
|
||||||
|
ContrailOffset: 16,-14
|
||||||
|
Contrail@2:
|
||||||
|
ContrailOffset: -16,-14
|
||||||
|
|
||||||
YAK:
|
YAK:
|
||||||
Inherits: ^Plane
|
Inherits: ^Plane
|
||||||
@@ -745,6 +757,8 @@ YAK:
|
|||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
ReturnOnIdle:
|
ReturnOnIdle:
|
||||||
WithMuzzleFlash:
|
WithMuzzleFlash:
|
||||||
|
Contrail:
|
||||||
|
ContrailOffset: 0, -20
|
||||||
|
|
||||||
TRAN:
|
TRAN:
|
||||||
Inherits: ^Plane
|
Inherits: ^Plane
|
||||||
@@ -776,7 +790,7 @@ TRAN:
|
|||||||
WithShadow:
|
WithShadow:
|
||||||
Cargo:
|
Cargo:
|
||||||
Types: Infantry
|
Types: Infantry
|
||||||
Passengers: 5
|
Passengers: 5
|
||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
FallsToEarth:
|
FallsToEarth:
|
||||||
|
|
||||||
@@ -873,6 +887,10 @@ U2:
|
|||||||
IronCurtainable:
|
IronCurtainable:
|
||||||
-Selectable:
|
-Selectable:
|
||||||
-GainsExperience:
|
-GainsExperience:
|
||||||
|
Contrail@1:
|
||||||
|
ContrailOffset: 16, -17
|
||||||
|
Contrail@2:
|
||||||
|
ContrailOffset: -16, -17
|
||||||
|
|
||||||
1TNK.Husk:
|
1TNK.Husk:
|
||||||
Inherits: ^Husk
|
Inherits: ^Husk
|
||||||
|
|||||||
Reference in New Issue
Block a user