Merge pull request #3348 from pchote/rendersprites

Renderer refactoring - Traits
This commit is contained in:
Chris Forbes
2013-05-31 20:05:02 -07:00
41 changed files with 384 additions and 179 deletions

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Editor
public static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, Palette p) 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)) using (var s = FileSystem.OpenWithExts(image, tileset.Extensions))
{ {

View File

@@ -41,7 +41,6 @@ namespace OpenRA.Graphics
IRenderable WithZOffset(int newOffset); IRenderable WithZOffset(int newOffset);
IRenderable WithPos(WPos pos); IRenderable WithPos(WPos pos);
void Render(WorldRenderer wr); void Render(WorldRenderer wr);
WVec Size(WorldRenderer wr);
} }
public struct SpriteRenderable : IRenderable public struct SpriteRenderable : IRenderable
@@ -84,11 +83,5 @@ namespace OpenRA.Graphics
{ {
sprite.DrawAt(wr.ScreenPxPosition(pos) - pxCenter, palette.Index, scale); 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);
}
} }
} }

View File

@@ -19,6 +19,7 @@ namespace OpenRA.Graphics
{ {
readonly Sprite[] sprites; readonly Sprite[] sprites;
readonly int start, length, stride, facings, tick; readonly int start, length, stride, facings, tick;
readonly bool reverseFacings, transpose;
public readonly string Name; public readonly string Name;
public int Start { get { return start; } } public int Start { get { return start; } }
@@ -49,16 +50,23 @@ namespace OpenRA.Graphics
else else
stride = length; stride = length;
if(d.ContainsKey("Facings")) 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 else
facings = 1; facings = 1;
if(d.ContainsKey("Tick")) if (d.ContainsKey("Tick"))
tick = int.Parse(d["Tick"].Value); tick = int.Parse(d["Tick"].Value);
else else
tick = 40; tick = 40;
if (d.ContainsKey("Transpose"))
transpose = bool.Parse(d["Transpose"].Value);
if (length > stride) if (length > stride)
throw new InvalidOperationException( throw new InvalidOperationException(
"{0}: Sequence {1}.{2}: Length must be <= stride" "{0}: Sequence {1}.{2}: Length must be <= stride"
@@ -71,15 +79,22 @@ namespace OpenRA.Graphics
info.Nodes[0].Location)); info.Nodes[0].Location));
} }
public Sprite GetSprite( int frame ) public Sprite GetSprite(int frame)
{ {
return GetSprite( frame, 0 ); return GetSprite(frame, 0);
} }
public Sprite GetSprite(int frame, int facing) public Sprite GetSprite(int frame, int facing)
{ {
var f = Traits.Util.QuantizeFacing( facing, facings ); 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];
} }
} }
} }

View File

@@ -225,6 +225,8 @@
<Compile Include="Network\UPnP.cs" /> <Compile Include="Network\UPnP.cs" />
<Compile Include="Widgets\ClientTooltipRegionWidget.cs" /> <Compile Include="Widgets\ClientTooltipRegionWidget.cs" />
<Compile Include="Graphics\Renderable.cs" /> <Compile Include="Graphics\Renderable.cs" />
<Compile Include="Traits\Render\RenderSprites.cs" />
<Compile Include="Traits\BodyOrientation.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View 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));
}
}
}

View File

@@ -16,23 +16,9 @@ using OpenRA.FileFormats;
namespace OpenRA.Traits namespace OpenRA.Traits
{ {
public class RenderSimpleInfo : ITraitInfo, LocalCoordinatesModelInfo public class RenderSimpleInfo : RenderSpritesInfo, Requires<IBodyOrientationInfo>
{ {
[Desc("Defaults to the actor name.")] public override object Create(ActorInitializer init) { return new RenderSimple(init.self); }
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 virtual IEnumerable<IRenderable> RenderPreview(ActorInfo ai, PaletteReference pr) 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; RenderSimpleInfo Info;
string cachedImage = null;
bool initializePalette = true;
protected PaletteReference palette;
public RenderSimple(Actor self, Func<int> baseFacing) public RenderSimple(Actor self, Func<int> baseFacing)
: base(self, baseFacing)
{ {
anims.Add("", new Animation(GetImage(self), baseFacing)); anims.Add("", new Animation(GetImage(self), baseFacing));
Info = self.Info.Traits.Get<RenderSimpleInfo>(); 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"); anim.PlayRepeating("idle");
} self.Trait<IBodyOrientation>().QuantizedFacings = anim.CurrentSequence.Facings;
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 int2 SelectionSize(Actor self) public int2 SelectionSize(Actor self)
@@ -120,12 +55,6 @@ namespace OpenRA.Traits
.FirstOrDefault(); .FirstOrDefault();
} }
public virtual void Tick(Actor self)
{
foreach (var a in anims.Values)
a.Animation.Tick();
}
protected virtual string NormalizeSequence(Actor self, string baseSequence) protected virtual string NormalizeSequence(Actor self, string baseSequence)
{ {
string damageState = self.GetDamageState() >= DamageState.Heavy ? "damaged-" : ""; string damageState = self.GetDamageState() >= DamageState.Heavy ? "damaged-" : "";
@@ -141,22 +70,5 @@ namespace OpenRA.Traits
anim.PlayThen(NormalizeSequence(self, name), anim.PlayThen(NormalizeSequence(self, name),
() => anim.PlayRepeating(NormalizeSequence(self, "idle"))); () => 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));
}
} }
} }

