add IHasLocation
This commit is contained in:
@@ -26,7 +26,8 @@ namespace OpenRA
|
||||
public readonly World World;
|
||||
public readonly uint ActorID;
|
||||
|
||||
public int2 Location { get { return Trait<IOccupySpace>().TopLeft; } }
|
||||
public int2 Location { get { return Trait<IOccupySpace>().TopLeft; } }
|
||||
public float2 CenterLocation { get { return Trait<IHasLocation>().PxPosition; } }
|
||||
[Sync]
|
||||
public Player Owner;
|
||||
|
||||
@@ -52,9 +53,6 @@ namespace OpenRA
|
||||
AddTrait(trait.Create(init));
|
||||
}
|
||||
|
||||
if( CenterLocation == float2.Zero && HasTrait<IOccupySpace>() )
|
||||
CenterLocation = Traits.Util.CenterOfCell(Location);
|
||||
|
||||
Size = Lazy.New(() =>
|
||||
{
|
||||
var si = Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
@@ -99,8 +97,6 @@ namespace OpenRA
|
||||
get { return currentActivity == null || currentActivity is Idle; }
|
||||
}
|
||||
|
||||
public float2 CenterLocation;
|
||||
|
||||
OpenRA.FileFormats.Lazy<float2> Size;
|
||||
|
||||
public IEnumerable<Renderable> Render()
|
||||
|
||||
@@ -16,11 +16,11 @@ namespace OpenRA.Traits.Activities
|
||||
{
|
||||
IActivity NextActivity { get; set; }
|
||||
|
||||
float2 endLocation;
|
||||
float2 startLocation;
|
||||
int2 endLocation;
|
||||
int2 startLocation;
|
||||
int length;
|
||||
|
||||
public Drag(float2 start, float2 end, int length)
|
||||
public Drag(int2 start, int2 end, int length)
|
||||
{
|
||||
startLocation = start;
|
||||
endLocation = end;
|
||||
@@ -29,15 +29,16 @@ namespace OpenRA.Traits.Activities
|
||||
|
||||
int ticks = 0;
|
||||
public IActivity Tick( Actor self )
|
||||
{
|
||||
self.CenterLocation = float2.Lerp(startLocation, endLocation, (float)ticks/(length-1));
|
||||
{
|
||||
var mobile = self.Trait<Mobile>();
|
||||
mobile.PxPosition = int2.Lerp( startLocation, endLocation, ticks, length - 1 );
|
||||
|
||||
if (++ticks >= length)
|
||||
{
|
||||
self.Trait<Mobile>().IsMoving = false;
|
||||
mobile.IsMoving = false;
|
||||
return NextActivity;
|
||||
}
|
||||
self.Trait<Mobile>().IsMoving = true;
|
||||
mobile.IsMoving = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -248,7 +248,7 @@ namespace OpenRA.Traits.Activities
|
||||
public override IEnumerable<float2> GetCurrentPath()
|
||||
{
|
||||
if( path != null )
|
||||
return Enumerable.Reverse(path).Select( c => Util.CenterOfCell(c) );
|
||||
return Enumerable.Reverse(path).Select( c => (float2)Util.CenterOfCell(c) );
|
||||
if( destination != null )
|
||||
return new float2[] { destination.Value };
|
||||
return new float2[ 0 ];
|
||||
@@ -257,12 +257,12 @@ namespace OpenRA.Traits.Activities
|
||||
abstract class MovePart : IActivity
|
||||
{
|
||||
public readonly Move move;
|
||||
public readonly float2 from, to;
|
||||
public readonly int2 from, to;
|
||||
public readonly int fromFacing, toFacing;
|
||||
public int moveFraction;
|
||||
public readonly int moveFractionTotal;
|
||||
|
||||
public MovePart( Move move, float2 from, float2 to, int fromFacing, int toFacing, int startingFraction )
|
||||
public MovePart( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction )
|
||||
{
|
||||
this.move = move;
|
||||
this.from = from;
|
||||
@@ -270,7 +270,7 @@ namespace OpenRA.Traits.Activities
|
||||
this.fromFacing = fromFacing;
|
||||
this.toFacing = toFacing;
|
||||
this.moveFraction = startingFraction;
|
||||
this.moveFractionTotal = (int)(( to - from ).Length*3);
|
||||
this.moveFractionTotal = (int)( ( to - from ) * 3 ).Length;
|
||||
}
|
||||
|
||||
public void Cancel( Actor self )
|
||||
@@ -311,14 +311,12 @@ namespace OpenRA.Traits.Activities
|
||||
|
||||
void UpdateCenterLocation( Actor self, Mobile mobile )
|
||||
{
|
||||
var frac = (float)moveFraction / moveFractionTotal;
|
||||
|
||||
self.CenterLocation = float2.Lerp( from, to, frac );
|
||||
mobile.PxPosition = int2.Lerp( from, to, moveFraction, moveFractionTotal );
|
||||
|
||||
if( moveFraction >= moveFractionTotal )
|
||||
mobile.Facing = toFacing & 0xFF;
|
||||
else
|
||||
mobile.Facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF;
|
||||
mobile.Facing = int2.Lerp( fromFacing, toFacing, moveFraction, moveFractionTotal ) & 0xFF;
|
||||
}
|
||||
|
||||
protected abstract MovePart OnComplete( Actor self, Mobile mobile, Move parent );
|
||||
@@ -331,7 +329,7 @@ namespace OpenRA.Traits.Activities
|
||||
|
||||
class MoveFirstHalf : MovePart
|
||||
{
|
||||
public MoveFirstHalf( Move move, float2 from, float2 to, int fromFacing, int toFacing, int startingFraction )
|
||||
public MoveFirstHalf( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction )
|
||||
: base( move, from, to, fromFacing, toFacing, startingFraction )
|
||||
{
|
||||
}
|
||||
@@ -370,14 +368,14 @@ namespace OpenRA.Traits.Activities
|
||||
|
||||
class MoveSecondHalf : MovePart
|
||||
{
|
||||
public MoveSecondHalf( Move move, float2 from, float2 to, int fromFacing, int toFacing, int startingFraction )
|
||||
public MoveSecondHalf( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction )
|
||||
: base( move, from, to, fromFacing, toFacing, startingFraction )
|
||||
{
|
||||
}
|
||||
|
||||
protected override MovePart OnComplete( Actor self, Mobile mobile, Move parent )
|
||||
{
|
||||
self.CenterLocation = Util.CenterOfCell( mobile.toCell );
|
||||
mobile.PxPosition = Util.CenterOfCell( mobile.toCell );
|
||||
mobile.SetLocation( mobile.toCell, mobile.toCell );
|
||||
mobile.FinishedMoving(self);
|
||||
return null;
|
||||
|
||||
@@ -47,13 +47,13 @@ namespace OpenRA.Traits
|
||||
|
||||
readonly PowerManager PlayerPower;
|
||||
|
||||
public int2 PxPosition { get { return ( 2 * topLeft + Info.Dimensions ) * Game.CellSize / 2; } }
|
||||
|
||||
public Building(ActorInitializer init)
|
||||
{
|
||||
this.self = init.self;
|
||||
this.topLeft = init.Get<LocationInit,int2>();
|
||||
Info = self.Info.Traits.Get<BuildingInfo>();
|
||||
self.CenterLocation = Game.CellSize
|
||||
* ((float2)topLeft + .5f * (float2)Info.Dimensions);
|
||||
|
||||
PlayerPower = init.self.Owner.PlayerActor.Trait<PowerManager>();
|
||||
}
|
||||
|
||||
@@ -81,17 +81,11 @@ namespace OpenRA.Traits
|
||||
public int InitialFacing { get { return Info.InitialFacing; } }
|
||||
|
||||
[Sync]
|
||||
public int2 fromCell
|
||||
{
|
||||
get { return __fromCell; }
|
||||
}
|
||||
|
||||
public int2 PxPosition { get; set; }
|
||||
[Sync]
|
||||
public int2 toCell
|
||||
{
|
||||
get { return __toCell; }
|
||||
}
|
||||
|
||||
public int2 fromCell { get { return __fromCell; } }
|
||||
[Sync]
|
||||
public int2 toCell { get { return __toCell; } }
|
||||
[Sync]
|
||||
public int PathHash; // written by Move.EvalPath, to temporarily debug this crap.
|
||||
|
||||
@@ -116,6 +110,7 @@ namespace OpenRA.Traits
|
||||
if (init.Contains<LocationInit>())
|
||||
{
|
||||
this.__fromCell = this.__toCell = init.Get<LocationInit,int2>();
|
||||
this.PxPosition = Util.CenterOfCell( fromCell );
|
||||
AddInfluence();
|
||||
}
|
||||
|
||||
@@ -126,7 +121,14 @@ namespace OpenRA.Traits
|
||||
public void SetPosition(Actor self, int2 cell)
|
||||
{
|
||||
SetLocation( cell, cell );
|
||||
self.CenterLocation = Util.CenterOfCell(fromCell);
|
||||
PxPosition = Util.CenterOfCell(fromCell);
|
||||
}
|
||||
|
||||
public void SetPxPosition( Actor self, int2 px )
|
||||
{
|
||||
var cell = Util.CellContaining( px );
|
||||
SetLocation( cell, cell );
|
||||
PxPosition = px;
|
||||
}
|
||||
|
||||
public int OrderPriority(Actor self, int2 xy, MouseInput mi, Actor underCursor)
|
||||
|
||||
@@ -63,7 +63,13 @@ namespace OpenRA.Traits
|
||||
|
||||
public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); }
|
||||
public interface IRadarColorModifier { Color RadarColorOverride(Actor self); }
|
||||
public interface IOccupySpace
|
||||
|
||||
public interface IHasLocation
|
||||
{
|
||||
int2 PxPosition { get; }
|
||||
}
|
||||
|
||||
public interface IOccupySpace : IHasLocation
|
||||
{
|
||||
int2 TopLeft { get; }
|
||||
IEnumerable<int2> OccupiedCells();
|
||||
@@ -97,15 +103,15 @@ namespace OpenRA.Traits
|
||||
public interface IPips { IEnumerable<PipType> GetPips(Actor self); }
|
||||
public interface ITags { IEnumerable<TagType> GetTags(); }
|
||||
|
||||
public interface ITeleportable /* crap name! */
|
||||
public interface ITeleportable : IHasLocation /* crap name! */
|
||||
{
|
||||
bool CanEnterCell(int2 location);
|
||||
void SetPosition(Actor self, int2 cell);
|
||||
void SetPxPosition(Actor self, int2 px);
|
||||
}
|
||||
|
||||
public interface IMove : ITeleportable
|
||||
{
|
||||
float MovementSpeedForCell(Actor self, int2 cell);
|
||||
int Altitude { get; set; }
|
||||
}
|
||||
|
||||
@@ -226,6 +232,7 @@ namespace OpenRA.Traits
|
||||
public static readonly Target None = new Target();
|
||||
|
||||
public bool IsValid { get { return valid && (actor == null || actor.IsInWorld); } }
|
||||
public int2 PxPosition { get { return actor != null ? actor.Trait<IHasLocation>().PxPosition : pos.ToInt2(); } }
|
||||
public float2 CenterLocation { get { return actor != null ? actor.CenterLocation : pos.ToInt2(); } }
|
||||
|
||||
public Actor Actor { get { return actor; } }
|
||||
|
||||
@@ -82,14 +82,14 @@ namespace OpenRA.Traits
|
||||
ecc * (cosAngle * v.Y - sinAngle * v.X));
|
||||
}
|
||||
|
||||
public static float2 CenterOfCell(int2 loc)
|
||||
public static int2 CenterOfCell(int2 loc)
|
||||
{
|
||||
return new float2(12, 12) + Game.CellSize * (float2)loc;
|
||||
return new int2(Game.CellSize/2, Game.CellSize/2) + Game.CellSize * loc;
|
||||
}
|
||||
|
||||
public static float2 BetweenCells(int2 from, int2 to)
|
||||
public static int2 BetweenCells(int2 from, int2 to)
|
||||
{
|
||||
return 0.5f * (CenterOfCell(from) + CenterOfCell(to));
|
||||
return int2.Lerp( CenterOfCell( from ), CenterOfCell( to ), 1, 2 );
|
||||
}
|
||||
|
||||
public static int2 AsInt2(this int[] xs) { return new int2(xs[0], xs[1]); }
|
||||
|
||||
@@ -45,9 +45,9 @@ namespace OpenRA.Traits
|
||||
for (var i = 0; i <= bins.GetUpperBound(0); i++)
|
||||
bins[i, j].Clear();
|
||||
|
||||
foreach (var a in self.World.Actors)
|
||||
foreach (var a in self.World.Queries.WithTrait<IHasLocation>())
|
||||
{
|
||||
var bounds = a.GetBounds(true);
|
||||
var bounds = a.Actor.GetBounds(true);
|
||||
|
||||
if (bounds.Right <= Game.CellSize * self.World.Map.XOffset) continue;
|
||||
if (bounds.Bottom <= Game.CellSize * self.World.Map.YOffset) continue;
|
||||
@@ -61,7 +61,7 @@ namespace OpenRA.Traits
|
||||
|
||||
for (var j = j1; j <= j2; j++)
|
||||
for (var i = i1; i <= i2; i++)
|
||||
bins[i, j].Add(a);
|
||||
bins[i, j].Add(a.Actor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user