Merge pull request #3348 from pchote/rendersprites
Renderer refactoring - Traits
This commit is contained in:
@@ -45,7 +45,7 @@ namespace OpenRA.Editor
|
||||
|
||||
public static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, Palette p)
|
||||
{
|
||||
var image = RenderSimple.GetImage(info);
|
||||
var image = RenderSprites.GetImage(info);
|
||||
|
||||
using (var s = FileSystem.OpenWithExts(image, tileset.Extensions))
|
||||
{
|
||||
|
||||
@@ -41,7 +41,6 @@ namespace OpenRA.Graphics
|
||||
IRenderable WithZOffset(int newOffset);
|
||||
IRenderable WithPos(WPos pos);
|
||||
void Render(WorldRenderer wr);
|
||||
WVec Size(WorldRenderer wr);
|
||||
}
|
||||
|
||||
public struct SpriteRenderable : IRenderable
|
||||
@@ -84,11 +83,5 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
readonly Sprite[] sprites;
|
||||
readonly int start, length, stride, facings, tick;
|
||||
readonly bool reverseFacings, transpose;
|
||||
|
||||
public readonly string Name;
|
||||
public int Start { get { return start; } }
|
||||
@@ -50,7 +51,11 @@ namespace OpenRA.Graphics
|
||||
stride = length;
|
||||
|
||||
if (d.ContainsKey("Facings"))
|
||||
facings = int.Parse(d["Facings"].Value);
|
||||
{
|
||||
var f = int.Parse(d["Facings"].Value);
|
||||
facings = Math.Abs(f);
|
||||
reverseFacings = f < 0;
|
||||
}
|
||||
else
|
||||
facings = 1;
|
||||
|
||||
@@ -59,6 +64,9 @@ namespace OpenRA.Graphics
|
||||
else
|
||||
tick = 40;
|
||||
|
||||
if (d.ContainsKey("Transpose"))
|
||||
transpose = bool.Parse(d["Transpose"].Value);
|
||||
|
||||
if (length > stride)
|
||||
throw new InvalidOperationException(
|
||||
"{0}: Sequence {1}.{2}: Length must be <= stride"
|
||||
@@ -79,7 +87,14 @@ namespace OpenRA.Graphics
|
||||
public Sprite GetSprite(int frame, int facing)
|
||||
{
|
||||
var f = Traits.Util.QuantizeFacing(facing, facings);
|
||||
return sprites[ (f * stride) + ( frame % length ) + start ];
|
||||
|
||||
if (reverseFacings)
|
||||
f = (facings - f) % facings;
|
||||
|
||||
int i = transpose ? (frame % length) * facings + f :
|
||||
(f * stride) + (frame % length);
|
||||
|
||||
return sprites[start + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,6 +225,8 @@
|
||||
<Compile Include="Network\UPnP.cs" />
|
||||
<Compile Include="Widgets\ClientTooltipRegionWidget.cs" />
|
||||
<Compile Include="Graphics\Renderable.cs" />
|
||||
<Compile Include="Traits\Render\RenderSprites.cs" />
|
||||
<Compile Include="Traits\BodyOrientation.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
58
OpenRA.Game/Traits/BodyOrientation.cs
Executable file
58
OpenRA.Game/Traits/BodyOrientation.cs
Executable file
@@ -0,0 +1,58 @@
|
||||
#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.Graphics;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class BodyOrientationInfo : ITraitInfo, IBodyOrientationInfo
|
||||
{
|
||||
[Desc("Camera pitch for rotation calculations")]
|
||||
public readonly WAngle CameraPitch = WAngle.FromDegrees(40);
|
||||
public object Create(ActorInitializer init) { return new BodyOrientation(init.self, this); }
|
||||
}
|
||||
|
||||
public class BodyOrientation : IBodyOrientation
|
||||
{
|
||||
[Sync] public int QuantizedFacings { get; set; }
|
||||
BodyOrientationInfo Info;
|
||||
|
||||
public BodyOrientation(Actor self, BodyOrientationInfo info)
|
||||
{
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public WAngle CameraPitch { get { return Info.CameraPitch; } }
|
||||
|
||||
public WVec LocalToWorld(WVec vec)
|
||||
{
|
||||
// RA's 2d perspective doesn't correspond to an orthonormal 3D
|
||||
// coordinate system, so fudge the y axis to make things look good
|
||||
return new WVec(vec.Y, -Info.CameraPitch.Sin()*vec.X/1024, vec.Z);
|
||||
}
|
||||
|
||||
public WRot QuantizeOrientation(Actor self, WRot orientation)
|
||||
{
|
||||
// Quantization disabled
|
||||
if (QuantizedFacings == 0)
|
||||
return orientation;
|
||||
|
||||
// Map yaw to the closest facing
|
||||
var facing = Util.QuantizeFacing(orientation.Yaw.Angle / 4, QuantizedFacings) * (256 / QuantizedFacings);
|
||||
|
||||
// Roll and pitch are always zero if yaw is quantized
|
||||
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,23 +16,9 @@ using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class RenderSimpleInfo : ITraitInfo, LocalCoordinatesModelInfo
|
||||
public class RenderSimpleInfo : RenderSpritesInfo, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Defaults to the actor name.")]
|
||||
public readonly string Image = null;
|
||||
[Desc("custom palette name")]
|
||||
public readonly string Palette = null;
|
||||
[Desc("custom PlayerColorPalette: BaseName")]
|
||||
public readonly string PlayerPalette = "player";
|
||||
[Desc("Change the sprite image size.")]
|
||||
public readonly float Scale = 1f;
|
||||
|
||||
[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 override object Create(ActorInitializer init) { return new RenderSimple(init.self); }
|
||||
|
||||
public virtual IEnumerable<IRenderable> RenderPreview(ActorInfo ai, PaletteReference pr)
|
||||
{
|
||||
@@ -43,73 +29,22 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class RenderSimple : IRender, ILocalCoordinatesModel, IAutoSelectionSize, ITick, INotifyOwnerChanged
|
||||
public class RenderSimple : RenderSprites, IAutoSelectionSize
|
||||
{
|
||||
public Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
|
||||
|
||||
public static Func<int> MakeFacingFunc(Actor self)
|
||||
{
|
||||
var facing = self.TraitOrDefault<IFacing>();
|
||||
if (facing == null) return () => 0;
|
||||
return () => facing.Facing;
|
||||
}
|
||||
|
||||
public Animation anim
|
||||
{
|
||||
get { return anims[""].Animation; }
|
||||
protected set { anims[""] = new AnimationWithOffset(value,
|
||||
anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].ZOffset); }
|
||||
}
|
||||
|
||||
public static string GetImage(ActorInfo actor)
|
||||
{
|
||||
var Info = actor.Traits.Get<RenderSimpleInfo>();
|
||||
return Info.Image ?? actor.Name;
|
||||
}
|
||||
|
||||
public string GetImage(Actor self)
|
||||
{
|
||||
if (cachedImage != null)
|
||||
return cachedImage;
|
||||
|
||||
return cachedImage = GetImage(self.Info);
|
||||
}
|
||||
|
||||
RenderSimpleInfo Info;
|
||||
string cachedImage = null;
|
||||
bool initializePalette = true;
|
||||
protected PaletteReference palette;
|
||||
|
||||
public RenderSimple(Actor self, Func<int> baseFacing)
|
||||
: base(self, baseFacing)
|
||||
{
|
||||
anims.Add("", new Animation(GetImage(self), baseFacing));
|
||||
Info = self.Info.Traits.Get<RenderSimpleInfo>();
|
||||
}
|
||||
|
||||
public RenderSimple(Actor self) : this( self, MakeFacingFunc(self) )
|
||||
public RenderSimple(Actor self)
|
||||
: this(self, MakeFacingFunc(self))
|
||||
{
|
||||
anim.PlayRepeating("idle");
|
||||
}
|
||||
|
||||
protected virtual string PaletteName(Actor self)
|
||||
{
|
||||
return Info.Palette ?? Info.PlayerPalette + self.Owner.InternalName;
|
||||
}
|
||||
|
||||
protected void UpdatePalette() { initializePalette = true; }
|
||||
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { UpdatePalette(); }
|
||||
|
||||
public virtual IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
|
||||
{
|
||||
if (initializePalette)
|
||||
{
|
||||
palette = wr.Palette(PaletteName(self));
|
||||
initializePalette = false;
|
||||
}
|
||||
|
||||
foreach (var a in anims.Values)
|
||||
if (a.DisableFunc == null || !a.DisableFunc())
|
||||
yield return a.Image(self, wr, palette, Info.Scale);
|
||||
self.Trait<IBodyOrientation>().QuantizedFacings = anim.CurrentSequence.Facings;
|
||||
}
|
||||
|
||||
public int2 SelectionSize(Actor self)
|
||||
@@ -120,12 +55,6 @@ namespace OpenRA.Traits
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public virtual void Tick(Actor self)
|
||||
{
|
||||
foreach (var a in anims.Values)
|
||||
a.Animation.Tick();
|
||||
}
|
||||
|
||||
protected virtual string NormalizeSequence(Actor self, string baseSequence)
|
||||
{
|
||||
string damageState = self.GetDamageState() >= DamageState.Heavy ? "damaged-" : "";
|
||||
@@ -141,22 +70,5 @@ namespace OpenRA.Traits
|
||||
anim.PlayThen(NormalizeSequence(self, name),
|
||||
() => anim.PlayRepeating(NormalizeSequence(self, "idle")));
|
||||
}
|
||||
|
||||
public WVec LocalToWorld(WVec vec)
|
||||
{
|
||||
// RA's 2d perspective doesn't correspond to an orthonormal 3D
|
||||
// coordinate system, so fudge the y axis to make things look good
|
||||
return new WVec(vec.Y, -Info.CameraPitch.Sin()*vec.X/1024, vec.Z);
|
||||
}
|
||||
|
||||
public WRot QuantizeOrientation(Actor self, WRot orientation)
|
||||
{
|
||||
// Map yaw to the closest facing
|
||||
var numDirs = Info.QuantizedFacings == -1 ? anim.CurrentSequence.Facings : Info.QuantizedFacings;
|
||||
var facing = Util.QuantizeFacing(orientation.Yaw.Angle / 4, numDirs) * (256 / numDirs);
|
||||
|
||||
// Roll and pitch are always zero
|
||||
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
107
OpenRA.Game/Traits/Render/RenderSprites.cs
Executable file
107
OpenRA.Game/Traits/Render/RenderSprites.cs
Executable file
@@ -0,0 +1,107 @@
|
||||
#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.Graphics;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
public class RenderSpritesInfo : ITraitInfo
|
||||
{
|
||||
[Desc("Defaults to the actor name.")]
|
||||
public readonly string Image = null;
|
||||
|
||||
[Desc("Custom palette name")]
|
||||
public readonly string Palette = null;
|
||||
[Desc("Custom PlayerColorPalette: BaseName")]
|
||||
public readonly string PlayerPalette = "player";
|
||||
[Desc("Change the sprite image size.")]
|
||||
public readonly float Scale = 1f;
|
||||
|
||||
public virtual object Create(ActorInitializer init) { return new RenderSprites(init.self); }
|
||||
}
|
||||
|
||||
public class RenderSprites : IRender, ITick, INotifyOwnerChanged
|
||||
{
|
||||
public Dictionary<string, AnimationWithOffset> anims = new Dictionary<string, AnimationWithOffset>();
|
||||
|
||||
public static Func<int> MakeFacingFunc(Actor self)
|
||||
{
|
||||
var facing = self.TraitOrDefault<IFacing>();
|
||||
if (facing == null) return () => 0;
|
||||
return () => facing.Facing;
|
||||
}
|
||||
|
||||
public Animation anim
|
||||
{
|
||||
get { return anims[""].Animation; }
|
||||
protected set { anims[""] = new AnimationWithOffset(value,
|
||||
anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].ZOffset); }
|
||||
}
|
||||
|
||||
RenderSpritesInfo Info;
|
||||
string cachedImage = null;
|
||||
bool initializePalette = true;
|
||||
protected PaletteReference palette;
|
||||
|
||||
public RenderSprites(Actor self, Func<int> baseFacing)
|
||||
{
|
||||
Info = self.Info.Traits.Get<RenderSpritesInfo>();
|
||||
}
|
||||
|
||||
public RenderSprites(Actor self)
|
||||
: this(self, MakeFacingFunc(self)) {}
|
||||
|
||||
public static string GetImage(ActorInfo actor)
|
||||
{
|
||||
var Info = actor.Traits.Get<RenderSpritesInfo>();
|
||||
return Info.Image ?? actor.Name;
|
||||
}
|
||||
|
||||
public string GetImage(Actor self)
|
||||
{
|
||||
if (cachedImage != null)
|
||||
return cachedImage;
|
||||
|
||||
return cachedImage = GetImage(self.Info);
|
||||
}
|
||||
|
||||
protected virtual string PaletteName(Actor self)
|
||||
{
|
||||
return Info.Palette ?? Info.PlayerPalette + self.Owner.InternalName;
|
||||
}
|
||||
|
||||
protected void UpdatePalette() { initializePalette = true; }
|
||||
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) { UpdatePalette(); }
|
||||
|
||||
public virtual IEnumerable<IRenderable> Render(Actor self, WorldRenderer wr)
|
||||
{
|
||||
if (initializePalette)
|
||||
{
|
||||
palette = wr.Palette(PaletteName(self));
|
||||
initializePalette = false;
|
||||
}
|
||||
|
||||
foreach (var a in anims.Values)
|
||||
if (a.DisableFunc == null || !a.DisableFunc())
|
||||
yield return a.Image(self, wr, palette, Info.Scale);
|
||||
}
|
||||
|
||||
public virtual void Tick(Actor self)
|
||||
{
|
||||
foreach (var a in anims.Values)
|
||||
a.Animation.Tick();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -187,12 +187,14 @@ namespace OpenRA.Traits
|
||||
public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr); }
|
||||
public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); }
|
||||
public interface IRenderAsTerrain { IEnumerable<IRenderable> RenderAsTerrain(WorldRenderer wr, Actor self); }
|
||||
public interface ILocalCoordinatesModel
|
||||
public interface IBodyOrientation
|
||||
{
|
||||
WAngle CameraPitch { get; }
|
||||
int QuantizedFacings { get; set; }
|
||||
WVec LocalToWorld(WVec vec);
|
||||
WRot QuantizeOrientation(Actor self, WRot orientation);
|
||||
}
|
||||
public interface LocalCoordinatesModelInfo {}
|
||||
public interface IBodyOrientationInfo {}
|
||||
|
||||
public interface ITargetable
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
class RenderGunboatInfo : RenderUnitInfo
|
||||
class RenderGunboatInfo : RenderSimpleInfo
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new RenderGunboat(init.self); }
|
||||
}
|
||||
@@ -26,8 +26,13 @@ namespace OpenRA.Mods.RA.Render
|
||||
string lastDir = "left";
|
||||
string lastDamage = "";
|
||||
|
||||
static Func<int> TurretFacingFunc(Actor self)
|
||||
{
|
||||
return () => self.HasTrait<Turreted>() ? self.TraitsImplementing<Turreted>().First().turretFacing : 0;
|
||||
}
|
||||
|
||||
public RenderGunboat(Actor self)
|
||||
: base(self, () => self.HasTrait<Turreted>() ? self.TraitsImplementing<Turreted>().First().turretFacing : 0)
|
||||
: base(self, TurretFacingFunc(self))
|
||||
{
|
||||
facing = self.Trait<IFacing>();
|
||||
anim.Play("left");
|
||||
@@ -40,6 +45,8 @@ namespace OpenRA.Mods.RA.Render
|
||||
anims.Add("wake", new AnimationWithOffset(wake,
|
||||
() => anims["wake"].Animation.CurrentSequence.Name == "left-wake" ? leftOffset : rightOffset,
|
||||
() => false, -87));
|
||||
|
||||
self.Trait<IBodyOrientation>().QuantizedFacings = anim.CurrentSequence.Facings;
|
||||
}
|
||||
|
||||
public override void Tick(Actor self)
|
||||
|
||||
@@ -18,7 +18,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc
|
||||
{
|
||||
public class WithCargoInfo : ITraitInfo, Requires<CargoInfo>, Requires<LocalCoordinatesModelInfo>
|
||||
public class WithCargoInfo : ITraitInfo, Requires<CargoInfo>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Cargo position relative to turret or body. (forward, right, up) triples")]
|
||||
public readonly WRange[] LocalOffset = {};
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Cnc
|
||||
IFacing facing;
|
||||
WithCargoInfo Info;
|
||||
WVec[] positions;
|
||||
ILocalCoordinatesModel coords;
|
||||
IBodyOrientation body;
|
||||
|
||||
public WithCargo(Actor self, WithCargoInfo info)
|
||||
{
|
||||
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc
|
||||
facing = self.TraitOrDefault<IFacing>();
|
||||
Info = info;
|
||||
|
||||
coords = self.Trait<ILocalCoordinatesModel>();
|
||||
body = self.Trait<IBodyOrientation>();
|
||||
|
||||
if (info.LocalOffset.Length % 3 != 0)
|
||||
throw new InvalidOperationException("Invalid LocalOffset array length");
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Cnc
|
||||
foreach (var rr in r)
|
||||
yield return rr;
|
||||
|
||||
var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation);
|
||||
var bodyOrientation = body.QuantizeOrientation(self, self.Orientation);
|
||||
var pos = self.CenterPosition;
|
||||
int i = 0;
|
||||
foreach (var c in cargo.Passengers)
|
||||
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Cnc
|
||||
var cargoPassenger = c.Trait<Passenger>();
|
||||
if (Info.DisplayTypes.Contains(cargoPassenger.info.CargoType))
|
||||
{
|
||||
var offset = pos - c.CenterPosition + coords.LocalToWorld(positions[i++ % positions.Length].Rotate(bodyOrientation));
|
||||
var offset = pos - c.CenterPosition + body.LocalToWorld(positions[i++ % positions.Length].Rotate(bodyOrientation));
|
||||
foreach (var cr in c.Render(wr))
|
||||
yield return cr.WithPos(cr.Pos + offset).WithZOffset(1);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc
|
||||
{
|
||||
class WithFireInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
class WithFireInfo : ITraitInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
public readonly WVec Offset = new WVec(299,-640,0);
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Cnc
|
||||
{
|
||||
public WithFire(Actor self, WithFireInfo info)
|
||||
{
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var roof = new Animation(rs.GetImage(self));
|
||||
roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop"));
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc
|
||||
{
|
||||
public class WithRoofInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
public class WithRoofInfo : ITraitInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new WithRoof(init.self); }
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Cnc
|
||||
{
|
||||
public WithRoof(Actor self)
|
||||
{
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var roof = new Animation(rs.GetImage(self), () => self.Trait<IFacing>().Facing);
|
||||
roof.Play("roof");
|
||||
rs.anims.Add("roof", new AnimationWithOffset(roof, null, null, 1024));
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
|
||||
public readonly WeaponInfo Weapon;
|
||||
public readonly Barrel[] Barrels;
|
||||
Lazy<Turreted> Turret;
|
||||
Lazy<ILocalCoordinatesModel> Coords;
|
||||
Lazy<IBodyOrientation> Coords;
|
||||
|
||||
public WRange Recoil;
|
||||
public int FireDelay { get; private set; }
|
||||
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
// We can't resolve these until runtime
|
||||
Turret = Lazy.New(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret));
|
||||
Coords = Lazy.New(() => self.Trait<ILocalCoordinatesModel>());
|
||||
Coords = Lazy.New(() => self.Trait<IBodyOrientation>());
|
||||
|
||||
Weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
|
||||
Burst = Weapon.Burst;
|
||||
|
||||
@@ -11,17 +11,30 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class BelowUnitsInfo : TraitInfo<BelowUnits> { }
|
||||
class BelowUnitsInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new BelowUnits(init.self); }
|
||||
}
|
||||
|
||||
class BelowUnits : IRenderModifier
|
||||
{
|
||||
int offset;
|
||||
|
||||
public BelowUnits(Actor self)
|
||||
{
|
||||
// Offset effective position to the top of the northernmost occupied cell
|
||||
var bi = self.Info.Traits.GetOrDefault<BuildingInfo>();
|
||||
offset = (bi != null) ? -FootprintUtils.CenterOffset(bi).Y : -512;
|
||||
}
|
||||
|
||||
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
|
||||
{
|
||||
return r.Select(a => a.WithZOffset(-a.Size(wr).Z));
|
||||
return r.Select(a => a.WithZOffset(offset));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Cnc
|
||||
{
|
||||
class DeadBuildingStateInfo : ITraitInfo, Requires<HealthInfo>, Requires<RenderSimpleInfo>
|
||||
class DeadBuildingStateInfo : ITraitInfo, Requires<HealthInfo>, Requires<RenderSpritesInfo>
|
||||
{
|
||||
public readonly int LingerTime = 20;
|
||||
|
||||
@@ -23,12 +23,12 @@ namespace OpenRA.Mods.Cnc
|
||||
class DeadBuildingState : INotifyKilled
|
||||
{
|
||||
DeadBuildingStateInfo info;
|
||||
RenderSimple rs;
|
||||
RenderSprites rs;
|
||||
|
||||
public DeadBuildingState(Actor self, DeadBuildingStateInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
rs = self.Trait<RenderSimple>();
|
||||
rs = self.Trait<RenderSprites>();
|
||||
self.Trait<Health>().RemoveOnDeath = !rs.anim.HasSequence("dead");
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class BurnsInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
class BurnsInfo : ITraitInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
public readonly string Anim = "1";
|
||||
public readonly int Damage = 1;
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
var anim = new Animation("fire", () => 0);
|
||||
anim.PlayRepeating(Info.Anim);
|
||||
self.Trait<RenderSimple>().anims.Add("fire",
|
||||
self.Trait<RenderSprites>().anims.Add("fire",
|
||||
new AnimationWithOffset(anim, () => info.Offset, null));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ using OpenRA.Mods.RA.Buildings;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class CrateInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
class CrateInfo : ITraitInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
public readonly int Lifetime = 5; // Seconds
|
||||
public readonly string[] TerrainTypes = { };
|
||||
@@ -116,7 +116,7 @@ namespace OpenRA.Mods.RA
|
||||
PxPosition = Util.CenterOfCell(cell);
|
||||
|
||||
var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "land";
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
if (seq != rs.anim.CurrentSequence.Name)
|
||||
rs.anim.PlayRepeating(seq);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class ContrailInfo : ITraitInfo, Requires<LocalCoordinatesModelInfo>
|
||||
class ContrailInfo : ITraitInfo, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Position relative to body")]
|
||||
public readonly WVec Offset = WVec.Zero;
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
ContrailInfo info;
|
||||
ContrailHistory history;
|
||||
ILocalCoordinatesModel coords;
|
||||
IBodyOrientation body;
|
||||
|
||||
public Contrail(Actor self, ContrailInfo info)
|
||||
{
|
||||
@@ -40,13 +40,13 @@ namespace OpenRA.Mods.RA
|
||||
history = new ContrailHistory(info.TrailLength,
|
||||
info.UsePlayerColor ? ContrailHistory.ChooseColor(self) : info.Color);
|
||||
|
||||
coords = self.Trait<ILocalCoordinatesModel>();
|
||||
body = self.Trait<IBodyOrientation>();
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
var local = info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation));
|
||||
history.Tick(self.CenterPosition + coords.LocalToWorld(local));
|
||||
var local = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation));
|
||||
history.Tick(self.CenterPosition + body.LocalToWorld(local));
|
||||
}
|
||||
|
||||
public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(wr, self); }
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
var self = init.self;
|
||||
// Work around a bogus crash
|
||||
anim.PlayRepeating( NormalizeSequence(self, "idle") );
|
||||
self.Trait<IBodyOrientation>().QuantizedFacings = anim.CurrentSequence.Facings;
|
||||
|
||||
// Can't call Complete() directly from ctor because other traits haven't been inited yet
|
||||
if (self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation && !init.Contains<SkipMakeAnimsInit>())
|
||||
|
||||
@@ -22,8 +22,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
class RenderBuildingTurreted : RenderBuilding
|
||||
{
|
||||
public RenderBuildingTurreted( ActorInitializer init, RenderBuildingInfo info )
|
||||
: base(init, info, MakeTurretFacingFunc(init.self)) { }
|
||||
Turreted t;
|
||||
|
||||
static Func<int> MakeTurretFacingFunc(Actor self)
|
||||
{
|
||||
@@ -31,5 +30,18 @@ namespace OpenRA.Mods.RA.Render
|
||||
var turreted = self.TraitsImplementing<Turreted>().FirstOrDefault();
|
||||
return () => turreted.turretFacing;
|
||||
}
|
||||
|
||||
public RenderBuildingTurreted(ActorInitializer init, RenderBuildingInfo info)
|
||||
: base(init, info, MakeTurretFacingFunc(init.self))
|
||||
{
|
||||
t = init.self.TraitsImplementing<Turreted>().FirstOrDefault();
|
||||
t.QuantizedFacings = anim.CurrentSequence.Facings;
|
||||
}
|
||||
|
||||
public override void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
base.DamageStateChanged(self, e);
|
||||
t.QuantizedFacings = anim.CurrentSequence.Facings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
foreach (var r in p)
|
||||
yield return r;
|
||||
|
||||
var anim = new Animation(RenderSimple.GetImage(building), () => 0);
|
||||
var anim = new Animation(RenderSprites.GetImage(building), () => 0);
|
||||
anim.PlayRepeating("idle-top");
|
||||
yield return new SpriteRenderable(anim.Image, WPos.Zero + Origin, 0, pr, 1f);
|
||||
}
|
||||
|
||||
@@ -55,12 +55,14 @@ namespace OpenRA.Mods.RA.Render
|
||||
public AnimationState State { get; private set; }
|
||||
|
||||
public RenderInfantry(Actor self, RenderInfantryInfo info)
|
||||
: base(self, RenderSimple.MakeFacingFunc(self))
|
||||
: base(self, MakeFacingFunc(self))
|
||||
{
|
||||
Info = info;
|
||||
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
|
||||
State = AnimationState.Waiting;
|
||||
mobile = self.Trait<Mobile>();
|
||||
|
||||
self.Trait<IBodyOrientation>().QuantizedFacings = anim.CurrentSequence.Facings;
|
||||
}
|
||||
|
||||
public void Attacking(Actor self, Target target)
|
||||
|
||||
@@ -22,10 +22,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
public class RenderUnit : RenderSimple
|
||||
{
|
||||
public RenderUnit(Actor self)
|
||||
: base(self, RenderSimple.MakeFacingFunc(self))
|
||||
{
|
||||
anim.PlayRepeating("idle");
|
||||
}
|
||||
: base(self) { }
|
||||
|
||||
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ using OpenRA.Mods.RA;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
class WithMuzzleFlashInfo : ITraitInfo, Requires<RenderSimpleInfo>, Requires<AttackBaseInfo>
|
||||
class WithMuzzleFlashInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<AttackBaseInfo>
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self); }
|
||||
}
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
public WithMuzzleFlash(Actor self)
|
||||
{
|
||||
var render = self.Trait<RenderSimple>();
|
||||
var render = self.Trait<RenderSprites>();
|
||||
var facing = self.TraitOrDefault<IFacing>();
|
||||
|
||||
var arms = self.TraitsImplementing<Armament>();
|
||||
|
||||
@@ -14,7 +14,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class WithRotorInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
public class WithRotorInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Position relative to body")]
|
||||
public readonly WVec Offset = WVec.Zero;
|
||||
@@ -28,12 +28,13 @@ namespace OpenRA.Mods.RA.Render
|
||||
public Animation rotorAnim;
|
||||
public WithRotor(Actor self, WithRotorInfo info)
|
||||
{
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var body = self.Trait<IBodyOrientation>();
|
||||
|
||||
rotorAnim = new Animation(rs.GetImage(self));
|
||||
rotorAnim.PlayRepeating("rotor");
|
||||
rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim,
|
||||
() => rs.LocalToWorld(info.Offset.Rotate(rs.QuantizeOrientation(self, self.Orientation))),
|
||||
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
|
||||
null, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class WithSmokeInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
public class WithSmokeInfo : ITraitInfo, Requires<RenderSpritesInfo>
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new WithSmoke(init.self); }
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Render
|
||||
|
||||
public WithSmoke(Actor self)
|
||||
{
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
|
||||
anim = new Animation("smoke_m");
|
||||
rs.anims.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking));
|
||||
|
||||
@@ -14,7 +14,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
class WithSpinnerInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
class WithSpinnerInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Sequence name to use")]
|
||||
public readonly string Sequence = "spinner";
|
||||
@@ -29,11 +29,13 @@ namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public WithSpinner(Actor self, WithSpinnerInfo info)
|
||||
{
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var body = self.Trait<IBodyOrientation>();
|
||||
|
||||
var spinner = new Animation(rs.GetImage(self));
|
||||
spinner.PlayRepeating(info.Sequence);
|
||||
rs.anims.Add("spinner_{0}".F(info.Sequence), new AnimationWithOffset(spinner,
|
||||
() => rs.LocalToWorld(info.Offset.Rotate(rs.QuantizeOrientation(self, self.Orientation))),
|
||||
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
|
||||
null, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#region Copyright & License Information
|
||||
#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
|
||||
@@ -17,7 +17,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
class WithTurretInfo : ITraitInfo, Requires<RenderSimpleInfo>, Requires<TurretedInfo>
|
||||
class WithTurretInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<TurretedInfo>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Sequence name to use")]
|
||||
public readonly string Sequence = "turret";
|
||||
@@ -28,13 +28,17 @@ namespace OpenRA.Mods.RA.Render
|
||||
[Desc("Turreted 'Turret' key to display")]
|
||||
public readonly string Turret = "primary";
|
||||
|
||||
[Desc("Render recoil")]
|
||||
public readonly bool Recoils = true;
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithTurret(init.self, this); }
|
||||
}
|
||||
|
||||
class WithTurret : ITick
|
||||
{
|
||||
WithTurretInfo info;
|
||||
RenderSimple rs;
|
||||
RenderSprites rs;
|
||||
IBodyOrientation body;
|
||||
AttackBase ab;
|
||||
Turreted t;
|
||||
IEnumerable<Armament> arms;
|
||||
@@ -43,7 +47,9 @@ namespace OpenRA.Mods.RA.Render
|
||||
public WithTurret(Actor self, WithTurretInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
rs = self.Trait<RenderSimple>();
|
||||
rs = self.Trait<RenderSprites>();
|
||||
body = self.Trait<IBodyOrientation>();
|
||||
|
||||
ab = self.TraitOrDefault<AttackBase>();
|
||||
t = self.TraitsImplementing<Turreted>()
|
||||
.First(tt => tt.Name == info.Turret);
|
||||
@@ -54,15 +60,21 @@ namespace OpenRA.Mods.RA.Render
|
||||
anim.Play(info.Sequence);
|
||||
rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset(
|
||||
anim, () => TurretOffset(self), null, p => ZOffsetFromCenter(self, p, 1)));
|
||||
|
||||
// Restrict turret facings to match the sprite
|
||||
t.QuantizedFacings = anim.CurrentSequence.Facings;
|
||||
}
|
||||
|
||||
WVec TurretOffset(Actor self)
|
||||
{
|
||||
if (!info.Recoils)
|
||||
return t.Position(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));
|
||||
return t.Position(self) + rs.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation));
|
||||
var bodyOrientation = body.QuantizeOrientation(self, self.Orientation);
|
||||
var turretOrientation = body.QuantizeOrientation(self, t.LocalOrientation(self));
|
||||
return t.Position(self) + body.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation));
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
|
||||
@@ -14,7 +14,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class SmokeTrailWhenDamagedInfo : ITraitInfo, Requires<LocalCoordinatesModelInfo>
|
||||
class SmokeTrailWhenDamagedInfo : ITraitInfo, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Position relative to body")]
|
||||
public readonly WVec Offset = WVec.Zero;
|
||||
@@ -26,14 +26,14 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
class SmokeTrailWhenDamaged : ITick
|
||||
{
|
||||
ILocalCoordinatesModel coords;
|
||||
IBodyOrientation body;
|
||||
SmokeTrailWhenDamagedInfo info;
|
||||
int ticks;
|
||||
|
||||
public SmokeTrailWhenDamaged(Actor self, SmokeTrailWhenDamagedInfo info)
|
||||
{
|
||||
this.info = info;
|
||||
coords = self.Trait<ILocalCoordinatesModel>();
|
||||
body = self.Trait<IBodyOrientation>();
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
@@ -44,8 +44,8 @@ namespace OpenRA.Mods.RA
|
||||
if (position.Z > 0 && self.GetDamageState() >= DamageState.Heavy &&
|
||||
!self.World.FogObscures(new CPos(position)))
|
||||
{
|
||||
var offset = info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation));
|
||||
var pos = position + coords.LocalToWorld(offset);
|
||||
var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation));
|
||||
var pos = position + body.LocalToWorld(offset);
|
||||
self.World.AddFrameEndTask(w => w.Add(new Smoke(w, pos, info.Sprite)));
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ namespace OpenRA.Mods.RA
|
||||
var tooltip = target.TraitsImplementing<IToolTip>().FirstOrDefault();
|
||||
disguisedAsName = tooltip.Name();
|
||||
disguisedAsPlayer = tooltip.Owner();
|
||||
disguisedAsSprite = target.Trait<RenderSimple>().GetImage(target);
|
||||
disguisedAsSprite = target.Trait<RenderSprites>().GetImage(target);
|
||||
}
|
||||
|
||||
void DropDisguise()
|
||||
|
||||
@@ -14,7 +14,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class NukePowerInfo : SupportPowerInfo
|
||||
class NukePowerInfo : SupportPowerInfo, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[WeaponReference]
|
||||
public readonly string MissileWeapon = "";
|
||||
@@ -25,7 +25,14 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
class NukePower : SupportPower
|
||||
{
|
||||
public NukePower(Actor self, NukePowerInfo info) : base(self, info) { }
|
||||
IBodyOrientation body;
|
||||
|
||||
public NukePower(Actor self, NukePowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
body = self.Trait<IBodyOrientation>();
|
||||
}
|
||||
|
||||
public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager)
|
||||
{
|
||||
Sound.PlayToPlayer(manager.self.Owner, Info.SelectTargetSound);
|
||||
@@ -42,7 +49,7 @@ namespace OpenRA.Mods.RA
|
||||
var rb = self.Trait<RenderSimple>();
|
||||
rb.PlayCustomAnim(self, "active");
|
||||
self.World.AddFrameEndTask(w => w.Add(
|
||||
new NukeLaunch(self.Owner, self, npi.MissileWeapon, self.CenterPosition + rb.LocalToWorld(npi.SpawnOffset), order.TargetLocation)));
|
||||
new NukeLaunch(self.Owner, self, npi.MissileWeapon, self.CenterPosition + body.LocalToWorld(npi.SpawnOffset), order.TargetLocation)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class ThrowsParticleInfo : ITraitInfo, Requires<RenderSimpleInfo>
|
||||
class ThrowsParticleInfo : ITraitInfo, Requires<RenderSimpleInfo>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
public readonly string Anim = null;
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
var self = init.self;
|
||||
var rs = self.Trait<RenderSimple>();
|
||||
var body = self.Trait<IBodyOrientation>();
|
||||
|
||||
// TODO: Carry orientation over from the parent instead of just facing
|
||||
var bodyFacing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : 0;
|
||||
@@ -63,7 +64,7 @@ namespace OpenRA.Mods.RA
|
||||
var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
|
||||
var throwOffset = new WVec((int)(Game.CosmeticRandom.Gauss1D(1)*info.ThrowRange.Range), 0, 0).Rotate(throwRotation);
|
||||
|
||||
initialPos = pos = info.Offset.Rotate(rs.QuantizeOrientation(self, WRot.FromFacing(bodyFacing)));
|
||||
initialPos = pos = info.Offset.Rotate(body.QuantizeOrientation(self, WRot.FromFacing(bodyFacing)));
|
||||
finalPos = initialPos + throwOffset;
|
||||
|
||||
// Facing rotation
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
public class Turreted : ITick, ISync, IResolveOrder
|
||||
{
|
||||
[Sync] public int QuantizedFacings = 0;
|
||||
[Sync] public int turretFacing = 0;
|
||||
public int? desiredFacing;
|
||||
TurretedInfo info;
|
||||
@@ -83,16 +84,25 @@ namespace OpenRA.Mods.RA
|
||||
// Turret offset in world-space
|
||||
public WVec Position(Actor self)
|
||||
{
|
||||
var coords = self.Trait<ILocalCoordinatesModel>();
|
||||
var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation);
|
||||
return coords.LocalToWorld(Offset.Rotate(bodyOrientation));
|
||||
var body = self.Trait<IBodyOrientation>();
|
||||
var bodyOrientation = body.QuantizeOrientation(self, self.Orientation);
|
||||
return body.LocalToWorld(Offset.Rotate(bodyOrientation));
|
||||
}
|
||||
|
||||
// Orientation in unit-space
|
||||
public WRot LocalOrientation(Actor self)
|
||||
{
|
||||
|
||||
// Hack: turretFacing is relative to the world, so subtract the body yaw
|
||||
return WRot.FromYaw(WAngle.FromFacing(turretFacing) - self.Orientation.Yaw);
|
||||
var local = WRot.FromYaw(WAngle.FromFacing(turretFacing) - self.Orientation.Yaw);
|
||||
|
||||
if (QuantizedFacings == 0)
|
||||
return local;
|
||||
|
||||
// Quantize orientation to match a rendered sprite
|
||||
// Implies no pitch or yaw
|
||||
var facing = Traits.Util.QuantizeFacing(local.Yaw.Angle / 4, QuantizedFacings) * (256 / QuantizedFacings);
|
||||
return new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(facing));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,3 +445,4 @@ VICE:
|
||||
AttackWander:
|
||||
RenderUnit:
|
||||
WithMuzzleFlash:
|
||||
BodyOrientation:
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Tank:
|
||||
AppearsOnRadar:
|
||||
@@ -72,6 +73,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Helicopter:
|
||||
AppearsOnRadar:
|
||||
@@ -97,6 +99,7 @@
|
||||
Weapon: HeliExplode
|
||||
EmptyWeapon: HeliExplode
|
||||
DebugMuzzlePositions:
|
||||
BodyOrientation:
|
||||
|
||||
^Infantry:
|
||||
AppearsOnRadar:
|
||||
@@ -149,6 +152,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^CivInfantry:
|
||||
Inherits: ^Infantry
|
||||
@@ -197,6 +201,7 @@
|
||||
DrawLineToTarget:
|
||||
ActorLostNotification:
|
||||
DebugMuzzlePositions:
|
||||
BodyOrientation:
|
||||
|
||||
^Ship:
|
||||
AppearsOnRadar:
|
||||
@@ -218,6 +223,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Building:
|
||||
AppearsOnRadar:
|
||||
@@ -266,6 +272,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guardable:
|
||||
Range: 3
|
||||
BodyOrientation:
|
||||
|
||||
^CivBuilding:
|
||||
Inherits: ^Building
|
||||
@@ -296,6 +303,7 @@
|
||||
RelativeToTopLeft: yes
|
||||
Tooltip:
|
||||
Name: Civilian Building (Destroyed)
|
||||
BodyOrientation:
|
||||
|
||||
^TechBuilding:
|
||||
Inherits: ^CivBuilding
|
||||
@@ -326,6 +334,7 @@
|
||||
Tooltip:
|
||||
Name: Field (Destroyed)
|
||||
BelowUnits:
|
||||
BodyOrientation:
|
||||
|
||||
^Wall:
|
||||
AppearsOnRadar:
|
||||
@@ -354,6 +363,7 @@
|
||||
AutoTargetIgnore:
|
||||
Sellable:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Tree:
|
||||
Tooltip:
|
||||
@@ -374,6 +384,7 @@
|
||||
Armor:
|
||||
Type: Wood
|
||||
AutoTargetIgnore:
|
||||
BodyOrientation:
|
||||
|
||||
^Rock:
|
||||
Tooltip:
|
||||
@@ -388,6 +399,7 @@
|
||||
Terrain: Tree
|
||||
EditorAppearance:
|
||||
RelativeToTopLeft: yes
|
||||
BodyOrientation:
|
||||
|
||||
^Husk:
|
||||
Health:
|
||||
@@ -403,6 +415,7 @@
|
||||
TransformOnCapture:
|
||||
ForceHealthPercentage: 25
|
||||
BelowUnits:
|
||||
BodyOrientation:
|
||||
# Capturable:
|
||||
# Type: husk
|
||||
# AllowAllies: true
|
||||
@@ -420,3 +433,4 @@
|
||||
SoundOnDamageTransition:
|
||||
DamagedSound: xplos.aud
|
||||
DestroyedSound: xplobig4.aud
|
||||
BodyOrientation:
|
||||
|
||||
@@ -351,11 +351,14 @@ CRATE:
|
||||
Unit: mcv
|
||||
RenderSimple:
|
||||
BelowUnits:
|
||||
BodyOrientation:
|
||||
|
||||
mpspawn:
|
||||
Waypoint:
|
||||
RenderEditorOnly:
|
||||
BodyOrientation:
|
||||
|
||||
waypoint:
|
||||
Waypoint:
|
||||
RenderEditorOnly:
|
||||
BodyOrientation:
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Tank:
|
||||
AppearsOnRadar:
|
||||
@@ -69,6 +70,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Husk:
|
||||
Health:
|
||||
@@ -84,6 +86,7 @@
|
||||
Types:Husk
|
||||
Tooltip:
|
||||
Name: Destroyed Tank
|
||||
BodyOrientation:
|
||||
|
||||
^TowerHusk:
|
||||
Health:
|
||||
@@ -101,6 +104,7 @@
|
||||
Name: Destroyed Tower
|
||||
ProximityCaptor:
|
||||
Types:Husk
|
||||
BodyOrientation:
|
||||
|
||||
^Infantry:
|
||||
AppearsOnRadar:
|
||||
@@ -149,6 +153,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Plane:
|
||||
AppearsOnRadar:
|
||||
@@ -168,6 +173,7 @@
|
||||
Types:Plane
|
||||
GivesBounty:
|
||||
DebugMuzzlePositions:
|
||||
BodyOrientation:
|
||||
|
||||
^Helicopter:
|
||||
Inherits: ^Plane
|
||||
@@ -216,3 +222,4 @@
|
||||
Bib:
|
||||
Guardable:
|
||||
Range: 3
|
||||
BodyOrientation:
|
||||
|
||||
@@ -372,6 +372,7 @@ WALL:
|
||||
Types:Wall
|
||||
Sellable:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
GUNTOWER:
|
||||
Inherits: ^Building
|
||||
|
||||
@@ -481,14 +481,17 @@ CRATE:
|
||||
ProximityCaptor:
|
||||
Types:Crate
|
||||
Passenger:
|
||||
BodyOrientation:
|
||||
|
||||
mpspawn:
|
||||
Waypoint:
|
||||
RenderEditorOnly:
|
||||
BodyOrientation:
|
||||
|
||||
waypoint:
|
||||
Waypoint:
|
||||
RenderEditorOnly:
|
||||
BodyOrientation:
|
||||
|
||||
SPICEBLOOM:
|
||||
RenderBuilding:
|
||||
@@ -508,6 +511,7 @@ SPICEBLOOM:
|
||||
Interval: 75
|
||||
RadarColorFromTerrain:
|
||||
Terrain: Spice
|
||||
BodyOrientation:
|
||||
|
||||
#SANDWORM:
|
||||
# Buildable:
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Tank:
|
||||
AppearsOnRadar:
|
||||
@@ -75,6 +76,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Infantry:
|
||||
AppearsOnRadar:
|
||||
@@ -126,6 +128,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Ship:
|
||||
AppearsOnRadar:
|
||||
@@ -157,6 +160,7 @@
|
||||
DebugMuzzlePositions:
|
||||
Guard:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^Plane:
|
||||
AppearsOnRadar:
|
||||
@@ -183,6 +187,7 @@
|
||||
String:Plane
|
||||
UpdatesPlayerStatistics:
|
||||
DebugMuzzlePositions:
|
||||
BodyOrientation:
|
||||
|
||||
^Helicopter:
|
||||
Inherits: ^Plane
|
||||
@@ -229,6 +234,7 @@
|
||||
Guardable:
|
||||
Range: 3
|
||||
AutoTargetIgnore:
|
||||
BodyOrientation:
|
||||
|
||||
^Wall:
|
||||
AppearsOnRadar:
|
||||
@@ -263,6 +269,7 @@
|
||||
Sellable:
|
||||
UpdatesPlayerStatistics:
|
||||
Guardable:
|
||||
BodyOrientation:
|
||||
|
||||
^TechBuilding:
|
||||
Inherits: ^Building
|
||||
@@ -344,6 +351,7 @@
|
||||
Armor:
|
||||
Type: Wood
|
||||
AutoTargetIgnore:
|
||||
BodyOrientation:
|
||||
|
||||
^Husk:
|
||||
Husk:
|
||||
@@ -358,6 +366,7 @@
|
||||
ProximityCaptor:
|
||||
Types:Husk
|
||||
BelowUnits:
|
||||
BodyOrientation:
|
||||
|
||||
^Bridge:
|
||||
Tooltip:
|
||||
@@ -373,6 +382,7 @@
|
||||
ProximityCaptor:
|
||||
Types:Bridge
|
||||
AutoTargetIgnore:
|
||||
BodyOrientation:
|
||||
|
||||
#Temperate Terrain Expansion
|
||||
^SVBridge:
|
||||
@@ -389,6 +399,7 @@
|
||||
ProximityCaptor:
|
||||
Types:Bridge
|
||||
AutoTargetIgnore:
|
||||
BodyOrientation:
|
||||
|
||||
^SHBridge:
|
||||
Tooltip:
|
||||
@@ -404,6 +415,7 @@
|
||||
ProximityCaptor:
|
||||
Types:Bridge
|
||||
AutoTargetIgnore:
|
||||
BodyOrientation:
|
||||
|
||||
^STDBridge:
|
||||
Tooltip:
|
||||
@@ -419,6 +431,7 @@
|
||||
ProximityCaptor:
|
||||
Types:Bridge
|
||||
AutoTargetIgnore:
|
||||
BodyOrientation:
|
||||
|
||||
#Desert Terrain Expansion:
|
||||
^Rock:
|
||||
@@ -437,6 +450,7 @@
|
||||
UseTerrainPalette: true
|
||||
ProximityCaptor:
|
||||
Types:Tree
|
||||
BodyOrientation:
|
||||
|
||||
^DesertCivBuilding:
|
||||
Inherits: ^CivBuilding
|
||||
|
||||
@@ -670,6 +670,7 @@ MINP:
|
||||
Types: Mine
|
||||
TargetableUnit:
|
||||
TargetTypes: Ground
|
||||
BodyOrientation:
|
||||
|
||||
MINV:
|
||||
Mine:
|
||||
@@ -695,6 +696,7 @@ MINV:
|
||||
Types: Mine
|
||||
TargetableUnit:
|
||||
TargetTypes: Ground
|
||||
BodyOrientation:
|
||||
|
||||
CRATE:
|
||||
Tooltip:
|
||||
@@ -757,6 +759,7 @@ CRATE:
|
||||
ProximityCaptor:
|
||||
Types:Crate
|
||||
Passenger:
|
||||
BodyOrientation:
|
||||
|
||||
CAMERA:
|
||||
Aircraft:
|
||||
@@ -766,6 +769,7 @@ CAMERA:
|
||||
Range: 10
|
||||
ProximityCaptor:
|
||||
Types:Camera
|
||||
BodyOrientation:
|
||||
|
||||
FLARE:
|
||||
Aircraft:
|
||||
@@ -780,6 +784,7 @@ FLARE:
|
||||
Name: Flare
|
||||
ProximityCaptor:
|
||||
Types: Flare
|
||||
BodyOrientation:
|
||||
|
||||
powerproxy.parabombs:
|
||||
AirstrikePower:
|
||||
@@ -805,7 +810,9 @@ powerproxy.sonarpulse:
|
||||
mpspawn:
|
||||
Waypoint:
|
||||
RenderEditorOnly:
|
||||
BodyOrientation:
|
||||
|
||||
waypoint:
|
||||
Waypoint:
|
||||
RenderEditorOnly:
|
||||
BodyOrientation:
|
||||
|
||||
Reference in New Issue
Block a user