View 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();
}
}
}

View File

@@ -187,12 +187,14 @@ namespace OpenRA.Traits
public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr); } public interface IPostRenderSelection { void RenderAfterWorld(WorldRenderer wr); }
public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); } public interface IPreRenderSelection { void RenderBeforeWorld(WorldRenderer wr, Actor self); }
public interface IRenderAsTerrain { IEnumerable<IRenderable> RenderAsTerrain(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); WVec LocalToWorld(WVec vec);
WRot QuantizeOrientation(Actor self, WRot orientation); WRot QuantizeOrientation(Actor self, WRot orientation);
} }
public interface LocalCoordinatesModelInfo {} public interface IBodyOrientationInfo {}
public interface ITargetable public interface ITargetable
{ {

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render namespace OpenRA.Mods.RA.Render
{ {
class RenderGunboatInfo : RenderUnitInfo class RenderGunboatInfo : RenderSimpleInfo
{ {
public override object Create(ActorInitializer init) { return new RenderGunboat(init.self); } public override object Create(ActorInitializer init) { return new RenderGunboat(init.self); }
} }
@@ -26,8 +26,13 @@ namespace OpenRA.Mods.RA.Render
string lastDir = "left"; string lastDir = "left";
string lastDamage = ""; string lastDamage = "";
static Func<int> TurretFacingFunc(Actor self)
{
return () => self.HasTrait<Turreted>() ? self.TraitsImplementing<Turreted>().First().turretFacing : 0;
}
public RenderGunboat(Actor self) public RenderGunboat(Actor self)
: base(self, () => self.HasTrait<Turreted>() ? self.TraitsImplementing<Turreted>().First().turretFacing : 0) : base(self, TurretFacingFunc(self))
{ {
facing = self.Trait<IFacing>(); facing = self.Trait<IFacing>();
anim.Play("left"); anim.Play("left");
@@ -40,6 +45,8 @@ namespace OpenRA.Mods.RA.Render
anims.Add("wake", new AnimationWithOffset(wake, anims.Add("wake", new AnimationWithOffset(wake,
() => anims["wake"].Animation.CurrentSequence.Name == "left-wake" ? leftOffset : rightOffset, () => anims["wake"].Animation.CurrentSequence.Name == "left-wake" ? leftOffset : rightOffset,
() => false, -87)); () => false, -87));
self.Trait<IBodyOrientation>().QuantizedFacings = anim.CurrentSequence.Facings;
} }
public override void Tick(Actor self) public override void Tick(Actor self)

View File

@@ -18,7 +18,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Cnc 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")] [Desc("Cargo position relative to turret or body. (forward, right, up) triples")]
public readonly WRange[] LocalOffset = {}; public readonly WRange[] LocalOffset = {};
@@ -33,7 +33,7 @@ namespace OpenRA.Mods.Cnc
IFacing facing; IFacing facing;
WithCargoInfo Info; WithCargoInfo Info;
WVec[] positions; WVec[] positions;
ILocalCoordinatesModel coords; IBodyOrientation body;
public WithCargo(Actor self, WithCargoInfo info) public WithCargo(Actor self, WithCargoInfo info)
{ {
@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc
facing = self.TraitOrDefault<IFacing>(); facing = self.TraitOrDefault<IFacing>();
Info = info; Info = info;
coords = self.Trait<ILocalCoordinatesModel>(); body = self.Trait<IBodyOrientation>();
if (info.LocalOffset.Length % 3 != 0) if (info.LocalOffset.Length % 3 != 0)
throw new InvalidOperationException("Invalid LocalOffset array length"); throw new InvalidOperationException("Invalid LocalOffset array length");
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Cnc
foreach (var rr in r) foreach (var rr in r)
yield return rr; yield return rr;
var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation); var bodyOrientation = body.QuantizeOrientation(self, self.Orientation);
var pos = self.CenterPosition; var pos = self.CenterPosition;
int i = 0; int i = 0;
foreach (var c in cargo.Passengers) foreach (var c in cargo.Passengers)
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Cnc
var cargoPassenger = c.Trait<Passenger>(); var cargoPassenger = c.Trait<Passenger>();
if (Info.DisplayTypes.Contains(cargoPassenger.info.CargoType)) 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)) foreach (var cr in c.Render(wr))
yield return cr.WithPos(cr.Pos + offset).WithZOffset(1); yield return cr.WithPos(cr.Pos + offset).WithZOffset(1);
} }

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Cnc namespace OpenRA.Mods.Cnc
{ {
class WithFireInfo : ITraitInfo, Requires<RenderSimpleInfo> class WithFireInfo : ITraitInfo, Requires<RenderSpritesInfo>
{ {
public readonly WVec Offset = new WVec(299,-640,0); public readonly WVec Offset = new WVec(299,-640,0);
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Cnc
{ {
public WithFire(Actor self, WithFireInfo info) public WithFire(Actor self, WithFireInfo info)
{ {
var rs = self.Trait<RenderSimple>(); var rs = self.Trait<RenderSprites>();
var roof = new Animation(rs.GetImage(self)); var roof = new Animation(rs.GetImage(self));
roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop")); roof.PlayThen("fire-start", () => roof.PlayRepeating("fire-loop"));

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Cnc 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); } public object Create(ActorInitializer init) { return new WithRoof(init.self); }
} }
@@ -22,7 +22,7 @@ namespace OpenRA.Mods.Cnc
{ {
public WithRoof(Actor self) 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); var roof = new Animation(rs.GetImage(self), () => self.Trait<IFacing>().Facing);
roof.Play("roof"); roof.Play("roof");
rs.anims.Add("roof", new AnimationWithOffset(roof, null, null, 1024)); rs.anims.Add("roof", new AnimationWithOffset(roof, null, null, 1024));

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
public readonly WeaponInfo Weapon; public readonly WeaponInfo Weapon;
public readonly Barrel[] Barrels; public readonly Barrel[] Barrels;
Lazy<Turreted> Turret; Lazy<Turreted> Turret;
Lazy<ILocalCoordinatesModel> Coords; Lazy<IBodyOrientation> Coords;
public WRange Recoil; public WRange Recoil;
public int FireDelay { get; private set; } public int FireDelay { get; private set; }
@@ -66,7 +66,7 @@ namespace OpenRA.Mods.RA
// We can't resolve these until runtime // We can't resolve these until runtime
Turret = Lazy.New(() => self.TraitsImplementing<Turreted>().FirstOrDefault(t => t.Name == info.Turret)); 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()]; Weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
Burst = Weapon.Burst; Burst = Weapon.Burst;

View File

@@ -11,17 +11,30 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class BelowUnitsInfo : TraitInfo<BelowUnits> { } class BelowUnitsInfo : ITraitInfo
{
public object Create(ActorInitializer init) { return new BelowUnits(init.self); }
}
class BelowUnits : IRenderModifier 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) 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));
} }
} }
} }

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.Cnc namespace OpenRA.Mods.Cnc
{ {
class DeadBuildingStateInfo : ITraitInfo, Requires<HealthInfo>, Requires<RenderSimpleInfo> class DeadBuildingStateInfo : ITraitInfo, Requires<HealthInfo>, Requires<RenderSpritesInfo>
{ {
public readonly int LingerTime = 20; public readonly int LingerTime = 20;
@@ -23,12 +23,12 @@ namespace OpenRA.Mods.Cnc
class DeadBuildingState : INotifyKilled class DeadBuildingState : INotifyKilled
{ {
DeadBuildingStateInfo info; DeadBuildingStateInfo info;
RenderSimple rs; RenderSprites rs;
public DeadBuildingState(Actor self, DeadBuildingStateInfo info) public DeadBuildingState(Actor self, DeadBuildingStateInfo info)
{ {
this.info = info; this.info = info;
rs = self.Trait<RenderSimple>(); rs = self.Trait<RenderSprites>();
self.Trait<Health>().RemoveOnDeath = !rs.anim.HasSequence("dead"); self.Trait<Health>().RemoveOnDeath = !rs.anim.HasSequence("dead");
} }

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class BurnsInfo : ITraitInfo, Requires<RenderSimpleInfo> class BurnsInfo : ITraitInfo, Requires<RenderSpritesInfo>
{ {
public readonly string Anim = "1"; public readonly string Anim = "1";
public readonly int Damage = 1; public readonly int Damage = 1;
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
var anim = new Animation("fire", () => 0); var anim = new Animation("fire", () => 0);
anim.PlayRepeating(Info.Anim); anim.PlayRepeating(Info.Anim);
self.Trait<RenderSimple>().anims.Add("fire", self.Trait<RenderSprites>().anims.Add("fire",
new AnimationWithOffset(anim, () => info.Offset, null)); new AnimationWithOffset(anim, () => info.Offset, null));
} }

View File

@@ -16,7 +16,7 @@ using OpenRA.Mods.RA.Buildings;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class CrateInfo : ITraitInfo, Requires<RenderSimpleInfo> class CrateInfo : ITraitInfo, Requires<RenderSpritesInfo>
{ {
public readonly int Lifetime = 5; // Seconds public readonly int Lifetime = 5; // Seconds
public readonly string[] TerrainTypes = { }; public readonly string[] TerrainTypes = { };
@@ -116,7 +116,7 @@ namespace OpenRA.Mods.RA
PxPosition = Util.CenterOfCell(cell); PxPosition = Util.CenterOfCell(cell);
var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "land"; 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) if (seq != rs.anim.CurrentSequence.Name)
rs.anim.PlayRepeating(seq); rs.anim.PlayRepeating(seq);

View File

@@ -16,7 +16,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class ContrailInfo : ITraitInfo, Requires<LocalCoordinatesModelInfo> class ContrailInfo : ITraitInfo, Requires<IBodyOrientationInfo>
{ {
[Desc("Position relative to body")] [Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero; public readonly WVec Offset = WVec.Zero;
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA
{ {
ContrailInfo info; ContrailInfo info;
ContrailHistory history; ContrailHistory history;
ILocalCoordinatesModel coords; IBodyOrientation body;
public Contrail(Actor self, ContrailInfo info) public Contrail(Actor self, ContrailInfo info)
{ {
@@ -40,13 +40,13 @@ namespace OpenRA.Mods.RA
history = new ContrailHistory(info.TrailLength, history = new ContrailHistory(info.TrailLength,
info.UsePlayerColor ? ContrailHistory.ChooseColor(self) : info.Color); info.UsePlayerColor ? ContrailHistory.ChooseColor(self) : info.Color);
coords = self.Trait<ILocalCoordinatesModel>(); body = self.Trait<IBodyOrientation>();
} }
public void Tick(Actor self) public void Tick(Actor self)
{ {
var local = info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation)); var local = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation));
history.Tick(self.CenterPosition + coords.LocalToWorld(local)); history.Tick(self.CenterPosition + body.LocalToWorld(local));
} }
public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(wr, self); } public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(wr, self); }

View File

@@ -57,6 +57,7 @@ namespace OpenRA.Mods.RA.Render
var self = init.self; var self = init.self;
// Work around a bogus crash // Work around a bogus crash
anim.PlayRepeating( NormalizeSequence(self, "idle") ); 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 // 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>()) if (self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation && !init.Contains<SkipMakeAnimsInit>())

View File

@@ -22,8 +22,7 @@ namespace OpenRA.Mods.RA.Render
class RenderBuildingTurreted : RenderBuilding class RenderBuildingTurreted : RenderBuilding
{ {
public RenderBuildingTurreted( ActorInitializer init, RenderBuildingInfo info ) Turreted t;
: base(init, info, MakeTurretFacingFunc(init.self)) { }
static Func<int> MakeTurretFacingFunc(Actor self) static Func<int> MakeTurretFacingFunc(Actor self)
{ {
@@ -31,5 +30,18 @@ namespace OpenRA.Mods.RA.Render
var turreted = self.TraitsImplementing<Turreted>().FirstOrDefault(); var turreted = self.TraitsImplementing<Turreted>().FirstOrDefault();
return () => turreted.turretFacing; 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;
}
} }
} }

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render
foreach (var r in p) foreach (var r in p)
yield return r; yield return r;
var anim = new Animation(RenderSimple.GetImage(building), () => 0); var anim = new Animation(RenderSprites.GetImage(building), () => 0);
anim.PlayRepeating("idle-top"); anim.PlayRepeating("idle-top");
yield return new SpriteRenderable(anim.Image, WPos.Zero + Origin, 0, pr, 1f); yield return new SpriteRenderable(anim.Image, WPos.Zero + Origin, 0, pr, 1f);
} }

View File

@@ -55,12 +55,14 @@ namespace OpenRA.Mods.RA.Render
public AnimationState State { get; private set; } public AnimationState State { get; private set; }
public RenderInfantry(Actor self, RenderInfantryInfo info) public RenderInfantry(Actor self, RenderInfantryInfo info)
: base(self, RenderSimple.MakeFacingFunc(self)) : base(self, MakeFacingFunc(self))
{ {
Info = info; Info = info;
anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0); anim.PlayFetchIndex(NormalizeInfantrySequence(self, "stand"), () => 0);
State = AnimationState.Waiting; State = AnimationState.Waiting;
mobile = self.Trait<Mobile>(); mobile = self.Trait<Mobile>();
self.Trait<IBodyOrientation>().QuantizedFacings = anim.CurrentSequence.Facings;
} }
public void Attacking(Actor self, Target target) public void Attacking(Actor self, Target target)

View File

@@ -22,10 +22,7 @@ namespace OpenRA.Mods.RA.Render
public class RenderUnit : RenderSimple public class RenderUnit : RenderSimple
{ {
public RenderUnit(Actor self) public RenderUnit(Actor self)
: base(self, RenderSimple.MakeFacingFunc(self)) : base(self) { }
{
anim.PlayRepeating("idle");
}
public void PlayCustomAnimation(Actor self, string newAnim, Action after) public void PlayCustomAnimation(Actor self, string newAnim, Action after)
{ {

View File

@@ -17,7 +17,7 @@ using OpenRA.Mods.RA;
namespace OpenRA.Mods.RA.Render 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); } public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self); }
} }
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Render
public WithMuzzleFlash(Actor self) public WithMuzzleFlash(Actor self)
{ {
var render = self.Trait<RenderSimple>(); var render = self.Trait<RenderSprites>();
var facing = self.TraitOrDefault<IFacing>(); var facing = self.TraitOrDefault<IFacing>();
var arms = self.TraitsImplementing<Armament>(); var arms = self.TraitsImplementing<Armament>();

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render namespace OpenRA.Mods.RA.Render
{ {
public class WithRotorInfo : ITraitInfo, Requires<RenderSimpleInfo> public class WithRotorInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
{ {
[Desc("Position relative to body")] [Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero; public readonly WVec Offset = WVec.Zero;
@@ -28,12 +28,13 @@ namespace OpenRA.Mods.RA.Render
public Animation rotorAnim; public Animation rotorAnim;
public WithRotor(Actor self, WithRotorInfo info) 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 = new Animation(rs.GetImage(self));
rotorAnim.PlayRepeating("rotor"); rotorAnim.PlayRepeating("rotor");
rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim, 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))); null, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
} }

View File

@@ -13,7 +13,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render 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); } public object Create(ActorInitializer init) { return new WithSmoke(init.self); }
} }
@@ -25,7 +25,7 @@ namespace OpenRA.Mods.RA.Render
public WithSmoke(Actor self) public WithSmoke(Actor self)
{ {
var rs = self.Trait<RenderSimple>(); var rs = self.Trait<RenderSprites>();
anim = new Animation("smoke_m"); anim = new Animation("smoke_m");
rs.anims.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking)); rs.anims.Add("smoke", new AnimationWithOffset(anim, null, () => !isSmoking));

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA.Render namespace OpenRA.Mods.RA.Render
{ {
class WithSpinnerInfo : ITraitInfo, Requires<RenderSimpleInfo> class WithSpinnerInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
{ {
[Desc("Sequence name to use")] [Desc("Sequence name to use")]
public readonly string Sequence = "spinner"; public readonly string Sequence = "spinner";
@@ -29,11 +29,13 @@ namespace OpenRA.Mods.RA.Render
{ {
public WithSpinner(Actor self, WithSpinnerInfo info) 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)); var spinner = new Animation(rs.GetImage(self));
spinner.PlayRepeating(info.Sequence); spinner.PlayRepeating(info.Sequence);
rs.anims.Add("spinner_{0}".F(info.Sequence), new AnimationWithOffset(spinner, 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))); null, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
} }
} }

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS) * Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * 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 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")] [Desc("Sequence name to use")]
public readonly string Sequence = "turret"; public readonly string Sequence = "turret";
@@ -28,13 +28,17 @@ namespace OpenRA.Mods.RA.Render
[Desc("Turreted 'Turret' key to display")] [Desc("Turreted 'Turret' key to display")]
public readonly string Turret = "primary"; public readonly string Turret = "primary";
[Desc("Render recoil")]
public readonly bool Recoils = true;
public object Create(ActorInitializer init) { return new WithTurret(init.self, this); } public object Create(ActorInitializer init) { return new WithTurret(init.self, this); }
} }
class WithTurret : ITick class WithTurret : ITick
{ {
WithTurretInfo info; WithTurretInfo info;
RenderSimple rs; RenderSprites rs;
IBodyOrientation body;
AttackBase ab; AttackBase ab;
Turreted t; Turreted t;
IEnumerable<Armament> arms; IEnumerable<Armament> arms;
@@ -43,7 +47,9 @@ namespace OpenRA.Mods.RA.Render
public WithTurret(Actor self, WithTurretInfo info) public WithTurret(Actor self, WithTurretInfo info)
{ {
this.info = info; this.info = info;
rs = self.Trait<RenderSimple>(); rs = self.Trait<RenderSprites>();
body = self.Trait<IBodyOrientation>();
ab = self.TraitOrDefault<AttackBase>(); ab = self.TraitOrDefault<AttackBase>();
t = self.TraitsImplementing<Turreted>() t = self.TraitsImplementing<Turreted>()
.First(tt => tt.Name == info.Turret); .First(tt => tt.Name == info.Turret);
@@ -54,15 +60,21 @@ namespace OpenRA.Mods.RA.Render
anim.Play(info.Sequence); anim.Play(info.Sequence);
rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset( rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset(
anim, () => TurretOffset(self), null, p => ZOffsetFromCenter(self, p, 1))); 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) WVec TurretOffset(Actor self)
{ {
if (!info.Recoils)
return t.Position(self);
var recoil = arms.Aggregate(WRange.Zero, (a,b) => a + b.Recoil); var recoil = arms.Aggregate(WRange.Zero, (a,b) => a + b.Recoil);
var localOffset = new WVec(-recoil, WRange.Zero, WRange.Zero); var localOffset = new WVec(-recoil, WRange.Zero, WRange.Zero);
var bodyOrientation = rs.QuantizeOrientation(self, self.Orientation); var bodyOrientation = body.QuantizeOrientation(self, self.Orientation);
var turretOrientation = rs.QuantizeOrientation(self, t.LocalOrientation(self)); var turretOrientation = body.QuantizeOrientation(self, t.LocalOrientation(self));
return t.Position(self) + rs.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation)); return t.Position(self) + body.LocalToWorld(localOffset.Rotate(turretOrientation).Rotate(bodyOrientation));
} }
public void Tick(Actor self) public void Tick(Actor self)

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class SmokeTrailWhenDamagedInfo : ITraitInfo, Requires<LocalCoordinatesModelInfo> class SmokeTrailWhenDamagedInfo : ITraitInfo, Requires<IBodyOrientationInfo>
{ {
[Desc("Position relative to body")] [Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero; public readonly WVec Offset = WVec.Zero;
@@ -26,14 +26,14 @@ namespace OpenRA.Mods.RA
class SmokeTrailWhenDamaged : ITick class SmokeTrailWhenDamaged : ITick
{ {
ILocalCoordinatesModel coords; IBodyOrientation body;
SmokeTrailWhenDamagedInfo info; SmokeTrailWhenDamagedInfo info;
int ticks; int ticks;
public SmokeTrailWhenDamaged(Actor self, SmokeTrailWhenDamagedInfo info) public SmokeTrailWhenDamaged(Actor self, SmokeTrailWhenDamagedInfo info)
{ {
this.info = info; this.info = info;
coords = self.Trait<ILocalCoordinatesModel>(); body = self.Trait<IBodyOrientation>();
} }
public void Tick(Actor self) public void Tick(Actor self)
@@ -44,8 +44,8 @@ namespace OpenRA.Mods.RA
if (position.Z > 0 && self.GetDamageState() >= DamageState.Heavy && if (position.Z > 0 && self.GetDamageState() >= DamageState.Heavy &&
!self.World.FogObscures(new CPos(position))) !self.World.FogObscures(new CPos(position)))
{ {
var offset = info.Offset.Rotate(coords.QuantizeOrientation(self, self.Orientation)); var offset = info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation));
var pos = position + coords.LocalToWorld(offset); var pos = position + body.LocalToWorld(offset);
self.World.AddFrameEndTask(w => w.Add(new Smoke(w, pos, info.Sprite))); self.World.AddFrameEndTask(w => w.Add(new Smoke(w, pos, info.Sprite)));
} }

View File

@@ -126,7 +126,7 @@ namespace OpenRA.Mods.RA
var tooltip = target.TraitsImplementing<IToolTip>().FirstOrDefault(); var tooltip = target.TraitsImplementing<IToolTip>().FirstOrDefault();
disguisedAsName = tooltip.Name(); disguisedAsName = tooltip.Name();
disguisedAsPlayer = tooltip.Owner(); disguisedAsPlayer = tooltip.Owner();
disguisedAsSprite = target.Trait<RenderSimple>().GetImage(target); disguisedAsSprite = target.Trait<RenderSprites>().GetImage(target);
} }
void DropDisguise() void DropDisguise()

View File

@@ -14,7 +14,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class NukePowerInfo : SupportPowerInfo class NukePowerInfo : SupportPowerInfo, Requires<IBodyOrientationInfo>
{ {
[WeaponReference] [WeaponReference]
public readonly string MissileWeapon = ""; public readonly string MissileWeapon = "";
@@ -25,7 +25,14 @@ namespace OpenRA.Mods.RA
class NukePower : SupportPower 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) public override IOrderGenerator OrderGenerator(string order, SupportPowerManager manager)
{ {
Sound.PlayToPlayer(manager.self.Owner, Info.SelectTargetSound); Sound.PlayToPlayer(manager.self.Owner, Info.SelectTargetSound);
@@ -42,7 +49,7 @@ namespace OpenRA.Mods.RA
var rb = self.Trait<RenderSimple>(); var rb = self.Trait<RenderSimple>();
rb.PlayCustomAnim(self, "active"); rb.PlayCustomAnim(self, "active");
self.World.AddFrameEndTask(w => w.Add( 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)));
} }
} }
} }

