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 fe2ac3a27d..b1798e36ec 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..9aa263c213 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..70c2b45160 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 = (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; diff --git a/OpenRA.Game/Traits/Building.cs b/OpenRA.Game/Traits/Building.cs index 64f506f3af..6b6a4acf6a 100644 --- a/OpenRA.Game/Traits/Building.cs +++ b/OpenRA.Game/Traits/Building.cs @@ -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(); 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 5de98f9b20..4de0aea639 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -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()) { this.__fromCell = this.__toCell = init.Get(); + 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) diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 0ba14d33bc..83a0d399d6 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -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 OccupiedCells(); @@ -97,15 +103,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; } } @@ -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().PxPosition : pos.ToInt2(); } } public float2 CenterLocation { get { return actor != null ? actor.CenterLocation : pos.ToInt2(); } } public Actor Actor { get { return actor; } } diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index ba6144001d..44475d3e02 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 efc2c2faa3..b6ff574e34 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -51,7 +51,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..33f2b186d5 100644 --- a/OpenRA.Mods.Cnc/RenderCargo.cs +++ b/OpenRA.Mods.Cnc/RenderCargo.cs @@ -31,9 +31,9 @@ namespace OpenRA.Mods.Cnc } public IEnumerable ModifyRender(Actor self, IEnumerable r) - { - foreach (var c in cargo.Passengers) - c.CenterLocation = self.CenterLocation; + { + foreach( var c in cargo.Passengers ) + 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..d7f7187a17 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..a0c7a26d7b 100644 --- a/OpenRA.Mods.RA/Activities/Fly.cs +++ b/OpenRA.Mods.RA/Activities/Fly.cs @@ -18,8 +18,13 @@ 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 pos ) + { + this.Pos = pos; + } + + 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) { @@ -57,7 +62,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..59307d2cac 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.ToPx(Util.CenterOfCell(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..11d12c4541 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; const int delay = 6; + int moveFraction; public Leap(Actor self, Target target) { this.target = target; - initialLocation = self.CenterLocation; + 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 9247451d25..86cd090979 100755 --- a/OpenRA.Mods.RA/Aircraft.cs +++ b/OpenRA.Mods.RA/Aircraft.cs @@ -36,13 +36,18 @@ 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) { - 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; @@ -61,9 +66,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 self, Actor a) { return Info.RearmBuildings.Contains( a.Info.Name ) @@ -83,5 +94,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 9de41281a3..83789d25ca 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 4a8da63cdd..c22040eaea 100644 --- a/OpenRA.Mods.RA/Helicopter.cs +++ b/OpenRA.Mods.RA/Helicopter.cs @@ -145,11 +145,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..3ef416cf3c 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -40,5 +40,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 ); } } } } diff --git a/OpenRA.Mods.RA/Mine.cs b/OpenRA.Mods.RA/Mine.cs index 37c981e23a..1db51c0adc 100644 --- a/OpenRA.Mods.RA/Mine.cs +++ b/OpenRA.Mods.RA/Mine.cs @@ -55,6 +55,8 @@ 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 e928f145aa..78b5f9f159 100644 --- a/OpenRA.Mods.RA/Plane.cs +++ b/OpenRA.Mods.RA/Plane.cs @@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA }); self.CancelActivity(); - self.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation))); + self.QueueActivity(Fly.ToPx(Util.CenterOfCell(order.TargetLocation))); } else if (order.OrderString == "Enter") diff --git a/OpenRA.Mods.RA/Production.cs b/OpenRA.Mods.RA/Production.cs index 548dc41ce2..0dacd54c86 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.CenterLocation.ToInt2() + 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 0218ff065d..1151b7274a 100755 --- a/OpenRA.Mods.RA/Render/RenderBuilding.cs +++ b/OpenRA.Mods.RA/Render/RenderBuilding.cs @@ -91,7 +91,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..9158feba4b 100644 --- a/OpenRA.Mods.RA/ReservableProduction.cs +++ b/OpenRA.Mods.RA/ReservableProduction.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA foreach (var s in self.Info.Traits.WithInterface()) { var exit = self.Location + s.ExitCell; - var spawn = self.CenterLocation + s.SpawnOffset; + var spawn = self.Trait().PxPosition + s.SpawnOffset; if (!self.World.WorldActor.Trait().GetUnitsAt( exit ).Any()) { var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary @@ -43,8 +43,7 @@ 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 ed9604bc11..e132b7a4f3 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 2917b1027a..0309d9dd92 100755 --- a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA }); plane.CancelActivity(); - plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation))); + plane.QueueActivity(Fly.ToPx(Util.CenterOfCell(order.TargetLocation))); plane.QueueActivity(new CallFunc(() => plane.World.AddFrameEndTask( w => { var camera = w.CreateActor("camera", new TypeDictionary