Move Cloak, HiddenUnderFog, FrozenUnderFog into Mods.RA; Simplify a pile of related stuff.

This commit is contained in:
Paul Chote
2010-07-28 21:11:50 +12:00
parent 6854d9853b
commit 8fab45ae39
12 changed files with 38 additions and 52 deletions

View File

@@ -122,6 +122,9 @@ namespace OpenRA.Graphics
foreach (var t in world.Queries.WithTraitMultiple<IRadarSignature>()) foreach (var t in world.Queries.WithTraitMultiple<IRadarSignature>())
{ {
if (!t.Actor.IsVisible())
continue;
var color = t.Trait.RadarSignatureColor(t.Actor); var color = t.Trait.RadarSignatureColor(t.Actor);
foreach (var cell in t.Trait.RadarSignatureCells(t.Actor)) foreach (var cell in t.Trait.RadarSignatureCells(t.Actor))
if (world.Map.IsInMap(cell)) if (world.Map.IsInMap(cell))

View File

@@ -82,10 +82,8 @@
<Compile Include="Server\ProtocolVersion.cs" /> <Compile Include="Server\ProtocolVersion.cs" />
<Compile Include="Traits\BaseBuilding.cs" /> <Compile Include="Traits\BaseBuilding.cs" />
<Compile Include="Traits\LintAttributes.cs" /> <Compile Include="Traits\LintAttributes.cs" />
<Compile Include="Traits\Modifiers\FrozenUnderFog.cs" />
<Compile Include="Traits\Player\PlayerResources.cs" /> <Compile Include="Traits\Player\PlayerResources.cs" />
<Compile Include="Traits\Player\TechTreeCache.cs" /> <Compile Include="Traits\Player\TechTreeCache.cs" />
<Compile Include="Traits\Modifiers\HiddenUnderFog.cs" />
<Compile Include="Traits\World\Shroud.cs" /> <Compile Include="Traits\World\Shroud.cs" />
<Compile Include="Widgets\ChatEntryWidget.cs" /> <Compile Include="Widgets\ChatEntryWidget.cs" />
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" /> <Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
@@ -179,7 +177,6 @@
<Compile Include="Traits\Production.cs" /> <Compile Include="Traits\Production.cs" />
<Compile Include="Traits\RallyPoint.cs" /> <Compile Include="Traits\RallyPoint.cs" />
<Compile Include="Traits\Render\RenderSimple.cs" /> <Compile Include="Traits\Render\RenderSimple.cs" />
<Compile Include="Traits\Cloak.cs" />
<Compile Include="Traits\TraitsInterfaces.cs" /> <Compile Include="Traits\TraitsInterfaces.cs" />
<Compile Include="Traits\Turreted.cs" /> <Compile Include="Traits\Turreted.cs" />
<Compile Include="Traits\Unit.cs" /> <Compile Include="Traits\Unit.cs" />
@@ -266,4 +263,7 @@
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
<ItemGroup>
<Folder Include="Traits\" />
</ItemGroup>
</Project> </Project>

View File

@@ -163,10 +163,6 @@ namespace OpenRA.Traits
public IEnumerable<int2> RadarSignatureCells(Actor self) public IEnumerable<int2> RadarSignatureCells(Actor self)
{ {
foreach (var mod in self.traits.WithInterface<IRadarVisibilityModifier>())
if (!mod.VisibleOnRadar(self))
return new int2[] {};
return Footprint.Tiles(self); return Footprint.Tiles(self);
} }

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Traits
Color RadarSignatureColor(Actor self); Color RadarSignatureColor(Actor self);
} }
public interface IRadarVisibilityModifier { bool VisibleOnRadar(Actor self); } public interface IVisibilityModifier { bool IsVisible(Actor self); }
public interface IRadarColorModifier { Color RadarColorOverride(Actor self); } public interface IRadarColorModifier { Color RadarColorOverride(Actor self); }
public interface IRevealShroud {} public interface IRevealShroud {}
public interface IOccupySpace public interface IOccupySpace

