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:
Kenny
2012-12-13 15:16:56 -08:00
parent 5249a17d48
commit f41fb32d60
48 changed files with 351 additions and 159 deletions

View File

@@ -43,6 +43,8 @@ namespace OpenRA
return HasLocation.PxPosition; return HasLocation.PxPosition;
} }
} }
public Shroud.ActorVisibility Sight;
[Sync] [Sync]
public Player Owner; public Player Owner;
@@ -85,6 +87,16 @@ namespace OpenRA
return (firstSprite.Sprite.size * firstSprite.Scale).ToInt2(); return (firstSprite.Sprite.size * firstSprite.Scale).ToInt2();
}); });
if(this.HasTrait<RevealsShroud>())
{
Sight = new Shroud.ActorVisibility
{
range = this.Trait<RevealsShroud>().RevealRange,
vis = Shroud.GetVisOrigins(this).ToArray()
};
}
ApplyIRender = x => x.Render(this); ApplyIRender = x => x.Render(this);
ApplyRenderModifier = (m, p) => p.ModifyRender(this, m); ApplyRenderModifier = (m, p) => p.ModifyRender(this, m);
@@ -99,6 +111,11 @@ namespace OpenRA
currentActivity = Util.RunActivity( this, currentActivity ); currentActivity = Util.RunActivity( this, currentActivity );
} }
public void UpdateSight()
{
Sight.vis = Shroud.GetVisOrigins(this).ToArray();
}
public bool IsIdle public bool IsIdle
{ {

View File

@@ -139,7 +139,7 @@ namespace OpenRA.Graphics
foreach (var t in world.ActorsWithTrait<IRadarSignature>()) foreach (var t in world.ActorsWithTrait<IRadarSignature>())
{ {
if (!world.LocalShroud.IsVisible(t.Actor)) if (!world.RenderedShroud.IsVisible(t.Actor))
continue; continue;
var color = t.Trait.RadarSignatureColor(t.Actor); var color = t.Trait.RadarSignatureColor(t.Actor);
@@ -158,7 +158,7 @@ namespace OpenRA.Graphics
var map = world.Map; var map = world.Map;
var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height)); var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
var bitmap = new Bitmap(size, size); var bitmap = new Bitmap(size, size);
if (world.LocalShroud.Disabled) if (world.RenderedShroud.Disabled)
return bitmap; return bitmap;
var bitmapData = bitmap.LockBits(bitmap.Bounds(), var bitmapData = bitmap.LockBits(bitmap.Bounds(),
@@ -176,9 +176,9 @@ namespace OpenRA.Graphics
{ {
var mapX = x + map.Bounds.Left; var mapX = x + map.Bounds.Left;
var mapY = y + map.Bounds.Top; var mapY = y + map.Bounds.Top;
if (!world.LocalShroud.IsExplored(mapX, mapY)) if (!world.RenderedShroud.IsExplored(mapX, mapY))
*(c + (y * bitmapData.Stride >> 2) + x) = shroud; *(c + (y * bitmapData.Stride >> 2) + x) = shroud;
else if (!world.LocalShroud.IsVisible(mapX,mapY)) else if (!world.RenderedShroud.IsVisible(mapX,mapY))
*(c + (y * bitmapData.Stride >> 2) + x) = fog; *(c + (y * bitmapData.Stride >> 2) + x) = fog;
} }
} }

View File

@@ -15,21 +15,25 @@ namespace OpenRA.Graphics
{ {
public class ShroudRenderer public class ShroudRenderer
{ {
Traits.Shroud shroud; World world;
Traits.Shroud shroud {
get {
return world.RenderedShroud;
}
}
Sprite[] shadowBits = Game.modData.SpriteLoader.LoadAllSprites("shadow"); Sprite[] shadowBits = Game.modData.SpriteLoader.LoadAllSprites("shadow");
Sprite[,] sprites, fogSprites; Sprite[,] sprites, fogSprites;
bool dirty = true;
Map map; Map map;
public ShroudRenderer(World world) public ShroudRenderer(World world)
{ {
this.shroud = world.LocalShroud; this.world = world;
this.map = world.Map; this.map = world.Map;
sprites = new Sprite[map.MapSize.X, map.MapSize.Y]; sprites = new Sprite[map.MapSize.X, map.MapSize.Y];
fogSprites = new Sprite[map.MapSize.X, map.MapSize.Y]; fogSprites = new Sprite[map.MapSize.X, map.MapSize.Y];
shroud.Dirty += () => dirty = true;
} }
static readonly byte[][] SpecialShroudTiles = static readonly byte[][] SpecialShroudTiles =
@@ -103,9 +107,9 @@ namespace OpenRA.Graphics
internal void Draw( WorldRenderer wr ) internal void Draw( WorldRenderer wr )
{ {
if (dirty) if (shroud != null && shroud.dirty)
{ {
dirty = false; shroud.dirty = false;
for (int i = map.Bounds.Left; i < map.Bounds.Right; i++) for (int i = map.Bounds.Left; i < map.Bounds.Right; i++)
for (int j = map.Bounds.Top; j < map.Bounds.Bottom; j++) for (int j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
sprites[i, j] = ChooseShroud(i, j); sprites[i, j] = ChooseShroud(i, j);

View File

@@ -72,9 +72,9 @@ namespace OpenRA.Graphics
if (firstRow < 0) firstRow = 0; if (firstRow < 0) firstRow = 0;
if (lastRow > map.Bounds.Height) lastRow = map.Bounds.Height; if (lastRow > map.Bounds.Height) lastRow = map.Bounds.Height;
if (world.LocalPlayer != null && !world.LocalShroud.Disabled && world.LocalShroud.Bounds.HasValue) if (world.RenderedPlayer != null && !world.RenderedShroud.Disabled && world.RenderedShroud.Bounds.HasValue)
{ {
var r = world.LocalShroud.Bounds.Value; var r = world.RenderedShroud.Bounds.Value;
if (firstRow < r.Top - map.Bounds.Top) if (firstRow < r.Top - map.Bounds.Top)
firstRow = r.Top - map.Bounds.Top; firstRow = r.Top - map.Bounds.Top;

View File

@@ -202,7 +202,7 @@ namespace OpenRA.Graphics
cachedScroll = scrollPosition; cachedScroll = scrollPosition;
} }
var b = world.LocalShroud.Bounds; var b = world.RenderedShroud.Bounds;
return (b.HasValue) ? Rectangle.Intersect(cachedRect, b.Value) : cachedRect; return (b.HasValue) ? Rectangle.Intersect(cachedRect, b.Value) : cachedRect;
} }
} }

View File

@@ -198,8 +198,7 @@ namespace OpenRA.Network
{ {
var oldStance = p.Stances[target]; var oldStance = p.Stances[target];
p.Stances[target] = s; p.Stances[target] = s;
if (target == w.LocalPlayer) target.Shroud.UpdatePlayerStance(w, p, oldStance, s);
w.WorldActor.Trait<Shroud>().UpdatePlayerStance(w, p, oldStance, s);
foreach (var nsc in w.ActorsWithTrait<INotifyStanceChanged>()) foreach (var nsc in w.ActorsWithTrait<INotifyStanceChanged>())
nsc.Trait.StanceChanged(nsc.Actor, p, target, oldStance, s); nsc.Trait.StanceChanged(nsc.Actor, p, target, oldStance, s);

View File

@@ -36,7 +36,7 @@ namespace OpenRA
public readonly PlayerReference PlayerReference; public readonly PlayerReference PlayerReference;
public bool IsBot; public bool IsBot;
public Shroud Shroud { get { return World.LocalShroud; } } public Shroud Shroud;
public World World { get; private set; } public World World { get; private set; }
static CountryInfo ChooseCountry(World world, string name) static CountryInfo ChooseCountry(World world, string name)
@@ -68,7 +68,7 @@ namespace OpenRA
else else
{ {
// Map player // Map player
ClientIndex = 0; // Owned by the host (todo: fix this) ClientIndex = -1; // Owned by the host (todo: fix this)
ColorRamp = pr.ColorRamp; ColorRamp = pr.ColorRamp;
PlayerName = pr.Name; PlayerName = pr.Name;
NonCombatant = pr.NonCombatant; NonCombatant = pr.NonCombatant;
@@ -76,7 +76,8 @@ namespace OpenRA
Country = ChooseCountry(world, pr.Race); Country = ChooseCountry(world, pr.Race);
} }
PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) });
Shroud = PlayerActor.Trait<Shroud>();
Shroud.Owner = this;
// Enable the bot logic on the host // Enable the bot logic on the host
IsBot = botType != null; IsBot = botType != null;
if (IsBot && Game.IsHost) if (IsBot && Game.IsHost)

View File

@@ -29,8 +29,12 @@ namespace OpenRA.Traits
public void Tick(Actor self) public void Tick(Actor self)
{ {
if (!self.IsDisabled()) if (!self.TraitsImplementing<IDisable>().Any(d => d.Disabled)) {
self.World.WorldActor.Trait<Shroud>().HideActor(self, Info.Range); var shrouds = self.World.ActorsWithTrait<Traits.Shroud>().Select(s => s.Actor.Owner.Shroud);
foreach (var shroud in shrouds) {
shroud.HideActor(self, Info.Range);
}
}
} }
} }
} }

View File

@@ -77,7 +77,7 @@ namespace OpenRA.Traits
{ {
DisableShroud ^= true; DisableShroud ^= true;
if (self.World.LocalPlayer == self.Owner) if (self.World.LocalPlayer == self.Owner)
self.World.LocalShroud.Disabled = DisableShroud; self.World.RenderedShroud.Disabled = DisableShroud;
break; break;
} }
case "DevPathDebug": case "DevPathDebug":
@@ -88,7 +88,7 @@ namespace OpenRA.Traits
case "DevGiveExploration": case "DevGiveExploration":
{ {
if (self.World.LocalPlayer == self.Owner) if (self.World.LocalPlayer == self.Owner)
self.World.WorldActor.Trait<Shroud>().ExploreAll(self.World); self.World.LocalPlayer.Shroud.ExploreAll(self.World);
break; break;
} }
case "DevUnlimitedPower": case "DevUnlimitedPower":

View File

@@ -29,11 +29,22 @@ namespace OpenRA.Traits
public void Tick(Actor self) public void Tick(Actor self)
{ {
// todo: don't tick all the time. // todo: don't tick all the time.
World w = self.World;
if(self.Owner == null) return;
if (previousLocation != self.Location) if (previousLocation != self.Location)
{ {
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);
} }
} }

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Traits
void DrawPips(WorldRenderer wr, Actor self, float2 basePosition) 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>(); var pipSources = self.TraitsImplementing<IPips>();
if (pipSources.Count() == 0) if (pipSources.Count() == 0)
@@ -95,7 +95,7 @@ namespace OpenRA.Traits
void DrawTags(WorldRenderer wr, Actor self, float2 basePosition) 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 // 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 var tagxyBase = basePosition + new float2(-16, 2); // Correct for the offset in the shp file

View File

@@ -83,7 +83,7 @@ namespace OpenRA.Traits
Color RadarSignatureColor(Actor self); 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 IRadarColorModifier { Color RadarColorOverride(Actor self); }
public interface IHasLocation { PPos PxPosition { get; } } 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 ILintPass { void Run(Action<string> emitError, Action<string> emitWarning); }
public interface IObjectivesPanel { string ObjectivesPanel { get; } } public interface IObjectivesPanel { string ObjectivesPanel { get; } }
public static class DisableExts public static class DisableExts
{ {
public static bool IsDisabled(this Actor a) public static bool IsDisabled(this Actor a)

View File

@@ -40,7 +40,7 @@ namespace OpenRA.Traits
for (int x = clip.Left; x < clip.Right; x++) for (int x = clip.Left; x < clip.Right; x++)
for (int y = clip.Top; y < clip.Bottom; y++) 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; continue;
var c = content[x, y]; var c = content[x, y];

View File

@@ -25,16 +25,23 @@ namespace OpenRA.Traits
Map map; Map map;
World world; World world;
public Player Owner;
public int[,] visibleCells; public int[,] visibleCells;
public bool[,] exploredCells; public bool[,] exploredCells;
Rectangle? exploredBounds; public Rectangle? exploredBounds;
bool disabled = false; bool disabled = false;
public bool dirty = true;
public bool Disabled public bool Disabled
{ {
get { return disabled || world.LocalPlayer == null; } get { return disabled; }
set { disabled = value; Dirty(); } set { disabled = value; Dirty(); }
} }
public bool Observing
{
get { return world.IsShellmap || (world.LocalPlayer == null && Owner == null);; }
}
public Rectangle? Bounds public Rectangle? Bounds
{ {
get { return Disabled ? null : exploredBounds; } get { return Disabled ? null : exploredBounds; }
@@ -42,6 +49,12 @@ namespace OpenRA.Traits
public event Action Dirty = () => { }; public event Action Dirty = () => { };
public void Jank()
{
Dirty();
}
public Shroud(World world) public Shroud(World world)
{ {
this.world = world; this.world = world;
@@ -50,12 +63,13 @@ namespace OpenRA.Traits
exploredCells = new bool[map.MapSize.X, map.MapSize.Y]; exploredCells = new bool[map.MapSize.X, map.MapSize.Y];
world.ActorAdded += AddActor; world.ActorAdded += AddActor;
world.ActorRemoved += RemoveActor; world.ActorRemoved += RemoveActor;
Dirty += () => dirty = true;
} }
// cache of positions that were added, so no matter what crazy trait code does, it // cache of positions that were added, so no matter what crazy trait code does, it
// can't make us invalid. // can't make us invalid.
class ActorVisibility { public int range; public CPos[] vis; } public class ActorVisibility { public int range; public CPos[] vis; }
Dictionary<Actor, ActorVisibility> vis = new Dictionary<Actor, ActorVisibility>(); 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)
{ {
@@ -72,25 +86,13 @@ namespace OpenRA.Traits
yield return new CPos(i, j); yield return new CPos(i, j);
} }
void AddActor(Actor a) public void AddActor(Actor a)
{ {
if (!a.HasTrait<RevealsShroud>()) if (!a.HasTrait<RevealsShroud>()) return;
return; if (a.Owner == null || Owner == null) return;
if(a.Owner.Stances[Owner] != Stance.Ally) return;
if (a.Owner.World.LocalPlayer == null
|| a.Owner.Stances[a.Owner.World.LocalPlayer] != Stance.Ally) return; ActorVisibility v = a.Sight;
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 (v.range == 0) return; // don't bother for things that can't see 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; exploredBounds = (exploredBounds.HasValue) ? Rectangle.Union(exploredBounds.Value, box) : box;
} }
vis[a] = v;
if (!Disabled) if (!Disabled)
Dirty(); Dirty();
} }
@@ -129,6 +129,16 @@ namespace OpenRA.Traits
if (!Disabled) if (!Disabled)
Dirty(); 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) 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 // No longer our ally; remove unit vis
if (oldStance == Stance.Ally) 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) foreach (var a in toRemove)
RemoveActor(a); RemoveActor(a);
} }
@@ -147,6 +157,16 @@ namespace OpenRA.Traits
foreach (var a in w.Actors.Where( a => a.Owner == player )) foreach (var a in w.Actors.Where( a => a.Owner == player ))
AddActor(a); 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) public static IEnumerable<CPos> GetVisOrigins(Actor a)
{ {
@@ -160,17 +180,18 @@ namespace OpenRA.Traits
return new[] { a.CenterLocation.ToCPos() }; return new[] { a.CenterLocation.ToCPos() };
} }
void RemoveActor(Actor a) public void RemoveActor(Actor a)
{ {
ActorVisibility v; if (!a.HasTrait<RevealsShroud>())return;
if (!vis.TryGetValue(a, out v)) 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 p in v.vis)
foreach (var q in FindVisibleTiles(a.World, p, v.range)) foreach (var q in FindVisibleTiles(a.World, p, v.range))
--visibleCells[q.X, q.Y]; --visibleCells[q.X, q.Y];
vis.Remove(a);
if (!Disabled) if (!Disabled)
Dirty(); Dirty();
} }
@@ -222,7 +243,7 @@ namespace OpenRA.Traits
if (!map.IsInMap(x, y)) if (!map.IsInMap(x, y))
return false; return false;
if (Disabled) if (Disabled || Observing)
return true; return true;
return exploredCells[x,y]; 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(CPos xy) { return IsVisible(xy.X, xy.Y); }
public bool IsVisible(int x, int y) public bool IsVisible(int x, int y)
{ {
if (Disabled) if (Disabled || Observing)
return true; return true;
// Visibility is allowed to extend beyond the map cordon so that // 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 // Actors are hidden under shroud, but not under fog by default
public bool IsVisible(Actor a) 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 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));
} }
} }
} }

