diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs index 35000092a8..b3cda1118f 100644 --- a/OpenRA.Game/CPos.cs +++ b/OpenRA.Game/CPos.cs @@ -37,9 +37,6 @@ namespace OpenRA public static CPos Max(CPos a, CPos b) { return new CPos(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); } public static CPos Min(CPos a, CPos b) { return new CPos(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); } - public float2 ToFloat2() { return new float2(X, Y); } - public int2 ToInt2() { return new int2(X, Y); } - public CPos Clamp(Rectangle r) { return new CPos(Math.Min(r.Right, Math.Max(X, r.Left)), diff --git a/OpenRA.Game/CVec.cs b/OpenRA.Game/CVec.cs index 206cfc3b29..f9db67b1ee 100644 --- a/OpenRA.Game/CVec.cs +++ b/OpenRA.Game/CVec.cs @@ -21,13 +21,8 @@ namespace OpenRA public readonly int X, Y; public CVec(int x, int y) { X = x; Y = y; } - public CVec(Size p) { X = p.Width; Y = p.Height; } - public static readonly CVec Zero = new CVec(0, 0); - public static explicit operator CVec(int2 a) { return new CVec(a.X, a.Y); } - public static explicit operator CVec(float2 a) { return new CVec((int)a.X, (int)a.Y); } - public static CVec operator +(CVec a, CVec b) { return new CVec(a.X + b.X, a.Y + b.Y); } public static CVec operator -(CVec a, CVec b) { return new CVec(a.X - b.X, a.Y - b.Y); } public static CVec operator *(int a, CVec b) { return new CVec(a * b.X, a * b.Y); } @@ -49,8 +44,6 @@ namespace OpenRA public int LengthSquared { get { return X * X + Y * Y; } } public int Length { get { return (int)Math.Sqrt(LengthSquared); } } - public float2 ToFloat2() { return new float2(X, Y); } - public int2 ToInt2() { return new int2(X, Y); } public WVec ToWVec() { return new WVec(X*1024, Y*1024, 0); } public CVec Clamp(Rectangle r) diff --git a/OpenRA.Game/Map/ActorInitializer.cs b/OpenRA.Game/Map/ActorInitializer.cs index 1481ae983e..1ce7eeb80f 100755 --- a/OpenRA.Game/Map/ActorInitializer.cs +++ b/OpenRA.Game/Map/ActorInitializer.cs @@ -57,10 +57,10 @@ namespace OpenRA public class LocationInit : IActorInit { - [FieldFromYamlKey] public readonly int2 value = int2.Zero; + [FieldFromYamlKey] public readonly CPos value = CPos.Zero; public LocationInit() { } - public LocationInit(CPos init) { value = init.ToInt2(); } - public CPos Value(World world) { return (CPos)value; } + public LocationInit(CPos init) { value = init; } + public CPos Value(World world) { return value; } } public class SubCellInit : IActorInit diff --git a/OpenRA.Game/Network/Order.cs b/OpenRA.Game/Network/Order.cs index 390cfa65c4..59f39711fc 100755 --- a/OpenRA.Game/Network/Order.cs +++ b/OpenRA.Game/Network/Order.cs @@ -113,11 +113,11 @@ namespace OpenRA if (TargetActor != null) w.Write(UIntFromActor(TargetActor)); if (TargetLocation != CPos.Zero) - w.Write(TargetLocation.ToInt2()); + w.Write(TargetLocation); if (TargetString != null) w.Write(TargetString); if (ExtraLocation != CPos.Zero) - w.Write(ExtraLocation.ToInt2()); + w.Write(ExtraLocation); if (ExtraData != 0) w.Write(ExtraData); diff --git a/OpenRA.Game/Network/OrderIO.cs b/OpenRA.Game/Network/OrderIO.cs index 3168330a71..20de5bdfa0 100755 --- a/OpenRA.Game/Network/OrderIO.cs +++ b/OpenRA.Game/Network/OrderIO.cs @@ -58,5 +58,11 @@ namespace OpenRA.Network w.Write(p.X); w.Write(p.Y); } + + public static void Write(this BinaryWriter w, CPos cell) + { + w.Write(cell.X); + w.Write(cell.Y); + } } } diff --git a/OpenRA.Mods.RA/Buildings/Building.cs b/OpenRA.Mods.RA/Buildings/Building.cs index 651583ada1..53c64d6dbc 100644 --- a/OpenRA.Mods.RA/Buildings/Building.cs +++ b/OpenRA.Mods.RA/Buildings/Building.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Buildings public readonly int Adjacent = 2; [Desc("x means space it blocks, _ is a part that is passable by actors.")] public readonly string Footprint = "x"; - public readonly int2 Dimensions = new int2(1, 1); + public readonly CVec Dimensions = new CVec(1, 1); public readonly bool RequiresBaseProvider = false; public readonly bool AllowInvalidPlacement = false; @@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Buildings if (RequiresBaseProvider && FindBaseProvider(world, p, topLeft) == null) return false; - var buildingMaxBounds = (CVec)Dimensions; + var buildingMaxBounds = Dimensions; var buildingTraits = world.Map.Rules.Actors[buildingName].Traits; if (buildingTraits.Contains() && !(buildingTraits.Get().HasMinibib)) buildingMaxBounds += new CVec(0, 1); diff --git a/OpenRA.Mods.RA/FreeActor.cs b/OpenRA.Mods.RA/FreeActor.cs index f73d282a3b..c1e2baa91f 100644 --- a/OpenRA.Mods.RA/FreeActor.cs +++ b/OpenRA.Mods.RA/FreeActor.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.RA [Desc("What the unit should start doing. Warning: If this is not a harvester", "it will break if you use FindResources.")] public readonly string InitialActivity = null; [Desc("Offset relative to structure-center in 2D (e.g. 1, 2)")] - public readonly int2 SpawnOffset = int2.Zero; + public readonly CVec SpawnOffset = CVec.Zero; [Desc("Which direction the unit should face.")] public readonly int Facing = 0; @@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA var a = w.CreateActor(info.Actor, new TypeDictionary { new ParentActorInit(init.self), - new LocationInit(init.self.Location + (CVec)info.SpawnOffset), + new LocationInit(init.self.Location + info.SpawnOffset), new OwnerInit(init.self.Owner), new FacingInit(info.Facing), }); diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index c3a1e0bda4..e434e15e1c 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -104,7 +104,7 @@ namespace OpenRA.Mods.RA var p = end - start; var q = new float2(p.Y, -p.X); q = (start != end) ? (1 / q.Length) * q : new float2(1, 0); - var c = -float2.Dot(q, start.ToInt2()); + var c = -float2.Dot(q, new float2(start.X, start.Y)); /* return all points such that |ax + by + c| < depth */ diff --git a/OpenRA.Mods.RA/OreRefinery.cs b/OpenRA.Mods.RA/OreRefinery.cs index 6ed490cfb4..8bc6903861 100644 --- a/OpenRA.Mods.RA/OreRefinery.cs +++ b/OpenRA.Mods.RA/OreRefinery.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA { public class OreRefineryInfo : ITraitInfo { - public readonly int2 DockOffset = new int2(1, 2); + public readonly CVec DockOffset = new CVec(1, 2); public readonly bool ShowTicks = true; public readonly int TickLifetime = 30; @@ -44,8 +44,7 @@ namespace OpenRA.Mods.RA [Sync] bool preventDock = false; public bool AllowDocking { get { return !preventDock; } } - - public CVec DeliverOffset { get { return (CVec)Info.DockOffset; } } + public CVec DeliverOffset { get { return Info.DockOffset; } } public virtual Activity DockSequence(Actor harv, Actor self) { return new RAHarvesterDockSequence(harv, self, Info.DockAngle); } diff --git a/OpenRA.Mods.RA/Transforms.cs b/OpenRA.Mods.RA/Transforms.cs index 0b6b6d730b..34c7904aec 100644 --- a/OpenRA.Mods.RA/Transforms.cs +++ b/OpenRA.Mods.RA/Transforms.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA class TransformsInfo : ITraitInfo { [ActorReference] public readonly string IntoActor = null; - public readonly int2 Offset = int2.Zero; + public readonly CVec Offset = CVec.Zero; public readonly int Facing = 96; public readonly string[] TransformSounds = { }; public readonly string[] NoTransformSounds = { }; @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA if (b != null && b.Locked) return false; - return bi == null || self.World.CanPlaceBuilding(info.IntoActor, bi, self.Location + (CVec)info.Offset, self); + return bi == null || self.World.CanPlaceBuilding(info.IntoActor, bi, self.Location + info.Offset, self); } public IEnumerable Orders @@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA if (rb != null && self.Info.Traits.Get().HasMakeAnimation) self.QueueActivity(new MakeAnimation(self, true, () => rb.PlayCustomAnim(self, "make"))); - self.QueueActivity(new Transform(self, info.IntoActor) { Offset = (CVec)info.Offset, Facing = info.Facing, Sounds = info.TransformSounds, Race = race }); + self.QueueActivity(new Transform(self, info.IntoActor) { Offset = info.Offset, Facing = info.Facing, Sounds = info.TransformSounds, Race = race }); } public void ResolveOrder(Actor self, Order order) diff --git a/OpenRA.Mods.RA/Widgets/RadarWidget.cs b/OpenRA.Mods.RA/Widgets/RadarWidget.cs index 13d5d0e8d3..960e484b5e 100755 --- a/OpenRA.Mods.RA/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.RA/Widgets/RadarWidget.cs @@ -242,18 +242,18 @@ namespace OpenRA.Mods.RA.Widgets int2 CellToMinimapPixel(CPos p) { - var viewOrigin = new float2(mapRect.X, mapRect.Y); var mapOrigin = new CPos(world.Map.Bounds.Left, world.Map.Bounds.Top); + var mapOffset = p - mapOrigin; - return (viewOrigin + previewScale * (p - mapOrigin).ToFloat2()).ToInt2(); + return new int2(mapRect.X, mapRect.Y) + (previewScale * new float2(mapOffset.X, mapOffset.Y)).ToInt2(); } CPos MinimapPixelToCell(int2 p) { var viewOrigin = new float2(mapRect.X, mapRect.Y); - var mapOrigin = new CPos(world.Map.Bounds.Left, world.Map.Bounds.Top); - - return (CPos)(mapOrigin.ToFloat2() + (1f / previewScale) * (p - viewOrigin)).ToInt2(); + var mapOrigin = new float2(world.Map.Bounds.Left, world.Map.Bounds.Top); + var fcell = mapOrigin + (1f / previewScale) * (p - viewOrigin); + return new CPos((int)fcell.X, (int)fcell.Y); } } }