Move Cloak, HiddenUnderFog, FrozenUnderFog into Mods.RA; Simplify a pile of related stuff.
This commit is contained in:
@@ -119,9 +119,12 @@ namespace OpenRA.Graphics
|
||||
unsafe
|
||||
{
|
||||
int* c = (int*)bitmapData.Scan0;
|
||||
|
||||
|
||||
foreach (var t in world.Queries.WithTraitMultiple<IRadarSignature>())
|
||||
{
|
||||
if (!t.Actor.IsVisible())
|
||||
continue;
|
||||
|
||||
var color = t.Trait.RadarSignatureColor(t.Actor);
|
||||
foreach (var cell in t.Trait.RadarSignatureCells(t.Actor))
|
||||
if (world.Map.IsInMap(cell))
|
||||
|
||||
@@ -82,10 +82,8 @@
|
||||
<Compile Include="Server\ProtocolVersion.cs" />
|
||||
<Compile Include="Traits\BaseBuilding.cs" />
|
||||
<Compile Include="Traits\LintAttributes.cs" />
|
||||
<Compile Include="Traits\Modifiers\FrozenUnderFog.cs" />
|
||||
<Compile Include="Traits\Player\PlayerResources.cs" />
|
||||
<Compile Include="Traits\Player\TechTreeCache.cs" />
|
||||
<Compile Include="Traits\Modifiers\HiddenUnderFog.cs" />
|
||||
<Compile Include="Traits\World\Shroud.cs" />
|
||||
<Compile Include="Widgets\ChatEntryWidget.cs" />
|
||||
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
|
||||
@@ -179,7 +177,6 @@
|
||||
<Compile Include="Traits\Production.cs" />
|
||||
<Compile Include="Traits\RallyPoint.cs" />
|
||||
<Compile Include="Traits\Render\RenderSimple.cs" />
|
||||
<Compile Include="Traits\Cloak.cs" />
|
||||
<Compile Include="Traits\TraitsInterfaces.cs" />
|
||||
<Compile Include="Traits\Turreted.cs" />
|
||||
<Compile Include="Traits\Unit.cs" />
|
||||
@@ -266,4 +263,7 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Folder Include="Traits\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -162,11 +162,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class CloakInfo : ITraitInfo
|
||||
{
|
||||
public readonly float InitialDelay = .4f; // seconds
|
||||
public readonly float CloakDelay = 1.2f; // Seconds
|
||||
public readonly string CloakSound = "subshow1.aud";
|
||||
public readonly string UncloakSound = "subshow1.aud";
|
||||
|
||||
public object Create(ActorInitializer init) { return new Cloak(init.self); }
|
||||
}
|
||||
|
||||
public class Cloak : IRenderModifier, INotifyAttack, ITick, INotifyDamage, IRadarVisibilityModifier, IRadarColorModifier
|
||||
{
|
||||
[Sync]
|
||||
int remainingTime;
|
||||
|
||||
Actor self;
|
||||
public Cloak(Actor self)
|
||||
{
|
||||
remainingTime = (int)(self.Info.Traits.Get<CloakInfo>().InitialDelay * 25);
|
||||
this.self = self;
|
||||
}
|
||||
|
||||
void DoSurface()
|
||||
{
|
||||
if (remainingTime <= 0)
|
||||
OnSurface();
|
||||
|
||||
remainingTime = Math.Max(remainingTime, (int)(self.Info.Traits.Get<CloakInfo>().CloakDelay * 25));
|
||||
}
|
||||
|
||||
public void Attacking(Actor self) { DoSurface(); }
|
||||
public void Damaged(Actor self, AttackInfo e) { DoSurface(); }
|
||||
|
||||
public IEnumerable<Renderable>
|
||||
ModifyRender(Actor self, IEnumerable<Renderable> rs)
|
||||
{
|
||||
if (remainingTime > 0)
|
||||
return rs;
|
||||
|
||||
if (self.Owner == self.World.LocalPlayer)
|
||||
return rs.Select(a => a.WithPalette("shadow"));
|
||||
else
|
||||
return new Renderable[] { };
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
if (remainingTime > 0)
|
||||
if (--remainingTime <= 0)
|
||||
OnDive();
|
||||
}
|
||||
|
||||
void OnSurface()
|
||||
{
|
||||
Sound.Play(self.Info.Traits.Get<CloakInfo>().UncloakSound, self.CenterLocation);
|
||||
}
|
||||
|
||||
void OnDive()
|
||||
{
|
||||
Sound.Play(self.Info.Traits.Get<CloakInfo>().CloakSound, self.CenterLocation);
|
||||
}
|
||||
|
||||
public bool Cloaked { get { return remainingTime == 0; } }
|
||||
|
||||
|
||||
public bool VisibleOnRadar(Actor self)
|
||||
{
|
||||
return !Cloaked || self.Owner == self.World.LocalPlayer;
|
||||
}
|
||||
|
||||
public Color RadarColorOverride(Actor self)
|
||||
{
|
||||
var c = self.Owner.Color;
|
||||
if (self.Owner == self.World.LocalPlayer && Cloaked)
|
||||
c = Color.FromArgb(128, c);
|
||||
return c;
|
||||
}
|
||||
|
||||
public void Decloak(int time)
|
||||
{
|
||||
DoSurface();
|
||||
remainingTime = Math.Max(remainingTime, time);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class FrozenUnderFogInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new FrozenUnderFog(init.self); }
|
||||
}
|
||||
|
||||
class FrozenUnderFog : IRenderModifier, IRadarVisibilityModifier
|
||||
{
|
||||
Shroud shroud;
|
||||
Renderable[] cache = { };
|
||||
|
||||
public FrozenUnderFog(Actor self)
|
||||
{
|
||||
shroud = self.World.WorldActor.traits.Get<Shroud>();
|
||||
}
|
||||
|
||||
bool IsVisible(Actor self)
|
||||
{
|
||||
return self.World.LocalPlayer == null
|
||||
|| self.Owner == self.World.LocalPlayer
|
||||
|| self.World.LocalPlayer.Shroud.Disabled
|
||||
|| 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)
|
||||
{
|
||||
if (IsVisible(self))
|
||||
cache = r.ToArray();
|
||||
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class HiddenUnderFogInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new HiddenUnderFog(init.self); }
|
||||
}
|
||||
|
||||
class HiddenUnderFog : IRenderModifier, IRadarVisibilityModifier
|
||||
{
|
||||
Shroud shroud;
|
||||
|
||||
public HiddenUnderFog(Actor self)
|
||||
{
|
||||
shroud = self.World.WorldActor.traits.Get<Shroud>();
|
||||
}
|
||||
|
||||
public bool IsVisible(Actor self)
|
||||
{
|
||||
return self.World.LocalPlayer == null
|
||||
|| self.Owner == self.World.LocalPlayer
|
||||
|| self.World.LocalPlayer.Shroud.Disabled
|
||||
|| shroud.visibleCells[self.Location.X, self.Location.Y] > 0;
|
||||
}
|
||||
|
||||
public bool VisibleOnRadar(Actor self)
|
||||
{
|
||||
return IsVisible(self);
|
||||
}
|
||||
|
||||
static Renderable[] Nothing = { };
|
||||
public IEnumerable<Renderable> ModifyRender(Actor self, IEnumerable<Renderable> r)
|
||||
{
|
||||
return IsVisible(self) ? r : Nothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace OpenRA.Traits
|
||||
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 IRevealShroud {}
|
||||
public interface IOccupySpace
|
||||
|
||||
@@ -48,11 +48,7 @@ namespace OpenRA.Traits
|
||||
}
|
||||
|
||||
public IEnumerable<int2> RadarSignatureCells(Actor self)
|
||||
{
|
||||
foreach (var mod in self.traits.WithInterface<IRadarVisibilityModifier>())
|
||||
if (!mod.VisibleOnRadar(self))
|
||||
yield break;
|
||||
|
||||
{
|
||||
yield return self.Location;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
return false;
|
||||
|
||||
var huf = a.traits.GetOrDefault<HiddenUnderFog>(); // hidden under fog
|
||||
if (huf != null && !huf.IsVisible(a))
|
||||
return false;
|
||||
|
||||
var cloak = a.traits.GetOrDefault<Cloak>();
|
||||
if (cloak != null && cloak.Cloaked && a.Owner != a.World.LocalPlayer)
|
||||
if (a.traits.WithInterface<IVisibilityModifier>().Any(t => !t.IsVisible(a)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user