View File

@@ -164,7 +164,7 @@ namespace OpenRA.Widgets
IEnumerable<Actor> SelectActorsInBox(World world, PPos a, PPos b, Func<Actor, bool> cond) IEnumerable<Actor> SelectActorsInBox(World world, PPos a, PPos b, Func<Actor, bool> cond)
{ {
return world.FindUnits(a, b) return world.FindUnits(a, b)
.Where( x => x.HasTrait<Selectable>() && world.LocalShroud.IsVisible(x) && cond(x) ) .Where( x => x.HasTrait<Selectable>() && world.RenderedShroud.IsVisible(x) && cond(x) )
.GroupBy(x => x.GetSelectionPriority()) .GroupBy(x => x.GetSelectionPriority())
.OrderByDescending(g => g.Key) .OrderByDescending(g => g.Key)
.Select( g => g.AsEnumerable() ) .Select( g => g.AsEnumerable() )

View File

@@ -41,10 +41,29 @@ namespace OpenRA
public Player LocalPlayer { get; private set; } public Player LocalPlayer { get; private set; }
public readonly Shroud LocalShroud; public readonly Shroud LocalShroud;
public Player RenderedPlayer;
public Shroud RenderedShroud {
get {
if(RenderedPlayer == null)
{
return LocalShroud;
}else{
return RenderedPlayer.Shroud;
}
}
}
public void SetLocalPlayer(string pr) public void SetLocalPlayer(string pr)
{ {
if (!(orderManager.Connection is ReplayConnection)) if (!(orderManager.Connection is ReplayConnection))
LocalPlayer = Players.FirstOrDefault(p => p.InternalName == pr); {
LocalPlayer = Players.FirstOrDefault(p => p.InternalName == pr);
RenderedPlayer = LocalPlayer;
}else{
}
} }
public readonly Actor WorldActor; public readonly Actor WorldActor;
@@ -138,6 +157,7 @@ namespace OpenRA
a.IsInWorld = false; a.IsInWorld = false;
actors.Remove(a); actors.Remove(a);
ActorRemoved(a); ActorRemoved(a);
} }
public void Add(IEffect b) { effects.Add(b); } public void Add(IEffect b) { effects.Add(b); }

