Added FacingInit and AltitudeInit. Used in Mobile/Aircraft/Husks. Refactored Production, SpyPlane, Paratroopers and LeavesHusk
This commit is contained in:
@@ -36,17 +36,57 @@ namespace OpenRA
|
||||
{
|
||||
return dict.Get<T>().Value( world );
|
||||
}
|
||||
|
||||
public bool Contains<T>()
|
||||
where T : IActorInit
|
||||
{
|
||||
return dict.Contains<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public interface IActorInit
|
||||
{
|
||||
}
|
||||
public interface IActorInit {}
|
||||
|
||||
public interface IActorInit<T> : IActorInit
|
||||
{
|
||||
T Value( World world );
|
||||
}
|
||||
|
||||
public class FacingInit : IActorInit<int>
|
||||
{
|
||||
[FieldFromYamlKey]
|
||||
public readonly int value = 128;
|
||||
|
||||
public FacingInit() { }
|
||||
|
||||
public FacingInit( int init )
|
||||
{
|
||||
value = init;
|
||||
}
|
||||
|
||||
public int Value( World world )
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public class AltitudeInit : IActorInit<int>
|
||||
{
|
||||
[FieldFromYamlKey]
|
||||
public readonly int value = 0;
|
||||
|
||||
public AltitudeInit() { }
|
||||
|
||||
public AltitudeInit( int init )
|
||||
{
|
||||
value = init;
|
||||
}
|
||||
|
||||
public int Value( World world )
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public class LocationInit : IActorInit<int2>
|
||||
{
|
||||
[FieldFromYamlKey]
|
||||
|
||||
@@ -77,6 +77,8 @@ namespace OpenRA.Traits
|
||||
this.self = init.self;
|
||||
this.Info = info;
|
||||
this.__fromCell = this.__toCell = init.Get<LocationInit,int2>();
|
||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
|
||||
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
|
||||
|
||||
shroud = self.World.WorldActor.traits.Get<Shroud>();
|
||||
uim = self.World.WorldActor.traits.Get<UnitInfluence>();
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
@@ -55,8 +56,11 @@ namespace OpenRA.Traits
|
||||
if( location == null || self.World.WorldActor.traits.Get<UnitInfluence>().GetUnitsAt( location.Value ).Any() )
|
||||
return false;
|
||||
|
||||
var newUnit = self.World.CreateActor( producee.Name, location.Value, self.Owner );
|
||||
newUnit.traits.Get<IFacing>().Facing = CreationFacing( self, newUnit ); ;
|
||||
var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary
|
||||
{
|
||||
new LocationInit( location.Value ),
|
||||
new OwnerInit( self.Owner ),
|
||||
});
|
||||
|
||||
var pi = self.Info.Traits.Get<ProductionInfo>();
|
||||
var rp = self.traits.GetOrDefault<RallyPoint>();
|
||||
|
||||
@@ -42,6 +42,8 @@ namespace OpenRA.Mods.RA
|
||||
public Aircraft( ActorInitializer init , AircraftInfo info)
|
||||
{
|
||||
this.Location = init.Get<LocationInit,int2>();
|
||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing;
|
||||
this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0;
|
||||
Info = info;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,13 @@ namespace OpenRA.Mods.RA
|
||||
[Sync]
|
||||
public int Facing { get; set; }
|
||||
public int ROT { get { return 0; } }
|
||||
public int InitialFacing { get { return 0; } }
|
||||
public int InitialFacing { get { return 128; } }
|
||||
|
||||
public Husk(ActorInitializer init)
|
||||
{
|
||||
this.self = init.self;
|
||||
this.location = init.Get<LocationInit,int2>();
|
||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : 128;
|
||||
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, this);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -26,9 +27,13 @@ namespace OpenRA.Mods.RA
|
||||
self.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var info = self.Info.Traits.Get<LeavesHuskInfo>();
|
||||
var husk = w.CreateActor(info.HuskActor, self.Location, self.Owner);
|
||||
husk.CenterLocation = self.CenterLocation;
|
||||
husk.traits.Get<IFacing>().Facing = self.traits.Get<IFacing>().Facing;
|
||||
|
||||
var husk = w.CreateActor(info.HuskActor, new TypeDictionary
|
||||
{
|
||||
new LocationInit( self.Location ),
|
||||
new OwnerInit( self.Owner ),
|
||||
new FacingInit( self.traits.Get<IFacing>().Facing ),
|
||||
});
|
||||
|
||||
var turreted = self.traits.GetOrDefault<Turreted>();
|
||||
if (turreted != null)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Orders;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -57,12 +58,16 @@ namespace OpenRA.Mods.RA
|
||||
var startPos = owner.World.ChooseRandomEdgeCell();
|
||||
owner.World.AddFrameEndTask(w =>
|
||||
{
|
||||
var flareType = (Info as ParatroopersPowerInfo).FlareType;
|
||||
var flare = flareType != null ? w.CreateActor(flareType, p, owner) : null;
|
||||
var info = (Info as ParatroopersPowerInfo);
|
||||
var flare = info.FlareType != null ? w.CreateActor(info.FlareType, p, owner) : null;
|
||||
|
||||
var a = w.CreateActor((Info as ParatroopersPowerInfo).UnitType, startPos, owner);
|
||||
a.traits.Get<IFacing>().Facing = Util.GetFacing(p - startPos, 0);
|
||||
a.traits.Get<IMove>().Altitude = a.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||
var a = w.CreateActor(info.UnitType, new TypeDictionary
|
||||
{
|
||||
new LocationInit( startPos ),
|
||||
new OwnerInit( owner ),
|
||||
new FacingInit( Util.GetFacing(p - startPos, 0) ),
|
||||
new AltitudeInit( Rules.Info[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude ),
|
||||
});
|
||||
|
||||
a.CancelActivity();
|
||||
a.QueueActivity(new FlyCircle(p));
|
||||
|
||||
@@ -12,6 +12,7 @@ using OpenRA.Mods.RA.Activities;
|
||||
using OpenRA.Orders;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Traits.Activities;
|
||||
using OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
@@ -45,9 +46,13 @@ namespace OpenRA.Mods.RA
|
||||
|
||||
var enterCell = self.World.ChooseRandomEdgeCell();
|
||||
|
||||
var plane = self.World.CreateActor("U2", enterCell, self.Owner);
|
||||
plane.traits.Get<IMove>().Altitude = plane.Info.Traits.Get<PlaneInfo>().CruiseAltitude;
|
||||
plane.traits.Get<IFacing>().Facing = Util.GetFacing(order.TargetLocation - enterCell, 0);
|
||||
var plane = self.World.CreateActor("u2", new TypeDictionary
|
||||
{
|
||||
new LocationInit( enterCell ),
|
||||
new OwnerInit( self.Owner ),
|
||||
new FacingInit( Util.GetFacing(order.TargetLocation - enterCell, 0) ),
|
||||
new AltitudeInit( Rules.Info["u2"].Traits.Get<PlaneInfo>().CruiseAltitude ),
|
||||
});
|
||||
|
||||
plane.CancelActivity();
|
||||
plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation)));
|
||||
|
||||
Reference in New Issue
Block a user