From 9c491435345d9a49854041af9bc95fc92f65443b Mon Sep 17 00:00:00 2001 From: James Dunne Date: Wed, 20 Jun 2012 23:22:27 -0500 Subject: [PATCH] New types for cell and pixel coordinate position/vectors. --- .gitignore | 3 + OpenRA.Editor/BrushTool.cs | 20 ++-- OpenRA.Editor/LegacyMapImporter.cs | 18 ++-- OpenRA.Editor/Surface.cs | 44 ++++----- OpenRA.Game/Actor.cs | 16 ++- OpenRA.Game/ActorInitializer.cs | 12 +-- OpenRA.Game/ActorMap.cs | 10 +- OpenRA.Game/CPos.cs | 71 ++++++++++++++ OpenRA.Game/CVec.cs | 76 ++++++++++++++ OpenRA.Game/GameRules/WeaponInfo.cs | 4 +- OpenRA.Game/Graphics/AnimationWithOffset.cs | 2 +- OpenRA.Game/Graphics/Viewport.cs | 16 +-- OpenRA.Game/Graphics/WorldRenderer.cs | 27 +++-- OpenRA.Game/Map.cs | 2 +- OpenRA.Game/Network/Order.cs | 32 +++--- OpenRA.Game/OpenRA.Game.csproj | 5 + OpenRA.Game/Orders/GenericSelectTarget.cs | 6 +- OpenRA.Game/Orders/IOrderGenerator.cs | 4 +- OpenRA.Game/Orders/UnitOrderGenerator.cs | 6 +- OpenRA.Game/PPos.cs | 70 +++++++++++++ OpenRA.Game/PVecFloat.cs | 97 ++++++++++++++++++ OpenRA.Game/PVecInt.cs | 79 +++++++++++++++ OpenRA.Game/Sound.cs | 16 +-- OpenRA.Game/Sync.cs | 40 ++++++++ OpenRA.Game/Traits/DrawLineToTarget.cs | 6 +- OpenRA.Game/Traits/RevealsShroud.cs | 2 +- OpenRA.Game/Traits/Selectable.cs | 4 +- OpenRA.Game/Traits/Target.cs | 10 +- OpenRA.Game/Traits/TraitsInterfaces.cs | 24 ++--- OpenRA.Game/Traits/Util.cs | 47 +++++---- OpenRA.Game/Traits/Waypoint.cs | 10 +- OpenRA.Game/Traits/World/ResourceLayer.cs | 14 +-- OpenRA.Game/Traits/World/Shroud.cs | 30 +++--- OpenRA.Game/Traits/World/SpatialBins.cs | 2 +- .../WorldInteractionControllerWidget.cs | 14 +-- OpenRA.Game/WorldUtils.cs | 38 +++---- .../Activities/HarvesterDockSequence.cs | 6 +- OpenRA.Mods.Cnc/Effects/IonCannon.cs | 4 +- OpenRA.Mods.Cnc/IonCannonPower.cs | 2 +- OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs | 10 +- OpenRA.Mods.Cnc/Missions/Gdi01Script.cs | 12 +-- OpenRA.Mods.Cnc/ProductionAirdrop.cs | 6 +- .../CncWorldInteractionControllerWidget.cs | 2 +- OpenRA.Mods.RA/AI/HackyAI.cs | 33 +++---- OpenRA.Mods.RA/Activities/FindResources.cs | 2 +- OpenRA.Mods.RA/Activities/Follow.cs | 2 +- OpenRA.Mods.RA/Activities/LayMines.cs | 7 +- OpenRA.Mods.RA/Activities/Leap.cs | 8 +- OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs | 2 +- OpenRA.Mods.RA/Activities/Teleport.cs | 4 +- OpenRA.Mods.RA/Activities/Transform.cs | 2 +- OpenRA.Mods.RA/Activities/UnloadCargo.cs | 8 +- OpenRA.Mods.RA/Air/Aircraft.cs | 26 ++--- OpenRA.Mods.RA/Air/EjectOnDeath.cs | 4 +- OpenRA.Mods.RA/Air/Fly.cs | 10 +- OpenRA.Mods.RA/Air/HeliAttack.cs | 2 +- OpenRA.Mods.RA/Air/HeliFly.cs | 8 +- OpenRA.Mods.RA/Air/HeliReturn.cs | 12 +-- OpenRA.Mods.RA/Air/Helicopter.cs | 10 +- OpenRA.Mods.RA/Air/Plane.cs | 2 +- OpenRA.Mods.RA/Air/ReturnToBase.cs | 19 ++-- OpenRA.Mods.RA/AppearsOnRadar.cs | 4 +- OpenRA.Mods.RA/Attack/AttackBase.cs | 4 +- OpenRA.Mods.RA/Attack/AttackWander.cs | 2 +- OpenRA.Mods.RA/AttackMove.cs | 4 +- OpenRA.Mods.RA/Bridge.cs | 14 +-- OpenRA.Mods.RA/BridgeLayer.cs | 10 +- OpenRA.Mods.RA/Buildings/BibLayer.cs | 11 +-- OpenRA.Mods.RA/Buildings/Building.cs | 33 +++---- OpenRA.Mods.RA/Buildings/BuildingInfluence.cs | 2 +- OpenRA.Mods.RA/Buildings/FootprintUtils.cs | 20 ++-- OpenRA.Mods.RA/Buildings/ShakeOnDeath.cs | 2 +- OpenRA.Mods.RA/Buildings/Util.cs | 12 +-- OpenRA.Mods.RA/Burns.cs | 3 +- OpenRA.Mods.RA/CarpetBomb.cs | 6 +- OpenRA.Mods.RA/CashTrickler.cs | 3 +- OpenRA.Mods.RA/ChronoshiftDeploy.cs | 5 +- OpenRA.Mods.RA/Chronoshiftable.cs | 10 +- OpenRA.Mods.RA/Combat.cs | 37 +++---- OpenRA.Mods.RA/Crate.cs | 20 ++-- OpenRA.Mods.RA/CrateDrop.cs | 2 +- OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs | 8 +- OpenRA.Mods.RA/DemoTruck.cs | 2 +- OpenRA.Mods.RA/Effects/Bullet.cs | 20 ++-- OpenRA.Mods.RA/Effects/CashTick.cs | 19 ++-- OpenRA.Mods.RA/Effects/Contrail.cs | 19 ++-- OpenRA.Mods.RA/Effects/Corpse.cs | 2 +- OpenRA.Mods.RA/Effects/CrateEffect.cs | 2 +- OpenRA.Mods.RA/Effects/Explosion.cs | 6 +- OpenRA.Mods.RA/Effects/GpsDot.cs | 2 +- OpenRA.Mods.RA/Effects/GravityBomb.cs | 2 +- OpenRA.Mods.RA/Effects/LaserZap.cs | 4 +- OpenRA.Mods.RA/Effects/Missile.cs | 21 ++-- OpenRA.Mods.RA/Effects/NukeLaunch.cs | 10 +- OpenRA.Mods.RA/Effects/Parachute.cs | 10 +- OpenRA.Mods.RA/Effects/PowerdownIndicator.cs | 2 +- OpenRA.Mods.RA/Effects/RallyPoint.cs | 10 +- OpenRA.Mods.RA/Effects/RepairIndicator.cs | 2 +- OpenRA.Mods.RA/Effects/SatelliteLaunch.cs | 2 +- OpenRA.Mods.RA/Effects/Smoke.cs | 6 +- OpenRA.Mods.RA/Effects/TeslaZap.cs | 16 +-- OpenRA.Mods.RA/FreeActor.cs | 2 +- OpenRA.Mods.RA/Harvester.cs | 8 +- OpenRA.Mods.RA/Husk.cs | 25 +++-- OpenRA.Mods.RA/IronCurtainable.cs | 3 +- OpenRA.Mods.RA/LimitedAmmo.cs | 3 +- OpenRA.Mods.RA/MPStartLocations.cs | 12 +-- OpenRA.Mods.RA/Mine.cs | 10 +- OpenRA.Mods.RA/Minelayer.cs | 28 +++--- OpenRA.Mods.RA/Missions/Allies01Script.cs | 4 +- .../Missions/DefaultShellmapScript.cs | 23 +++-- OpenRA.Mods.RA/Move/Drag.cs | 8 +- OpenRA.Mods.RA/Move/Mobile.cs | 98 +++++++++---------- OpenRA.Mods.RA/Move/Move.cs | 40 ++++---- OpenRA.Mods.RA/Move/PathFinder.cs | 56 +++++------ OpenRA.Mods.RA/Move/PathSearch.cs | 46 ++++----- OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs | 2 +- .../Orders/PlaceBuildingOrderGenerator.cs | 14 +-- .../Orders/PowerDownOrderGenerator.cs | 6 +- OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs | 6 +- .../Orders/SetChronoTankDestination.cs | 4 +- OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs | 2 +- OpenRA.Mods.RA/OreRefinery.cs | 2 +- OpenRA.Mods.RA/ParaDrop.cs | 17 ++-- OpenRA.Mods.RA/Player/BaseAttackNotifier.cs | 4 +- OpenRA.Mods.RA/Player/ProductionQueue.cs | 18 ++-- OpenRA.Mods.RA/Production.cs | 15 +-- OpenRA.Mods.RA/RallyPoint.cs | 8 +- OpenRA.Mods.RA/Render/RenderBuildingWall.cs | 13 ++- .../Render/RenderBuildingWarFactory.cs | 7 +- OpenRA.Mods.RA/Render/RenderUnitSpinner.cs | 2 +- OpenRA.Mods.RA/Render/RenderUnitTurreted.cs | 2 +- OpenRA.Mods.RA/Render/WithMuzzleFlash.cs | 2 +- OpenRA.Mods.RA/Render/WithRotor.cs | 2 +- OpenRA.Mods.RA/RenderDetectionCircle.cs | 2 +- OpenRA.Mods.RA/RenderRangeCircle.cs | 8 +- OpenRA.Mods.RA/RenderShroudCircle.cs | 6 +- OpenRA.Mods.RA/Repairable.cs | 2 +- OpenRA.Mods.RA/ScaredyCat.cs | 2 +- OpenRA.Mods.RA/Scripting/RASpecialPowers.cs | 2 +- OpenRA.Mods.RA/SeedsResource.cs | 7 +- OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs | 8 +- OpenRA.Mods.RA/SpawnMPUnits.cs | 2 +- OpenRA.Mods.RA/StoresOre.cs | 3 +- .../SupportPowers/ChronoshiftPower.cs | 46 ++++----- .../SupportPowers/IronCurtainPower.cs | 14 +-- OpenRA.Mods.RA/SupportPowers/NukePower.cs | 3 +- OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs | 2 +- .../SupportPowers/SupportPowerManager.cs | 4 +- OpenRA.Mods.RA/TakeCover.cs | 7 +- OpenRA.Mods.RA/TargetableBuilding.cs | 2 +- OpenRA.Mods.RA/TargetableUnit.cs | 4 +- OpenRA.Mods.RA/ThrowsParticle.cs | 2 +- OpenRA.Mods.RA/TraitsInterfaces.cs | 2 +- OpenRA.Mods.RA/Transforms.cs | 4 +- OpenRA.Mods.RA/Weapon.cs | 23 +++-- .../Widgets/Logic/DiplomacyLogic.cs | 3 +- OpenRA.Mods.RA/Widgets/RadarBinWidget.cs | 16 +-- OpenRA.Mods.RA/Widgets/RadarWidget.cs | 22 ++--- OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs | 5 +- OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs | 2 +- OpenRA.Mods.RA/World/SmudgeLayer.cs | 12 +-- 162 files changed, 1291 insertions(+), 865 deletions(-) create mode 100644 OpenRA.Game/CPos.cs create mode 100644 OpenRA.Game/CVec.cs create mode 100644 OpenRA.Game/PPos.cs create mode 100644 OpenRA.Game/PVecFloat.cs create mode 100644 OpenRA.Game/PVecInt.cs diff --git a/.gitignore b/.gitignore index ac341d94d4..318756313c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ obj *.manifest mods/*/*.dll +# ReSharper crap +_ReSharper.*/ + # Red Alert binary files mods/*/packages/*.[mM][iI][xX] diff --git a/OpenRA.Editor/BrushTool.cs b/OpenRA.Editor/BrushTool.cs index f89efa6834..cd4288efeb 100644 --- a/OpenRA.Editor/BrushTool.cs +++ b/OpenRA.Editor/BrushTool.cs @@ -39,7 +39,7 @@ namespace OpenRA.Editor for (var u = 0; u < template.Size.X; u++) for (var v = 0; v < template.Size.Y; v++) { - if (surface.Map.IsInMap(new int2(u, v) + pos)) + if (surface.Map.IsInMap(new CVec(u, v) + pos)) { var z = u + v * template.Size.X; if (tile.TileBitmapBytes[z] != null) @@ -69,17 +69,17 @@ namespace OpenRA.Editor Brush.Bitmap.Height * surface.Zoom); } - void FloodFillWithBrush(Surface s, int2 pos) + void FloodFillWithBrush(Surface s, CPos pos) { - var queue = new Queue(); + var queue = new Queue(); var replace = s.Map.MapTiles.Value[pos.X, pos.Y]; var touched = new bool[s.Map.MapSize.X, s.Map.MapSize.Y]; - Action MaybeEnqueue = (x, y) => + Action maybeEnqueue = (x, y) => { if (s.Map.IsInMap(x, y) && !touched[x, y]) { - queue.Enqueue(new int2(x, y)); + queue.Enqueue(new CPos(x, y)); touched[x, y] = true; } }; @@ -91,16 +91,16 @@ namespace OpenRA.Editor if (!s.Map.MapTiles.Value[p.X, p.Y].Equals(replace)) continue; - var a = FindEdge(s, p, new int2(-1, 0), replace); - var b = FindEdge(s, p, new int2(1, 0), replace); + var a = FindEdge(s, p, new CVec(-1, 0), replace); + var b = FindEdge(s, p, new CVec(1, 0), replace); for (var x = a.X; x <= b.X; x++) { s.Map.MapTiles.Value[x, p.Y] = new TileReference { type = Brush.N, index = (byte)0 }; if (s.Map.MapTiles.Value[x, p.Y - 1].Equals(replace)) - MaybeEnqueue(x, p.Y - 1); + maybeEnqueue(x, p.Y - 1); if (s.Map.MapTiles.Value[x, p.Y + 1].Equals(replace)) - MaybeEnqueue(x, p.Y + 1); + maybeEnqueue(x, p.Y + 1); } } @@ -109,7 +109,7 @@ namespace OpenRA.Editor s.Chunks.Clear(); } - int2 FindEdge(Surface s, int2 p, int2 d, TileReference replace) + CPos FindEdge(Surface s, CPos p, CVec d, TileReference replace) { for (; ; ) { diff --git a/OpenRA.Editor/LegacyMapImporter.cs b/OpenRA.Editor/LegacyMapImporter.cs index 1095a32b2d..6b9510201a 100644 --- a/OpenRA.Editor/LegacyMapImporter.cs +++ b/OpenRA.Editor/LegacyMapImporter.cs @@ -175,7 +175,7 @@ namespace OpenRA.Editor foreach( var kv in wps ) { var a = new ActorReference("mpspawn"); - a.Add(new LocationInit(kv.Second)); + a.Add(new LocationInit((CPos)kv.Second)); a.Add(new OwnerInit("Neutral")); Map.Actors.Value.Add("spawn" + kv.First, a); } @@ -276,7 +276,7 @@ namespace OpenRA.Editor Map.Actors.Value.Add("Actor" + ActorCount++, new ActorReference(overlayActorMapping[raOverlayNames[o]]) { - new LocationInit( new int2(i, j) ), + new LocationInit( new CPos(i, j) ), new OwnerInit( "Neutral" ) }); } @@ -294,7 +294,7 @@ namespace OpenRA.Editor Map.Actors.Value.Add("Actor" + ActorCount++, new ActorReference(kv.Value.ToLowerInvariant()) { - new LocationInit(new int2(loc % MapSize, loc / MapSize)), + new LocationInit(new CPos(loc % MapSize, loc / MapSize)), new OwnerInit("Neutral") }); } @@ -323,7 +323,7 @@ namespace OpenRA.Editor foreach (KeyValuePair kv in overlay) { var loc = int.Parse(kv.Key); - var cell = new int2(loc % MapSize, loc / MapSize); + var cell = new CPos(loc % MapSize, loc / MapSize); var res = Pair.New((byte)0, (byte)0); if (overlayResourceMapping.ContainsKey(kv.Value.ToLower())) @@ -353,7 +353,7 @@ namespace OpenRA.Editor Map.Actors.Value.Add("Actor" + ActorCount++, new ActorReference(kv.Value.Split(',')[0].ToLowerInvariant()) { - new LocationInit(new int2(loc % MapSize, loc / MapSize)), + new LocationInit(new CPos(loc % MapSize, loc / MapSize)), new OwnerInit("Neutral") }); } @@ -380,7 +380,7 @@ namespace OpenRA.Editor var actor = new ActorReference(parts[1].ToLowerInvariant()) { - new LocationInit(new int2(loc % MapSize, loc / MapSize)), + new LocationInit(new CPos(loc % MapSize, loc / MapSize)), new OwnerInit(parts[0]), new HealthInit(float.Parse(parts[2], NumberFormatInfo.InvariantInfo)/256), new FacingInit((section == "INFANTRY") ? int.Parse(parts[6]) : int.Parse(parts[4])), @@ -432,7 +432,7 @@ namespace OpenRA.Editor (byte)(color.Second.GetBrightness() * 255)) }; - var Neutral = new [] {"Neutral"}; + var neutral = new [] {"Neutral"}; foreach (var s in file.GetSection(section, true)) { Console.WriteLine(s.Key); @@ -442,8 +442,8 @@ namespace OpenRA.Editor pr.InitialCash = int.Parse(s.Value); break; case "Allies": - pr.Allies = s.Value.Split(',').Intersect(Players).Except(Neutral).ToArray(); - pr.Enemies = s.Value.Split(',').SymmetricDifference(Players).Except(Neutral).ToArray(); + pr.Allies = s.Value.Split(',').Intersect(Players).Except(neutral).ToArray(); + pr.Enemies = s.Value.Split(',').SymmetricDifference(Players).Except(neutral).ToArray(); break; } } diff --git a/OpenRA.Editor/Surface.cs b/OpenRA.Editor/Surface.cs index 7cad793e53..b6812c8b64 100755 --- a/OpenRA.Editor/Surface.cs +++ b/OpenRA.Editor/Surface.cs @@ -157,23 +157,23 @@ namespace OpenRA.Editor void Erase() { // Crash preventing - var BrushLocation = GetBrushLocation(); + var brushLocation = GetBrushLocation(); - if (Map == null || BrushLocation.X >= Map.MapSize.X || - BrushLocation.Y >= Map.MapSize.Y || - BrushLocation.X < 0 || - BrushLocation.Y < 0) + if (Map == null || brushLocation.X >= Map.MapSize.X || + brushLocation.Y >= Map.MapSize.Y || + brushLocation.X < 0 || + brushLocation.Y < 0) return; Tool = null; - var key = Map.Actors.Value.FirstOrDefault(a => a.Value.Location() == BrushLocation); + var key = Map.Actors.Value.FirstOrDefault(a => a.Value.Location() == brushLocation); if (key.Key != null) Map.Actors.Value.Remove(key.Key); - if (Map.MapResources.Value[BrushLocation.X, BrushLocation.Y].type != 0) + if (Map.MapResources.Value[brushLocation.X, brushLocation.Y].type != 0) { - Map.MapResources.Value[BrushLocation.X, BrushLocation.Y] = new TileReference(); - var ch = new int2((BrushLocation.X) / ChunkSize, (BrushLocation.Y) / ChunkSize); + Map.MapResources.Value[brushLocation.X, brushLocation.Y] = new TileReference(); + var ch = new int2((brushLocation.X) / ChunkSize, (brushLocation.Y) / ChunkSize); if (Chunks.ContainsKey(ch)) { Chunks[ch].Dispose(); @@ -267,31 +267,31 @@ namespace OpenRA.Editor return bitmap; } - public int2 GetBrushLocation() + public CPos GetBrushLocation() { var vX = (int)Math.Floor((MousePos.X - Offset.X) / Zoom); var vY = (int)Math.Floor((MousePos.Y - Offset.Y) / Zoom); - return new int2(vX / TileSet.TileSize, vY / TileSet.TileSize); + return new CPos(vX / TileSet.TileSize, vY / TileSet.TileSize); } - public void DrawActor(SGraphics g, int2 p, ActorTemplate t, ColorPalette cp) + public void DrawActor(SGraphics g, CPos p, ActorTemplate t, ColorPalette cp) { var centered = t.Appearance == null || !t.Appearance.RelativeToTopLeft; DrawImage(g, t.Bitmap, p, centered, cp); } - float2 GetDrawPosition(int2 location, Bitmap bmp, bool centered) + float2 GetDrawPosition(CPos location, Bitmap bmp, bool centered) { - float OffsetX = centered ? bmp.Width / 2 - TileSet.TileSize / 2 : 0; - float DrawX = TileSet.TileSize * location.X * Zoom + Offset.X - OffsetX; + float offsetX = centered ? bmp.Width / 2 - TileSet.TileSize / 2 : 0; + float drawX = TileSet.TileSize * location.X * Zoom + Offset.X - offsetX; - float OffsetY = centered ? bmp.Height / 2 - TileSet.TileSize / 2 : 0; - float DrawY = TileSet.TileSize * location.Y * Zoom + Offset.Y - OffsetY; + float offsetY = centered ? bmp.Height / 2 - TileSet.TileSize / 2 : 0; + float drawY = TileSet.TileSize * location.Y * Zoom + Offset.Y - offsetY; - return new float2(DrawX, DrawY); + return new float2(drawX, drawY); } - public void DrawImage(SGraphics g, Bitmap bmp, int2 location, bool centered, ColorPalette cp) + public void DrawImage(SGraphics g, Bitmap bmp, CPos location, bool centered, ColorPalette cp) { var drawPos = GetDrawPosition(location, bmp, centered); @@ -304,7 +304,7 @@ namespace OpenRA.Editor if (cp != null) bmp.Palette = restorePalette; } - void DrawActorBorder(SGraphics g, int2 p, ActorTemplate t) + void DrawActorBorder(SGraphics g, CPos p, ActorTemplate t) { var centered = t.Appearance == null || !t.Appearance.RelativeToTopLeft; var drawPos = GetDrawPosition(p, t.Bitmap, centered); @@ -399,9 +399,9 @@ namespace OpenRA.Editor static class ActorReferenceExts { - public static int2 Location(this ActorReference ar) + public static CPos Location(this ActorReference ar) { - return ar.InitDict.Get().value; + return (CPos)ar.InitDict.Get().value; } public static void DrawStringContrast(this SGraphics g, Font f, string s, int x, int y, Brush fg, Brush bg) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 7956ba978e..a2a956060f 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -32,9 +32,9 @@ namespace OpenRA public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } } - public int2 Location { get { return occupySpace.Value.TopLeft; } } + public CPos Location { get { return occupySpace.Value.TopLeft; } } - public int2 CenterLocation + public PPos CenterLocation { get { @@ -123,22 +123,30 @@ namespace OpenRA // at its current altitude Rectangle CalculateBounds(bool useAltitude) { - var size = Size.Value; + var size = (PVecInt)(Size.Value); var loc = CenterLocation - size / 2; var si = Info.Traits.GetOrDefault(); if (si != null && si.Bounds != null && si.Bounds.Length > 2) { +#if true + loc += new PVecInt(si.Bounds[2], si.Bounds[3]); +#else loc.X += si.Bounds[2]; loc.Y += si.Bounds[3]; +#endif } var move = Move.Value; if (move != null) { +#if true + loc -= new PVecInt(0, move.Altitude); +#else loc.Y -= move.Altitude; +#endif if (useAltitude) - size = new int2(size.X, size.Y + move.Altitude); + size = new PVecInt(size.X, size.Y + move.Altitude); } return new Rectangle(loc.X, loc.Y, size.X, size.Y); diff --git a/OpenRA.Game/ActorInitializer.cs b/OpenRA.Game/ActorInitializer.cs index 3aa354fbb2..5f8a6bb7b2 100755 --- a/OpenRA.Game/ActorInitializer.cs +++ b/OpenRA.Game/ActorInitializer.cs @@ -62,12 +62,12 @@ namespace OpenRA public int Value( World world ) { return value; } } - public class LocationInit : IActorInit + public class LocationInit : IActorInit { [FieldFromYamlKey] public readonly int2 value = int2.Zero; public LocationInit() { } - public LocationInit( int2 init ) { value = init; } - public int2 Value( World world ) { return value; } + public LocationInit( CPos init ) { value = init.ToInt2(); } + public CPos Value(World world) { return (CPos)value; } } public class SubCellInit : IActorInit @@ -78,12 +78,12 @@ namespace OpenRA public SubCell Value(World world) { return (SubCell)value; } } - public class CenterLocationInit : IActorInit + public class CenterLocationInit : IActorInit { [FieldFromYamlKey] public readonly int2 value = int2.Zero; public CenterLocationInit() { } - public CenterLocationInit( int2 init ) { value = init; } - public int2 Value( World world ) { return value; } + public CenterLocationInit(PPos init) { value = init.ToInt2(); } + public PPos Value(World world) { return (PPos)value; } } public class OwnerInit : IActorInit diff --git a/OpenRA.Game/ActorMap.cs b/OpenRA.Game/ActorMap.cs index 233c226c4a..6e276b4262 100644 --- a/OpenRA.Game/ActorMap.cs +++ b/OpenRA.Game/ActorMap.cs @@ -37,7 +37,7 @@ namespace OpenRA world.ActorRemoved += a => Remove( a, a.OccupiesSpace ); } - public IEnumerable GetUnitsAt( int2 a ) + public IEnumerable GetUnitsAt(CPos a) { if (!map.IsInMap(a)) yield break; @@ -46,7 +46,7 @@ namespace OpenRA yield return i.actor; } - public IEnumerable GetUnitsAt( int2 a, SubCell sub ) + public IEnumerable GetUnitsAt(CPos a, SubCell sub) { if (!map.IsInMap(a)) yield break; @@ -55,7 +55,7 @@ namespace OpenRA yield return i.actor; } - public bool HasFreeSubCell(int2 a) + public bool HasFreeSubCell(CPos a) { if (!AnyUnitsAt(a)) return true; @@ -64,12 +64,12 @@ namespace OpenRA SubCell.BottomLeft, SubCell.BottomRight }.Any(b => !AnyUnitsAt(a,b)); } - public bool AnyUnitsAt(int2 a) + public bool AnyUnitsAt(CPos a) { return influence[ a.X, a.Y ] != null; } - public bool AnyUnitsAt(int2 a, SubCell sub) + public bool AnyUnitsAt(CPos a, SubCell sub) { for( var i = influence[ a.X, a.Y ] ; i != null ; i = i.next ) if (i.subCell == sub || i.subCell == SubCell.FullCell) diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs new file mode 100644 index 0000000000..2743ca021a --- /dev/null +++ b/OpenRA.Game/CPos.cs @@ -0,0 +1,71 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Drawing; + +namespace OpenRA +{ + /// + /// Cell coordinate position in the world (coarse). + /// + public struct CPos + { + public readonly int X, Y; + + public CPos(int x, int y) { X = x; Y = y; } + + public static readonly CPos Zero = new CPos(0, 0); + + public static explicit operator CPos(int2 a) { return new CPos(a.X, a.Y); } + + public static CPos operator +(CVec a, CPos b) { return new CPos(a.X + b.X, a.Y + b.Y); } + public static CPos operator +(CPos a, CVec b) { return new CPos(a.X + b.X, a.Y + b.Y); } + public static CPos operator -(CPos a, CVec b) { return new CPos(a.X - b.X, a.Y - b.Y); } + + public static CVec operator -(CPos a, CPos b) { return new CVec(a.X - b.X, a.Y - b.Y); } + + public static bool operator ==(CPos me, CPos other) { return (me.X == other.X && me.Y == other.Y); } + public static bool operator !=(CPos me, CPos other) { return !(me == other); } + + 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 PPos ToPPos() { return new PPos(Game.CellSize * X, Game.CellSize * Y); } + + public CPos Clamp(Rectangle r) + { + return new CPos(Math.Min(r.Right, Math.Max(X, r.Left)), + Math.Min(r.Bottom, Math.Max(Y, r.Top))); + } + + public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + + CPos o = (CPos)obj; + return o == this; + } + + public override string ToString() { return "{0},{1}".F(X, Y); } + + } + + public static class RectangleExtensions + { + public static CPos TopLeftAsCPos(this Rectangle r) { return new CPos(r.Left, r.Top); } + public static CPos BottomRightAsCPos(this Rectangle r) { return new CPos(r.Right, r.Bottom); } + } +} diff --git a/OpenRA.Game/CVec.cs b/OpenRA.Game/CVec.cs new file mode 100644 index 0000000000..31b4e3bbc5 --- /dev/null +++ b/OpenRA.Game/CVec.cs @@ -0,0 +1,76 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Drawing; + +namespace OpenRA +{ + /// + /// Cell coordinate vector (coarse). + /// + public struct CVec + { + 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); } + public static CVec operator *(CVec b, int a) { return new CVec(a * b.X, a * b.Y); } + public static CVec operator /(CVec a, int b) { return new CVec(a.X / b, a.Y / b); } + + public static CVec operator -(CVec a) { return new CVec(-a.X, -a.Y); } + + public static bool operator ==(CVec me, CVec other) { return (me.X == other.X && me.Y == other.Y); } + public static bool operator !=(CVec me, CVec other) { return !(me == other); } + + public static CVec Max(CVec a, CVec b) { return new CVec(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); } + public static CVec Min(CVec a, CVec b) { return new CVec(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); } + + public static int Dot(CVec a, CVec b) { return a.X * b.X + a.Y * b.Y; } + + public CVec Sign() { return new CVec(Math.Sign(X), Math.Sign(Y)); } + public CVec Abs() { return new CVec(Math.Abs(X), Math.Abs(Y)); } + 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 CVec Clamp(Rectangle r) + { + return new CVec( + Math.Min(r.Right, Math.Max(X, r.Left)), + Math.Min(r.Bottom, Math.Max(Y, r.Top)) + ); + } + + public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + + CVec o = (CVec)obj; + return o == this; + } + + public override string ToString() { return "{0},{1}".F(X, Y); } + } +} diff --git a/OpenRA.Game/GameRules/WeaponInfo.cs b/OpenRA.Game/GameRules/WeaponInfo.cs index 5abe4ad1de..5a331cde61 100644 --- a/OpenRA.Game/GameRules/WeaponInfo.cs +++ b/OpenRA.Game/GameRules/WeaponInfo.cs @@ -72,11 +72,11 @@ namespace OpenRA.GameRules { public WeaponInfo weapon; public Actor firedBy; - public int2 src; + public PPos src; public int srcAltitude; public int facing; public Target target; - public int2 dest; + public PPos dest; public int destAltitude; public float firepowerModifier = 1.0f; } diff --git a/OpenRA.Game/Graphics/AnimationWithOffset.cs b/OpenRA.Game/Graphics/AnimationWithOffset.cs index 9c02b5bac1..c29c341688 100644 --- a/OpenRA.Game/Graphics/AnimationWithOffset.cs +++ b/OpenRA.Game/Graphics/AnimationWithOffset.cs @@ -35,7 +35,7 @@ namespace OpenRA.Graphics public Renderable Image(Actor self, string pal) { var p = self.CenterLocation; - var loc = p - 0.5f * Animation.Image.size + var loc = p.ToFloat2() - 0.5f * Animation.Image.size + (OffsetFunc != null ? OffsetFunc() : float2.Zero); var r = new Renderable(Animation.Image, loc, pal, p.Y); diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index fbcafce3a5..72725616a9 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -149,18 +149,18 @@ namespace OpenRA.Graphics } // Convert from viewport coords to cell coords (not px) - public float2 ViewToWorld(MouseInput mi) { return ViewToWorld(mi.Location); } - public float2 ViewToWorld(int2 loc) + public CPos ViewToWorld(MouseInput mi) { return ViewToWorld(mi.Location); } + public CPos ViewToWorld(int2 loc) { - return (1f / Game.CellSize) * (1f/Zoom*loc.ToFloat2() + Location); + return (CPos)( (1f / Game.CellSize) * (1f/Zoom*loc.ToFloat2() + Location) ).ToInt2(); } - public int2 ViewToWorldPx(int2 loc) { return (1f/Zoom*loc.ToFloat2() + Location).ToInt2(); } - public int2 ViewToWorldPx(MouseInput mi) { return ViewToWorldPx(mi.Location); } + public PPos ViewToWorldPx(int2 loc) { return (PPos)(1f/Zoom*loc.ToFloat2() + Location).ToInt2(); } + public PPos ViewToWorldPx(MouseInput mi) { return ViewToWorldPx(mi.Location); } public void Center(float2 loc) { - scrollPosition = NormalizeScrollPosition((Game.CellSize*loc - 1f/(2*Zoom)*screenSize.ToFloat2()).ToInt2()); + scrollPosition = NormalizeScrollPosition((Game.CellSize * loc - 1f/(2*Zoom)*screenSize.ToFloat2()).ToInt2()); } public void Center(IEnumerable actors) @@ -168,9 +168,9 @@ namespace OpenRA.Graphics if (!actors.Any()) return; var avgPos = actors - .Select(a => a.CenterLocation) + .Select(a => (PVecInt)a.CenterLocation) .Aggregate((a, b) => a + b) / actors.Count(); - scrollPosition = NormalizeScrollPosition((avgPos - 1f/(2*Zoom)*screenSize.ToFloat2()).ToInt2()); + scrollPosition = NormalizeScrollPosition(((PVecFloat)avgPos - (PVecFloat)(1f / (2 * Zoom) * screenSize.ToFloat2())).ToInt2()); } // Rectangle (in viewport coords) that contains things to be drawn diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 9d7b5a1cb0..ba662975a2 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -53,8 +53,9 @@ namespace OpenRA.Graphics var comparer = new SpriteComparer(); var actors = world.FindUnits( - new int2(Game.CellSize*bounds.Left, Game.CellSize*bounds.Top), - new int2(Game.CellSize*bounds.Right, Game.CellSize*bounds.Bottom)); + bounds.TopLeftAsCPos().ToPPos(), + bounds.BottomRightAsCPos().ToPPos() + ); var renderables = actors.SelectMany(a => a.Render()) .OrderBy(r => r, comparer); @@ -140,25 +141,21 @@ namespace OpenRA.Graphics selectable.DrawRollover(this, unit); } - public void DrawLocus(Color c, int2[] cells) + public void DrawLocus(Color c, CPos[] cells) { var dict = cells.ToDictionary(a => a, a => 0); var wlr = Game.Renderer.WorldLineRenderer; foreach (var t in dict.Keys) { - if (!dict.ContainsKey(t + new int2(-1, 0))) - wlr.DrawLine(Game.CellSize * t, Game.CellSize * (t + new int2(0, 1)), - c, c); - if (!dict.ContainsKey(t + new int2(1, 0))) - wlr.DrawLine(Game.CellSize * (t + new int2(1, 0)), Game.CellSize * (t + new int2(1, 1)), - c, c); - if (!dict.ContainsKey(t + new int2(0, -1))) - wlr.DrawLine(Game.CellSize * t, Game.CellSize * (t + new int2(1, 0)), - c, c); - if (!dict.ContainsKey(t + new int2(0, 1))) - wlr.DrawLine(Game.CellSize * (t + new int2(0, 1)), Game.CellSize * (t + new int2(1, 1)), - c, c); + if (!dict.ContainsKey(t + new CVec(-1, 0))) + wlr.DrawLine(t.ToPPos().ToFloat2(), (t + new CVec(0, 1)).ToPPos().ToFloat2(), c, c); + if (!dict.ContainsKey(t + new CVec(1, 0))) + wlr.DrawLine((t + new CVec(1, 0)).ToPPos().ToFloat2(), (t + new CVec(1, 1)).ToPPos().ToFloat2(), c, c); + if (!dict.ContainsKey(t + new CVec(0, -1))) + wlr.DrawLine(t.ToPPos().ToFloat2(), (t + new CVec(1, 0)).ToPPos().ToFloat2(), c, c); + if (!dict.ContainsKey(t + new CVec(0, 1))) + wlr.DrawLine((t + new CVec(0, 1)).ToPPos().ToFloat2(), (t + new CVec(1, 1)).ToPPos().ToFloat2(), c, c); } } diff --git a/OpenRA.Game/Map.cs b/OpenRA.Game/Map.cs index 2eebf00039..dd342cf2bc 100644 --- a/OpenRA.Game/Map.cs +++ b/OpenRA.Game/Map.cs @@ -338,7 +338,7 @@ namespace OpenRA return dataStream.ToArray(); } - public bool IsInMap(int2 xy) { return IsInMap(xy.X, xy.Y); } + public bool IsInMap(CPos xy) { return IsInMap(xy.X, xy.Y); } public bool IsInMap(int x, int y) { return Bounds.Contains(x,y); } static T[,] ResizeArray(T[,] ts, T t, int width, int height) diff --git a/OpenRA.Game/Network/Order.cs b/OpenRA.Game/Network/Order.cs index 7f2bb449b7..0f486e987b 100755 --- a/OpenRA.Game/Network/Order.cs +++ b/OpenRA.Game/Network/Order.cs @@ -39,15 +39,15 @@ namespace OpenRA public readonly Actor Subject; public readonly bool Queued; public Actor TargetActor; - public int2 TargetLocation; + public CPos TargetLocation; public string TargetString; - public int2 ExtraLocation; + public CPos ExtraLocation; public bool IsImmediate; public Player Player { get { return Subject.Owner; } } Order(string orderString, Actor subject, - Actor targetActor, int2 targetLocation, string targetString, bool queued, int2 extraLocation) + Actor targetActor, CPos targetLocation, string targetString, bool queued, CPos extraLocation) { this.OrderString = orderString; this.Subject = subject; @@ -60,10 +60,10 @@ namespace OpenRA // For scripting special powers public Order() - : this(null, null, null, int2.Zero, null, false, int2.Zero) { } + : this(null, null, null, CPos.Zero, null, false, CPos.Zero) { } public Order(string orderString, Actor subject, bool queued) - : this(orderString, subject, null, int2.Zero, null, queued, int2.Zero) { } + : this(orderString, subject, null, CPos.Zero, null, queued, CPos.Zero) { } public Order(string orderstring, Order order) : this(orderstring, order.Subject, order.TargetActor, order.TargetLocation, @@ -98,21 +98,21 @@ namespace OpenRA OrderFields fields = 0; if (TargetActor != null) fields |= OrderFields.TargetActor; - if (TargetLocation != int2.Zero) fields |= OrderFields.TargetLocation; + if (TargetLocation != CPos.Zero) fields |= OrderFields.TargetLocation; if (TargetString != null) fields |= OrderFields.TargetString; if (Queued) fields |= OrderFields.Queued; - if (ExtraLocation != int2.Zero) fields |= OrderFields.ExtraLocation; + if (ExtraLocation != CPos.Zero) fields |= OrderFields.ExtraLocation; w.Write((byte)fields); if (TargetActor != null) w.Write(UIntFromActor(TargetActor)); - if (TargetLocation != int2.Zero) - w.Write(TargetLocation); + if (TargetLocation != CPos.Zero) + w.Write(TargetLocation.ToInt2()); if (TargetString != null) w.Write(TargetString); - if (ExtraLocation != int2.Zero) - w.Write(ExtraLocation); + if (ExtraLocation != CPos.Zero) + w.Write(ExtraLocation.ToInt2()); return ret.ToArray(); } @@ -130,10 +130,10 @@ namespace OpenRA var flags = (OrderFields)r.ReadByte(); var targetActorId = flags.HasField(OrderFields.TargetActor) ? r.ReadUInt32() : 0xffffffff; - var targetLocation = flags.HasField(OrderFields.TargetLocation) ? r.ReadInt2() : int2.Zero; + var targetLocation = (CPos)( flags.HasField(OrderFields.TargetLocation) ? r.ReadInt2() : int2.Zero ); var targetString = flags.HasField(OrderFields.TargetString) ? r.ReadString() : null; var queued = flags.HasField(OrderFields.Queued); - var extraLocation = flags.HasField(OrderFields.ExtraLocation) ? r.ReadInt2() : int2.Zero; + var extraLocation = (CPos)(flags.HasField(OrderFields.ExtraLocation) ? r.ReadInt2() : int2.Zero); Actor subject, targetActor; if( !TryGetActorFromUInt( world, subjectId, out subject ) || !TryGetActorFromUInt( world, targetActorId, out targetActor ) ) @@ -218,17 +218,17 @@ namespace OpenRA public static Order StartProduction(Actor subject, string item, int count) { - return new Order("StartProduction", subject, false) { TargetLocation = new int2(count, 0), TargetString = item }; + return new Order("StartProduction", subject, false) { TargetLocation = new CPos(count, 0), TargetString = item }; } public static Order PauseProduction(Actor subject, string item, bool pause) { - return new Order("PauseProduction", subject, false) { TargetLocation = new int2(pause ? 1 : 0, 0), TargetString = item }; + return new Order("PauseProduction", subject, false) { TargetLocation = new CPos(pause ? 1 : 0, 0), TargetString = item }; } public static Order CancelProduction(Actor subject, string item, int count) { - return new Order("CancelProduction", subject, false) { TargetLocation = new int2(count, 0), TargetString = item }; + return new Order("CancelProduction", subject, false) { TargetLocation = new CPos(count, 0), TargetString = item }; } } } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 17ab5219b7..bca92c4d0e 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -78,6 +78,9 @@ + + + @@ -114,6 +117,8 @@ + + diff --git a/OpenRA.Game/Orders/GenericSelectTarget.cs b/OpenRA.Game/Orders/GenericSelectTarget.cs index 8025dd5af2..481f19e925 100644 --- a/OpenRA.Game/Orders/GenericSelectTarget.cs +++ b/OpenRA.Game/Orders/GenericSelectTarget.cs @@ -48,14 +48,14 @@ namespace OpenRA.Orders } - public IEnumerable Order(World world, int2 xy, MouseInput mi) + public IEnumerable Order(World world, CPos xy, MouseInput mi) { if (mi.Button != expectedButton) world.CancelInputMode(); return OrderInner(world, xy, mi); } - IEnumerable OrderInner(World world, int2 xy, MouseInput mi) + IEnumerable OrderInner(World world, CPos xy, MouseInput mi) { if (mi.Button == expectedButton && world.Map.IsInMap(xy)) { @@ -68,6 +68,6 @@ namespace OpenRA.Orders public virtual void Tick(World world) { } public void RenderBeforeWorld(WorldRenderer wr, World world) { } public void RenderAfterWorld(WorldRenderer wr, World world) { } - public string GetCursor(World world, int2 xy, MouseInput mi) { return world.Map.IsInMap(xy) ? cursor : "generic-blocked"; } + public string GetCursor(World world, CPos xy, MouseInput mi) { return world.Map.IsInMap(xy) ? cursor : "generic-blocked"; } } } diff --git a/OpenRA.Game/Orders/IOrderGenerator.cs b/OpenRA.Game/Orders/IOrderGenerator.cs index bb45c00450..7de5a38ee6 100644 --- a/OpenRA.Game/Orders/IOrderGenerator.cs +++ b/OpenRA.Game/Orders/IOrderGenerator.cs @@ -15,10 +15,10 @@ namespace OpenRA { public interface IOrderGenerator { - IEnumerable Order(World world, int2 xy, MouseInput mi); + IEnumerable Order(World world, CPos xy, MouseInput mi); void Tick(World world); void RenderBeforeWorld(WorldRenderer wr, World world); void RenderAfterWorld(WorldRenderer wr, World world); - string GetCursor(World world, int2 xy, MouseInput mi); + string GetCursor(World world, CPos xy, MouseInput mi); } } diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index bc48460593..a1717319b1 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -17,7 +17,7 @@ namespace OpenRA.Orders { class UnitOrderGenerator : IOrderGenerator { - public IEnumerable Order( World world, int2 xy, MouseInput mi ) + public IEnumerable Order( World world, CPos xy, MouseInput mi ) { var underCursor = world.FindUnitsAtMouse(mi.Location) .Where(a => a.HasTrait()) @@ -45,7 +45,7 @@ namespace OpenRA.Orders public void RenderBeforeWorld( WorldRenderer wr, World world ) { } public void RenderAfterWorld( WorldRenderer wr, World world ) { } - public string GetCursor( World world, int2 xy, MouseInput mi ) + public string GetCursor(World world, CPos xy, MouseInput mi) { bool useSelect = false; @@ -68,7 +68,7 @@ namespace OpenRA.Orders return orders[0].cursor ?? ((useSelect) ? "select" : "default"); } - static UnitOrderResult OrderForUnit( Actor self, int2 xy, MouseInput mi, Actor underCursor ) + static UnitOrderResult OrderForUnit(Actor self, CPos xy, MouseInput mi, Actor underCursor) { if (self.Owner != self.World.LocalPlayer) return null; diff --git a/OpenRA.Game/PPos.cs b/OpenRA.Game/PPos.cs new file mode 100644 index 0000000000..1dd27eddb6 --- /dev/null +++ b/OpenRA.Game/PPos.cs @@ -0,0 +1,70 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Drawing; + +namespace OpenRA +{ + /// + /// Pixel coordinate position in the world (fine). + /// + public struct PPos + { + public readonly int X, Y; + + public PPos(int x, int y) { X = x; Y = y; } + + public static readonly PPos Zero = new PPos(0, 0); + + public static explicit operator PPos(int2 a) { return new PPos(a.X, a.Y); } + + public static explicit operator PVecInt(PPos a) { return new PVecInt(a.X, a.Y); } + public static explicit operator PVecFloat(PPos a) { return new PVecFloat(a.X, a.Y); } + + public static PPos operator +(PPos a, PVecInt b) { return new PPos(a.X + b.X, a.Y + b.Y); } + public static PVecInt operator -(PPos a, PPos b) { return new PVecInt(a.X - b.X, a.Y - b.Y); } + public static PPos operator -(PPos a, PVecInt b) { return new PPos(a.X - b.X, a.Y - b.Y); } + + public static bool operator ==(PPos me, PPos other) { return (me.X == other.X && me.Y == other.Y); } + public static bool operator !=(PPos me, PPos other) { return !(me == other); } + + public static PPos Max(PPos a, PPos b) { return new PPos(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); } + public static PPos Min(PPos a, PPos b) { return new PPos(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); } + + public static PPos Lerp(PPos a, PPos b, int mul, int div) + { + return a + ((PVecInt)(b - a) * mul / div); + } + + public float2 ToFloat2() { return new float2(X, Y); } + public int2 ToInt2() { return new int2(X, Y); } + public CPos ToCPos() { return new CPos((int)(1f / Game.CellSize * X), (int)(1f / Game.CellSize * Y)); } + + public PPos Clamp(Rectangle r) + { + return new PPos(Math.Min(r.Right, Math.Max(X, r.Left)), + Math.Min(r.Bottom, Math.Max(Y, r.Top))); + } + + public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + + PPos o = (PPos)obj; + return o == this; + } + + public override string ToString() { return "{0},{1}".F(X, Y); } + } +} diff --git a/OpenRA.Game/PVecFloat.cs b/OpenRA.Game/PVecFloat.cs new file mode 100644 index 0000000000..be463763d4 --- /dev/null +++ b/OpenRA.Game/PVecFloat.cs @@ -0,0 +1,97 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Drawing; + +namespace OpenRA +{ + /// + /// Pixel coordinate vector (fine; float) + /// + public struct PVecFloat + { + public readonly float X, Y; + + public PVecFloat(float x, float y) { X = x; Y = y; } + public PVecFloat(Size p) { X = p.Width; Y = p.Height; } + + public static readonly PVecFloat Zero = new PVecFloat(0, 0); + + public static explicit operator PVecInt(PVecFloat a) { return new PVecInt((int)a.X, (int)a.Y); } + public static explicit operator PVecFloat(float2 a) { return new PVecFloat(a.X, a.Y); } + + public static PVecFloat operator +(PVecFloat a, PVecFloat b) { return new PVecFloat(a.X + b.X, a.Y + b.Y); } + public static PVecFloat operator -(PVecFloat a, PVecFloat b) { return new PVecFloat(a.X - b.X, a.Y - b.Y); } + public static PVecFloat operator *(float a, PVecFloat b) { return new PVecFloat(a * b.X, a * b.Y); } + public static PVecFloat operator *(PVecFloat b, float a) { return new PVecFloat(a * b.X, a * b.Y); } + public static PVecFloat operator /(PVecFloat a, float b) { return new PVecFloat(a.X / b, a.Y / b); } + + public static PVecFloat operator -(PVecFloat a) { return new PVecFloat(-a.X, -a.Y); } + + public static bool operator ==(PVecFloat me, PVecFloat other) { return (me.X == other.X && me.Y == other.Y); } + public static bool operator !=(PVecFloat me, PVecFloat other) { return !(me == other); } + + public static PVecFloat Max(PVecFloat a, PVecFloat b) { return new PVecFloat(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); } + public static PVecFloat Min(PVecFloat a, PVecFloat b) { return new PVecFloat(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); } + + public static float Dot(PVecFloat a, PVecFloat b) { return a.X * b.X + a.Y * b.Y; } + + public static PVecFloat FromAngle(float a) { return new PVecFloat((float)Math.Sin(a), (float)Math.Cos(a)); } + + public static PVecFloat Lerp(PVecFloat a, PVecFloat b, float t) + { + return new PVecFloat( + float2.Lerp(a.X, b.X, t), + float2.Lerp(a.Y, b.Y, t) + ); + } + + public static PVecFloat Lerp(PVecFloat a, PVecFloat b, PVecFloat t) + { + return new PVecFloat( + float2.Lerp(a.X, b.X, t.X), + float2.Lerp(a.Y, b.Y, t.Y) + ); + } + + public PVecFloat Sign() { return new PVecFloat(Math.Sign(X), Math.Sign(Y)); } + public PVecFloat Abs() { return new PVecFloat(Math.Abs(X), Math.Abs(Y)); } + public PVecFloat Round() { return new PVecFloat((float)Math.Round(X), (float)Math.Round(Y)); } + public float LengthSquared { get { return X * X + Y * Y; } } + public float Length { get { return (float)Math.Sqrt(LengthSquared); } } + + public float2 ToFloat2() { return new float2(X, Y); } + public int2 ToInt2() { return new int2((int)X, (int)Y); } + + static float Constrain(float x, float a, float b) { return x < a ? a : x > b ? b : x; } + + public PVecFloat Constrain(PVecFloat min, PVecFloat max) + { + return new PVecFloat( + Constrain(X, min.X, max.X), + Constrain(Y, min.Y, max.Y) + ); + } + + public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + + PVecFloat o = (PVecFloat)obj; + return o == this; + } + + public override string ToString() { return "({0},{1})".F(X, Y); } + } +} diff --git a/OpenRA.Game/PVecInt.cs b/OpenRA.Game/PVecInt.cs new file mode 100644 index 0000000000..e6e5832256 --- /dev/null +++ b/OpenRA.Game/PVecInt.cs @@ -0,0 +1,79 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see COPYING. + */ +#endregion + +using System; +using System.Drawing; + +namespace OpenRA +{ + /// + /// Pixel coordinate vector (fine; integer) + /// + public struct PVecInt + { + public readonly int X, Y; + + public PVecInt(int x, int y) { X = x; Y = y; } + public PVecInt(Size p) { X = p.Width; Y = p.Height; } + + public static readonly PVecInt Zero = new PVecInt(0, 0); + public static PVecInt OneCell { get { return new PVecInt(Game.CellSize, Game.CellSize); } } + + public static implicit operator PVecFloat(PVecInt a) { return new PVecFloat((float)a.X, (float)a.Y); } + public static explicit operator PVecInt(int2 a) { return new PVecInt(a.X, a.Y); } + + public static PVecInt FromRadius(int r) { return new PVecInt(r, r); } + + public static PVecInt operator +(PVecInt a, PVecInt b) { return new PVecInt(a.X + b.X, a.Y + b.Y); } + public static PVecInt operator -(PVecInt a, PVecInt b) { return new PVecInt(a.X - b.X, a.Y - b.Y); } + public static PVecInt operator *(int a, PVecInt b) { return new PVecInt(a * b.X, a * b.Y); } + public static PVecInt operator *(PVecInt b, int a) { return new PVecInt(a * b.X, a * b.Y); } + public static PVecInt operator /(PVecInt a, int b) { return new PVecInt(a.X / b, a.Y / b); } + + public static PVecInt operator -(PVecInt a) { return new PVecInt(-a.X, -a.Y); } + + public static bool operator ==(PVecInt me, PVecInt other) { return (me.X == other.X && me.Y == other.Y); } + public static bool operator !=(PVecInt me, PVecInt other) { return !(me == other); } + + public static PVecInt Max(PVecInt a, PVecInt b) { return new PVecInt(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); } + public static PVecInt Min(PVecInt a, PVecInt b) { return new PVecInt(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); } + + public static int Dot(PVecInt a, PVecInt b) { return a.X * b.X + a.Y * b.Y; } + + public PVecInt Sign() { return new PVecInt(Math.Sign(X), Math.Sign(Y)); } + public PVecInt Abs() { return new PVecInt(Math.Abs(X), Math.Abs(Y)); } + 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 PVecInt Clamp(Rectangle r) + { + return new PVecInt( + Math.Min(r.Right, Math.Max(X, r.Left)), + Math.Min(r.Bottom, Math.Max(Y, r.Top)) + ); + } + + public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } + + public override bool Equals(object obj) + { + if (obj == null) + return false; + + PVecInt o = (PVecInt)obj; + return o == this; + } + + public override string ToString() { return "{0},{1}".F(X, Y); } + } +} diff --git a/OpenRA.Game/Sound.cs b/OpenRA.Game/Sound.cs index 5fbc99ec59..b2f34c4473 100644 --- a/OpenRA.Game/Sound.cs +++ b/OpenRA.Game/Sound.cs @@ -64,7 +64,7 @@ namespace OpenRA public static void SetListenerPosition(float2 position) { soundEngine.SetListenerPosition(position); } - static ISound Play(Player player, string name, bool headRelative, float2 pos, float volumeModifier) + static ISound Play(Player player, string name, bool headRelative, PPos pos, float volumeModifier) { if (player != null && player != player.World.LocalPlayer) return null; @@ -72,16 +72,16 @@ namespace OpenRA return null; return soundEngine.Play2D(sounds[name], - false, headRelative, pos, + false, headRelative, pos.ToFloat2(), InternalSoundVolume * volumeModifier); } - public static ISound Play(string name) { return Play(null, name, true, float2.Zero, 1); } - public static ISound Play(string name, float2 pos) { return Play(null, name, false, pos, 1); } - public static ISound Play(string name, float volumeModifier) { return Play(null, name, true, float2.Zero, volumeModifier); } - public static ISound Play(string name, float2 pos, float volumeModifier) { return Play(null, name, false, pos, volumeModifier); } - public static ISound PlayToPlayer(Player player, string name) { return Play( player, name, true, float2.Zero, 1); } - public static ISound PlayToPlayer(Player player, string name, float2 pos) { return Play(player, name, false, pos, 1); } + public static ISound Play(string name) { return Play(null, name, true, PPos.Zero, 1); } + public static ISound Play(string name, PPos pos) { return Play(null, name, false, pos, 1); } + public static ISound Play(string name, float volumeModifier) { return Play(null, name, true, PPos.Zero, volumeModifier); } + public static ISound Play(string name, PPos pos, float volumeModifier) { return Play(null, name, false, pos, volumeModifier); } + public static ISound PlayToPlayer(Player player, string name) { return Play(player, name, true, PPos.Zero, 1); } + public static ISound PlayToPlayer(Player player, string name, PPos pos) { return Play(player, name, false, pos, 1); } public static void PlayVideo(byte[] raw) { diff --git a/OpenRA.Game/Sync.cs b/OpenRA.Game/Sync.cs index 63c1e02ea0..029367a5e5 100755 --- a/OpenRA.Game/Sync.cs +++ b/OpenRA.Game/Sync.cs @@ -50,6 +50,26 @@ namespace OpenRA il.EmitCall(OpCodes.Call, ((Func)hash_int2).Method, null); il.Emit(OpCodes.Xor); } + else if (type == typeof(CPos)) + { + il.EmitCall(OpCodes.Call, ((Func)hash_CPos).Method, null); + il.Emit(OpCodes.Xor); + } + else if (type == typeof(CVec)) + { + il.EmitCall(OpCodes.Call, ((Func)hash_CVec).Method, null); + il.Emit(OpCodes.Xor); + } + else if (type == typeof(PPos)) + { + il.EmitCall(OpCodes.Call, ((Func)hash_PPos).Method, null); + il.Emit(OpCodes.Xor); + } + else if (type == typeof(PVecInt)) + { + il.EmitCall(OpCodes.Call, ((Func)hash_PVecInt).Method, null); + il.Emit(OpCodes.Xor); + } else if (type == typeof(TypeDictionary)) { il.EmitCall(OpCodes.Call, ((Func)hash_tdict).Method, null); @@ -110,6 +130,26 @@ namespace OpenRA return ( ( i2.X * 5 ) ^ ( i2.Y * 3 ) ) / 4; } + public static int hash_CPos( CPos i2 ) + { + return ( ( i2.X * 5) ^ ( i2.Y * 3 ) ) / 4; + } + + public static int hash_CVec( CVec i2 ) + { + return ( ( i2.X * 5) ^ ( i2.Y * 3 ) ) / 4; + } + + public static int hash_PPos( PPos i2 ) + { + return ( ( i2.X * 5) ^ ( i2.Y * 3 ) ) / 4; + } + + public static int hash_PVecInt( PVecInt i2 ) + { + return ( ( i2.X * 5) ^ ( i2.Y * 3 ) ) / 4; + } + public static int hash_tdict( TypeDictionary d ) { int ret = 0; diff --git a/OpenRA.Game/Traits/DrawLineToTarget.cs b/OpenRA.Game/Traits/DrawLineToTarget.cs index ff2a300786..5f6dcc7a41 100644 --- a/OpenRA.Game/Traits/DrawLineToTarget.cs +++ b/OpenRA.Game/Traits/DrawLineToTarget.cs @@ -52,12 +52,12 @@ namespace OpenRA.Traits return; var move = self.TraitOrDefault(); - var origin = move != null ? self.CenterLocation - new int2(0, move.Altitude) : self.CenterLocation; + var origin = (move != null ? self.CenterLocation - new PVecInt(0, move.Altitude) : self.CenterLocation).ToFloat2(); var wlr = Game.Renderer.WorldLineRenderer; - wlr.DrawLine(origin, target.CenterLocation, c, c); - DrawTargetMarker(wlr, target.CenterLocation); + wlr.DrawLine(origin, target.CenterLocation.ToFloat2(), c, c); + DrawTargetMarker(wlr, target.CenterLocation.ToFloat2()); DrawTargetMarker(wlr, origin); } diff --git a/OpenRA.Game/Traits/RevealsShroud.cs b/OpenRA.Game/Traits/RevealsShroud.cs index b9f06c475f..64ab26a019 100644 --- a/OpenRA.Game/Traits/RevealsShroud.cs +++ b/OpenRA.Game/Traits/RevealsShroud.cs @@ -19,7 +19,7 @@ namespace OpenRA.Traits class RevealsShroud : ITick { RevealsShroudInfo Info; - int2 previousLocation; + CPos previousLocation; public RevealsShroud(RevealsShroudInfo info) { diff --git a/OpenRA.Game/Traits/Selectable.cs b/OpenRA.Game/Traits/Selectable.cs index c00ebbef6e..22562f6382 100644 --- a/OpenRA.Game/Traits/Selectable.cs +++ b/OpenRA.Game/Traits/Selectable.cs @@ -146,12 +146,12 @@ namespace OpenRA.Traits { var alt = new float2(0, -mobile.Altitude); var targets = activity.GetTargets(self); - var start = self.CenterLocation + alt; + var start = self.CenterLocation.ToFloat2() + alt; var c = Color.Green; var wlr = Game.Renderer.WorldLineRenderer; - foreach (var step in targets.Select(p => p.CenterLocation)) + foreach (var step in targets.Select(p => p.CenterLocation.ToFloat2())) { var stp = step + alt; wlr.DrawLine(stp + new float2(-1, -1), stp + new float2(-1, 1), c, c); diff --git a/OpenRA.Game/Traits/Target.cs b/OpenRA.Game/Traits/Target.cs index c7b4f1578e..633fb7a84e 100644 --- a/OpenRA.Game/Traits/Target.cs +++ b/OpenRA.Game/Traits/Target.cs @@ -16,7 +16,7 @@ namespace OpenRA.Traits Actor actor; Player owner; - int2 pos; + PPos pos; bool valid; public static Target FromActor(Actor a) @@ -28,8 +28,8 @@ namespace OpenRA.Traits owner = (a != null) ? a.Owner : null }; } - public static Target FromPos(int2 p) { return new Target { pos = p, valid = true }; } - public static Target FromCell(int2 c) { return new Target { pos = Util.CenterOfCell(c), valid = true }; } + public static Target FromPos(PPos p) { return new Target { pos = p, valid = true }; } + public static Target FromCell(CPos c) { return new Target { pos = Util.CenterOfCell(c), valid = true }; } public static Target FromOrder(Order o) { return o.TargetActor != null @@ -40,8 +40,8 @@ namespace OpenRA.Traits public static readonly Target None = new Target(); public bool IsValid { get { return valid && (actor == null || (actor.IsInWorld && actor.Owner == owner)); } } - public int2 PxPosition { get { return IsActor ? actor.Trait().PxPosition : pos; } } - public int2 CenterLocation { get { return PxPosition; } } + public PPos PxPosition { get { return IsActor ? actor.Trait().PxPosition : pos; } } + public PPos CenterLocation { get { return PxPosition; } } public Actor Actor { get { return IsActor ? actor : null; } } public bool IsActor { get { return actor != null && !actor.Destroyed; } } diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 5ae50ac14b..e5aa229606 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -47,7 +47,7 @@ namespace OpenRA.Traits string OrderID { get; } int OrderPriority { get; } bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceQueue, ref string cursor); - bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueue, ref string cursor); + bool CanTargetLocation(Actor self, CPos location, List actorsAtLocation, bool forceAttack, bool forceQueue, ref string cursor); bool IsQueued { get; } } @@ -60,7 +60,7 @@ namespace OpenRA.Traits public interface INotifyKilled { void Killed(Actor self, AttackInfo e); } public interface INotifyAppliedDamage { void AppliedDamage(Actor self, Actor damaged, AttackInfo e); } public interface INotifyBuildComplete { void BuildingComplete(Actor self); } - public interface INotifyProduction { void UnitProduced(Actor self, Actor other, int2 exit); } + public interface INotifyProduction { void UnitProduced(Actor self, Actor other, CPos exit); } public interface INotifyCapture { void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner); } public interface INotifyOtherCaptured { void OnActorCaptured(Actor self, Actor captured, Actor captor, Player oldOwner, Player newOwner); } public interface IAcceptSpy { void OnInfiltrate(Actor self, Actor spy); } @@ -79,23 +79,23 @@ namespace OpenRA.Traits public interface IRadarSignature { - IEnumerable RadarSignatureCells(Actor self); + IEnumerable RadarSignatureCells(Actor self); Color RadarSignatureColor(Actor self); } public interface IVisibilityModifier { bool IsVisible(Actor self); } public interface IRadarColorModifier { Color RadarColorOverride(Actor self); } - public interface IHasLocation { int2 PxPosition { get; } } + public interface IHasLocation { PPos PxPosition { get; } } public interface IOccupySpace : IHasLocation { - int2 TopLeft { get; } - IEnumerable> OccupiedCells(); + CPos TopLeft { get; } + IEnumerable> OccupiedCells(); } public static class IOccupySpaceExts { - public static int2 NearestCellTo(this IOccupySpace ios, int2 other) + public static CPos NearestCellTo(this IOccupySpace ios, CPos other) { var nearest = ios.TopLeft; var nearestDistance = int.MaxValue; @@ -125,10 +125,10 @@ namespace OpenRA.Traits public interface ITeleportable : IHasLocation /* crap name! */ { - bool CanEnterCell(int2 location); - void SetPosition(Actor self, int2 cell); - void SetPxPosition(Actor self, int2 px); - void AdjustPxPosition(Actor self, int2 px); /* works like SetPxPosition, but visual only */ + bool CanEnterCell(CPos location); + void SetPosition(Actor self, CPos cell); + void SetPxPosition(Actor self, PPos px); + void AdjustPxPosition(Actor self, PPos px); /* works like SetPxPosition, but visual only */ } public interface IMove : ITeleportable { int Altitude { get; set; } } @@ -212,7 +212,7 @@ namespace OpenRA.Traits public interface ITargetable { string[] TargetTypes { get; } - IEnumerable TargetableCells(Actor self); + IEnumerable TargetableCells(Actor self); bool TargetableBy(Actor self, Actor byActor); } diff --git a/OpenRA.Game/Traits/Util.cs b/OpenRA.Game/Traits/Util.cs index 956c587c95..d4a0834533 100755 --- a/OpenRA.Game/Traits/Util.cs +++ b/OpenRA.Game/Traits/Util.cs @@ -30,6 +30,16 @@ namespace OpenRA.Traits return ( facing - rot ) & 0xFF; } + public static int GetFacing(PVecInt d, int currentFacing) + { + return GetFacing(d.ToInt2(), currentFacing); + } + + public static int GetFacing(CVec d, int currentFacing) + { + return GetFacing(d.ToInt2(), currentFacing); + } + public static int GetFacing( int2 d, int currentFacing ) { if (d == int2.Zero) @@ -80,14 +90,14 @@ namespace OpenRA.Traits ecc * (cosAngle * v.Y - sinAngle * v.X)); } - public static int2 CenterOfCell(int2 loc) + public static PPos CenterOfCell(CPos loc) { - return new int2( Game.CellSize / 2, Game.CellSize / 2 ) + Game.CellSize * loc; + return loc.ToPPos() + new PVecInt(Game.CellSize / 2, Game.CellSize / 2); } - public static int2 BetweenCells(int2 from, int2 to) + public static PPos BetweenCells(CPos from, CPos to) { - return int2.Lerp( CenterOfCell( from ), CenterOfCell( to ), 1, 2 ); + return PPos.Lerp(CenterOfCell(from), CenterOfCell(to), 1, 2); } public static int2 AsInt2(this int[] xs) { return new int2(xs[0], xs[1]); } @@ -120,6 +130,7 @@ namespace OpenRA.Traits public static Color ArrayToColor(int[] x) { return Color.FromArgb(x[0], x[1], x[2]); } + [Obsolete("Use ToCPos() method", true)] public static int2 CellContaining(float2 pos) { return (1f / Game.CellSize * pos).ToInt2(); } /* pretty crap */ @@ -134,39 +145,39 @@ namespace OpenRA.Traits } } - static IEnumerable Neighbours(int2 c, bool allowDiagonal) + static IEnumerable Neighbours(CPos c, bool allowDiagonal) { yield return c; - yield return new int2(c.X - 1, c.Y); - yield return new int2(c.X + 1, c.Y); - yield return new int2(c.X, c.Y - 1); - yield return new int2(c.X, c.Y + 1); + yield return new CPos(c.X - 1, c.Y); + yield return new CPos(c.X + 1, c.Y); + yield return new CPos(c.X, c.Y - 1); + yield return new CPos(c.X, c.Y + 1); if (allowDiagonal) { - yield return new int2(c.X - 1, c.Y - 1); - yield return new int2(c.X + 1, c.Y - 1); - yield return new int2(c.X - 1, c.Y + 1); - yield return new int2(c.X + 1, c.Y + 1); + yield return new CPos(c.X - 1, c.Y - 1); + yield return new CPos(c.X + 1, c.Y - 1); + yield return new CPos(c.X - 1, c.Y + 1); + yield return new CPos(c.X + 1, c.Y + 1); } } - public static IEnumerable ExpandFootprint(IEnumerable cells, bool allowDiagonal) + public static IEnumerable ExpandFootprint(IEnumerable cells, bool allowDiagonal) { - var result = new Dictionary(); + var result = new Dictionary(); foreach (var c in cells.SelectMany(c => Neighbours(c, allowDiagonal))) result[c] = true; return result.Keys; } - public static IEnumerable AdjacentCells( Target target ) + public static IEnumerable AdjacentCells(Target target) { var cells = target.IsActor ? target.Actor.OccupiesSpace.OccupiedCells().Select(c => c.First).ToArray() - : new int2[] {}; + : new CPos[] {}; if (cells.Length == 0) - cells = new [] { Util.CellContaining(target.CenterLocation) }; + cells = new CPos[] { target.CenterLocation.ToCPos() }; return Util.ExpandFootprint(cells, true); } diff --git a/OpenRA.Game/Traits/Waypoint.cs b/OpenRA.Game/Traits/Waypoint.cs index 9eaae124a0..96b29fb8f5 100644 --- a/OpenRA.Game/Traits/Waypoint.cs +++ b/OpenRA.Game/Traits/Waypoint.cs @@ -20,16 +20,16 @@ namespace OpenRA.Traits class Waypoint : IOccupySpace, ISync { - [Sync] int2 location; + [Sync] CPos location; public Waypoint(ActorInitializer init) { - this.location = init.Get(); + this.location = init.Get(); } - public int2 TopLeft { get { return location; } } + public CPos TopLeft { get { return location; } } - public IEnumerable> OccupiedCells() { yield break; } - public int2 PxPosition { get { return Util.CenterOfCell( location ); } } + public IEnumerable> OccupiedCells() { yield break; } + public PPos PxPosition { get { return Util.CenterOfCell(location); } } } } diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index 7bf1f78c96..1fb5edf034 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -39,13 +39,13 @@ namespace OpenRA.Traits for (int x = clip.Left; x < clip.Right; x++) for (int y = clip.Top; y < clip.Bottom; y++) { - if (!world.LocalShroud.IsExplored(new int2(x, y))) + if (!world.LocalShroud.IsExplored(new CPos(x, y))) continue; var c = content[x, y]; if (c.image != null) c.image[c.density].DrawAt( - Game.CellSize * new int2(x, y), + new CPos(x, y).ToPPos().ToFloat2(), c.type.info.PaletteIndex); } } @@ -70,7 +70,7 @@ namespace OpenRA.Traits if (type == null) continue; - if (!AllowResourceAt(type, new int2(x,y))) + if (!AllowResourceAt(type, new CPos(x,y))) continue; content[x, y].type = type; @@ -86,7 +86,7 @@ namespace OpenRA.Traits } } - public bool AllowResourceAt(ResourceType rt, int2 a) + public bool AllowResourceAt(ResourceType rt, CPos a) { if (!world.Map.IsInMap(a.X, a.Y)) return false; if (!rt.info.AllowedTerrainTypes.Contains(world.GetTerrainInfo(a).Type)) return false; @@ -136,7 +136,7 @@ namespace OpenRA.Traits public bool IsFull(int i, int j) { return content[i, j].density == content[i, j].image.Length - 1; } - public ResourceType Harvest(int2 p) + public ResourceType Harvest(CPos p) { var type = content[p.X,p.Y].type; if (type == null) return null; @@ -150,7 +150,7 @@ namespace OpenRA.Traits return type; } - public void Destroy(int2 p) + public void Destroy(CPos p) { // Don't break other users of CustomTerrain if there are no resources if (content[p.X, p.Y].type == null) @@ -162,7 +162,7 @@ namespace OpenRA.Traits world.Map.CustomTerrain[p.X, p.Y] = null; } - public ResourceType GetResource(int2 p) { return content[p.X, p.Y].type; } + public ResourceType GetResource(CPos p) { return content[p.X, p.Y].type; } public struct CellContents { diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index e77e557fd2..9a552aad67 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -54,22 +54,22 @@ namespace OpenRA.Traits // cache of positions that were added, so no matter what crazy trait code does, it // can't make us invalid. - class ActorVisibility { public int range; public int2[] vis; } + class ActorVisibility { public int range; public CPos[] vis; } Dictionary vis = new Dictionary(); - static IEnumerable FindVisibleTiles(World world, int2 a, int r) + static IEnumerable FindVisibleTiles(World world, CPos a, int r) { - var min = a - new int2(r, r); - var max = a + new int2(r, r); - if (min.X < world.Map.Bounds.Left - 1) min.X = world.Map.Bounds.Left - 1; - if (min.Y < world.Map.Bounds.Top - 1) min.Y = world.Map.Bounds.Top - 1; - if (max.X > world.Map.Bounds.Right) max.X = world.Map.Bounds.Right; - if (max.Y > world.Map.Bounds.Bottom) max.Y = world.Map.Bounds.Bottom; + var min = a - new CVec(r, r); + var max = a + new CVec(r, r); + if (min.X < world.Map.Bounds.Left - 1) min = new CPos(world.Map.Bounds.Left - 1, min.Y); + if (min.Y < world.Map.Bounds.Top - 1) min = new CPos(min.X, world.Map.Bounds.Top - 1); + if (max.X > world.Map.Bounds.Right) max = new CPos(world.Map.Bounds.Right, max.Y); + if (max.Y > world.Map.Bounds.Bottom) max = new CPos(max.X, world.Map.Bounds.Bottom); for (var j = min.Y; j <= max.Y; j++) for (var i = min.X; i <= max.X; i++) - if (r * r >= (new int2(i, j) - a).LengthSquared) - yield return new int2(i, j); + if (r * r >= (new CPos(i, j) - a).LengthSquared) + yield return new CPos(i, j); } void AddActor(Actor a) @@ -148,7 +148,7 @@ namespace OpenRA.Traits AddActor(a); } - public static IEnumerable GetVisOrigins(Actor a) + public static IEnumerable GetVisOrigins(Actor a) { var ios = a.OccupiesSpace; if (ios != null) @@ -157,7 +157,7 @@ namespace OpenRA.Traits if (cells.Any()) return cells.Select(c => c.First); } - return new[] { a.CenterLocation / Game.CellSize }; + return new[] { a.CenterLocation.ToCPos() }; } void RemoveActor(Actor a) @@ -183,7 +183,7 @@ namespace OpenRA.Traits RemoveActor(a); AddActor(a); } - public void Explore(World world, int2 center, int range) + public void Explore(World world, CPos center, int range) { foreach (var q in FindVisibleTiles(world, center, range)) exploredCells[q.X, q.Y] = true; @@ -216,7 +216,7 @@ namespace OpenRA.Traits Dirty(); } - public bool IsExplored(int2 xy) { return IsExplored(xy.X, xy.Y); } + public bool IsExplored(CPos xy) { return IsExplored(xy.X, xy.Y); } public bool IsExplored(int x, int y) { if (!map.IsInMap(x, y)) @@ -228,7 +228,7 @@ namespace OpenRA.Traits return exploredCells[x,y]; } - public bool IsVisible(int2 xy) { return IsVisible(xy.X, xy.Y); } + public bool IsVisible(CPos xy) { return IsVisible(xy.X, xy.Y); } public bool IsVisible(int x, int y) { if (Disabled) diff --git a/OpenRA.Game/Traits/World/SpatialBins.cs b/OpenRA.Game/Traits/World/SpatialBins.cs index c6a72ef2a9..563311cf6e 100644 --- a/OpenRA.Game/Traits/World/SpatialBins.cs +++ b/OpenRA.Game/Traits/World/SpatialBins.cs @@ -75,7 +75,7 @@ namespace OpenRA.Traits yield return a; } - public IEnumerable ActorsInBox(int2 a, int2 b) + public IEnumerable ActorsInBox(PPos a, PPos b) { var r = Rectangle.FromLTRB(a.X, a.Y, b.X, b.Y); diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 29721ccaa2..2022188277 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -42,12 +42,12 @@ namespace OpenRA.Widgets return; } - Game.Renderer.WorldLineRenderer.DrawRect(selbox.Value.First, selbox.Value.Second, Color.White); + Game.Renderer.WorldLineRenderer.DrawRect(selbox.Value.First.ToFloat2(), selbox.Value.Second.ToFloat2(), Color.White); foreach (var u in SelectActorsInBox(world, selbox.Value.First, selbox.Value.Second, _ => true)) worldRenderer.DrawRollover(u); } - int2 dragStart, dragEnd; + PPos dragStart, dragEnd; public override bool HandleMouseInput(MouseInput mi) { @@ -101,7 +101,7 @@ namespace OpenRA.Widgets return true; } - public Pair? SelectionBox + public Pair? SelectionBox { get { @@ -110,11 +110,11 @@ namespace OpenRA.Widgets } } - public void ApplyOrders(World world, int2 xy, MouseInput mi) + public void ApplyOrders(World world, PPos xy, MouseInput mi) { if (world.OrderGenerator == null) return; - var orders = world.OrderGenerator.Order(world, Traits.Util.CellContaining(xy), mi).ToArray(); + var orders = world.OrderGenerator.Order(world, xy.ToCPos(), mi).ToArray(); orders.Do( o => world.IssueOrder( o ) ); world.PlayVoiceForOrders(orders); @@ -135,7 +135,7 @@ namespace OpenRA.Widgets }; // TODO: fix this up. - return world.OrderGenerator.GetCursor( world, Game.viewport.ViewToWorld(mi).ToInt2(), mi ); + return world.OrderGenerator.GetCursor( world, Game.viewport.ViewToWorld(mi), mi ); } ); } @@ -161,7 +161,7 @@ namespace OpenRA.Widgets } static readonly Actor[] NoActors = {}; - IEnumerable SelectActorsInBox(World world, int2 a, int2 b, Func cond) + IEnumerable SelectActorsInBox(World world, PPos a, PPos b, Func cond) { return world.FindUnits(a, b) .Where( x => x.HasTrait() && world.LocalShroud.IsVisible(x) && cond(x) ) diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index faa127316a..53c442fa92 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -27,24 +27,24 @@ namespace OpenRA return FindUnits(world, loc, loc).Where(a => world.LocalShroud.IsVisible(a)); } - public static IEnumerable FindUnits(this World world, int2 a, int2 b) + public static IEnumerable FindUnits(this World world, PPos a, PPos b) { - var u = float2.Min(a, b).ToInt2(); - var v = float2.Max(a, b).ToInt2(); + var u = PPos.Min(a, b); + var v = PPos.Max(a, b); return world.WorldActor.Trait().ActorsInBox(u,v); } - public static Actor ClosestTo( this IEnumerable actors, int2 px ) + public static Actor ClosestTo(this IEnumerable actors, PPos px) { return actors.OrderBy( a => (a.CenterLocation - px).LengthSquared ).FirstOrDefault(); } - public static IEnumerable FindUnitsInCircle(this World world, int2 a, int r) + public static IEnumerable FindUnitsInCircle(this World world, PPos a, int r) { using (new PerfSample("FindUnitsInCircle")) { - var min = a - new int2(r, r); - var max = a + new int2(r, r); + var min = a - PVecInt.FromRadius(r); + var max = a + PVecInt.FromRadius(r); var actors = world.FindUnits(min, max); @@ -56,48 +56,48 @@ namespace OpenRA } } - public static IEnumerable FindTilesInCircle(this World world, int2 a, int r) + public static IEnumerable FindTilesInCircle(this World world, CPos a, int r) { - var min = world.ClampToWorld(a - new int2(r, r)); - var max = world.ClampToWorld(a + new int2(r, r)); + var min = world.ClampToWorld(a - new CVec(r, r)); + var max = world.ClampToWorld(a + new CVec(r, r)); for (var j = min.Y; j <= max.Y; j++) for (var i = min.X; i <= max.X; i++) - if (r * r >= (new int2(i, j) - a).LengthSquared) - yield return new int2(i, j); + if (r * r >= (new CPos(i, j) - a).LengthSquared) + yield return new CPos(i, j); } - public static string GetTerrainType(this World world, int2 cell) + public static string GetTerrainType(this World world, CPos cell) { var custom = world.Map.CustomTerrain[cell.X, cell.Y]; return custom != null ? custom : world.TileSet.GetTerrainType(world.Map.MapTiles.Value[cell.X, cell.Y]); } - public static TerrainTypeInfo GetTerrainInfo(this World world, int2 cell) + public static TerrainTypeInfo GetTerrainInfo(this World world, CPos cell) { return world.TileSet.Terrain[world.GetTerrainType(cell)]; } - public static int2 ClampToWorld( this World world, int2 xy ) + public static CPos ClampToWorld(this World world, CPos xy) { var r = world.Map.Bounds; return xy.Clamp(new Rectangle(r.X,r.Y,r.Width-1, r.Height-1)); } - public static int2 ChooseRandomEdgeCell(this World w) + public static CPos ChooseRandomEdgeCell(this World w) { var isX = w.SharedRandom.Next(2) == 0; var edge = w.SharedRandom.Next(2) == 0; - return new int2( + return new CPos( isX ? w.SharedRandom.Next(w.Map.Bounds.Left, w.Map.Bounds.Right) : (edge ? w.Map.Bounds.Left : w.Map.Bounds.Right), !isX ? w.SharedRandom.Next(w.Map.Bounds.Top, w.Map.Bounds.Bottom) : (edge ? w.Map.Bounds.Top : w.Map.Bounds.Bottom)); } - public static int2 ChooseRandomCell(this World w, Thirdparty.Random r) + public static CPos ChooseRandomCell(this World w, Thirdparty.Random r) { - return new int2( + return new CPos( r.Next(w.Map.Bounds.Left, w.Map.Bounds.Right), r.Next(w.Map.Bounds.Top, w.Map.Bounds.Bottom)); } diff --git a/OpenRA.Mods.Cnc/Activities/HarvesterDockSequence.cs b/OpenRA.Mods.Cnc/Activities/HarvesterDockSequence.cs index 7cf0efcbb0..ebe1db626d 100644 --- a/OpenRA.Mods.Cnc/Activities/HarvesterDockSequence.cs +++ b/OpenRA.Mods.Cnc/Activities/HarvesterDockSequence.cs @@ -27,8 +27,8 @@ namespace OpenRA.Mods.Cnc readonly RenderUnit ru; State state; - int2 startDock; - int2 endDock; + PPos startDock; + PPos endDock; public HarvesterDockSequence(Actor self, Actor proc) { this.proc = proc; @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Cnc harv = self.Trait(); ru = self.Trait(); startDock = self.Trait().PxPosition; - endDock = proc.Trait().PxPosition + new int2(-15,8); + endDock = proc.Trait().PxPosition + new PVecInt(-15,8); } public override Activity Tick(Actor self) diff --git a/OpenRA.Mods.Cnc/Effects/IonCannon.cs b/OpenRA.Mods.Cnc/Effects/IonCannon.cs index acfb886414..9d7543d9b9 100644 --- a/OpenRA.Mods.Cnc/Effects/IonCannon.cs +++ b/OpenRA.Mods.Cnc/Effects/IonCannon.cs @@ -22,7 +22,7 @@ namespace OpenRA.Mods.Cnc.Effects Animation anim; Actor firedBy; - public IonCannon(Actor firedBy, World world, int2 location) + public IonCannon(Actor firedBy, World world, CPos location) { this.firedBy = firedBy; target = Target.FromCell(location); @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Cnc.Effects public IEnumerable Render() { yield return new Renderable(anim.Image, - target.CenterLocation - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize), + target.CenterLocation.ToFloat2() - new float2(.5f * anim.Image.size.X, anim.Image.size.Y - Game.CellSize), "effect", (int)target.CenterLocation.Y); } diff --git a/OpenRA.Mods.Cnc/IonCannonPower.cs b/OpenRA.Mods.Cnc/IonCannonPower.cs index 59327a9078..03b0eee3b9 100644 --- a/OpenRA.Mods.Cnc/IonCannonPower.cs +++ b/OpenRA.Mods.Cnc/IonCannonPower.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc { self.World.AddFrameEndTask(w => { - Sound.Play(Info.LaunchSound, Game.CellSize * order.TargetLocation.ToFloat2()); + Sound.Play(Info.LaunchSound, order.TargetLocation.ToPPos()); w.Add(new IonCannon(self, w, order.TargetLocation)); }); } diff --git a/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs b/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs index ac79a44ef5..d35ddfd2ac 100755 --- a/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs +++ b/OpenRA.Mods.Cnc/Missions/CncShellmapScript.cs @@ -22,13 +22,13 @@ namespace OpenRA.Mods.RA class CncShellmapScript: IWorldLoaded, ITick { Dictionary Actors; - static int2 ViewportOrigin; + static CPos ViewportOrigin; public void WorldLoaded(World w) { var b = w.Map.Bounds; - ViewportOrigin = new int2(b.Left + b.Width/2, b.Top + b.Height/2); - Game.MoveViewport(ViewportOrigin); + ViewportOrigin = new CPos(b.Left + b.Width/2, b.Top + b.Height/2); + Game.MoveViewport(ViewportOrigin.ToFloat2()); Actors = w.WorldActor.Trait().Actors; @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA void SetViewport() { var t = (ticks + 45) % (360f * speed) * (Math.PI / 180) * 1f / speed; - var loc = ViewportOrigin + new float2(-15,4) * float2.FromAngle( (float)t ); + var loc = ViewportOrigin.ToFloat2() + (new float2(-15,4) * float2.FromAngle( (float)t )); Game.viewport.Center(loc); } @@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA })); } - void LoopTrack(Actor self, int2 left, int2 right) + void LoopTrack(Actor self, CPos left, CPos right) { var mobile = self.Trait(); self.QueueActivity(mobile.ScriptedMove(left)); diff --git a/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs b/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs index 6c17b8cc2f..5a6272214f 100644 --- a/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs +++ b/OpenRA.Mods.Cnc/Missions/Gdi01Script.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Cnc Players = w.Players.ToDictionary(p => p.InternalName); Actors = w.WorldActor.Trait().Actors; var b = w.Map.Bounds; - Game.MoveViewport(new int2(b.Left + b.Width/2, b.Top + b.Height/2)); + Game.MoveViewport(new CPos(b.Left + b.Width/2, b.Top + b.Height/2).ToFloat2()); Scripting.Media.PlayFMVFullscreen(w, "gdi1.vqa", () => Scripting.Media.PlayFMVFullscreen(w, "landing.vqa", () => @@ -130,7 +130,7 @@ namespace OpenRA.Mods.Cnc ReinforceFromSea(self.World, Actors["lstStart"].Location, Actors["lstEnd"].Location, - new int2(53,53), + new CPos(53, 53), new string[] {"e1","e1","e1"}, Players["GoodGuy"]); } @@ -140,7 +140,7 @@ namespace OpenRA.Mods.Cnc ReinforceFromSea(self.World, Actors["lstStart"].Location, Actors["lstEnd"].Location, - new int2(53,53), + new CPos(53, 53), new string[] {"e1","e1","e1"}, Players["GoodGuy"]); } @@ -150,7 +150,7 @@ namespace OpenRA.Mods.Cnc ReinforceFromSea(self.World, Actors["lstStart"].Location, Actors["lstEnd"].Location, - new int2(53,53), + new CPos(53, 53), new string[] {"jeep"}, Players["GoodGuy"]); } @@ -160,7 +160,7 @@ namespace OpenRA.Mods.Cnc ReinforceFromSea(self.World, Actors["lstStart"].Location, Actors["lstEnd"].Location, - new int2(53,53), + new CPos(53, 53), new string[] {"jeep"}, Players["GoodGuy"]); } @@ -177,7 +177,7 @@ namespace OpenRA.Mods.Cnc self.QueueActivity(new CallFunc(() => SetGunboatPath())); } - void ReinforceFromSea(World world, int2 startPos, int2 endPos, int2 unload, string[] items, Player player) + void ReinforceFromSea(World world, CPos startPos, CPos endPos, CPos unload, string[] items, Player player) { world.AddFrameEndTask(w => { diff --git a/OpenRA.Mods.Cnc/ProductionAirdrop.cs b/OpenRA.Mods.Cnc/ProductionAirdrop.cs index 07d2debd6d..476f48f7d7 100644 --- a/OpenRA.Mods.Cnc/ProductionAirdrop.cs +++ b/OpenRA.Mods.Cnc/ProductionAirdrop.cs @@ -36,8 +36,8 @@ namespace OpenRA.Mods.Cnc // Start a fixed distance away: the width of the map. // This makes the production timing independent of spawnpoint - var startPos = self.Location + new int2(owner.World.Map.Bounds.Width, 0); - var endPos = new int2(owner.World.Map.Bounds.Left - 5, self.Location.Y); + var startPos = self.Location + new CVec(owner.World.Map.Bounds.Width, 0); + var endPos = new CPos(owner.World.Map.Bounds.Left - 5, self.Location.Y); // Assume a single exit point for simplicity var exit = self.Info.Traits.WithInterface().First(); @@ -57,7 +57,7 @@ namespace OpenRA.Mods.Cnc new AltitudeInit( Rules.Info[actorType].Traits.Get().CruiseAltitude ), }); - a.QueueActivity(Fly.ToCell(self.Location + new int2(6,0))); + a.QueueActivity(Fly.ToCell(self.Location + new CVec(6, 0))); a.QueueActivity(new Land(Target.FromActor(self))); a.QueueActivity(new CallFunc(() => { diff --git a/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs b/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs index 27293e2871..10a0f5ec7c 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncWorldInteractionControllerWidget.cs @@ -62,7 +62,7 @@ namespace OpenRA.Mods.Cnc.Widgets public void UpdateMouseover() { TooltipType = WorldTooltipType.None; - var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2(); + var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos); if (!world.Map.IsInMap(cell)) return; diff --git a/OpenRA.Mods.RA/AI/HackyAI.cs b/OpenRA.Mods.RA/AI/HackyAI.cs index be02529d02..28c5346768 100644 --- a/OpenRA.Mods.RA/AI/HackyAI.cs +++ b/OpenRA.Mods.RA/AI/HackyAI.cs @@ -72,7 +72,7 @@ namespace OpenRA.Mods.RA.AI readonly HackyAIInfo Info; Cache aggro = new Cache( _ => new Enemy() ); - int2 baseCenter; + CPos baseCenter; XRandom random = new XRandom(); //we do not use the synced random number generator. BaseBuilder[] builders; @@ -116,7 +116,7 @@ namespace OpenRA.Mods.RA.AI ActorInfo ChooseRandomUnitToBuild(ProductionQueue queue) { var buildableThings = queue.BuildableItems(); - if (buildableThings.Count() == 0) return null; + if (!buildableThings.Any()) return null; return buildableThings.ElementAtOrDefault(random.Next(buildableThings.Count())); } @@ -154,13 +154,13 @@ namespace OpenRA.Mods.RA.AI return null; } - bool NoBuildingsUnder(IEnumerable cells) + bool NoBuildingsUnder(IEnumerable cells) { var bi = world.WorldActor.Trait(); return cells.All(c => bi.GetBuildingAt(c) == null); } - public int2? ChooseBuildLocation(string actorType) + public CPos? ChooseBuildLocation(string actorType) { var bi = Rules.Info[actorType].Traits.Get(); @@ -200,12 +200,12 @@ namespace OpenRA.Mods.RA.AI //A bunch of hardcoded lists to keep track of which units are doing what. List unitsHangingAroundTheBase = new List(); List attackForce = new List(); - int2? attackTarget; + CPos? attackTarget; //Units that the ai already knows about. Any unit not on this list needs to be given a role. List activeUnits = new List(); - int2? ChooseEnemyTarget() + CPos? ChooseEnemyTarget() { var liveEnemies = world.Players .Where(q => p != q && p.Stances[q] == Stance.Enemy) @@ -219,14 +219,14 @@ namespace OpenRA.Mods.RA.AI if (leastLikedEnemies == null) return null; - var enemy = leastLikedEnemies != null ? leastLikedEnemies.Random(random) : null; + var enemy = leastLikedEnemies.Random(random); /* pick something worth attacking owned by that player */ var targets = world.Actors .Where(a => a.Owner == enemy && a.HasTrait()); - Actor target=null; + Actor target = null; - if (targets.Count()>0) + if (targets.Any()) target = targets.Random(random); if (target == null) @@ -346,7 +346,7 @@ namespace OpenRA.Mods.RA.AI } } - bool IsRallyPointValid(int2 x) + bool IsRallyPointValid(CPos x) { // this is actually WRONG as soon as HackyAI is building units with a variety of // movement capabilities. (has always been wrong) @@ -363,16 +363,15 @@ namespace OpenRA.Mods.RA.AI BotDebug("Bot {0} needs to find rallypoints for {1} buildings.", p.PlayerName, buildings.Length); - foreach (var a in buildings) { - int2 newRallyPoint = ChooseRallyLocationNear(a.Actor.Location); + CPos newRallyPoint = ChooseRallyLocationNear(a.Actor.Location); world.IssueOrder(new Order("SetRallyPoint", a.Actor, false) { TargetLocation = newRallyPoint }); } } //won't work for shipyards... - int2 ChooseRallyLocationNear(int2 startPos) + CPos ChooseRallyLocationNear(CPos startPos) { var possibleRallyPoints = world.FindTilesInCircle(startPos, 8).Where(IsRallyPointValid).ToArray(); if (possibleRallyPoints.Length == 0) @@ -384,18 +383,18 @@ namespace OpenRA.Mods.RA.AI return possibleRallyPoints.Random(random); } - int2? ChooseDestinationNear(Actor a, int2 desiredMoveTarget) + CPos? ChooseDestinationNear(Actor a, CPos desiredMoveTarget) { var move = a.TraitOrDefault(); if (move == null) return null; - int2 xy; + CPos xy; int loopCount = 0; //avoid infinite loops. int range = 2; do { //loop until we find a valid move location - xy = new int2(desiredMoveTarget.X + random.Next(-range, range), desiredMoveTarget.Y + random.Next(-range, range)); + xy = new CPos(desiredMoveTarget.X + random.Next(-range, range), desiredMoveTarget.Y + random.Next(-range, range)); loopCount++; range = Math.Max(range, loopCount / 2); if (loopCount > 10) return null; @@ -406,7 +405,7 @@ namespace OpenRA.Mods.RA.AI //try very hard to find a valid move destination near the target. //(Don't accept a move onto the subject's current position. maybe this is already not allowed? ) - bool TryToMove(Actor a, int2 desiredMoveTarget, bool attackMove) + bool TryToMove(Actor a, CPos desiredMoveTarget, bool attackMove) { var xy = ChooseDestinationNear(a, desiredMoveTarget); if (xy == null) diff --git a/OpenRA.Mods.RA/Activities/FindResources.cs b/OpenRA.Mods.RA/Activities/FindResources.cs index 2a683f837e..e2108ccb01 100755 --- a/OpenRA.Mods.RA/Activities/FindResources.cs +++ b/OpenRA.Mods.RA/Activities/FindResources.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Activities public override IEnumerable GetTargets(Actor self) { - yield return Target.FromPos(self.Location); + yield return Target.FromCell(self.Location); } } diff --git a/OpenRA.Mods.RA/Activities/Follow.cs b/OpenRA.Mods.RA/Activities/Follow.cs index a534d036b2..f806851da1 100644 --- a/OpenRA.Mods.RA/Activities/Follow.cs +++ b/OpenRA.Mods.RA/Activities/Follow.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Activities if (IsCanceled) return NextActivity; if (!Target.IsValid) return NextActivity; - var inRange = ( Util.CellContaining( Target.CenterLocation ) - self.Location ).LengthSquared < Range * Range; + var inRange = ( Target.CenterLocation.ToCPos() - self.Location ).LengthSquared < Range * Range; if( inRange ) return this; if (--nextPathTime > 0) return this; diff --git a/OpenRA.Mods.RA/Activities/LayMines.cs b/OpenRA.Mods.RA/Activities/LayMines.cs index 9bb861737b..7e6f9f8d07 100644 --- a/OpenRA.Mods.RA/Activities/LayMines.cs +++ b/OpenRA.Mods.RA/Activities/LayMines.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Activities return Util.SequenceActivities( new MoveAdjacentTo(Target.FromActor(rearmTarget)), - mobile.MoveTo(Traits.Util.CellContaining(rearmTarget.CenterLocation), rearmTarget), + mobile.MoveTo(rearmTarget.CenterLocation.ToCPos(), rearmTarget), new Rearm(self), new Repair(rearmTarget), this ); @@ -65,11 +65,10 @@ namespace OpenRA.Mods.RA.Activities return new Wait(20); // nothing to do here } - bool ShouldLayMine(Actor self, int2 p) + bool ShouldLayMine(Actor self, CPos p) { // if there is no unit (other than me) here, we want to place a mine here - return !self.World.ActorMap - .GetUnitsAt(p).Any(a => a != self); + return !self.World.ActorMap.GetUnitsAt(p).Any(a => a != self); } void LayMine(Actor self) diff --git a/OpenRA.Mods.RA/Activities/Leap.cs b/OpenRA.Mods.RA/Activities/Leap.cs index 6ede865d88..d8f4537386 100644 --- a/OpenRA.Mods.RA/Activities/Leap.cs +++ b/OpenRA.Mods.RA/Activities/Leap.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Activities class Leap : Activity { Target target; - int2 initialLocation; + PPos initialLocation; int moveFraction; const int delay = 6; @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Activities public Leap(Actor self, Target target) { this.target = target; - initialLocation = self.Trait().PxPosition; + initialLocation = (PPos) self.Trait().PxPosition; self.Trait().Attacking(self, target); Sound.Play("dogg5p.aud", self.CenterLocation); @@ -41,12 +41,12 @@ namespace OpenRA.Mods.RA.Activities var mobile = self.Trait(); ++moveFraction; - mobile.PxPosition = int2.Lerp(initialLocation, target.PxPosition, moveFraction, delay); + mobile.PxPosition = PPos.Lerp(initialLocation, target.PxPosition, moveFraction, delay); if (moveFraction >= delay) { self.TraitsImplementing().FirstOrDefault() - .SetPosition(self, Util.CellContaining(target.CenterLocation)); + .SetPosition(self, target.CenterLocation.ToCPos()); if (target.IsActor) target.Actor.Kill(self); diff --git a/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs b/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs index 93f1c0e553..5b2ce313a9 100755 --- a/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs +++ b/OpenRA.Mods.RA/Activities/MoveAdjacentTo.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA.Activities ps1.heuristic = PathSearch.DefaultEstimator( mobile.toCell ); - var ps2 = PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, Util.CellContaining(target.CenterLocation), true ); + var ps2 = PathSearch.FromPoint( self.World, mobile.Info, self.Owner, mobile.toCell, target.CenterLocation.ToCPos(), true ); var ret = self.World.WorldActor.Trait().FindBidiPath( ps1, ps2 ); return Util.SequenceActivities( mobile.MoveTo( () => ret ), this ); diff --git a/OpenRA.Mods.RA/Activities/Teleport.cs b/OpenRA.Mods.RA/Activities/Teleport.cs index b3275532a3..3155c16378 100755 --- a/OpenRA.Mods.RA/Activities/Teleport.cs +++ b/OpenRA.Mods.RA/Activities/Teleport.cs @@ -15,9 +15,9 @@ namespace OpenRA.Mods.RA.Activities { public class Teleport : Activity { - int2 destination; + CPos destination; - public Teleport(int2 destination) + public Teleport(CPos destination) { this.destination = destination; } diff --git a/OpenRA.Mods.RA/Activities/Transform.cs b/OpenRA.Mods.RA/Activities/Transform.cs index 09a90e3614..4641f91d40 100644 --- a/OpenRA.Mods.RA/Activities/Transform.cs +++ b/OpenRA.Mods.RA/Activities/Transform.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA.Activities class Transform : Activity { public readonly string ToActor = null; - public int2 Offset = new int2(0,0); + public CVec Offset = new CVec(0, 0); public int Facing = 96; public string[] Sounds = {}; public int ForceHealthPercentage = 0; diff --git a/OpenRA.Mods.RA/Activities/UnloadCargo.cs b/OpenRA.Mods.RA/Activities/UnloadCargo.cs index 9c57f66649..ae2e7bcd8a 100644 --- a/OpenRA.Mods.RA/Activities/UnloadCargo.cs +++ b/OpenRA.Mods.RA/Activities/UnloadCargo.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Activities { public class UnloadCargo : Activity { - int2? ChooseExitTile(Actor self, Actor cargo) + CPos? ChooseExitTile(Actor self, Actor cargo) { // is anyone still hogging this tile? if (self.World.ActorMap.GetUnitsAt(self.Location).Count() > 1) @@ -29,8 +29,8 @@ namespace OpenRA.Mods.RA.Activities for (var i = -1; i < 2; i++) for (var j = -1; j < 2; j++) if ((i != 0 || j != 0) && - mobile.CanEnterCell(self.Location + new int2(i, j))) - return self.Location + new int2(i, j); + mobile.CanEnterCell(self.Location + new CVec(i, j))) + return self.Location + new CVec(i, j); return null; } @@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Activities if (actor.Destroyed) return; var mobile = actor.Trait(); - mobile.Facing = Util.GetFacing( exitPx - currentPx, mobile.Facing ); + mobile.Facing = Util.GetFacing( (exitPx - currentPx).ToInt2(), mobile.Facing ); mobile.SetPosition(actor, exitTile.Value); mobile.AdjustPxPosition(actor, currentPx); var speed = mobile.MovementSpeedForCell(actor, exitTile.Value); diff --git a/OpenRA.Mods.RA/Air/Aircraft.cs b/OpenRA.Mods.RA/Air/Aircraft.cs index 49e76f1693..0294967ea7 100755 --- a/OpenRA.Mods.RA/Air/Aircraft.cs +++ b/OpenRA.Mods.RA/Air/Aircraft.cs @@ -108,8 +108,8 @@ namespace OpenRA.Mods.RA.Air public int Altitude { get; set; } [Sync] public int2 SubPxPosition; - public int2 PxPosition { get { return new int2( SubPxPosition.X / 1024, SubPxPosition.Y / 1024 ); } } - public int2 TopLeft { get { return Util.CellContaining( PxPosition ); } } + public PPos PxPosition { get { return new PPos( SubPxPosition.X / 1024, SubPxPosition.Y / 1024 ); } } + public CPos TopLeft { get { return PxPosition.ToCPos(); } } readonly AircraftInfo Info; @@ -117,7 +117,7 @@ namespace OpenRA.Mods.RA.Air { this.self = init.self; if( init.Contains() ) - this.SubPxPosition = 1024 * Util.CenterOfCell( init.Get() ); + this.SubPxPosition = 1024 * Util.CenterOfCell( init.Get() ).ToInt2(); this.Facing = init.Contains() ? init.Get() : info.InitialFacing; this.Altitude = init.Contains() ? init.Get() : 0; @@ -151,17 +151,17 @@ namespace OpenRA.Mods.RA.Air public int InitialFacing { get { return Info.InitialFacing; } } - public void SetPosition(Actor self, int2 cell) + public void SetPosition(Actor self, CPos cell) { SetPxPosition( self, Util.CenterOfCell( cell ) ); } - public void SetPxPosition( Actor self, int2 px ) + public void SetPxPosition( Actor self, PPos px ) { - SubPxPosition = px * 1024; + SubPxPosition = px.ToInt2() * 1024; } - public void AdjustPxPosition(Actor self, int2 px) { SetPxPosition(self, px); } + public void AdjustPxPosition(Actor self, PPos px) { SetPxPosition(self, px); } public bool AircraftCanEnter(Actor a) { @@ -170,7 +170,7 @@ namespace OpenRA.Mods.RA.Air || Info.RepairBuildings.Contains( a.Info.Name ); } - public bool CanEnterCell(int2 location) { return true; } + public bool CanEnterCell(CPos location) { return true; } public int MovementSpeed { @@ -183,8 +183,8 @@ namespace OpenRA.Mods.RA.Air } } - Pair[] noCells = new Pair[] { }; - public IEnumerable> OccupiedCells() { return noCells; } + Pair[] noCells = new Pair[] { }; + public IEnumerable> OccupiedCells() { return noCells; } public void TickMove( int speed, int facing ) { @@ -192,7 +192,7 @@ namespace OpenRA.Mods.RA.Air SubPxPosition += rawspeed * -Util.SubPxVector[facing]; } - public bool CanLand(int2 cell) + public bool CanLand(CPos cell) { if (!self.World.Map.IsInMap(cell)) return false; @@ -230,7 +230,7 @@ namespace OpenRA.Mods.RA.Air return new Order(order.OrderID, self, queued) { TargetActor = target.Actor }; if (order.OrderID == "Move") - return new Order(order.OrderID, self, queued) { TargetLocation = Util.CellContaining(target.CenterLocation) }; + return new Order(order.OrderID, self, queued) { TargetLocation = target.CenterLocation.ToCPos() }; return null; } @@ -273,7 +273,7 @@ namespace OpenRA.Mods.RA.Air return false; } - public bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) + public bool CanTargetLocation(Actor self, CPos location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) { IsQueued = forceQueued; cursor = self.World.Map.IsInMap(location) ? "move" : "move-blocked"; diff --git a/OpenRA.Mods.RA/Air/EjectOnDeath.cs b/OpenRA.Mods.RA/Air/EjectOnDeath.cs index fa2676fdd8..20463555c9 100644 --- a/OpenRA.Mods.RA/Air/EjectOnDeath.cs +++ b/OpenRA.Mods.RA/Air/EjectOnDeath.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA { self.World.AddFrameEndTask(w => w.Add( new Parachute(pilot.Owner, - Util.CenterOfCell(Util.CellContaining(self.CenterLocation)), + Util.CenterOfCell(self.CenterLocation.ToCPos()), aircraft.Altitude, pilot))); Sound.Play(info.ChuteSound, self.CenterLocation); @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA pilot.Destroy(); } - bool IsSuitableCell(Actor actorToDrop, int2 p) + bool IsSuitableCell(Actor actorToDrop, CPos p) { return actorToDrop.Trait().CanEnterCell(p); } diff --git a/OpenRA.Mods.RA/Air/Fly.cs b/OpenRA.Mods.RA/Air/Fly.cs index 470e473fa1..edd808956d 100755 --- a/OpenRA.Mods.RA/Air/Fly.cs +++ b/OpenRA.Mods.RA/Air/Fly.cs @@ -16,12 +16,12 @@ namespace OpenRA.Mods.RA.Air { public class Fly : Activity { - public readonly int2 Pos; + public readonly PPos Pos; - Fly( int2 px ) { Pos = px; } + Fly(PPos px) { Pos = px; } - public static Fly ToPx( int2 px ) { return new Fly( px ); } - public static Fly ToCell( int2 pos ) { return new Fly( Util.CenterOfCell( pos ) ); } + public static Fly ToPx( PPos px ) { return new Fly( px ); } + public static Fly ToCell(CPos pos) { return new Fly(Util.CenterOfCell(pos)); } public override Activity Tick(Actor self) { @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Air var aircraft = self.Trait(); - var desiredFacing = Util.GetFacing(d, aircraft.Facing); + var desiredFacing = Util.GetFacing(d.ToInt2(), aircraft.Facing); if (aircraft.Altitude == cruiseAltitude) aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT); diff --git a/OpenRA.Mods.RA/Air/HeliAttack.cs b/OpenRA.Mods.RA/Air/HeliAttack.cs index bfe3f19a27..2a6719c7fc 100755 --- a/OpenRA.Mods.RA/Air/HeliAttack.cs +++ b/OpenRA.Mods.RA/Air/HeliAttack.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Air var desiredFacing = Util.GetFacing(dist, aircraft.Facing); aircraft.Facing = Util.TickFacing(aircraft.Facing, desiredFacing, aircraft.ROT); - if( !float2.WithinEpsilon( float2.Zero, dist, range * Game.CellSize ) ) + if( !float2.WithinEpsilon( float2.Zero, dist.ToFloat2(), range * Game.CellSize ) ) aircraft.TickMove( 1024 * aircraft.MovementSpeed, desiredFacing ); attack.DoAttack( self, target ); diff --git a/OpenRA.Mods.RA/Air/HeliFly.cs b/OpenRA.Mods.RA/Air/HeliFly.cs index c96a7b0c24..7cb79a952d 100755 --- a/OpenRA.Mods.RA/Air/HeliFly.cs +++ b/OpenRA.Mods.RA/Air/HeliFly.cs @@ -16,8 +16,8 @@ namespace OpenRA.Mods.RA.Air { class HeliFly : Activity { - public readonly int2 Dest; - public HeliFly(int2 dest) + public readonly PPos Dest; + public HeliFly(PPos dest) { Dest = dest; } @@ -36,9 +36,9 @@ namespace OpenRA.Mods.RA.Air } var dist = Dest - aircraft.PxPosition; - if (float2.WithinEpsilon(float2.Zero, dist, 2)) + if (float2.WithinEpsilon(float2.Zero, dist.ToFloat2(), 2)) { - aircraft.SubPxPosition = Dest * 1024; + aircraft.SubPxPosition = (Dest.ToInt2() * 1024); return NextActivity; } diff --git a/OpenRA.Mods.RA/Air/HeliReturn.cs b/OpenRA.Mods.RA/Air/HeliReturn.cs index 3ece3fd027..597b5d5e22 100755 --- a/OpenRA.Mods.RA/Air/HeliReturn.cs +++ b/OpenRA.Mods.RA/Air/HeliReturn.cs @@ -37,11 +37,11 @@ namespace OpenRA.Mods.RA.Air var nearestHpad = self.World.ActorsWithTrait() .Where(a => a.Actor.Owner == self.Owner && rearmBuildings.Contains(a.Actor.Info.Name)) .Select(a => a.Actor) - .ClosestTo(self.CenterLocation); - - if (nearestHpad == null) - return Util.SequenceActivities(new Turn(initialFacing), new HeliLand(true), NextActivity); - else + .ClosestTo(self.CenterLocation); + + if (nearestHpad == null) + return Util.SequenceActivities(new Turn(initialFacing), new HeliLand(true), NextActivity); + else return Util.SequenceActivities(new HeliFly(Util.CenterOfCell(nearestHpad.Location))); } @@ -51,7 +51,7 @@ namespace OpenRA.Mods.RA.Air heli.reservation = res.Reserve(dest, self, heli); var exit = dest.Info.Traits.WithInterface().FirstOrDefault(); - var offset = exit != null ? exit.SpawnOffset : int2.Zero; + var offset = exit != null ? exit.SpawnOffsetVector : PVecInt.Zero; return Util.SequenceActivities( new HeliFly(dest.Trait().PxPosition + offset), diff --git a/OpenRA.Mods.RA/Air/Helicopter.cs b/OpenRA.Mods.RA/Air/Helicopter.cs index d21b01de0e..18cf030303 100755 --- a/OpenRA.Mods.RA/Air/Helicopter.cs +++ b/OpenRA.Mods.RA/Air/Helicopter.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Air reservation = res.Reserve(order.TargetActor, self, this); var exit = order.TargetActor.Info.Traits.WithInterface().FirstOrDefault(); - var offset = exit != null ? exit.SpawnOffset : int2.Zero; + var offset = exit != null ? exit.SpawnOffsetVector : PVecInt.Zero; self.SetTargetLine(Target.FromActor(order.TargetActor), Color.Green); @@ -118,9 +118,9 @@ namespace OpenRA.Mods.RA.Air .Select(h => GetRepulseForce(self, h)) .Aggregate(int2.Zero, (a, b) => a + b); - int RepulsionFacing = Util.GetFacing( f, -1 ); - if( RepulsionFacing != -1 ) - TickMove( 1024 * MovementSpeed, RepulsionFacing ); + int repulsionFacing = Util.GetFacing( f, -1 ); + if( repulsionFacing != -1 ) + TickMove( 1024 * MovementSpeed, repulsionFacing ); } // Returns an int2 in subPx units @@ -137,7 +137,7 @@ namespace OpenRA.Mods.RA.Air if (d.LengthSquared < 1) return Util.SubPxVector[self.World.SharedRandom.Next(255)]; - return (5120 / d.LengthSquared) * d; + return (5120 / d.LengthSquared) * d.ToInt2(); } } } diff --git a/OpenRA.Mods.RA/Air/Plane.cs b/OpenRA.Mods.RA/Air/Plane.cs index 9c239618d4..d1c0f6786c 100755 --- a/OpenRA.Mods.RA/Air/Plane.cs +++ b/OpenRA.Mods.RA/Air/Plane.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.RA.Air public class Plane : Aircraft, IResolveOrder, ITick, ISync { - [Sync] public int2 RTBPathHash; + [Sync] public PVecInt RTBPathHash; public Plane( ActorInitializer init, PlaneInfo info ) : base( init, info ) { } diff --git a/OpenRA.Mods.RA/Air/ReturnToBase.cs b/OpenRA.Mods.RA/Air/ReturnToBase.cs index 726828063c..ed8c01b83a 100755 --- a/OpenRA.Mods.RA/Air/ReturnToBase.cs +++ b/OpenRA.Mods.RA/Air/ReturnToBase.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Air bool isCalculated; Actor dest; - int2 w1, w2, w3; /* tangent points to turn circles */ + PPos w1, w2, w3; /* tangent points to turn circles */ public static Actor ChooseAirfield(Actor self) { @@ -52,19 +52,18 @@ namespace OpenRA.Mods.RA.Air var speed = .2f * aircraft.MovementSpeed; - var approachStart = landPos - new float2(aircraft.Altitude * speed, 0); + var approachStart = landPos.ToFloat2() - new float2(aircraft.Altitude * speed, 0); var turnRadius = (128f / self.Info.Traits.Get().ROT) * speed / (float)Math.PI; /* work out the center points */ var fwd = -float2.FromAngle(aircraft.Facing / 128f * (float)Math.PI); var side = new float2(-fwd.Y, fwd.X); /* rotate */ var sideTowardBase = new[] { side, -side } - .OrderBy(a => float2.Dot(a, self.CenterLocation - approachStart)) + .OrderBy(a => float2.Dot(a, self.CenterLocation.ToFloat2() - approachStart)) .First(); - var c1 = self.CenterLocation + turnRadius * sideTowardBase; - var c2 = approachStart + new float2(0, - turnRadius * Math.Sign(self.CenterLocation.Y - approachStart.Y)); // above or below start point + var c1 = self.CenterLocation.ToFloat2() + turnRadius * sideTowardBase; + var c2 = approachStart + new float2(0, turnRadius * Math.Sign(self.CenterLocation.Y - approachStart.Y)); // above or below start point /* work out tangent points */ var d = c2 - c1; @@ -75,10 +74,10 @@ namespace OpenRA.Mods.RA.Air if (f.X > 0) f = -f; - w1 = (c1 + f).ToInt2(); - w2 = (c2 + f).ToInt2(); - w3 = (approachStart).ToInt2(); - plane.RTBPathHash = w1 + w2 + w3; + w1 = (PPos)(c1 + f).ToInt2(); + w2 = (PPos)(c2 + f).ToInt2(); + w3 = (PPos)(approachStart).ToInt2(); + plane.RTBPathHash = (PVecInt)w1 + (PVecInt)w2 + (PVecInt)w3; isCalculated = true; } diff --git a/OpenRA.Mods.RA/AppearsOnRadar.cs b/OpenRA.Mods.RA/AppearsOnRadar.cs index 579d71c5f6..714a8846f6 100755 --- a/OpenRA.Mods.RA/AppearsOnRadar.cs +++ b/OpenRA.Mods.RA/AppearsOnRadar.cs @@ -28,10 +28,10 @@ namespace OpenRA.Mods.RA public AppearsOnRadar(AppearsOnRadarInfo info) { this.info = info; } - public IEnumerable RadarSignatureCells(Actor self) + public IEnumerable RadarSignatureCells(Actor self) { if (info.UseLocation) - return new int2[] { self.Location }; + return new CPos[] { self.Location }; else return self.OccupiesSpace.OccupiedCells().Select(c => c.First); } diff --git a/OpenRA.Mods.RA/Attack/AttackBase.cs b/OpenRA.Mods.RA/Attack/AttackBase.cs index c146b296f2..08c58ff9a9 100644 --- a/OpenRA.Mods.RA/Attack/AttackBase.cs +++ b/OpenRA.Mods.RA/Attack/AttackBase.cs @@ -149,7 +149,7 @@ namespace OpenRA.Mods.RA if( target.IsActor ) return new Order("Attack", self, queued) { TargetActor = target.Actor }; else - return new Order( "Attack", self, queued ) { TargetLocation = Util.CellContaining( target.CenterLocation ) }; + return new Order( "Attack", self, queued ) { TargetLocation = target.CenterLocation.ToCPos() }; } return null; } @@ -217,7 +217,7 @@ namespace OpenRA.Mods.RA return self.Owner.Stances[ target.Owner ] == targetableRelationship; } - public bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) + public bool CanTargetLocation(Actor self, CPos location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) { if (!self.World.Map.IsInMap(location)) return false; diff --git a/OpenRA.Mods.RA/Attack/AttackWander.cs b/OpenRA.Mods.RA/Attack/AttackWander.cs index 7171ab09dd..43a631d9ae 100644 --- a/OpenRA.Mods.RA/Attack/AttackWander.cs +++ b/OpenRA.Mods.RA/Attack/AttackWander.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA public void TickIdle(Actor self) { - var target = Util.SubPxVector[self.World.SharedRandom.Next(255)]* Info.MoveRadius / 1024 + self.Location; + var target = (CVec)( Util.SubPxVector[self.World.SharedRandom.Next(255)] * Info.MoveRadius / 1024) + self.Location; self.Trait().ResolveOrder(self, new Order("AttackMove", self, false) { TargetLocation = target }); } } diff --git a/OpenRA.Mods.RA/AttackMove.cs b/OpenRA.Mods.RA/AttackMove.cs index 895aaa1a1e..022485625a 100644 --- a/OpenRA.Mods.RA/AttackMove.cs +++ b/OpenRA.Mods.RA/AttackMove.cs @@ -23,8 +23,8 @@ namespace OpenRA.Mods.RA class AttackMove : IResolveOrder, IOrderVoice, INotifyIdle, ISync { - [Sync] public int2 _targetLocation { get { return TargetLocation.HasValue ? TargetLocation.Value : int2.Zero; } } - public int2? TargetLocation = null; + [Sync] public CPos _targetLocation { get { return TargetLocation.HasValue ? TargetLocation.Value : CPos.Zero; } } + public CPos? TargetLocation = null; readonly Mobile mobile; readonly AttackMoveInfo Info; diff --git a/OpenRA.Mods.RA/Bridge.cs b/OpenRA.Mods.RA/Bridge.cs index 2261b2f050..67d84a569b 100644 --- a/OpenRA.Mods.RA/Bridge.cs +++ b/OpenRA.Mods.RA/Bridge.cs @@ -67,7 +67,7 @@ namespace OpenRA.Mods.RA static string cachedTileset; static Cache, Sprite> sprites; - Dictionary> TileSprites = new Dictionary>(); + Dictionary> TileSprites = new Dictionary>(); Dictionary Templates = new Dictionary(); ushort currentTemplate; @@ -86,7 +86,7 @@ namespace OpenRA.Mods.RA this.Type = self.Info.Name; } - public void Create(ushort template, Dictionary subtiles) + public void Create(ushort template, Dictionary subtiles) { currentTemplate = template; @@ -103,7 +103,7 @@ namespace OpenRA.Mods.RA foreach (var t in Info.Templates) { Templates.Add(t.First,self.World.TileSet.Templates[t.First]); - TileSprites.Add(t.First,subtiles.ToDictionary( + TileSprites.Add(t.First, subtiles.ToDictionary( a => a.Key, a => sprites[new TileReference(t.First, (byte)a.Value)])); } @@ -113,10 +113,10 @@ namespace OpenRA.Mods.RA self.World.Map.CustomTerrain[c.X, c.Y] = GetTerrainType(c); } - public string GetTerrainType(int2 cell) + public string GetTerrainType(CPos cell) { var dx = cell - self.Location; - var index = dx.X + Templates[currentTemplate].Size.X*dx.Y; + var index = dx.X + Templates[currentTemplate].Size.X * dx.Y; return self.World.TileSet.GetTerrainType(new TileReference(currentTemplate,(byte)index)); } @@ -132,13 +132,13 @@ namespace OpenRA.Mods.RA public Bridge GetNeighbor(int[] offset, BridgeLayer bridges) { if (offset == null) return null; - return bridges.GetBridge(self.Location + new int2(offset[0], offset[1])); + return bridges.GetBridge(self.Location + new CVec(offset[0], offset[1])); } public IEnumerable RenderAsTerrain(Actor self) { foreach (var t in TileSprites[currentTemplate]) - yield return new Renderable(t.Value, Game.CellSize * t.Key, "terrain", Game.CellSize * t.Key.Y); + yield return new Renderable(t.Value, t.Key.ToPPos().ToFloat2(), "terrain", Game.CellSize * t.Key.Y); } bool IsIntact(Bridge b) diff --git a/OpenRA.Mods.RA/BridgeLayer.cs b/OpenRA.Mods.RA/BridgeLayer.cs index c3f8c30367..8e0df7e4dc 100644 --- a/OpenRA.Mods.RA/BridgeLayer.cs +++ b/OpenRA.Mods.RA/BridgeLayer.cs @@ -75,12 +75,12 @@ namespace OpenRA.Mods.RA // Create a new actor for this bridge and keep track of which subtiles this bridge includes var bridge = w.CreateActor(BridgeTypes[tile].First, new TypeDictionary { - new LocationInit( new int2(ni, nj) ), + new LocationInit( new CPos(ni, nj) ), new OwnerInit( w.WorldActor.Owner ), new HealthInit( BridgeTypes[tile].Second ), }).Trait(); - Dictionary subTiles = new Dictionary(); + var subTiles = new Dictionary(); // For each subtile in the template for (byte ind = 0; ind < template.Size.X*template.Size.Y; ind++) @@ -97,16 +97,16 @@ namespace OpenRA.Mods.RA if (!w.Map.IsInMap(x, y) || w.Map.MapTiles.Value[x, y].index != ind) continue; - subTiles.Add(new int2(x,y),ind); + subTiles.Add(new CPos(x, y), ind); Bridges[x,y] = bridge; } bridge.Create(tile, subTiles); } // Used to check for neighbouring bridges - public Bridge GetBridge(int2 cell) + public Bridge GetBridge(CPos cell) { - if (!world.Map.IsInMap(cell.X, cell.Y)) + if (!world.Map.IsInMap(cell)) return null; return Bridges[ cell.X, cell.Y ]; diff --git a/OpenRA.Mods.RA/Buildings/BibLayer.cs b/OpenRA.Mods.RA/Buildings/BibLayer.cs index 6d3f015738..e89f6db34d 100755 --- a/OpenRA.Mods.RA/Buildings/BibLayer.cs +++ b/OpenRA.Mods.RA/Buildings/BibLayer.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Buildings { World world; BibLayerInfo info; - Dictionary> tiles; + Dictionary> tiles; Sprite[][] bibSprites; public BibLayer(Actor self, BibLayerInfo info) @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Buildings public void WorldLoaded(World w) { world = w; - tiles = new Dictionary>(); + tiles = new Dictionary>(); } public void DoBib(Actor b, bool isAdd) @@ -63,9 +63,9 @@ namespace OpenRA.Mods.RA.Buildings for (int i = 0; i < 2 * size; i++) { - var p = b.Location + new int2(i % size, i / size + bibOffset); + var p = b.Location + new CVec(i % size, i / size + bibOffset); if (isAdd) - tiles[p] = new TileReference((byte)((isAdd) ? bib + 1 : 0), (byte)i); + tiles[p] = new TileReference((byte)(bib + 1), (byte)i); else tiles.Remove(p); } @@ -81,8 +81,7 @@ namespace OpenRA.Mods.RA.Buildings if (!world.LocalShroud.IsExplored(kv.Key)) continue; - bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt( wr, - Game.CellSize * kv.Key, "terrain"); + bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt(wr, kv.Key.ToPPos().ToFloat2(), "terrain"); } } } diff --git a/OpenRA.Mods.RA/Buildings/Building.cs b/OpenRA.Mods.RA/Buildings/Building.cs index 2f7c6c5ddb..31f1fa5215 100755 --- a/OpenRA.Mods.RA/Buildings/Building.cs +++ b/OpenRA.Mods.RA/Buildings/Building.cs @@ -32,28 +32,28 @@ namespace OpenRA.Mods.RA.Buildings public object Create(ActorInitializer init) { return new Building(init, this); } - public bool IsCloseEnoughToBase(World world, Player p, string buildingName, int2 topLeft) + public bool IsCloseEnoughToBase(World world, Player p, string buildingName, CPos topLeft) { if (p.PlayerActor.Trait().BuildAnywhere) return true; - var buildingMaxBounds = Dimensions; + var buildingMaxBounds = (CVec)Dimensions; if( Rules.Info[ buildingName ].Traits.Contains() ) - buildingMaxBounds.Y += 1; + buildingMaxBounds += new CVec(0, 1); - var scanStart = world.ClampToWorld( topLeft - new int2( Adjacent, Adjacent ) ); - var scanEnd = world.ClampToWorld( topLeft + buildingMaxBounds + new int2( Adjacent, Adjacent ) ); + var scanStart = world.ClampToWorld( topLeft - new CVec( Adjacent, Adjacent ) ); + var scanEnd = world.ClampToWorld(topLeft + buildingMaxBounds + new CVec(Adjacent, Adjacent)); - var nearnessCandidates = new List(); + var nearnessCandidates = new List(); var bi = world.WorldActor.Trait(); for( int y = scanStart.Y ; y < scanEnd.Y ; y++ ) for( int x = scanStart.X ; x < scanEnd.X ; x++ ) { - var at = bi.GetBuildingAt( new int2( x, y ) ); + var at = bi.GetBuildingAt( new CPos( x, y ) ); if( at != null && at.Owner.Stances[ p ] == Stance.Ally && at.HasTrait() ) - nearnessCandidates.Add( new int2( x, y ) ); + nearnessCandidates.Add( new CPos( x, y ) ); } var buildingTiles = FootprintUtils.Tiles( buildingName, this, topLeft ).ToList(); @@ -68,27 +68,26 @@ namespace OpenRA.Mods.RA.Buildings { readonly Actor self; public readonly BuildingInfo Info; - [Sync] - readonly int2 topLeft; + [Sync] readonly CPos topLeft; PowerManager PlayerPower; - int2 pxPosition; + PPos pxPosition; - public int2 TopLeft { get { return topLeft; } } - public int2 PxPosition { get { return pxPosition; } } + public CPos TopLeft { get { return topLeft; } } + public PPos PxPosition { get { return pxPosition; } } public IEnumerable ProvidesPrerequisites { get { yield return self.Info.Name; } } public Building(ActorInitializer init, BuildingInfo info) { this.self = init.self; - this.topLeft = init.Get(); + this.topLeft = init.Get(); this.Info = info; this.PlayerPower = init.self.Owner.PlayerActor.Trait(); occupiedCells = FootprintUtils.UnpathableTiles( self.Info.Name, Info, TopLeft ) .Select(c => Pair.New(c, SubCell.FullCell)).ToArray(); - pxPosition = ( 2 * topLeft + Info.Dimensions ) * Game.CellSize / 2; + pxPosition = (PPos) (( 2 * topLeft.ToInt2() + Info.Dimensions ) * Game.CellSize / 2); } public int GetPowerUsage() @@ -107,8 +106,8 @@ namespace OpenRA.Mods.RA.Buildings PlayerPower.UpdateActor(self, GetPowerUsage()); } - Pair[] occupiedCells; - public IEnumerable> OccupiedCells() { return occupiedCells; } + Pair[] occupiedCells; + public IEnumerable> OccupiedCells() { return occupiedCells; } public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) { diff --git a/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs b/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs index 8b011c3ed2..be31f43dd2 100755 --- a/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs +++ b/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Buildings influence[ u.X, u.Y ] = isAdd ? a : null; } - public Actor GetBuildingAt(int2 cell) + public Actor GetBuildingAt(CPos cell) { if (!map.IsInMap(cell)) return null; return influence[cell.X, cell.Y]; diff --git a/OpenRA.Mods.RA/Buildings/FootprintUtils.cs b/OpenRA.Mods.RA/Buildings/FootprintUtils.cs index 7f93ef2029..6808cbf94d 100755 --- a/OpenRA.Mods.RA/Buildings/FootprintUtils.cs +++ b/OpenRA.Mods.RA/Buildings/FootprintUtils.cs @@ -16,34 +16,34 @@ namespace OpenRA.Mods.RA.Buildings { public static class FootprintUtils { - public static IEnumerable Tiles( string name, BuildingInfo buildingInfo, int2 topLeft ) + public static IEnumerable Tiles(string name, BuildingInfo buildingInfo, CPos topLeft) { - var dim = buildingInfo.Dimensions; + var dim = (CVec)buildingInfo.Dimensions; var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x)); if (Rules.Info[ name ].Traits.Contains()) { - dim.Y += 1; + dim += new CVec(0, 1); footprint = footprint.Concat(new char[dim.X]); } return TilesWhere( name, dim, footprint.ToArray(), a => a != '_' ).Select( t => t + topLeft ); } - public static IEnumerable Tiles(Actor a) + public static IEnumerable Tiles(Actor a) { return Tiles( a.Info.Name, a.Info.Traits.Get(), a.Location ); } - public static IEnumerable UnpathableTiles( string name, BuildingInfo buildingInfo, int2 position ) + public static IEnumerable UnpathableTiles(string name, BuildingInfo buildingInfo, CPos position) { var footprint = buildingInfo.Footprint.Where( x => !char.IsWhiteSpace( x ) ).ToArray(); - foreach( var tile in TilesWhere( name, buildingInfo.Dimensions, footprint, a => a == 'x' ) ) + foreach( var tile in TilesWhere( name, (CVec)buildingInfo.Dimensions, footprint, a => a == 'x' ) ) yield return tile + position; } - static IEnumerable TilesWhere( string name, int2 dim, char[] footprint, Func cond ) + static IEnumerable TilesWhere(string name, CVec dim, char[] footprint, Func cond) { if( footprint.Length != dim.X * dim.Y ) throw new InvalidOperationException( "Invalid footprint for " + name ); @@ -52,13 +52,13 @@ namespace OpenRA.Mods.RA.Buildings for( int y = 0 ; y < dim.Y ; y++ ) for( int x = 0 ; x < dim.X ; x++ ) if( cond( footprint[ index++ ] ) ) - yield return new int2( x, y ); + yield return new CVec(x, y); } - public static int2 AdjustForBuildingSize( BuildingInfo buildingInfo ) + public static CVec AdjustForBuildingSize( BuildingInfo buildingInfo ) { var dim = buildingInfo.Dimensions; - return new int2( dim.X / 2, dim.Y > 1 ? ( dim.Y + 1 ) / 2 : 0 ); + return new CVec(dim.X / 2, dim.Y > 1 ? (dim.Y + 1) / 2 : 0); } } } diff --git a/OpenRA.Mods.RA/Buildings/ShakeOnDeath.cs b/OpenRA.Mods.RA/Buildings/ShakeOnDeath.cs index 7d036d0949..8b6375a8ad 100644 --- a/OpenRA.Mods.RA/Buildings/ShakeOnDeath.cs +++ b/OpenRA.Mods.RA/Buildings/ShakeOnDeath.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Buildings public void Killed(Actor self, AttackInfo e) { - self.World.WorldActor.Trait().AddEffect(Info.Intensity, self.CenterLocation, 1); + self.World.WorldActor.Trait().AddEffect(Info.Intensity, self.CenterLocation.ToFloat2(), 1); } } } diff --git a/OpenRA.Mods.RA/Buildings/Util.cs b/OpenRA.Mods.RA/Buildings/Util.cs index 14492b7e9c..eda571bde6 100755 --- a/OpenRA.Mods.RA/Buildings/Util.cs +++ b/OpenRA.Mods.RA/Buildings/Util.cs @@ -16,12 +16,12 @@ namespace OpenRA.Mods.RA.Buildings { public static class BuildingUtils { - public static bool IsCellBuildable(this World world, int2 a, BuildingInfo bi) + public static bool IsCellBuildable(this World world, CPos a, BuildingInfo bi) { return world.IsCellBuildable(a, bi, null); } - public static bool IsCellBuildable(this World world, int2 a, BuildingInfo bi, Actor toIgnore) + public static bool IsCellBuildable(this World world, CPos a, BuildingInfo bi, Actor toIgnore) { if (world.WorldActor.Trait().GetBuildingAt(a) != null) return false; if (world.ActorMap.GetUnitsAt(a).Any(b => b != toIgnore)) return false; @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Buildings return world.Map.IsInMap(a) && bi.TerrainTypes.Contains(world.GetTerrainType(a)); } - public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, int2 topLeft, Actor toIgnore) + public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, CPos topLeft, Actor toIgnore) { var res = world.WorldActor.Trait(); return FootprintUtils.Tiles(name, building, topLeft).All( @@ -37,7 +37,7 @@ namespace OpenRA.Mods.RA.Buildings world.IsCellBuildable(t, building, toIgnore)); } - public static IEnumerable GetLineBuildCells(World world, int2 location, string name, BuildingInfo bi) + public static IEnumerable GetLineBuildCells(World world, CPos location, string name, BuildingInfo bi) { int range = Rules.Info[name].Traits.Get().Range; var topLeft = location; // 1x1 assumption! @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Buildings // Start at place location, search outwards // TODO: First make it work, then make it nice - var vecs = new[] { new int2(1, 0), new int2(0, 1), new int2(-1, 0), new int2(0, -1) }; + var vecs = new[] { new CVec(1, 0), new CVec(0, 1), new CVec(-1, 0), new CVec(0, -1) }; int[] dirs = { 0, 0, 0, 0 }; for (int d = 0; d < 4; d++) { @@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA.Buildings if (dirs[d] != 0) continue; - int2 cell = topLeft + i * vecs[d]; + CPos cell = topLeft + i * vecs[d]; if (world.IsCellBuildable(cell, bi)) continue; // Cell is empty; continue search diff --git a/OpenRA.Mods.RA/Burns.cs b/OpenRA.Mods.RA/Burns.cs index 11a7c51310..bc39d33ef8 100644 --- a/OpenRA.Mods.RA/Burns.cs +++ b/OpenRA.Mods.RA/Burns.cs @@ -24,8 +24,7 @@ namespace OpenRA.Mods.RA class Burns : ITick, ISync { - [Sync] - int ticks; + [Sync] int ticks; BurnsInfo Info; public Burns(Actor self, BurnsInfo info) diff --git a/OpenRA.Mods.RA/CarpetBomb.cs b/OpenRA.Mods.RA/CarpetBomb.cs index d19fbfaaeb..34409a3031 100644 --- a/OpenRA.Mods.RA/CarpetBomb.cs +++ b/OpenRA.Mods.RA/CarpetBomb.cs @@ -22,16 +22,16 @@ namespace OpenRA.Mods.RA class CarpetBomb : ITick // todo: maybe integrate this better with the normal weapons system? { - int2 Target; + CPos Target; int dropDelay; - public void SetTarget(int2 targetCell) { Target = targetCell; } + public void SetTarget(CPos targetCell) { Target = targetCell; } public void Tick(Actor self) { var info = self.Info.Traits.Get(); - if( !Combat.IsInRange( self.CenterLocation, info.Range, Target * Game.CellSize ) ) + if( !Combat.IsInRange( self.CenterLocation, info.Range, Target.ToPPos() ) ) return; var limitedAmmo = self.TraitOrDefault(); diff --git a/OpenRA.Mods.RA/CashTrickler.cs b/OpenRA.Mods.RA/CashTrickler.cs index 6fe37b796f..f65a1e66c7 100644 --- a/OpenRA.Mods.RA/CashTrickler.cs +++ b/OpenRA.Mods.RA/CashTrickler.cs @@ -26,8 +26,7 @@ namespace OpenRA.Mods.RA class CashTrickler : ITick, ISync { - [Sync] - int ticks; + [Sync] int ticks; CashTricklerInfo Info; public CashTrickler(CashTricklerInfo info) { diff --git a/OpenRA.Mods.RA/ChronoshiftDeploy.cs b/OpenRA.Mods.RA/ChronoshiftDeploy.cs index c8079f2004..af4cea046f 100644 --- a/OpenRA.Mods.RA/ChronoshiftDeploy.cs +++ b/OpenRA.Mods.RA/ChronoshiftDeploy.cs @@ -24,8 +24,7 @@ namespace OpenRA.Mods.RA class ChronoshiftDeploy : IIssueOrder, IResolveOrder, ITick, IPips, IOrderVoice, ISync { // Recharge logic - [Sync] - int chargeTick = 0; // How long until we can chronoshift again? + [Sync] int chargeTick = 0; // How long until we can chronoshift again? public void Tick(Actor self) { @@ -60,7 +59,7 @@ namespace OpenRA.Mods.RA self.CancelActivity(); self.QueueActivity(new Teleport(order.TargetLocation)); Sound.Play("chrotnk1.aud", self.CenterLocation); - Sound.Play("chrotnk1.aud", Game.CellSize * order.TargetLocation.ToFloat2()); + Sound.Play("chrotnk1.aud", order.TargetLocation.ToPPos()); chargeTick = 25 * self.Info.Traits.Get().ChargeTime; foreach (var a in self.World.ActorsWithTrait()) diff --git a/OpenRA.Mods.RA/Chronoshiftable.cs b/OpenRA.Mods.RA/Chronoshiftable.cs index 6f20385360..0d722e0f22 100755 --- a/OpenRA.Mods.RA/Chronoshiftable.cs +++ b/OpenRA.Mods.RA/Chronoshiftable.cs @@ -18,10 +18,8 @@ namespace OpenRA.Mods.RA public class Chronoshiftable : ITick, ISync { // Return-to-sender logic - [Sync] - int2 chronoshiftOrigin; - [Sync] - int chronoshiftReturnTicks = 0; + [Sync] CPos chronoshiftOrigin; + [Sync] int chronoshiftReturnTicks = 0; public void Tick(Actor self) { @@ -41,7 +39,7 @@ namespace OpenRA.Mods.RA } // Can't be used in synced code, except with ignoreVis. - public virtual bool CanChronoshiftTo(Actor self, int2 targetLocation, bool ignoreVis) + public virtual bool CanChronoshiftTo(Actor self, CPos targetLocation, bool ignoreVis) { // Todo: Allow enemy units to be chronoshifted into bad terrain to kill them return self.HasTrait() && @@ -49,7 +47,7 @@ namespace OpenRA.Mods.RA (ignoreVis || self.World.LocalShroud.IsExplored(targetLocation)); } - public virtual bool Teleport(Actor self, int2 targetLocation, int duration, bool killCargo, Actor chronosphere) + public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere) { /// Set up return-to-sender info chronoshiftOrigin = self.Location; diff --git a/OpenRA.Mods.RA/Combat.cs b/OpenRA.Mods.RA/Combat.cs index 03e75c239d..bbb9922a30 100755 --- a/OpenRA.Mods.RA/Combat.cs +++ b/OpenRA.Mods.RA/Combat.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA public static void DoImpact(WarheadInfo warhead, ProjectileArgs args) { var world = args.firedBy.World; - var targetTile = Util.CellContaining(args.dest); + var targetTile = args.dest.ToCPos(); if (!world.Map.IsInMap(targetTile)) return; @@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA case DamageModel.PerCell: { foreach (var t in world.FindTilesInCircle(targetTile, warhead.Size[0])) - foreach (var unit in world.FindUnits(Game.CellSize * t, Game.CellSize * (t + new int2(1,1)))) + foreach (var unit in world.FindUnits(t.ToPPos(), (t + new CVec(1,1)).ToPPos())) unit.InflictDamage(args.firedBy, (int)(warhead.Damage * warhead.EffectivenessAgainst(unit)), warhead); } break; @@ -103,16 +103,19 @@ namespace OpenRA.Mods.RA { foreach (var warhead in args.weapon.Warheads) { - Action a = () => DoImpact(warhead, args); + // NOTE(jsd): Fixed access to modified closure bug! + var warheadClosed = warhead; + + Action a = () => DoImpact(warheadClosed, args); if (warhead.Delay > 0) args.firedBy.World.AddFrameEndTask( - w => w.Add(new DelayedAction(warhead.Delay, a))); + w => w.Add(new DelayedAction(warheadClosed.Delay, a))); else a(); } } - public static void DoExplosion(Actor attacker, string weapontype, int2 pos, int altitude) + public static void DoExplosion(Actor attacker, string weapontype, PPos pos, int altitude) { var args = new ProjectileArgs { @@ -174,7 +177,7 @@ namespace OpenRA.Mods.RA return true; } - public static bool WeaponValidForTarget( WeaponInfo weapon, World world, int2 location ) + public static bool WeaponValidForTarget( WeaponInfo weapon, World world, CPos location ) { if( weapon.ValidTargets.Contains( "Ground" ) && world.GetTerrainType( location ) != "Water" ) return true; if( weapon.ValidTargets.Contains( "Water" ) && world.GetTerrainType( location ) == "Water" ) return true; @@ -192,7 +195,7 @@ namespace OpenRA.Mods.RA return Util.RotateVectorByFacing(localRecoil, facing, .7f); } - public static float2 GetTurretPosition(Actor self, IFacing facing, Turret turret) + public static PVecInt GetTurretPosition(Actor self, IFacing facing, Turret turret) { if (facing == null) return turret.ScreenSpacePosition; /* things that don't have a rotating base don't need the turrets repositioned */ @@ -201,41 +204,41 @@ namespace OpenRA.Mods.RA var bodyFacing = facing.Facing; var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs); - return (Util.RotateVectorByFacing(turret.UnitSpacePosition, quantizedFacing, .7f) + return (PVecInt) ((PVecFloat)(Util.RotateVectorByFacing(turret.UnitSpacePosition.ToFloat2(), quantizedFacing, .7f) + GetRecoil(self, turret.Recoil)) - + turret.ScreenSpacePosition; + + turret.ScreenSpacePosition); } // gets the screen-space position of a barrel. - public static float2 GetBarrelPosition(Actor self, IFacing facing, Turret turret, Barrel barrel) + public static PVecInt GetBarrelPosition(Actor self, IFacing facing, Turret turret, Barrel barrel) { var turreted = self.TraitOrDefault(); if (turreted == null && facing == null) - return float2.Zero; + return PVecInt.Zero; var turretFacing = turreted != null ? turreted.turretFacing : facing.Facing; return GetTurretPosition(self, facing, turret) + barrel.ScreenSpaceOffset - + Util.RotateVectorByFacing(barrel.TurretSpaceOffset, turretFacing, .7f); + + (PVecInt)(PVecFloat)Util.RotateVectorByFacing(barrel.TurretSpaceOffset.ToFloat2(), turretFacing, .7f); } - public static bool IsInRange( float2 attackOrigin, float range, Actor target ) + public static bool IsInRange( PPos attackOrigin, float range, Actor target ) { var rsq = range * range * Game.CellSize * Game.CellSize; - foreach( var cell in target.Trait().TargetableCells( target ) ) - if( ( attackOrigin - cell * Game.CellSize ).LengthSquared <= rsq ) + foreach ( var cell in target.Trait().TargetableCells( target ) ) + if ( (attackOrigin - cell.ToPPos()).LengthSquared <= rsq ) return true; return false; } - public static bool IsInRange( float2 attackOrigin, float range, float2 targetLocation ) + public static bool IsInRange(PPos attackOrigin, float range, PPos targetLocation) { var rsq = range * range * Game.CellSize * Game.CellSize; return ( attackOrigin - targetLocation ).LengthSquared <= rsq; } - public static bool IsInRange( float2 attackOrigin, float range, Target target ) + public static bool IsInRange(PPos attackOrigin, float range, Target target) { if( !target.IsValid ) return false; if( target.IsActor ) diff --git a/OpenRA.Mods.RA/Crate.cs b/OpenRA.Mods.RA/Crate.cs index 5324a12287..5e622c6e0f 100644 --- a/OpenRA.Mods.RA/Crate.cs +++ b/OpenRA.Mods.RA/Crate.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA { readonly Actor self; [Sync] int ticks; - [Sync] public int2 Location; + [Sync] public CPos Location; CrateInfo Info; public Crate(ActorInitializer init, CrateInfo info) @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA this.self = init.self; if (init.Contains()) { - this.Location = init.Get(); + this.Location = init.Get(); PxPosition = Util.CenterOfCell(Location); } this.Info = info; @@ -79,19 +79,19 @@ namespace OpenRA.Mods.RA self.Destroy(); } - public int2 TopLeft { get { return Location; } } - public IEnumerable> OccupiedCells() { yield return Pair.New( Location, SubCell.FullCell); } + public CPos TopLeft { get { return Location; } } + public IEnumerable> OccupiedCells() { yield return Pair.New( Location, SubCell.FullCell); } - public int2 PxPosition { get; private set; } + public PPos PxPosition { get; private set; } - public void SetPxPosition( Actor self, int2 px ) + public void SetPxPosition(Actor self, PPos px) { - SetPosition( self, Util.CellContaining( px ) ); + SetPosition( self, px.ToCPos() ); } - public void AdjustPxPosition(Actor self, int2 px) { SetPxPosition(self, px); } + public void AdjustPxPosition(Actor self, PPos px) { SetPxPosition(self, px); } - public bool CanEnterCell(int2 cell) + public bool CanEnterCell(CPos cell) { if (!self.World.Map.IsInMap(cell.X, cell.Y)) return false; var type = self.World.GetTerrainType(cell); @@ -104,7 +104,7 @@ namespace OpenRA.Mods.RA return true; } - public void SetPosition(Actor self, int2 cell) + public void SetPosition(Actor self, CPos cell) { if( self.IsInWorld ) self.World.ActorMap.Remove(self, this); diff --git a/OpenRA.Mods.RA/CrateDrop.cs b/OpenRA.Mods.RA/CrateDrop.cs index 5cb288042b..2e2d362d1d 100644 --- a/OpenRA.Mods.RA/CrateDrop.cs +++ b/OpenRA.Mods.RA/CrateDrop.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA } } - int2? ChooseDropCell(Actor self, bool inWater, int maxTries) + CPos? ChooseDropCell(Actor self, bool inWater, int maxTries) { for( var n = 0; n < maxTries; n++ ) { diff --git a/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs b/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs index e80f77b278..a6c33d4195 100644 --- a/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs +++ b/OpenRA.Mods.RA/Crates/GiveUnitCrateAction.cs @@ -60,17 +60,17 @@ namespace OpenRA.Mods.RA.Crates base.Activate(collector); } - IEnumerable GetSuitableCells(int2 near) + IEnumerable GetSuitableCells(CPos near) { var mi = Rules.Info[Info.Unit].Traits.Get(); for (var i = -1; i < 2; i++) for (var j = -1; j < 2; j++) - if (mi.CanEnterCell(self.World, self.Owner, near + new int2(i, j), null, true)) - yield return near + new int2(i, j); + if (mi.CanEnterCell(self.World, self.Owner, near + new CVec(i, j), null, true)) + yield return near + new CVec(i, j); } - int2? ChooseEmptyCellNear(Actor a) + CPos? ChooseEmptyCellNear(Actor a) { var possibleCells = GetSuitableCells(a.Location).ToArray(); if (possibleCells.Length == 0) diff --git a/OpenRA.Mods.RA/DemoTruck.cs b/OpenRA.Mods.RA/DemoTruck.cs index d8de762a82..ddc0373746 100644 --- a/OpenRA.Mods.RA/DemoTruck.cs +++ b/OpenRA.Mods.RA/DemoTruck.cs @@ -17,7 +17,7 @@ namespace OpenRA.Mods.RA class DemoTruck : Chronoshiftable, INotifyKilled { // Explode on chronoshift - public override bool Teleport(Actor self, int2 targetLocation, int duration, bool killCargo, Actor chronosphere) + public override bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere) { Detonate(self, chronosphere); return false; diff --git a/OpenRA.Mods.RA/Effects/Bullet.cs b/OpenRA.Mods.RA/Effects/Bullet.cs index b44e238f72..48f839e43b 100755 --- a/OpenRA.Mods.RA/Effects/Bullet.cs +++ b/OpenRA.Mods.RA/Effects/Bullet.cs @@ -57,8 +57,8 @@ namespace OpenRA.Mods.RA.Effects if (info.Inaccuracy > 0) { - var factor = ((Args.dest - Args.src).Length / Game.CellSize) / args.weapon.Range; - Args.dest += (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2(); + var factor = ((Args.dest - Args.src).Length / (float)Game.CellSize) / args.weapon.Range; + Args.dest += (PVecInt) (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2(); } if (Info.Image != null) @@ -110,7 +110,7 @@ namespace OpenRA.Mods.RA.Effects { var at = (float)t / TotalTime(); var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at); - var pos = float2.Lerp(Args.src, Args.dest, at) - new float2(0, altitude); + var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at) - new float2(0, altitude); var highPos = (Info.High || Info.Angle > 0) ? (pos - new float2(0, GetAltitude())) @@ -119,24 +119,24 @@ namespace OpenRA.Mods.RA.Effects if (Info.Trail != null && --ticksToNextSmoke < 0) { world.AddFrameEndTask(w => w.Add( - new Smoke(w, highPos.ToInt2(), Info.Trail))); + new Smoke(w, (PPos) highPos.ToInt2(), Info.Trail))); ticksToNextSmoke = Info.TrailInterval; } if (Trail != null) - Trail.Tick(highPos); + Trail.Tick((PPos)highPos.ToInt2()); } if (!Info.High) // check for hitting a wall { var at = (float)t / TotalTime(); - var pos = float2.Lerp(Args.src, Args.dest, at); - var cell = Traits.Util.CellContaining(pos); + var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at); + var cell = ((PPos) pos.ToInt2()).ToCPos(); if (world.ActorMap.GetUnitsAt(cell).Any( a => a.HasTrait())) { - Args.dest = pos.ToInt2(); + Args.dest = (PPos) pos.ToInt2(); Explode(world); } } @@ -151,9 +151,9 @@ namespace OpenRA.Mods.RA.Effects var at = (float)t / TotalTime(); var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at); - var pos = float2.Lerp(Args.src, Args.dest, at) - new float2(0, altitude); + var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at) - new float2(0, altitude); - if (Args.firedBy.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(pos))) + if (Args.firedBy.World.LocalShroud.IsVisible(((PPos) pos.ToInt2()).ToCPos())) { if (Info.High || Info.Angle > 0) { diff --git a/OpenRA.Mods.RA/Effects/CashTick.cs b/OpenRA.Mods.RA/Effects/CashTick.cs index cc1ea80607..8c2195da9a 100644 --- a/OpenRA.Mods.RA/Effects/CashTick.cs +++ b/OpenRA.Mods.RA/Effects/CashTick.cs @@ -18,19 +18,20 @@ namespace OpenRA.Mods.RA.Effects { class CashTick : IEffect { - string s; + readonly string s; int remaining; - int velocity; - float2 pos, offset; - Color color; - SpriteFont font; + readonly int velocity; + PPos pos; + readonly float2 offset; + readonly Color color; + readonly SpriteFont font; static string FormatCashAmount(int x) { return "{0}${1}".F(x < 0 ? "-" : "+", x); } - public CashTick(int value, int lifetime, int velocity, float2 pos, Color color) + public CashTick(int value, int lifetime, int velocity, PPos pos, Color color) : this( FormatCashAmount(value), lifetime, velocity, pos, color ) { } - public CashTick(string value, int lifetime, int velocity, float2 pos, Color color) + public CashTick(string value, int lifetime, int velocity, PPos pos, Color color) { this.color = color; this.velocity = velocity; @@ -45,12 +46,12 @@ namespace OpenRA.Mods.RA.Effects { if (--remaining <= 0) world.AddFrameEndTask(w => w.Remove(this)); - pos.Y -= velocity; + pos -= new PVecInt(0, velocity); } public IEnumerable Render() { - font.DrawTextWithContrast(s, Game.viewport.Zoom*(pos - Game.viewport.Location) - offset, color, Color.Black,1); + font.DrawTextWithContrast(s, Game.viewport.Zoom*(pos.ToFloat2() - Game.viewport.Location) - offset, color, Color.Black,1); yield break; } } diff --git a/OpenRA.Mods.RA/Effects/Contrail.cs b/OpenRA.Mods.RA/Effects/Contrail.cs index 3fe86a8112..c59f30d5df 100755 --- a/OpenRA.Mods.RA/Effects/Contrail.cs +++ b/OpenRA.Mods.RA/Effects/Contrail.cs @@ -45,8 +45,7 @@ namespace OpenRA.Mods.RA public void Tick(Actor self) { - history.Tick(self.CenterLocation - new int2(0, move.Altitude) - - Combat.GetTurretPosition(self, facing, contrailTurret)); + history.Tick(self.CenterLocation - new PVecInt(0, move.Altitude) - Combat.GetTurretPosition(self, facing, contrailTurret)); } public void RenderAfterWorld(WorldRenderer wr, Actor self) { history.Render(self); } @@ -54,7 +53,7 @@ namespace OpenRA.Mods.RA class ContrailHistory { - List positions = new List(); + List positions = new List(); readonly int TrailLength; readonly Color Color; readonly int StartSkip; @@ -75,7 +74,7 @@ namespace OpenRA.Mods.RA this.StartSkip = startSkip; } - public void Tick(float2 currentPos) + public void Tick(PPos currentPos) { positions.Add(currentPos); if (positions.Count >= TrailLength) @@ -85,22 +84,20 @@ namespace OpenRA.Mods.RA public void Render(Actor self) { Color trailStart = Color; - Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R, - trailStart.G, trailStart.B); + Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R, trailStart.G, trailStart.B); for (int i = positions.Count - 1 - StartSkip; i >= 1; --i) { var conPos = positions[i]; var nextPos = positions[i - 1]; - if (self.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(conPos)) || - self.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(nextPos))) + if (self.World.LocalShroud.IsVisible(conPos.ToCPos()) || + self.World.LocalShroud.IsVisible(nextPos.ToCPos())) { - Game.Renderer.WorldLineRenderer.DrawLine(conPos, nextPos, trailStart, trailEnd); + Game.Renderer.WorldLineRenderer.DrawLine(conPos.ToFloat2(), nextPos.ToFloat2(), trailStart, trailEnd); trailStart = trailEnd; - trailEnd = Color.FromArgb(trailStart.A - 255 / positions.Count, trailStart.R, - trailStart.G, trailStart.B); + trailEnd = Color.FromArgb(trailStart.A - 255 / positions.Count, trailStart.R, trailStart.G, trailStart.B); } } } diff --git a/OpenRA.Mods.RA/Effects/Corpse.cs b/OpenRA.Mods.RA/Effects/Corpse.cs index be596e9b32..7a536b9ab8 100644 --- a/OpenRA.Mods.RA/Effects/Corpse.cs +++ b/OpenRA.Mods.RA/Effects/Corpse.cs @@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Effects anim.PlayThen(sequence, () => fromActor.World.AddFrameEndTask(w => w.Remove(this))); - pos = fromActor.CenterLocation; + pos = fromActor.CenterLocation.ToFloat2(); } public void Tick( World world ) { anim.Tick(); } diff --git a/OpenRA.Mods.RA/Effects/CrateEffect.cs b/OpenRA.Mods.RA/Effects/CrateEffect.cs index 5eb9d21540..7f0e7ab083 100644 --- a/OpenRA.Mods.RA/Effects/CrateEffect.cs +++ b/OpenRA.Mods.RA/Effects/CrateEffect.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA.Effects { if (a.IsInWorld) yield return new Renderable(anim.Image, - a.CenterLocation - .5f * anim.Image.size + offset, "effect", (int)a.CenterLocation.Y); + a.CenterLocation.ToFloat2() - .5f * anim.Image.size + offset, "effect", (int)a.CenterLocation.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/Explosion.cs b/OpenRA.Mods.RA/Effects/Explosion.cs index 2a3e27ebd9..646999ae2f 100644 --- a/OpenRA.Mods.RA/Effects/Explosion.cs +++ b/OpenRA.Mods.RA/Effects/Explosion.cs @@ -18,10 +18,10 @@ namespace OpenRA.Mods.RA.Effects public class Explosion : IEffect { Animation anim; - int2 pos; + PPos pos; int altitude; - public Explosion(World world, int2 pixelPos, string style, bool isWater, int altitude) + public Explosion(World world, PPos pixelPos, string style, bool isWater, int altitude) { this.pos = pixelPos; this.altitude = altitude; @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { yield return new Renderable(anim.Image, - pos - .5f * anim.Image.size - new int2(0,altitude), + pos.ToFloat2() - .5f * anim.Image.size - new int2(0,altitude), "effect", (int)pos.Y - altitude); } diff --git a/OpenRA.Mods.RA/Effects/GpsDot.cs b/OpenRA.Mods.RA/Effects/GpsDot.cs index 8d50c820f8..fdce097bcc 100644 --- a/OpenRA.Mods.RA/Effects/GpsDot.cs +++ b/OpenRA.Mods.RA/Effects/GpsDot.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.RA.Effects if (show && !self.Destroyed) { var p = self.CenterLocation; - yield return new Renderable(anim.Image, p - 0.5f * anim.Image.size, rs.Palette(self.Owner), p.Y) + yield return new Renderable(anim.Image, p.ToFloat2() - 0.5f * anim.Image.size, rs.Palette(self.Owner), p.Y) .WithScale(1.5f); } } diff --git a/OpenRA.Mods.RA/Effects/GravityBomb.cs b/OpenRA.Mods.RA/Effects/GravityBomb.cs index b2b6f83ff6..36a142c7ab 100755 --- a/OpenRA.Mods.RA/Effects/GravityBomb.cs +++ b/OpenRA.Mods.RA/Effects/GravityBomb.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { yield return new Renderable(anim.Image, - Args.dest - new int2(0, altitude) - .5f * anim.Image.size, "effect", Args.dest.Y); + Args.dest.ToInt2() - new int2(0, altitude) - .5f * anim.Image.size, "effect", Args.dest.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/LaserZap.cs b/OpenRA.Mods.RA/Effects/LaserZap.cs index d4de3e53bf..bba07c0386 100755 --- a/OpenRA.Mods.RA/Effects/LaserZap.cs +++ b/OpenRA.Mods.RA/Effects/LaserZap.cs @@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA.Effects { if (explosion != null) yield return new Renderable(explosion.Image, - args.dest - .5f * explosion.Image.size, "effect", (int)args.dest.Y); + args.dest.ToFloat2() - .5f * explosion.Image.size, "effect", (int)args.dest.Y); if (ticks >= info.BeamDuration) yield break; @@ -87,7 +87,7 @@ namespace OpenRA.Mods.RA.Effects var wlr = Game.Renderer.WorldLineRenderer; wlr.LineWidth = info.BeamRadius * 2; - wlr.DrawLine(args.src, args.dest, rc, rc); + wlr.DrawLine(args.src.ToFloat2(), args.dest.ToFloat2(), rc, rc); wlr.Flush(); wlr.LineWidth = 1f; } diff --git a/OpenRA.Mods.RA/Effects/Missile.cs b/OpenRA.Mods.RA/Effects/Missile.cs index d7df87b0ce..426b3d0808 100755 --- a/OpenRA.Mods.RA/Effects/Missile.cs +++ b/OpenRA.Mods.RA/Effects/Missile.cs @@ -46,9 +46,9 @@ namespace OpenRA.Mods.RA.Effects readonly MissileInfo Info; readonly ProjectileArgs Args; - int2 offset; + PVecInt offset; public int2 SubPxPosition; - public int2 PxPosition { get { return new int2( SubPxPosition.X / 1024, SubPxPosition.Y / 1024 ); } } + public PPos PxPosition { get { return new PPos(SubPxPosition.X / 1024, SubPxPosition.Y / 1024); } } readonly Animation anim; int Facing; @@ -61,12 +61,12 @@ namespace OpenRA.Mods.RA.Effects Info = info; Args = args; - SubPxPosition = 1024 * Args.src; + SubPxPosition = 1024 * Args.src.ToInt2(); Altitude = Args.srcAltitude; Facing = Args.facing; if (info.Inaccuracy > 0) - offset = (info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2(); + offset = (PVecInt)(info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2(); if (Info.Image != null) { @@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA.Effects if (Info.Trail != null) { - var sp = (SubPxPosition - (move * 3) / 2) / 1024 - new int2(0, Altitude); + var sp = (PPos)((SubPxPosition - (move * 3) / 2) / 1024) - new PVecInt(0, Altitude); if (--ticksToNextSmoke < 0) { @@ -135,14 +135,13 @@ namespace OpenRA.Mods.RA.Effects if (!Info.High) // check for hitting a wall { - var cell = Traits.Util.CellContaining(PxPosition); - if (world.ActorMap.GetUnitsAt(cell).Any( - a => a.HasTrait())) + var cell = PxPosition.ToCPos(); + if (world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait())) Explode(world); } if (Trail != null) - Trail.Tick(PxPosition - new float2(0,Altitude)); + Trail.Tick(PxPosition - new PVecInt(0, Altitude)); } void Explode(World world) @@ -155,8 +154,8 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { - if (Args.firedBy.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(PxPosition.ToFloat2()))) - yield return new Renderable(anim.Image,PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude), + if (Args.firedBy.World.LocalShroud.IsVisible(PxPosition.ToCPos())) + yield return new Renderable(anim.Image, PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude), Args.weapon.Underwater ? "shadow" : "effect", PxPosition.Y); if (Trail != null) diff --git a/OpenRA.Mods.RA/Effects/NukeLaunch.cs b/OpenRA.Mods.RA/Effects/NukeLaunch.cs index 1db21fb3ea..251370991f 100755 --- a/OpenRA.Mods.RA/Effects/NukeLaunch.cs +++ b/OpenRA.Mods.RA/Effects/NukeLaunch.cs @@ -19,13 +19,13 @@ namespace OpenRA.Mods.RA.Effects { readonly Player firedBy; Animation anim; - int2 pos; - int2 targetLocation; + PPos pos; + CPos targetLocation; int altitude; bool goingUp = true; string weapon; - public NukeLaunch(Player firedBy, Actor silo, string weapon, int2 spawnOffset, int2 targetLocation) + public NukeLaunch(Player firedBy, Actor silo, string weapon, PVecInt spawnOffset, CPos targetLocation) { this.firedBy = firedBy; this.targetLocation = targetLocation; @@ -71,7 +71,7 @@ namespace OpenRA.Mods.RA.Effects { world.AddFrameEndTask(w => w.Remove(this)); Combat.DoExplosion(firedBy.PlayerActor, weapon, pos, 0); - world.WorldActor.Trait().AddEffect(20, pos, 5); + world.WorldActor.Trait().AddEffect(20, pos.ToFloat2(), 5); foreach (var a in world.ActorsWithTrait()) a.Trait.Enable(); @@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { - yield return new Renderable(anim.Image, pos - 0.5f * anim.Image.size - new float2(0, altitude), + yield return new Renderable(anim.Image, pos.ToFloat2() - 0.5f * anim.Image.size - new float2(0, altitude), "effect", (int)pos.Y); } } diff --git a/OpenRA.Mods.RA/Effects/Parachute.cs b/OpenRA.Mods.RA/Effects/Parachute.cs index 439e3c099a..318bce35ee 100644 --- a/OpenRA.Mods.RA/Effects/Parachute.cs +++ b/OpenRA.Mods.RA/Effects/Parachute.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA.Effects readonly Animation anim; readonly string palette; readonly Animation paraAnim; - readonly float2 location; + readonly PPos location; readonly Actor cargo; @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA.Effects float altitude; const float fallRate = .3f; - public Parachute(Player owner, float2 location, int altitude, Actor cargo) + public Parachute(Player owner, PPos location, int altitude, Actor cargo) { this.location = location; this.altitude = altitude; @@ -63,7 +63,7 @@ namespace OpenRA.Mods.RA.Effects world.AddFrameEndTask(w => { w.Remove(this); - var loc = Traits.Util.CellContaining(location); + var loc = location.ToCPos(); cargo.CancelActivity(); cargo.Trait().SetPosition(cargo, loc); w.Add(cargo); @@ -72,8 +72,8 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { - var pos = location - new float2(0, altitude); - yield return new Renderable(anim.Image, location - .5f * anim.Image.size, "shadow", 0); + var pos = location.ToFloat2() - new float2(0, altitude); + yield return new Renderable(anim.Image, location.ToFloat2() - .5f * anim.Image.size, "shadow", 0); yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, palette, 2); yield return new Renderable(paraAnim.Image, pos - .5f * paraAnim.Image.size + offset, palette, 3); } diff --git a/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs b/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs index b4f63ec4d2..96b568c3d3 100644 --- a/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs +++ b/OpenRA.Mods.RA/Effects/PowerdownIndicator.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Effects { if (!a.Destroyed && (a.World.LocalPlayer == null || a.Owner.Stances[a.Owner.World.LocalPlayer] == Stance.Ally)) yield return new Renderable(anim.Image, - a.CenterLocation - .5f * anim.Image.size, "chrome", (int)a.CenterLocation.Y); + a.CenterLocation.ToFloat2() - .5f * anim.Image.size, "chrome", (int)a.CenterLocation.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/RallyPoint.cs b/OpenRA.Mods.RA/Effects/RallyPoint.cs index 0dccf825e0..bedd9a904e 100755 --- a/OpenRA.Mods.RA/Effects/RallyPoint.cs +++ b/OpenRA.Mods.RA/Effects/RallyPoint.cs @@ -18,8 +18,8 @@ namespace OpenRA.Mods.RA.Effects { class RallyPoint : IEffect { - Actor building; - RA.RallyPoint rp; + readonly Actor building; + readonly RA.RallyPoint rp; public Animation flag = new Animation("rallypoint"); public Animation circles = new Animation("rallypoint"); @@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Effects circles.Play("circles"); } - int2 cachedLocation; + CPos cachedLocation; public void Tick( World world ) { flag.Tick(); @@ -55,11 +55,11 @@ namespace OpenRA.Mods.RA.Effects var palette = building.Trait().Palette(building.Owner); yield return new Renderable(circles.Image, - pos - .5f * circles.Image.size, + pos.ToFloat2() - .5f * circles.Image.size, palette, (int)pos.Y); yield return new Renderable(flag.Image, - pos + new float2(-1,-17), + pos.ToFloat2() + new float2(-1,-17), palette, (int)pos.Y); } } diff --git a/OpenRA.Mods.RA/Effects/RepairIndicator.cs b/OpenRA.Mods.RA/Effects/RepairIndicator.cs index 5e4c6ac951..e710e92534 100755 --- a/OpenRA.Mods.RA/Effects/RepairIndicator.cs +++ b/OpenRA.Mods.RA/Effects/RepairIndicator.cs @@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Effects var palette = building.Trait().Palette(player); yield return new Renderable(anim.Image, - building.CenterLocation - .5f * anim.Image.size, palette, (int)building.CenterLocation.Y); + building.CenterLocation.ToFloat2() - .5f * anim.Image.size, palette, (int)building.CenterLocation.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs b/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs index ed7cd7c62e..1934e6f3e0 100644 --- a/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs +++ b/OpenRA.Mods.RA/Effects/SatelliteLaunch.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Effects doors.PlayThen("active", () => a.World.AddFrameEndTask(w => w.Remove(this))); - pos = a.CenterLocation - .5f * doors.Image.size + doorOffset; + pos = a.CenterLocation.ToFloat2() - .5f * doors.Image.size + doorOffset; } public void Tick( World world ) diff --git a/OpenRA.Mods.RA/Effects/Smoke.cs b/OpenRA.Mods.RA/Effects/Smoke.cs index 360e0a24a2..e966e9b355 100644 --- a/OpenRA.Mods.RA/Effects/Smoke.cs +++ b/OpenRA.Mods.RA/Effects/Smoke.cs @@ -17,10 +17,10 @@ namespace OpenRA.Mods.RA.Effects { public class Smoke : IEffect { - readonly int2 pos; + readonly PPos pos; readonly Animation anim; - public Smoke(World world, int2 pos, string trail) + public Smoke(World world, PPos pos, string trail) { this.pos = pos; anim = new Animation(trail); @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { - yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, "effect", (int)pos.Y); + yield return new Renderable(anim.Image, pos.ToFloat2() - .5f * anim.Image.size, "effect", (int)pos.Y); } } } diff --git a/OpenRA.Mods.RA/Effects/TeslaZap.cs b/OpenRA.Mods.RA/Effects/TeslaZap.cs index e006047a45..4ef516e5d0 100755 --- a/OpenRA.Mods.RA/Effects/TeslaZap.cs +++ b/OpenRA.Mods.RA/Effects/TeslaZap.cs @@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA.Effects public IEnumerable Render() { return renderables; } - static IEnumerable DrawZapWandering(int2 from, int2 to, Sequence s) + static IEnumerable DrawZapWandering(PPos from, PPos to, Sequence s) { var z = float2.Zero; /* hack */ var dist = to - from; @@ -73,19 +73,19 @@ namespace OpenRA.Mods.RA.Effects var renderables = new List(); if (Game.CosmeticRandom.Next(2) != 0) { - var p1 = from + (1 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm; - var p2 = from + (2 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm; + var p1 = from.ToFloat2() + (1 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm; + var p2 = from.ToFloat2() + (2 / 3f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm; - renderables.AddRange(DrawZap(from, p1, s, out p1)); + renderables.AddRange(DrawZap(from.ToFloat2(), p1, s, out p1)); renderables.AddRange(DrawZap(p1, p2, s, out p2)); - renderables.AddRange(DrawZap(p2, to, s, out z)); + renderables.AddRange(DrawZap(p2, to.ToFloat2(), s, out z)); } else { - var p1 = from + (1 / 2f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm; + var p1 = from.ToFloat2() + (1 / 2f) * dist.ToFloat2() + Game.CosmeticRandom.Gauss1D(1) * .2f * dist.Length * norm; - renderables.AddRange(DrawZap(from, p1, s, out p1)); - renderables.AddRange(DrawZap(p1, to, s, out z)); + renderables.AddRange(DrawZap(from.ToFloat2(), p1, s, out p1)); + renderables.AddRange(DrawZap(p1, to.ToFloat2(), s, out z)); } return renderables; diff --git a/OpenRA.Mods.RA/FreeActor.cs b/OpenRA.Mods.RA/FreeActor.cs index 9df8000c92..1ed405c92b 100644 --- a/OpenRA.Mods.RA/FreeActor.cs +++ b/OpenRA.Mods.RA/FreeActor.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA { var a = w.CreateActor(info.Actor, new TypeDictionary { - new LocationInit( self.Location + info.SpawnOffset ), + new LocationInit( self.Location + (CVec)info.SpawnOffset ), new OwnerInit( self.Owner ), new FacingInit( info.Facing ), }); diff --git a/OpenRA.Mods.RA/Harvester.cs b/OpenRA.Mods.RA/Harvester.cs index 33c96403b3..42a0dafc03 100644 --- a/OpenRA.Mods.RA/Harvester.cs +++ b/OpenRA.Mods.RA/Harvester.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.RA [Sync] public Actor LinkedProc = null; [Sync] int currentUnloadTicks; - public int2? LastHarvestedCell = null; + public CPos? LastHarvestedCell = null; [Sync] public int ContentValue { get { return contents.Sum(c => c.Key.ValuePerUnit*c.Value); } } readonly HarvesterInfo Info; @@ -131,7 +131,7 @@ namespace OpenRA.Mods.RA return new Order(order.OrderID, self, queued) { TargetActor = target.Actor }; if( order.OrderID == "Harvest" ) - return new Order(order.OrderID, self, queued) { TargetLocation = Util.CellContaining(target.CenterLocation) }; + return new Order(order.OrderID, self, queued) { TargetLocation = target.CenterLocation.ToCPos() }; return null; } @@ -147,7 +147,7 @@ namespace OpenRA.Mods.RA { var mobile = self.Trait(); self.CancelActivity(); - if (order.TargetLocation != int2.Zero) + if (order.TargetLocation != CPos.Zero) { self.QueueActivity(mobile.MoveTo(order.TargetLocation, 0)); self.SetTargetLine(Target.FromOrder(order), Color.Red); @@ -218,7 +218,7 @@ namespace OpenRA.Mods.RA return false; } - public bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) + public bool CanTargetLocation(Actor self, CPos location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) { // Don't leak info about resources under the shroud if (!self.World.LocalShroud.IsExplored(location)) return false; diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index d63494cc35..8bca20ca7f 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -22,22 +22,19 @@ namespace OpenRA.Mods.RA class Husk : IOccupySpace, IFacing, ISync { - [Sync] - int2 location; + [Sync] CPos location; - [Sync] - public int2 PxPosition { get; set; } + [Sync] public PPos PxPosition { get; set; } - [Sync] - public int Facing { get; set; } + [Sync] public int Facing { get; set; } public int ROT { get { return 0; } } public int InitialFacing { get { return 128; } } public Husk(ActorInitializer init) { var self = init.self; - location = init.Get(); - PxPosition = init.Get(); + location = init.Get(); + PxPosition = init.Get(); Facing = init.Contains() ? init.Get() : 128; var speed = init.Contains() ? init.Get() : 0; @@ -49,18 +46,18 @@ namespace OpenRA.Mods.RA } } - public int2 TopLeft { get { return location; } } + public CPos TopLeft { get { return location; } } - public IEnumerable> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); } + public IEnumerable> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); } class DragHusk : Activity { Husk husk; - int2 endLocation; - int2 startLocation; + PPos endLocation; + PPos startLocation; int length; - public DragHusk(int2 start, int2 end, int length, Husk husk) + public DragHusk(PPos start, PPos end, int length, Husk husk) { startLocation = start; endLocation = end; @@ -77,7 +74,7 @@ namespace OpenRA.Mods.RA return NextActivity; } - husk.PxPosition = int2.Lerp(startLocation, endLocation, ticks++, length - 1); + husk.PxPosition = PPos.Lerp(startLocation, endLocation, ticks++, length - 1); return this; } diff --git a/OpenRA.Mods.RA/IronCurtainable.cs b/OpenRA.Mods.RA/IronCurtainable.cs index f448478c4d..02239e47bd 100644 --- a/OpenRA.Mods.RA/IronCurtainable.cs +++ b/OpenRA.Mods.RA/IronCurtainable.cs @@ -18,8 +18,7 @@ namespace OpenRA.Mods.RA class IronCurtainable : IDamageModifier, ITick, ISync { - [Sync] - int RemainingTicks = 0; + [Sync] int RemainingTicks = 0; public void Tick(Actor self) { diff --git a/OpenRA.Mods.RA/LimitedAmmo.cs b/OpenRA.Mods.RA/LimitedAmmo.cs index 02df6181d5..2360889c17 100644 --- a/OpenRA.Mods.RA/LimitedAmmo.cs +++ b/OpenRA.Mods.RA/LimitedAmmo.cs @@ -24,8 +24,7 @@ namespace OpenRA.Mods.RA public class LimitedAmmo : INotifyAttack, IPips, ISync { - [Sync] - int ammo; + [Sync] int ammo; LimitedAmmoInfo Info; public LimitedAmmo(LimitedAmmoInfo info) diff --git a/OpenRA.Mods.RA/MPStartLocations.cs b/OpenRA.Mods.RA/MPStartLocations.cs index 79ad39e8ae..64fa49e993 100755 --- a/OpenRA.Mods.RA/MPStartLocations.cs +++ b/OpenRA.Mods.RA/MPStartLocations.cs @@ -24,13 +24,13 @@ namespace OpenRA.Mods.RA public class MPStartLocations : IWorldLoaded { - public Dictionary Start = new Dictionary(); + public Dictionary Start = new Dictionary(); public void WorldLoaded(World world) { var taken = world.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0 && c.Slot != null) - .Select(c => world.Map.GetSpawnPoints()[c.SpawnPoint-1]).ToList(); - var available = world.Map.GetSpawnPoints().Except(taken).ToList(); + .Select(c => (CPos) world.Map.GetSpawnPoints()[c.SpawnPoint-1]).ToList(); + var available = world.Map.GetSpawnPoints().Select(c => (CPos)c).Except(taken).ToList(); // Set spawn foreach (var kv in world.LobbyInfo.Slots) @@ -41,7 +41,7 @@ namespace OpenRA.Mods.RA var client = world.LobbyInfo.ClientInSlot(kv.Key); var spid = (client == null || client.SpawnPoint == 0) ? ChooseSpawnPoint(world, available, taken) - : world.Map.GetSpawnPoints()[client.SpawnPoint-1]; + : (CPos)world.Map.GetSpawnPoints()[client.SpawnPoint-1]; Start.Add(player, spid); } @@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA // Set viewport if (world.LocalPlayer != null && Start.ContainsKey(world.LocalPlayer)) - Game.viewport.Center(Start[world.LocalPlayer]); + Game.viewport.Center(Start[world.LocalPlayer].ToFloat2()); } static Player FindPlayerInSlot(World world, string pr) @@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA return world.Players.FirstOrDefault(p => p.PlayerReference.Name == pr); } - static int2 ChooseSpawnPoint(World world, List available, List taken) + static CPos ChooseSpawnPoint(World world, List available, List taken) { if (available.Count == 0) throw new InvalidOperationException("No free spawnpoint."); diff --git a/OpenRA.Mods.RA/Mine.cs b/OpenRA.Mods.RA/Mine.cs index d167591a8c..ab91a66ece 100644 --- a/OpenRA.Mods.RA/Mine.cs +++ b/OpenRA.Mods.RA/Mine.cs @@ -31,13 +31,13 @@ namespace OpenRA.Mods.RA { readonly Actor self; readonly MineInfo info; - [Sync] readonly int2 location; + [Sync] readonly CPos location; public Mine(ActorInitializer init, MineInfo info) { this.self = init.self; this.info = info; - this.location = init.Get(); + this.location = init.Get(); } public void WarnCrush(Actor crusher) {} @@ -60,10 +60,10 @@ namespace OpenRA.Mods.RA return info.CrushClasses.Intersect(crushClasses).Any(); } - public int2 TopLeft { get { return location; } } + public CPos TopLeft { get { return location; } } - public IEnumerable> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); } - public int2 PxPosition { get { return Util.CenterOfCell( location ); } } + public IEnumerable> OccupiedCells() { yield return Pair.New(TopLeft, SubCell.FullCell); } + public PPos PxPosition { get { return Util.CenterOfCell( location ); } } } /* tag trait for stuff that shouldnt trigger mines */ diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index ff2a1cc63c..b3ff8b450e 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -31,8 +31,8 @@ namespace OpenRA.Mods.RA class Minelayer : IIssueOrder, IResolveOrder, IPostRenderSelection, ISync { /* [Sync] when sync can cope with arrays! */ - public int2[] minefield = null; - [Sync] int2 minefieldStart; + public CPos[] minefield = null; + [Sync] CPos minefieldStart; Actor self; public Minelayer(Actor self) { this.self = self; } @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA { if( order is BeginMinefieldOrderTargeter ) { - var start = Traits.Util.CellContaining( target.CenterLocation ); + var start = target.CenterLocation.ToCPos(); self.World.OrderGenerator = new MinefieldOrderGenerator( self, start ); return new Order("BeginMinefield", self, false) { TargetLocation = start }; } @@ -71,34 +71,34 @@ namespace OpenRA.Mods.RA } } - static IEnumerable GetMinefieldCells(int2 start, int2 end, float depth) + static IEnumerable GetMinefieldCells(CPos start, CPos end, float depth) { - var mins = int2.Min(start, end); - var maxs = int2.Max(start, end); + var mins = CPos.Min(start, end); + var maxs = CPos.Max(start, end); /* todo: proper endcaps, if anyone cares (which won't happen unless depth is large) */ 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); + var c = -float2.Dot(q, start.ToFloat2()); /* return all points such that |ax + by + c| < depth */ for (var i = mins.X; i <= maxs.X; i++) for (var j = mins.Y; j <= maxs.Y; j++) if (Math.Abs(q.X * i + q.Y * j + c) < depth) - yield return new int2(i, j); + yield return new CPos(i, j); } class MinefieldOrderGenerator : IOrderGenerator { readonly Actor minelayer; - readonly int2 minefieldStart; + readonly CPos minefieldStart; - public MinefieldOrderGenerator(Actor self, int2 xy ) { minelayer = self; minefieldStart = xy; } + public MinefieldOrderGenerator(Actor self, CPos xy ) { minelayer = self; minefieldStart = xy; } - public IEnumerable Order(World world, int2 xy, MouseInput mi) + public IEnumerable Order(World world, CPos xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { @@ -124,7 +124,7 @@ namespace OpenRA.Mods.RA world.CancelInputMode(); } - int2 lastMousePos; + CPos lastMousePos; public void RenderAfterWorld(WorldRenderer wr, World world) { if (!minelayer.IsInWorld) @@ -140,7 +140,7 @@ namespace OpenRA.Mods.RA public void RenderBeforeWorld(WorldRenderer wr, World world) { } - public string GetCursor(World world, int2 xy, MouseInput mi) { lastMousePos = xy; return "ability"; } /* todo */ + public string GetCursor(World world, CPos xy, MouseInput mi) { lastMousePos = xy; return "ability"; } /* todo */ } public void RenderAfterWorld(WorldRenderer wr) @@ -162,7 +162,7 @@ namespace OpenRA.Mods.RA return false; } - public bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) + public bool CanTargetLocation(Actor self, CPos location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) { if (!self.World.Map.IsInMap(location)) return false; diff --git a/OpenRA.Mods.RA/Missions/Allies01Script.cs b/OpenRA.Mods.RA/Missions/Allies01Script.cs index 9712484eb0..23d119f8bb 100644 --- a/OpenRA.Mods.RA/Missions/Allies01Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies01Script.cs @@ -204,8 +204,8 @@ namespace OpenRA.Mods.RA.Missions for (int i = 0; i < ships.Length; i++) { var actor = self.World.CreateActor(ships[i], - new TypeDictionary { new OwnerInit(allies), new LocationInit(shipSpawnPoint.Location + new int2(i * 2, 0)) }); - actor.QueueActivity(new Move.Move(shipMovePoint.Location + new int2(i * 4, 0))); + new TypeDictionary { new OwnerInit(allies), new LocationInit(shipSpawnPoint.Location + new CVec(i * 2, 0)) }); + actor.QueueActivity(new Move.Move(shipMovePoint.Location + new CVec(i * 4, 0))); } } diff --git a/OpenRA.Mods.RA/Missions/DefaultShellmapScript.cs b/OpenRA.Mods.RA/Missions/DefaultShellmapScript.cs index 603e1788b6..c36e02f0fb 100644 --- a/OpenRA.Mods.RA/Missions/DefaultShellmapScript.cs +++ b/OpenRA.Mods.RA/Missions/DefaultShellmapScript.cs @@ -21,13 +21,13 @@ namespace OpenRA.Mods.RA class DefaultShellmapScript: IWorldLoaded, ITick { Dictionary Actors; - static int2 ViewportOrigin; + static CPos ViewportOrigin; public void WorldLoaded(World w) { var b = w.Map.Bounds; - ViewportOrigin = new int2(b.Left + b.Width/2, b.Top + b.Height/2); - Game.MoveViewport(ViewportOrigin); + ViewportOrigin = new CPos(b.Left + b.Width/2, b.Top + b.Height/2); + Game.MoveViewport(ViewportOrigin.ToFloat2()); Actors = w.WorldActor.Trait().Actors; Sound.SoundVolumeModifier = 0.25f; @@ -39,26 +39,27 @@ namespace OpenRA.Mods.RA { var loc = new float2( (float)(System.Math.Sin((ticks + 45) % (360f * speed) * (Math.PI / 180) * 1f / speed) * 15f + ViewportOrigin.X), - (float)(System.Math.Cos((ticks + 45) % (360f * speed) * (Math.PI / 180) * 1f / speed) * 10f + ViewportOrigin.Y)); + (float)(System.Math.Cos((ticks + 45) % (360f * speed) * (Math.PI / 180) * 1f / speed) * 10f + ViewportOrigin.Y) + ); Game.MoveViewport(loc); if (ticks == 250) { - Scripting.RASpecialPowers.Chronoshift(self.World, new List>() + Scripting.RASpecialPowers.Chronoshift(self.World, new List>() { - Pair.New(Actors["ca1"], new int2(90, 70)), - Pair.New(Actors["ca2"], new int2(92, 71)) + Pair.New(Actors["ca1"], new CPos(90, 70)), + Pair.New(Actors["ca2"], new CPos(92, 71)) }, Actors["pdox"], -1, false); } if (ticks == 100) - Actors["mslo1"].Trait().Activate(Actors["mslo1"], new Order(){ TargetLocation = new int2(98, 52) }); + Actors["mslo1"].Trait().Activate(Actors["mslo1"], new Order() { TargetLocation = new CPos(98, 52) }); if (ticks == 140) - Actors["mslo2"].Trait().Activate(Actors["mslo2"], new Order(){ TargetLocation = new int2(95, 54) }); + Actors["mslo2"].Trait().Activate(Actors["mslo2"], new Order() { TargetLocation = new CPos(95, 54) }); if (ticks == 180) - Actors["mslo3"].Trait().Activate(Actors["mslo3"], new Order(){ TargetLocation = new int2(95, 49) }); + Actors["mslo3"].Trait().Activate(Actors["mslo3"], new Order() { TargetLocation = new CPos(95, 49) }); if (ticks == 430) { @@ -70,6 +71,4 @@ namespace OpenRA.Mods.RA ticks++; } } - - } diff --git a/OpenRA.Mods.RA/Move/Drag.cs b/OpenRA.Mods.RA/Move/Drag.cs index 909cefd703..9379d8c936 100755 --- a/OpenRA.Mods.RA/Move/Drag.cs +++ b/OpenRA.Mods.RA/Move/Drag.cs @@ -15,12 +15,12 @@ namespace OpenRA.Mods.RA.Move { public class Drag : Activity { - int2 endLocation; - int2 startLocation; + PPos endLocation; + PPos startLocation; int length; int ticks = 0; - public Drag(int2 start, int2 end, int length) + public Drag(PPos start, PPos end, int length) { startLocation = start; endLocation = end; @@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Move { var mobile = self.Trait(); mobile.PxPosition = length > 1 - ? int2.Lerp(startLocation, endLocation, ticks, length - 1) + ? PPos.Lerp(startLocation, endLocation, ticks, length - 1) : endLocation; if (++ticks >= length) diff --git a/OpenRA.Mods.RA/Move/Mobile.cs b/OpenRA.Mods.RA/Move/Mobile.cs index c674139016..4e8713174c 100755 --- a/OpenRA.Mods.RA/Move/Mobile.cs +++ b/OpenRA.Mods.RA/Move/Mobile.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.RA.Move public decimal Speed = 0; } - public int MovementCostForCell(World world, int2 cell) + public int MovementCostForCell(World world, CPos cell) { if (!world.Map.IsInMap(cell.X, cell.Y)) return int.MaxValue; @@ -67,17 +67,17 @@ namespace OpenRA.Mods.RA.Move return TerrainSpeeds[type].Cost; } - public readonly Dictionary SubCellOffsets = new Dictionary() + public readonly Dictionary SubCellOffsets = new Dictionary() { - {SubCell.TopLeft, new int2(-7,-6)}, - {SubCell.TopRight, new int2(6,-6)}, - {SubCell.Center, new int2(0,0)}, - {SubCell.BottomLeft, new int2(-7,6)}, - {SubCell.BottomRight, new int2(6,6)}, - {SubCell.FullCell, new int2(0,0)}, + {SubCell.TopLeft, new PVecInt(-7,-6)}, + {SubCell.TopRight, new PVecInt(6,-6)}, + {SubCell.Center, new PVecInt(0,0)}, + {SubCell.BottomLeft, new PVecInt(-7,6)}, + {SubCell.BottomRight, new PVecInt(6,6)}, + {SubCell.FullCell, new PVecInt(0,0)}, }; - public bool CanEnterCell(World world, Player owner, int2 cell, Actor ignoreActor, bool checkTransientActors) + public bool CanEnterCell(World world, Player owner, CPos cell, Actor ignoreActor, bool checkTransientActors) { if (MovementCostForCell(world, cell) == int.MaxValue) return false; @@ -108,35 +108,29 @@ namespace OpenRA.Mods.RA.Move public bool IsMoving { get; internal set; } int __facing; - int2 __fromCell, __toCell; + CPos __fromCell, __toCell; public SubCell fromSubCell, toSubCell; //int __altitude; - [Sync] - public int Facing + [Sync] public int Facing { get { return __facing; } set { __facing = value; } } - [Sync] - public int Altitude { get; set; } + [Sync] public int Altitude { get; set; } public int ROT { get { return Info.ROT; } } public int InitialFacing { get { return Info.InitialFacing; } } - [Sync] - public int2 PxPosition { get; set; } - [Sync] - public int2 fromCell { get { return __fromCell; } } - [Sync] - public int2 toCell { get { return __toCell; } } + [Sync] public PPos PxPosition { get; set; } + [Sync] public CPos fromCell { get { return __fromCell; } } + [Sync] public CPos toCell { get { return __toCell; } } - [Sync] - public int PathHash; // written by Move.EvalPath, to temporarily debug this crap. + [Sync] public int PathHash; // written by Move.EvalPath, to temporarily debug this crap. - public void SetLocation(int2 from, SubCell fromSub, int2 to, SubCell toSub) + public void SetLocation(CPos from, SubCell fromSub, CPos to, SubCell toSub) { if (fromCell == from && toCell == to) return; RemoveInfluence(); @@ -164,7 +158,7 @@ namespace OpenRA.Mods.RA.Move if (init.Contains()) { - this.__fromCell = this.__toCell = init.Get(); + this.__fromCell = this.__toCell = init.Get(); this.PxPosition = Util.CenterOfCell(fromCell) + info.SubCellOffsets[fromSubCell]; } @@ -172,22 +166,22 @@ namespace OpenRA.Mods.RA.Move this.Altitude = init.Contains() ? init.Get() : 0; } - public void SetPosition(Actor self, int2 cell) + public void SetPosition(Actor self, CPos cell) { SetLocation(cell,fromSubCell, cell,fromSubCell); PxPosition = Util.CenterOfCell(fromCell) + Info.SubCellOffsets[fromSubCell]; FinishedMoving(self); } - public void SetPxPosition(Actor self, int2 px) + public void SetPxPosition(Actor self, PPos px) { - var cell = Util.CellContaining(px); + var cell = px.ToCPos(); SetLocation(cell,fromSubCell, cell,fromSubCell); PxPosition = px; FinishedMoving(self); } - public void AdjustPxPosition(Actor self, int2 px) /* visual hack only */ + public void AdjustPxPosition(Actor self, PPos px) /* visual hack only */ { PxPosition = px; } @@ -200,17 +194,17 @@ namespace OpenRA.Mods.RA.Move if (order is MoveOrderTargeter) { if (Info.OnRails) return null; - return new Order("Move", self, queued) { TargetLocation = Util.CellContaining(target.CenterLocation) }; + return new Order("Move", self, queued) { TargetLocation = target.CenterLocation.ToCPos() }; } return null; } - public int2 NearestMoveableCell(int2 target) + public CPos NearestMoveableCell(CPos target) { if (CanEnterCell(target)) return target; - var searched = new List() { }; + var searched = new List(); // Limit search to a radius of 10 tiles for (int r = 1; r < 10; r++) foreach (var tile in self.World.FindTilesInCircle(target, r).Except(searched)) @@ -225,9 +219,9 @@ namespace OpenRA.Mods.RA.Move return target; } - void PerformMoveInner(Actor self, int2 targetLocation, bool queued) + void PerformMoveInner(Actor self, CPos targetLocation, bool queued) { - int2 currentLocation = NearestMoveableCell(targetLocation); + var currentLocation = NearestMoveableCell(targetLocation); if (!CanEnterCell(currentLocation)) { @@ -244,12 +238,12 @@ namespace OpenRA.Mods.RA.Move self.SetTargetLine(Target.FromCell(currentLocation), Color.Green); } - protected void PerformMove(Actor self, int2 targetLocation, bool queued) + protected void PerformMove(Actor self, CPos targetLocation, bool queued) { if (queued) - self.QueueActivity(new CallFunc(() => PerformMoveInner(self, targetLocation, queued))); + self.QueueActivity(new CallFunc(() => PerformMoveInner(self, targetLocation, true))); else - PerformMoveInner(self, targetLocation, queued); + PerformMoveInner(self, targetLocation, false); } public void ResolveOrder(Actor self, Order order) @@ -278,9 +272,9 @@ namespace OpenRA.Mods.RA.Move } } - public int2 TopLeft { get { return toCell; } } + public CPos TopLeft { get { return toCell; } } - public IEnumerable> OccupiedCells() + public IEnumerable> OccupiedCells() { if (fromCell == toCell) yield return Pair.New(fromCell, fromSubCell); @@ -293,7 +287,7 @@ namespace OpenRA.Mods.RA.Move } } - public SubCell GetDesiredSubcell(int2 a, Actor ignoreActor) + public SubCell GetDesiredSubcell(CPos a, Actor ignoreActor) { if (!Info.SharesCell) return SubCell.FullCell; @@ -303,7 +297,7 @@ namespace OpenRA.Mods.RA.Move SubCell.BottomLeft, SubCell.BottomRight}.First(b => { var blockingActors = self.World.ActorMap.GetUnitsAt(a,b).Where(c => c != ignoreActor); - if (blockingActors.Count() > 0) + if (blockingActors.Any()) { // Non-sharable unit can enter a cell with shareable units only if it can crush all of them if (Info.Crushes == null) @@ -317,12 +311,12 @@ namespace OpenRA.Mods.RA.Move }); } - public bool CanEnterCell(int2 p) + public bool CanEnterCell(CPos p) { return CanEnterCell(p, null, true); } - public bool CanEnterCell(int2 cell, Actor ignoreActor, bool checkTransientActors) + public bool CanEnterCell(CPos cell, Actor ignoreActor, bool checkTransientActors) { return Info.CanEnterCell(self.World, self.Owner, cell, ignoreActor, checkTransientActors); } @@ -349,7 +343,7 @@ namespace OpenRA.Mods.RA.Move } } - public int MovementSpeedForCell(Actor self, int2 cell) + public int MovementSpeedForCell(Actor self, CPos cell) { var type = self.World.GetTerrainType(cell); @@ -385,13 +379,13 @@ namespace OpenRA.Mods.RA.Move return; /* don't nudge if we're busy doing something! */ // pick an adjacent available cell. - var availCells = new List(); - var notStupidCells = new List(); + var availCells = new List(); + var notStupidCells = new List(); for (var i = -1; i < 2; i++) for (var j = -1; j < 2; j++) { - var p = toCell + new int2(i, j); + var p = toCell + new CVec(i, j); if (CanEnterCell(p)) availCells.Add(p); else @@ -400,7 +394,7 @@ namespace OpenRA.Mods.RA.Move } var moveTo = availCells.Any() ? availCells.Random(self.World.SharedRandom) : - notStupidCells.Any() ? notStupidCells.Random(self.World.SharedRandom) : (int2?)null; + notStupidCells.Any() ? notStupidCells.Random(self.World.SharedRandom) : (CPos?)null; if (moveTo.HasValue) { @@ -434,7 +428,7 @@ namespace OpenRA.Mods.RA.Move return false; } - public bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) + public bool CanTargetLocation(Actor self, CPos location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) { IsQueued = forceQueued; cursor = "move"; @@ -446,10 +440,10 @@ namespace OpenRA.Mods.RA.Move } } - public Activity ScriptedMove(int2 cell) { return new Move(cell); } - public Activity MoveTo(int2 cell, int nearEnough) { return new Move(cell, nearEnough); } - public Activity MoveTo(int2 cell, Actor ignoredActor) { return new Move(cell, ignoredActor); } + public Activity ScriptedMove(CPos cell) { return new Move(cell); } + public Activity MoveTo(CPos cell, int nearEnough) { return new Move(cell, nearEnough); } + public Activity MoveTo(CPos cell, Actor ignoredActor) { return new Move(cell, ignoredActor); } public Activity MoveWithinRange(Target target, int range) { return new Move(target, range); } - public Activity MoveTo(Func> pathFunc) { return new Move(pathFunc); } + public Activity MoveTo(Func> pathFunc) { return new Move(pathFunc); } } } diff --git a/OpenRA.Mods.RA/Move/Move.cs b/OpenRA.Mods.RA/Move/Move.cs index 15d090d3c4..1d95370079 100755 --- a/OpenRA.Mods.RA/Move/Move.cs +++ b/OpenRA.Mods.RA/Move/Move.cs @@ -20,15 +20,15 @@ namespace OpenRA.Mods.RA.Move { class Move : Activity { - int2? destination; + CPos? destination; int nearEnough; - public List path; - Func> getPath; + public List path; + Func> getPath; public Actor ignoreBuilding; // Scriptable move order // Ignores lane bias and nearby units - public Move( int2 destination ) + public Move(CPos destination) { this.getPath = (self,mobile) => self.World.WorldActor.Trait().FindPath( @@ -38,14 +38,14 @@ namespace OpenRA.Mods.RA.Move this.nearEnough = 0; } - public Move( int2 destination, int nearEnough ) + public Move(CPos destination, int nearEnough) { this.getPath = (self,mobile) => self.World.WorldActor.Trait().FindUnitPath( mobile.toCell, destination, self ); this.destination = destination; this.nearEnough = nearEnough; } - public Move(int2 destination, Actor ignoreBuilding) + public Move(CPos destination, Actor ignoreBuilding) { this.getPath = (self,mobile) => self.World.WorldActor.Trait().FindPath( @@ -60,13 +60,13 @@ namespace OpenRA.Mods.RA.Move public Move(Target target, int range) { this.getPath = (self,mobile) => self.World.WorldActor.Trait().FindUnitPathToRange( - mobile.toCell, Util.CellContaining(target.CenterLocation), + mobile.toCell, target.CenterLocation.ToCPos(), range, self); this.destination = null; this.nearEnough = range; } - public Move(Func> getPath) + public Move(Func> getPath) { this.getPath = (_1,_2) => getPath(); this.destination = null; @@ -83,7 +83,7 @@ namespace OpenRA.Mods.RA.Move return hash; } - List EvalPath( Actor self, Mobile mobile ) + List EvalPath(Actor self, Mobile mobile) { var path = getPath(self, mobile).TakeWhile(a => a != mobile.toCell).ToList(); mobile.PathHash = HashList(path); @@ -131,7 +131,7 @@ namespace OpenRA.Mods.RA.Move if( nextCell == null ) return this; - int2 dir = nextCell.Value.First - mobile.fromCell; + var dir = nextCell.Value.First - mobile.fromCell; var firstFacing = Util.GetFacing( dir, mobile.Facing ); if( firstFacing != mobile.Facing ) { @@ -167,7 +167,7 @@ namespace OpenRA.Mods.RA.Move bool hasNudged; int waitTicksRemaining; - void NudgeBlocker(Actor self, int2 nextCell) + void NudgeBlocker(Actor self, CPos nextCell) { var blocker = self.World.ActorMap.GetUnitsAt(nextCell).FirstOrDefault(); if (blocker == null) return; @@ -180,7 +180,7 @@ namespace OpenRA.Mods.RA.Move nudge.OnNudge(blocker, self, false); } - Pair? PopPath( Actor self, Mobile mobile ) + Pair? PopPath(Actor self, Mobile mobile) { if( path.Count == 0 ) return null; var nextCell = path[ path.Count - 1 ]; @@ -233,7 +233,7 @@ namespace OpenRA.Mods.RA.Move public override void Cancel( Actor self ) { - path = new List(); + path = new List(); base.Cancel(self); } @@ -242,19 +242,19 @@ namespace OpenRA.Mods.RA.Move if( path != null ) return Enumerable.Reverse(path).Select( c => Target.FromCell(c) ); if( destination != null ) - return new Target[] { Target.FromPos(destination.Value) }; + return new Target[] { Target.FromCell(destination.Value) }; return Target.NoTargets; } abstract class MovePart : Activity { public readonly Move move; - public readonly int2 from, to; + public readonly PPos 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, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction) { this.move = move; this.from = from; @@ -304,7 +304,7 @@ namespace OpenRA.Mods.RA.Move void UpdateCenterLocation( Actor self, Mobile mobile ) { - mobile.PxPosition = int2.Lerp( from, to, moveFraction, moveFractionTotal ); + mobile.PxPosition = PPos.Lerp(from, to, moveFraction, moveFractionTotal); if( moveFraction >= moveFractionTotal ) mobile.Facing = toFacing & 0xFF; @@ -322,10 +322,10 @@ namespace OpenRA.Mods.RA.Move class MoveFirstHalf : MovePart { - public MoveFirstHalf( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction ) + public MoveFirstHalf(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction) : base( move, from, to, fromFacing, toFacing, startingFraction ) { } - static bool IsTurn( Mobile mobile, int2 nextCell ) + static bool IsTurn( Mobile mobile, CPos nextCell ) { return nextCell - mobile.toCell != mobile.toCell - mobile.fromCell; @@ -373,7 +373,7 @@ namespace OpenRA.Mods.RA.Move class MoveSecondHalf : MovePart { - public MoveSecondHalf( Move move, int2 from, int2 to, int fromFacing, int toFacing, int startingFraction ) + public MoveSecondHalf(Move move, PPos from, PPos to, int fromFacing, int toFacing, int startingFraction) : base( move, from, to, fromFacing, toFacing, startingFraction ) { } diff --git a/OpenRA.Mods.RA/Move/PathFinder.cs b/OpenRA.Mods.RA/Move/PathFinder.cs index b12e25a26e..b1d0033985 100755 --- a/OpenRA.Mods.RA/Move/PathFinder.cs +++ b/OpenRA.Mods.RA/Move/PathFinder.cs @@ -29,9 +29,9 @@ namespace OpenRA.Mods.RA.Move class CachedPath { - public int2 from; - public int2 to; - public List result; + public CPos from; + public CPos to; + public List result; public int tick; public Actor actor; } @@ -39,7 +39,7 @@ namespace OpenRA.Mods.RA.Move List CachedPaths = new List(); const int MaxPathAge = 50; /* x 40ms ticks */ - public List FindUnitPath(int2 from, int2 target, Actor self) + public List FindUnitPath(CPos from, CPos target, Actor self) { using (new PerfSample("Pathfinder")) { @@ -48,25 +48,25 @@ namespace OpenRA.Mods.RA.Move { Log.Write("debug", "Actor {0} asked for a path from {1} tick(s) ago", self.ActorID, world.FrameNumber - cached.tick); cached.tick = world.FrameNumber; - return new List(cached.result); + return new List(cached.result); } var mi = self.Info.Traits.Get(); var pb = FindBidiPath( PathSearch.FromPoint(world, mi, self.Owner, target, from, true), - PathSearch.FromPoint(world, mi, self.Owner, from, target, true) - .InReverse()); + PathSearch.FromPoint(world, mi, self.Owner, from, target, true).InReverse() + ); CheckSanePath2(pb, from, target); CachedPaths.RemoveAll(p => world.FrameNumber - p.tick > MaxPathAge); CachedPaths.Add(new CachedPath { from = from, to = target, actor = self, result = pb, tick = world.FrameNumber }); - return new List(pb); + return new List(pb); } } - public List FindUnitPathToRange( int2 src, int2 target, int range, Actor self ) + public List FindUnitPathToRange(CPos src, CPos target, int range, Actor self) { using( new PerfSample( "Pathfinder" ) ) { @@ -76,18 +76,18 @@ namespace OpenRA.Mods.RA.Move var path = FindBidiPath( PathSearch.FromPoints(world, mi, self.Owner, tilesInRange, src, true), - PathSearch.FromPoint(world, mi, self.Owner, src, target, true) - .InReverse()); + PathSearch.FromPoint(world, mi, self.Owner, src, target, true).InReverse() + ); return path; } } - public List FindPath( PathSearch search ) + public List FindPath(PathSearch search) { using (new PerfSample("Pathfinder")) { - using(search) + using (search) while (!search.queue.Empty) { var p = search.Expand(world); @@ -96,14 +96,14 @@ namespace OpenRA.Mods.RA.Move } // no path exists - return new List(); + return new List(0); } } - static List MakePath( CellInfo[ , ] cellInfo, int2 destination ) + static List MakePath(CellInfo[,] cellInfo, CPos destination) { - List ret = new List(); - int2 pathNode = destination; + var ret = new List(); + CPos pathNode = destination; while( cellInfo[ pathNode.X, pathNode.Y ].Path != pathNode ) { @@ -116,9 +116,7 @@ namespace OpenRA.Mods.RA.Move return ret; } - - - public List FindBidiPath( /* searches from both ends toward each other */ + public List FindBidiPath( /* searches from both ends toward each other */ PathSearch fromSrc, PathSearch fromDest) { @@ -141,16 +139,16 @@ namespace OpenRA.Mods.RA.Move return MakeBidiPath(fromSrc, fromDest, q); } - return new List(); + return new List(0); } } - static List MakeBidiPath(PathSearch a, PathSearch b, int2 p) + static List MakeBidiPath(PathSearch a, PathSearch b, CPos p) { var ca = a.cellInfo; var cb = b.cellInfo; - var ret = new List(); + var ret = new List(); var q = p; while (ca[q.X, q.Y].Path != q) @@ -174,7 +172,7 @@ namespace OpenRA.Mods.RA.Move } [Conditional( "SANITY_CHECKS" )] - static void CheckSanePath( List path ) + static void CheckSanePath(List path) { if( path.Count == 0 ) return; @@ -189,7 +187,7 @@ namespace OpenRA.Mods.RA.Move } [Conditional("SANITY_CHECKS")] - static void CheckSanePath2(List path, int2 src, int2 dest) + static void CheckSanePath2(List path, CPos src, CPos dest) { if (path.Count == 0) return; @@ -204,10 +202,10 @@ namespace OpenRA.Mods.RA.Move public struct CellInfo { public int MinCost; - public int2 Path; + public CPos Path; public bool Seen; - public CellInfo( int minCost, int2 path, bool seen ) + public CellInfo(int minCost, CPos path, bool seen) { MinCost = minCost; Path = path; @@ -218,9 +216,9 @@ namespace OpenRA.Mods.RA.Move public struct PathDistance : IComparable { public int EstTotal; - public int2 Location; + public CPos Location; - public PathDistance(int estTotal, int2 location) + public PathDistance(int estTotal, CPos location) { EstTotal = estTotal; Location = location; diff --git a/OpenRA.Mods.RA/Move/PathSearch.cs b/OpenRA.Mods.RA/Move/PathSearch.cs index feb7e2b885..04e0348e9d 100755 --- a/OpenRA.Mods.RA/Move/PathSearch.cs +++ b/OpenRA.Mods.RA/Move/PathSearch.cs @@ -20,8 +20,8 @@ namespace OpenRA.Mods.RA.Move World world; public CellInfo[ , ] cellInfo; public PriorityQueue queue; - public Func heuristic; - Func customBlock; + public Func heuristic; + Func customBlock; public bool checkForBlocked; public Actor ignoreBuilding; public bool inReverse; @@ -44,7 +44,7 @@ namespace OpenRA.Mods.RA.Move return this; } - public PathSearch WithCustomBlocker(Func customBlock) + public PathSearch WithCustomBlocker(Func customBlock) { this.customBlock = customBlock; return this; @@ -56,7 +56,7 @@ namespace OpenRA.Mods.RA.Move return this; } - public PathSearch WithHeuristic(Func h) + public PathSearch WithHeuristic(Func h) { heuristic = h; return this; @@ -68,7 +68,7 @@ namespace OpenRA.Mods.RA.Move return this; } - public PathSearch FromPoint(int2 from) + public PathSearch FromPoint(CPos from) { AddInitialCell( from ); return this; @@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA.Move int LaneBias = 1; - public int2 Expand( World world ) + public CPos Expand(World world) { var p = queue.Pop(); while (cellInfo[p.Location.X, p.Location.Y].Seen) @@ -92,9 +92,9 @@ namespace OpenRA.Mods.RA.Move if (thisCost == int.MaxValue) return p.Location; - foreach( int2 d in directions ) + foreach( CVec d in directions ) { - int2 newHere = p.Location + d; + CPos newHere = p.Location + d; if (!world.Map.IsInMap(newHere.X, newHere.Y)) continue; if( cellInfo[ newHere.X, newHere.Y ].Seen ) @@ -141,19 +141,19 @@ namespace OpenRA.Mods.RA.Move return p.Location; } - static readonly int2[] directions = + static readonly CVec[] directions = { - new int2( -1, -1 ), - new int2( -1, 0 ), - new int2( -1, 1 ), - new int2( 0, -1 ), - new int2( 0, 1 ), - new int2( 1, -1 ), - new int2( 1, 0 ), - new int2( 1, 1 ), + new CVec( -1, -1 ), + new CVec( -1, 0 ), + new CVec( -1, 1 ), + new CVec( 0, -1 ), + new CVec( 0, 1 ), + new CVec( 1, -1 ), + new CVec( 1, 0 ), + new CVec( 1, 1 ), }; - public void AddInitialCell( int2 location ) + public void AddInitialCell(CPos location) { if (!world.Map.IsInMap(location.X, location.Y)) return; @@ -169,7 +169,7 @@ namespace OpenRA.Mods.RA.Move return search; } - public static PathSearch FromPoint( World world, MobileInfo mi, Player owner, int2 from, int2 target, bool checkForBlocked ) + public static PathSearch FromPoint(World world, MobileInfo mi, Player owner, CPos from, CPos target, bool checkForBlocked) { var search = new PathSearch(world, mi, owner) { heuristic = DefaultEstimator( target ), @@ -179,7 +179,7 @@ namespace OpenRA.Mods.RA.Move return search; } - public static PathSearch FromPoints(World world, MobileInfo mi, Player owner, IEnumerable froms, int2 target, bool checkForBlocked) + public static PathSearch FromPoints(World world, MobileInfo mi, Player owner, IEnumerable froms, CPos target, bool checkForBlocked) { var search = new PathSearch(world, mi, owner) { @@ -229,16 +229,16 @@ namespace OpenRA.Mods.RA.Move for( int x = 0 ; x < world.Map.MapSize.X ; x++ ) for( int y = 0 ; y < world.Map.MapSize.Y ; y++ ) - result[ x, y ] = new CellInfo( int.MaxValue, new int2( x, y ), false ); + result[ x, y ] = new CellInfo( int.MaxValue, new CPos( x, y ), false ); return result; } - public static Func DefaultEstimator( int2 destination ) + public static Func DefaultEstimator(CPos destination) { return here => { - int2 d = ( here - destination ).Abs(); + CVec d = (here - destination).Abs(); int diag = Math.Min( d.X, d.Y ); int straight = Math.Abs( d.X - d.Y ); return (3400 * diag / 24) + (100 * straight); diff --git a/OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs b/OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs index 3c73c69e1b..35b1354213 100755 --- a/OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs +++ b/OpenRA.Mods.RA/Orders/DeployOrderTargeter.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Orders return self == target; } - public bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) + public bool CanTargetLocation(Actor self, CPos location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) { return false; } diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index 769eeb3cb5..5367ccc611 100755 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA.Orders buildBlocked = SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0); } - public IEnumerable Order(World world, int2 xy, MouseInput mi) + public IEnumerable Order(World world, CPos xy, MouseInput mi) { if (mi.Button == MouseButton.Right) world.CancelInputMode(); @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Orders return ret; } - IEnumerable InnerOrder(World world, int2 xy, MouseInput mi) + IEnumerable InnerOrder(World world, CPos xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { @@ -73,14 +73,14 @@ namespace OpenRA.Mods.RA.Orders public void RenderAfterWorld( WorldRenderer wr, World world ) {} public void RenderBeforeWorld( WorldRenderer wr, World world ) { - var position = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2(); + var position = Game.viewport.ViewToWorld(Viewport.LastMousePos); var topLeft = position - FootprintUtils.AdjustForBuildingSize( BuildingInfo ); var actorInfo = Rules.Info[Building]; foreach (var dec in actorInfo.Traits.WithInterface()) dec.Render(wr, world, actorInfo, Traits.Util.CenterOfCell(position)); /* hack hack */ - var cells = new Dictionary(); + var cells = new Dictionary(); // Linebuild for walls. // Assumes a 1x1 footprint; weird things will happen for other footprints if (Rules.Info[Building].Traits.Contains()) @@ -91,7 +91,7 @@ namespace OpenRA.Mods.RA.Orders else { foreach (var r in Preview) - r.Sprite.DrawAt(Game.CellSize*topLeft + r.Pos, + r.Sprite.DrawAt(topLeft.ToPPos().ToFloat2() + r.Pos, wr.GetPaletteIndex(r.Palette), r.Scale*r.Sprite.size); @@ -102,9 +102,9 @@ namespace OpenRA.Mods.RA.Orders } foreach( var c in cells ) - ( c.Value ? buildOk : buildBlocked ).DrawAt( wr, Game.CellSize * c.Key, "terrain" ); + ( c.Value ? buildOk : buildBlocked ).DrawAt(wr, c.Key.ToPPos().ToFloat2(), "terrain" ); } - public string GetCursor(World world, int2 xy, MouseInput mi) { return "default"; } + public string GetCursor(World world, CPos xy, MouseInput mi) { return "default"; } } } diff --git a/OpenRA.Mods.RA/Orders/PowerDownOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PowerDownOrderGenerator.cs index 3dcf38a460..a56769227c 100755 --- a/OpenRA.Mods.RA/Orders/PowerDownOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PowerDownOrderGenerator.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Orders this.order = order; } - public IEnumerable Order(World world, int2 xy, MouseInput mi) + public IEnumerable Order(World world, CPos xy, MouseInput mi) { if (mi.Button == MouseButton.Right) world.CancelInputMode(); @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Orders return OrderInner(world, xy, mi); } - IEnumerable OrderInner(World world, int2 xy, MouseInput mi) + IEnumerable OrderInner(World world, CPos xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { @@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA.Orders public void RenderAfterWorld(WorldRenderer wr, World world) { } public void RenderBeforeWorld(WorldRenderer wr, World world) { } - public string GetCursor(World world, int2 xy, MouseInput mi) + public string GetCursor(World world, CPos xy, MouseInput mi) { mi.Button = MouseButton.Left; return cursor + (OrderInner(world, xy, mi).Any() ? "" : "-blocked"); diff --git a/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs b/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs index cbbf16e54c..1b6745752b 100644 --- a/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/RepairOrderGenerator.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA.Orders { public class RepairOrderGenerator : IOrderGenerator { - public IEnumerable Order(World world, int2 xy, MouseInput mi) + public IEnumerable Order(World world, CPos xy, MouseInput mi) { if (mi.Button == MouseButton.Right) world.CancelInputMode(); @@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Orders return OrderInner(world, xy, mi); } - IEnumerable OrderInner(World world, int2 xy, MouseInput mi) + IEnumerable OrderInner(World world, CPos xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { @@ -52,7 +52,7 @@ namespace OpenRA.Mods.RA.Orders public void RenderAfterWorld(WorldRenderer wr, World world) { } public void RenderBeforeWorld(WorldRenderer wr, World world) { } - public string GetCursor(World world, int2 xy, MouseInput mi) + public string GetCursor(World world, CPos xy, MouseInput mi) { mi.Button = MouseButton.Left; return OrderInner(world, xy, mi).Any() diff --git a/OpenRA.Mods.RA/Orders/SetChronoTankDestination.cs b/OpenRA.Mods.RA/Orders/SetChronoTankDestination.cs index e59b6a38cf..20c8ee01cf 100644 --- a/OpenRA.Mods.RA/Orders/SetChronoTankDestination.cs +++ b/OpenRA.Mods.RA/Orders/SetChronoTankDestination.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Orders this.self = self; } - public IEnumerable Order(World world, int2 xy, MouseInput mi) + public IEnumerable Order(World world, CPos xy, MouseInput mi) { if (mi.Button == MouseButton.Left) { @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Orders public void RenderBeforeWorld( WorldRenderer wr, World world ) { } - public string GetCursor(World world, int2 xy, MouseInput mi) + public string GetCursor(World world, CPos xy, MouseInput mi) { if (!world.LocalPlayer.Shroud.IsExplored(xy)) return "move-blocked"; diff --git a/OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs b/OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs index 368d8adc09..5acf4d9b91 100755 --- a/OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs +++ b/OpenRA.Mods.RA/Orders/UnitOrderTargeter.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.RA.Orders return true; } - public virtual bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) + public virtual bool CanTargetLocation(Actor self, CPos location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) { return false; } diff --git a/OpenRA.Mods.RA/OreRefinery.cs b/OpenRA.Mods.RA/OreRefinery.cs index c35a63cc17..19e94a50dc 100644 --- a/OpenRA.Mods.RA/OreRefinery.cs +++ b/OpenRA.Mods.RA/OreRefinery.cs @@ -43,7 +43,7 @@ namespace OpenRA.Mods.RA [Sync] bool preventDock = false; public bool AllowDocking { get { return !preventDock; } } - public int2 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); } diff --git a/OpenRA.Mods.RA/ParaDrop.cs b/OpenRA.Mods.RA/ParaDrop.cs index 8eb87429de..1759c12cab 100644 --- a/OpenRA.Mods.RA/ParaDrop.cs +++ b/OpenRA.Mods.RA/ParaDrop.cs @@ -24,10 +24,10 @@ namespace OpenRA.Mods.RA public class ParaDrop : ITick { - readonly List droppedAt = new List(); - int2 lz; + readonly List droppedAt = new List(); + CPos lz; - public void SetLZ(int2 lz) + public void SetLZ(CPos lz) { this.lz = lz; droppedAt.Clear(); @@ -55,16 +55,19 @@ namespace OpenRA.Mods.RA var aircraft = self.Trait(); self.World.AddFrameEndTask(w => w.Add( - new Parachute(self.Owner, - Util.CenterOfCell(Util.CellContaining(self.CenterLocation)), - aircraft.Altitude, a))); + new Parachute( + self.Owner, + Util.CenterOfCell(self.CenterLocation.ToCPos()), + aircraft.Altitude, a + ) + )); Sound.Play(info.ChuteSound, self.CenterLocation); } } } - bool IsSuitableCell(Actor actorToDrop, int2 p) + bool IsSuitableCell(Actor actorToDrop, CPos p) { return actorToDrop.Trait().CanEnterCell(p); } diff --git a/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs b/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs index 00dfc1e916..021d106b06 100644 --- a/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs +++ b/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs @@ -28,7 +28,7 @@ namespace OpenRA.Mods.RA BaseAttackNotifierInfo info; public int lastAttackTime = -1; - public float2 lastAttackLocation; + public CPos lastAttackLocation; public BaseAttackNotifier(BaseAttackNotifierInfo info) { this.info = info; } @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA if (self.World.FrameNumber - lastAttackTime > info.NotifyInterval * 25) Sound.PlayToPlayer(self.Owner, info.Audio); - lastAttackLocation = self.CenterLocation / Game.CellSize; + lastAttackLocation = self.CenterLocation.ToCPos(); lastAttackTime = self.World.FrameNumber; } } diff --git a/OpenRA.Mods.RA/Player/ProductionQueue.cs b/OpenRA.Mods.RA/Player/ProductionQueue.cs index 43010b059f..d5fc343382 100755 --- a/OpenRA.Mods.RA/Player/ProductionQueue.cs +++ b/OpenRA.Mods.RA/Player/ProductionQueue.cs @@ -44,18 +44,12 @@ namespace OpenRA.Mods.RA // A list of things we are currently building public List Queue = new List(); - [Sync] - public int QueueLength { get { return Queue.Count; } } - [Sync] - public int CurrentRemainingCost { get { return QueueLength == 0 ? 0 : Queue[0].RemainingCost; } } - [Sync] - public int CurrentRemainingTime { get { return QueueLength == 0 ? 0 : Queue[0].RemainingTime; } } - [Sync] - public int CurrentSlowdown { get { return QueueLength == 0 ? 0 : Queue[0].slowdown; } } - [Sync] - public bool CurrentPaused { get { return QueueLength == 0 ? false : Queue[0].Paused; } } - [Sync] - public bool CurrentDone { get { return QueueLength == 0 ? false : Queue[0].Done; } } + [Sync] public int QueueLength { get { return Queue.Count; } } + [Sync] public int CurrentRemainingCost { get { return QueueLength == 0 ? 0 : Queue[0].RemainingCost; } } + [Sync] public int CurrentRemainingTime { get { return QueueLength == 0 ? 0 : Queue[0].RemainingTime; } } + [Sync] public int CurrentSlowdown { get { return QueueLength == 0 ? 0 : Queue[0].slowdown; } } + [Sync] public bool CurrentPaused { get { return QueueLength == 0 ? false : Queue[0].Paused; } } + [Sync] public bool CurrentDone { get { return QueueLength == 0 ? false : Queue[0].Done; } } // A list of things we could possibly build, even if our race doesn't normally get it public Dictionary Produceable; diff --git a/OpenRA.Mods.RA/Production.cs b/OpenRA.Mods.RA/Production.cs index 443dcf02a9..f92ade2f58 100755 --- a/OpenRA.Mods.RA/Production.cs +++ b/OpenRA.Mods.RA/Production.cs @@ -27,9 +27,12 @@ namespace OpenRA.Mods.RA public class ExitInfo : TraitInfo { - public readonly int2 SpawnOffset = int2.Zero; // in px relative to CenterLocation - public readonly int2 ExitCell = int2.Zero; // in cells relative to TopLeft + 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; + + public PVecInt SpawnOffsetVector { get { return (PVecInt)SpawnOffset; } } + public CVec ExitCellVector { get { return (CVec)ExitCell; } } } public class Exit {} @@ -48,8 +51,8 @@ namespace OpenRA.Mods.RA new OwnerInit( self.Owner ), }); - var exit = self.Location + exitinfo.ExitCell; - var spawn = self.Trait().PxPosition + exitinfo.SpawnOffset; + var exit = self.Location + exitinfo.ExitCellVector; + var spawn = self.Trait().PxPosition + exitinfo.SpawnOffsetVector; var teleportable = newUnit.Trait(); var facing = newUnit.TraitOrDefault(); @@ -78,7 +81,7 @@ namespace OpenRA.Mods.RA t.UnitProduced(self, newUnit, exit); } - static int2 MoveToRallyPoint(Actor self, Actor newUnit, int2 exitLocation) + static CPos MoveToRallyPoint(Actor self, Actor newUnit, CPos exitLocation) { var rp = self.TraitOrDefault(); if (rp == null) @@ -126,7 +129,7 @@ namespace OpenRA.Mods.RA var mobileInfo = producee.Traits.GetOrDefault(); return mobileInfo == null || - mobileInfo.CanEnterCell(self.World, self.Owner, self.Location + s.ExitCell, self, true); + mobileInfo.CanEnterCell(self.World, self.Owner, self.Location + s.ExitCellVector, self, true); } } } diff --git a/OpenRA.Mods.RA/RallyPoint.cs b/OpenRA.Mods.RA/RallyPoint.cs index 1c4d57b150..961646e572 100755 --- a/OpenRA.Mods.RA/RallyPoint.cs +++ b/OpenRA.Mods.RA/RallyPoint.cs @@ -23,12 +23,12 @@ namespace OpenRA.Mods.RA public class RallyPoint : IIssueOrder, IResolveOrder, ISync { - [Sync] public int2 rallyPoint; + [Sync] public CPos rallyPoint; public RallyPoint(Actor self) { var info = self.Info.Traits.Get(); - rallyPoint = self.Location + new int2(info.RallyPoint[0], info.RallyPoint[1]); + rallyPoint = self.Location + new CVec(info.RallyPoint[0], info.RallyPoint[1]); self.World.AddFrameEndTask(w => w.Add(new Effects.RallyPoint(self))); } @@ -40,7 +40,7 @@ namespace OpenRA.Mods.RA public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ) { if( order.OrderID == "SetRallyPoint" ) - return new Order(order.OrderID, self, false) { TargetLocation = Traits.Util.CellContaining(target.CenterLocation) }; + return new Order(order.OrderID, self, false) { TargetLocation = target.CenterLocation.ToCPos() }; return null; } @@ -61,7 +61,7 @@ namespace OpenRA.Mods.RA return false; } - public bool CanTargetLocation(Actor self, int2 location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) + public bool CanTargetLocation(Actor self, CPos location, List actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) { if (self.World.Map.IsInMap(location)) { diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWall.cs b/OpenRA.Mods.RA/Render/RenderBuildingWall.cs index 7feb201ae0..a31e5331e1 100644 --- a/OpenRA.Mods.RA/Render/RenderBuildingWall.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWall.cs @@ -56,8 +56,7 @@ namespace OpenRA.Mods.RA.Render if (!hasTicked) { - var oneCell = new int2(Game.CellSize, Game.CellSize); - var adjWalls = self.World.FindUnits(self.CenterLocation - oneCell, self.CenterLocation + oneCell) + var adjWalls = self.World.FindUnits(self.CenterLocation - PVecInt.OneCell, self.CenterLocation + PVecInt.OneCell) .Where(a => a.Info == self.Info && a != self); foreach (var w in adjWalls) @@ -69,12 +68,12 @@ namespace OpenRA.Mods.RA.Render } } - void AddAdjacentWall(int2 location, int2 otherLocation) + void AddAdjacentWall(CPos location, CPos otherLocation) { - if (otherLocation == location + new int2(0, -1)) adjacentWalls |= 1; - if (otherLocation == location + new int2(+1, 0)) adjacentWalls |= 2; - if (otherLocation == location + new int2(0, +1)) adjacentWalls |= 4; - if (otherLocation == location + new int2(-1, 0)) adjacentWalls |= 8; + if (otherLocation == location + new CVec(0, -1)) adjacentWalls |= 1; + if (otherLocation == location + new CVec(+1, 0)) adjacentWalls |= 2; + if (otherLocation == location + new CVec(0, +1)) adjacentWalls |= 4; + if (otherLocation == location + new CVec(-1, 0)) adjacentWalls |= 8; } } } diff --git a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs index f86b0cd55a..83a1d1e738 100755 --- a/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs +++ b/OpenRA.Mods.RA/Render/RenderBuildingWarFactory.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA.Render { Animation roof; [Sync] bool isOpen; - [Sync] int2 openExit; + [Sync] CPos openExit; bool buildComplete; public RenderBuildingWarFactory(ActorInitializer init, RenderBuildingInfo info) @@ -64,8 +64,7 @@ namespace OpenRA.Mods.RA.Render public override void Tick(Actor self) { base.Tick(self); - if (isOpen && !self.World.ActorMap.GetUnitsAt(openExit) - .Any( a => a != self )) + if (isOpen && !self.World.ActorMap.GetUnitsAt(openExit).Any( a => a != self )) { isOpen = false; roof.PlayBackwardsThen(NormalizeSequence(self, "build-top"), @@ -86,7 +85,7 @@ namespace OpenRA.Mods.RA.Render base.DamageStateChanged(self, e); } - public void UnitProduced(Actor self, Actor other, int2 exit) + public void UnitProduced(Actor self, Actor other, CPos exit) { roof.PlayThen(NormalizeSequence(self, "build-top"), () => { isOpen = true; openExit = exit; }); } diff --git a/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs b/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs index 87378d49b4..89573ea115 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitSpinner.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Render anims.Add("spinner", new AnimationWithOffset( spinnerAnim, - () => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)), + () => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)).ToFloat2(), null ) { ZOffset = 1 } ); } } diff --git a/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs b/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs index d1a996c4f4..665f35e608 100755 --- a/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs +++ b/OpenRA.Mods.RA/Render/RenderUnitTurreted.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Render var turret = attack.Turrets[i]; anims.Add( "turret_{0}".F(i), new AnimationWithOffset( turretAnim, - () => Combat.GetTurretPosition( self, facing, turret ), + () => Combat.GetTurretPosition( self, facing, turret ).ToFloat2(), null)); } } diff --git a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs index 00f5585ecb..aead118204 100644 --- a/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs +++ b/OpenRA.Mods.RA/Render/WithMuzzleFlash.cs @@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA.Render muzzleFlashes.Add("muzzle{0}".F(muzzleFlashes.Count), new AnimationWithOffset( muzzleFlash, - () => Combat.GetBarrelPosition(self, facing, turret, barrel), + () => Combat.GetBarrelPosition(self, facing, turret, barrel).ToFloat2(), () => !isShowing)); } } diff --git a/OpenRA.Mods.RA/Render/WithRotor.cs b/OpenRA.Mods.RA/Render/WithRotor.cs index d44cf2c38a..bb7ae40ddf 100755 --- a/OpenRA.Mods.RA/Render/WithRotor.cs +++ b/OpenRA.Mods.RA/Render/WithRotor.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Render rotorAnim.PlayRepeating("rotor"); rs.anims.Add(info.Id, new AnimationWithOffset( rotorAnim, - () => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)), + () => Combat.GetTurretPosition( self, facing, new Turret(info.Offset)).ToFloat2(), null ) { ZOffset = 1 } ); } diff --git a/OpenRA.Mods.RA/RenderDetectionCircle.cs b/OpenRA.Mods.RA/RenderDetectionCircle.cs index 30645533e4..b7846b0a4a 100644 --- a/OpenRA.Mods.RA/RenderDetectionCircle.cs +++ b/OpenRA.Mods.RA/RenderDetectionCircle.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA wr.DrawRangeCircle( Color.FromArgb(128, Color.LimeGreen), - self.CenterLocation, self.Info.Traits.Get().Range); + self.CenterLocation.ToFloat2(), self.Info.Traits.Get().Range); } } } diff --git a/OpenRA.Mods.RA/RenderRangeCircle.cs b/OpenRA.Mods.RA/RenderRangeCircle.cs index 21c79d931a..10e9192681 100644 --- a/OpenRA.Mods.RA/RenderRangeCircle.cs +++ b/OpenRA.Mods.RA/RenderRangeCircle.cs @@ -16,18 +16,18 @@ namespace OpenRA.Mods.RA { public interface IPlaceBuildingDecoration { - void Render(WorldRenderer wr, World w, ActorInfo ai, int2 centerLocation); + void Render(WorldRenderer wr, World w, ActorInfo ai, PPos centerLocation); } class RenderRangeCircleInfo : TraitInfo, IPlaceBuildingDecoration { public readonly string RangeCircleType = null; - public void Render(WorldRenderer wr, World w, ActorInfo ai, int2 centerLocation) + public void Render(WorldRenderer wr, World w, ActorInfo ai, PPos centerLocation) { wr.DrawRangeCircle( Color.FromArgb(128, Color.Yellow), - centerLocation, + centerLocation.ToFloat2(), ai.Traits.Get().GetMaximumRange()); foreach (var a in w.ActorsWithTrait()) @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA wr.DrawRangeCircle( Color.FromArgb(128, Color.Yellow), - self.CenterLocation, (int)self.Trait().GetMaximumRange()); + self.CenterLocation.ToFloat2(), (int)self.Trait().GetMaximumRange()); } } } diff --git a/OpenRA.Mods.RA/RenderShroudCircle.cs b/OpenRA.Mods.RA/RenderShroudCircle.cs index 738942fe10..7ed26059a2 100644 --- a/OpenRA.Mods.RA/RenderShroudCircle.cs +++ b/OpenRA.Mods.RA/RenderShroudCircle.cs @@ -16,11 +16,11 @@ namespace OpenRA.Mods.RA { class RenderShroudCircleInfo : TraitInfo, IPlaceBuildingDecoration { - public void Render(WorldRenderer wr, World w, ActorInfo ai, int2 centerLocation) + public void Render(WorldRenderer wr, World w, ActorInfo ai, PPos centerLocation) { wr.DrawRangeCircle( Color.FromArgb(128, Color.Cyan), - centerLocation, + centerLocation.ToFloat2(), ai.Traits.Get().Range); foreach (var a in w.ActorsWithTrait()) @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA wr.DrawRangeCircle( Color.FromArgb(128, Color.Cyan), - self.CenterLocation, (int)self.Info.Traits.Get().Range); + self.CenterLocation.ToFloat2(), (int)self.Info.Traits.Get().Range); } } } diff --git a/OpenRA.Mods.RA/Repairable.cs b/OpenRA.Mods.RA/Repairable.cs index f29e2a2438..9137a95360 100644 --- a/OpenRA.Mods.RA/Repairable.cs +++ b/OpenRA.Mods.RA/Repairable.cs @@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA self.CancelActivity(); self.QueueActivity(new MoveAdjacentTo(target)); - self.QueueActivity(mobile.MoveTo(Traits.Util.CellContaining(order.TargetActor.CenterLocation), order.TargetActor)); + self.QueueActivity(mobile.MoveTo(order.TargetActor.CenterLocation.ToCPos(), order.TargetActor)); self.QueueActivity(new Rearm(self)); self.QueueActivity(new Repair(order.TargetActor)); diff --git a/OpenRA.Mods.RA/ScaredyCat.cs b/OpenRA.Mods.RA/ScaredyCat.cs index ed9e0d5230..45e534f068 100644 --- a/OpenRA.Mods.RA/ScaredyCat.cs +++ b/OpenRA.Mods.RA/ScaredyCat.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA { if (!Panicked) return; - var target = Util.SubPxVector[self.World.SharedRandom.Next(255)]* Info.MoveRadius / 1024 + self.Location; + var target = (CVec)( Util.SubPxVector[self.World.SharedRandom.Next(255)] * Info.MoveRadius / 1024 ) + self.Location; self.Trait().ResolveOrder(self, new Order("Move", self, false) { TargetLocation = target }); } diff --git a/OpenRA.Mods.RA/Scripting/RASpecialPowers.cs b/OpenRA.Mods.RA/Scripting/RASpecialPowers.cs index 9bbe3865a9..0cb8c4d09a 100644 --- a/OpenRA.Mods.RA/Scripting/RASpecialPowers.cs +++ b/OpenRA.Mods.RA/Scripting/RASpecialPowers.cs @@ -18,7 +18,7 @@ namespace OpenRA.Scripting { public class RASpecialPowers { - public static void Chronoshift(World world, List>units, Actor chronosphere, int duration, bool killCargo) + public static void Chronoshift(World world, List> units, Actor chronosphere, int duration, bool killCargo) { if (chronosphere != null) chronosphere.Trait().PlayCustomAnim(chronosphere, "active"); diff --git a/OpenRA.Mods.RA/SeedsResource.cs b/OpenRA.Mods.RA/SeedsResource.cs index efc6d5c425..70ab7ad172 100644 --- a/OpenRA.Mods.RA/SeedsResource.cs +++ b/OpenRA.Mods.RA/SeedsResource.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA var cell = RandomWalk(self.Location, self.World.SharedRandom) .Take(info.MaxRange) .SkipWhile(p => resLayer.GetResource(p) == resourceType && resLayer.IsFull(p.X, p.Y)) - .Cast().FirstOrDefault(); + .Cast().FirstOrDefault(); if (cell != null && self.World.Map.IsInMap(cell.Value) && (resLayer.GetResource(cell.Value) == resourceType @@ -64,7 +64,7 @@ namespace OpenRA.Mods.RA } } - static IEnumerable RandomWalk(int2 p, Thirdparty.Random r) + static IEnumerable RandomWalk(CPos p, Thirdparty.Random r) { for (; ; ) { @@ -74,8 +74,7 @@ namespace OpenRA.Mods.RA if (dx == 0 && dy == 0) continue; - p.X += dx; - p.Y += dy; + p += new CVec(dx, dy); yield return p; } } diff --git a/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs b/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs index ed30c7ecd8..58f48a8e82 100644 --- a/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs +++ b/OpenRA.Mods.RA/SmokeTrailWhenDamaged.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA class SmokeTrailWhenDamaged : ITick { Turret smokeTurret; - int2 position; + PPos position; int interval; int ticks; @@ -42,10 +42,10 @@ namespace OpenRA.Mods.RA if (move.Altitude > 0 && self.GetDamageState() >= DamageState.Heavy) { var facing = self.Trait(); - var altitude = new int2(0, move.Altitude); - position = (self.CenterLocation - Combat.GetTurretPosition(self, facing, smokeTurret)).ToInt2(); + var altitude = new PVecInt(0, move.Altitude); + position = (self.CenterLocation - Combat.GetTurretPosition(self, facing, smokeTurret)); - if (self.World.LocalShroud.IsVisible(Util.CellContaining(position))) + if (self.World.LocalShroud.IsVisible(position.ToCPos())) self.World.AddFrameEndTask( w => w.Add(new Smoke(w, position - altitude, "smokey"))); } diff --git a/OpenRA.Mods.RA/SpawnMPUnits.cs b/OpenRA.Mods.RA/SpawnMPUnits.cs index d7a02e47af..061779499c 100644 --- a/OpenRA.Mods.RA/SpawnMPUnits.cs +++ b/OpenRA.Mods.RA/SpawnMPUnits.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA SpawnUnitsForPlayer(s.Key, s.Value); } - void SpawnUnitsForPlayer(Player p, int2 sp) + void SpawnUnitsForPlayer(Player p, CPos sp) { if (!p.PlayerReference.DefaultStartingUnits) return; /* they don't want an mcv, the map provides something else for them */ diff --git a/OpenRA.Mods.RA/StoresOre.cs b/OpenRA.Mods.RA/StoresOre.cs index ece2241db1..569b619154 100644 --- a/OpenRA.Mods.RA/StoresOre.cs +++ b/OpenRA.Mods.RA/StoresOre.cs @@ -25,8 +25,7 @@ namespace OpenRA.Mods.RA { readonly StoresOreInfo Info; - [Sync] - public int Stored { get { return Player.OreCapacity == 0 ? 0 : Info.Capacity * Player.Ore / Player.OreCapacity; } } + [Sync] public int Stored { get { return Player.OreCapacity == 0 ? 0 : Info.Capacity * Player.Ore / Player.OreCapacity; } } PlayerResources Player; public StoresOre(Actor self, StoresOreInfo info) diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index e4d4e76c61..e3b85e08c8 100755 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -45,12 +45,12 @@ namespace OpenRA.Mods.RA foreach (var a in self.World.ActorsWithTrait()) a.Trait.Enable(); - Sound.Play("chrono2.aud", Game.CellSize * order.TargetLocation); - Sound.Play("chrono2.aud", Game.CellSize * order.ExtraLocation); + Sound.Play("chrono2.aud", order.TargetLocation.ToPPos()); + Sound.Play("chrono2.aud", order.ExtraLocation.ToPPos()); foreach (var target in UnitsInRange(order.ExtraLocation)) { var cs = target.Trait(); - var targetCell = target.Location + order.TargetLocation - order.ExtraLocation; + var targetCell = target.Location + (order.TargetLocation - order.ExtraLocation); var cpi = Info as ChronoshiftPowerInfo; if (cs.CanChronoshiftTo(target, targetCell, true)) @@ -59,7 +59,7 @@ namespace OpenRA.Mods.RA } } - public IEnumerable UnitsInRange(int2 xy) + public IEnumerable UnitsInRange(CPos xy) { int range = (Info as ChronoshiftPowerInfo).Range; var tiles = self.World.FindTilesInCircle(xy, range); @@ -87,7 +87,7 @@ namespace OpenRA.Mods.RA tile = SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0); } - public IEnumerable Order(World world, int2 xy, MouseInput mi) + public IEnumerable Order(World world, CPos xy, MouseInput mi) { world.CancelInputMode(); if (mi.Button == MouseButton.Left) @@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA public void RenderAfterWorld(WorldRenderer wr, World world) { - var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2(); + var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos); var targetUnits = power.UnitsInRange(xy); foreach (var unit in targetUnits) wr.DrawSelectionBox(unit, Color.Red); @@ -113,13 +113,13 @@ namespace OpenRA.Mods.RA public void RenderBeforeWorld(WorldRenderer wr, World world) { - var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2(); + var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos); var tiles = world.FindTilesInCircle(xy, range); foreach (var t in tiles) - tile.DrawAt( wr, Game.CellSize * t, "terrain" ); + tile.DrawAt( wr, t.ToPPos().ToFloat2(), "terrain" ); } - public string GetCursor(World world, int2 xy, MouseInput mi) + public string GetCursor(World world, CPos xy, MouseInput mi) { return "chrono-select"; } @@ -128,13 +128,13 @@ namespace OpenRA.Mods.RA class SelectDestination : IOrderGenerator { readonly ChronoshiftPower power; - readonly int2 sourceLocation; + readonly CPos sourceLocation; readonly int range; readonly Sprite validTile, invalidTile, sourceTile; readonly SupportPowerManager manager; readonly string order; - public SelectDestination(string order, SupportPowerManager manager, ChronoshiftPower power, int2 sourceLocation) + public SelectDestination(string order, SupportPowerManager manager, ChronoshiftPower power, CPos sourceLocation) { this.manager = manager; this.order = order; @@ -147,7 +147,7 @@ namespace OpenRA.Mods.RA sourceTile = SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0); } - public IEnumerable Order(World world, int2 xy, MouseInput mi) + public IEnumerable Order(World world, CPos xy, MouseInput mi) { if (mi.Button == MouseButton.Right) { @@ -163,7 +163,7 @@ namespace OpenRA.Mods.RA yield return ret; } - IEnumerable OrderInner(World world, int2 xy, MouseInput mi) + IEnumerable OrderInner(World world, CPos xy, MouseInput mi) { // Cannot chronoshift into unexplored location if (IsValidTarget(xy)) @@ -189,22 +189,22 @@ namespace OpenRA.Mods.RA public void RenderBeforeWorld(WorldRenderer wr, World world) { - var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2(); + var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos); // Source tiles foreach (var t in world.FindTilesInCircle(sourceLocation, range)) - sourceTile.DrawAt( wr, Game.CellSize * t, "terrain" ); + sourceTile.DrawAt( wr, t.ToPPos().ToFloat2(), "terrain" ); // Destination tiles foreach (var t in world.FindTilesInCircle(xy, range)) - sourceTile.DrawAt( wr, Game.CellSize * t, "terrain" ); + sourceTile.DrawAt( wr, t.ToPPos().ToFloat2(), "terrain" ); // Unit previews foreach (var unit in power.UnitsInRange(sourceLocation)) { - var targetCell = unit.Location + xy - sourceLocation; + var targetCell = unit.Location + (xy - sourceLocation); foreach (var r in unit.Render()) - r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location) + Traits.Util.CenterOfCell(targetCell), + r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location).ToFloat2() + Traits.Util.CenterOfCell(targetCell).ToFloat2(), wr.GetPaletteIndex(r.Palette), r.Scale*r.Sprite.size); } @@ -212,19 +212,19 @@ namespace OpenRA.Mods.RA // Unit tiles foreach (var unit in power.UnitsInRange(sourceLocation)) { - var targetCell = unit.Location + xy - sourceLocation; + var targetCell = unit.Location + (xy - sourceLocation); var canEnter = unit.Trait().CanChronoshiftTo(unit,targetCell, false); var tile = canEnter ? validTile : invalidTile; - tile.DrawAt( wr, Game.CellSize * targetCell, "terrain" ); + tile.DrawAt( wr, targetCell.ToPPos().ToFloat2(), "terrain" ); } } - bool IsValidTarget(int2 xy) + bool IsValidTarget(CPos xy) { var canTeleport = false; foreach (var unit in power.UnitsInRange(sourceLocation)) { - var targetCell = unit.Location + xy - sourceLocation; + var targetCell = unit.Location + (xy - sourceLocation); if (unit.Trait().CanChronoshiftTo(unit,targetCell, false)) { canTeleport = true; @@ -234,7 +234,7 @@ namespace OpenRA.Mods.RA return canTeleport; } - public string GetCursor(World world, int2 xy, MouseInput mi) + public string GetCursor(World world, CPos xy, MouseInput mi) { return IsValidTarget(xy) ? "chrono-target" : "move-blocked"; } diff --git a/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs b/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs index 9f64ff2784..b817ec938e 100755 --- a/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/IronCurtainPower.cs @@ -39,12 +39,12 @@ namespace OpenRA.Mods.RA { self.Trait().PlayCustomAnim(self, "active"); - Sound.Play("ironcur9.aud", Game.CellSize * order.TargetLocation); + Sound.Play("ironcur9.aud", order.TargetLocation.ToPPos()); foreach (var target in UnitsInRange(order.TargetLocation)) target.Trait().Activate(target, (Info as IronCurtainPowerInfo).Duration * 25); } - public IEnumerable UnitsInRange(int2 xy) + public IEnumerable UnitsInRange(CPos xy) { int range = (Info as IronCurtainPowerInfo).Range; var tiles = self.World.FindTilesInCircle(xy, range); @@ -72,7 +72,7 @@ namespace OpenRA.Mods.RA tile = SequenceProvider.GetSequence("overlay", "target-select").GetSprite(0); } - public IEnumerable Order(World world, int2 xy, MouseInput mi) + public IEnumerable Order(World world, CPos xy, MouseInput mi) { world.CancelInputMode(); if (mi.Button == MouseButton.Left && power.UnitsInRange(xy).Any()) @@ -88,19 +88,19 @@ namespace OpenRA.Mods.RA public void RenderAfterWorld(WorldRenderer wr, World world) { - var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2(); + var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos); foreach (var unit in power.UnitsInRange(xy)) wr.DrawSelectionBox(unit, Color.Red); } public void RenderBeforeWorld(WorldRenderer wr, World world) { - var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2(); + var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos); foreach (var t in world.FindTilesInCircle(xy, range)) - tile.DrawAt( wr, Game.CellSize * t, "terrain" ); + tile.DrawAt( wr, t.ToPPos().ToFloat2(), "terrain" ); } - public string GetCursor(World world, int2 xy, MouseInput mi) + public string GetCursor(World world, CPos xy, MouseInput mi) { return power.UnitsInRange(xy).Any() ? "ability" : "move-blocked"; } diff --git a/OpenRA.Mods.RA/SupportPowers/NukePower.cs b/OpenRA.Mods.RA/SupportPowers/NukePower.cs index ac9e6c54c9..633dced27a 100755 --- a/OpenRA.Mods.RA/SupportPowers/NukePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/NukePower.cs @@ -42,8 +42,7 @@ namespace OpenRA.Mods.RA self.Trait().PlayCustomAnim(self, "active"); self.World.AddFrameEndTask(w => w.Add( - new NukeLaunch(self.Owner, self, npi.MissileWeapon, npi.SpawnOffset, - order.TargetLocation))); + new NukeLaunch(self.Owner, self, npi.MissileWeapon, (PVecInt)npi.SpawnOffset, order.TargetLocation))); } } } diff --git a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs index 648f1a571a..3320fc1d2c 100755 --- a/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs +++ b/OpenRA.Mods.RA/SupportPowers/SpyPlanePower.cs @@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA { new LocationInit( enterCell ), new OwnerInit( self.Owner ), - new FacingInit( Util.GetFacing(order.TargetLocation - enterCell, 0) ), + new FacingInit( Util.GetFacing((order.TargetLocation - enterCell).ToInt2(), 0) ), new AltitudeInit( Rules.Info["u2"].Traits.Get().CruiseAltitude ), }); diff --git a/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs b/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs index 9abbb16009..f282115141 100755 --- a/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs +++ b/OpenRA.Mods.RA/SupportPowers/SupportPowerManager.cs @@ -201,7 +201,7 @@ namespace OpenRA.Mods.RA expectedButton = button; } - public IEnumerable Order(World world, int2 xy, MouseInput mi) + public IEnumerable Order(World world, CPos xy, MouseInput mi) { world.CancelInputMode(); if (mi.Button == expectedButton && world.Map.IsInMap(xy)) @@ -217,6 +217,6 @@ namespace OpenRA.Mods.RA public void RenderBeforeWorld(WorldRenderer wr, World world) { } public void RenderAfterWorld(WorldRenderer wr, World world) { } - public string GetCursor(World world, int2 xy, MouseInput mi) { return world.Map.IsInMap(xy) ? cursor : "generic-blocked"; } + public string GetCursor(World world, CPos xy, MouseInput mi) { return world.Map.IsInMap(xy) ? cursor : "generic-blocked"; } } } diff --git a/OpenRA.Mods.RA/TakeCover.cs b/OpenRA.Mods.RA/TakeCover.cs index 274b20a887..96ac4e50da 100644 --- a/OpenRA.Mods.RA/TakeCover.cs +++ b/OpenRA.Mods.RA/TakeCover.cs @@ -28,8 +28,7 @@ namespace OpenRA.Mods.RA public class TakeCover : ITick, INotifyDamage, IDamageModifier, ISpeedModifier, ISync { TakeCoverInfo Info; - [Sync] - int remainingProneTime = 0; + [Sync] int remainingProneTime = 0; public TakeCover(TakeCoverInfo info) { @@ -70,8 +69,8 @@ namespace OpenRA.Mods.RA foreach (var w in ab.Weapons) foreach (var b in w.Barrels) { - b.TurretSpaceOffset += sign*new int2(Info.BarrelOffset[0], Info.BarrelOffset[1]); - b.ScreenSpaceOffset += sign*new int2(Info.BarrelOffset[2], Info.BarrelOffset[3]); + b.TurretSpaceOffset += sign * new PVecInt(Info.BarrelOffset[0], Info.BarrelOffset[1]); + b.ScreenSpaceOffset += sign * new PVecInt(Info.BarrelOffset[2], Info.BarrelOffset[3]); } } diff --git a/OpenRA.Mods.RA/TargetableBuilding.cs b/OpenRA.Mods.RA/TargetableBuilding.cs index 057e9e2bbb..5b75818cee 100755 --- a/OpenRA.Mods.RA/TargetableBuilding.cs +++ b/OpenRA.Mods.RA/TargetableBuilding.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA public string[] TargetTypes { get { return info.TargetTypes; } } public bool TargetableBy(Actor self, Actor byActor) { return true; } - public IEnumerable TargetableCells( Actor self ) + public IEnumerable TargetableCells( Actor self ) { return self.Trait().OccupiedCells().Select(c => c.First); } diff --git a/OpenRA.Mods.RA/TargetableUnit.cs b/OpenRA.Mods.RA/TargetableUnit.cs index cb6cfb82a8..37da70da40 100755 --- a/OpenRA.Mods.RA/TargetableUnit.cs +++ b/OpenRA.Mods.RA/TargetableUnit.cs @@ -52,9 +52,9 @@ namespace OpenRA.Mods.RA public virtual string[] TargetTypes { get { return info.TargetTypes; } } - public virtual IEnumerable TargetableCells( Actor self ) + public virtual IEnumerable TargetableCells( Actor self ) { - yield return Util.CellContaining( self.CenterLocation ); + yield return self.CenterLocation.ToCPos(); } } } diff --git a/OpenRA.Mods.RA/ThrowsParticle.cs b/OpenRA.Mods.RA/ThrowsParticle.cs index 0710a359ce..351dfb899e 100644 --- a/OpenRA.Mods.RA/ThrowsParticle.cs +++ b/OpenRA.Mods.RA/ThrowsParticle.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA alt = 0; facing = Turreted.GetInitialTurretFacing( init, 0 ); - pos = Combat.GetTurretPosition(self, ifacing, new Turret(info.Offset)); + pos = Combat.GetTurretPosition(self, ifacing, new Turret(info.Offset)).ToFloat2(); v = Game.CosmeticRandom.Gauss2D(1) * info.Spread.RelOffset(); dfacing = Game.CosmeticRandom.Gauss1D(2) * info.ROT; diff --git a/OpenRA.Mods.RA/TraitsInterfaces.cs b/OpenRA.Mods.RA/TraitsInterfaces.cs index db261188e6..d02d252259 100755 --- a/OpenRA.Mods.RA/TraitsInterfaces.cs +++ b/OpenRA.Mods.RA/TraitsInterfaces.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA void OnDock(Actor harv, DeliverResources dockOrder); void GiveOre(int amount); bool CanGiveOre(int amount); - int2 DeliverOffset { get; } + CVec DeliverOffset { get; } bool AllowDocking { get; } } diff --git a/OpenRA.Mods.RA/Transforms.cs b/OpenRA.Mods.RA/Transforms.cs index 68533b3177..f7364b8db5 100644 --- a/OpenRA.Mods.RA/Transforms.cs +++ b/OpenRA.Mods.RA/Transforms.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA bool CanDeploy() { - return (bi == null || self.World.CanPlaceBuilding(Info.IntoActor, bi, self.Location + Info.Offset, self)); + return (bi == null || self.World.CanPlaceBuilding(Info.IntoActor, bi, self.Location + (CVec)Info.Offset, self)); } public IEnumerable Orders @@ -83,7 +83,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 = Info.Offset, Facing = Info.Facing, Sounds = Info.TransformSounds}); + self.QueueActivity(new Transform(self, Info.IntoActor) { Offset = (CVec)Info.Offset, Facing = Info.Facing, Sounds = Info.TransformSounds }); } } } diff --git a/OpenRA.Mods.RA/Weapon.cs b/OpenRA.Mods.RA/Weapon.cs index 1b712a6e07..675923f9e5 100644 --- a/OpenRA.Mods.RA/Weapon.cs +++ b/OpenRA.Mods.RA/Weapon.cs @@ -18,8 +18,8 @@ namespace OpenRA.Mods.RA { public class Barrel { - public int2 TurretSpaceOffset; // position in turret space - public int2 ScreenSpaceOffset; // screen-space hack to make things line up good. + public PVecInt TurretSpaceOffset; // position in turret space + public PVecInt ScreenSpaceOffset; // screen-space hack to make things line up good. public int Facing; // deviation from turret facing } @@ -27,13 +27,13 @@ namespace OpenRA.Mods.RA { public float Recoil = 0.0f; // remaining recoil public float RecoilRecovery = 0.2f; // recoil recovery rate - public int2 UnitSpacePosition; // where, in the unit's local space. - public int2 ScreenSpacePosition; // screen-space hack to make things line up good. + public PVecInt UnitSpacePosition; // where, in the unit's local space. + public PVecInt ScreenSpacePosition; // screen-space hack to make things line up good. public Turret(int[] offset, float recoilRecovery) { - ScreenSpacePosition = offset.AbsOffset().ToInt2(); - UnitSpacePosition = offset.RelOffset().ToInt2(); + ScreenSpacePosition = (PVecInt) offset.AbsOffset().ToInt2(); + UnitSpacePosition = (PVecInt) offset.RelOffset().ToInt2(); RecoilRecovery = recoilRecovery; } @@ -61,14 +61,14 @@ namespace OpenRA.Mods.RA for (var i = 0; i < localOffset.Length / 5; i++) barrels.Add(new Barrel { - TurretSpaceOffset = new int2(localOffset[5 * i], localOffset[5 * i + 1]), - ScreenSpaceOffset = new int2(localOffset[5 * i + 2], localOffset[5 * i + 3]), + TurretSpaceOffset = new PVecInt(localOffset[5 * i], localOffset[5 * i + 1]), + ScreenSpaceOffset = new PVecInt(localOffset[5 * i + 2], localOffset[5 * i + 3]), Facing = localOffset[5 * i + 4] }); // if no barrels specified, the default is "turret position; turret facing". if (barrels.Count == 0) - barrels.Add(new Barrel { TurretSpaceOffset = int2.Zero, ScreenSpaceOffset = int2.Zero, Facing = 0 }); + barrels.Add(new Barrel { TurretSpaceOffset = PVecInt.Zero, ScreenSpaceOffset = PVecInt.Zero, Facing = 0 }); Barrels = barrels.ToArray(); } @@ -86,7 +86,7 @@ namespace OpenRA.Mods.RA if( target.IsActor ) return Combat.WeaponValidForTarget( Info, target.Actor ); else - return Combat.WeaponValidForTarget( Info, world, Util.CellContaining( target.CenterLocation ) ); + return Combat.WeaponValidForTarget( Info, world, target.CenterLocation.ToCPos() ); } public void FiredShot() @@ -126,8 +126,7 @@ namespace OpenRA.Mods.RA firedBy = self, target = target, - src = (self.CenterLocation - + Combat.GetBarrelPosition(self, facing, Turret, barrel)).ToInt2(), + src = (self.CenterLocation + Combat.GetBarrelPosition(self, facing, Turret, barrel)), srcAltitude = move != null ? move.Altitude : 0, dest = target.CenterLocation, destAltitude = destMove != null ? destMove.Altitude : 0, diff --git a/OpenRA.Mods.RA/Widgets/Logic/DiplomacyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/DiplomacyLogic.cs index ea12dc4de9..7673691c24 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/DiplomacyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/DiplomacyLogic.cs @@ -141,8 +141,9 @@ namespace OpenRA.Mods.RA.Widgets.Logic if (p.World.LobbyInfo.GlobalSettings.LockTeams) return; // team changes are banned + // NOTE(jsd): Abuse of the type system here with `CPos` world.IssueOrder(new Order("SetStance", world.LocalPlayer.PlayerActor, false) - { TargetLocation = new int2((int)ss, 0), TargetString = p.InternalName }); + { TargetLocation = new CPos((int)ss, 0), TargetString = p.InternalName }); bw.Text = ss.ToString(); } diff --git a/OpenRA.Mods.RA/Widgets/RadarBinWidget.cs b/OpenRA.Mods.RA/Widgets/RadarBinWidget.cs index ba840b8c37..102eaefb2f 100755 --- a/OpenRA.Mods.RA/Widgets/RadarBinWidget.cs +++ b/OpenRA.Mods.RA/Widgets/RadarBinWidget.cs @@ -77,7 +77,7 @@ namespace OpenRA.Mods.RA.Widgets var mi = new MouseInput { - Location = loc, + Location = loc.ToInt2(), Button = MouseButton.Right, Modifiers = Game.GetModifierKeys() }; @@ -98,7 +98,7 @@ namespace OpenRA.Mods.RA.Widgets var loc = MinimapPixelToCell(mi.Location); if ((mi.Event == MouseInputEvent.Down || mi.Event == MouseInputEvent.Move) && mi.Button == MouseButton.Left) - Game.viewport.Center(loc); + Game.viewport.Center(loc.ToFloat2()); if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Right) { @@ -108,7 +108,7 @@ namespace OpenRA.Mods.RA.Widgets Event = MouseInputEvent.Down, Button = MouseButton.Right, Modifiers = mi.Modifiers, - Location = (loc * Game.CellSize - Game.viewport.Location).ToInt2() + Location = (loc.ToPPos().ToFloat2() - Game.viewport.Location).ToInt2() }; if (WorldInteractionController != null) @@ -154,9 +154,9 @@ namespace OpenRA.Mods.RA.Widgets if (radarAnimationFrame == radarSlideAnimationLength + radarActivateAnimationLength) { var wr = Game.viewport.WorldRect; - var wro = new int2(wr.X, wr.Y); + var wro = new CPos(wr.X, wr.Y); var tl = CellToMinimapPixel(wro); - var br = CellToMinimapPixel(wro + new int2(wr.Width, wr.Height)); + var br = CellToMinimapPixel(wro + new CVec(wr.Width, wr.Height)); Game.Renderer.EnableScissor((int)mapRect.Left, (int)mapRect.Top, (int)mapRect.Width, (int)mapRect.Height); Game.Renderer.LineRenderer.DrawRect(tl, br, Color.White); @@ -220,14 +220,14 @@ namespace OpenRA.Mods.RA.Widgets radarAnimating = false; } - int2 CellToMinimapPixel(int2 p) + int2 CellToMinimapPixel(CPos p) { return new int2((int)(mapRect.X +previewScale*(p.X - world.Map.Bounds.Left)), (int)(mapRect.Y + previewScale*(p.Y - world.Map.Bounds.Top))); } - int2 MinimapPixelToCell(int2 p) + CPos MinimapPixelToCell(int2 p) { - return new int2(world.Map.Bounds.Left + (int)((p.X - mapRect.X)/previewScale), world.Map.Bounds.Top + (int)((p.Y - mapRect.Y)/previewScale)); + return new CPos(world.Map.Bounds.Left + (int)((p.X - mapRect.X) / previewScale), world.Map.Bounds.Top + (int)((p.Y - mapRect.Y) / previewScale)); } } } diff --git a/OpenRA.Mods.RA/Widgets/RadarWidget.cs b/OpenRA.Mods.RA/Widgets/RadarWidget.cs index 8ab6801137..c9b0248b49 100755 --- a/OpenRA.Mods.RA/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.RA/Widgets/RadarWidget.cs @@ -74,7 +74,7 @@ namespace OpenRA.Mods.RA.Widgets var mi = new MouseInput { - Location = loc, + Location = loc.ToInt2(), Button = MouseButton.Right, Modifiers = Game.GetModifierKeys() }; @@ -95,7 +95,7 @@ namespace OpenRA.Mods.RA.Widgets var loc = MinimapPixelToCell(mi.Location); if ((mi.Event == MouseInputEvent.Down || mi.Event == MouseInputEvent.Move) && mi.Button == MouseButton.Left) - Game.viewport.Center(loc); + Game.viewport.Center(loc.ToFloat2()); if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Right) { @@ -105,7 +105,7 @@ namespace OpenRA.Mods.RA.Widgets Event = MouseInputEvent.Down, Button = MouseButton.Right, Modifiers = mi.Modifiers, - Location = (loc * Game.CellSize - Game.viewport.Location).ToInt2() + Location = (loc.ToPPos().ToFloat2() - Game.viewport.Location).ToInt2() }; if (WorldInteractionController != null) @@ -141,9 +141,9 @@ namespace OpenRA.Mods.RA.Widgets if (hasRadar && !animating) { var wr = Game.viewport.WorldRect; - var wro = new int2(wr.X, wr.Y); + var wro = new CPos(wr.X, wr.Y); var tl = CellToMinimapPixel(wro); - var br = CellToMinimapPixel(wro + new int2(wr.Width, wr.Height)); + var br = CellToMinimapPixel(wro + new CVec(wr.Width, wr.Height)); Game.Renderer.EnableScissor((int)mapRect.Left, (int)mapRect.Top, (int)mapRect.Width, (int)mapRect.Height); Game.Renderer.LineRenderer.DrawRect(tl, br, Color.White); @@ -197,20 +197,20 @@ namespace OpenRA.Mods.RA.Widgets animating = false; } - int2 CellToMinimapPixel(int2 p) + int2 CellToMinimapPixel(CPos p) { var viewOrigin = new float2(mapRect.X, mapRect.Y); - var mapOrigin = new float2(world.Map.Bounds.Left, world.Map.Bounds.Top); + var mapOrigin = new CPos(world.Map.Bounds.Left, world.Map.Bounds.Top); - return (viewOrigin + previewScale * (p - mapOrigin)).ToInt2(); + return (viewOrigin + previewScale * (p - mapOrigin).ToFloat2()).ToInt2(); } - int2 MinimapPixelToCell(int2 p) + CPos MinimapPixelToCell(int2 p) { var viewOrigin = new float2(mapRect.X, mapRect.Y); - var mapOrigin = new float2(world.Map.Bounds.Left, world.Map.Bounds.Top); + var mapOrigin = new CPos(world.Map.Bounds.Left, world.Map.Bounds.Top); - return (mapOrigin + (1/previewScale) * (p - viewOrigin)).ToInt2(); + return (CPos)(mapOrigin.ToFloat2() + (1f / previewScale) * (p - viewOrigin)).ToInt2(); } } } diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index 17a1c57747..2434bca958 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -140,7 +140,8 @@ namespace OpenRA.Mods.RA.Widgets { var at = a.TraitOrDefault(); if (at != null) at.predictedStance = nextStance; - return new Order("SetUnitStance", a, false) { TargetLocation = new int2((int)nextStance, 0) }; + // NOTE(jsd): Abuse of the type system here with `CPos` + return new Order("SetUnitStance", a, false) { TargetLocation = new CPos((int)nextStance, 0) }; }); Game.Debug( "Unit stance set to: {0}".F(nextStance) ); @@ -180,7 +181,7 @@ namespace OpenRA.Mods.RA.Widgets if (eventNotifier.lastAttackTime < 0) return true; - Game.viewport.Center(eventNotifier.lastAttackLocation); + Game.viewport.Center(eventNotifier.lastAttackLocation.ToFloat2()); return true; } } diff --git a/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs b/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs index b9c297e278..82a62ec147 100755 --- a/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldTooltipWidget.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.RA.Widgets if (Viewport.TicksSinceLastMove < TooltipDelay || world == null) return; - var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos).ToInt2(); + var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos); if (!world.Map.IsInMap(cell)) return; if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(cell)) diff --git a/OpenRA.Mods.RA/World/SmudgeLayer.cs b/OpenRA.Mods.RA/World/SmudgeLayer.cs index dbf39b2bff..134eec097a 100755 --- a/OpenRA.Mods.RA/World/SmudgeLayer.cs +++ b/OpenRA.Mods.RA/World/SmudgeLayer.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA public class SmudgeLayer: IRenderOverlay, IWorldLoaded { public SmudgeLayerInfo Info; - Dictionary> tiles; + Dictionary> tiles; Sprite[][] smudgeSprites; World world; @@ -45,15 +45,14 @@ namespace OpenRA.Mods.RA public void WorldLoaded(World w) { world = w; - tiles = new Dictionary>(); + tiles = new Dictionary>(); // Add map smudges foreach (var s in w.Map.Smudges.Value.Where( s => Info.Types.Contains(s.Type ))) - tiles.Add(s.Location,new TileReference((byte)Array.IndexOf(Info.Types,s.Type), - (byte)s.Depth)); + tiles.Add((CPos)s.Location, new TileReference((byte)Array.IndexOf(Info.Types, s.Type), (byte)s.Depth)); } - public void AddSmudge(int2 loc) + public void AddSmudge(CPos loc) { if (!world.GetTerrainInfo(loc).AcceptSmudge) return; @@ -90,8 +89,7 @@ namespace OpenRA.Mods.RA if (localPlayer != null && !localPlayer.Shroud.IsExplored(kv.Key)) continue; - smudgeSprites[kv.Value.type- 1][kv.Value.index].DrawAt( wr, - Game.CellSize * kv.Key, "terrain"); + smudgeSprites[kv.Value.type- 1][kv.Value.index].DrawAt(wr, kv.Key.ToPPos().ToFloat2(), "terrain"); } } }