From cf3cc43a2842330a87e139f058d6928d8694c201 Mon Sep 17 00:00:00 2001 From: Chicken man Date: Thu, 20 Feb 2014 17:37:18 -0500 Subject: [PATCH] Changed things to do with Shroud to WRange. Updated Utility. --- OpenRA.FileFormats/WRange.cs | 4 ++- OpenRA.Game/Traits/CreatesShroud.cs | 4 +-- OpenRA.Game/Traits/RevealsShroud.cs | 4 +-- OpenRA.Game/Traits/World/Shroud.cs | 35 +++++++++------------ OpenRA.Mods.RA/ActorExts.cs | 4 +-- OpenRA.Mods.RA/MPStartLocations.cs | 2 +- OpenRA.Mods.RA/Missions/Allies02Script.cs | 8 ++--- OpenRA.Mods.RA/Missions/Survival01Script.cs | 4 +-- OpenRA.Mods.RA/Player/PlayerStatistics.cs | 2 +- OpenRA.Mods.RA/RenderShroudCircle.cs | 4 +-- OpenRA.Utility/UpgradeRules.cs | 10 ++++++ 11 files changed, 44 insertions(+), 37 deletions(-) diff --git a/OpenRA.FileFormats/WRange.cs b/OpenRA.FileFormats/WRange.cs index 1275376d4e..2b4952775f 100644 --- a/OpenRA.FileFormats/WRange.cs +++ b/OpenRA.FileFormats/WRange.cs @@ -16,7 +16,7 @@ namespace OpenRA /// /// 1d world distance - 1024 units = 1 cell. /// - public struct WRange : IComparable + public struct WRange : IComparable, IComparable { public readonly int Range; @@ -92,6 +92,8 @@ namespace OpenRA return Range.CompareTo(o.Value.Range); } + public int CompareTo(WRange other) { return Range.CompareTo(other.Range); } + public override string ToString() { return "{0}".F(Range); } } } diff --git a/OpenRA.Game/Traits/CreatesShroud.cs b/OpenRA.Game/Traits/CreatesShroud.cs index ef78d9a0b7..f148a333fc 100644 --- a/OpenRA.Game/Traits/CreatesShroud.cs +++ b/OpenRA.Game/Traits/CreatesShroud.cs @@ -14,7 +14,7 @@ namespace OpenRA.Traits { public class CreatesShroudInfo : ITraitInfo { - public readonly int Range = 0; + public readonly WRange Range = WRange.Zero; public object Create(ActorInitializer init) { return new CreatesShroud(this); } } @@ -43,6 +43,6 @@ namespace OpenRA.Traits } } - public int Range { get { return cachedDisabled ? 0 : Info.Range; } } + public WRange Range { get { return cachedDisabled ? WRange.Zero : Info.Range; } } } } \ No newline at end of file diff --git a/OpenRA.Game/Traits/RevealsShroud.cs b/OpenRA.Game/Traits/RevealsShroud.cs index c8fb7e7e99..74bae01aec 100644 --- a/OpenRA.Game/Traits/RevealsShroud.cs +++ b/OpenRA.Game/Traits/RevealsShroud.cs @@ -14,7 +14,7 @@ namespace OpenRA.Traits { public class RevealsShroudInfo : ITraitInfo { - public readonly int Range = 0; + public readonly WRange Range = WRange.Zero; public object Create(ActorInitializer init) { return new RevealsShroud(this); } } @@ -39,6 +39,6 @@ namespace OpenRA.Traits } } - public int Range { get { return Info.Range; } } + public WRange Range { get { return Info.Range; } } } } diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index cf86cfa312..30e71b7bfa 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -64,32 +64,24 @@ namespace OpenRA.Traits Hash = Sync.hash_player(self.Owner) + self.World.FrameNumber * 3; } - static IEnumerable FindVisibleTiles(World world, CPos a, int r) + static IEnumerable FindVisibleTiles(World world, CPos position, WRange radius) { - 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); + var r = (radius.Range + 1023) / 1024; + var min = (position - new CVec(r, r)).Clamp(world.Map.Bounds); + var max = (position + new CVec(r, r)).Clamp(world.Map.Bounds); + var circleArea = radius.Range * radius.Range; + var pos = position.CenterPosition; for (var j = min.Y; j <= max.Y; j++) for (var i = min.X; i <= max.X; i++) - if (r*r >= (new CPos(i, j) - a).LengthSquared) + if (circleArea >= (new CPos(i, j).CenterPosition - pos).LengthSquared) yield return new CPos(i, j); } void AddVisibility(Actor a) { var rs = a.TraitOrDefault(); - if (rs == null || !a.Owner.IsAlliedWith(self.Owner) || rs.Range == 0) + if (rs == null || !a.Owner.IsAlliedWith(self.Owner) || rs.Range == WRange.Zero) return; var origins = GetVisOrigins(a); @@ -97,9 +89,11 @@ namespace OpenRA.Traits .Distinct().ToArray(); // Update bounding rect + var r = (rs.Range.Range + 1023) / 1024; + foreach (var o in origins) { - var box = new Rectangle(o.X - rs.Range, o.Y - rs.Range, 2*rs.Range + 1, 2*rs.Range + 1); + var box = new Rectangle(o.X - r, o.Y - r, 2 * r + 1, 2 * r + 1); ExploredBounds = Rectangle.Union(ExploredBounds, box); } @@ -143,7 +137,7 @@ namespace OpenRA.Traits void AddShroudGeneration(Actor a) { var cs = a.TraitOrDefault(); - if (cs == null || a.Owner.IsAlliedWith(self.Owner) || cs.Range == 0) + if (cs == null || a.Owner.IsAlliedWith(self.Owner) || cs.Range == WRange.Zero) return; var shrouded = GetVisOrigins(a).SelectMany(o => FindVisibleTiles(a.World, o, cs.Range)) @@ -202,12 +196,13 @@ namespace OpenRA.Traits return new[] { a.CenterPosition.ToCPos() }; } - public void Explore(World world, CPos center, int range) + public void Explore(World world, CPos center, WRange range) { foreach (var q in FindVisibleTiles(world, center, range)) explored[q.X, q.Y] = true; - var box = new Rectangle(center.X - range, center.Y - range, 2*range + 1, 2*range + 1); + var r = (range.Range + 1023) / 1024; + var box = new Rectangle(center.X - r, center.Y - r, 2 * r + 1, 2 * r + 1); ExploredBounds = Rectangle.Union(ExploredBounds, box); Invalidate(); diff --git a/OpenRA.Mods.RA/ActorExts.cs b/OpenRA.Mods.RA/ActorExts.cs index 33ff923b62..360bfca05a 100644 --- a/OpenRA.Mods.RA/ActorExts.cs +++ b/OpenRA.Mods.RA/ActorExts.cs @@ -75,9 +75,9 @@ namespace OpenRA.Mods.RA { // Move within sight range of the frozen actor var sight = self.TraitOrDefault(); - var range = sight != null ? sight.Range : 2; + var range = sight != null ? sight.Range : WRange.FromCells(2); - self.QueueActivity(move.MoveWithinRange(Target.FromPos(frozen.CenterPosition), WRange.FromCells(range))); + self.QueueActivity(move.MoveWithinRange(Target.FromPos(frozen.CenterPosition), range)); } return Target.Invalid; diff --git a/OpenRA.Mods.RA/MPStartLocations.cs b/OpenRA.Mods.RA/MPStartLocations.cs index b85d0dbfe5..e2f8c15a4f 100755 --- a/OpenRA.Mods.RA/MPStartLocations.cs +++ b/OpenRA.Mods.RA/MPStartLocations.cs @@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA { public class MPStartLocationsInfo : TraitInfo { - public readonly int InitialExploreRange = 5; + public readonly WRange InitialExploreRange = WRange.FromCells(5); } public class MPStartLocations : IWorldLoaded diff --git a/OpenRA.Mods.RA/Missions/Allies02Script.cs b/OpenRA.Mods.RA/Missions/Allies02Script.cs index 4bf15e537a..ee017320c4 100644 --- a/OpenRA.Mods.RA/Missions/Allies02Script.cs +++ b/OpenRA.Mods.RA/Missions/Allies02Script.cs @@ -462,10 +462,10 @@ namespace OpenRA.Mods.RA.Missions SetupAlliedBase(); var shroud = allies1.Shroud; - shroud.Explore(w, sam1.Location, 2); - shroud.Explore(w, sam2.Location, 2); - shroud.Explore(w, sam3.Location, 2); - shroud.Explore(w, sam4.Location, 2); + shroud.Explore(w, sam1.Location, WRange.FromCells(2)); + shroud.Explore(w, sam2.Location, WRange.FromCells(2)); + shroud.Explore(w, sam3.Location, WRange.FromCells(2)); + shroud.Explore(w, sam4.Location, WRange.FromCells(2)); if (w.LocalPlayer == null || w.LocalPlayer == allies1) wr.Viewport.Center(chinookHusk.CenterPosition); diff --git a/OpenRA.Mods.RA/Missions/Survival01Script.cs b/OpenRA.Mods.RA/Missions/Survival01Script.cs index 52a33c97be..4d7b0e0d16 100644 --- a/OpenRA.Mods.RA/Missions/Survival01Script.cs +++ b/OpenRA.Mods.RA/Missions/Survival01Script.cs @@ -333,8 +333,8 @@ namespace OpenRA.Mods.RA.Missions sam2 = actors["Sam2"]; var shroud = allies.PlayerActor.Trait(); - shroud.Explore(w, sam1.Location, 4); - shroud.Explore(w, sam2.Location, 4); + shroud.Explore(w, sam1.Location, WRange.FromCells(4)); + shroud.Explore(w, sam2.Location, WRange.FromCells(4)); wr.Viewport.Center(alliesbase.CenterPosition); StartCountDownTimer(); diff --git a/OpenRA.Mods.RA/Player/PlayerStatistics.cs b/OpenRA.Mods.RA/Player/PlayerStatistics.cs index 845663e366..5779954e5f 100644 --- a/OpenRA.Mods.RA/Player/PlayerStatistics.cs +++ b/OpenRA.Mods.RA/Player/PlayerStatistics.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA var total = (double)world.Map.Bounds.Width * world.Map.Bounds.Height; MapControl = world.Actors .Where(a => !a.IsDead() && a.IsInWorld && a.Owner == player && a.HasTrait()) - .SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait().Range.Clamp(0, 50))) + .SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait().Range.Clamp(WRange.Zero, WRange.FromCells(50)).Range / 1024)) .Distinct() .Count() / total; } diff --git a/OpenRA.Mods.RA/RenderShroudCircle.cs b/OpenRA.Mods.RA/RenderShroudCircle.cs index cfc2868c90..58e7e787a5 100644 --- a/OpenRA.Mods.RA/RenderShroudCircle.cs +++ b/OpenRA.Mods.RA/RenderShroudCircle.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA { wr.DrawRangeCircleWithContrast( centerPosition, - WRange.FromCells(ai.Traits.Get().Range), + ai.Traits.Get().Range, Color.FromArgb(128, Color.Cyan), Color.FromArgb(96, Color.Black) ); @@ -46,7 +46,7 @@ namespace OpenRA.Mods.RA wr.DrawRangeCircleWithContrast( self.CenterPosition, - WRange.FromCells(self.Info.Traits.Get().Range), + self.Info.Traits.Get().Range, Color.FromArgb(128, Color.Cyan), Color.FromArgb(96, Color.Black) ); diff --git a/OpenRA.Utility/UpgradeRules.cs b/OpenRA.Utility/UpgradeRules.cs index c6d8a06eb8..4dbc29fae2 100644 --- a/OpenRA.Utility/UpgradeRules.cs +++ b/OpenRA.Utility/UpgradeRules.cs @@ -120,6 +120,16 @@ namespace OpenRA.Utility node.Value.Nodes.RemoveAll(n => n.Key == "UnloadFacing"); } + // RevealShroud was updated to use world units. + if (engineVersion < 20140220) + { + if (depth == 2 && parentKey == "RevealsShroud" && node.Key == "Range") + ConvertFloatToRange(ref node.Value.Value); + + if (depth == 2 && parentKey == "CreatesShroud" && node.Key == "Range") + ConvertFloatToRange(ref node.Value.Value); + } + UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1); } }