Remove conversions between legacy and world types.
This commit is contained in:
@@ -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)),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -57,10 +57,10 @@ namespace OpenRA
|
||||
|
||||
public class LocationInit : IActorInit<CPos>
|
||||
{
|
||||
[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<SubCell>
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<BibInfo>() && !(buildingTraits.Get<BibInfo>().HasMinibib))
|
||||
buildingMaxBounds += new CVec(0, 1);
|
||||
|
||||
@@ -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),
|
||||
});
|
||||
|
||||
@@ -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 */
|
||||
|
||||
|
||||
@@ -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); }
|
||||
|
||||
|
||||
@@ -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<IOrderTargeter> Orders
|
||||
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA
|
||||
if (rb != null && self.Info.Traits.Get<RenderBuildingInfo>().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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user