Rewrite ActorInit queries.
This commit is contained in:
@@ -122,8 +122,9 @@ namespace OpenRA
|
|||||||
|
|
||||||
World = world;
|
World = world;
|
||||||
ActorID = world.NextAID();
|
ActorID = world.NextAID();
|
||||||
if (initDict.Contains<OwnerInit>())
|
var ownerInit = init.GetOrDefault<OwnerInit>(null);
|
||||||
Owner = init.Get<OwnerInit, Player>();
|
if (ownerInit != null)
|
||||||
|
Owner = ownerInit.Value(world);
|
||||||
|
|
||||||
if (name != null)
|
if (name != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,17 +9,21 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
public interface IActorInitializer
|
public interface IActorInitializer
|
||||||
{
|
{
|
||||||
World World { get; }
|
World World { get; }
|
||||||
T Get<T>() where T : IActorInit;
|
T GetOrDefault<T>(TraitInfo info) where T : IActorInit;
|
||||||
U Get<T, U>() where T : IActorInit<U>;
|
T Get<T>(TraitInfo info) where T : IActorInit;
|
||||||
bool Contains<T>() where T : IActorInit;
|
U GetValue<T, U>(TraitInfo info) where T : IActorInit<U>;
|
||||||
|
U GetValue<T, U>(TraitInfo info, U fallback) where T : IActorInit<U>;
|
||||||
|
bool Contains<T>(TraitInfo info) where T : IActorInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ActorInitializer : IActorInitializer
|
public class ActorInitializer : IActorInitializer
|
||||||
@@ -35,16 +39,39 @@ namespace OpenRA
|
|||||||
Dict = dict;
|
Dict = dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get<T>() where T : IActorInit { return Dict.Get<T>(); }
|
public T GetOrDefault<T>(TraitInfo info) where T : IActorInit
|
||||||
public U Get<T, U>() where T : IActorInit<U> { return Dict.Get<T>().Value(World); }
|
{
|
||||||
public bool Contains<T>() where T : IActorInit { return Dict.Contains<T>(); }
|
return Dict.GetOrDefault<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Get<T>(TraitInfo info) where T : IActorInit
|
||||||
|
{
|
||||||
|
var init = GetOrDefault<T>(info);
|
||||||
|
if (init == null)
|
||||||
|
throw new InvalidOperationException("TypeDictionary does not contain instance of type `{0}`".F(typeof(T)));
|
||||||
|
|
||||||
|
return init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public U GetValue<T, U>(TraitInfo info) where T : IActorInit<U>
|
||||||
|
{
|
||||||
|
return Get<T>(info).Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public U GetValue<T, U>(TraitInfo info, U fallback) where T : IActorInit<U>
|
||||||
|
{
|
||||||
|
var init = GetOrDefault<T>(info);
|
||||||
|
return init != null ? init.Value : fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Contains<T>(TraitInfo info) where T : IActorInit { return GetOrDefault<T>(info) != null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IActorInit { }
|
public interface IActorInit { }
|
||||||
|
|
||||||
public interface IActorInit<T> : IActorInit
|
public interface IActorInit<T> : IActorInit
|
||||||
{
|
{
|
||||||
T Value(World world);
|
T Value { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LocationInit : IActorInit<CPos>
|
public class LocationInit : IActorInit<CPos>
|
||||||
@@ -54,23 +81,23 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LocationInit() { }
|
public LocationInit() { }
|
||||||
public LocationInit(CPos init) { value = init; }
|
public LocationInit(CPos init) { value = init; }
|
||||||
public CPos Value(World world) { return value; }
|
public CPos Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class OwnerInit : IActorInit<Player>
|
public class OwnerInit : IActorInit
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey]
|
[FieldFromYamlKey]
|
||||||
public readonly string PlayerName = "Neutral";
|
public readonly string InternalName = "Neutral";
|
||||||
|
|
||||||
Player player;
|
Player player;
|
||||||
|
|
||||||
public OwnerInit() { }
|
public OwnerInit() { }
|
||||||
public OwnerInit(string playerName) { PlayerName = playerName; }
|
public OwnerInit(string playerName) { InternalName = playerName; }
|
||||||
|
|
||||||
public OwnerInit(Player player)
|
public OwnerInit(Player player)
|
||||||
{
|
{
|
||||||
this.player = player;
|
this.player = player;
|
||||||
PlayerName = player.InternalName;
|
InternalName = player.InternalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player Value(World world)
|
public Player Value(World world)
|
||||||
@@ -78,7 +105,7 @@ namespace OpenRA
|
|||||||
if (player != null)
|
if (player != null)
|
||||||
return player;
|
return player;
|
||||||
|
|
||||||
return world.Players.First(x => x.InternalName == PlayerName);
|
return world.Players.First(x => x.InternalName == InternalName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -276,7 +276,7 @@ namespace OpenRA
|
|||||||
foreach (var kv in actorDefinitions.Nodes.Where(d => d.Value.Value == "mpspawn"))
|
foreach (var kv in actorDefinitions.Nodes.Where(d => d.Value.Value == "mpspawn"))
|
||||||
{
|
{
|
||||||
var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
||||||
spawns.Add(s.InitDict.Get<LocationInit>().Value(null));
|
spawns.Add(s.InitDict.Get<LocationInit>().Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
newData.SpawnPoints = spawns.ToArray();
|
newData.SpawnPoints = spawns.ToArray();
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
turret = turrets.FirstOrDefault();
|
turret = turrets.FirstOrDefault();
|
||||||
wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
|
wsb = init.Self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
|
||||||
skippedMakeAnimation = init.Contains<SkipMakeAnimsInit>();
|
skippedMakeAnimation = init.Contains<SkipMakeAnimsInit>(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using OpenRA.Mods.Cnc.Activities;
|
using OpenRA.Mods.Cnc.Activities;
|
||||||
using OpenRA.Mods.Common.Activities;
|
using OpenRA.Mods.Common.Activities;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
@@ -58,18 +59,14 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
|
ReturnTicks = init.GetValue<ChronoshiftReturnInit, int>(info, 0);
|
||||||
|
duration = init.GetValue<ChronoshiftDurationInit, int>(info, 0);
|
||||||
|
Origin = init.GetValue<ChronoshiftOriginInit, CPos>(info, CPos.Zero);
|
||||||
|
|
||||||
if (init.Contains<ChronoshiftReturnInit>())
|
// Defer to the end of tick as the lazy value may reference an actor that hasn't been created yet
|
||||||
ReturnTicks = init.Get<ChronoshiftReturnInit, int>();
|
var chronosphereInit = init.GetOrDefault<ChronoshiftChronosphereInit>(info);
|
||||||
|
if (chronosphereInit != null)
|
||||||
if (init.Contains<ChronoshiftDurationInit>())
|
init.World.AddFrameEndTask(w => chronosphere = chronosphereInit.Value(init.World).Value);
|
||||||
duration = init.Get<ChronoshiftDurationInit, int>();
|
|
||||||
|
|
||||||
if (init.Contains<ChronoshiftOriginInit>())
|
|
||||||
Origin = init.Get<ChronoshiftOriginInit, CPos>();
|
|
||||||
|
|
||||||
if (init.Contains<ChronoshiftChronosphereInit>())
|
|
||||||
chronosphere = init.Get<ChronoshiftChronosphereInit, Actor>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ITick.Tick(Actor self)
|
void ITick.Tick(Actor self)
|
||||||
@@ -186,7 +183,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
public ChronoshiftReturnInit() { }
|
public ChronoshiftReturnInit() { }
|
||||||
public ChronoshiftReturnInit(int init) { value = init; }
|
public ChronoshiftReturnInit(int init) { value = init; }
|
||||||
public int Value(World world) { return value; }
|
public int Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ChronoshiftDurationInit : IActorInit<int>
|
public class ChronoshiftDurationInit : IActorInit<int>
|
||||||
@@ -196,7 +193,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
public ChronoshiftDurationInit() { }
|
public ChronoshiftDurationInit() { }
|
||||||
public ChronoshiftDurationInit(int init) { value = init; }
|
public ChronoshiftDurationInit(int init) { value = init; }
|
||||||
public int Value(World world) { return value; }
|
public int Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ChronoshiftOriginInit : IActorInit<CPos>
|
public class ChronoshiftOriginInit : IActorInit<CPos>
|
||||||
@@ -205,13 +202,14 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
readonly CPos value;
|
readonly CPos value;
|
||||||
|
|
||||||
public ChronoshiftOriginInit(CPos init) { value = init; }
|
public ChronoshiftOriginInit(CPos init) { value = init; }
|
||||||
public CPos Value(World world) { return value; }
|
public CPos Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ChronoshiftChronosphereInit : IActorInit<Actor>
|
public class ChronoshiftChronosphereInit : IActorInit
|
||||||
{
|
{
|
||||||
readonly Actor value;
|
readonly Actor value;
|
||||||
public ChronoshiftChronosphereInit(Actor init) { value = init; }
|
public ChronoshiftChronosphereInit(Actor init) { value = init; }
|
||||||
public Actor Value(World world) { return value; }
|
|
||||||
|
public Lazy<Actor> Value(World world) { return new Lazy<Actor>(() => value); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Mods.Common;
|
using OpenRA.Mods.Common;
|
||||||
@@ -94,19 +95,15 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
health = self.Trait<Health>();
|
health = self.Trait<Health>();
|
||||||
|
|
||||||
wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
|
wsb = self.TraitsImplementing<WithSpriteBody>().Single(w => w.Info.Name == info.Body);
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
|
faction = init.GetValue<FactionInit, string>(info, self.Owner.Faction.InternalName);
|
||||||
|
returnTicks = init.GetValue<ChronoshiftReturnInit, int>(info, 0);
|
||||||
|
duration = init.GetValue<ChronoshiftDurationInit, int>(info, 0);
|
||||||
|
origin = init.GetValue<ChronoshiftOriginInit, CPos>(info, CPos.Zero);
|
||||||
|
|
||||||
if (init.Contains<ChronoshiftReturnInit>())
|
// Defer to the end of tick as the lazy value may reference an actor that hasn't been created yet
|
||||||
returnTicks = init.Get<ChronoshiftReturnInit, int>();
|
var chronosphereInit = init.GetOrDefault<ChronoshiftChronosphereInit>(info);
|
||||||
|
if (chronosphereInit != null)
|
||||||
if (init.Contains<ChronoshiftDurationInit>())
|
init.World.AddFrameEndTask(w => chronosphere = chronosphereInit.Value(init.World).Value);
|
||||||
duration = init.Get<ChronoshiftDurationInit, int>();
|
|
||||||
|
|
||||||
if (init.Contains<ChronoshiftOriginInit>())
|
|
||||||
origin = init.Get<ChronoshiftOriginInit, CPos>();
|
|
||||||
|
|
||||||
if (init.Contains<ChronoshiftChronosphereInit>())
|
|
||||||
chronosphere = init.Get<ChronoshiftChronosphereInit, Actor>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<VariableObserver> IObservesVariables.GetVariableObservers()
|
IEnumerable<VariableObserver> IObservesVariables.GetVariableObservers()
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
public InfiltrateForTransform(ActorInitializer init, InfiltrateForTransformInfo info)
|
public InfiltrateForTransform(ActorInitializer init, InfiltrateForTransformInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
faction = init.GetValue<FactionInit, string>(info, init.Self.Owner.Faction.InternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator, BitSet<TargetableType> types)
|
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator, BitSet<TargetableType> types)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
|
||||||
{
|
{
|
||||||
if (init.Contains<HideBibPreviewInit>() && init.Get<HideBibPreviewInit, bool>())
|
if (init.Contains<HideBibPreviewInit>(this))
|
||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
if (Palette != null)
|
if (Palette != null)
|
||||||
@@ -45,10 +45,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
var bibOffset = bi.Dimensions.Y - rows;
|
var bibOffset = bi.Dimensions.Y - rows;
|
||||||
var centerOffset = bi.CenterOffset(init.World);
|
var centerOffset = bi.CenterOffset(init.World);
|
||||||
var map = init.World.Map;
|
var map = init.World.Map;
|
||||||
var location = CPos.Zero;
|
var location = init.GetValue<LocationInit, CPos>(this, CPos.Zero);
|
||||||
|
|
||||||
if (init.Contains<LocationInit>())
|
|
||||||
location = init.Get<LocationInit, CPos>();
|
|
||||||
|
|
||||||
for (var i = 0; i < rows * width; i++)
|
for (var i = 0; i < rows * width; i++)
|
||||||
{
|
{
|
||||||
@@ -136,13 +133,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HideBibPreviewInit : IActorInit<bool>, ISuppressInitExport
|
class HideBibPreviewInit : IActorInit, ISuppressInitExport
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey]
|
|
||||||
readonly bool value = true;
|
|
||||||
|
|
||||||
public HideBibPreviewInit() { }
|
public HideBibPreviewInit() { }
|
||||||
public HideBibPreviewInit(bool init) { value = init; }
|
|
||||||
public bool Value(World world) { return value; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
|||||||
var wsb = init.Actor.TraitInfos<WithSpriteBodyInfo>().FirstOrDefault();
|
var wsb = init.Actor.TraitInfos<WithSpriteBodyInfo>().FirstOrDefault();
|
||||||
|
|
||||||
// Show the correct turret facing
|
// Show the correct turret facing
|
||||||
var facing = WAngle.FromFacing(init.Contains<TurretFacingInit>() ? init.Get<TurretFacingInit>().Value(init.World) : t.InitialFacing);
|
var facing = WAngle.FromFacing(init.GetValue<TurretFacingInit, int>(this, t.InitialFacing));
|
||||||
|
|
||||||
var anim = new Animation(init.World, image, () => facing);
|
var anim = new Animation(init.World, image, () => facing);
|
||||||
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), wsb.Sequence));
|
anim.PlayRepeating(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), wsb.Sequence));
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
|||||||
{
|
{
|
||||||
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
|
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
|
||||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||||
var frame = init.Contains<BodyAnimationFrameInit>() ? init.Get<BodyAnimationFrameInit, uint>() : 0;
|
var frame = init.GetValue<BodyAnimationFrameInit, uint>(this, 0);
|
||||||
|
|
||||||
yield return new ModelAnimation(model, () => WVec.Zero,
|
yield return new ModelAnimation(model, () => WVec.Zero,
|
||||||
() => new[] { body.QuantizeOrientation(orientation(), facings) },
|
() => new[] { body.QuantizeOrientation(orientation(), facings) },
|
||||||
@@ -102,6 +102,6 @@ namespace OpenRA.Mods.Cnc.Traits.Render
|
|||||||
|
|
||||||
public BodyAnimationFrameInit() { }
|
public BodyAnimationFrameInit() { }
|
||||||
public BodyAnimationFrameInit(uint init) { value = init; }
|
public BodyAnimationFrameInit(uint init) { value = init; }
|
||||||
public uint Value(World world) { return value; }
|
public uint Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,13 +80,15 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
Info = info;
|
Info = info;
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
|
|
||||||
if (init.Contains<LocationInit>())
|
var locationInit = init.GetOrDefault<LocationInit>(info);
|
||||||
SetPosition(self, init.Get<LocationInit, CPos>());
|
if (locationInit != null)
|
||||||
|
SetPosition(self, locationInit.Value);
|
||||||
|
|
||||||
if (init.Contains<CenterPositionInit>())
|
var centerPositionInit = init.GetOrDefault<CenterPositionInit>(info);
|
||||||
SetPosition(self, init.Get<CenterPositionInit, WPos>());
|
if (centerPositionInit != null)
|
||||||
|
SetPosition(self, centerPositionInit.Value);
|
||||||
|
|
||||||
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : Info.GetInitialFacing();
|
Facing = init.GetValue<FacingInit, int>(info, Info.GetInitialFacing());
|
||||||
|
|
||||||
// Prevent mappers from setting bogus facings
|
// Prevent mappers from setting bogus facings
|
||||||
if (Facing != 64 && Facing != 192)
|
if (Facing != 64 && Facing != 192)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common
|
|||||||
|
|
||||||
public FacingInit() { }
|
public FacingInit() { }
|
||||||
public FacingInit(int init) { value = init; }
|
public FacingInit(int init) { value = init; }
|
||||||
public int Value(World world) { return value; }
|
public int Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CreationActivityDelayInit : IActorInit<int>
|
public class CreationActivityDelayInit : IActorInit<int>
|
||||||
@@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common
|
|||||||
|
|
||||||
public CreationActivityDelayInit() { }
|
public CreationActivityDelayInit() { }
|
||||||
public CreationActivityDelayInit(int init) { value = init; }
|
public CreationActivityDelayInit(int init) { value = init; }
|
||||||
public int Value(World world) { return value; }
|
public int Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DynamicFacingInit : IActorInit<Func<int>>
|
public class DynamicFacingInit : IActorInit<Func<int>>
|
||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common
|
|||||||
readonly Func<int> func;
|
readonly Func<int> func;
|
||||||
|
|
||||||
public DynamicFacingInit(Func<int> func) { this.func = func; }
|
public DynamicFacingInit(Func<int> func) { this.func = func; }
|
||||||
public Func<int> Value(World world) { return func; }
|
public Func<int> Value { get { return func; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SubCellInit : IActorInit<SubCell>
|
public class SubCellInit : IActorInit<SubCell>
|
||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common
|
|||||||
public SubCellInit() { }
|
public SubCellInit() { }
|
||||||
public SubCellInit(byte init) { value = init; }
|
public SubCellInit(byte init) { value = init; }
|
||||||
public SubCellInit(SubCell init) { value = (byte)init; }
|
public SubCellInit(SubCell init) { value = (byte)init; }
|
||||||
public SubCell Value(World world) { return (SubCell)value; }
|
public SubCell Value { get { return (SubCell)value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CenterPositionInit : IActorInit<WPos>
|
public class CenterPositionInit : IActorInit<WPos>
|
||||||
@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common
|
|||||||
|
|
||||||
public CenterPositionInit() { }
|
public CenterPositionInit() { }
|
||||||
public CenterPositionInit(WPos init) { value = init; }
|
public CenterPositionInit(WPos init) { value = init; }
|
||||||
public WPos Value(World world) { return value; }
|
public WPos Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows maps / transformations to specify the faction variant of an actor.
|
// Allows maps / transformations to specify the faction variant of an actor.
|
||||||
@@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common
|
|||||||
|
|
||||||
public FactionInit() { }
|
public FactionInit() { }
|
||||||
public FactionInit(string faction) { Faction = faction; }
|
public FactionInit(string faction) { Faction = faction; }
|
||||||
public string Value(World world) { return Faction; }
|
public string Value { get { return Faction; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class EffectiveOwnerInit : IActorInit<Player>
|
public class EffectiveOwnerInit : IActorInit<Player>
|
||||||
@@ -81,6 +81,6 @@ namespace OpenRA.Mods.Common
|
|||||||
|
|
||||||
public EffectiveOwnerInit() { }
|
public EffectiveOwnerInit() { }
|
||||||
public EffectiveOwnerInit(Player owner) { value = owner; }
|
public EffectiveOwnerInit(Player owner) { value = owner; }
|
||||||
Player IActorInit<Player>.Value(World world) { return value; }
|
public Player Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
var location = copy.InitDict.Get<LocationInit>();
|
var location = copy.InitDict.Get<LocationInit>();
|
||||||
copy.InitDict.Remove(location);
|
copy.InitDict.Remove(location);
|
||||||
copy.InitDict.Add(new LocationInit(location.Value(worldRenderer.World) + offset));
|
copy.InitDict.Add(new LocationInit(location.Value + offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
previews.Add(preview.ID, copy);
|
previews.Add(preview.ID, copy);
|
||||||
|
|||||||
@@ -41,9 +41,32 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
this.dict = dict;
|
this.dict = dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get<T>() where T : IActorInit { return dict.Get<T>(); }
|
public T GetOrDefault<T>(TraitInfo info) where T : IActorInit
|
||||||
public U Get<T, U>() where T : IActorInit<U> { return dict.Get<T>().Value(World); }
|
{
|
||||||
public bool Contains<T>() where T : IActorInit { return dict.Contains<T>(); }
|
return dict.GetOrDefault<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T Get<T>(TraitInfo info) where T : IActorInit
|
||||||
|
{
|
||||||
|
var init = GetOrDefault<T>(info);
|
||||||
|
if (init == null)
|
||||||
|
throw new InvalidOperationException("TypeDictionary does not contain instance of type `{0}`".F(typeof(T)));
|
||||||
|
|
||||||
|
return init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public U GetValue<T, U>(TraitInfo info) where T : IActorInit<U>
|
||||||
|
{
|
||||||
|
return Get<T>(info).Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public U GetValue<T, U>(TraitInfo info, U fallback) where T : IActorInit<U>
|
||||||
|
{
|
||||||
|
var init = GetOrDefault<T>(info);
|
||||||
|
return init != null ? init.Value : fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Contains<T>(TraitInfo info) where T : IActorInit { return GetOrDefault<T>(info) != null; }
|
||||||
|
|
||||||
public Func<WRot> GetOrientation()
|
public Func<WRot> GetOrientation()
|
||||||
{
|
{
|
||||||
@@ -56,13 +79,13 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
if (dynamicInit != null)
|
if (dynamicInit != null)
|
||||||
{
|
{
|
||||||
// TODO: Account for terrain slope
|
// TODO: Account for terrain slope
|
||||||
var getFacing = dynamicInit.Value(null);
|
var getFacing = dynamicInit.Value;
|
||||||
return () => WRot.FromFacing(getFacing());
|
return () => WRot.FromFacing(getFacing());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to initial actor facing if an Init isn't available
|
// Fall back to initial actor facing if an Init isn't available
|
||||||
var facingInit = dict.GetOrDefault<FacingInit>();
|
var facingInit = dict.GetOrDefault<FacingInit>();
|
||||||
var facing = facingInit != null ? facingInit.Value(null) : facingInfo.GetInitialFacing();
|
var facing = facingInit != null ? facingInit.Value : facingInfo.GetInitialFacing();
|
||||||
var orientation = WRot.FromFacing(facing);
|
var orientation = WRot.FromFacing(facing);
|
||||||
return () => orientation;
|
return () => orientation;
|
||||||
}
|
}
|
||||||
@@ -77,13 +100,13 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
var dynamicInit = dict.GetOrDefault<DynamicFacingInit>();
|
var dynamicInit = dict.GetOrDefault<DynamicFacingInit>();
|
||||||
if (dynamicInit != null)
|
if (dynamicInit != null)
|
||||||
{
|
{
|
||||||
var getFacing = dynamicInit.Value(null);
|
var getFacing = dynamicInit.Value;
|
||||||
return () => WAngle.FromFacing(getFacing());
|
return () => WAngle.FromFacing(getFacing());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to initial actor facing if an Init isn't available
|
// Fall back to initial actor facing if an Init isn't available
|
||||||
var facingInit = dict.GetOrDefault<FacingInit>();
|
var facingInit = dict.GetOrDefault<FacingInit>();
|
||||||
var facing = WAngle.FromFacing(facingInit != null ? facingInit.Value(null) : facingInfo.GetInitialFacing());
|
var facing = WAngle.FromFacing(facingInit != null ? facingInit.Value : facingInfo.GetInitialFacing());
|
||||||
return () => facing;
|
return () => facing;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +117,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
if (health == null)
|
if (health == null)
|
||||||
return DamageState.Undamaged;
|
return DamageState.Undamaged;
|
||||||
|
|
||||||
var hf = health.Value(null);
|
var hf = health.Value;
|
||||||
|
|
||||||
if (hf <= 0)
|
if (hf <= 0)
|
||||||
return DamageState.Dead;
|
return DamageState.Dead;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
foreach (var kv in map.ActorDefinitions.Where(d => d.Value.Value == "mpspawn"))
|
foreach (var kv in map.ActorDefinitions.Where(d => d.Value.Value == "mpspawn"))
|
||||||
{
|
{
|
||||||
var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
||||||
spawns.Add(s.InitDict.Get<LocationInit>().Value(null));
|
spawns.Add(s.InitDict.Get<LocationInit>().Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerCount > spawns.Count)
|
if (playerCount > spawns.Count)
|
||||||
@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
emitError("Actor {0} is not owned by any player.".F(kv.Key));
|
emitError("Actor {0} is not owned by any player.".F(kv.Key));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var ownerName = ownerInit.PlayerName;
|
var ownerName = ownerInit.InternalName;
|
||||||
if (!playerNames.Contains(ownerName))
|
if (!playerNames.Contains(ownerName))
|
||||||
emitError("Actor {0} is owned by unknown player {1}.".F(kv.Key, ownerName));
|
emitError("Actor {0} is owned by unknown player {1}.".F(kv.Key, ownerName));
|
||||||
|
|
||||||
|
|||||||
@@ -41,11 +41,18 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
if (initType == null)
|
if (initType == null)
|
||||||
throw new LuaException("Unknown initializer type '{0}'".F(typeName));
|
throw new LuaException("Unknown initializer type '{0}'".F(typeName));
|
||||||
|
|
||||||
// Cast it up to an IActorInit<T>
|
// HACK: Handle OwnerInit as a special case until ActorInit creation can be rewritten
|
||||||
var genericType = initType.GetInterfaces()
|
Type innerType, valueType;
|
||||||
.First(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IActorInit<>));
|
if (initType != typeof(OwnerInit))
|
||||||
var innerType = genericType.GetGenericArguments().First();
|
{
|
||||||
var valueType = innerType.IsEnum ? Enum.GetUnderlyingType(innerType) : innerType;
|
// Cast it up to an IActorInit<T>
|
||||||
|
var genericType = initType.GetInterfaces()
|
||||||
|
.First(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IActorInit<>));
|
||||||
|
innerType = genericType.GetGenericArguments().First();
|
||||||
|
valueType = innerType.IsEnum ? Enum.GetUnderlyingType(innerType) : innerType;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
innerType = valueType = typeof(Player);
|
||||||
|
|
||||||
// Try and coerce the table value to the required type
|
// Try and coerce the table value to the required type
|
||||||
object value;
|
object value;
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
actor =>
|
actor =>
|
||||||
{
|
{
|
||||||
var init = actor.Init<FacingInit>();
|
var init = actor.Init<FacingInit>();
|
||||||
return init != null ? init.Value(world) : InitialFacing;
|
return init != null ? init.Value : InitialFacing;
|
||||||
},
|
},
|
||||||
(actor, value) => actor.ReplaceInit(new FacingInit((int)value)));
|
(actor, value) => actor.ReplaceInit(new FacingInit((int)value)));
|
||||||
}
|
}
|
||||||
@@ -241,16 +241,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
|
|
||||||
if (init.Contains<LocationInit>())
|
var locationInit = init.GetOrDefault<LocationInit>(info);
|
||||||
SetPosition(self, init.Get<LocationInit, CPos>());
|
if (locationInit != null)
|
||||||
|
SetPosition(self, locationInit.Value);
|
||||||
|
|
||||||
if (init.Contains<CenterPositionInit>())
|
var centerPositionInit = init.GetOrDefault<CenterPositionInit>(info);
|
||||||
SetPosition(self, init.Get<CenterPositionInit, WPos>());
|
if (centerPositionInit != null)
|
||||||
|
SetPosition(self, centerPositionInit.Value);
|
||||||
|
|
||||||
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : Info.InitialFacing;
|
Facing = init.GetValue<FacingInit, int>(info, Info.InitialFacing);
|
||||||
|
creationActivityDelay = init.GetValue<CreationActivityDelayInit, int>(info, 0);
|
||||||
if (init.Contains<CreationActivityDelayInit>())
|
|
||||||
creationActivityDelay = init.Get<CreationActivityDelayInit, int>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public WDist LandAltitude
|
public WDist LandAltitude
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public FallsToEarth(ActorInitializer init, FallsToEarthInfo info)
|
public FallsToEarth(ActorInitializer init, FallsToEarthInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
effectiveOwner = init.Contains<EffectiveOwnerInit>() ? init.Get<EffectiveOwnerInit, Player>() : init.Self.Owner;
|
effectiveOwner = init.GetValue<EffectiveOwnerInit, Player>(info, init.Self.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We return init.Self.Owner if there's no effective owner
|
// We return init.Self.Owner if there's no effective owner
|
||||||
|
|||||||
@@ -42,14 +42,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var owner = map.PlayerDefinitions.Where(p => s.InitDict.Get<OwnerInit>().PlayerName == p.Value.Nodes.First(k => k.Key == "Name").Value.Value).First();
|
var owner = map.PlayerDefinitions.Single(p => s.InitDict.Get<OwnerInit>().InternalName == p.Value.Nodes.Last(k => k.Key == "Name").Value.Value);
|
||||||
var colorValue = owner.Value.Nodes.Where(n => n.Key == "Color");
|
var colorValue = owner.Value.Nodes.Where(n => n.Key == "Color");
|
||||||
var ownerColor = colorValue.Any() ? colorValue.First().Value.Value : "FFFFFF";
|
var ownerColor = colorValue.Any() ? colorValue.First().Value.Value : "FFFFFF";
|
||||||
Color.TryParse(ownerColor, out color);
|
Color.TryParse(ownerColor, out color);
|
||||||
}
|
}
|
||||||
|
|
||||||
var ios = ai.TraitInfo<IOccupySpaceInfo>();
|
var ios = ai.TraitInfo<IOccupySpaceInfo>();
|
||||||
var cells = ios.OccupiedCells(ai, s.InitDict.Get<LocationInit>().Value(null));
|
var cells = ios.OccupiedCells(ai, s.InitDict.Get<LocationInit>().Value);
|
||||||
foreach (var cell in cells)
|
foreach (var cell in cells)
|
||||||
destinationBuffer.Add(new Pair<MPos, Color>(cell.Key.ToMPos(map), color));
|
destinationBuffer.Add(new Pair<MPos, Color>(cell.Key.ToMPos(map), color));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
actor =>
|
actor =>
|
||||||
{
|
{
|
||||||
var init = actor.Init<StanceInit>();
|
var init = actor.Init<StanceInit>();
|
||||||
var stance = init != null ? init.Value(world) : InitialStance;
|
var stance = init != null ? init.Value : InitialStance;
|
||||||
return stances[(int)stance];
|
return stances[(int)stance];
|
||||||
},
|
},
|
||||||
(actor, value) => actor.ReplaceInit(new StanceInit((UnitStance)stances.IndexOf(value))));
|
(actor, value) => actor.ReplaceInit(new StanceInit((UnitStance)stances.IndexOf(value))));
|
||||||
@@ -183,10 +183,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var self = init.Self;
|
var self = init.Self;
|
||||||
ActiveAttackBases = self.TraitsImplementing<AttackBase>().ToArray().Where(Exts.IsTraitEnabled);
|
ActiveAttackBases = self.TraitsImplementing<AttackBase>().ToArray().Where(Exts.IsTraitEnabled);
|
||||||
|
|
||||||
if (init.Contains<StanceInit>())
|
stance = init.GetValue<StanceInit, UnitStance>(info, self.Owner.IsBot || !self.Owner.Playable ? info.InitialStanceAI : info.InitialStance);
|
||||||
stance = init.Get<StanceInit, UnitStance>();
|
|
||||||
else
|
|
||||||
stance = self.Owner.IsBot || !self.Owner.Playable ? info.InitialStanceAI : info.InitialStance;
|
|
||||||
|
|
||||||
PredictedStance = stance;
|
PredictedStance = stance;
|
||||||
|
|
||||||
@@ -455,6 +452,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public StanceInit() { }
|
public StanceInit() { }
|
||||||
public StanceInit(UnitStance init) { value = init; }
|
public StanceInit(UnitStance init) { value = init; }
|
||||||
public UnitStance Value(World world) { return value; }
|
public UnitStance Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
var self = init.Self;
|
var self = init.Self;
|
||||||
var faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
|
var faction = init.GetValue<FactionInit, string>(info, self.Owner.Faction.InternalName);
|
||||||
|
|
||||||
quantizedFacings = Exts.Lazy(() =>
|
quantizedFacings = Exts.Lazy(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.OverridePalette))
|
if (!string.IsNullOrEmpty(info.OverridePalette))
|
||||||
{
|
{
|
||||||
var owner = init.Get<OwnerInit>().Value(wr.World);
|
var ownerName = init.Get<OwnerInit>().InternalName;
|
||||||
palette = wr.Palette(info.OverridePaletteIsPlayerPalette ? info.OverridePalette + owner.InternalName : info.OverridePalette);
|
palette = wr.Palette(info.OverridePaletteIsPlayerPalette ? info.OverridePalette + ownerName : info.OverridePalette);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public Building(ActorInitializer init, BuildingInfo info)
|
public Building(ActorInitializer init, BuildingInfo info)
|
||||||
{
|
{
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
topLeft = init.Get<LocationInit, CPos>();
|
topLeft = init.GetValue<LocationInit, CPos>(info);
|
||||||
Info = info;
|
Info = info;
|
||||||
influence = self.World.WorldActor.Trait<BuildingInfluence>();
|
influence = self.World.WorldActor.Trait<BuildingInfluence>();
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -43,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
var init = actor.Init<FreeActorInit>();
|
var init = actor.Init<FreeActorInit>();
|
||||||
if (init != null)
|
if (init != null)
|
||||||
return init.Value(world);
|
return init.Value;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@@ -63,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public FreeActor(ActorInitializer init, FreeActorInfo info)
|
public FreeActor(ActorInitializer init, FreeActorInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
allowSpawn = !init.Contains<FreeActorInit>() || init.Get<FreeActorInit>().ActorValue;
|
allowSpawn = init.GetValue<FreeActorInit, bool>(info, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void TraitEnabled(Actor self)
|
protected override void TraitEnabled(Actor self)
|
||||||
@@ -92,13 +93,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly bool ActorValue = true;
|
public readonly bool ActorValue = true;
|
||||||
public FreeActorInit() { }
|
public FreeActorInit() { }
|
||||||
public FreeActorInit(bool init) { ActorValue = init; }
|
public FreeActorInit(bool init) { ActorValue = init; }
|
||||||
public bool Value(World world) { return ActorValue; }
|
public bool Value { get { return ActorValue; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ParentActorInit : IActorInit<Actor>
|
public class ParentActorInit : IActorInit
|
||||||
{
|
{
|
||||||
public readonly Actor ActorValue;
|
readonly Actor value;
|
||||||
public ParentActorInit(Actor parent) { ActorValue = parent; }
|
public ParentActorInit(Actor init) { value = init; }
|
||||||
public Actor Value(World world) { return ActorValue; }
|
|
||||||
|
public Lazy<Actor> Value(World world) { return new Lazy<Actor>(() => value); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,22 +20,26 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
public bool IsValidTarget(ActorInfo actorInfo, Actor saboteur) { return false; } // TODO: bridges don't support frozen under fog
|
public bool IsValidTarget(ActorInfo actorInfo, Actor saboteur) { return false; } // TODO: bridges don't support frozen under fog
|
||||||
|
|
||||||
public override object Create(ActorInitializer init) { return new LegacyBridgeHut(init); }
|
public override object Create(ActorInitializer init) { return new LegacyBridgeHut(init, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class LegacyBridgeHut : IDemolishable
|
class LegacyBridgeHut : IDemolishable
|
||||||
{
|
{
|
||||||
public readonly Bridge FirstBridge;
|
public Bridge FirstBridge { get; private set; }
|
||||||
public readonly Bridge Bridge;
|
public Bridge Bridge { get; private set; }
|
||||||
public DamageState BridgeDamageState { get { return Bridge.AggregateDamageState(); } }
|
public DamageState BridgeDamageState { get { return Bridge.AggregateDamageState(); } }
|
||||||
public bool Repairing { get { return repairDirections > 0; } }
|
public bool Repairing { get { return repairDirections > 0; } }
|
||||||
int repairDirections = 0;
|
int repairDirections = 0;
|
||||||
|
|
||||||
public LegacyBridgeHut(ActorInitializer init)
|
public LegacyBridgeHut(ActorInitializer init, LegacyBridgeHutInfo info)
|
||||||
{
|
{
|
||||||
Bridge = init.Get<ParentActorInit>().ActorValue.Trait<Bridge>();
|
var bridge = init.GetOrDefault<ParentActorInit>(info);
|
||||||
Bridge.AddHut(this);
|
init.World.AddFrameEndTask(_ =>
|
||||||
FirstBridge = Bridge.Enumerate(0, true).Last();
|
{
|
||||||
|
Bridge = bridge.Value(init.World).Value.Trait<Bridge>();
|
||||||
|
Bridge.AddHut(this);
|
||||||
|
FirstBridge = Bridge.Enumerate(0, true).Last();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Repair(Actor repairer)
|
public void Repair(Actor repairer)
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public LineBuildDirectionInit() { }
|
public LineBuildDirectionInit() { }
|
||||||
public LineBuildDirectionInit(LineBuildDirection init) { value = init; }
|
public LineBuildDirectionInit(LineBuildDirection init) { value = init; }
|
||||||
public LineBuildDirection Value(World world) { return value; }
|
public LineBuildDirection Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LineBuildParentInit : IActorInit<Actor[]>
|
public class LineBuildParentInit : IActorInit<string[]>
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey]
|
[FieldFromYamlKey]
|
||||||
public readonly string[] ParentNames = new string[0];
|
public readonly string[] ParentNames = new string[0];
|
||||||
@@ -35,7 +35,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public LineBuildParentInit() { }
|
public LineBuildParentInit() { }
|
||||||
public LineBuildParentInit(Actor[] init) { parents = init; }
|
public LineBuildParentInit(Actor[] init) { parents = init; }
|
||||||
public Actor[] Value(World world)
|
public string[] Value { get { return ParentNames; } }
|
||||||
|
public Actor[] ActorValue(World world)
|
||||||
{
|
{
|
||||||
if (parents != null)
|
if (parents != null)
|
||||||
return parents;
|
return parents;
|
||||||
@@ -79,8 +80,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public LineBuild(ActorInitializer init, LineBuildInfo info)
|
public LineBuild(ActorInitializer init, LineBuildInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
if (init.Contains<LineBuildParentInit>())
|
var lineBuildParentInit = init.GetOrDefault<LineBuildParentInit>(info);
|
||||||
parentNodes = init.Get<LineBuildParentInit>().Value(init.World);
|
if (lineBuildParentInit != null)
|
||||||
|
parentNodes = lineBuildParentInit.ActorValue(init.World);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyLineBuildSegmentsChanged.SegmentAdded(Actor self, Actor segment)
|
void INotifyLineBuildSegmentsChanged.SegmentAdded(Actor self, Actor segment)
|
||||||
|
|||||||
@@ -61,15 +61,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
: base(wr, ai, info, init)
|
: base(wr, ai, info, init)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
var owner = init.Get<OwnerInit>().Value(wr.World);
|
var ownerName = init.Get<OwnerInit>().InternalName;
|
||||||
var faction = init.Get<FactionInit>().Value(wr.World);
|
var faction = init.Get<FactionInit>().Value;
|
||||||
|
|
||||||
var rsi = ai.TraitInfo<RenderSpritesInfo>();
|
var rsi = ai.TraitInfo<RenderSpritesInfo>();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(info.SequencePalette))
|
if (!string.IsNullOrEmpty(info.SequencePalette))
|
||||||
palette = wr.Palette(info.SequencePaletteIsPlayerPalette ? info.SequencePalette + owner.InternalName : info.SequencePalette);
|
palette = wr.Palette(info.SequencePaletteIsPlayerPalette ? info.SequencePalette + ownerName : info.SequencePalette);
|
||||||
else
|
else
|
||||||
palette = wr.Palette(rsi.Palette ?? rsi.PlayerPalette + owner.InternalName);
|
palette = wr.Palette(rsi.Palette ?? rsi.PlayerPalette + ownerName);
|
||||||
|
|
||||||
preview = new Animation(wr.World, rsi.GetImage(ai, wr.World.Map.Rules.Sequences, faction));
|
preview = new Animation(wr.World, rsi.GetImage(ai, wr.World.Map.Rules.Sequences, faction));
|
||||||
preview.PlayRepeating(info.Sequence);
|
preview.PlayRepeating(info.Sequence);
|
||||||
|
|||||||
@@ -129,14 +129,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return Util.AdjacentCells(self.World, Target.FromActor(self)).Where(c => loc != c);
|
return Util.AdjacentCells(self.World, Target.FromActor(self)).Where(c => loc != c);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (init.Contains<RuntimeCargoInit>())
|
var runtimeCargoInit = init.GetOrDefault<RuntimeCargoInit>(info);
|
||||||
|
var cargoInit = init.GetOrDefault<CargoInit>(info);
|
||||||
|
if (runtimeCargoInit != null)
|
||||||
{
|
{
|
||||||
cargo = new List<Actor>(init.Get<RuntimeCargoInit, Actor[]>());
|
cargo = runtimeCargoInit.Value.ToList();
|
||||||
totalWeight = cargo.Sum(c => GetWeight(c));
|
totalWeight = cargo.Sum(c => GetWeight(c));
|
||||||
}
|
}
|
||||||
else if (init.Contains<CargoInit>())
|
else if (cargoInit != null)
|
||||||
{
|
{
|
||||||
foreach (var u in init.Get<CargoInit, string[]>())
|
foreach (var u in cargoInit.Value)
|
||||||
{
|
{
|
||||||
var unit = self.World.CreateActor(false, u.ToLowerInvariant(),
|
var unit = self.World.CreateActor(false, u.ToLowerInvariant(),
|
||||||
new TypeDictionary { new OwnerInit(self.Owner) });
|
new TypeDictionary { new OwnerInit(self.Owner) });
|
||||||
@@ -487,7 +489,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly Actor[] value = { };
|
readonly Actor[] value = { };
|
||||||
public RuntimeCargoInit() { }
|
public RuntimeCargoInit() { }
|
||||||
public RuntimeCargoInit(Actor[] init) { value = init; }
|
public RuntimeCargoInit(Actor[] init) { value = init; }
|
||||||
public Actor[] Value(World world) { return value; }
|
public Actor[] Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CargoInit : IActorInit<string[]>
|
public class CargoInit : IActorInit<string[]>
|
||||||
@@ -496,6 +498,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly string[] value = { };
|
readonly string[] value = { };
|
||||||
public CargoInit() { }
|
public CargoInit() { }
|
||||||
public CargoInit(string[] init) { value = init; }
|
public CargoInit(string[] init) { value = init; }
|
||||||
public string[] Value(World world) { return value; }
|
public string[] Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
var init = actor.Init<DeployStateInit>();
|
var init = actor.Init<DeployStateInit>();
|
||||||
if (init != null)
|
if (init != null)
|
||||||
return init.Value(world) == DeployState.Deployed;
|
return init.Value == DeployState.Deployed;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
@@ -111,8 +111,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
checkTerrainType = info.AllowedTerrainTypes.Count > 0;
|
checkTerrainType = info.AllowedTerrainTypes.Count > 0;
|
||||||
canTurn = self.Info.HasTraitInfo<IFacingInfo>();
|
canTurn = self.Info.HasTraitInfo<IFacingInfo>();
|
||||||
move = self.TraitOrDefault<IMove>();
|
move = self.TraitOrDefault<IMove>();
|
||||||
if (init.Contains<DeployStateInit>())
|
deployState = init.GetValue<DeployStateInit, DeployState>(info, DeployState.Undeployed);
|
||||||
deployState = init.Get<DeployStateInit, DeployState>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
@@ -344,6 +343,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly DeployState value = DeployState.Deployed;
|
readonly DeployState value = DeployState.Deployed;
|
||||||
public DeployStateInit() { }
|
public DeployStateInit() { }
|
||||||
public DeployStateInit(DeployState init) { value = init; }
|
public DeployStateInit(DeployState init) { value = init; }
|
||||||
public DeployState Value(World world) { return value; }
|
public DeployState Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public GrantConditionOnFaction(ActorInitializer init, GrantConditionOnFactionInfo info)
|
public GrantConditionOnFaction(ActorInitializer init, GrantConditionOnFactionInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
faction = init.GetValue<FactionInit, string>(info, init.Self.Owner.Faction.InternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public GrantConditionOnLineBuildDirection(ActorInitializer init, GrantConditionOnLineBuildDirectionInfo info)
|
public GrantConditionOnLineBuildDirection(ActorInitializer init, GrantConditionOnLineBuildDirectionInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
direction = init.Get<LineBuildDirectionInit>().Value(init.World);
|
direction = init.GetValue<LineBuildDirectionInit, LineBuildDirection>(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
|
|||||||
@@ -93,8 +93,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self = init.Self;
|
self = init.Self;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
|
||||||
if (init.Contains<LocationInit>())
|
var locationInit = init.GetOrDefault<LocationInit>(info);
|
||||||
SetPosition(self, init.Get<LocationInit, CPos>());
|
if (locationInit != null)
|
||||||
|
SetPosition(self, locationInit.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
|
|||||||
@@ -74,9 +74,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
|
|
||||||
MaxLevel = info.Conditions.Count;
|
MaxLevel = info.Conditions.Count;
|
||||||
|
initialExperience = init.GetValue<ExperienceInit, int>(info, 0);
|
||||||
if (init.Contains<ExperienceInit>())
|
|
||||||
initialExperience = init.Get<ExperienceInit, int>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
@@ -154,6 +152,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public ExperienceInit() { }
|
public ExperienceInit() { }
|
||||||
public ExperienceInit(int init) { value = init; }
|
public ExperienceInit(int init) { value = init; }
|
||||||
public int Value(World world) { return value; }
|
public int Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
actor =>
|
actor =>
|
||||||
{
|
{
|
||||||
var init = actor.Init<HealthInit>();
|
var init = actor.Init<HealthInit>();
|
||||||
return init != null ? init.Value(world) : 100;
|
return init != null ? init.Value : 100;
|
||||||
},
|
},
|
||||||
(actor, value) => actor.ReplaceInit(new HealthInit((int)value)));
|
(actor, value) => actor.ReplaceInit(new HealthInit((int)value)));
|
||||||
}
|
}
|
||||||
@@ -68,10 +68,12 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public Health(ActorInitializer init, HealthInfo info)
|
public Health(ActorInitializer init, HealthInfo info)
|
||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
MaxHP = info.HP > 0 ? info.HP : 1;
|
MaxHP = hp = info.HP > 0 ? info.HP : 1;
|
||||||
|
|
||||||
// Cast to long to avoid overflow when multiplying by the health
|
// Cast to long to avoid overflow when multiplying by the health
|
||||||
hp = init.Contains<HealthInit>() ? (int)(init.Get<HealthInit, int>() * (long)MaxHP / 100) : MaxHP;
|
var healthInit = init.GetOrDefault<HealthInit>(info);
|
||||||
|
if (healthInit != null)
|
||||||
|
hp = (int)(healthInit.Value * (long)MaxHP / 100);
|
||||||
|
|
||||||
DisplayHP = hp;
|
DisplayHP = hp;
|
||||||
}
|
}
|
||||||
@@ -247,12 +249,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
value = init;
|
value = init;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Value(World world)
|
public int Value
|
||||||
{
|
{
|
||||||
if (value < 0 || (value == 0 && !allowZero))
|
get
|
||||||
return 1;
|
{
|
||||||
|
if (value < 0 || (value == 0 && !allowZero))
|
||||||
|
return 1;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,14 +78,14 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
self = init.Self;
|
self = init.Self;
|
||||||
|
|
||||||
TopLeft = init.Get<LocationInit, CPos>();
|
TopLeft = init.GetValue<LocationInit, CPos>(info);
|
||||||
CenterPosition = init.Contains<CenterPositionInit>() ? init.Get<CenterPositionInit, WPos>() : init.World.Map.CenterOfCell(TopLeft);
|
CenterPosition = init.GetValue<CenterPositionInit, WPos>(info, init.World.Map.CenterOfCell(TopLeft));
|
||||||
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 128;
|
Facing = init.GetValue<FacingInit, int>(info, 128);
|
||||||
|
|
||||||
dragSpeed = init.Contains<HuskSpeedInit>() ? init.Get<HuskSpeedInit, int>() : 0;
|
dragSpeed = init.GetValue<HuskSpeedInit, int>(info, 0);
|
||||||
finalPosition = init.World.Map.CenterOfCell(TopLeft);
|
finalPosition = init.World.Map.CenterOfCell(TopLeft);
|
||||||
|
|
||||||
effectiveOwner = init.Contains<EffectiveOwnerInit>() ? init.Get<EffectiveOwnerInit, Player>() : self.Owner;
|
effectiveOwner = init.GetValue<EffectiveOwnerInit, Player>(info, self.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
@@ -178,6 +178,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public HuskSpeedInit() { }
|
public HuskSpeedInit() { }
|
||||||
public HuskSpeedInit(int init) { value = init; }
|
public HuskSpeedInit(int init) { value = init; }
|
||||||
public int Value(World world) { return value; }
|
public int Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public Immobile(ActorInitializer init, ImmobileInfo info)
|
public Immobile(ActorInitializer init, ImmobileInfo info)
|
||||||
{
|
{
|
||||||
location = init.Get<LocationInit, CPos>();
|
location = init.GetValue<LocationInit, CPos>(info);
|
||||||
position = init.World.Map.CenterOfCell(location);
|
position = init.World.Map.CenterOfCell(location);
|
||||||
|
|
||||||
if (info.OccupiesSpace)
|
if (info.OccupiesSpace)
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
actor =>
|
actor =>
|
||||||
{
|
{
|
||||||
var init = actor.Init<FacingInit>();
|
var init = actor.Init<FacingInit>();
|
||||||
return init != null ? init.Value(world) : InitialFacing;
|
return init != null ? init.Value : InitialFacing;
|
||||||
},
|
},
|
||||||
(actor, value) =>
|
(actor, value) =>
|
||||||
{
|
{
|
||||||
@@ -137,18 +137,18 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var turretsInit = actor.Init<TurretFacingsInit>();
|
var turretsInit = actor.Init<TurretFacingsInit>();
|
||||||
var facingInit = actor.Init<FacingInit>();
|
var facingInit = actor.Init<FacingInit>();
|
||||||
|
|
||||||
var oldFacing = facingInit != null ? facingInit.Value(world) : InitialFacing;
|
var oldFacing = facingInit != null ? facingInit.Value : InitialFacing;
|
||||||
var newFacing = (int)value;
|
var newFacing = (int)value;
|
||||||
|
|
||||||
if (turretInit != null)
|
if (turretInit != null)
|
||||||
{
|
{
|
||||||
var newTurretFacing = (turretInit.Value(world) + newFacing - oldFacing + 255) % 255;
|
var newTurretFacing = (turretInit.Value + newFacing - oldFacing + 255) % 255;
|
||||||
actor.ReplaceInit(new TurretFacingInit(newTurretFacing));
|
actor.ReplaceInit(new TurretFacingInit(newTurretFacing));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (turretsInit != null)
|
if (turretsInit != null)
|
||||||
{
|
{
|
||||||
var newTurretFacings = turretsInit.Value(world)
|
var newTurretFacings = turretsInit.Value
|
||||||
.ToDictionary(kv => kv.Key, kv => (kv.Value + newFacing - oldFacing + 255) % 255);
|
.ToDictionary(kv => kv.Key, kv => (kv.Value + newFacing - oldFacing + 255) % 255);
|
||||||
actor.ReplaceInit(new TurretFacingsInit(newTurretFacings));
|
actor.ReplaceInit(new TurretFacingsInit(newTurretFacings));
|
||||||
}
|
}
|
||||||
@@ -263,31 +263,34 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
speedModifiers = Exts.Lazy(() => self.TraitsImplementing<ISpeedModifier>().ToArray().Select(x => x.GetSpeedModifier()));
|
speedModifiers = Exts.Lazy(() => self.TraitsImplementing<ISpeedModifier>().ToArray().Select(x => x.GetSpeedModifier()));
|
||||||
|
|
||||||
ToSubCell = FromSubCell = info.LocomotorInfo.SharesCell ? init.World.Map.Grid.DefaultSubCell : SubCell.FullCell;
|
ToSubCell = FromSubCell = info.LocomotorInfo.SharesCell ? init.World.Map.Grid.DefaultSubCell : SubCell.FullCell;
|
||||||
if (init.Contains<SubCellInit>())
|
|
||||||
|
var subCellInit = init.GetOrDefault<SubCellInit>(info);
|
||||||
|
if (subCellInit != null)
|
||||||
{
|
{
|
||||||
FromSubCell = ToSubCell = init.Get<SubCellInit, SubCell>();
|
FromSubCell = ToSubCell = subCellInit.Value;
|
||||||
returnToCellOnCreationRecalculateSubCell = false;
|
returnToCellOnCreationRecalculateSubCell = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init.Contains<LocationInit>())
|
var locationInit = init.GetOrDefault<LocationInit>(info);
|
||||||
|
if (locationInit != null)
|
||||||
{
|
{
|
||||||
fromCell = toCell = init.Get<LocationInit, CPos>();
|
fromCell = toCell = locationInit.Value;
|
||||||
SetVisualPosition(self, init.World.Map.CenterOfSubCell(FromCell, FromSubCell));
|
SetVisualPosition(self, init.World.Map.CenterOfSubCell(FromCell, FromSubCell));
|
||||||
}
|
}
|
||||||
|
|
||||||
Facing = oldFacing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : info.InitialFacing;
|
Facing = oldFacing = init.GetValue<FacingInit, int>(info, info.InitialFacing);
|
||||||
|
|
||||||
// Sets the initial visual position
|
// Sets the initial visual position
|
||||||
// Unit will move into the cell grid (defined by LocationInit) as its initial activity
|
// Unit will move into the cell grid (defined by LocationInit) as its initial activity
|
||||||
if (init.Contains<CenterPositionInit>())
|
var centerPositionInit = init.GetOrDefault<CenterPositionInit>(info);
|
||||||
|
if (centerPositionInit != null)
|
||||||
{
|
{
|
||||||
oldPos = init.Get<CenterPositionInit, WPos>();
|
oldPos = centerPositionInit.Value;
|
||||||
SetVisualPosition(self, oldPos);
|
SetVisualPosition(self, oldPos);
|
||||||
returnToCellOnCreation = true;
|
returnToCellOnCreation = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init.Contains<CreationActivityDelayInit>())
|
creationActivityDelay = init.GetValue<CreationActivityDelayInit, int>(info, 0);
|
||||||
creationActivityDelay = init.Get<CreationActivityDelayInit, int>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
// Explore map-placed actors if the "Explore Map" option is enabled
|
// Explore map-placed actors if the "Explore Map" option is enabled
|
||||||
var shroudInfo = init.World.Map.Rules.Actors["player"].TraitInfo<ShroudInfo>();
|
var shroudInfo = init.World.Map.Rules.Actors["player"].TraitInfo<ShroudInfo>();
|
||||||
var exploredMap = init.World.LobbyInfo.GlobalSettings.OptionOrDefault("explored", shroudInfo.ExploredMapCheckboxEnabled);
|
var exploredMap = init.World.LobbyInfo.GlobalSettings.OptionOrDefault("explored", shroudInfo.ExploredMapCheckboxEnabled);
|
||||||
startsRevealed = exploredMap && init.Contains<SpawnedByMapInit>() && !init.Contains<HiddenUnderFogInit>();
|
startsRevealed = exploredMap && init.Contains<SpawnedByMapInit>(info) && !init.Contains<HiddenUnderFogInit>(info);
|
||||||
var buildingInfo = init.Self.Info.TraitInfoOrDefault<BuildingInfo>();
|
var buildingInfo = init.Self.Info.TraitInfoOrDefault<BuildingInfo>();
|
||||||
var footprintCells = buildingInfo != null ? buildingInfo.FrozenUnderFogTiles(init.Self.Location).ToList() : new List<CPos>() { init.Self.Location };
|
var footprintCells = buildingInfo != null ? buildingInfo.FrozenUnderFogTiles(init.Self.Location).ToList() : new List<CPos>() { init.Self.Location };
|
||||||
footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray();
|
footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray();
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self = init.Self;
|
self = init.Self;
|
||||||
Info = info;
|
Info = info;
|
||||||
|
|
||||||
Faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
|
Faction = init.GetValue<FactionInit, string>(info, self.Owner.Faction.InternalName);
|
||||||
IsValidFaction = !info.Factions.Any() || info.Factions.Contains(Faction);
|
IsValidFaction = !info.Factions.Any() || info.Factions.Contains(Faction);
|
||||||
Enabled = IsValidFaction;
|
Enabled = IsValidFaction;
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (string.IsNullOrEmpty(prerequisite))
|
if (string.IsNullOrEmpty(prerequisite))
|
||||||
prerequisite = init.Self.Info.Name;
|
prerequisite = init.Self.Info.Name;
|
||||||
|
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
faction = init.GetValue<FactionInit, string>(info, init.Self.Owner.Faction.InternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> ProvidesPrerequisites
|
public IEnumerable<string> ProvidesPrerequisites
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
|
|
||||||
var plugInit = init.Contains<PlugsInit>() ? init.Get<PlugsInit, Dictionary<CVec, string>>() : new Dictionary<CVec, string>();
|
var plugInit = init.GetValue<PlugsInit, Dictionary<CVec, string>>(info, new Dictionary<CVec, string>());
|
||||||
if (plugInit.ContainsKey(Info.Offset))
|
if (plugInit.ContainsKey(Info.Offset))
|
||||||
initialPlug = plugInit[Info.Offset];
|
initialPlug = plugInit[Info.Offset];
|
||||||
|
|
||||||
@@ -126,6 +126,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly Dictionary<CVec, string> value = new Dictionary<CVec, string>();
|
readonly Dictionary<CVec, string> value = new Dictionary<CVec, string>();
|
||||||
public PlugsInit() { }
|
public PlugsInit() { }
|
||||||
public PlugsInit(Dictionary<CVec, string> init) { value = init; }
|
public PlugsInit(Dictionary<CVec, string> init) { value = init; }
|
||||||
public Dictionary<CVec, string> Value(World world) { return value; }
|
public Dictionary<CVec, string> Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
rp = Exts.Lazy(() => init.Self.IsDead ? null : init.Self.TraitOrDefault<RallyPoint>());
|
rp = Exts.Lazy(() => init.Self.IsDead ? null : init.Self.TraitOrDefault<RallyPoint>());
|
||||||
Faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
Faction = init.GetValue<FactionInit, string>(info, init.Self.Owner.Faction.InternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string productionType, TypeDictionary inits)
|
public virtual void DoProduction(Actor self, ActorInfo producee, ExitInfo exitinfo, string productionType, TypeDictionary inits)
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Primitives;
|
using OpenRA.Primitives;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
@@ -30,8 +31,10 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
: base(init, info)
|
: base(init, info)
|
||||||
{
|
{
|
||||||
domainIndex = init.Self.World.WorldActor.Trait<DomainIndex>();
|
domainIndex = init.Self.World.WorldActor.Trait<DomainIndex>();
|
||||||
if (init.Contains<ProductionSpawnLocationInit>())
|
|
||||||
spawnLocation = init.Get<ProductionSpawnLocationInit, CPos>();
|
var spawnLocationInit = init.GetOrDefault<ProductionSpawnLocationInit>(info);
|
||||||
|
if (spawnLocationInit != null)
|
||||||
|
spawnLocation = spawnLocationInit.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
@@ -114,6 +117,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public ProductionSpawnLocationInit() { }
|
public ProductionSpawnLocationInit() { }
|
||||||
public ProductionSpawnLocationInit(CPos init) { value = init; }
|
public ProductionSpawnLocationInit(CPos init) { value = init; }
|
||||||
public CPos Value(World world) { return value; }
|
public CPos Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
public IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
|
public IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
|
||||||
{
|
{
|
||||||
var sequenceProvider = init.World.Map.Rules.Sequences;
|
var sequenceProvider = init.World.Map.Rules.Sequences;
|
||||||
var faction = init.Get<FactionInit, string>();
|
var faction = init.GetValue<FactionInit, string>(this);
|
||||||
var ownerName = init.Get<OwnerInit>().PlayerName;
|
var ownerName = init.Get<OwnerInit>(this).InternalName;
|
||||||
var image = GetImage(init.Actor, sequenceProvider, faction);
|
var image = GetImage(init.Actor, sequenceProvider, faction);
|
||||||
var palette = init.WorldRenderer.Palette(Palette ?? PlayerPalette + ownerName);
|
var palette = init.WorldRenderer.Palette(Palette ?? PlayerPalette + ownerName);
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
public RenderSprites(ActorInitializer init, RenderSpritesInfo info)
|
public RenderSprites(ActorInitializer init, RenderSpritesInfo info)
|
||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
faction = init.GetValue<FactionInit, string>(info, init.Self.Owner.Faction.InternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetImage(Actor self)
|
public string GetImage(Actor self)
|
||||||
|
|||||||
@@ -57,8 +57,8 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
public virtual IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
|
public virtual IEnumerable<IActorPreview> RenderPreview(ActorPreviewInitializer init)
|
||||||
{
|
{
|
||||||
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
var body = init.Actor.TraitInfo<BodyOrientationInfo>();
|
||||||
var faction = init.Get<FactionInit, string>();
|
var faction = init.GetValue<FactionInit, string>(this);
|
||||||
var ownerName = init.Get<OwnerInit>().PlayerName;
|
var ownerName = init.Get<OwnerInit>(this).InternalName;
|
||||||
var sequenceProvider = init.World.Map.Rules.Sequences;
|
var sequenceProvider = init.World.Map.Rules.Sequences;
|
||||||
var image = Image ?? init.Actor.Name;
|
var image = Image ?? init.Actor.Name;
|
||||||
var facings = body.QuantizedFacings == -1 ?
|
var facings = body.QuantizedFacings == -1 ?
|
||||||
|
|||||||
@@ -49,14 +49,15 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
p = init.WorldRenderer.Palette(Palette);
|
p = init.WorldRenderer.Palette(Palette);
|
||||||
|
|
||||||
Func<WAngle> facing;
|
Func<WAngle> facing;
|
||||||
if (init.Contains<DynamicFacingInit>())
|
var dynamicfacingInit = init.GetOrDefault<DynamicFacingInit>(this);
|
||||||
|
if (dynamicfacingInit != null)
|
||||||
{
|
{
|
||||||
var getFacing = init.Get<DynamicFacingInit, Func<int>>();
|
var getFacing = dynamicfacingInit.Value;
|
||||||
facing = () => WAngle.FromFacing(getFacing());
|
facing = () => WAngle.FromFacing(getFacing());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var f = WAngle.FromFacing(init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0);
|
var f = WAngle.FromFacing(init.GetValue<FacingInit, int>(this, 0));
|
||||||
facing = () => f;
|
facing = () => f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
var self = init.Self;
|
var self = init.Self;
|
||||||
wsbs = self.TraitsImplementing<WithSpriteBody>().Where(w => info.BodyNames.Contains(w.Info.Name)).ToArray();
|
wsbs = self.TraitsImplementing<WithSpriteBody>().Where(w => info.BodyNames.Contains(w.Info.Name)).ToArray();
|
||||||
skipMakeAnimation = init.Contains<SkipMakeAnimsInit>();
|
skipMakeAnimation = init.Contains<SkipMakeAnimsInit>(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCreated.Created(Actor self)
|
void INotifyCreated.Created(Actor self)
|
||||||
|
|||||||
@@ -78,11 +78,12 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
p = init.WorldRenderer.Palette(Palette);
|
p = init.WorldRenderer.Palette(Palette);
|
||||||
|
|
||||||
Func<int> facing;
|
Func<int> facing;
|
||||||
if (init.Contains<DynamicFacingInit>())
|
var dynamicfacingInit = init.GetOrDefault<DynamicFacingInit>(this);
|
||||||
facing = init.Get<DynamicFacingInit, Func<int>>();
|
if (dynamicfacingInit != null)
|
||||||
|
facing = dynamicfacingInit.Value;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var f = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
|
var f = init.GetValue<FacingInit, int>(this, 0);
|
||||||
facing = () => f;
|
facing = () => f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
var t = init.Actor.TraitInfos<TurretedInfo>()
|
var t = init.Actor.TraitInfos<TurretedInfo>()
|
||||||
.First(tt => tt.Turret == armament.Turret);
|
.First(tt => tt.Turret == armament.Turret);
|
||||||
|
|
||||||
var turretFacing = Turreted.TurretFacingFromInit(init, t.InitialFacing, armament.Turret);
|
var turretFacing = Turreted.TurretFacingFromInit(init, t);
|
||||||
var anim = new Animation(init.World, image, () => WAngle.FromFacing(turretFacing()));
|
var anim = new Animation(init.World, image, () => WAngle.FromFacing(turretFacing()));
|
||||||
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
var t = init.Actor.TraitInfos<TurretedInfo>()
|
var t = init.Actor.TraitInfos<TurretedInfo>()
|
||||||
.First(tt => tt.Turret == Turret);
|
.First(tt => tt.Turret == Turret);
|
||||||
|
|
||||||
var turretFacing = Turreted.TurretFacingFromInit(init, t.InitialFacing, Turret);
|
var turretFacing = Turreted.TurretFacingFromInit(init, t);
|
||||||
var anim = new Animation(init.World, image, () => WAngle.FromFacing(turretFacing()));
|
var anim = new Animation(init.World, image, () => WAngle.FromFacing(turretFacing()));
|
||||||
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
anim.Play(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence));
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (IsPlayerPalette)
|
if (IsPlayerPalette)
|
||||||
p = init.WorldRenderer.Palette(Palette + init.Get<OwnerInit>().PlayerName);
|
p = init.WorldRenderer.Palette(Palette + init.Get<OwnerInit>(this).InternalName);
|
||||||
else if (Palette != null)
|
else if (Palette != null)
|
||||||
p = init.WorldRenderer.Palette(Palette);
|
p = init.WorldRenderer.Palette(Palette);
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
|
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
|
||||||
|
|
||||||
var turretFacing = Turreted.TurretFacingFromInit(init, t.InitialFacing, t.Turret);
|
var turretFacing = Turreted.TurretFacingFromInit(init, t);
|
||||||
Func<WRot> turretOrientation = () => body.QuantizeOrientation(WRot.FromYaw(WAngle.FromFacing(turretFacing()) - orientation().Yaw), facings);
|
Func<WRot> turretOrientation = () => body.QuantizeOrientation(WRot.FromYaw(WAngle.FromFacing(turretFacing()) - orientation().Yaw), facings);
|
||||||
|
|
||||||
Func<WRot> quantizedTurret = () => body.QuantizeOrientation(turretOrientation(), facings);
|
Func<WRot> quantizedTurret = () => body.QuantizeOrientation(turretOrientation(), facings);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
|
var model = init.World.ModelCache.GetModelSequence(image, Sequence);
|
||||||
Func<WVec> turretOffset = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
|
Func<WVec> turretOffset = () => body.LocalToWorld(t.Offset.Rotate(orientation()));
|
||||||
|
|
||||||
var turretFacing = Turreted.TurretFacingFromInit(init, t.InitialFacing, Turret);
|
var turretFacing = Turreted.TurretFacingFromInit(init, t);
|
||||||
Func<WRot> turretBodyOrientation = () => WRot.FromYaw(WAngle.FromFacing(turretFacing()) - orientation().Yaw);
|
Func<WRot> turretBodyOrientation = () => WRot.FromYaw(WAngle.FromFacing(turretFacing()) - orientation().Yaw);
|
||||||
yield return new ModelAnimation(model, turretOffset,
|
yield return new ModelAnimation(model, turretOffset,
|
||||||
() => new[] { turretBodyOrientation(), body.QuantizeOrientation(orientation(), facings) }, () => false, () => 0, ShowShadow);
|
() => new[] { turretBodyOrientation(), body.QuantizeOrientation(orientation(), facings) }, () => false, () => 0, ShowShadow);
|
||||||
|
|||||||
@@ -37,15 +37,13 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
yield break;
|
yield break;
|
||||||
|
|
||||||
var adjacent = 0;
|
var adjacent = 0;
|
||||||
|
var locationInit = init.GetOrDefault<LocationInit>(this);
|
||||||
|
var neighbourInit = init.GetOrDefault<RuntimeNeighbourInit>(this);
|
||||||
|
|
||||||
if (init.Contains<RuntimeNeighbourInit>())
|
if (locationInit != null && neighbourInit != null)
|
||||||
{
|
{
|
||||||
var location = CPos.Zero;
|
var location = locationInit.Value;
|
||||||
if (init.Contains<LocationInit>())
|
foreach (var kv in neighbourInit.Value)
|
||||||
location = init.Get<LocationInit, CPos>();
|
|
||||||
|
|
||||||
var neighbours = init.Get<RuntimeNeighbourInit, Dictionary<CPos, string[]>>();
|
|
||||||
foreach (var kv in neighbours)
|
|
||||||
{
|
{
|
||||||
var haveNeighbour = false;
|
var haveNeighbour = false;
|
||||||
foreach (var n in kv.Value)
|
foreach (var n in kv.Value)
|
||||||
@@ -177,6 +175,6 @@ namespace OpenRA.Mods.Common.Traits.Render
|
|||||||
|
|
||||||
public RuntimeNeighbourInit() { }
|
public RuntimeNeighbourInit() { }
|
||||||
public RuntimeNeighbourInit(Dictionary<CPos, string[]> init) { value = init; }
|
public RuntimeNeighbourInit(Dictionary<CPos, string[]> init) { value = init; }
|
||||||
public Dictionary<CPos, string[]> Value(World world) { return value; }
|
public Dictionary<CPos, string[]> Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public ScriptTags(ActorInitializer init, ScriptTagsInfo info)
|
public ScriptTags(ActorInitializer init, ScriptTagsInfo info)
|
||||||
{
|
{
|
||||||
if (init.Contains<ScriptTagsInit>())
|
var scriptTagsInit = init.GetOrDefault<ScriptTagsInit>(info);
|
||||||
foreach (var tag in init.Get<ScriptTagsInit, string[]>())
|
if (scriptTagsInit != null)
|
||||||
|
foreach (var tag in scriptTagsInit.Value)
|
||||||
tags.Add(tag);
|
tags.Add(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +56,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public ScriptTagsInit() { }
|
public ScriptTagsInit() { }
|
||||||
public ScriptTagsInit(string[] init) { value = init; }
|
public ScriptTagsInit(string[] init) { value = init; }
|
||||||
public string[] Value(World world) { return value; }
|
public string[] Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
enabled = !info.RequiresLobbyCreeps || init.Self.World.WorldActor.Trait<MapCreeps>().Enabled;
|
enabled = !info.RequiresLobbyCreeps || init.Self.World.WorldActor.Trait<MapCreeps>().Enabled;
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
faction = init.GetValue<FactionInit, string>(info, init.Self.Owner.Faction.InternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
void INotifyKilled.Killed(Actor self, AttackInfo e)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public ProduceActorPower(ActorInitializer init, ProduceActorPowerInfo info)
|
public ProduceActorPower(ActorInitializer init, ProduceActorPowerInfo info)
|
||||||
: base(init.Self, info)
|
: base(init.Self, info)
|
||||||
{
|
{
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
faction = init.GetValue<FactionInit, string>(info, init.Self.Owner.Faction.InternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var body = self.Trait<BodyOrientation>();
|
var body = self.Trait<BodyOrientation>();
|
||||||
|
|
||||||
// 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<DynamicFacingInit>() ? init.Get<DynamicFacingInit, Func<int>>()()
|
var dynamicFacingInit = init.GetOrDefault<DynamicFacingInit>(info);
|
||||||
: init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 0;
|
var bodyFacing = dynamicFacingInit != null ? dynamicFacingInit.Value() : init.GetValue<FacingInit, int>(info, 0);
|
||||||
facing = WAngle.FromFacing(Turreted.TurretFacingFromInit(init, 0)());
|
facing = WAngle.FromFacing(Turreted.TurretFacingFromInit(init, info, 0)());
|
||||||
|
|
||||||
// Calculate final position
|
// Calculate final position
|
||||||
var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
|
var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public TransformCrusherOnCrush(ActorInitializer init, TransformCrusherOnCrushInfo info)
|
public TransformCrusherOnCrush(ActorInitializer init, TransformCrusherOnCrushInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
faction = init.GetValue<FactionInit, string>(info, init.Self.Owner.Faction.InternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses) { }
|
void INotifyCrushed.WarnCrush(Actor self, Actor crusher, BitSet<CrushClass> crushClasses) { }
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public TransformOnCapture(ActorInitializer init, TransformOnCaptureInfo info)
|
public TransformOnCapture(ActorInitializer init, TransformOnCaptureInfo info)
|
||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : init.Self.Owner.Faction.InternalName;
|
faction = init.GetValue<FactionInit, string>(info, init.Self.Owner.Faction.InternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
|
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet<CaptureType> captureTypes)
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
self = init.Self;
|
self = init.Self;
|
||||||
actorInfo = self.World.Map.Rules.Actors[info.IntoActor];
|
actorInfo = self.World.Map.Rules.Actors[info.IntoActor];
|
||||||
buildingInfo = actorInfo.TraitInfoOrDefault<BuildingInfo>();
|
buildingInfo = actorInfo.TraitInfoOrDefault<BuildingInfo>();
|
||||||
faction = init.Contains<FactionInit>() ? init.Get<FactionInit, string>() : self.Owner.Faction.InternalName;
|
faction = init.GetValue<FactionInit, string>(info, self.Owner.Faction.InternalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string VoicePhraseForOrder(Actor self, Order order)
|
public string VoicePhraseForOrder(Actor self, Order order)
|
||||||
|
|||||||
@@ -55,11 +55,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
var init = actor.Init<TurretFacingInit>();
|
var init = actor.Init<TurretFacingInit>();
|
||||||
if (init != null)
|
if (init != null)
|
||||||
return init.Value(world);
|
return init.Value;
|
||||||
|
|
||||||
var facingInit = actor.Init<FacingInit>();
|
var facingInit = actor.Init<FacingInit>();
|
||||||
if (facingInit != null)
|
if (facingInit != null)
|
||||||
return facingInit.Value(world);
|
return facingInit.Value;
|
||||||
|
|
||||||
return InitialFacing;
|
return InitialFacing;
|
||||||
},
|
},
|
||||||
@@ -94,44 +94,51 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public WVec Offset { get { return Info.Offset + localOffset; } }
|
public WVec Offset { get { return Info.Offset + localOffset; } }
|
||||||
public string Name { get { return Info.Turret; } }
|
public string Name { get { return Info.Turret; } }
|
||||||
|
|
||||||
public static Func<int> TurretFacingFromInit(IActorInitializer init, int def, string turret = null)
|
public static Func<int> TurretFacingFromInit(IActorInitializer init, TurretedInfo info)
|
||||||
{
|
{
|
||||||
if (turret != null && init.Contains<DynamicTurretFacingsInit>())
|
return TurretFacingFromInit(init, info, info.InitialFacing, info.Turret);
|
||||||
{
|
}
|
||||||
Func<int> facing;
|
|
||||||
if (init.Get<DynamicTurretFacingsInit, Dictionary<string, Func<int>>>().TryGetValue(turret, out facing))
|
|
||||||
return facing;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (turret != null && init.Contains<TurretFacingsInit>())
|
public static Func<int> TurretFacingFromInit(IActorInitializer init, TraitInfo info, int defaultFacing, string turret = null)
|
||||||
|
{
|
||||||
|
if (turret != null)
|
||||||
{
|
{
|
||||||
|
Func<int> getFacing;
|
||||||
|
var dynamicTurretFacingsInit = init.GetOrDefault<DynamicTurretFacingsInit>(info);
|
||||||
|
if (dynamicTurretFacingsInit != null && dynamicTurretFacingsInit.Value.TryGetValue(turret, out getFacing))
|
||||||
|
return getFacing;
|
||||||
|
|
||||||
int facing;
|
int facing;
|
||||||
if (init.Get<TurretFacingsInit, Dictionary<string, int>>().TryGetValue(turret, out facing))
|
var turretFacingsInit = init.GetOrDefault<TurretFacingsInit>(info);
|
||||||
|
if (turretFacingsInit != null && turretFacingsInit.Value.TryGetValue(turret, out facing))
|
||||||
return () => facing;
|
return () => facing;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init.Contains<TurretFacingInit>())
|
var turretFacingInit = init.GetOrDefault<TurretFacingInit>(info);
|
||||||
|
if (turretFacingInit != null)
|
||||||
{
|
{
|
||||||
var facing = init.Get<TurretFacingInit, int>();
|
var facing = turretFacingInit.Value;
|
||||||
return () => facing;
|
return () => facing;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init.Contains<DynamicFacingInit>())
|
var dynamicFacingInit = init.GetOrDefault<DynamicFacingInit>(info);
|
||||||
return init.Get<DynamicFacingInit, Func<int>>();
|
if (dynamicFacingInit != null)
|
||||||
|
return dynamicFacingInit.Value;
|
||||||
|
|
||||||
if (init.Contains<FacingInit>())
|
var facingInit = init.GetOrDefault<FacingInit>(info);
|
||||||
|
if (facingInit != null)
|
||||||
{
|
{
|
||||||
var facing = init.Get<FacingInit, int>();
|
var facing = facingInit.Value;
|
||||||
return () => facing;
|
return () => facing;
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => def;
|
return () => defaultFacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Turreted(ActorInitializer init, TurretedInfo info)
|
public Turreted(ActorInitializer init, TurretedInfo info)
|
||||||
: base(info)
|
: base(info)
|
||||||
{
|
{
|
||||||
TurretFacing = TurretFacingFromInit(init, Info.InitialFacing, Info.Turret)();
|
TurretFacing = TurretFacingFromInit(init, Info)();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
@@ -228,8 +235,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
init.Add(facings);
|
init.Add(facings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!facings.Value(self.World).ContainsKey(Name))
|
if (!facings.Value.ContainsKey(Name))
|
||||||
facings.Value(self.World).Add(Name, TurretFacing);
|
facings.Value.Add(Name, TurretFacing);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
void IActorPreviewInitModifier.ModifyActorPreviewInit(Actor self, TypeDictionary inits)
|
||||||
@@ -245,13 +252,13 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var dynamicFacing = inits.GetOrDefault<DynamicFacingInit>();
|
var dynamicFacing = inits.GetOrDefault<DynamicFacingInit>();
|
||||||
var staticFacing = inits.GetOrDefault<FacingInit>();
|
var staticFacing = inits.GetOrDefault<FacingInit>();
|
||||||
if (dynamicFacing != null)
|
if (dynamicFacing != null)
|
||||||
bodyFacing = dynamicFacing.Value(self.World);
|
bodyFacing = dynamicFacing.Value;
|
||||||
else if (staticFacing != null)
|
else if (staticFacing != null)
|
||||||
bodyFacing = () => staticFacing.Value(self.World);
|
bodyFacing = () => staticFacing.Value;
|
||||||
|
|
||||||
// Freeze the relative turret facing to its current value
|
// Freeze the relative turret facing to its current value
|
||||||
var facingOffset = TurretFacing - bodyFacing();
|
var facingOffset = TurretFacing - bodyFacing();
|
||||||
facings.Value(self.World).Add(Name, () => bodyFacing() + facingOffset);
|
facings.Value.Add(Name, () => bodyFacing() + facingOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void TraitDisabled(Actor self)
|
protected override void TraitDisabled(Actor self)
|
||||||
@@ -268,7 +275,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public TurretFacingInit() { }
|
public TurretFacingInit() { }
|
||||||
public TurretFacingInit(int init) { value = init; }
|
public TurretFacingInit(int init) { value = init; }
|
||||||
public int Value(World world) { return value; }
|
public int Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TurretFacingsInit : IActorInit<Dictionary<string, int>>
|
public class TurretFacingsInit : IActorInit<Dictionary<string, int>>
|
||||||
@@ -278,7 +285,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public TurretFacingsInit() { }
|
public TurretFacingsInit() { }
|
||||||
public TurretFacingsInit(Dictionary<string, int> init) { value = init; }
|
public TurretFacingsInit(Dictionary<string, int> init) { value = init; }
|
||||||
public Dictionary<string, int> Value(World world) { return value; }
|
public Dictionary<string, int> Value { get { return value; } }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DynamicTurretFacingsInit : IActorInit<Dictionary<string, Func<int>>>
|
public class DynamicTurretFacingsInit : IActorInit<Dictionary<string, Func<int>>>
|
||||||
@@ -286,6 +293,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
readonly Dictionary<string, Func<int>> value = new Dictionary<string, Func<int>>();
|
readonly Dictionary<string, Func<int>> value = new Dictionary<string, Func<int>>();
|
||||||
public DynamicTurretFacingsInit() { }
|
public DynamicTurretFacingsInit() { }
|
||||||
public DynamicTurretFacingsInit(Dictionary<string, Func<int>> init) { value = init; }
|
public DynamicTurretFacingsInit(Dictionary<string, Func<int>> init) { value = init; }
|
||||||
public Dictionary<string, Func<int>> Value(World world) { return value; }
|
public Dictionary<string, Func<int>> Value { get { return value; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,8 +118,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public EditorActorPreview Add(string id, ActorReference reference, bool initialSetup = false)
|
public EditorActorPreview Add(string id, ActorReference reference, bool initialSetup = false)
|
||||||
{
|
{
|
||||||
var owner = Players.Players[reference.InitDict.Get<OwnerInit>().PlayerName];
|
var owner = Players.Players[reference.InitDict.Get<OwnerInit>().InternalName];
|
||||||
|
|
||||||
var preview = new EditorActorPreview(worldRenderer, id, reference, owner);
|
var preview = new EditorActorPreview(worldRenderer, id, reference, owner);
|
||||||
|
|
||||||
Add(preview, initialSetup);
|
Add(preview, initialSetup);
|
||||||
|
|||||||
@@ -67,11 +67,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
CenterPosition = PreviewPosition(world, actor.InitDict);
|
CenterPosition = PreviewPosition(world, actor.InitDict);
|
||||||
|
|
||||||
var location = actor.InitDict.Get<LocationInit>().Value(worldRenderer.World);
|
var location = actor.InitDict.Get<LocationInit>().Value;
|
||||||
var ios = Info.TraitInfoOrDefault<IOccupySpaceInfo>();
|
var ios = Info.TraitInfoOrDefault<IOccupySpaceInfo>();
|
||||||
|
|
||||||
var subCellInit = actor.InitDict.GetOrDefault<SubCellInit>();
|
var subCellInit = actor.InitDict.GetOrDefault<SubCellInit>();
|
||||||
var subCell = subCellInit != null ? subCellInit.Value(worldRenderer.World) : SubCell.Any;
|
var subCell = subCellInit != null ? subCellInit.Value : SubCell.Any;
|
||||||
|
|
||||||
if (ios != null)
|
if (ios != null)
|
||||||
Footprint = ios.OccupiedCells(Info, location, subCell);
|
Footprint = ios.OccupiedCells(Info, location, subCell);
|
||||||
@@ -152,7 +152,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
Func<object, bool> saveInit = init =>
|
Func<object, bool> saveInit = init =>
|
||||||
{
|
{
|
||||||
var factionInit = init as FactionInit;
|
var factionInit = init as FactionInit;
|
||||||
if (factionInit != null && factionInit.Faction == Owner.Faction)
|
if (factionInit != null && factionInit.Value == Owner.Faction)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// TODO: Other default values will need to be filtered
|
// TODO: Other default values will need to be filtered
|
||||||
@@ -166,15 +166,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
WPos PreviewPosition(World world, TypeDictionary init)
|
WPos PreviewPosition(World world, TypeDictionary init)
|
||||||
{
|
{
|
||||||
if (init.Contains<CenterPositionInit>())
|
if (init.Contains<CenterPositionInit>())
|
||||||
return init.Get<CenterPositionInit>().Value(world);
|
return init.Get<CenterPositionInit>().Value;
|
||||||
|
|
||||||
if (init.Contains<LocationInit>())
|
if (init.Contains<LocationInit>())
|
||||||
{
|
{
|
||||||
var cell = init.Get<LocationInit>().Value(world);
|
var cell = init.Get<LocationInit>().Value;
|
||||||
var offset = WVec.Zero;
|
var offset = WVec.Zero;
|
||||||
|
|
||||||
var subCellInit = Actor.InitDict.GetOrDefault<SubCellInit>();
|
var subCellInit = Actor.InitDict.GetOrDefault<SubCellInit>();
|
||||||
var subCell = subCellInit != null ? subCellInit.Value(worldRenderer.World) : SubCell.Any;
|
var subCell = subCellInit != null ? subCellInit.Value : SubCell.Any;
|
||||||
|
|
||||||
var buildingInfo = Info.TraitInfoOrDefault<BuildingInfo>();
|
var buildingInfo = Info.TraitInfoOrDefault<BuildingInfo>();
|
||||||
if (buildingInfo != null)
|
if (buildingInfo != null)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
var actorReference = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
||||||
|
|
||||||
// If there is no real player associated, don't spawn it.
|
// If there is no real player associated, don't spawn it.
|
||||||
var ownerName = actorReference.InitDict.Get<OwnerInit>().PlayerName;
|
var ownerName = actorReference.InitDict.Get<OwnerInit>().InternalName;
|
||||||
if (!world.Players.Any(p => p.InternalName == ownerName))
|
if (!world.Players.Any(p => p.InternalName == ownerName))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -68,9 +68,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly string Name;
|
public readonly string Name;
|
||||||
public SpawnedByMapInit(string name) { Name = name; }
|
public SpawnedByMapInit(string name) { Name = name; }
|
||||||
|
|
||||||
public string Value(World world)
|
public string Value { get { return Name; } }
|
||||||
{
|
|
||||||
return Name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
foreach (var kv in map.ActorDefinitions)
|
foreach (var kv in map.ActorDefinitions)
|
||||||
{
|
{
|
||||||
var actor = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
var actor = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
|
||||||
var location = actor.InitDict.Get<LocationInit>().Value(null);
|
var location = actor.InitDict.Get<LocationInit>().Value;
|
||||||
if (!map.Contains(location))
|
if (!map.Contains(location))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Removing actor {0} located at {1} due being outside of the new map boundaries.".F(actor.Type, location));
|
Console.WriteLine("Removing actor {0} located at {1} due being outside of the new map boundaries.".F(actor.Type, location));
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace OpenRA.Mods.D2k.Traits.Render
|
|||||||
{
|
{
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
|
||||||
if (init.Contains<SkipMakeAnimsInit>())
|
if (init.Contains<SkipMakeAnimsInit>(info))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
renderSprites = init.Self.Trait<RenderSprites>();
|
renderSprites = init.Self.Trait<RenderSprites>();
|
||||||
|
|||||||
Reference in New Issue
Block a user