View File

@@ -24,7 +24,7 @@ namespace OpenRA
public static IEnumerable<Actor> FindUnitsAtMouse(this World world, int2 mouseLocation) public static IEnumerable<Actor> FindUnitsAtMouse(this World world, int2 mouseLocation)
{ {
var loc = Game.viewport.ViewToWorldPx(mouseLocation); var loc = Game.viewport.ViewToWorldPx(mouseLocation);
return FindUnits(world, loc, loc).Where(a => world.LocalShroud.IsVisible(a)); return FindUnits(world, loc, loc).Where(a => world.RenderedShroud.IsVisible(a));
} }
public static IEnumerable<Actor> FindUnits(this World world, PPos a, PPos b) public static IEnumerable<Actor> FindUnits(this World world, PPos a, PPos b)

View File

@@ -54,6 +54,9 @@ namespace OpenRA.Mods.RA.Activities
if (!Target.IsValid) if (!Target.IsValid)
return NextActivity; return NextActivity;
if (!self.Owner.HasFogVisibility() && Target.Actor != null && Target.Actor.HasTrait<Mobile>() && !self.Owner.Shroud.IsTargetable(Target.Actor))
return NextActivity;
if (targetable != null && !targetable.TargetableBy(Target.Actor, self)) if (targetable != null && !targetable.TargetableBy(Target.Actor, self))
return NextActivity; return NextActivity;

