Auto-detect offset coordinate type.

This commit is contained in:
Paul Chote
2013-03-29 15:57:48 +13:00
parent 0cff8b5b12
commit 79d51f0ce2
2 changed files with 26 additions and 4 deletions

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA
public readonly float LegacyRecoilRecovery = 0.2f;
public readonly int[] LegacyLocalOffset = { };
public readonly CoordinateModel OffsetModel = CoordinateModel.Legacy;
public CoordinateModel OffsetModel = CoordinateModel.Legacy;
[Desc("Muzzle position relative to turret or body. (forward, right, up) triples")]
public readonly WRange[] LocalOffset = {};
[Desc("Muzzle yaw relative to turret or body.")]
@@ -57,7 +57,14 @@ namespace OpenRA.Mods.RA
[Desc("Recoil recovery per-frame")]
public readonly WRange RecoilRecovery = new WRange(9);
public object Create(ActorInitializer init) { return new Armament(init.self, this); }
public object Create(ActorInitializer init)
{
// Auto-detect coordinate type
if (LocalOffset.Length > 0 && OffsetModel == CoordinateModel.Legacy)
OffsetModel = CoordinateModel.World;
return new Armament(init.self, this);
}
}
public class Armament : ITick

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.RA.Render;
using OpenRA.FileFormats;
using OpenRA.Traits;
@@ -25,11 +26,25 @@ namespace OpenRA.Mods.RA
public readonly int[] LegacyOffset = {0,0};
public readonly bool AlignWhenIdle = false;
public readonly CoordinateModel OffsetModel = CoordinateModel.Legacy;
public CoordinateModel OffsetModel = CoordinateModel.Legacy;
[Desc("Muzzle position relative to turret or body. (forward, right, up) triples")]
public readonly WVec Offset = WVec.Zero;
public virtual object Create(ActorInitializer init) { return new Turreted(init, this); }
bool HasWorldOffset(ArmamentInfo ai)
{
return ai.OffsetModel == CoordinateModel.World || ai.LocalOffset.Length > 0;
}
public virtual object Create(ActorInitializer init)
{
// Auto-detect coordinate type
var arms = init.self.Info.Traits.WithInterface<ArmamentInfo>();
if (Offset != WVec.Zero || arms.Any(ai => HasWorldOffset(ai)))
OffsetModel = CoordinateModel.World;
return new Turreted(init, this);
}
}
public class Turreted : ITick, ISync, IResolveOrder