View File

@@ -49,10 +49,6 @@ namespace OpenRA.Traits
public IEnumerable<int2> RadarSignatureCells(Actor self) public IEnumerable<int2> RadarSignatureCells(Actor self)
{ {
foreach (var mod in self.traits.WithInterface<IRadarVisibilityModifier>())
if (!mod.VisibleOnRadar(self))
yield break;
yield return self.Location; yield return self.Location;
} }

View File

@@ -121,12 +121,7 @@ namespace OpenRA
if (!Shroud.GetVisOrigins(a).Any(o => a.World.Map.IsInMap(o) && shroud.exploredCells[o.X, o.Y])) // covered by shroud if (!Shroud.GetVisOrigins(a).Any(o => a.World.Map.IsInMap(o) && shroud.exploredCells[o.X, o.Y])) // covered by shroud
return false; return false;
var huf = a.traits.GetOrDefault<HiddenUnderFog>(); // hidden under fog if (a.traits.WithInterface<IVisibilityModifier>().Any(t => !t.IsVisible(a)))
if (huf != null && !huf.IsVisible(a))
return false;
var cloak = a.traits.GetOrDefault<Cloak>();
if (cloak != null && cloak.Cloaked && a.Owner != a.World.LocalPlayer)
return false; return false;
return true; return true;

View File

