diff --git a/OpenRA.FileFormats/Primitives/int2.cs b/OpenRA.FileFormats/Primitives/int2.cs index 4426048304..2f05672ede 100644 --- a/OpenRA.FileFormats/Primitives/int2.cs +++ b/OpenRA.FileFormats/Primitives/int2.cs @@ -25,6 +25,7 @@ namespace OpenRA public static int2 operator -(int2 a, int2 b) { return new int2(a.X - b.X, a.Y - b.Y); } public static int2 operator *(int a, int2 b) { return new int2(a * b.X, a * b.Y); } public static int2 operator *(int2 b, int a) { return new int2(a * b.X, a * b.Y); } + public static int2 operator /(int2 a, int b) { return new int2(a.X / b, a.Y / b); } public static bool operator ==(int2 me, int2 other) { return (me.X == other.X && me.Y == other.Y); } public static bool operator !=(int2 me, int2 other) { return !(me == other); } @@ -59,5 +60,15 @@ namespace OpenRA { return (uint)((orig & 0xff000000) >> 24) | ((orig & 0x00ff0000) >> 8) | ((orig & 0x0000ff00) << 8) | ((orig & 0x000000ff) << 24); } + + public static int Lerp( int a, int b, int mul, int div ) + { + return a + ( b - a ) * mul / div; + } + + public static int2 Lerp( int2 a, int2 b, int mul, int div ) + { + return a + ( b - a ) * mul / div; + } } } diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 54da1172f1..a169328996 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -26,7 +26,8 @@ namespace OpenRA public readonly World World; public readonly uint ActorID; - public int2 Location { get { return Trait().TopLeft; } } + public int2 Location { get { return Trait().TopLeft; } } + public float2 CenterLocation { get { return Trait().PxPosition; } } [Sync] public Player Owner; @@ -52,9 +53,6 @@ namespace OpenRA AddTrait(trait.Create(init)); } - if( CenterLocation == float2.Zero && HasTrait() ) - CenterLocation = Traits.Util.CenterOfCell(Location); - Size = Lazy.New(() => { var si = Info.Traits.GetOrDefault(); @@ -99,8 +97,6 @@ namespace OpenRA get { return currentActivity == null || currentActivity is Idle; } } - public float2 CenterLocation; - OpenRA.FileFormats.Lazy Size; public IEnumerable Render() diff --git a/OpenRA.Game/Traits/Activities/Drag.cs b/OpenRA.Game/Traits/Activities/Drag.cs index 525272d731..0655f3e735 100644 --- a/OpenRA.Game/Traits/Activities/Drag.cs +++ b/OpenRA.Game/Traits/Activities/Drag.cs @@ -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.PxPosition = int2.Lerp(startLocation, endLocation, ticks, length - 1); if (++ticks >= length) { - self.Trait().IsMoving = false; + mobile.IsMoving = false; return NextActivity; } - self.Trait().IsMoving = true; + mobile.IsMoving = true; return this; } diff --git a/OpenRA.Game/Traits/Activities/Move.cs b/OpenRA.Game/Traits/Activities/Move.cs index c8ae9be1b0..4b7136fddb 100755 --- a/OpenRA.Game/Traits/Activities/Move.cs +++ b/OpenRA.Game/Traits/Activities/Move.cs @@ -248,7 +248,7 @@ namespace OpenRA.Traits.Activities public override IEnumerable 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 = ( ( 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; diff --git a/OpenRA.Game/Traits/Building.cs b/OpenRA.Game/Traits/Building.cs index 64f506f3af..b4a42cd6f7 100644 --- a/OpenRA.Game/Traits/Building.cs +++ b/OpenRA.Game/Traits/Building.cs @@ -44,16 +44,16 @@ namespace OpenRA.Traits public readonly BuildingInfo Info; [Sync] readonly int2 topLeft; - + 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(); Info = self.Info.Traits.Get(); - self.CenterLocation = Game.CellSize - * ((float2)topLeft + .5f * (float2)Info.Dimensions); PlayerPower = init.self.Owner.PlayerActor.Trait(); } diff --git a/OpenRA.Game/Traits/Mobile.cs b/OpenRA.Game/Traits/Mobile.cs index 813746954b..a5f256f81b 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -82,16 +82,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. @@ -117,6 +112,7 @@ namespace OpenRA.Traits if (init.Contains()) { this.__fromCell = this.__toCell = init.Get(); + this.PxPosition = Util.CenterOfCell( fromCell ); AddInfluence(); } @@ -127,7 +123,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 IEnumerable Orders { get { yield return new MoveOrderTargeter( Info ); } } diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 5152adbc34..3ff2c1b729 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -70,7 +70,12 @@ 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 OccupiedCells(); @@ -104,15 +109,15 @@ namespace OpenRA.Traits public interface IPips { IEnumerable GetPips(Actor self); } public interface ITags { IEnumerable 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; } } @@ -233,9 +238,10 @@ namespace OpenRA.Traits public static readonly Target None = new Target(); public bool IsValid { get { return valid && (actor == null || actor.IsInWorld); } } - public float2 CenterLocation { get { return actor != null ? actor.CenterLocation : pos.ToInt2(); } } + public int2 PxPosition { get { return IsActor ? actor.Trait().PxPosition : pos.ToInt2(); } } + public float2 CenterLocation { get { return PxPosition; } } - public Actor Actor { get { return actor; } } - public bool IsActor { get { return actor != null; } } + public Actor Actor { get { return IsActor ? actor : null; } } + public bool IsActor { get { return actor != null && !actor.Destroyed; } } } } diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index ba6144001d..adfac5b5bb 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -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]); } diff --git a/OpenRA.Game/Traits/World/SpatialBins.cs b/OpenRA.Game/Traits/World/SpatialBins.cs index 5a390a5728..970be709b1 100644 --- a/OpenRA.Game/Traits/World/SpatialBins.cs +++ b/OpenRA.Game/Traits/World/SpatialBins.cs @@ -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()) { - 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); } } diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index ead2648fc4..082238478d 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Cnc new AltitudeInit( Rules.Info["c17"].Traits.Get().CruiseAltitude ), }); - a.QueueActivity(new Fly(self.Location + new int2(6,0))); + a.QueueActivity(Fly.ToCell(self.Location + new int2(6,0))); a.QueueActivity(new Land(Target.FromActor(self))); a.QueueActivity(new CallFunc(() => { @@ -60,7 +60,7 @@ namespace OpenRA.Mods.Cnc rb.PlayCustomAnimRepeating(self, "idle"); self.World.AddFrameEndTask(ww => DoProduction(self, producee, exit)); })); - a.QueueActivity(new Fly(endPos)); + a.QueueActivity(Fly.ToCell(endPos)); a.QueueActivity(new RemoveSelf()); }); diff --git a/OpenRA.Mods.Cnc/RenderCargo.cs b/OpenRA.Mods.Cnc/RenderCargo.cs index d597125668..dfb92b40f2 100644 --- a/OpenRA.Mods.Cnc/RenderCargo.cs +++ b/OpenRA.Mods.Cnc/RenderCargo.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.Cnc public IEnumerable ModifyRender(Actor self, IEnumerable r) { foreach (var c in cargo.Passengers) - c.CenterLocation = self.CenterLocation; + c.Trait().SetPxPosition( c, self.Trait().PxPosition ); return r.Concat(cargo.Passengers.SelectMany(a => a.Render())); } diff --git a/OpenRA.Mods.Cnc/TiberiumRefineryDockAction.cs b/OpenRA.Mods.Cnc/TiberiumRefineryDockAction.cs index ffaee86dde..48832e881a 100644 --- a/OpenRA.Mods.Cnc/TiberiumRefineryDockAction.cs +++ b/OpenRA.Mods.Cnc/TiberiumRefineryDockAction.cs @@ -25,8 +25,8 @@ namespace OpenRA.Mods.Cnc bool preventDock = false; public void OnDock(Actor self, Actor harv, DeliverResources dockOrder) { - float2 startDock = harv.CenterLocation; - float2 endDock = self.CenterLocation + new float2(-15,8); + int2 startDock = harv.Trait().PxPosition; + int2 endDock = self.Trait().PxPosition + new int2(-15,8); var harvester = harv.Trait(); harv.QueueActivity( new Turn(112) ); diff --git a/OpenRA.Mods.RA/Activities/Fly.cs b/OpenRA.Mods.RA/Activities/Fly.cs index 3f9c23d473..5a61250d26 100644 --- a/OpenRA.Mods.RA/Activities/Fly.cs +++ b/OpenRA.Mods.RA/Activities/Fly.cs @@ -18,9 +18,11 @@ namespace OpenRA.Mods.RA.Activities { public readonly float2 Pos; - public Fly(float2 pos) { Pos = pos; } - public Fly(int2 pos) { Pos = Util.CenterOfCell(pos); } + private Fly( float2 px ) { Pos = px; } + public static Fly ToPx( float2 px ) { return new Fly( px ); } + public static Fly ToCell( int2 pos ) { return new Fly( Util.CenterOfCell( pos ) ); } + public override IActivity Tick(Actor self) { var cruiseAltitude = self.Info.Traits.Get().CruiseAltitude; @@ -57,7 +59,7 @@ namespace OpenRA.Mods.RA.Activities var aircraft = self.Trait(); var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location); var angle = aircraft.Facing / 128f * Math.PI; - self.CenterLocation += speed * -float2.FromAngle((float)angle); + aircraft.center += speed * -float2.FromAngle((float)angle); aircraft.Location = Util.CellContaining(self.CenterLocation); aircraft.Altitude += Math.Sign(desiredAltitude - aircraft.Altitude); } diff --git a/OpenRA.Mods.RA/Activities/FlyAttack.cs b/OpenRA.Mods.RA/Activities/FlyAttack.cs index adb56e0d67..1e6e772c45 100644 --- a/OpenRA.Mods.RA/Activities/FlyAttack.cs +++ b/OpenRA.Mods.RA/Activities/FlyAttack.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Activities return NextActivity; return Util.SequenceActivities( - new Fly(Target.CenterLocation), + Fly.ToPx(Target.CenterLocation), new FlyTimed(50), this); } @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Activities if( IsCanceled ) return NextActivity; return Util.SequenceActivities( - new Fly(Util.CenterOfCell(Target)), + Fly.ToCell(Target), new FlyTimed(50), this); } diff --git a/OpenRA.Mods.RA/Activities/HeliAttack.cs b/OpenRA.Mods.RA/Activities/HeliAttack.cs index 13a7a86032..82def3f317 100644 --- a/OpenRA.Mods.RA/Activities/HeliAttack.cs +++ b/OpenRA.Mods.RA/Activities/HeliAttack.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Activities var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location); if (!float2.WithinEpsilon(float2.Zero, dist, range * Game.CellSize)) - self.CenterLocation += (rawSpeed / dist.Length) * dist; + aircraft.center += (rawSpeed / dist.Length) * dist; return this; } diff --git a/OpenRA.Mods.RA/Activities/HeliFly.cs b/OpenRA.Mods.RA/Activities/HeliFly.cs index 9a49bf2434..1572d5cba7 100644 --- a/OpenRA.Mods.RA/Activities/HeliFly.cs +++ b/OpenRA.Mods.RA/Activities/HeliFly.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Activities var dist = Dest - self.CenterLocation; if (float2.WithinEpsilon(float2.Zero, dist, 2)) { - self.CenterLocation = Dest; + aircraft.center = Dest; aircraft.Location = Util.CellContaining(self.CenterLocation); return NextActivity; } @@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA.Activities aircraft.ROT); var rawSpeed = .2f * aircraft.MovementSpeedForCell(self, self.Location); - self.CenterLocation += (rawSpeed / dist.Length) * dist; + aircraft.center += (rawSpeed / dist.Length) * dist; aircraft.Location = Util.CellContaining(self.CenterLocation); return this; diff --git a/OpenRA.Mods.RA/Activities/Land.cs b/OpenRA.Mods.RA/Activities/Land.cs index dd08e32d74..d779648df2 100644 --- a/OpenRA.Mods.RA/Activities/Land.cs +++ b/OpenRA.Mods.RA/Activities/Land.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA.Activities var speed = .2f * aircraft.MovementSpeedForCell(self, self.Location); var angle = aircraft.Facing / 128f * Math.PI; - self.CenterLocation += speed * -float2.FromAngle((float)angle); + aircraft.center += speed * -float2.FromAngle((float)angle); aircraft.Location = Util.CellContaining(self.CenterLocation); return this; diff --git a/OpenRA.Mods.RA/Activities/Leap.cs b/OpenRA.Mods.RA/Activities/Leap.cs index 06d6bf68f4..fa1c653c70 100644 --- a/OpenRA.Mods.RA/Activities/Leap.cs +++ b/OpenRA.Mods.RA/Activities/Leap.cs @@ -17,15 +17,15 @@ namespace OpenRA.Mods.RA.Activities class Leap : CancelableActivity { Target target; - float2 initialLocation; - float t; + int2 initialLocation; + int moveFraction; const int delay = 6; public Leap(Actor self, Target target) { - this.target = target; - initialLocation = self.CenterLocation; + this.target = target; + initialLocation = self.Trait().PxPosition; self.Trait().Attacking(self); Sound.Play("dogg5p.aud", self.CenterLocation); @@ -33,16 +33,16 @@ namespace OpenRA.Mods.RA.Activities public override IActivity Tick(Actor self) { - if( t == 0 && IsCanceled ) return NextActivity; + if( moveFraction == 0 && IsCanceled ) return NextActivity; if (!target.IsValid) return NextActivity; self.Trait().IsLeaping = true; + var mobile = self.Trait(); + ++moveFraction; - t += (1f / delay); + mobile.PxPosition = int2.Lerp(initialLocation, target.PxPosition, moveFraction, delay); - self.CenterLocation = float2.Lerp(initialLocation, target.CenterLocation, t); - - if (t >= 1f) + if (moveFraction >= delay) { self.TraitsImplementing().FirstOrDefault() .SetPosition(self, Util.CellContaining(target.CenterLocation)); diff --git a/OpenRA.Mods.RA/Activities/ReturnToBase.cs b/OpenRA.Mods.RA/Activities/ReturnToBase.cs index 083fb9f18c..3155fe9d89 100644 --- a/OpenRA.Mods.RA/Activities/ReturnToBase.cs +++ b/OpenRA.Mods.RA/Activities/ReturnToBase.cs @@ -92,9 +92,9 @@ namespace OpenRA.Mods.RA.Activities Calculate(self); return Util.SequenceActivities( - new Fly(w1), - new Fly(w2), - new Fly(w3), + Fly.ToPx(w1), + Fly.ToPx(w2), + Fly.ToPx(w3), new Land(Target.FromActor(dest)), NextActivity); } diff --git a/OpenRA.Mods.RA/Aircraft.cs b/OpenRA.Mods.RA/Aircraft.cs index 5b281aaeaa..7b87250001 100755 --- a/OpenRA.Mods.RA/Aircraft.cs +++ b/OpenRA.Mods.RA/Aircraft.cs @@ -37,14 +37,19 @@ namespace OpenRA.Mods.RA public int Facing { get; set; } [Sync] public int Altitude { get; set; } - + + public float2 center; + AircraftInfo Info; public Aircraft( ActorInitializer init , AircraftInfo info) { this.self = init.self; - if (init.Contains()) - this.Location = init.Get(); + if( init.Contains() ) + { + this.Location = init.Get(); + this.center = Util.CenterOfCell( Location ); + } this.Facing = init.Contains() ? init.Get() : info.InitialFacing; this.Altitude = init.Contains() ? init.Get() : 0; @@ -63,9 +68,15 @@ namespace OpenRA.Mods.RA public void SetPosition(Actor self, int2 cell) { Location = cell; - self.CenterLocation = Util.CenterOfCell(cell); + center = Util.CenterOfCell(cell); } - + + public void SetPxPosition( Actor self, int2 px ) + { + Location = Util.CellContaining( px ); + center = px; + } + public bool AircraftCanEnter(Actor a) { if( self.Owner != a.Owner ) return false; @@ -86,5 +97,6 @@ namespace OpenRA.Mods.RA int2[] noCells = new int2[] { }; public IEnumerable OccupiedCells() { return noCells; } + public int2 PxPosition { get { return center.ToInt2(); } } } } diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index 1565c3c401..172b98e1ad 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -82,6 +82,13 @@ namespace OpenRA.Mods.RA public int2 TopLeft { get { return Location; } } public IEnumerable OccupiedCells() { return new int2[] { Location }; } + public int2 PxPosition { get; private set; } + + public void SetPxPosition( Actor self, int2 px ) + { + SetPosition( self, Util.CellContaining( px ) ); + } + public bool CanEnterCell(int2 cell) { if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false; @@ -96,7 +103,7 @@ namespace OpenRA.Mods.RA uim.Remove(self, this); Location = cell; - self.CenterLocation = Util.CenterOfCell(cell); + PxPosition = Util.CenterOfCell(cell); var seq = self.World.GetTerrainInfo(cell).IsWater ? "water" : "idle"; if (seq != self.Trait().anim.CurrentSequence.Name) diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index 1ec90f2f8c..d6d87d02b0 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -58,18 +58,7 @@ namespace OpenRA.Mods.RA.Effects w.Remove(this); var loc = Traits.Util.CellContaining(location); cargo.CancelActivity(); - - var mobile = cargo.TraitOrDefault(); - - if (mobile != null) - mobile.SetPosition(cargo, loc); - else - { - cargo.CenterLocation = Traits.Util.CenterOfCell(loc); - - if (cargo.HasTrait()) - world.WorldActor.Trait().Add(cargo, cargo.Trait()); - } + cargo.Trait().SetPosition(cargo, loc); w.Add(cargo); }); } diff --git a/OpenRA.Mods.RA/Helicopter.cs b/OpenRA.Mods.RA/Helicopter.cs index a3019371b1..10223b2e1d 100644 --- a/OpenRA.Mods.RA/Helicopter.cs +++ b/OpenRA.Mods.RA/Helicopter.cs @@ -139,11 +139,11 @@ namespace OpenRA.Mods.RA .Select(h => self.Trait().GetRepulseForce(self, h)) .Aggregate(float2.Zero, (a, b) => a + b); - self.CenterLocation += rawSpeed * f; + aircraft.center += rawSpeed * f; if (--offsetTicks <= 0) { - self.CenterLocation += Info.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5); + aircraft.center += Info.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5); aircraft.Altitude += (int)(Info.InstabilityMagnitude * self.World.SharedRandom.Gauss1D(5)); offsetTicks = Info.InstabilityTicks; } diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index ebbfaa5a23..60e608de35 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -40,5 +40,6 @@ namespace OpenRA.Mods.RA public int2 TopLeft { get { return location; } } public IEnumerable OccupiedCells() { yield return TopLeft; } + public int2 PxPosition { get { return Util.CenterOfCell( location ); } } } } diff --git a/OpenRA.Mods.RA/Mine.cs b/OpenRA.Mods.RA/Mine.cs index 37c981e23a..74b45523a4 100644 --- a/OpenRA.Mods.RA/Mine.cs +++ b/OpenRA.Mods.RA/Mine.cs @@ -55,6 +55,7 @@ namespace OpenRA.Mods.RA public int2 TopLeft { get { return location; } } public IEnumerable OccupiedCells() { yield return TopLeft; } + public int2 PxPosition { get { return Util.CenterOfCell( location ); } } } /* tag trait for stuff that shouldnt trigger mines */ diff --git a/OpenRA.Mods.RA/Plane.cs b/OpenRA.Mods.RA/Plane.cs index f704484c0d..94dc332eec 100644 --- a/OpenRA.Mods.RA/Plane.cs +++ b/OpenRA.Mods.RA/Plane.cs @@ -100,7 +100,7 @@ namespace OpenRA.Mods.RA }); self.CancelActivity(); - self.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation))); + self.QueueActivity(Fly.ToCell(order.TargetLocation)); } else if (order.OrderString == "Enter") diff --git a/OpenRA.Mods.RA/Production.cs b/OpenRA.Mods.RA/Production.cs index 548dc41ce2..f9c51defbb 100755 --- a/OpenRA.Mods.RA/Production.cs +++ b/OpenRA.Mods.RA/Production.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA public class ExitInfo : TraitInfo { - public readonly float2 SpawnOffset = float2.Zero; // in px relative to CenterLocation + public readonly int2 SpawnOffset = int2.Zero; // in px relative to CenterLocation public readonly int2 ExitCell = int2.Zero; // in cells relative to TopLeft public readonly int Facing = -1; } @@ -46,21 +46,21 @@ namespace OpenRA.Mods.RA }); var exit = self.Location + exitinfo.ExitCell; - var spawn = self.CenterLocation + exitinfo.SpawnOffset; + var spawn = self.Trait().PxPosition + exitinfo.SpawnOffset; - var move = newUnit.Trait(); + var mobile = newUnit.Trait(); var facing = newUnit.TraitOrDefault(); // Set the physical position of the unit as the exit cell - move.SetPosition(newUnit,exit); + mobile.SetPosition(newUnit,exit); var to = Util.CenterOfCell(exit); - newUnit.CenterLocation = spawn; + mobile.PxPosition = spawn; if (facing != null) facing.Facing = exitinfo.Facing < 0 ? Util.GetFacing(to - spawn, facing.Facing) : exitinfo.Facing; self.World.Add(newUnit); // Animate the spawn -> exit transition - var speed = move.MovementSpeedForCell(self, exit); + var speed = mobile.MovementSpeedForCell(self, exit); var length = speed > 0 ? (int)( ( to - spawn ).Length*3 / speed ) : 0; newUnit.QueueActivity(new Drag(spawn, to, length)); diff --git a/OpenRA.Mods.RA/Render/RenderBuilding.cs b/OpenRA.Mods.RA/Render/RenderBuilding.cs index c0eed39458..25958148b1 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -90,7 +90,7 @@ namespace OpenRA.Mods.RA.Render foreach (var t in Footprint.UnpathableTiles( self.Info.Name, self.Info.Traits.Get(), self.Location )) { var cell = t; // required: c# fails at bindings - self.World.AddFrameEndTask(w => w.Add(new Explosion(w, Util.CenterOfCell(cell).ToInt2(), "building", false))); + self.World.AddFrameEndTask(w => w.Add(new Explosion(w, Util.CenterOfCell(cell), "building", false))); } else if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy) { diff --git a/OpenRA.Mods.RA/ReservableProduction.cs b/OpenRA.Mods.RA/ReservableProduction.cs index cb9f00c774..0b72741bd8 100644 --- a/OpenRA.Mods.RA/ReservableProduction.cs +++ b/OpenRA.Mods.RA/ReservableProduction.cs @@ -43,7 +43,6 @@ namespace OpenRA.Mods.RA new LocationInit( exit ), new OwnerInit( self.Owner ), }); - newUnit.CenterLocation = spawn; var rp = self.TraitOrDefault(); if( rp != null ) diff --git a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs index b38fbf2e08..354baff71f 100755 --- a/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/AirstrikePower.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA a.Trait().SetTarget(order.TargetLocation); a.CancelActivity(); - a.QueueActivity(new Fly(order.TargetLocation)); + a.QueueActivity(Fly.ToCell(order.TargetLocation)); if (flare != null) a.QueueActivity(new CallFunc(() => flare.Destroy())); diff --git a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs index 96cf322654..6a4e0ac43a 100755 --- a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA }); plane.CancelActivity(); - plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation))); + plane.QueueActivity(Fly.ToCell(order.TargetLocation)); plane.QueueActivity(new CallFunc(() => plane.World.AddFrameEndTask( w => { var camera = w.CreateActor("camera", new TypeDictionary