Skip to content

Commit

Permalink
Issue #40 update Reduced sight then moving
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeniysergeev committed May 29, 2017
1 parent f13105c commit c2d0bd2
Show file tree
Hide file tree
Showing 19 changed files with 212 additions and 20 deletions.
125 changes: 125 additions & 0 deletions OpenRA.Mods.D2/Traits/D2AffectsShroud.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using System.Linq;
using OpenRA.Traits;
using OpenRA.Mods.Common.Traits;

namespace OpenRA.Mods.D2.Traits
{
public abstract class D2AffectsShroudInfo : ConditionalTraitInfo
{
[Desc("Range applied then idle.")]
public readonly WDist Range = WDist.Zero;

[Desc("Range applied then moving.")]
public readonly WDist MovingRange = new WDist(1280);

[Desc("If >= 0, prevent cells that are this much higher than the actor from being revealed.")]
public readonly int MaxHeightDelta = -1;

[Desc("Possible values are CenterPosition (measure range from the center) and ",
"Footprint (measure range from the footprint)")]
public readonly VisibilityType Type = VisibilityType.Footprint;
}

public abstract class D2AffectsShroud : ConditionalTrait<D2AffectsShroudInfo>, ITick, ISync, INotifyAddedToWorld, INotifyRemovedFromWorld
{
static readonly PPos[] NoCells = { };

D2AffectsShroudInfo info;

[Sync] CPos cachedLocation;
[Sync] bool cachedDisabled;
[Sync] bool cachedTraitDisabled;
[Sync] bool cachedIdle;

protected abstract void AddCellsToPlayerShroud(Actor self, Player player, PPos[] uv);
protected abstract void RemoveCellsFromPlayerShroud(Actor self, Player player);
protected virtual bool IsDisabled(Actor self) { return false; }

public D2AffectsShroud(Actor self, D2AffectsShroudInfo info)
: base(info)
{
this.info = info;
}

PPos[] ProjectedCells(Actor self)
{
var map = self.World.Map;
var range = self.IsIdle ? Range : info.MovingRange;
if (range == WDist.Zero)
return NoCells;

if (Info.Type == VisibilityType.Footprint)
return self.OccupiesSpace.OccupiedCells()
.SelectMany(kv => Shroud.ProjectedCellsInRange(map, kv.First, range, Info.MaxHeightDelta))
.Distinct().ToArray();

var pos = self.CenterPosition;
if (Info.Type == VisibilityType.GroundPosition)
pos -= new WVec(WDist.Zero, WDist.Zero, self.World.Map.DistanceAboveTerrain(pos));

return Shroud.ProjectedCellsInRange(map, pos, range, Info.MaxHeightDelta)
.ToArray();
}

void ITick.Tick(Actor self)
{
if (!self.IsInWorld)
return;

var centerPosition = self.CenterPosition;
var projectedPos = centerPosition - new WVec(0, centerPosition.Z, centerPosition.Z);
var projectedLocation = self.World.Map.CellContaining(projectedPos);
var disabled = IsDisabled(self);
var traitDisabled = IsTraitDisabled;
var idle = self.IsIdle;

if (cachedLocation == projectedLocation && traitDisabled == cachedTraitDisabled && cachedDisabled == disabled && cachedIdle == idle)
return;

cachedLocation = projectedLocation;
cachedDisabled = disabled;
cachedTraitDisabled = traitDisabled;
cachedIdle = idle;

var cells = ProjectedCells(self);
foreach (var p in self.World.Players)
{
RemoveCellsFromPlayerShroud(self, p);
AddCellsToPlayerShroud(self, p, cells);
}
}

void INotifyAddedToWorld.AddedToWorld(Actor self)
{
var centerPosition = self.CenterPosition;
var projectedPos = centerPosition - new WVec(0, centerPosition.Z, centerPosition.Z);
cachedLocation = self.World.Map.CellContaining(projectedPos);
cachedDisabled = IsDisabled(self);
cachedTraitDisabled = IsTraitDisabled;
cachedIdle = self.IsIdle;
var cells = ProjectedCells(self);

foreach (var p in self.World.Players)
AddCellsToPlayerShroud(self, p, cells);
}

void INotifyRemovedFromWorld.RemovedFromWorld(Actor self)
{
foreach (var p in self.World.Players)
RemoveCellsFromPlayerShroud(self, p);
}

public WDist Range { get { return (cachedDisabled || cachedTraitDisabled) ? WDist.Zero : Info.Range; } }
}
}
51 changes: 51 additions & 0 deletions OpenRA.Mods.D2/Traits/D2RevealsShroud.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#region Copyright & License Information
/*
* Copyright 2007-2017 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, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using OpenRA.Traits;
using OpenRA.Mods.Common.Traits;

namespace OpenRA.Mods.D2.Traits
{
public class D2RevealsShroudInfo : D2AffectsShroudInfo
{
[Desc("Stance the watching player needs to see the shroud removed.")]
public readonly Stance ValidStances = Stance.Ally;

[Desc("Can this actor reveal shroud generated by the GeneratesShroud trait?")]
public readonly bool RevealGeneratedShroud = true;

public override object Create(ActorInitializer init) { return new D2RevealsShroud(init.Self, this); }
}

public class D2RevealsShroud : D2AffectsShroud
{
readonly D2RevealsShroudInfo info;
readonly Shroud.SourceType type;

public D2RevealsShroud(Actor self, D2RevealsShroudInfo info)
: base(self, info)
{
this.info = info;
type = info.RevealGeneratedShroud ? Shroud.SourceType.Visibility
: Shroud.SourceType.PassiveVisibility;
}

protected override void AddCellsToPlayerShroud(Actor self, Player p, PPos[] uv)
{
if (!info.ValidStances.HasStance(p.Stances[self.Owner]))
return;

p.Shroud.AddSource(this, type, uv);
}

protected override void RemoveCellsFromPlayerShroud(Actor self, Player p) { p.Shroud.RemoveSource(this); }
}
}
2 changes: 1 addition & 1 deletion rules/barracks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ barracks:
Armor:
Type: wood
RevealsShroud:
Range: 3c768
Range: 2c0
RallyPoint:
Offset: 1,2
Exit@1:
Expand Down
5 changes: 3 additions & 2 deletions rules/combat_tank.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
Mobile:
Speed: 75
TurnSpeed: 5
RevealsShroud:
Range: 5c768
D2RevealsShroud:
Range: 3c256
MovingRange: 1c256
Turreted:
TurnSpeed: 5
RealignDelay: 0
Expand Down
3 changes: 2 additions & 1 deletion rules/devastator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ devastator:
TurnSpeed: 3
Speed: 31
Crushes: infantry, spicebloom, wall
RevealsShroud:
D2RevealsShroud:
Range: 4c768
MovingRange: 1c256
Armament:
Weapon: DevBullet
LocalOffset: 640,0,32
Expand Down
3 changes: 2 additions & 1 deletion rules/deviator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ deviator:
HP: 120
Armor:
Type: wood
RevealsShroud:
D2RevealsShroud:
Range: 4c768
MovingRange: 1c256
Armament:
Weapon: DeviatorMissile
LocalOffset: -299,0,85
Expand Down
3 changes: 2 additions & 1 deletion rules/fremen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ fremen:
Cost: 200 ## actually 0, but spawns from support power at Palace
Health:
HP: 700
RevealsShroud:
D2RevealsShroud:
Range: 4c768
MovingRange: 1c256
AutoTarget:
ScanRadius: 7
InitialStance: HoldFire
Expand Down
3 changes: 2 additions & 1 deletion rules/harvester.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ harvester:
Mobile:
Speed: 43
Crushes: infantry, spicebloom
RevealsShroud:
D2RevealsShroud:
Range: 3c768
MovingRange: 1c256
Explodes:
Weapon: UnitExplodeLarge
EmptyWeapon: UnitExplodeLarge
Expand Down
5 changes: 3 additions & 2 deletions rules/infantry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
Radius: 96
Armor:
Type: none
RevealsShroud:
Range: 1c768
Mobile:
Crushes: spicebloom
SharesCell: true
Expand All @@ -22,6 +20,9 @@
SpiceBlobs: 100
Dune: 80
Rough: 80
D2RevealsShroud:
Range: 1c768
MovingRange: 1c256
SelectionDecorations:
WithSpriteControlGroupDecoration:
Selectable:
Expand Down
3 changes: 2 additions & 1 deletion rules/mcv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ mcv:
Mobile:
Speed: 31
Crushes: infantry, spicebloom
RevealsShroud:
D2RevealsShroud:
Range: 2c768
MovingRange: 1c256
MustBeDestroyed:
RequiredForShortGame: true
BaseBuilding:
Expand Down
3 changes: 2 additions & 1 deletion rules/missile_tank.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ missile_tank:
HP: 100
Armor:
Type: wood
RevealsShroud:
D2RevealsShroud:
Range: 6c768
MovingRange: 1c256
Armament:
Weapon: mtank_pri
LocalOffset: -128,128,171, -128,-128,171
Expand Down
3 changes: 2 additions & 1 deletion rules/quad.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ quad:
Mobile:
TurnSpeed: 8
Speed: 96
RevealsShroud:
D2RevealsShroud:
Range: 4c768
MovingRange: 1c256
Armament:
Weapon: Rocket
LocalOffset: 128,64,64, 128,-64,64
Expand Down
3 changes: 2 additions & 1 deletion rules/raider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ raider:
Mobile:
TurnSpeed: 10
Speed: 149
RevealsShroud:
D2RevealsShroud:
Range: 4c768
MovingRange: 1c256
WithMuzzleOverlay:
Armament@damage:
Weapon: HMGo
Expand Down
3 changes: 2 additions & 1 deletion rules/sardaukar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ sardaukar:
HP: 1000
Mobile:
Speed: 31
RevealsShroud:
D2RevealsShroud:
Range: 4c768
MovingRange: 1c256
WithInfantryBody:
DefaultAttackSequence: shoot
Armament@PRIMARY:
Expand Down
3 changes: 2 additions & 1 deletion rules/siege_tank.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ siege_tank:
Mobile:
Speed: 43
TurnSpeed: 3
RevealsShroud:
D2RevealsShroud:
Range: 6c768
MovingRange: 1c256
Turreted:
TurnSpeed: 3
Offset: 0,0,-32
Expand Down
3 changes: 2 additions & 1 deletion rules/sonic_tank.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ sonic_tank:
Mobile:
TurnSpeed: 3
Speed: 31
RevealsShroud:
D2RevealsShroud:
Range: 5c768
MovingRange: 1c256
Armament:
Weapon: Sound
LocalOffset: 600,0,427
Expand Down
5 changes: 3 additions & 2 deletions rules/trike.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ trike:
Mobile:
TurnSpeed: 10
Speed: 128
RevealsShroud:
Range: 4c768
D2RevealsShroud:
Range: 3c512
MovingRange: 1c256
WithMuzzleOverlay:
Armament@damage:
Weapon: HMG
Expand Down
3 changes: 2 additions & 1 deletion rules/trooper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ trooper:
Name: Trooper
Health:
HP: 45
RevealsShroud:
D2RevealsShroud:
Range: 4c768
MovingRange: 1c256
Mobile:
Speed: 31
Armament:
Expand Down
3 changes: 2 additions & 1 deletion rules/trooper_squad.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ trooper_squad:
Name: Trooper
Health:
HP: 110
RevealsShroud:
D2RevealsShroud:
Range: 4c768
MovingRange: 1c256
Mobile:
SharesCell: false
Speed: 31
Expand Down

0 comments on commit c2d0bd2

Please sign in to comment.