Fix overlapping tracks when vehicle rotates.

Also optimize the function slightly.
This commit is contained in:
Matthias Mailänder
2021-08-12 10:11:04 +02:00
committed by abcdefg30
parent 5220da1bae
commit a6cb20a4ec

View File

@@ -10,6 +10,7 @@
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Effects;
using OpenRA.Traits;
@@ -93,6 +94,10 @@ namespace OpenRA.Mods.Common.Traits.Render
bool wasStationary;
bool isMoving;
bool previouslySpawned;
CPos previousSpawnCell;
WAngle previousSpawnFacing;
void ITick.Tick(Actor self)
{
if (IsTraitDisabled)
@@ -120,18 +125,26 @@ namespace OpenRA.Mods.Common.Traits.Render
if (++offset >= Info.Offsets.Length)
offset = 0;
if (!Info.TerrainTypes.Any() || Info.TerrainTypes.Contains(type))
{
var spawnFacing = Info.SpawnAtLastPosition ? cachedFacing : facing?.Facing ?? WAngle.Zero;
if (previouslySpawned && previousSpawnCell == spawnCell)
spawnFacing = previousSpawnFacing;
var offsetRotation = Info.Offsets[offset].Rotate(body.QuantizeOrientation(self, self.Orientation));
var spawnPosition = Info.SpawnAtLastPosition ? cachedPosition : self.CenterPosition;
var pos = Info.Type == TrailType.CenterPosition ? spawnPosition + body.LocalToWorld(offsetRotation) :
self.World.Map.CenterOfCell(spawnCell);
var spawnFacing = Info.SpawnAtLastPosition ? cachedFacing : facing?.Facing ?? WAngle.Zero;
if (Info.TerrainTypes.Count == 0 || Info.TerrainTypes.Contains(type))
self.World.AddFrameEndTask(w => w.Add(new SpriteEffect(pos, spawnFacing, self.World, Info.Image,
Info.Sequences.Random(Game.CosmeticRandom), Info.Palette, Info.VisibleThroughFog)));
previouslySpawned = true;
previousSpawnCell = spawnCell;
previousSpawnFacing = spawnFacing;
}
cachedPosition = self.CenterPosition;
cachedFacing = facing?.Facing ?? WAngle.Zero;
ticks = 0;