Rewrite husks using world coords.
This commit is contained in:
@@ -9,88 +9,79 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Traits;
|
|
||||||
using OpenRA.Mods.RA.Move;
|
using OpenRA.Mods.RA.Move;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
class HuskInfo : ITraitInfo, IFacingInfo
|
class HuskInfo : ITraitInfo, IFacingInfo
|
||||||
{
|
{
|
||||||
public object Create( ActorInitializer init ) { return new Husk( init ); }
|
public readonly string[] AllowedTerrain = { };
|
||||||
|
|
||||||
|
public object Create(ActorInitializer init) { return new Husk(init, this); }
|
||||||
|
|
||||||
public int GetInitialFacing() { return 128; }
|
public int GetInitialFacing() { return 128; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class Husk : IOccupySpace, IFacing, ISync
|
class Husk : IPositionable, IFacing, ISync
|
||||||
{
|
{
|
||||||
[Sync] CPos location;
|
readonly HuskInfo info;
|
||||||
[Sync] PPos PxPosition;
|
readonly Actor self;
|
||||||
|
|
||||||
public WPos CenterPosition { get { return PxPosition.ToWPos(0); } }
|
[Sync] public CPos TopLeft { get; private set; }
|
||||||
|
[Sync] public WPos CenterPosition { get; private set; }
|
||||||
|
[Sync] public int Facing { get; set; }
|
||||||
|
|
||||||
|
public int ROT { get { return 0; } }
|
||||||
public int Altitude { get { return 0; } set { } }
|
public int Altitude { get { return 0; } set { } }
|
||||||
|
|
||||||
[Sync] public int Facing { get; set; }
|
public Husk(ActorInitializer init, HuskInfo info)
|
||||||
public int ROT { get { return 0; } }
|
|
||||||
|
|
||||||
public Husk(ActorInitializer init)
|
|
||||||
{
|
{
|
||||||
var self = init.self;
|
this.info = info;
|
||||||
location = init.Get<LocationInit, CPos>();
|
this.self = init.self;
|
||||||
PxPosition = init.Contains<CenterLocationInit>() ? init.Get<CenterLocationInit, PPos>() : Util.CenterOfCell(location);
|
|
||||||
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : 128;
|
|
||||||
|
|
||||||
var speed = init.Contains<HuskSpeedInit>() ? init.Get<HuskSpeedInit,int>() : 0;
|
TopLeft = init.Get<LocationInit, CPos>();
|
||||||
if (speed > 0)
|
var ppos = init.Contains<CenterLocationInit>() ? init.Get<CenterLocationInit, PPos>() : Util.CenterOfCell(TopLeft);
|
||||||
{
|
CenterPosition = ppos.ToWPos(0);
|
||||||
var to = Util.CenterOfCell(location);
|
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 128;
|
||||||
var length = (int)((to - PxPosition).Length * 3 / speed);
|
|
||||||
self.QueueActivity(new DragHusk(PxPosition, to, length, this));
|
var speed = init.Contains<HuskSpeedInit>() ? init.Get<HuskSpeedInit, int>() : 0;
|
||||||
}
|
var distance = (TopLeft.CenterPosition - CenterPosition).Length;
|
||||||
|
if (speed > 0 && distance > 0)
|
||||||
|
self.QueueActivity(new Drag(CenterPosition, TopLeft.CenterPosition, distance / speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CPos TopLeft { get { return location; } }
|
|
||||||
|
|
||||||
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
|
public IEnumerable<Pair<CPos, SubCell>> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); }
|
||||||
|
public bool CanEnterCell(CPos cell)
|
||||||
class DragHusk : Activity
|
|
||||||
{
|
{
|
||||||
Husk husk;
|
if (!self.World.Map.IsInMap(cell.X, cell.Y))
|
||||||
PPos endLocation;
|
return false;
|
||||||
PPos startLocation;
|
|
||||||
int length;
|
|
||||||
|
|
||||||
public DragHusk(PPos start, PPos end, int length, Husk husk)
|
if (!info.AllowedTerrain.Contains(self.World.GetTerrainType(cell)))
|
||||||
{
|
return false;
|
||||||
startLocation = start;
|
|
||||||
endLocation = end;
|
|
||||||
this.length = length;
|
|
||||||
this.husk = husk;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ticks = 0;
|
return !self.World.ActorMap.AnyUnitsAt(cell);
|
||||||
public override Activity Tick( Actor self )
|
}
|
||||||
{
|
|
||||||
if (ticks >= length || length <= 1)
|
|
||||||
{
|
|
||||||
husk.PxPosition = endLocation;
|
|
||||||
return NextActivity;
|
|
||||||
}
|
|
||||||
|
|
||||||
husk.PxPosition = PPos.Lerp(startLocation, endLocation, ticks++, length - 1);
|
public void SetPosition(Actor self, CPos cell) { SetPosition(self, cell.CenterPosition); }
|
||||||
return this;
|
public void SetVisualPosition(Actor self, WPos pos) { CenterPosition = pos; }
|
||||||
}
|
|
||||||
|
|
||||||
public override IEnumerable<Target> GetTargets( Actor self ) { yield break; }
|
public void SetPosition(Actor self, WPos pos)
|
||||||
public override void Cancel( Actor self ) { }
|
{
|
||||||
|
self.World.ActorMap.Remove(self, this);
|
||||||
|
CenterPosition = pos;
|
||||||
|
TopLeft = pos.ToCPos();
|
||||||
|
self.World.ActorMap.Add(self, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class HuskSpeedInit : IActorInit<int>
|
public class HuskSpeedInit : IActorInit<int>
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey] public readonly int value = 0;
|
[FieldFromYamlKey] readonly int value = 0;
|
||||||
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(World world) { return value; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (mobile != null)
|
if (mobile != null)
|
||||||
{
|
{
|
||||||
if (!mobile.CanEnterCell(self.Location, self, false)) return;
|
if (!mobile.CanEnterCell(self.Location, self, false)) return;
|
||||||
td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location) * 3 * Game.CellSize / 1024));
|
td.Add(new HuskSpeedInit(mobile.MovementSpeedForCell(self, self.Location)));
|
||||||
}
|
}
|
||||||
|
|
||||||
var aircraft = self.TraitOrDefault<Aircraft>();
|
var aircraft = self.TraitOrDefault<Aircraft>();
|
||||||
|
|||||||
@@ -28,19 +28,25 @@ namespace OpenRA.Mods.RA.Move
|
|||||||
|
|
||||||
public override Activity Tick(Actor self)
|
public override Activity Tick(Actor self)
|
||||||
{
|
{
|
||||||
var mobile = self.Trait<Mobile>();
|
var positionable = self.Trait<IPositionable>();
|
||||||
|
var mobile = positionable as Mobile;
|
||||||
|
|
||||||
var pos = length > 1
|
var pos = length > 1
|
||||||
? WPos.Lerp(start, end, ticks, length - 1)
|
? WPos.Lerp(start, end, ticks, length - 1)
|
||||||
: end;
|
: end;
|
||||||
|
|
||||||
mobile.SetVisualPosition(self, pos);
|
positionable.SetVisualPosition(self, pos);
|
||||||
if (++ticks >= length)
|
if (++ticks >= length)
|
||||||
{
|
{
|
||||||
mobile.IsMoving = false;
|
if (mobile != null)
|
||||||
|
mobile.IsMoving = false;
|
||||||
|
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
mobile.IsMoving = true;
|
if (mobile != null)
|
||||||
|
mobile.IsMoving = true;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -449,6 +449,7 @@
|
|||||||
Armor:
|
Armor:
|
||||||
Type: Light
|
Type: Light
|
||||||
Husk:
|
Husk:
|
||||||
|
AllowedTerrain: Clear, Rough, Road, Tiberium, BlueTiberium, Beach
|
||||||
HiddenUnderFog:
|
HiddenUnderFog:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
Burns:
|
Burns:
|
||||||
|
|||||||
@@ -78,6 +78,7 @@
|
|||||||
Armor:
|
Armor:
|
||||||
Type: Light
|
Type: Light
|
||||||
Husk:
|
Husk:
|
||||||
|
AllowedTerrain: Sand, Rock, Transition, Concrete, Spice, SpiceBlobs, Dune
|
||||||
HiddenUnderFog:
|
HiddenUnderFog:
|
||||||
AppearsOnRadar:
|
AppearsOnRadar:
|
||||||
Burns:
|
Burns:
|
||||||
|
|||||||
@@ -373,6 +373,7 @@
|
|||||||
|
|
||||||
^Husk:
|
^Husk:
|
||||||
Husk:
|
Husk:
|
||||||
|
AllowedTerrain: Clear, Rough, Road, Ore, Gems, Beach
|
||||||
RenderUnit:
|
RenderUnit:
|
||||||
Health:
|
Health:
|
||||||
HP: 140
|
HP: 140
|
||||||
|
|||||||
Reference in New Issue
Block a user