View File

@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class ThrowsParticleInfo : ITraitInfo, Requires<RenderSimpleInfo> class ThrowsParticleInfo : ITraitInfo, Requires<RenderSimpleInfo>, Requires<IBodyOrientationInfo>
{ {
public readonly string Anim = null; public readonly string Anim = null;
@@ -54,6 +54,7 @@ namespace OpenRA.Mods.RA
var self = init.self; var self = init.self;
var rs = self.Trait<RenderSimple>(); var rs = self.Trait<RenderSimple>();
var body = self.Trait<IBodyOrientation>();
// TODO: Carry orientation over from the parent instead of just facing // TODO: Carry orientation over from the parent instead of just facing
var bodyFacing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : 0; 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 throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
var throwOffset = new WVec((int)(Game.CosmeticRandom.Gauss1D(1)*info.ThrowRange.Range), 0, 0).Rotate(throwRotation); 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; finalPos = initialPos + throwOffset;
// Facing rotation // Facing rotation

View File

@@ -33,6 +33,7 @@ namespace OpenRA.Mods.RA
public class Turreted : ITick, ISync, IResolveOrder public class Turreted : ITick, ISync, IResolveOrder
{ {
[Sync] public int QuantizedFacings = 0;
[Sync] public int turretFacing = 0; [Sync] public int turretFacing = 0;
public int? desiredFacing; public int? desiredFacing;
TurretedInfo info; TurretedInfo info;
@@ -83,16 +84,25 @@ namespace OpenRA.Mods.RA
// Turret offset in world-space // Turret offset in world-space
public WVec Position(Actor self) public WVec Position(Actor self)
{ {
var coords = self.Trait<ILocalCoordinatesModel>(); var body = self.Trait<IBodyOrientation>();
var bodyOrientation = coords.QuantizeOrientation(self, self.Orientation); var bodyOrientation = body.QuantizeOrientation(self, self.Orientation);
return coords.LocalToWorld(Offset.Rotate(bodyOrientation)); return body.LocalToWorld(Offset.Rotate(bodyOrientation));
} }
// Orientation in unit-space // Orientation in unit-space
public WRot LocalOrientation(Actor self) public WRot LocalOrientation(Actor self)
{ {
// Hack: turretFacing is relative to the world, so subtract the body yaw // 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));
} }
} }
} }

