Permalink
Browse files

Changed things to do with Shroud to WRange. Updated Utility.

  • Loading branch information...
1 parent 9e1f154 commit cf3cc43a2842330a87e139f058d6928d8694c201 @Unit158 Unit158 committed Feb 20, 2014
View
4 OpenRA.FileFormats/WRange.cs
@@ -16,7 +16,7 @@ namespace OpenRA
/// <summary>
/// 1d world distance - 1024 units = 1 cell.
/// </summary>
- public struct WRange : IComparable
+ public struct WRange : IComparable, IComparable<WRange>
{
public readonly int Range;
@@ -92,6 +92,8 @@ public int CompareTo(object obj)
return Range.CompareTo(o.Value.Range);
}
+ public int CompareTo(WRange other) { return Range.CompareTo(other.Range); }
+
public override string ToString() { return "{0}".F(Range); }
}
}
View
4 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 @@ public void Tick(Actor self)
}
}
- public int Range { get { return cachedDisabled ? 0 : Info.Range; } }
+ public WRange Range { get { return cachedDisabled ? WRange.Zero : Info.Range; } }
}
}
View
4 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 @@ public void Tick(Actor self)
}
}
- public int Range { get { return Info.Range; } }
+ public WRange Range { get { return Info.Range; } }
}
}
View
35 OpenRA.Game/Traits/World/Shroud.cs
@@ -64,42 +64,36 @@ void Invalidate()
Hash = Sync.hash_player(self.Owner) + self.World.FrameNumber * 3;
}
- static IEnumerable<CPos> FindVisibleTiles(World world, CPos a, int r)
+ static IEnumerable<CPos> 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<RevealsShroud>();
- 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);
var visible = origins.SelectMany(o => FindVisibleTiles(a.World, o, rs.Range))
.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 @@ public void UpdateVisibility(Actor a)
void AddShroudGeneration(Actor a)
{
var cs = a.TraitOrDefault<CreatesShroud>();
- 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 @@ public static IEnumerable<CPos> GetVisOrigins(Actor a)
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();
View
4 OpenRA.Mods.RA/ActorExts.cs
@@ -75,9 +75,9 @@ public static Target ResolveFrozenActorOrder(this Actor self, Order order, Color
{
// Move within sight range of the frozen actor
var sight = self.TraitOrDefault<RevealsShroud>();
- 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;
View
2 OpenRA.Mods.RA/MPStartLocations.cs
@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA
{
public class MPStartLocationsInfo : TraitInfo<MPStartLocations>
{
- public readonly int InitialExploreRange = 5;
+ public readonly WRange InitialExploreRange = WRange.FromCells(5);
}
public class MPStartLocations : IWorldLoaded
View
8 OpenRA.Mods.RA/Missions/Allies02Script.cs
@@ -462,10 +462,10 @@ public void WorldLoaded(World w, WorldRenderer wr)
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);
View
4 OpenRA.Mods.RA/Missions/Survival01Script.cs
@@ -333,8 +333,8 @@ public void WorldLoaded(World w, WorldRenderer wr)
sam2 = actors["Sam2"];
var shroud = allies.PlayerActor.Trait<Shroud>();
- 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();
View
2 OpenRA.Mods.RA/Player/PlayerStatistics.cs
@@ -58,7 +58,7 @@ void UpdateMapControl()
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<RevealsShroud>())
- .SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait<RevealsShroud>().Range.Clamp(0, 50)))
+ .SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait<RevealsShroud>().Range.Clamp(WRange.Zero, WRange.FromCells(50)).Range / 1024))
.Distinct()
.Count() / total;
}
View
4 OpenRA.Mods.RA/RenderShroudCircle.cs
@@ -20,7 +20,7 @@ public void Render(WorldRenderer wr, World w, ActorInfo ai, WPos centerPosition)
{
wr.DrawRangeCircleWithContrast(
centerPosition,
- WRange.FromCells(ai.Traits.Get<CreatesShroudInfo>().Range),
+ ai.Traits.Get<CreatesShroudInfo>().Range,
Color.FromArgb(128, Color.Cyan),
Color.FromArgb(96, Color.Black)
);
@@ -46,7 +46,7 @@ public void RenderAfterWorld(WorldRenderer wr)
wr.DrawRangeCircleWithContrast(
self.CenterPosition,
- WRange.FromCells(self.Info.Traits.Get<CreatesShroudInfo>().Range),
+ self.Info.Traits.Get<CreatesShroudInfo>().Range,
Color.FromArgb(128, Color.Cyan),
Color.FromArgb(96, Color.Black)
);
View
10 OpenRA.Utility/UpgradeRules.cs
@@ -120,6 +120,16 @@ static void UpgradeActorRules(int engineVersion, ref List<MiniYamlNode> nodes, M
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);
}
}

0 comments on commit cf3cc43

Please sign in to comment.