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 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 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)
|
public CPos Clamp(Rectangle r)
|
||||||
{
|
{
|
||||||
return new CPos(Math.Min(r.Right, Math.Max(X, r.Left)),
|
return new CPos(Math.Min(r.Right, Math.Max(X, r.Left)),
|
||||||
|
|||||||
@@ -21,13 +21,8 @@ namespace OpenRA
|
|||||||
public readonly int X, Y;
|
public readonly int X, Y;
|
||||||
|
|
||||||
public CVec(int x, int y) { X = x; Y = 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 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 -(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); }
|
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 LengthSquared { get { return X * X + Y * Y; } }
|
||||||
public int Length { get { return (int)Math.Sqrt(LengthSquared); } }
|
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 WVec ToWVec() { return new WVec(X*1024, Y*1024, 0); }
|
||||||
|
|
||||||
public CVec Clamp(Rectangle r)
|
public CVec Clamp(Rectangle r)
|
||||||
|
|||||||
@@ -57,10 +57,10 @@ namespace OpenRA
|
|||||||
|
|
||||||
public class LocationInit : IActorInit<CPos>
|
public class LocationInit : IActorInit<CPos>
|
||||||
{
|
{
|
||||||
[FieldFromYamlKey] public readonly int2 value = int2.Zero;
|
[FieldFromYamlKey] public readonly CPos value = CPos.Zero;
|
||||||
public LocationInit() { }
|
public LocationInit() { }
|
||||||
public LocationInit(CPos init) { value = init.ToInt2(); }
|
public LocationInit(CPos init) { value = init; }
|
||||||
public CPos Value(World world) { return (CPos)value; }
|
public CPos Value(World world) { return value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SubCellInit : IActorInit<SubCell>
|
public class SubCellInit : IActorInit<SubCell>
|
||||||
|
|||||||
@@ -113,11 +113,11 @@ namespace OpenRA
|
|||||||
if (TargetActor != null)
|
if (TargetActor != null)
|
||||||
w.Write(UIntFromActor(TargetActor));
|
w.Write(UIntFromActor(TargetActor));
|
||||||
if (TargetLocation != CPos.Zero)
|
if (TargetLocation != CPos.Zero)
|
||||||
w.Write(TargetLocation.ToInt2());
|
w.Write(TargetLocation);
|
||||||
if (TargetString != null)
|
if (TargetString != null)
|
||||||
w.Write(TargetString);
|
w.Write(TargetString);
|
||||||
if (ExtraLocation != CPos.Zero)
|
if (ExtraLocation != CPos.Zero)
|
||||||
w.Write(ExtraLocation.ToInt2());
|
w.Write(ExtraLocation);
|
||||||
if (ExtraData != 0)
|
if (ExtraData != 0)
|
||||||
w.Write(ExtraData);
|
w.Write(ExtraData);
|
||||||
|
|
||||||
|
|||||||
@@ -58,5 +58,11 @@ namespace OpenRA.Network
|
|||||||
w.Write(p.X);
|
w.Write(p.X);
|
||||||
w.Write(p.Y);
|
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;
|
public readonly int Adjacent = 2;
|
||||||
[Desc("x means space it blocks, _ is a part that is passable by actors.")]
|
[Desc("x means space it blocks, _ is a part that is passable by actors.")]
|
||||||
public readonly string Footprint = "x";
|
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 RequiresBaseProvider = false;
|
||||||
public readonly bool AllowInvalidPlacement = false;
|
public readonly bool AllowInvalidPlacement = false;
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
if (RequiresBaseProvider && FindBaseProvider(world, p, topLeft) == null)
|
if (RequiresBaseProvider && FindBaseProvider(world, p, topLeft) == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var buildingMaxBounds = (CVec)Dimensions;
|
var buildingMaxBounds = Dimensions;
|
||||||
var buildingTraits = world.Map.Rules.Actors[buildingName].Traits;
|
var buildingTraits = world.Map.Rules.Actors[buildingName].Traits;
|
||||||
if (buildingTraits.Contains<BibInfo>() && !(buildingTraits.Get<BibInfo>().HasMinibib))
|
if (buildingTraits.Contains<BibInfo>() && !(buildingTraits.Get<BibInfo>().HasMinibib))
|
||||||
buildingMaxBounds += new CVec(0, 1);
|
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.")]
|
[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;
|
public readonly string InitialActivity = null;
|
||||||
[Desc("Offset relative to structure-center in 2D (e.g. 1, 2)")]
|
[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.")]
|
[Desc("Which direction the unit should face.")]
|
||||||
public readonly int Facing = 0;
|
public readonly int Facing = 0;
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA
|
|||||||
var a = w.CreateActor(info.Actor, new TypeDictionary
|
var a = w.CreateActor(info.Actor, new TypeDictionary
|
||||||
{
|
{
|
||||||
new ParentActorInit(init.self),
|
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 OwnerInit(init.self.Owner),
|
||||||
new FacingInit(info.Facing),
|
new FacingInit(info.Facing),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.RA
|
|||||||
var p = end - start;
|
var p = end - start;
|
||||||
var q = new float2(p.Y, -p.X);
|
var q = new float2(p.Y, -p.X);
|
||||||
q = (start != end) ? (1 / q.Length) * q : new float2(1, 0);
|
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 */
|
/* return all points such that |ax + by + c| < depth */
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
public class OreRefineryInfo : ITraitInfo
|
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 bool ShowTicks = true;
|
||||||
public readonly int TickLifetime = 30;
|
public readonly int TickLifetime = 30;
|
||||||
@@ -44,8 +44,7 @@ namespace OpenRA.Mods.RA
|
|||||||
[Sync] bool preventDock = false;
|
[Sync] bool preventDock = false;
|
||||||
|
|
||||||
public bool AllowDocking { get { return !preventDock; } }
|
public bool AllowDocking { get { return !preventDock; } }
|
||||||
|
public CVec DeliverOffset { get { return Info.DockOffset; } }
|
||||||
public CVec DeliverOffset { get { return (CVec)Info.DockOffset; } }
|
|
||||||
|
|
||||||
public virtual Activity DockSequence(Actor harv, Actor self) { return new RAHarvesterDockSequence(harv, self, Info.DockAngle); }
|
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
|
class TransformsInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
[ActorReference] public readonly string IntoActor = null;
|
[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 int Facing = 96;
|
||||||
public readonly string[] TransformSounds = { };
|
public readonly string[] TransformSounds = { };
|
||||||
public readonly string[] NoTransformSounds = { };
|
public readonly string[] NoTransformSounds = { };
|
||||||
@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (b != null && b.Locked)
|
if (b != null && b.Locked)
|
||||||
return false;
|
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
|
public IEnumerable<IOrderTargeter> Orders
|
||||||
@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA
|
|||||||
if (rb != null && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation)
|
if (rb != null && self.Info.Traits.Get<RenderBuildingInfo>().HasMakeAnimation)
|
||||||
self.QueueActivity(new MakeAnimation(self, true, () => rb.PlayCustomAnim(self, "make")));
|
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)
|
public void ResolveOrder(Actor self, Order order)
|
||||||
|
|||||||
@@ -242,18 +242,18 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
|
|
||||||
int2 CellToMinimapPixel(CPos p)
|
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 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)
|
CPos MinimapPixelToCell(int2 p)
|
||||||
{
|
{
|
||||||
var viewOrigin = new float2(mapRect.X, mapRect.Y);
|
var viewOrigin = new float2(mapRect.X, mapRect.Y);
|
||||||
var mapOrigin = new CPos(world.Map.Bounds.Left, world.Map.Bounds.Top);
|
var mapOrigin = new float2(world.Map.Bounds.Left, world.Map.Bounds.Top);
|
||||||
|
var fcell = mapOrigin + (1f / previewScale) * (p - viewOrigin);
|
||||||
return (CPos)(mapOrigin.ToFloat2() + (1f / previewScale) * (p - viewOrigin)).ToInt2();
|
return new CPos((int)fcell.X, (int)fcell.Y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user