Convert contrails to world coords.
This commit is contained in:
@@ -34,6 +34,28 @@ namespace OpenRA
|
||||
public static bool operator ==(WPos me, WPos other) { return (me.X == other.X && me.Y == other.Y && me.Z == other.Z); }
|
||||
public static bool operator !=(WPos me, WPos other) { return !(me == other); }
|
||||
|
||||
public static WPos Average(params WPos[] list)
|
||||
{
|
||||
if (list == null || list.Length == 0)
|
||||
return WPos.Zero;
|
||||
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var z = 0;
|
||||
foreach(var pos in list)
|
||||
{
|
||||
x += pos.X;
|
||||
y += pos.Y;
|
||||
z += pos.Z;
|
||||
}
|
||||
|
||||
x /= list.Length;
|
||||
y /= list.Length;
|
||||
z /= list.Length;
|
||||
|
||||
return new WPos(x,y,z);
|
||||
}
|
||||
|
||||
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode(); }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
||||
@@ -21,6 +21,7 @@ namespace OpenRA
|
||||
public readonly int X, Y;
|
||||
|
||||
public CPos(int x, int y) { X = x; Y = y; }
|
||||
public CPos(WPos a) { X = a.X / 1024; Y = a.Y / 1024; }
|
||||
|
||||
public static readonly CPos Zero = new CPos(0, 0);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class RenderSimpleInfo : ITraitInfo
|
||||
public class RenderSimpleInfo : ITraitInfo, LocalCoordinatesModelInfo
|
||||
{
|
||||
[Desc("Defaults to the actor name.")]
|
||||
public readonly string Image = null;
|
||||
|
||||
@@ -216,6 +216,7 @@ namespace OpenRA.Traits
|
||||
WVec LocalToWorld(WVec vec);
|
||||
WRot QuantizeOrientation(Actor self, WRot orientation);
|
||||
}
|
||||
public interface LocalCoordinatesModelInfo {}
|
||||
|
||||
public interface ITargetable
|
||||
{
|
||||
|
||||
@@ -128,7 +128,10 @@ namespace OpenRA.Mods.RA.Effects
|
||||
}
|
||||
|
||||
if (Trail != null)
|
||||
Trail.Tick((PPos)highPos.ToInt2());
|
||||
{
|
||||
var alt = (Info.High || Info.Angle > 0) ? GetAltitude() : 0;
|
||||
Trail.Tick(new PPos((int)pos.X, (int)pos.Y).ToWPos((int)alt));
|
||||
}
|
||||
}
|
||||
|
||||
if (!Info.High) // check for hitting a wall
|
||||
@@ -175,7 +178,7 @@ namespace OpenRA.Mods.RA.Effects
|
||||
}
|
||||
|
||||
if (Trail != null)
|
||||
Trail.Render(Args.firedBy);
|
||||
Trail.Render(wr, Args.firedBy);
|
||||
}
|
||||
|
||||
void Explode( World world )
|
||||
|
||||
@@ -16,9 +16,10 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class ContrailInfo : ITraitInfo
|
||||
class ContrailInfo : ITraitInfo, Requires<LocalCoordinatesModelInfo>
|
||||
{
|
||||
public readonly int[] ContrailOffset = {0, 0};
|
||||
[Desc("Position relative to body")]
|
||||
public readonly WVec Offset = WVec.Zero;
|
||||
|
||||
public readonly int TrailLength = 25;
|
||||
public readonly Color Color = Color.White;
|
||||
@@ -29,31 +30,31 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
class Contrail : ITick, IPostRender
|
||||
{
|
||||
Turret contrailTurret = null;
|
||||
ContrailInfo info;
|
||||
ContrailHistory history;
|
||||
IFacing facing;
|
||||
IMove move;
|
||||
ILocalCoordinatesModel coords;
|
||||
|
||||
public Contrail(Actor self, ContrailInfo info)
|
||||
{
|
||||
contrailTurret = new Turret(info.ContrailOffset);
|
||||
this.info = info;
|
||||
history = new ContrailHistory(info.TrailLength,
|
||||
info.UsePlayerColor ? ContrailHistory.ChooseColor(self) : info.Color);
|
||||
facing = self.Trait<IFacing>();
|
||||
move = self.Trait<IMove>();
|
||||
|
||||
coords = self.Trait<ILocalCoordinatesModel>();
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
history.Tick(self.CenterLocation - new PVecInt(0, move.Altitude) - (PVecInt)contrailTurret.PxPosition(self, facing).ToInt2());
|
||||
var local = info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation));
|
||||
history.Tick(self.CenterPosition + coords.LocalToWorld(local));
|
||||
}
|
||||
|
||||
public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(self); }
|
||||
public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(wr, self); }
|
||||
}
|
||||
|
||||
class ContrailHistory
|
||||
{
|
||||
List<PPos> positions = new List<PPos>();
|
||||
List<WPos> positions = new List<WPos>();
|
||||
readonly int TrailLength;
|
||||
readonly Color Color;
|
||||
readonly int StartSkip;
|
||||
@@ -74,27 +75,28 @@ namespace OpenRA.Mods.RA
|
||||
this.StartSkip = startSkip;
|
||||
}
|
||||
|
||||
public void Tick(PPos currentPos)
|
||||
public void Tick(WPos currentPos)
|
||||
{
|
||||
positions.Add(currentPos);
|
||||
if (positions.Count >= TrailLength)
|
||||
positions.RemoveAt(0);
|
||||
}
|
||||
|
||||
public void Render(Actor self)
|
||||
public void Render(WorldRenderer wr, Actor self)
|
||||
{
|
||||
Color trailStart = Color;
|
||||
Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R, trailStart.G, trailStart.B);
|
||||
|
||||
for (int i = positions.Count - 1 - StartSkip; i >= 4; --i)
|
||||
{
|
||||
var conPos = PPos.Average(positions[i], positions[i-1], positions[i-2], positions[i-3]);
|
||||
var nextPos = PPos.Average(positions[i-1], positions[i-2], positions[i-3], positions[i-4]);
|
||||
// World positions
|
||||
var conPos = WPos.Average(positions[i], positions[i-1], positions[i-2], positions[i-3]);
|
||||
var nextPos = WPos.Average(positions[i-1], positions[i-2], positions[i-3], positions[i-4]);
|
||||
|
||||
if (self.World.RenderedShroud.IsVisible(conPos.ToCPos()) ||
|
||||
self.World.RenderedShroud.IsVisible(nextPos.ToCPos()))
|
||||
if (self.World.RenderedShroud.IsVisible(new CPos(conPos)) ||
|
||||
self.World.RenderedShroud.IsVisible(new CPos(nextPos)))
|
||||
{
|
||||
Game.Renderer.WorldLineRenderer.DrawLine(conPos.ToFloat2(), nextPos.ToFloat2(), trailStart, trailEnd);
|
||||
Game.Renderer.WorldLineRenderer.DrawLine(wr.ScreenPosition(conPos), wr.ScreenPosition(nextPos), trailStart, trailEnd);
|
||||
|
||||
trailStart = trailEnd;
|
||||
trailEnd = Color.FromArgb(trailStart.A - 255 / positions.Count, trailStart.R, trailStart.G, trailStart.B);
|
||||
|
||||
@@ -145,7 +145,7 @@ namespace OpenRA.Mods.RA.Effects
|
||||
}
|
||||
|
||||
if (Trail != null)
|
||||
Trail.Tick(PxPosition - new PVecInt(0, Altitude));
|
||||
Trail.Tick(PxPosition.ToWPos(Altitude));
|
||||
}
|
||||
|
||||
void Explode(World world)
|
||||
@@ -163,7 +163,7 @@ namespace OpenRA.Mods.RA.Effects
|
||||
wr.Palette(Args.weapon.Underwater ? "shadow" : "effect"), PxPosition.Y);
|
||||
|
||||
if (Trail != null)
|
||||
Trail.Render(Args.firedBy);
|
||||
Trail.Render(wr, Args.firedBy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ BADR:
|
||||
Tooltip:
|
||||
Name: Badger
|
||||
Contrail@1:
|
||||
ContrailOffset: 11, -11
|
||||
Offset: -469,469,0
|
||||
Contrail@2:
|
||||
ContrailOffset: -11, -11
|
||||
Offset: -469,-469,0
|
||||
FallsToEarth:
|
||||
Spins: no
|
||||
Moves: yes
|
||||
@@ -59,9 +59,9 @@ BADR.bomber:
|
||||
Tooltip:
|
||||
Name: Badger
|
||||
Contrail@1:
|
||||
ContrailOffset: 11, -11
|
||||
Offset: 469,469,0
|
||||
Contrail@2:
|
||||
ContrailOffset: -11, -11
|
||||
Offset: 469,-469,0
|
||||
FallsToEarth:
|
||||
Spins: no
|
||||
Moves: yes
|
||||
@@ -107,6 +107,7 @@ MIG:
|
||||
Speed: 20
|
||||
RearmBuildings: afld
|
||||
RenderUnit:
|
||||
CameraPitch: 99
|
||||
WithShadow:
|
||||
LimitedAmmo:
|
||||
Ammo: 8
|
||||
@@ -115,9 +116,9 @@ MIG:
|
||||
Selectable:
|
||||
Bounds: 44,40,0,0
|
||||
Contrail@1:
|
||||
ContrailOffset: 16,-14
|
||||
Offset: -598,-683,0
|
||||
Contrail@2:
|
||||
ContrailOffset: -16,-14
|
||||
Offset: -598,683,0
|
||||
FallsToEarth:
|
||||
Spins: no
|
||||
Moves: yes
|
||||
@@ -160,6 +161,7 @@ YAK:
|
||||
ROT: 5
|
||||
Speed: 16
|
||||
RenderUnit:
|
||||
CameraPitch: 99
|
||||
WithShadow:
|
||||
LimitedAmmo:
|
||||
Ammo: 18
|
||||
@@ -169,7 +171,7 @@ YAK:
|
||||
ReturnOnIdle:
|
||||
WithMuzzleFlash:
|
||||
Contrail:
|
||||
ContrailOffset: 0, -20
|
||||
Offset: -853,0,0
|
||||
FallsToEarth:
|
||||
Spins: no
|
||||
Moves: yes
|
||||
@@ -345,9 +347,9 @@ U2:
|
||||
-Selectable:
|
||||
-GainsExperience:
|
||||
Contrail@1:
|
||||
ContrailOffset: 16, -17
|
||||
Offset: -725,683,0
|
||||
Contrail@2:
|
||||
ContrailOffset: -16, -17
|
||||
Offset: -725,-683,0
|
||||
FallsToEarth:
|
||||
Spins: no
|
||||
Moves: yes
|
||||
|
||||
Reference in New Issue
Block a user