Refactor Mobile.TeleportTo -> IMove.SetPosition
This commit is contained in:
@@ -66,9 +66,9 @@ namespace OpenRA.Traits
|
|||||||
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, this);
|
self.World.WorldActor.traits.Get<UnitInfluence>().Add(self, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void TeleportTo(Actor self, int2 xy)
|
public void SetPosition(Actor self, int2 cell)
|
||||||
{
|
{
|
||||||
SetLocation( xy, xy );
|
SetLocation( cell, cell );
|
||||||
self.CenterLocation = Util.CenterOfCell(fromCell);
|
self.CenterLocation = Util.CenterOfCell(fromCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ namespace OpenRA.Traits
|
|||||||
UnitMovementType GetMovementType();
|
UnitMovementType GetMovementType();
|
||||||
bool CanEnterCell(int2 location);
|
bool CanEnterCell(int2 location);
|
||||||
IEnumerable<float2> GetCurrentPath(Actor self);
|
IEnumerable<float2> GetCurrentPath(Actor self);
|
||||||
|
void SetPosition(Actor self, int2 cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IOffsetCenterLocation { float2 CenterOffset { get; } }
|
public interface IOffsetCenterLocation { float2 CenterOffset { get; } }
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.GameRules;
|
using OpenRA.GameRules;
|
||||||
using OpenRA.Mods.RA;
|
using OpenRA.Mods.RA;
|
||||||
using OpenRA.Mods.RA.Activities;
|
using OpenRA.Mods.RA.Activities;
|
||||||
@@ -66,7 +67,7 @@ namespace OpenRA.Mods.Cnc
|
|||||||
self.World.AddFrameEndTask(ww =>
|
self.World.AddFrameEndTask(ww =>
|
||||||
{
|
{
|
||||||
ww.Add(actor);
|
ww.Add(actor);
|
||||||
actor.traits.Get<Mobile>().TeleportTo(actor, self.Location + unloadOffset);
|
actor.traits.WithInterface<IMove>().FirstOrDefault().SetPosition(actor, self.Location + unloadOffset);
|
||||||
newUnit.traits.Get<Unit>().Facing = 192;
|
newUnit.traits.Get<Unit>().Facing = 192;
|
||||||
actor.CancelActivity();
|
actor.CancelActivity();
|
||||||
actor.QueueActivity(new Move(self.Location + exitOffset, self));
|
actor.QueueActivity(new Move(self.Location + exitOffset, self));
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
using System.Linq;
|
||||||
namespace OpenRA.Mods.RA.Activities
|
namespace OpenRA.Mods.RA.Activities
|
||||||
{
|
{
|
||||||
class Leap : IActivity
|
class Leap : IActivity
|
||||||
@@ -51,7 +52,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
|
|
||||||
if (t >= 1f)
|
if (t >= 1f)
|
||||||
{
|
{
|
||||||
self.traits.Get<Mobile>().TeleportTo(self, target.Location);
|
self.traits.WithInterface<IMove>().FirstOrDefault().SetPosition(self, target.Location);
|
||||||
target.InflictDamage(self, target.Health, null); // kill it
|
target.InflictDamage(self, target.Health, null); // kill it
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Activities
|
namespace OpenRA.Mods.RA.Activities
|
||||||
@@ -35,8 +36,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
|
|
||||||
public IActivity Tick(Actor self)
|
public IActivity Tick(Actor self)
|
||||||
{
|
{
|
||||||
var mobile = self.traits.Get<Mobile>();
|
self.traits.WithInterface<IMove>().FirstOrDefault().SetPosition(self, destination);
|
||||||
mobile.TeleportTo(self, destination);
|
|
||||||
return NextActivity;
|
return NextActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA.Activities
|
|||||||
self.World.AddFrameEndTask(w =>
|
self.World.AddFrameEndTask(w =>
|
||||||
{
|
{
|
||||||
w.Add(actor);
|
w.Add(actor);
|
||||||
actor.traits.Get<Mobile>().TeleportTo(actor, self.Location);
|
actor.traits.WithInterface<IMove>().FirstOrDefault().SetPosition(actor, self.Location);
|
||||||
actor.CancelActivity();
|
actor.CancelActivity();
|
||||||
actor.QueueActivity(new Move(exitTile.Value, 0));
|
actor.QueueActivity(new Move(exitTile.Value, 0));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -49,6 +49,12 @@ namespace OpenRA.Mods.RA
|
|||||||
get { return Location; }
|
get { return Location; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetPosition(Actor self, int2 cell)
|
||||||
|
{
|
||||||
|
Location = cell;
|
||||||
|
self.CenterLocation = Util.CenterOfCell(cell);
|
||||||
|
}
|
||||||
|
|
||||||
public bool AircraftCanEnter(Actor self, Actor a)
|
public bool AircraftCanEnter(Actor self, Actor a)
|
||||||
{
|
{
|
||||||
var aircraft = self.Info.Traits.Get<AircraftInfo>();
|
var aircraft = self.Info.Traits.Get<AircraftInfo>();
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using OpenRA.Effects;
|
using OpenRA.Effects;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -67,8 +68,11 @@ namespace OpenRA.Mods.RA.Effects
|
|||||||
w.Remove(this);
|
w.Remove(this);
|
||||||
var loc = Traits.Util.CellContaining(location);
|
var loc = Traits.Util.CellContaining(location);
|
||||||
cargo.CancelActivity();
|
cargo.CancelActivity();
|
||||||
if (cargo.traits.Contains<Mobile>())
|
|
||||||
cargo.traits.Get<Mobile>().TeleportTo(cargo, loc);
|
var mobile = cargo.traits.WithInterface<IMove>().FirstOrDefault();
|
||||||
|
|
||||||
|
if (mobile != null)
|
||||||
|
mobile.SetPosition(cargo, loc);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cargo.CenterLocation = Traits.Util.CenterOfCell(loc);
|
cargo.CenterLocation = Traits.Util.CenterOfCell(loc);
|
||||||
|
|||||||
Reference in New Issue
Block a user