Fix FrozenUnderFog.
This commit is contained in:
53
OpenRA.Mods.RA/Effects/FrozenActorProxy.cs
Normal file
53
OpenRA.Mods.RA/Effects/FrozenActorProxy.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2013 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.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Effects;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA.Effects
|
||||||
|
{
|
||||||
|
public class FrozenActorProxy : IEffect
|
||||||
|
{
|
||||||
|
readonly Actor self;
|
||||||
|
readonly IEnumerable<CPos> footprint;
|
||||||
|
IRenderable[] renderables;
|
||||||
|
|
||||||
|
public FrozenActorProxy(Actor self, IEnumerable<CPos> footprint)
|
||||||
|
{
|
||||||
|
this.self = self;
|
||||||
|
this.footprint = footprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick(World world) { }
|
||||||
|
public void SetRenderables(IEnumerable<IRenderable> r)
|
||||||
|
{
|
||||||
|
renderables = r.Select(rr => rr).ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<IRenderable> Render(WorldRenderer wr)
|
||||||
|
{
|
||||||
|
if (renderables == null)
|
||||||
|
return SpriteRenderable.None;
|
||||||
|
|
||||||
|
if (footprint.Any(c => !wr.world.FogObscures(c)))
|
||||||
|
{
|
||||||
|
if (self.Destroyed)
|
||||||
|
self.World.AddFrameEndTask(w => w.Remove(this));
|
||||||
|
|
||||||
|
return SpriteRenderable.None;
|
||||||
|
}
|
||||||
|
|
||||||
|
return renderables;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#region Copyright & License Information
|
#region Copyright & License Information
|
||||||
/*
|
/*
|
||||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||||
* This file is part of OpenRA, which is free software. It is made
|
* 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
|
* available to you under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation. For more information,
|
* as published by the Free Software Foundation. For more information,
|
||||||
@@ -11,25 +11,48 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.RA.Buildings;
|
||||||
|
using OpenRA.Mods.RA.Effects;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA
|
namespace OpenRA.Mods.RA
|
||||||
{
|
{
|
||||||
class FrozenUnderFogInfo : TraitInfo<FrozenUnderFog> {}
|
public class FrozenUnderFogInfo : ITraitInfo, Requires<BuildingInfo>, Requires<RenderSpritesInfo>
|
||||||
|
|
||||||
class FrozenUnderFog : IRenderModifier, IVisibilityModifier
|
|
||||||
{
|
{
|
||||||
|
public object Create(ActorInitializer init) { return new FrozenUnderFog(init.self); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FrozenUnderFog : IRenderModifier, IVisibilityModifier, ITickRender
|
||||||
|
{
|
||||||
|
FrozenActorProxy proxy;
|
||||||
|
IEnumerable<CPos> footprint;
|
||||||
|
bool visible;
|
||||||
|
|
||||||
|
public FrozenUnderFog(Actor self)
|
||||||
|
{
|
||||||
|
footprint = FootprintUtils.Tiles(self);
|
||||||
|
proxy = new FrozenActorProxy(self, footprint);
|
||||||
|
self.World.AddFrameEndTask(w => w.Add(proxy));
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsVisible(Actor self, Player byPlayer)
|
public bool IsVisible(Actor self, Player byPlayer)
|
||||||
{
|
{
|
||||||
return byPlayer == null || Shroud.GetVisOrigins(self).Any(o => byPlayer.Shroud.IsVisible(o));
|
return byPlayer == null || footprint.Any(c => byPlayer.Shroud.IsVisible(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TickRender(WorldRenderer wr, Actor self)
|
||||||
|
{
|
||||||
|
if (self.Destroyed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
visible = IsVisible(self, self.World.RenderPlayer);
|
||||||
|
if (visible)
|
||||||
|
proxy.SetRenderables(self.Render(wr));
|
||||||
}
|
}
|
||||||
|
|
||||||
IRenderable[] cache = { };
|
|
||||||
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
|
public IEnumerable<IRenderable> ModifyRender(Actor self, WorldRenderer wr, IEnumerable<IRenderable> r)
|
||||||
{
|
{
|
||||||
if (IsVisible(self, self.World.RenderPlayer))
|
return visible ? r : SpriteRenderable.None;
|
||||||
cache = r.ToArray();
|
|
||||||
return cache;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -461,6 +461,7 @@
|
|||||||
<Compile Include="World\DomainIndex.cs" />
|
<Compile Include="World\DomainIndex.cs" />
|
||||||
<Compile Include="MPStartUnits.cs" />
|
<Compile Include="MPStartUnits.cs" />
|
||||||
<Compile Include="Orders\SetChronoTankDestination.cs" />
|
<Compile Include="Orders\SetChronoTankDestination.cs" />
|
||||||
|
<Compile Include="Effects\FrozenActorProxy.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
Reference in New Issue
Block a user