View File

@@ -50,6 +50,7 @@ namespace OpenRA.Mods.RA
{ {
return new TeslaAttack( newTarget ); return new TeslaAttack( newTarget );
} }
public override void ResolveOrder(Actor self, Order order) public override void ResolveOrder(Actor self, Order order)
{ {

View File

@@ -111,11 +111,21 @@ namespace OpenRA.Mods.RA
var inRange = self.World.FindUnitsInCircle(self.CenterLocation, (int)(Game.CellSize * range)); var inRange = self.World.FindUnitsInCircle(self.CenterLocation, (int)(Game.CellSize * range));
return inRange if (self.Owner.HasFogVisibility()) {
.Where(a => a.AppearsHostileTo(self)) return inRange
.Where(a => !a.HasTrait<AutoTargetIgnore>()) .Where(a => a.AppearsHostileTo(self))
.Where(a => attack.HasAnyValidWeapons(Target.FromActor(a))) .Where(a => !a.HasTrait<AutoTargetIgnore>())
.ClosestTo( self.CenterLocation ); .Where(a => attack.HasAnyValidWeapons(Target.FromActor(a)))
.ClosestTo( self.CenterLocation );
}
else {
return inRange
.Where(a => a.AppearsHostileTo(self))
.Where(a => !a.HasTrait<AutoTargetIgnore>())
.Where(a => attack.HasAnyValidWeapons(Target.FromActor(a)))
.Where(a => self.Owner.Shroud.IsTargetable(a))
.ClosestTo( self.CenterLocation );
}
} }
} }

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA.Buildings
{ {
if (!cliprect.Contains(kv.Key.X, kv.Key.Y)) if (!cliprect.Contains(kv.Key.X, kv.Key.Y))
continue; continue;
if (!world.LocalShroud.IsExplored(kv.Key)) if (!world.RenderedShroud.IsExplored(kv.Key))
continue; continue;
bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt(wr, kv.Key.ToPPos().ToFloat2(), "terrain"); bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt(wr, kv.Key.ToPPos().ToFloat2(), "terrain");

View File

@@ -97,7 +97,7 @@ namespace OpenRA.Mods.RA
if (chargeTick <= 0 // Can jump if (chargeTick <= 0 // Can jump
&& (self.Location - xy).Length <= Info.JumpDistance // Within jump range && (self.Location - xy).Length <= Info.JumpDistance // Within jump range
&& movement.CanEnterCell(xy) // Can enter cell && movement.CanEnterCell(xy) // Can enter cell
&& (ignoreVis || self.World.LocalShroud.IsExplored(xy))) // Not in shroud && (ignoreVis || self.Owner.Shroud.IsExplored(xy))) // Not in shroud
return true; return true;
else else
return false; return false;

View File

@@ -44,12 +44,10 @@ namespace OpenRA.Mods.RA
} }
// Can't be used in synced code, except with ignoreVis. // Can't be used in synced code, except with ignoreVis.
public virtual bool CanChronoshiftTo(Actor self, CPos targetLocation, bool ignoreVis) public virtual bool CanChronoshiftTo(Actor self, CPos targetLocation)
{ {
// Todo: Allow enemy units to be chronoshifted into bad terrain to kill them // Todo: Allow enemy units to be chronoshifted into bad terrain to kill them
return self.HasTrait<ITeleportable>() && return (self.HasTrait<ITeleportable>() && self.Trait<ITeleportable>().CanEnterCell(targetLocation));
self.Trait<ITeleportable>().CanEnterCell(targetLocation) &&
(ignoreVis || self.World.LocalShroud.IsExplored(targetLocation));
} }
public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere) public virtual bool Teleport(Actor self, CPos targetLocation, int duration, bool killCargo, Actor chronosphere)

View File