View File

@@ -445,3 +445,4 @@ VICE:
AttackWander: AttackWander:
RenderUnit: RenderUnit:
WithMuzzleFlash: WithMuzzleFlash:
BodyOrientation:

View File

@@ -33,6 +33,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^Tank: ^Tank:
AppearsOnRadar: AppearsOnRadar:
@@ -72,6 +73,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^Helicopter: ^Helicopter:
AppearsOnRadar: AppearsOnRadar:
@@ -97,6 +99,7 @@
Weapon: HeliExplode Weapon: HeliExplode
EmptyWeapon: HeliExplode EmptyWeapon: HeliExplode
DebugMuzzlePositions: DebugMuzzlePositions:
BodyOrientation:
^Infantry: ^Infantry:
AppearsOnRadar: AppearsOnRadar:
@@ -149,6 +152,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^CivInfantry: ^CivInfantry:
Inherits: ^Infantry Inherits: ^Infantry
@@ -197,6 +201,7 @@
DrawLineToTarget: DrawLineToTarget:
ActorLostNotification: ActorLostNotification:
DebugMuzzlePositions: DebugMuzzlePositions:
BodyOrientation:
^Ship: ^Ship:
AppearsOnRadar: AppearsOnRadar:
@@ -218,6 +223,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^Building: ^Building:
AppearsOnRadar: AppearsOnRadar:
@@ -266,6 +272,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guardable: Guardable:
Range: 3 Range: 3
BodyOrientation:
^CivBuilding: ^CivBuilding:
Inherits: ^Building Inherits: ^Building
@@ -296,6 +303,7 @@
RelativeToTopLeft: yes RelativeToTopLeft: yes
Tooltip: Tooltip:
Name: Civilian Building (Destroyed) Name: Civilian Building (Destroyed)
BodyOrientation:
^TechBuilding: ^TechBuilding:
Inherits: ^CivBuilding Inherits: ^CivBuilding
@@ -326,6 +334,7 @@
Tooltip: Tooltip:
Name: Field (Destroyed) Name: Field (Destroyed)
BelowUnits: BelowUnits:
BodyOrientation:
^Wall: ^Wall:
AppearsOnRadar: AppearsOnRadar:
@@ -354,6 +363,7 @@
AutoTargetIgnore: AutoTargetIgnore:
Sellable: Sellable:
Guardable: Guardable:
BodyOrientation:
^Tree: ^Tree:
Tooltip: Tooltip:
@@ -374,6 +384,7 @@
Armor: Armor:
Type: Wood Type: Wood
AutoTargetIgnore: AutoTargetIgnore:
BodyOrientation:
^Rock: ^Rock:
Tooltip: Tooltip:
@@ -388,6 +399,7 @@
Terrain: Tree Terrain: Tree
EditorAppearance: EditorAppearance:
RelativeToTopLeft: yes RelativeToTopLeft: yes
BodyOrientation:
^Husk: ^Husk:
Health: Health:
@@ -403,6 +415,7 @@
TransformOnCapture: TransformOnCapture:
ForceHealthPercentage: 25 ForceHealthPercentage: 25
BelowUnits: BelowUnits:
BodyOrientation:
# Capturable: # Capturable:
# Type: husk # Type: husk
# AllowAllies: true # AllowAllies: true
@@ -420,3 +433,4 @@
SoundOnDamageTransition: SoundOnDamageTransition:
DamagedSound: xplos.aud DamagedSound: xplos.aud
DestroyedSound: xplobig4.aud DestroyedSound: xplobig4.aud
BodyOrientation:

