Simplify and increase robustness of Shroud et al. Fixes #3440.
This commit is contained in:
@@ -66,8 +66,6 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Shroud.ActorVisibility Sight;
|
|
||||||
|
|
||||||
[Sync] public Player Owner;
|
[Sync] public Player Owner;
|
||||||
|
|
||||||
Activity currentActivity;
|
Activity currentActivity;
|
||||||
@@ -107,15 +105,6 @@ namespace OpenRA
|
|||||||
return TraitsImplementing<IAutoSelectionSize>().Select(x => x.SelectionSize(this)).FirstOrDefault();
|
return TraitsImplementing<IAutoSelectionSize>().Select(x => x.SelectionSize(this)).FirstOrDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.HasTrait<RevealsShroud>())
|
|
||||||
{
|
|
||||||
Sight = new Shroud.ActorVisibility
|
|
||||||
{
|
|
||||||
range = this.Trait<RevealsShroud>().RevealRange,
|
|
||||||
vis = Shroud.GetVisOrigins(this).ToArray()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
ApplyIRender = (x, wr) => x.Render(this, wr);
|
ApplyIRender = (x, wr) => x.Render(this, wr);
|
||||||
ApplyRenderModifier = (m, p, wr) => p.ModifyRender(this, wr, m);
|
ApplyRenderModifier = (m, p, wr) => p.ModifyRender(this, wr, m);
|
||||||
|
|
||||||
@@ -131,11 +120,6 @@ namespace OpenRA
|
|||||||
currentActivity = Traits.Util.RunActivity(this, currentActivity);
|
currentActivity = Traits.Util.RunActivity(this, currentActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateSight()
|
|
||||||
{
|
|
||||||
Sight.vis = Shroud.GetVisOrigins(this).ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsIdle
|
public bool IsIdle
|
||||||
{
|
{
|
||||||
get { return currentActivity == null; }
|
get { return currentActivity == null; }
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ namespace OpenRA.Traits
|
|||||||
public class CreatesShroud : ITick, ISync
|
public class CreatesShroud : ITick, ISync
|
||||||
{
|
{
|
||||||
CreatesShroudInfo Info;
|
CreatesShroudInfo Info;
|
||||||
[Sync] CPos previousLocation;
|
[Sync] CPos cachedLocation;
|
||||||
Shroud.ActorVisibility v;
|
[Sync] bool cachedDisabled;
|
||||||
|
|
||||||
public CreatesShroud(CreatesShroudInfo info)
|
public CreatesShroud(CreatesShroudInfo info)
|
||||||
{
|
{
|
||||||
@@ -31,29 +31,18 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
// TODO: don't tick all the time.
|
var disabled = self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
|
||||||
if (self.Owner == null)
|
if (cachedLocation != self.Location || cachedDisabled != disabled)
|
||||||
return;
|
|
||||||
|
|
||||||
var shrouds = self.World.ActorsWithTrait<Shroud>().Select(s => s.Actor.Owner.Shroud);
|
|
||||||
if (previousLocation != self.Location && v != null)
|
|
||||||
{
|
{
|
||||||
previousLocation = self.Location;
|
cachedLocation = self.Location;
|
||||||
|
cachedDisabled = disabled;
|
||||||
|
|
||||||
foreach (var shroud in shrouds)
|
var shroud = self.World.Players.Select(p => p.Shroud);
|
||||||
shroud.UnhideActor(self, v, Info.Range);
|
foreach (var s in shroud)
|
||||||
|
s.UpdateShroudGeneration(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!self.TraitsImplementing<IDisable>().Any(d => d.Disabled))
|
|
||||||
foreach (var shroud in shrouds)
|
|
||||||
shroud.HideActor(self, Info.Range);
|
|
||||||
else
|
|
||||||
foreach (var shroud in shrouds)
|
|
||||||
shroud.UnhideActor(self, v, Info.Range);
|
|
||||||
|
|
||||||
v = new Shroud.ActorVisibility {
|
|
||||||
vis = Shroud.GetVisOrigins(self).ToArray()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int Range { get { return cachedDisabled ? 0 : Info.Range; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRA.Traits
|
namespace OpenRA.Traits
|
||||||
{
|
{
|
||||||
public class RevealsShroudInfo : ITraitInfo
|
public class RevealsShroudInfo : ITraitInfo
|
||||||
@@ -19,7 +21,7 @@ namespace OpenRA.Traits
|
|||||||
public class RevealsShroud : ITick, ISync
|
public class RevealsShroud : ITick, ISync
|
||||||
{
|
{
|
||||||
RevealsShroudInfo Info;
|
RevealsShroudInfo Info;
|
||||||
[Sync] CPos previousLocation;
|
[Sync] CPos cachedLocation;
|
||||||
|
|
||||||
public RevealsShroud(RevealsShroudInfo info)
|
public RevealsShroud(RevealsShroudInfo info)
|
||||||
{
|
{
|
||||||
@@ -28,26 +30,15 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void Tick(Actor self)
|
public void Tick(Actor self)
|
||||||
{
|
{
|
||||||
// TODO: don't tick all the time.
|
if (cachedLocation != self.Location)
|
||||||
World w = self.World;
|
|
||||||
if(self.Owner == null) return;
|
|
||||||
|
|
||||||
if (previousLocation != self.Location)
|
|
||||||
{
|
{
|
||||||
previousLocation = self.Location;
|
cachedLocation = self.Location;
|
||||||
var actors = w.ActorsWithTrait<Shroud>();
|
|
||||||
|
|
||||||
foreach( var s in actors )
|
|
||||||
s.Actor.Owner.Shroud.RemoveActor(self);
|
|
||||||
|
|
||||||
self.UpdateSight();
|
|
||||||
|
|
||||||
foreach( var s in actors )
|
|
||||||
s.Actor.Owner.Shroud.AddActor(self);
|
|
||||||
|
|
||||||
|
foreach (var s in self.World.Players.Select(p => p.Shroud))
|
||||||
|
s.UpdateVisibility(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int RevealRange { get { return Info.Range; } }
|
public int Range { get { return Info.Range; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,9 +29,14 @@ namespace OpenRA.Traits
|
|||||||
Actor self;
|
Actor self;
|
||||||
Map map;
|
Map map;
|
||||||
|
|
||||||
int[,] visibleCells;
|
int[,] visibleCount;
|
||||||
bool[,] exploredCells;
|
int[,] generatedShroudCount;
|
||||||
bool[,] foggedCells;
|
bool[,] explored;
|
||||||
|
|
||||||
|
// Cache of visibility that was added, so no matter what crazy trait code does, it
|
||||||
|
// can't make us invalid.
|
||||||
|
Dictionary<Actor, CPos[]> visibility = new Dictionary<Actor, CPos[]>();
|
||||||
|
Dictionary<Actor, CPos[]> generation = new Dictionary<Actor, CPos[]>();
|
||||||
|
|
||||||
public Rectangle ExploredBounds { get; private set; }
|
public Rectangle ExploredBounds { get; private set; }
|
||||||
|
|
||||||
@@ -43,11 +48,15 @@ namespace OpenRA.Traits
|
|||||||
this.self = self;
|
this.self = self;
|
||||||
map = self.World.Map;
|
map = self.World.Map;
|
||||||
|
|
||||||
visibleCells = new int[map.MapSize.X, map.MapSize.Y];
|
visibleCount = new int[map.MapSize.X, map.MapSize.Y];
|
||||||
exploredCells = new bool[map.MapSize.X, map.MapSize.Y];
|
generatedShroudCount = new int[map.MapSize.X, map.MapSize.Y];
|
||||||
foggedCells = new bool[map.MapSize.X, map.MapSize.Y];
|
explored = new bool[map.MapSize.X, map.MapSize.Y];
|
||||||
self.World.ActorAdded += AddActor;
|
|
||||||
self.World.ActorRemoved += RemoveActor;
|
self.World.ActorAdded += AddVisibility;
|
||||||
|
self.World.ActorRemoved += RemoveVisibility;
|
||||||
|
|
||||||
|
self.World.ActorAdded += AddShroudGeneration;
|
||||||
|
self.World.ActorRemoved += RemoveShroudGeneration;
|
||||||
|
|
||||||
if (!info.Shroud)
|
if (!info.Shroud)
|
||||||
ExploredBounds = map.Bounds;
|
ExploredBounds = map.Bounds;
|
||||||
@@ -58,16 +67,6 @@ namespace OpenRA.Traits
|
|||||||
Hash = Sync.hash_player(self.Owner) + self.World.FrameNumber * 3;
|
Hash = Sync.hash_player(self.Owner) + self.World.FrameNumber * 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache of positions that were added, so no matter what crazy trait code does, it
|
|
||||||
// can't make us invalid.
|
|
||||||
public class ActorVisibility
|
|
||||||
{
|
|
||||||
[Sync] public int range;
|
|
||||||
[Sync] public CPos[] vis;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dictionary<Actor, ActorVisibility> vis = new Dictionary<Actor, ActorVisibility>();
|
|
||||||
|
|
||||||
static IEnumerable<CPos> FindVisibleTiles(World world, CPos a, int r)
|
static IEnumerable<CPos> FindVisibleTiles(World world, CPos a, int r)
|
||||||
{
|
{
|
||||||
var min = a - new CVec(r, r);
|
var min = a - new CVec(r, r);
|
||||||
@@ -86,77 +85,89 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
for (var j = min.Y; j <= max.Y; j++)
|
for (var j = min.Y; j <= max.Y; j++)
|
||||||
for (var i = min.X; i <= max.X; i++)
|
for (var i = min.X; i <= max.X; i++)
|
||||||
if (r * r >= (new CPos(i, j) - a).LengthSquared)
|
if (r*r >= (new CPos(i, j) - a).LengthSquared)
|
||||||
yield return new CPos(i, j);
|
yield return new CPos(i, j);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddActor(Actor a)
|
void AddVisibility(Actor a)
|
||||||
{
|
{
|
||||||
if (!a.HasTrait<RevealsShroud>() || !a.Owner.IsAlliedWith(self.Owner))
|
var rs = a.TraitOrDefault<RevealsShroud>();
|
||||||
|
if (rs == null || !a.Owner.IsAlliedWith(self.Owner) || rs.Range == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ActorVisibility v = a.Sight;
|
var origins = GetVisOrigins(a);
|
||||||
if (v.range == 0)
|
var visible = origins.SelectMany(o => FindVisibleTiles(a.World, o, rs.Range))
|
||||||
return;
|
.Distinct().ToArray();
|
||||||
|
|
||||||
foreach (var p in v.vis)
|
// Update bounding rect
|
||||||
|
foreach (var o in origins)
|
||||||
{
|
{
|
||||||
foreach (var q in FindVisibleTiles(a.World, p, v.range))
|
var box = new Rectangle(o.X - rs.Range, o.Y - rs.Range, 2*rs.Range + 1, 2*rs.Range + 1);
|
||||||
{
|
|
||||||
++visibleCells[q.X, q.Y];
|
|
||||||
exploredCells[q.X, q.Y] = true;
|
|
||||||
foggedCells[q.X, q.Y] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var box = new Rectangle(p.X - v.range, p.Y - v.range, 2 * v.range + 1, 2 * v.range + 1);
|
|
||||||
ExploredBounds = Rectangle.Union(ExploredBounds, box);
|
ExploredBounds = Rectangle.Union(ExploredBounds, box);
|
||||||
}
|
}
|
||||||
|
|
||||||
Invalidate();
|
// Update visibility
|
||||||
}
|
foreach (var c in visible)
|
||||||
|
|
||||||
public void HideActor(Actor a, int range)
|
|
||||||
{
|
|
||||||
if (a.Owner.IsAlliedWith(self.Owner))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var v = new ActorVisibility
|
|
||||||
{
|
{
|
||||||
vis = GetVisOrigins(a).ToArray()
|
visibleCount[c.X, c.Y]++;
|
||||||
};
|
explored[c.X, c.Y] = true;
|
||||||
|
|
||||||
foreach (var p in v.vis)
|
|
||||||
foreach (var q in FindVisibleTiles(a.World, p, range))
|
|
||||||
foggedCells[q.X, q.Y] = visibleCells[q.X, q.Y] > 0;
|
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnhideActor(Actor a, ActorVisibility v, int range)
|
|
||||||
{
|
|
||||||
if (a.Owner.IsAlliedWith(self.Owner) || v == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var p in v.vis)
|
|
||||||
foreach (var q in FindVisibleTiles(a.World, p, range))
|
|
||||||
foggedCells[q.X, q.Y] = exploredCells[q.X, q.Y];
|
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void MergeShroud(Shroud s)
|
|
||||||
{
|
|
||||||
for (int i = map.Bounds.Left; i < map.Bounds.Right; i++)
|
|
||||||
{
|
|
||||||
for (int j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
|
|
||||||
{
|
|
||||||
if (s.exploredCells[i,j] == true)
|
|
||||||
exploredCells[i, j] = true;
|
|
||||||
if (s.foggedCells[i,j] == true)
|
|
||||||
foggedCells[i, j] = true;
|
|
||||||
}
|
|
||||||
ExploredBounds = Rectangle.Union(ExploredBounds, s.ExploredBounds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
visibility[a] = visible;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveVisibility(Actor a)
|
||||||
|
{
|
||||||
|
CPos[] visible;
|
||||||
|
if (!visibility.TryGetValue(a, out visible))
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var c in visible)
|
||||||
|
visibleCount[c.X, c.Y]--;
|
||||||
|
|
||||||
|
visibility.Remove(a);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateVisibility(Actor a)
|
||||||
|
{
|
||||||
|
RemoveVisibility(a);
|
||||||
|
AddVisibility(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddShroudGeneration(Actor a)
|
||||||
|
{
|
||||||
|
var cs = a.TraitOrDefault<CreatesShroud>();
|
||||||
|
if (cs == null || a.Owner.IsAlliedWith(self.Owner) || cs.Range == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var shrouded = GetVisOrigins(a).SelectMany(o => FindVisibleTiles(a.World, o, cs.Range))
|
||||||
|
.Distinct().ToArray();
|
||||||
|
foreach (var c in shrouded)
|
||||||
|
generatedShroudCount[c.X, c.Y]++;
|
||||||
|
|
||||||
|
generation[a] = shrouded;
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveShroudGeneration(Actor a)
|
||||||
|
{
|
||||||
|
CPos[] shrouded;
|
||||||
|
if (!generation.TryGetValue(a, out shrouded))
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var c in shrouded)
|
||||||
|
generatedShroudCount[c.X, c.Y]--;
|
||||||
|
|
||||||
|
generation.Remove(a);
|
||||||
|
Invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateShroudGeneration(Actor a)
|
||||||
|
{
|
||||||
|
RemoveShroudGeneration(a);
|
||||||
|
AddShroudGeneration(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdatePlayerStance(World w, Player player, Stance oldStance, Stance newStance)
|
public void UpdatePlayerStance(World w, Player player, Stance oldStance, Stance newStance)
|
||||||
@@ -164,29 +175,11 @@ namespace OpenRA.Traits
|
|||||||
if (oldStance == newStance)
|
if (oldStance == newStance)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// No longer our ally; remove unit vis
|
foreach (var a in w.Actors.Where(a => a.Owner == player))
|
||||||
if (oldStance == Stance.Ally)
|
|
||||||
{
|
{
|
||||||
var toRemove = w.Actors.Where(a => a.Owner == player).ToList();
|
UpdateVisibility(a);
|
||||||
foreach (var a in toRemove)
|
UpdateShroudGeneration(a);
|
||||||
RemoveActor(a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is now our ally; add unit vis
|
|
||||||
if (newStance == Stance.Ally)
|
|
||||||
foreach (var a in w.Actors.Where( a => a.Owner == player ))
|
|
||||||
AddActor(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Explored()
|
|
||||||
{
|
|
||||||
int seen = 0;
|
|
||||||
for (int i = map.Bounds.Left; i < map.Bounds.Right; i++)
|
|
||||||
for (int j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
|
|
||||||
if (foggedCells[i, j])
|
|
||||||
seen++;
|
|
||||||
|
|
||||||
return seen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<CPos> GetVisOrigins(Actor a)
|
public static IEnumerable<CPos> GetVisOrigins(Actor a)
|
||||||
@@ -195,64 +188,40 @@ namespace OpenRA.Traits
|
|||||||
if (ios != null)
|
if (ios != null)
|
||||||
{
|
{
|
||||||
var cells = ios.OccupiedCells();
|
var cells = ios.OccupiedCells();
|
||||||
if (cells.Any()) return cells.Select(c => c.First);
|
if (cells.Any())
|
||||||
|
return cells.Select(c => c.First);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new[] { a.CenterLocation.ToCPos() };
|
return new[] { a.CenterLocation.ToCPos() };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveActor(Actor a)
|
|
||||||
{
|
|
||||||
ActorVisibility v = a.Sight;
|
|
||||||
if (!a.Owner.IsAlliedWith(self.Owner))
|
|
||||||
{
|
|
||||||
if (a.HasTrait<CreatesShroud>())
|
|
||||||
foreach (var p in v.vis)
|
|
||||||
foreach (var q in FindVisibleTiles(a.World, p, v.range))
|
|
||||||
foggedCells[q.X, q.Y] = exploredCells[q.X, q.Y];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!a.HasTrait<RevealsShroud>())
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var p in v.vis)
|
|
||||||
foreach (var q in FindVisibleTiles(a.World, p, v.range))
|
|
||||||
--visibleCells[q.X, q.Y];
|
|
||||||
|
|
||||||
Invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateActor(Actor a)
|
|
||||||
{
|
|
||||||
if (!a.Owner.IsAlliedWith(self.Owner))
|
|
||||||
return;
|
|
||||||
|
|
||||||
RemoveActor(a);
|
|
||||||
AddActor(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Explore(World world, CPos center, int range)
|
public void Explore(World world, CPos center, int range)
|
||||||
{
|
{
|
||||||
foreach (var q in FindVisibleTiles(world, center, range)) {
|
foreach (var q in FindVisibleTiles(world, center, range))
|
||||||
exploredCells[q.X, q.Y] = true;
|
explored[q.X, q.Y] = true;
|
||||||
foggedCells[q.X, q.Y] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
var box = new Rectangle(center.X - range, center.Y - range, 2 * range + 1, 2 * range + 1);
|
var box = new Rectangle(center.X - range, center.Y - range, 2*range + 1, 2*range + 1);
|
||||||
ExploredBounds = Rectangle.Union(ExploredBounds, box);
|
ExploredBounds = Rectangle.Union(ExploredBounds, box);
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Explore(Shroud s)
|
||||||
|
{
|
||||||
|
for (var i = map.Bounds.Left; i < map.Bounds.Right; i++)
|
||||||
|
for (var j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
|
||||||
|
if (s.explored[i,j] == true)
|
||||||
|
explored[i, j] = true;
|
||||||
|
|
||||||
|
ExploredBounds = Rectangle.Union(ExploredBounds, s.ExploredBounds);
|
||||||
|
}
|
||||||
|
|
||||||
public void ExploreAll(World world)
|
public void ExploreAll(World world)
|
||||||
{
|
{
|
||||||
for (int i = map.Bounds.Left; i < map.Bounds.Right; i++) {
|
for (var i = map.Bounds.Left; i < map.Bounds.Right; i++)
|
||||||
for (int j = map.Bounds.Top; j < map.Bounds.Bottom; j++) {
|
for (var j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
|
||||||
exploredCells[i, j] = true;
|
explored[i, j] = true;
|
||||||
foggedCells[i, j] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ExploredBounds = world.Map.Bounds;
|
ExploredBounds = world.Map.Bounds;
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
@@ -260,13 +229,9 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void ResetExploration()
|
public void ResetExploration()
|
||||||
{
|
{
|
||||||
for (var j = 0; j <= exploredCells.GetUpperBound(1); j++)
|
for (var i = map.Bounds.Left; i < map.Bounds.Right; i++)
|
||||||
for (var i = 0; i <= exploredCells.GetUpperBound(0); i++)
|
for (var j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
|
||||||
exploredCells[i, j] = visibleCells[i, j] > 0;
|
explored[i, j] = visibleCount[i, j] > 0;
|
||||||
|
|
||||||
for (var j = 0; j <= foggedCells.GetUpperBound(1); j++)
|
|
||||||
for (var i = 0; i <= foggedCells.GetUpperBound(0); i++)
|
|
||||||
foggedCells[i, j] = visibleCells[i, j] > 0;
|
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
@@ -280,7 +245,7 @@ namespace OpenRA.Traits
|
|||||||
if (!Info.Shroud)
|
if (!Info.Shroud)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return foggedCells[x,y];
|
return explored[x, y] && (generatedShroudCount[x, y] == 0 || visibleCount[x, y] > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsExplored(Actor a)
|
public bool IsExplored(Actor a)
|
||||||
@@ -299,7 +264,7 @@ namespace OpenRA.Traits
|
|||||||
if (!Info.Fog)
|
if (!Info.Fog)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return visibleCells[x,y] != 0;
|
return visibleCount[x, y] > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actors are hidden under shroud, but not under fog by default
|
// Actors are hidden under shroud, but not under fog by default
|
||||||
@@ -311,7 +276,8 @@ namespace OpenRA.Traits
|
|||||||
return a.Owner.IsAlliedWith(self.Owner) || IsExplored(a);
|
return a.Owner.IsAlliedWith(self.Owner) || IsExplored(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsTargetable(Actor a) {
|
public bool IsTargetable(Actor a)
|
||||||
|
{
|
||||||
if (a.TraitsImplementing<IVisibilityModifier>().Any(t => !t.IsVisible(a, self.Owner)))
|
if (a.TraitsImplementing<IVisibilityModifier>().Any(t => !t.IsVisible(a, self.Owner)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ namespace OpenRA.Mods.RA
|
|||||||
{
|
{
|
||||||
public void OnInfiltrate(Actor self, Actor infiltrator)
|
public void OnInfiltrate(Actor self, Actor infiltrator)
|
||||||
{
|
{
|
||||||
infiltrator.Owner.Shroud.MergeShroud(self.Owner.Shroud);
|
// Steal and reset the owners exploration
|
||||||
|
infiltrator.Owner.Shroud.Explore(self.Owner.Shroud);
|
||||||
if (!self.Owner.HasFogVisibility())
|
if (!self.Owner.HasFogVisibility())
|
||||||
self.Owner.Shroud.ResetExploration();
|
self.Owner.Shroud.ResetExploration();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA
|
|||||||
var total = (double)world.Map.Bounds.Width * world.Map.Bounds.Height;
|
var total = (double)world.Map.Bounds.Width * world.Map.Bounds.Height;
|
||||||
MapControl = world.Actors
|
MapControl = world.Actors
|
||||||
.Where(a => !a.IsDead() && a.IsInWorld && a.Owner == player && a.HasTrait<RevealsShroud>())
|
.Where(a => !a.IsDead() && a.IsInWorld && a.Owner == player && a.HasTrait<RevealsShroud>())
|
||||||
.SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait<RevealsShroud>().RevealRange.Clamp(0, 50)))
|
.SelectMany(a => world.FindTilesInCircle(a.Location, a.Trait<RevealsShroud>().Range.Clamp(0, 50)))
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.Count() / total;
|
.Count() / total;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user