@@ -92,14 +92,27 @@ namespace OpenRA.Mods.RA
lastPos = self.Location; lastPos = self.Location;
} }
} }
public bool IsVisible(Actor self) public bool IsVisible(Actor self)
{ {
if (!Cloaked || self.Owner == self.World.LocalPlayer || return IsVisible(null, self);
self.World.LocalPlayer == null || }
self.Owner.Stances[self.World.LocalPlayer] == Stance.Ally)
return true;
public bool IsVisible(Shroud s, Actor self)
{
if (self.World.LocalPlayer != null) {
if (s == null) {
if (!Cloaked || self.Owner == self.World.LocalPlayer ||
self.Owner.Stances[self.World.LocalPlayer] == Stance.Ally)
return true;
}
else {
if (!Cloaked || self.Owner == s.Owner ||
self.Owner.Stances[s.Owner] == Stance.Ally)
return true;
}
}
return self.World.ActorsWithTrait<DetectCloaked>().Any(a => return self.World.ActorsWithTrait<DetectCloaked>().Any(a =>
a.Actor.Owner.Stances[self.Owner] != Stance.Ally && a.Actor.Owner.Stances[self.Owner] != Stance.Ally &&
(self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<DetectCloakedInfo>().Range); (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<DetectCloakedInfo>().Range);

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Mods.RA
if (self.Owner == self.World.LocalPlayer) if (self.Owner == self.World.LocalPlayer)
{ {
self.World.LocalShroud.Disabled = true; self.World.RenderedShroud.Disabled = true;
Game.RunAfterDelay(Info.NotificationDelay, () => Game.RunAfterDelay(Info.NotificationDelay, () =>
{ {
if (Game.IsCurrentWorld(self.World)) if (Game.IsCurrentWorld(self.World))
@@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA
Game.Debug("{0} is victorious.".F(self.Owner.PlayerName)); Game.Debug("{0} is victorious.".F(self.Owner.PlayerName));
if (self.Owner == self.World.LocalPlayer) if (self.Owner == self.World.LocalPlayer)
{ {
self.World.LocalShroud.Disabled = true; self.World.RenderedShroud.Disabled = true;
Game.RunAfterDelay(Info.NotificationDelay, () => Sound.PlayNotification(self.Owner, "Speech", "Win", self.Owner.Country.Race)); Game.RunAfterDelay(Info.NotificationDelay, () => Sound.PlayNotification(self.Owner, "Speech", "Win", self.Owner.Country.Race));
} }
} }

View File

@@ -25,8 +25,7 @@ namespace OpenRA.Mods.RA
public override int GetSelectionShares (Actor collector) public override int GetSelectionShares (Actor collector)
{ {
// don't ever hide the map for people who have GPS. // don't ever hide the map for people who have GPS.
var gpsWatcher = collector.Owner.PlayerActor.TraitOrDefault<GpsWatcher>(); if (collector.Owner.HasFogVisibility())
if (gpsWatcher != null && (gpsWatcher.Granted || gpsWatcher.GrantedAllies))
return 0; return 0;
return base.GetSelectionShares (collector); return base.GetSelectionShares (collector);
@@ -36,7 +35,7 @@ namespace OpenRA.Mods.RA
{ {
base.Activate(collector); base.Activate(collector);
if (collector.Owner == collector.World.LocalPlayer) if (collector.Owner == collector.World.LocalPlayer)
collector.World.WorldActor.Trait<Shroud>().ResetExploration(); collector.Owner.Shroud.ResetExploration();
} }
} }
} }

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA
base.Activate(collector); base.Activate(collector);
if (ShouldReveal( collector.Owner )) if (ShouldReveal( collector.Owner ))
collector.World.WorldActor.Trait<Shroud>().ExploreAll(collector.World); collector.Owner.Shroud.ExploreAll(collector.World);
} }
} }
} }

View File