View File

@@ -351,11 +351,14 @@ CRATE:
Unit: mcv Unit: mcv
RenderSimple: RenderSimple:
BelowUnits: BelowUnits:
BodyOrientation:
mpspawn: mpspawn:
Waypoint: Waypoint:
RenderEditorOnly: RenderEditorOnly:
BodyOrientation:
waypoint: waypoint:
Waypoint: Waypoint:
RenderEditorOnly: RenderEditorOnly:
BodyOrientation:

View File

@@ -33,6 +33,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^Tank: ^Tank:
AppearsOnRadar: AppearsOnRadar:
@@ -69,6 +70,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^Husk: ^Husk:
Health: Health:
@@ -84,6 +86,7 @@
Types:Husk Types:Husk
Tooltip: Tooltip:
Name: Destroyed Tank Name: Destroyed Tank
BodyOrientation:
^TowerHusk: ^TowerHusk:
Health: Health:
@@ -101,6 +104,7 @@
Name: Destroyed Tower Name: Destroyed Tower
ProximityCaptor: ProximityCaptor:
Types:Husk Types:Husk
BodyOrientation:
^Infantry: ^Infantry:
AppearsOnRadar: AppearsOnRadar:
@@ -149,6 +153,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^Plane: ^Plane:
AppearsOnRadar: AppearsOnRadar:
@@ -168,6 +173,7 @@
Types:Plane Types:Plane
GivesBounty: GivesBounty:
DebugMuzzlePositions: DebugMuzzlePositions:
BodyOrientation:
^Helicopter: ^Helicopter:
Inherits: ^Plane Inherits: ^Plane
@@ -216,3 +222,4 @@
Bib: Bib:
Guardable: Guardable:
Range: 3 Range: 3
BodyOrientation:

