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

@@ -45,9 +45,8 @@ namespace OpenRA.Mods.RA
var targetCell = target.Location + (order.TargetLocation - order.ExtraLocation);
var cpi = Info as ChronoshiftPowerInfo;
if (cs.CanChronoshiftTo(target, targetCell, true))
cs.Teleport(target, targetCell,
cpi.Duration * 25, cpi.KillCargo, self);
if (self.Owner.Shroud.IsExplored(targetCell) && cs.CanChronoshiftTo(target, targetCell))
cs.Teleport(target, targetCell, cpi.Duration * 25, cpi.KillCargo, self);
}
}
@@ -61,6 +60,48 @@ namespace OpenRA.Mods.RA
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
{
@@ -99,8 +140,11 @@ namespace OpenRA.Mods.RA
{
var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos);
var targetUnits = power.UnitsInRange(xy);
foreach (var unit in targetUnits)
wr.DrawSelectionBox(unit, Color.Red);
foreach (var unit in targetUnits) {
if (manager.self.Owner.Shroud.IsTargetable(unit) || manager.self.Owner.HasFogVisibility()) {
wr.DrawSelectionBox(unit, Color.Red);
}
}
}
public void RenderBeforeWorld(WorldRenderer wr, World world)
@@ -175,8 +219,11 @@ namespace OpenRA.Mods.RA
public void RenderAfterWorld(WorldRenderer wr, World world)
{
foreach (var unit in power.UnitsInRange(sourceLocation))
wr.DrawSelectionBox(unit, Color.Red);
foreach (var unit in power.UnitsInRange(sourceLocation)) {
if (manager.self.Owner.Shroud.IsTargetable(unit) || manager.self.Owner.HasFogVisibility()) {
wr.DrawSelectionBox(unit, Color.Red);
}
}
}
public void RenderBeforeWorld(WorldRenderer wr, World world)
@@ -194,20 +241,24 @@ namespace OpenRA.Mods.RA
// Unit previews
foreach (var unit in power.UnitsInRange(sourceLocation))
{
var targetCell = unit.Location + (xy - sourceLocation);
foreach (var r in unit.Render())
r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location).ToFloat2() + Traits.Util.CenterOfCell(targetCell).ToFloat2(),
wr.GetPaletteIndex(r.Palette),
r.Scale*r.Sprite.size);
if (manager.self.Owner.Shroud.IsTargetable(unit)) {
var targetCell = unit.Location + (xy - sourceLocation);
foreach (var r in unit.Render())
r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location).ToFloat2() + Traits.Util.CenterOfCell(targetCell).ToFloat2(),
wr.GetPaletteIndex(r.Palette),
r.Scale*r.Sprite.size);
}
}
// Unit tiles
foreach (var unit in power.UnitsInRange(sourceLocation))
{
var targetCell = unit.Location + (xy - sourceLocation);
var canEnter = unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell, false);
var tile = canEnter ? validTile : invalidTile;
tile.DrawAt( wr, targetCell.ToPPos().ToFloat2(), "terrain" );
if (manager.self.Owner.Shroud.IsTargetable(unit)) {
var targetCell = unit.Location + (xy - sourceLocation);
var canEnter = ((manager.self.Owner.Shroud.IsExplored(targetCell) || manager.self.Owner.HasFogVisibility())&& unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell));
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))
{
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;
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;
}