diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index a399e3b7b2..9e18197c68 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -9,88 +9,79 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.FileFormats; -using OpenRA.Traits; using OpenRA.Mods.RA.Move; +using OpenRA.Traits; namespace OpenRA.Mods.RA { 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; } } - class Husk : IOccupySpace, IFacing, ISync + class Husk : IPositionable, IFacing, ISync { - [Sync] CPos location; - [Sync] PPos PxPosition; + readonly HuskInfo info; + 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 { } } - [Sync] public int Facing { get; set; } - public int ROT { get { return 0; } } - - public Husk(ActorInitializer init) + public Husk(ActorInitializer init, HuskInfo info) { - var self = init.self; - location = init.Get(); - PxPosition = init.Contains() ? init.Get() : Util.CenterOfCell(location); - Facing = init.Contains() ? init.Get() : 128; + this.info = info; + this.self = init.self; - var speed = init.Contains() ? init.Get() : 0; - if (speed > 0) - { - var to = Util.CenterOfCell(location); - var length = (int)((to - PxPosition).Length * 3 / speed); - self.QueueActivity(new DragHusk(PxPosition, to, length, this)); - } + TopLeft = init.Get(); + var ppos = init.Contains() ? init.Get() : Util.CenterOfCell(TopLeft); + CenterPosition = ppos.ToWPos(0); + Facing = init.Contains() ? init.Get() : 128; + + var speed = init.Contains() ? init.Get() : 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> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); } - - class DragHusk : Activity + public bool CanEnterCell(CPos cell) { - Husk husk; - PPos endLocation; - PPos startLocation; - int length; + if (!self.World.Map.IsInMap(cell.X, cell.Y)) + return false; - public DragHusk(PPos start, PPos end, int length, Husk husk) - { - startLocation = start; - endLocation = end; - this.length = length; - this.husk = husk; - } + if (!info.AllowedTerrain.Contains(self.World.GetTerrainType(cell))) + return false; - int ticks = 0; - public override Activity Tick( Actor self ) - { - if (ticks >= length || length <= 1) - { - husk.PxPosition = endLocation; - return NextActivity; - } + return !self.World.ActorMap.AnyUnitsAt(cell); + } - husk.PxPosition = PPos.Lerp(startLocation, endLocation, ticks++, length - 1); - return this; - } + public void SetPosition(Actor self, CPos cell) { SetPosition(self, cell.CenterPosition); } + public void SetVisualPosition(Actor self, WPos pos) { CenterPosition = pos; } - public override IEnumerable GetTargets( Actor self ) { yield break; } - public override void Cancel( Actor self ) { } + public void SetPosition(Actor self, WPos pos) + { + self.World.ActorMap.Remove(self, this); + CenterPosition = pos; + TopLeft = pos.ToCPos(); + self.World.ActorMap.Add(self, this); } } public class HuskSpeedInit : IActorInit { - [FieldFromYamlKey] public readonly int value = 0; + [FieldFromYamlKey] readonly int value = 0; public HuskSpeedInit() { } - public HuskSpeedInit( int init ) { value = init; } - public int Value( World world ) { return value; } + public HuskSpeedInit(int init) { value = init; } + public int Value(World world) { return value; } } } diff --git a/OpenRA.Mods.RA/LeavesHusk.cs b/OpenRA.Mods.RA/LeavesHusk.cs index f5efe15fc1..7b04b1d9c2 100644 --- a/OpenRA.Mods.RA/LeavesHusk.cs +++ b/OpenRA.Mods.RA/LeavesHusk.cs @@ -49,7 +49,7 @@ namespace OpenRA.Mods.RA if (mobile != null) { 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(); diff --git a/OpenRA.Mods.RA/Move/Drag.cs b/OpenRA.Mods.RA/Move/Drag.cs index 17eeb0d92e..41c8ff89ed 100755 --- a/OpenRA.Mods.RA/Move/Drag.cs +++ b/OpenRA.Mods.RA/Move/Drag.cs @@ -28,19 +28,25 @@ namespace OpenRA.Mods.RA.Move public override Activity Tick(Actor self) { - var mobile = self.Trait(); + var positionable = self.Trait(); + var mobile = positionable as Mobile; + var pos = length > 1 ? WPos.Lerp(start, end, ticks, length - 1) : end; - mobile.SetVisualPosition(self, pos); + positionable.SetVisualPosition(self, pos); if (++ticks >= length) { - mobile.IsMoving = false; + if (mobile != null) + mobile.IsMoving = false; + return NextActivity; } - mobile.IsMoving = true; + if (mobile != null) + mobile.IsMoving = true; + return this; } diff --git a/mods/cnc/rules/defaults.yaml b/mods/cnc/rules/defaults.yaml index f9b9dd77d5..91240d58a8 100644 --- a/mods/cnc/rules/defaults.yaml +++ b/mods/cnc/rules/defaults.yaml @@ -449,6 +449,7 @@ Armor: Type: Light Husk: + AllowedTerrain: Clear, Rough, Road, Tiberium, BlueTiberium, Beach HiddenUnderFog: AppearsOnRadar: Burns: diff --git a/mods/d2k/rules/defaults.yaml b/mods/d2k/rules/defaults.yaml index f465db8147..af1f33ef81 100644 --- a/mods/d2k/rules/defaults.yaml +++ b/mods/d2k/rules/defaults.yaml @@ -78,6 +78,7 @@ Armor: Type: Light Husk: + AllowedTerrain: Sand, Rock, Transition, Concrete, Spice, SpiceBlobs, Dune HiddenUnderFog: AppearsOnRadar: Burns: diff --git a/mods/ra/rules/defaults.yaml b/mods/ra/rules/defaults.yaml index b9abf0f52b..d43f5c585e 100644 --- a/mods/ra/rules/defaults.yaml +++ b/mods/ra/rules/defaults.yaml @@ -373,6 +373,7 @@ ^Husk: Husk: + AllowedTerrain: Clear, Rough, Road, Ore, Gems, Beach RenderUnit: Health: HP: 140