View File

@@ -372,6 +372,7 @@ WALL:
Types:Wall Types:Wall
Sellable: Sellable:
Guardable: Guardable:
BodyOrientation:
GUNTOWER: GUNTOWER:
Inherits: ^Building Inherits: ^Building

View File

@@ -481,14 +481,17 @@ CRATE:
ProximityCaptor: ProximityCaptor:
Types:Crate Types:Crate
Passenger: Passenger:
BodyOrientation:
mpspawn: mpspawn:
Waypoint: Waypoint:
RenderEditorOnly: RenderEditorOnly:
BodyOrientation:
waypoint: waypoint:
Waypoint: Waypoint:
RenderEditorOnly: RenderEditorOnly:
BodyOrientation:
SPICEBLOOM: SPICEBLOOM:
RenderBuilding: RenderBuilding:
@@ -508,6 +511,7 @@ SPICEBLOOM:
Interval: 75 Interval: 75
RadarColorFromTerrain: RadarColorFromTerrain:
Terrain: Spice Terrain: Spice
BodyOrientation:
#SANDWORM: #SANDWORM:
# Buildable: # Buildable:

View File

@@ -36,6 +36,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^Tank: ^Tank:
AppearsOnRadar: AppearsOnRadar:
@@ -75,6 +76,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^Infantry: ^Infantry:
AppearsOnRadar: AppearsOnRadar:
@@ -126,6 +128,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^Ship: ^Ship:
AppearsOnRadar: AppearsOnRadar:
@@ -157,6 +160,7 @@
DebugMuzzlePositions: DebugMuzzlePositions:
Guard: Guard:
Guardable: Guardable:
BodyOrientation:
^Plane: ^Plane:
AppearsOnRadar: AppearsOnRadar:
@@ -183,6 +187,7 @@
String:Plane String:Plane
UpdatesPlayerStatistics: UpdatesPlayerStatistics:
DebugMuzzlePositions: DebugMuzzlePositions:
BodyOrientation:
^Helicopter: ^Helicopter:
Inherits: ^Plane Inherits: ^Plane
@@ -229,6 +234,7 @@
Guardable: Guardable:
Range: 3 Range: 3
AutoTargetIgnore: AutoTargetIgnore:
BodyOrientation:
^Wall: ^Wall:
AppearsOnRadar: AppearsOnRadar:
@@ -263,6 +269,7 @@
Sellable: Sellable:
UpdatesPlayerStatistics: UpdatesPlayerStatistics:
Guardable: Guardable:
BodyOrientation:
^TechBuilding: ^TechBuilding:
Inherits: ^Building Inherits: ^Building
@@ -344,6 +351,7 @@
Armor: Armor:
Type: Wood Type: Wood
AutoTargetIgnore: AutoTargetIgnore:
BodyOrientation:
^Husk: ^Husk:
Husk: Husk:
@@ -358,6 +366,7 @@
ProximityCaptor: ProximityCaptor:
Types:Husk Types:Husk
BelowUnits: BelowUnits:
BodyOrientation:
^Bridge: ^Bridge:
Tooltip: Tooltip:
@@ -373,6 +382,7 @@
ProximityCaptor: ProximityCaptor:
Types:Bridge Types:Bridge
AutoTargetIgnore: AutoTargetIgnore:
BodyOrientation:
#Temperate Terrain Expansion #Temperate Terrain Expansion
^SVBridge: ^SVBridge:
@@ -389,6 +399,7 @@
ProximityCaptor: ProximityCaptor:
Types:Bridge Types:Bridge
AutoTargetIgnore: AutoTargetIgnore:
BodyOrientation:
^SHBridge: ^SHBridge:
Tooltip: Tooltip:
@@ -404,6 +415,7 @@
ProximityCaptor: ProximityCaptor:
Types:Bridge Types:Bridge
AutoTargetIgnore: AutoTargetIgnore:
BodyOrientation:
^STDBridge: ^STDBridge:
Tooltip: Tooltip:
@@ -419,6 +431,7 @@
ProximityCaptor: ProximityCaptor:
Types:Bridge Types:Bridge
AutoTargetIgnore: AutoTargetIgnore:
BodyOrientation:
#Desert Terrain Expansion: #Desert Terrain Expansion:
^Rock: ^Rock:
@@ -437,6 +450,7 @@
UseTerrainPalette: true UseTerrainPalette: true
ProximityCaptor: ProximityCaptor:
Types:Tree Types:Tree
BodyOrientation:
^DesertCivBuilding: ^DesertCivBuilding:
Inherits: ^CivBuilding Inherits: ^CivBuilding