@@ -153,7 +153,7 @@ namespace OpenRA.Mods.RA.Effects
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at); var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at) - new float2(0, altitude); var pos = float2.Lerp(Args.src.ToFloat2(), Args.dest.ToFloat2(), at) - new float2(0, altitude);
if (Args.firedBy.World.LocalShroud.IsVisible(((PPos) pos.ToInt2()).ToCPos())) if (Args.firedBy.World.RenderedShroud.IsVisible(((PPos) pos.ToInt2()).ToCPos()))
{ {
if (Info.High || Info.Angle > 0) if (Info.High || Info.Angle > 0)
{ {

View File

@@ -91,8 +91,8 @@ namespace OpenRA.Mods.RA
var conPos = positions[i]; var conPos = positions[i];
var nextPos = positions[i - 1]; var nextPos = positions[i - 1];
if (self.World.LocalShroud.IsVisible(conPos.ToCPos()) || if (self.World.RenderedShroud.IsVisible(conPos.ToCPos()) ||
self.World.LocalShroud.IsVisible(nextPos.ToCPos())) self.World.RenderedShroud.IsVisible(nextPos.ToCPos()))
{ {
Game.Renderer.WorldLineRenderer.DrawLine(conPos.ToFloat2(), nextPos.ToFloat2(), trailStart, trailEnd); Game.Renderer.WorldLineRenderer.DrawLine(conPos.ToFloat2(), nextPos.ToFloat2(), trailStart, trailEnd);

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.RA.Effects
if ( if (
self.IsInWorld self.IsInWorld
&& (watcher.Granted || watcher.GrantedAllies) && (watcher.Granted || watcher.GrantedAllies)
&& !self.Trait<HiddenUnderFog>().IsVisible(self) && !self.Trait<HiddenUnderFog>().IsVisible(self.World.RenderedShroud, self) // WRONG
&& (!self.HasTrait<Cloak>() || !self.Trait<Cloak>().Cloaked) && (!self.HasTrait<Cloak>() || !self.Trait<Cloak>().Cloaked)
&& (!self.HasTrait<Spy>() || !self.Trait<Spy>().Disguised) && (!self.HasTrait<Spy>() || !self.Trait<Spy>().Disguised)
) )

View File

@@ -154,7 +154,7 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()
{ {
if (Args.firedBy.World.LocalShroud.IsVisible(PxPosition.ToCPos())) if (Args.firedBy.World.RenderedShroud.IsVisible(PxPosition.ToCPos()))
yield return new Renderable(anim.Image, PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude), yield return new Renderable(anim.Image, PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude),
Args.weapon.Underwater ? "shadow" : "effect", PxPosition.Y); Args.weapon.Underwater ? "shadow" : "effect", PxPosition.Y);

View File

@@ -428,7 +428,7 @@ namespace OpenRA.Mods.RA
public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor) public bool CanTargetLocation(Actor self, CPos location, List<Actor> actorsAtLocation, bool forceAttack, bool forceQueued, ref string cursor)
{ {
// Don't leak info about resources under the shroud // Don't leak info about resources under the shroud
if (!self.World.LocalShroud.IsExplored(location)) return false; if (!self.Owner.Shroud.IsExplored(location)) return false;
var res = self.World.WorldActor.Trait<ResourceLayer>().GetResource(location); var res = self.World.WorldActor.Trait<ResourceLayer>().GetResource(location);
var info = self.Info.Traits.Get<HarvesterInfo>(); var info = self.Info.Traits.Get<HarvesterInfo>();

View File

@@ -20,18 +20,9 @@ namespace OpenRA.Mods.RA
{ {
public void OnInfiltrate(Actor self, Actor spy) public void OnInfiltrate(Actor self, Actor spy)
{ {
/* todo: changes for per-player shrouds: spy.Owner.Shroud.MergeShroud(self.Owner.Shroud);
* - apply this everywhere, not just on the victim's client if (!self.Owner.HasFogVisibility())
* - actually steal their exploration before resetting it self.Owner.Shroud.ResetExploration();
*/
if (self.World.LocalPlayer != null && self.World.LocalPlayer.Stances[self.Owner] == Stance.Ally)
{
var gpsWatcher = self.Owner.PlayerActor.TraitOrDefault<GpsWatcher>();
if (gpsWatcher != null && (gpsWatcher.Granted || gpsWatcher.GrantedAllies))
return;
self.Owner.Shroud.ResetExploration();
}
} }
} }
} }

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Mods.RA
class InvisibleToEnemy : IRenderModifier, IVisibilityModifier, IRadarColorModifier class InvisibleToEnemy : IRenderModifier, IVisibilityModifier, IRadarColorModifier
{ {
public bool IsVisible(Actor self) public bool IsVisible(Shroud s, Actor self)
{ {
return self.World.LocalPlayer == null || return self.World.LocalPlayer == null ||
self.Owner.Stances[self.World.LocalPlayer] == Stance.Ally; self.Owner.Stances[self.World.LocalPlayer] == Stance.Ally;
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {
return IsVisible(self) ? r : Nothing; return IsVisible(self.Owner.Shroud, self) ? r : Nothing;
} }
} }
} }

View File

@@ -18,15 +18,15 @@ namespace OpenRA.Mods.RA
class FrozenUnderFog : IRenderModifier, IVisibilityModifier class FrozenUnderFog : IRenderModifier, IVisibilityModifier
{ {
public bool IsVisible(Actor self) public bool IsVisible(Shroud s, Actor self)
{ {
return Shroud.GetVisOrigins(self).Any(o => self.World.LocalShroud.IsVisible(o)); return Shroud.GetVisOrigins(self).Any(o => s.IsVisible(o));
} }
Renderable[] cache = { }; Renderable[] cache = { };
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {
if (IsVisible(self)) if (IsVisible(self.World.RenderedShroud, self))
cache = r.ToArray(); cache = r.ToArray();
return cache; return cache;
} }

View File

@@ -18,15 +18,15 @@ namespace OpenRA.Mods.RA
class HiddenUnderFog : IRenderModifier, IVisibilityModifier class HiddenUnderFog : IRenderModifier, IVisibilityModifier
{ {
public bool IsVisible(Actor self) public bool IsVisible(Shroud s, Actor self)
{ {
return Shroud.GetVisOrigins(self).Any(o => self.World.LocalShroud.IsVisible(o)); return Shroud.GetVisOrigins(self).Any(o => s.IsVisible(o));
} }
static Renderable[] Nothing = { }; static Renderable[] Nothing = { };
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {
return IsVisible(self) ? r : Nothing; return IsVisible(self.World.RenderedShroud, self) ? r : Nothing;
} }
} }
} }

View File

@@ -276,6 +276,7 @@
<Compile Include="Player\PlaceBuilding.cs" /> <Compile Include="Player\PlaceBuilding.cs" />
<Compile Include="Player\ProductionQueue.cs" /> <Compile Include="Player\ProductionQueue.cs" />
<Compile Include="Player\TechTree.cs" /> <Compile Include="Player\TechTree.cs" />
<Compile Include="PlayerExts.cs" />
<Compile Include="PrimaryBuilding.cs" /> <Compile Include="PrimaryBuilding.cs" />
<Compile Include="Production.cs" /> <Compile Include="Production.cs" />
<Compile Include="ProductionBar.cs" /> <Compile Include="ProductionBar.cs" />

View File

@@ -0,0 +1,25 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public static class PlayerExts
{
public static bool HasFogVisibility( this Player a )
{
var gpsWatcher = a.PlayerActor.TraitOrDefault<GpsWatcher>();
return gpsWatcher != null && (gpsWatcher.Granted || gpsWatcher.GrantedAllies);
}
}
}

View File

@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA
public float GetValue() public float GetValue()
{ {
// only people we like should see our production status. // only people we like should see our production status.
if (self.World.LocalPlayer != null && self.Owner.Stances[self.World.LocalPlayer] != Stance.Ally) if (self.World.RenderedPlayer != null && self.Owner.Stances[self.World.RenderedPlayer] != Stance.Ally)
return 0; return 0;
var queue = self.TraitsImplementing<ProductionQueue>().FirstOrDefault(q => q.CurrentItem() != null); var queue = self.TraitsImplementing<ProductionQueue>().FirstOrDefault(q => q.CurrentItem() != null);

View File

@@ -25,7 +25,7 @@ namespace OpenRA.Scripting
var target = kv.First; var target = kv.First;
var targetCell = kv.Second; var targetCell = kv.Second;
var cs = target.Trait<Chronoshiftable>(); var cs = target.Trait<Chronoshiftable>();
if (cs.CanChronoshiftTo(target, targetCell, true)) if (chronosphere.Owner.Shroud.IsExplored(targetCell) && cs.CanChronoshiftTo(target, targetCell))
cs.Teleport(target, targetCell, duration, killCargo,chronosphere); cs.Teleport(target, targetCell, duration, killCargo,chronosphere);
} }
} }

View File