@@ -12,8 +12,9 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Drawing; using System.Drawing;
using OpenRA.Traits;
namespace OpenRA.Traits namespace OpenRA.Mods.RA
{ {
class CloakInfo : ITraitInfo class CloakInfo : ITraitInfo
{ {
@@ -25,7 +26,7 @@ namespace OpenRA.Traits
public object Create(ActorInitializer init) { return new Cloak(init.self); } public object Create(ActorInitializer init) { return new Cloak(init.self); }
} }
public class Cloak : IRenderModifier, INotifyAttack, ITick, INotifyDamage, IRadarVisibilityModifier, IRadarColorModifier public class Cloak : IRenderModifier, INotifyAttack, ITick, INotifyDamage, IVisibilityModifier, IRadarColorModifier
{ {
[Sync] [Sync]
int remainingTime; int remainingTime;
@@ -80,7 +81,7 @@ namespace OpenRA.Traits
public bool Cloaked { get { return remainingTime == 0; } } public bool Cloaked { get { return remainingTime == 0; } }
public bool VisibleOnRadar(Actor self) public bool IsVisible(Actor self)
{ {
return !Cloaked || self.Owner == self.World.LocalPlayer; return !Cloaked || self.Owner == self.World.LocalPlayer;
} }

View File

@@ -9,14 +9,25 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class InvisibleToOthersInfo : TraitInfo<InvisibleToOthers> { } class InvisibleToOthersInfo : TraitInfo<InvisibleToOthers> { }
class InvisibleToOthers : IRenderModifier class InvisibleToOthers : IRenderModifier, IVisibilityModifier, IRadarColorModifier
{ {
public bool IsVisible(Actor self)
{
return self.Owner == self.World.LocalPlayer;
}
public Color RadarColorOverride(Actor self)
{
return Color.FromArgb(128, self.Owner.Color);
}
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {
return self.World.LocalPlayer == self.Owner return self.World.LocalPlayer == self.Owner

View File

@@ -11,7 +11,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Traits; using OpenRA.Traits;
using OpenRA.Traits.Activities; using OpenRA.Traits.Activities;
using System.Drawing;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
@@ -25,7 +24,7 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new Mine(init, this); } public object Create(ActorInitializer init) { return new Mine(init, this); }
} }
class Mine : ICrushable, IOccupySpace, IRadarVisibilityModifier, IRadarColorModifier class Mine : ICrushable, IOccupySpace
{ {
readonly Actor self; readonly Actor self;
readonly MineInfo info; readonly MineInfo info;
@@ -56,16 +55,6 @@ namespace OpenRA.Mods.RA
public int2 TopLeft { get { return location; } } public int2 TopLeft { get { return location; } }
public IEnumerable<int2> OccupiedCells() { yield return TopLeft; } public IEnumerable<int2> OccupiedCells() { yield return TopLeft; }
public bool VisibleOnRadar(Actor self)
{
return self.Owner == self.World.LocalPlayer;
}
public Color RadarColorOverride(Actor self)
{
return Color.FromArgb(128, self.Owner.Color);
}
} }
/* tag trait for stuff that shouldnt trigger mines */ /* tag trait for stuff that shouldnt trigger mines */

View File

@@ -10,15 +10,16 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Traits namespace OpenRA.Mods.RA
{ {
class FrozenUnderFogInfo : ITraitInfo class FrozenUnderFogInfo : ITraitInfo
{ {
public object Create(ActorInitializer init) { return new FrozenUnderFog(init.self); } public object Create(ActorInitializer init) { return new FrozenUnderFog(init.self); }
} }
class FrozenUnderFog : IRenderModifier, IRadarVisibilityModifier class FrozenUnderFog : IRenderModifier, IVisibilityModifier
{ {
Shroud shroud; Shroud shroud;
Renderable[] cache = { }; Renderable[] cache = { };
@@ -28,7 +29,7 @@ namespace OpenRA.Traits
shroud = self.World.WorldActor.traits.Get<Shroud>(); shroud = self.World.WorldActor.traits.Get<Shroud>();
} }
bool IsVisible(Actor self) public bool IsVisible(Actor self)
{ {
return self.World.LocalPlayer == null return self.World.LocalPlayer == null
|| self.Owner == self.World.LocalPlayer || self.Owner == self.World.LocalPlayer
@@ -36,11 +37,6 @@ namespace OpenRA.Traits
|| Shroud.GetVisOrigins(self).Any(o => self.World.Map.IsInMap(o) && shroud.visibleCells[o.X, o.Y] != 0); || Shroud.GetVisOrigins(self).Any(o => self.World.Map.IsInMap(o) && shroud.visibleCells[o.X, o.Y] != 0);
} }
public bool VisibleOnRadar(Actor self)
{
return IsVisible(self);
}
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {
if (IsVisible(self)) if (IsVisible(self))

View File

@@ -9,15 +9,16 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Traits;
namespace OpenRA.Traits namespace OpenRA.Mods.RA
{ {
class HiddenUnderFogInfo : ITraitInfo class HiddenUnderFogInfo : ITraitInfo
{ {
public object Create(ActorInitializer init) { return new HiddenUnderFog(init.self); } public object Create(ActorInitializer init) { return new HiddenUnderFog(init.self); }
} }
class HiddenUnderFog : IRenderModifier, IRadarVisibilityModifier class HiddenUnderFog : IRenderModifier, IVisibilityModifier
{ {
Shroud shroud; Shroud shroud;
@@ -34,11 +35,6 @@ namespace OpenRA.Traits
|| shroud.visibleCells[self.Location.X, self.Location.Y] > 0; || shroud.visibleCells[self.Location.X, self.Location.Y] > 0;
} }
public bool VisibleOnRadar(Actor self)
{
return IsVisible(self);
}
static Renderable[] Nothing = { }; static Renderable[] Nothing = { };
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r) public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
{ {

View File

@@ -222,6 +222,9 @@
<Compile Include="ChronoshiftDeploy.cs" /> <Compile Include="ChronoshiftDeploy.cs" />
<Compile Include="DemoTruck.cs" /> <Compile Include="DemoTruck.cs" />
<Compile Include="Orders\SetChronoTankDestination.cs" /> <Compile Include="Orders\SetChronoTankDestination.cs" />
<Compile Include="Cloak.cs" />
<Compile Include="Modifiers\FrozenUnderFog.cs" />
<Compile Include="Modifiers\HiddenUnderFog.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj"> <ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">