diff --git a/OpenRA.FileFormats/Primitives/int2.cs b/OpenRA.FileFormats/Primitives/int2.cs index 2f05672ede..4426048304 100644 --- a/OpenRA.FileFormats/Primitives/int2.cs +++ b/OpenRA.FileFormats/Primitives/int2.cs @@ -25,7 +25,6 @@ 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); } @@ -60,15 +59,5 @@ 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 b1798e36ec..fe2ac3a27d 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -26,8 +26,7 @@ namespace OpenRA public readonly World World; public readonly uint ActorID; - public int2 Location { get { return Trait().TopLeft; } } - public float2 CenterLocation { get { return Trait().PxPosition; } } + public int2 Location { get { return Trait().TopLeft; } } [Sync] public Player Owner; @@ -53,6 +52,9 @@ namespace OpenRA AddTrait(trait.Create(init)); } + if( CenterLocation == float2.Zero && HasTrait() ) + CenterLocation = Traits.Util.CenterOfCell(Location); + Size = Lazy.New(() => { var si = Info.Traits.GetOrDefault(); @@ -97,6 +99,8 @@ 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 9aa263c213..525272d731 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; } - int2 endLocation; - int2 startLocation; + float2 endLocation; + float2 startLocation; int length; - public Drag(int2 start, int2 end, int length) + public Drag(float2 start, float2 end, int length) { startLocation = start; endLocation = end; @@ -29,16 +29,15 @@ namespace OpenRA.Traits.Activities int ticks = 0; public IActivity Tick( Actor self ) - { - var mobile = self.Trait(); - mobile.PxPosition = int2.Lerp( startLocation, endLocation, ticks, length - 1 ); + { + self.CenterLocation = float2.Lerp(startLocation, endLocation, (float)ticks/(length-1)); if (++ticks >= length) { - mobile.IsMoving = false; + self.Trait().IsMoving = false; return NextActivity; } - mobile.IsMoving = true; + self.Trait().IsMoving = true; return this; } diff --git a/OpenRA.Game/Traits/Activities/Move.cs b/OpenRA.Game/Traits/Activities/Move.cs index 70c2b45160..c8ae9be1b0 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 => (float2)Util.CenterOfCell(c) ); + return Enumerable.Reverse(path).Select( c => 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 int2 from, to; + public readonly float2 from, to; public readonly int fromFacing, toFacing; public int moveFraction; public readonly int moveFractionTotal; - public MovePart( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction ) + public MovePart( Move move, float2 from, float2 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 ) * 3 ).Length; + this.moveFractionTotal = (int)(( to - from ).Length*3); } public void Cancel( Actor self ) @@ -311,12 +311,14 @@ namespace OpenRA.Traits.Activities void UpdateCenterLocation( Actor self, Mobile mobile ) { - mobile.PxPosition = int2.Lerp( from, to, moveFraction, moveFractionTotal ); + var frac = (float)moveFraction / moveFractionTotal; + + self.CenterLocation = float2.Lerp( from, to, frac ); if( moveFraction >= moveFractionTotal ) mobile.Facing = toFacing & 0xFF; else - mobile.Facing = int2.Lerp( fromFacing, toFacing, moveFraction, moveFractionTotal ) & 0xFF; + mobile.Facing = ( fromFacing + ( toFacing - fromFacing ) * moveFraction / moveFractionTotal ) & 0xFF; } protected abstract MovePart OnComplete( Actor self, Mobile mobile, Move parent ); @@ -329,7 +331,7 @@ namespace OpenRA.Traits.Activities class MoveFirstHalf : MovePart { - public MoveFirstHalf( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction ) + public MoveFirstHalf( Move move, float2 from, float2 to, int fromFacing, int toFacing, int startingFraction ) : base( move, from, to, fromFacing, toFacing, startingFraction ) { } @@ -368,14 +370,14 @@ namespace OpenRA.Traits.Activities class MoveSecondHalf : MovePart { - public MoveSecondHalf( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction ) + public MoveSecondHalf( Move move, float2 from, float2 to, int fromFacing, int toFacing, int startingFraction ) : base( move, from, to, fromFacing, toFacing, startingFraction ) { } protected override MovePart OnComplete( Actor self, Mobile mobile, Move parent ) { - mobile.PxPosition = Util.CenterOfCell( mobile.toCell ); + self.CenterLocation = 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 6b6a4acf6a..64f506f3af 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 4de0aea639..5de98f9b20 100644 --- a/OpenRA.Game/Traits/Mobile.cs +++ b/OpenRA.Game/Traits/Mobile.cs @@ -81,11 +81,17 @@ namespace OpenRA.Traits public int InitialFacing { get { return Info.InitialFacing; } } [Sync] - public int2 PxPosition { get; set; } + public int2 fromCell + { + get { return __fromCell; } + } + [Sync] - public int2 fromCell { get { return __fromCell; } } - [Sync] - public int2 toCell { get { return __toCell; } } + public int2 toCell + { + get { return __toCell; } + } + [Sync] public int PathHash; // written by Move.EvalPath, to temporarily debug this crap. @@ -110,7 +116,6 @@ namespace OpenRA.Traits if (init.Contains()) { this.__fromCell = this.__toCell = init.Get(); - this.PxPosition = Util.CenterOfCell( fromCell ); AddInfluence(); } @@ -121,14 +126,7 @@ namespace OpenRA.Traits public void SetPosition(Actor self, int2 cell) { SetLocation( cell, cell ); - PxPosition = Util.CenterOfCell(fromCell); - } - - public void SetPxPosition( Actor self, int2 px ) - { - var cell = Util.CellContaining( px ); - SetLocation( cell, cell ); - PxPosition = px; + self.CenterLocation = Util.CenterOfCell(fromCell); } 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 83a0d399d6..0ba14d33bc 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -63,13 +63,7 @@ namespace OpenRA.Traits public interface IVisibilityModifier { bool IsVisible(Actor self, Player byPlayer); } public interface IRadarColorModifier { Color RadarColorOverride(Actor self); } - - public interface IHasLocation - { - int2 PxPosition { get; } - } - - public interface IOccupySpace : IHasLocation + public interface IOccupySpace { int2 TopLeft { get; } IEnumerable OccupiedCells(); @@ -103,15 +97,15 @@ namespace OpenRA.Traits public interface IPips { IEnumerable GetPips(Actor self); } public interface ITags { IEnumerable GetTags(); } - public interface ITeleportable : IHasLocation /* crap name! */ + public interface ITeleportable /* 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; } } @@ -232,7 +226,6 @@ 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 44475d3e02..ba6144001d 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 int2 CenterOfCell(int2 loc) + public static float2 CenterOfCell(int2 loc) { - return new int2(Game.CellSize/2, Game.CellSize/2) + Game.CellSize * loc; + return new float2(12, 12) + Game.CellSize * (float2)loc; } - public static int2 BetweenCells(int2 from, int2 to) + public static float2 BetweenCells(int2 from, int2 to) { - return int2.Lerp( CenterOfCell( from ), CenterOfCell( to ), 1, 2 ); + return 0.5f * (CenterOfCell(from) + CenterOfCell(to)); } 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 970be709b1..5a390a5728 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.Queries.WithTrait()) + foreach (var a in self.World.Actors) { - var bounds = a.Actor.GetBounds(true); + var bounds = a.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.Actor); + bins[i, j].Add(a); } } diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index b6ff574e34..efc2c2faa3 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(Fly.ToCell(self.Location + new int2(6,0))); + a.QueueActivity(new Fly(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(Fly.ToCell(endPos)); + a.QueueActivity(new Fly(endPos)); a.QueueActivity(new RemoveSelf()); }); diff --git a/OpenRA.Mods.Cnc/RenderCargo.cs b/OpenRA.Mods.Cnc/RenderCargo.cs index 33f2b186d5..d597125668 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.Trait().SetPxPosition( c, self.Trait().PxPosition ); + { + foreach (var c in cargo.Passengers) + c.CenterLocation = self.CenterLocation; return r.Concat(cargo.Passengers.SelectMany(a => a.Render())); } diff --git a/OpenRA.Mods.Cnc/TiberiumRefineryDockAction.cs b/OpenRA.Mods.Cnc/TiberiumRefineryDockAction.cs index d7f7187a17..ffaee86dde 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) { - int2 startDock = harv.Trait().PxPosition; - int2 endDock = self.Trait().PxPosition + new int2(-15,8); + float2 startDock = harv.CenterLocation; + float2 endDock = self.CenterLocation + new float2(-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 a0c7a26d7b..3f9c23d473 100644 --- a/OpenRA.Mods.RA/Activities/Fly.cs +++ b/OpenRA.Mods.RA/Activities/Fly.cs @@ -18,13 +18,8 @@ namespace OpenRA.Mods.RA.Activities { public readonly float2 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 Fly(float2 pos) { Pos = pos; } + public Fly(int2 pos) { Pos = Util.CenterOfCell(pos); } public override IActivity Tick(Actor self) { @@ -62,7 +57,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; - aircraft.center += speed * -float2.FromAngle((float)angle); + self.CenterLocation += 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 59307d2cac..adb56e0d67 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( - Fly.ToPx(Target.CenterLocation), + new Fly(Target.CenterLocation), new FlyTimed(50), this); } @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA.Activities if( IsCanceled ) return NextActivity; return Util.SequenceActivities( - Fly.ToPx(Util.CenterOfCell(Target)), + new Fly(Util.CenterOfCell(Target)), new FlyTimed(50), this); } diff --git a/OpenRA.Mods.RA/Activities/HeliAttack.cs b/OpenRA.Mods.RA/Activities/HeliAttack.cs index 82def3f317..13a7a86032 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)) - aircraft.center += (rawSpeed / dist.Length) * dist; + self.CenterLocation += (rawSpeed / dist.Length) * dist; return this; } diff --git a/OpenRA.Mods.RA/Activities/HeliFly.cs b/OpenRA.Mods.RA/Activities/HeliFly.cs index 1572d5cba7..9a49bf2434 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)) { - aircraft.center = Dest; + self.CenterLocation = 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); - aircraft.center += (rawSpeed / dist.Length) * dist; + self.CenterLocation += (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 d779648df2..dd08e32d74 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; - aircraft.center += speed * -float2.FromAngle((float)angle); + self.CenterLocation += 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 11d12c4541..06d6bf68f4 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; - int2 initialLocation; + float2 initialLocation; + float t; const int delay = 6; - int moveFraction; public Leap(Actor self, Target target) { this.target = target; - initialLocation = self.Trait().PxPosition; + initialLocation = self.CenterLocation; 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( moveFraction == 0 && IsCanceled ) return NextActivity; + if( t == 0 && IsCanceled ) return NextActivity; if (!target.IsValid) return NextActivity; self.Trait().IsLeaping = true; - var mobile = self.Trait(); - ++moveFraction; - mobile.PxPosition = int2.Lerp(initialLocation, target.PxPosition, moveFraction, delay); + t += (1f / delay); - if (moveFraction >= delay) + self.CenterLocation = float2.Lerp(initialLocation, target.CenterLocation, t); + + if (t >= 1f) { 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 3155fe9d89..083fb9f18c 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( - Fly.ToPx(w1), - Fly.ToPx(w2), - Fly.ToPx(w3), + new Fly(w1), + new Fly(w2), + new Fly(w3), new Land(Target.FromActor(dest)), NextActivity); } diff --git a/OpenRA.Mods.RA/Aircraft.cs b/OpenRA.Mods.RA/Aircraft.cs index 86cd090979..9247451d25 100755 --- a/OpenRA.Mods.RA/Aircraft.cs +++ b/OpenRA.Mods.RA/Aircraft.cs @@ -36,18 +36,13 @@ 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(); - this.center = Util.CenterOfCell( Location ); - } + if (init.Contains()) + this.Location = init.Get(); this.Facing = init.Contains() ? init.Get() : info.InitialFacing; this.Altitude = init.Contains() ? init.Get() : 0; @@ -66,15 +61,9 @@ namespace OpenRA.Mods.RA public void SetPosition(Actor self, int2 cell) { Location = cell; - center = Util.CenterOfCell(cell); + self.CenterLocation = 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 ) @@ -94,6 +83,5 @@ 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 83789d25ca..9de41281a3 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -82,13 +82,6 @@ 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; @@ -103,7 +96,7 @@ namespace OpenRA.Mods.RA uim.Remove(self, this); Location = cell; - PxPosition = Util.CenterOfCell(cell); + self.CenterLocation = 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 d6d87d02b0..1ec90f2f8c 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -58,7 +58,18 @@ namespace OpenRA.Mods.RA.Effects w.Remove(this); var loc = Traits.Util.CellContaining(location); cargo.CancelActivity(); - cargo.Trait().SetPosition(cargo, loc); + + 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()); + } w.Add(cargo); }); } diff --git a/OpenRA.Mods.RA/Helicopter.cs b/OpenRA.Mods.RA/Helicopter.cs index c22040eaea..4a8da63cdd 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); - aircraft.center += rawSpeed * f; + self.CenterLocation += rawSpeed * f; if (--offsetTicks <= 0) { - aircraft.center += Info.InstabilityMagnitude * self.World.SharedRandom.Gauss2D(5); + self.CenterLocation += 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 3ef416cf3c..ebbfaa5a23 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -40,7 +40,5 @@ 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 1db51c0adc..37c981e23a 100644 --- a/OpenRA.Mods.RA/Mine.cs +++ b/OpenRA.Mods.RA/Mine.cs @@ -55,8 +55,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 ); } } } /* tag trait for stuff that shouldnt trigger mines */ diff --git a/OpenRA.Mods.RA/Plane.cs b/OpenRA.Mods.RA/Plane.cs index 78b5f9f159..e928f145aa 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(Fly.ToPx(Util.CenterOfCell(order.TargetLocation))); + self.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation))); } else if (order.OrderString == "Enter") diff --git a/OpenRA.Mods.RA/Production.cs b/OpenRA.Mods.RA/Production.cs index 0dacd54c86..548dc41ce2 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 int2 SpawnOffset = int2.Zero; // in px relative to CenterLocation + public readonly float2 SpawnOffset = float2.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.ToInt2() + exitinfo.SpawnOffset; + var spawn = self.CenterLocation + exitinfo.SpawnOffset; - var mobile = newUnit.Trait(); + var move = newUnit.Trait(); var facing = newUnit.TraitOrDefault(); // Set the physical position of the unit as the exit cell - mobile.SetPosition(newUnit,exit); + move.SetPosition(newUnit,exit); var to = Util.CenterOfCell(exit); - mobile.PxPosition = spawn; + newUnit.CenterLocation = 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 = mobile.MovementSpeedForCell(self, exit); + var speed = move.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 1151b7274a..0218ff065d 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), "building", false))); + self.World.AddFrameEndTask(w => w.Add(new Explosion(w, Util.CenterOfCell(cell).ToInt2(), "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 9158feba4b..cb9f00c774 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.Trait().PxPosition + s.SpawnOffset; + var spawn = self.CenterLocation + s.SpawnOffset; if (!self.World.WorldActor.Trait().GetUnitsAt( exit ).Any()) { var newUnit = self.World.CreateActor( producee.Name, new TypeDictionary @@ -43,7 +43,8 @@ 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 e132b7a4f3..ed9604bc11 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(Fly.ToCell(order.TargetLocation)); + a.QueueActivity(new Fly(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 0309d9dd92..2917b1027a 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(Fly.ToPx(Util.CenterOfCell(order.TargetLocation))); + plane.QueueActivity(new Fly(Util.CenterOfCell(order.TargetLocation))); plane.QueueActivity(new CallFunc(() => plane.World.AddFrameEndTask( w => { var camera = w.CreateActor("camera", new TypeDictionary