@@ -45,7 +45,7 @@ namespace OpenRA.Mods.RA
var altitude = new PVecInt(0, move.Altitude); var altitude = new PVecInt(0, move.Altitude);
position = (self.CenterLocation - Combat.GetTurretPosition(self, facing, smokeTurret)); position = (self.CenterLocation - Combat.GetTurretPosition(self, facing, smokeTurret));
if (self.World.LocalShroud.IsVisible(position.ToCPos())) if (self.World.RenderedShroud.IsVisible(position.ToCPos()))
self.World.AddFrameEndTask( self.World.AddFrameEndTask(
w => w.Add(new Smoke(w, position - altitude, "smokey"))); w => w.Add(new Smoke(w, position - altitude, "smokey")));
} }

View File

@@ -45,9 +45,8 @@ namespace OpenRA.Mods.RA
var targetCell = target.Location + (order.TargetLocation - order.ExtraLocation); var targetCell = target.Location + (order.TargetLocation - order.ExtraLocation);
var cpi = Info as ChronoshiftPowerInfo; var cpi = Info as ChronoshiftPowerInfo;
if (cs.CanChronoshiftTo(target, targetCell, true)) if (self.Owner.Shroud.IsExplored(targetCell) && cs.CanChronoshiftTo(target, targetCell))
cs.Teleport(target, targetCell, cs.Teleport(target, targetCell, cpi.Duration * 25, cpi.KillCargo, self);
cpi.Duration * 25, cpi.KillCargo, self);
} }
} }
@@ -61,6 +60,48 @@ namespace OpenRA.Mods.RA
return units.Distinct().Where(a => a.HasTrait<Chronoshiftable>()); return units.Distinct().Where(a => a.HasTrait<Chronoshiftable>());
} }
public bool SimilarTerrain(CPos xy, CPos sourceLocation) {
if (!self.Owner.Shroud.IsExplored(xy))
return false;
int range = (Info as ChronoshiftPowerInfo).Range;
var sourceTiles = self.World.FindTilesInCircle(xy, range);
var destTiles = self.World.FindTilesInCircle(sourceLocation, range);
List<string> sourceTerrain = new List<string>();
List<string> destTerrain = new List<string>();
int j = 0;
foreach (var t in sourceTiles) {
j = j + 1;
if (!self.Owner.Shroud.IsExplored(t))
return false;
sourceTerrain.Add(self.World.GetTerrainType( t ));
}
j = 0;
foreach (var t in destTiles) {
j = j + 1;
if (!self.Owner.Shroud.IsExplored(t)) {
return false;
}
self.World.GetTerrainType( t );
destTerrain.Add(self.World.GetTerrainType( t ));
}
// HACK but I don't want to write a comparison function
if (sourceTerrain.Count != destTerrain.Count)
return false;
for (int i = 0; i < sourceTerrain.Count; i++) {
if (!sourceTerrain[i].Equals(destTerrain[i]))
return false;
}
return true;
}
class SelectTarget : IOrderGenerator class SelectTarget : IOrderGenerator
{ {
@@ -99,8 +140,11 @@ namespace OpenRA.Mods.RA
{ {
var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos); var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos);
var targetUnits = power.UnitsInRange(xy); var targetUnits = power.UnitsInRange(xy);
foreach (var unit in targetUnits) foreach (var unit in targetUnits) {
wr.DrawSelectionBox(unit, Color.Red); if (manager.self.Owner.Shroud.IsTargetable(unit) || manager.self.Owner.HasFogVisibility()) {
wr.DrawSelectionBox(unit, Color.Red);
}
}
} }
public void RenderBeforeWorld(WorldRenderer wr, World world) public void RenderBeforeWorld(WorldRenderer wr, World world)
@@ -175,8 +219,11 @@ namespace OpenRA.Mods.RA
public void RenderAfterWorld(WorldRenderer wr, World world) public void RenderAfterWorld(WorldRenderer wr, World world)
{ {
foreach (var unit in power.UnitsInRange(sourceLocation)) foreach (var unit in power.UnitsInRange(sourceLocation)) {
wr.DrawSelectionBox(unit, Color.Red); if (manager.self.Owner.Shroud.IsTargetable(unit) || manager.self.Owner.HasFogVisibility()) {
wr.DrawSelectionBox(unit, Color.Red);
}
}
} }
public void RenderBeforeWorld(WorldRenderer wr, World world) public void RenderBeforeWorld(WorldRenderer wr, World world)
@@ -194,20 +241,24 @@ namespace OpenRA.Mods.RA
// Unit previews // Unit previews
foreach (var unit in power.UnitsInRange(sourceLocation)) foreach (var unit in power.UnitsInRange(sourceLocation))
{ {
var targetCell = unit.Location + (xy - sourceLocation); if (manager.self.Owner.Shroud.IsTargetable(unit)) {
foreach (var r in unit.Render()) var targetCell = unit.Location + (xy - sourceLocation);
r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location).ToFloat2() + Traits.Util.CenterOfCell(targetCell).ToFloat2(), foreach (var r in unit.Render())
wr.GetPaletteIndex(r.Palette), r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location).ToFloat2() + Traits.Util.CenterOfCell(targetCell).ToFloat2(),
r.Scale*r.Sprite.size); wr.GetPaletteIndex(r.Palette),
r.Scale*r.Sprite.size);
}
} }
// Unit tiles // Unit tiles
foreach (var unit in power.UnitsInRange(sourceLocation)) foreach (var unit in power.UnitsInRange(sourceLocation))
{ {
var targetCell = unit.Location + (xy - sourceLocation); if (manager.self.Owner.Shroud.IsTargetable(unit)) {
var canEnter = unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell, false); var targetCell = unit.Location + (xy - sourceLocation);
var tile = canEnter ? validTile : invalidTile; var canEnter = ((manager.self.Owner.Shroud.IsExplored(targetCell) || manager.self.Owner.HasFogVisibility())&& unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell));
tile.DrawAt( wr, targetCell.ToPPos().ToFloat2(), "terrain" ); var tile = canEnter ? validTile : invalidTile;
tile.DrawAt( wr, targetCell.ToPPos().ToFloat2(), "terrain" );
}
} }
} }
@@ -217,12 +268,18 @@ namespace OpenRA.Mods.RA
foreach (var unit in power.UnitsInRange(sourceLocation)) foreach (var unit in power.UnitsInRange(sourceLocation))
{ {
var targetCell = unit.Location + (xy - sourceLocation); var targetCell = unit.Location + (xy - sourceLocation);
if (unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell, false)) if (manager.self.Owner.Shroud.IsExplored(targetCell) && unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell))
{ {
canTeleport = true; canTeleport = true;
break; break;
} }
} }
if (!canTeleport) {
// Check the terrain types. This will allow chronoshifts to occur on empty terrain to terrain of
// a similar type. This also keeps the cursor from changing in non-visible property, alerting the
// chronoshifter of enemy unit presence
canTeleport = power.SimilarTerrain(sourceLocation,xy);
}
return canTeleport; return canTeleport;
} }