View File

@@ -670,6 +670,7 @@ MINP:
Types: Mine Types: Mine
TargetableUnit: TargetableUnit:
TargetTypes: Ground TargetTypes: Ground
BodyOrientation:
MINV: MINV:
Mine: Mine:
@@ -695,6 +696,7 @@ MINV:
Types: Mine Types: Mine
TargetableUnit: TargetableUnit:
TargetTypes: Ground TargetTypes: Ground
BodyOrientation:
CRATE: CRATE:
Tooltip: Tooltip:
@@ -757,6 +759,7 @@ CRATE:
ProximityCaptor: ProximityCaptor:
Types:Crate Types:Crate
Passenger: Passenger:
BodyOrientation:
CAMERA: CAMERA:
Aircraft: Aircraft:
@@ -766,6 +769,7 @@ CAMERA:
Range: 10 Range: 10
ProximityCaptor: ProximityCaptor:
Types:Camera Types:Camera
BodyOrientation:
FLARE: FLARE:
Aircraft: Aircraft:
@@ -780,6 +784,7 @@ FLARE:
Name: Flare Name: Flare
ProximityCaptor: ProximityCaptor:
Types: Flare Types: Flare
BodyOrientation:
powerproxy.parabombs: powerproxy.parabombs:
AirstrikePower: AirstrikePower:
@@ -805,7 +810,9 @@ powerproxy.sonarpulse:
mpspawn: mpspawn:
Waypoint: Waypoint:
RenderEditorOnly: RenderEditorOnly:
BodyOrientation:
waypoint: waypoint:
Waypoint: Waypoint:
RenderEditorOnly: RenderEditorOnly:
BodyOrientation: