Introducing per-player shrouds.
- Each player has their own shroud and their visibility does not extend outside of the shroud. - Units and buildings can no longer target other units outside of their visibility. Buildings can still be targetted if they have been explored. - GPS will provide visibility in the fog-of-war. - Spies that infiltrate radar domes will gain their victim's exploration and reset it on all clients (if the victim does not have GPS)
This commit is contained in:
@@ -29,8 +29,12 @@ namespace OpenRA.Traits
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (!self.IsDisabled())
|
||||
self.World.WorldActor.Trait<Shroud>().HideActor(self, Info.Range);
|
||||
if (!self.TraitsImplementing<IDisable>().Any(d => d.Disabled)) {
|
||||
var shrouds = self.World.ActorsWithTrait<Traits.Shroud>().Select(s => s.Actor.Owner.Shroud);
|
||||
foreach (var shroud in shrouds) {
|
||||
shroud.HideActor(self, Info.Range);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
DisableShroud ^= true;
|
||||
if (self.World.LocalPlayer == self.Owner)
|
||||
self.World.LocalShroud.Disabled = DisableShroud;
|
||||
self.World.RenderedShroud.Disabled = DisableShroud;
|
||||
break;
|
||||
}
|
||||
case "DevPathDebug":
|
||||
@@ -88,7 +88,7 @@ namespace OpenRA.Traits
|
||||
case "DevGiveExploration":
|
||||
{
|
||||
if (self.World.LocalPlayer == self.Owner)
|
||||
self.World.WorldActor.Trait<Shroud>().ExploreAll(self.World);
|
||||
self.World.LocalPlayer.Shroud.ExploreAll(self.World);
|
||||
break;
|
||||
}
|
||||
case "DevUnlimitedPower":
|
||||
|
||||
@@ -29,11 +29,22 @@ namespace OpenRA.Traits
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
// todo: don't tick all the time.
|
||||
|
||||
World w = self.World;
|
||||
if(self.Owner == null) return;
|
||||
|
||||
if (previousLocation != self.Location)
|
||||
{
|
||||
previousLocation = self.Location;
|
||||
self.World.WorldActor.Trait<Shroud>().UpdateActor(self);
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRA.Traits
|
||||
|
||||
void DrawPips(WorldRenderer wr, Actor self, float2 basePosition)
|
||||
{
|
||||
if (self.Owner != self.World.LocalPlayer) return;
|
||||
if (self.Owner != self.World.RenderedPlayer) return;
|
||||
|
||||
var pipSources = self.TraitsImplementing<IPips>();
|
||||
if (pipSources.Count() == 0)
|
||||
@@ -95,7 +95,7 @@ namespace OpenRA.Traits
|
||||
|
||||
void DrawTags(WorldRenderer wr, Actor self, float2 basePosition)
|
||||
{
|
||||
if (self.Owner != self.World.LocalPlayer) return;
|
||||
if (self.Owner != self.World.RenderedPlayer) return;
|
||||
|
||||
// If a mod wants to implement a unit with multiple tags, then they are placed on multiple rows
|
||||
var tagxyBase = basePosition + new float2(-16, 2); // Correct for the offset in the shp file
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace OpenRA.Traits
|
||||
Color RadarSignatureColor(Actor self);
|
||||
}
|
||||
|
||||
public interface IVisibilityModifier { bool IsVisible(Actor self); }
|
||||
public interface IVisibilityModifier { bool IsVisible(Shroud s, Actor self); }
|
||||
public interface IRadarColorModifier { Color RadarColorOverride(Actor self); }
|
||||
public interface IHasLocation { PPos PxPosition { get; } }
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace OpenRA.Traits
|
||||
public interface ILintPass { void Run(Action<string> emitError, Action<string> emitWarning); }
|
||||
|
||||
public interface IObjectivesPanel { string ObjectivesPanel { get; } }
|
||||
|
||||
|
||||
public static class DisableExts
|
||||
{
|
||||
public static bool IsDisabled(this Actor a)
|
||||
|
||||
@@ -40,7 +40,7 @@ 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 CPos(x, y)))
|
||||
if (!world.RenderedShroud.IsExplored(new CPos(x, y)))
|
||||
continue;
|
||||
|
||||
var c = content[x, y];
|
||||
|
||||
@@ -25,16 +25,23 @@ namespace OpenRA.Traits
|
||||
Map map;
|
||||
World world;
|
||||
|
||||
public Player Owner;
|
||||
public int[,] visibleCells;
|
||||
public bool[,] exploredCells;
|
||||
Rectangle? exploredBounds;
|
||||
public Rectangle? exploredBounds;
|
||||
bool disabled = false;
|
||||
public bool dirty = true;
|
||||
public bool Disabled
|
||||
{
|
||||
get { return disabled || world.LocalPlayer == null; }
|
||||
get { return disabled; }
|
||||
set { disabled = value; Dirty(); }
|
||||
}
|
||||
|
||||
public bool Observing
|
||||
{
|
||||
get { return world.IsShellmap || (world.LocalPlayer == null && Owner == null);; }
|
||||
}
|
||||
|
||||
public Rectangle? Bounds
|
||||
{
|
||||
get { return Disabled ? null : exploredBounds; }
|
||||
@@ -42,6 +49,12 @@ namespace OpenRA.Traits
|
||||
|
||||
public event Action Dirty = () => { };
|
||||
|
||||
public void Jank()
|
||||
{
|
||||
Dirty();
|
||||
}
|
||||
|
||||
|
||||
public Shroud(World world)
|
||||
{
|
||||
this.world = world;
|
||||
@@ -50,12 +63,13 @@ namespace OpenRA.Traits
|
||||
exploredCells = new bool[map.MapSize.X, map.MapSize.Y];
|
||||
world.ActorAdded += AddActor;
|
||||
world.ActorRemoved += RemoveActor;
|
||||
Dirty += () => dirty = true;
|
||||
}
|
||||
|
||||
// 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 CPos[] vis; }
|
||||
Dictionary<Actor, ActorVisibility> vis = new Dictionary<Actor, ActorVisibility>();
|
||||
public class ActorVisibility { public int range; public CPos[] vis; }
|
||||
public Dictionary<Actor, ActorVisibility> vis = new Dictionary<Actor, ActorVisibility>();
|
||||
|
||||
static IEnumerable<CPos> FindVisibleTiles(World world, CPos a, int r)
|
||||
{
|
||||
@@ -72,25 +86,13 @@ namespace OpenRA.Traits
|
||||
yield return new CPos(i, j);
|
||||
}
|
||||
|
||||
void AddActor(Actor a)
|
||||
public void AddActor(Actor a)
|
||||
{
|
||||
if (!a.HasTrait<RevealsShroud>())
|
||||
return;
|
||||
|
||||
if (a.Owner.World.LocalPlayer == null
|
||||
|| a.Owner.Stances[a.Owner.World.LocalPlayer] != Stance.Ally) return;
|
||||
|
||||
if (vis.ContainsKey(a))
|
||||
{
|
||||
Game.Debug("Warning: Actor {0}:{1} at {2} bad vis".F(a.Info.Name, a.ActorID, a.Location));
|
||||
RemoveActor(a);
|
||||
}
|
||||
|
||||
var v = new ActorVisibility
|
||||
{
|
||||
range = a.Trait<RevealsShroud>().RevealRange,
|
||||
vis = GetVisOrigins(a).ToArray()
|
||||
};
|
||||
if (!a.HasTrait<RevealsShroud>()) return;
|
||||
if (a.Owner == null || Owner == null) return;
|
||||
if(a.Owner.Stances[Owner] != Stance.Ally) return;
|
||||
|
||||
ActorVisibility v = a.Sight;
|
||||
|
||||
if (v.range == 0) return; // don't bother for things that can't see
|
||||
|
||||
@@ -106,8 +108,6 @@ namespace OpenRA.Traits
|
||||
exploredBounds = (exploredBounds.HasValue) ? Rectangle.Union(exploredBounds.Value, box) : box;
|
||||
}
|
||||
|
||||
vis[a] = v;
|
||||
|
||||
if (!Disabled)
|
||||
Dirty();
|
||||
}
|
||||
@@ -129,6 +129,16 @@ namespace OpenRA.Traits
|
||||
if (!Disabled)
|
||||
Dirty();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
exploredBounds = Rectangle.Union(exploredBounds.Value, s.exploredBounds.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePlayerStance(World w, Player player, Stance oldStance, Stance newStance)
|
||||
{
|
||||
@@ -138,7 +148,7 @@ namespace OpenRA.Traits
|
||||
// No longer our ally; remove unit vis
|
||||
if (oldStance == Stance.Ally)
|
||||
{
|
||||
var toRemove = vis.Select(a => a.Key).Where(a => a.Owner == player).ToList();
|
||||
var toRemove = w.Actors.Where(a => a.Owner == player).ToList();
|
||||
foreach (var a in toRemove)
|
||||
RemoveActor(a);
|
||||
}
|
||||
@@ -147,6 +157,16 @@ namespace OpenRA.Traits
|
||||
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(exploredCells[i, j]) seen++;
|
||||
|
||||
return seen;
|
||||
}
|
||||
|
||||
public static IEnumerable<CPos> GetVisOrigins(Actor a)
|
||||
{
|
||||
@@ -160,17 +180,18 @@ namespace OpenRA.Traits
|
||||
return new[] { a.CenterLocation.ToCPos() };
|
||||
}
|
||||
|
||||
void RemoveActor(Actor a)
|
||||
public void RemoveActor(Actor a)
|
||||
{
|
||||
ActorVisibility v;
|
||||
if (!vis.TryGetValue(a, out v)) return;
|
||||
if (!a.HasTrait<RevealsShroud>())return;
|
||||
if (a.Owner == null || Owner == null) return;
|
||||
if(a.Owner.Stances[Owner] != Stance.Ally) return;
|
||||
|
||||
ActorVisibility v = a.Sight;
|
||||
|
||||
foreach (var p in v.vis)
|
||||
foreach (var q in FindVisibleTiles(a.World, p, v.range))
|
||||
--visibleCells[q.X, q.Y];
|
||||
|
||||
vis.Remove(a);
|
||||
|
||||
if (!Disabled)
|
||||
Dirty();
|
||||
}
|
||||
@@ -222,7 +243,7 @@ namespace OpenRA.Traits
|
||||
if (!map.IsInMap(x, y))
|
||||
return false;
|
||||
|
||||
if (Disabled)
|
||||
if (Disabled || Observing)
|
||||
return true;
|
||||
|
||||
return exploredCells[x,y];
|
||||
@@ -231,7 +252,7 @@ namespace OpenRA.Traits
|
||||
public bool IsVisible(CPos xy) { return IsVisible(xy.X, xy.Y); }
|
||||
public bool IsVisible(int x, int y)
|
||||
{
|
||||
if (Disabled)
|
||||
if (Disabled || Observing)
|
||||
return true;
|
||||
|
||||
// Visibility is allowed to extend beyond the map cordon so that
|
||||
@@ -245,10 +266,20 @@ namespace OpenRA.Traits
|
||||
// Actors are hidden under shroud, but not under fog by default
|
||||
public bool IsVisible(Actor a)
|
||||
{
|
||||
if (a.TraitsImplementing<IVisibilityModifier>().Any(t => !t.IsVisible(a)))
|
||||
// I need to pass in the current shroud, otherwise we're just checking that true==true
|
||||
if (a.TraitsImplementing<IVisibilityModifier>().Any(t => !t.IsVisible(this, a)))
|
||||
return false;
|
||||
|
||||
return Disabled || a.Owner == a.World.LocalPlayer || GetVisOrigins(a).Any(o => IsExplored(o));
|
||||
if(Owner == null) return true;
|
||||
|
||||
return Disabled || Observing || a.Owner.Stances[Owner] == Stance.Ally || GetVisOrigins(a).Any(o => IsExplored(o));
|
||||
}
|
||||
|
||||
public bool IsTargetable(Actor a) {
|
||||
if (a.TraitsImplementing<IVisibilityModifier>().Any(t => !t.IsVisible(this, a)))
|
||||
return false;
|
||||
|
||||
return GetVisOrigins(a).Any(o => IsVisible(o));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user