View File

@@ -58,15 +58,12 @@ namespace OpenRA.Mods.RA
public void RefreshGps(Actor atek) public void RefreshGps(Actor atek)
{ {
RefreshGranted(); RefreshGranted();
foreach (TraitPair<GpsWatcher> i in atek.World.ActorsWithTrait<GpsWatcher>()) foreach (TraitPair<GpsWatcher> i in atek.World.ActorsWithTrait<GpsWatcher>())
i.Trait.RefreshGranted(); i.Trait.RefreshGranted();
if (atek.World.LocalPlayer == null) if ((Granted || GrantedAllies) && atek.World.LocalPlayer != null && (atek.World.LocalPlayer.Stances[atek.Owner] == Stance.Ally))
return; atek.Owner.Shroud.ExploreAll(atek.World);
if ((Granted || GrantedAllies) && (atek.World.LocalPlayer.Stances[atek.Owner] == Stance.Ally))
atek.World.WorldActor.Trait<Shroud>().ExploreAll(atek.World);
} }
void RefreshGranted() void RefreshGranted()
@@ -74,6 +71,9 @@ namespace OpenRA.Mods.RA
Granted = (actors.Count > 0 && Launched); Granted = (actors.Count > 0 && Launched);
GrantedAllies = owner.World.ActorsWithTrait<GpsWatcher>().Any(p => GrantedAllies = owner.World.ActorsWithTrait<GpsWatcher>().Any(p =>
p.Actor.Owner.Stances[owner] == Stance.Ally && p.Trait.Granted); p.Actor.Owner.Stances[owner] == Stance.Ally && p.Trait.Granted);
if (Granted || GrantedAllies)
owner.Shroud.ExploreAll(owner.World);
} }
} }

View File

@@ -131,32 +131,38 @@ namespace OpenRA.Mods.RA
Key = key; Key = key;
} }
static bool InstanceDisabled(SupportPower sp)
{
return sp.self.TraitsImplementing<IDisable>().Any(d => d.Disabled);
}
bool notifiedCharging; bool notifiedCharging;
bool notifiedReady; bool notifiedReady;
public void Tick() public void Tick()
{ {
Active = !Disabled && Instances.Any(i => !i.self.IsDisabled()); Active = !Disabled && Instances.Any(i => !i.self.IsDisabled());
if (!Active) if (!Active)
return; return;
if (Manager.devMode.FastCharge && RemainingTime > 25) if (Active)
RemainingTime = 25;
if (RemainingTime > 0) --RemainingTime;
var power = Instances.First();
if (!notifiedCharging)
{ {
power.Charging(power.self, Key); var power = Instances.First();
notifiedCharging = true; if (Manager.devMode.FastCharge && RemainingTime > 25)
} RemainingTime = 25;
if (RemainingTime == 0 && !notifiedReady) if (RemainingTime > 0) --RemainingTime;
{ if (!notifiedCharging)
power.Charged(power.self, Key); {
notifiedReady = true; power.Charging(power.self, Key);
notifiedCharging = true;
}
if (RemainingTime == 0
&& !notifiedReady)
{
power.Charged(power.self, Key);
notifiedReady = true;
}
} }
} }
@@ -173,7 +179,7 @@ namespace OpenRA.Mods.RA
if (!Ready) if (!Ready)
return; return;
var power = Instances.First(i => !i.self.IsDisabled()); var power = Instances.First(i => !InstanceDisabled(i));
// Note: order.Subject is the *player* actor // Note: order.Subject is the *player* actor
power.Activate(power.self, order); power.Activate(power.self, order);

View File

@@ -33,7 +33,7 @@ namespace OpenRA.Mods.RA.Widgets
var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos); var cell = Game.viewport.ViewToWorld(Viewport.LastMousePos);
if (!world.Map.IsInMap(cell)) return; if (!world.Map.IsInMap(cell)) return;
if (world.LocalPlayer != null && !world.LocalPlayer.Shroud.IsExplored(cell)) if (world.LocalPlayer != null && !world.RenderedShroud.IsExplored(cell))
{ {
var utext = "Unexplored Terrain"; var utext = "Unexplored Terrain";
var usz = Game.Renderer.Fonts["Bold"].Measure(utext) + new int2(20, 24); var usz = Game.Renderer.Fonts["Bold"].Measure(utext) + new int2(20, 24);

View File

@@ -83,7 +83,7 @@ namespace OpenRA.Mods.RA
{ {
if (!cliprect.Contains(kv.Key.X,kv.Key.Y)) if (!cliprect.Contains(kv.Key.X,kv.Key.Y))
continue; continue;
if (localPlayer != null && !localPlayer.Shroud.IsExplored(kv.Key)) if (localPlayer != null && !world.RenderedShroud.IsExplored(kv.Key))
continue; continue;
smudgeSprites[kv.Value.type- 1][kv.Value.index].DrawAt(wr, kv.Key.ToPPos().ToFloat2(), "terrain"); smudgeSprites[kv.Value.type- 1][kv.Value.index].DrawAt(wr, kv.Key.ToPPos().ToFloat2(), "terrain");

Binary file not shown.

View File

@@ -188,6 +188,7 @@ Player:
DebugResourceOre: DebugResourceOre:
DebugResourceOreCapacity: DebugResourceOreCapacity:
GpsWatcher: GpsWatcher:
Shroud:
BaseAttackNotifier: BaseAttackNotifier:
World: World: