Drag husks to their final location. Fixes #730.
This commit is contained in:
@@ -50,7 +50,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
T Value( World world );
|
T Value( World world );
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FacingInit : IActorInit<int>
|
public class FacingInit : IActorInit<int>
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey]
|
[FieldFromYamlKey]
|
||||||
@@ -68,7 +68,7 @@ namespace OpenRA
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AltitudeInit : IActorInit<int>
|
public class AltitudeInit : IActorInit<int>
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey]
|
[FieldFromYamlKey]
|
||||||
@@ -105,6 +105,24 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CenterLocationInit : IActorInit<int2>
|
||||||
|
{
|
||||||
|
[FieldFromYamlKey]
|
||||||
|
public readonly int2 value = int2.Zero;
|
||||||
|
|
||||||
|
public CenterLocationInit() { }
|
||||||
|
|
||||||
|
public CenterLocationInit( int2 init )
|
||||||
|
{
|
||||||
|
value = init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int2 Value( World world )
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class OwnerInit : IActorInit<Player>
|
public class OwnerInit : IActorInit<Player>
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey]
|
[FieldFromYamlKey]
|
||||||
|
|||||||
@@ -9,8 +9,10 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using OpenRA.Traits;
|
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Mods.RA.Move;
|
||||||
|
using OpenRA.Traits.Activities;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
@@ -23,7 +25,10 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
[Sync]
|
[Sync]
|
||||||
int2 location;
|
int2 location;
|
||||||
|
|
||||||
|
[Sync]
|
||||||
|
public int2 PxPosition { get; set; }
|
||||||
|
|
||||||
[Sync]
|
[Sync]
|
||||||
public int Facing { get; set; }
|
public int Facing { get; set; }
|
||||||
public int ROT { get { return 0; } }
|
public int ROT { get { return 0; } }
|
||||||
@@ -31,13 +36,69 @@ namespace OpenRA.Mods.RA
|
|||||||
|
|
||||||
public Husk(ActorInitializer init)
|
public Husk(ActorInitializer init)
|
||||||
{
|
{
|
||||||
this.location = init.Get<LocationInit,int2>();
|
var self = init.self;
|
||||||
this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : 128;
|
location = init.Get<LocationInit,int2>();
|
||||||
|
PxPosition = init.Get<CenterLocationInit, int2>();
|
||||||
|
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : 128;
|
||||||
|
|
||||||
|
var speed = init.Contains<HuskSpeedInit>() ? init.Get<HuskSpeedInit,int>() : 0;
|
||||||
|
if (speed > 0)
|
||||||
|
{
|
||||||
|
var to = Util.CenterOfCell(location);
|
||||||
|
var length = (int)((to - PxPosition).Length * 3 / speed);
|
||||||
|
self.QueueActivity(new DragHusk(PxPosition, to, length));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int2 TopLeft { get { return location; } }
|
public int2 TopLeft { get { return location; } }
|
||||||
|
|
||||||
public IEnumerable<Pair<int2, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
|
public IEnumerable<Pair<int2, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
|
||||||
public int2 PxPosition { get { return Util.CenterOfCell( location ); } }
|
|
||||||
|
class DragHusk : Activity
|
||||||
|
{
|
||||||
|
int2 endLocation;
|
||||||
|
int2 startLocation;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
public DragHusk(int2 start, int2 end, int length)
|
||||||
|
{
|
||||||
|
startLocation = start;
|
||||||
|
endLocation = end;
|
||||||
|
this.length = length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ticks = 0;
|
||||||
|
public override Activity Tick( Actor self )
|
||||||
|
{
|
||||||
|
var husk = self.Trait<Husk>();
|
||||||
|
husk.PxPosition = int2.Lerp(startLocation, endLocation, ticks, length - 1);
|
||||||
|
|
||||||
|
if (++ticks >= length)
|
||||||
|
return NextActivity;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerable<Target> GetTargets( Actor self ) { yield break; }
|
||||||
|
public override void Cancel( Actor self ) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class HuskSpeedInit : IActorInit<int>
|
||||||
|
{
|
||||||
|
[FieldFromYamlKey]
|
||||||
|
public readonly int value = 0;
|
||||||
|
|
||||||
|
public HuskSpeedInit() { }
|
||||||
|
|
||||||
|
public HuskSpeedInit( int init )
|
||||||
|
{
|
||||||
|
value = init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Value( World world )
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using OpenRA.Traits;
|
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Mods.RA.Move;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
@@ -24,24 +25,30 @@ namespace OpenRA.Mods.RA
|
|||||||
public void Killed(Actor self, AttackInfo e)
|
public void Killed(Actor self, AttackInfo e)
|
||||||
{
|
{
|
||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
|
{
|
||||||
|
var info = self.Info.Traits.Get<LeavesHuskInfo>();
|
||||||
|
var td = new TypeDictionary()
|
||||||
{
|
{
|
||||||
var info = self.Info.Traits.Get<LeavesHuskInfo>();
|
new LocationInit( self.Location ),
|
||||||
var td = new TypeDictionary
|
new CenterLocationInit(self.CenterLocation),
|
||||||
{
|
new OwnerInit( self.Owner ),
|
||||||
new LocationInit( self.Location ),
|
new SkipMakeAnimsInit()
|
||||||
new OwnerInit( self.Owner ),
|
};
|
||||||
new SkipMakeAnimsInit()
|
|
||||||
};
|
|
||||||
|
|
||||||
if (self.HasTrait<IFacing>())
|
|
||||||
td.Add(new FacingInit( self.Trait<IFacing>().Facing ));
|
|
||||||
|
|
||||||
var husk = w.CreateActor(info.HuskActor, td);
|
if (self.HasTrait<IFacing>())
|
||||||
var turreted = self.TraitOrDefault<Turreted>();
|
td.Add(new FacingInit( self.Trait<IFacing>().Facing ));
|
||||||
if (turreted != null)
|
|
||||||
foreach (var p in husk.TraitsImplementing<ThrowsParticle>())
|
// Allows the husk to drag to its final position
|
||||||
p.InitialFacing = turreted.turretFacing;
|
var mobile = self.TraitOrDefault<Mobile>();
|
||||||
});
|
if (mobile != null)
|
||||||
|
td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location)));
|
||||||
|
|
||||||
|
var husk = w.CreateActor(info.HuskActor, td);
|
||||||
|
var turreted = self.TraitOrDefault<Turreted>();
|
||||||
|
if (turreted != null)
|
||||||
|
foreach (var p in husk.TraitsImplementing<ThrowsParticle>())
|
||||||
|
p.InitialFacing = turreted.turretFacing;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user