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

This commit is contained in:
Chicken man
2014-02-20 17:37:18 -05:00
parent 9e1f15448d
commit cf3cc43a28
11 changed files with 44 additions and 37 deletions

View File

@@ -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 @@ 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); }
}
}

View File

@@ -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; } }
}
}

View File

@@ -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; } }
}
}

View File

@@ -64,32 +64,24 @@ namespace OpenRA.Traits
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);
@@ -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<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 @@ 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();

View File

@@ -75,9 +75,9 @@ namespace OpenRA.Mods.RA
{
// 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 File

@@ -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 File

@@ -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);

View File

@@ -333,8 +333,8 @@ namespace OpenRA.Mods.RA.Missions
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 File

@@ -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<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 File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA
{
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 @@ namespace OpenRA.Mods.RA
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 File

@@ -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);
}
}