Allow maps/mods to properly disable fog or shroud (or both).
This commit is contained in:
@@ -16,6 +16,7 @@ namespace OpenRA.Graphics
|
||||
public class ShroudRenderer
|
||||
{
|
||||
Map map;
|
||||
ShroudInfo shroudInfo;
|
||||
Sprite[] shadowBits = Game.modData.SpriteLoader.LoadAllSprites("shadow");
|
||||
Sprite[,] sprites, fogSprites;
|
||||
int shroudHash;
|
||||
@@ -46,6 +47,7 @@ namespace OpenRA.Graphics
|
||||
public ShroudRenderer(World world)
|
||||
{
|
||||
this.map = world.Map;
|
||||
shroudInfo = Rules.Info["player"].Traits.Get<ShroudInfo>();
|
||||
|
||||
sprites = new Sprite[map.MapSize.X, map.MapSize.Y];
|
||||
fogSprites = new Sprite[map.MapSize.X, map.MapSize.Y];
|
||||
@@ -150,7 +152,8 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
if (initializePalettes)
|
||||
{
|
||||
fogPalette = wr.Palette("fog");
|
||||
if (shroudInfo.Fog)
|
||||
fogPalette = wr.Palette("fog");
|
||||
shroudPalette = wr.Palette("shroud");
|
||||
initializePalettes = false;
|
||||
}
|
||||
@@ -158,8 +161,11 @@ namespace OpenRA.Graphics
|
||||
GenerateSprites(shroud);
|
||||
|
||||
var clipRect = Game.viewport.WorldBounds(wr.world);
|
||||
|
||||
// We draw the shroud when disabled to hide the sharp map edges
|
||||
DrawShroud(wr, clipRect, sprites, shroudPalette);
|
||||
if (wr.world.WorldActor.HasTrait<Fog>())
|
||||
|
||||
if (shroudInfo.Fog)
|
||||
DrawShroud(wr, clipRect, fogSprites, fogPalette);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,6 @@
|
||||
<Compile Include="Traits\ValidateOrder.cs" />
|
||||
<Compile Include="Traits\Waypoint.cs" />
|
||||
<Compile Include="Traits\World\Country.cs" />
|
||||
<Compile Include="Traits\World\Fog.cs" />
|
||||
<Compile Include="Traits\World\PlayerColorPalette.cs" />
|
||||
<Compile Include="Traits\World\ResourceLayer.cs" />
|
||||
<Compile Include="Traits\World\ResourceType.cs" />
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#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 OpenRA.FileFormats;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
[Desc("This tag trait will enable fog of war in ShroudRenderer.",
|
||||
"Don't forget about HiddenUnderFog and FrozenUnderFog.")]
|
||||
public class FogInfo : TraitInfo<Fog> { }
|
||||
|
||||
public class Fog { }
|
||||
}
|
||||
@@ -18,13 +18,16 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public class ShroudInfo : ITraitInfo
|
||||
{
|
||||
public object Create(ActorInitializer init) { return new Shroud(init.self); }
|
||||
public readonly bool Shroud = true;
|
||||
public readonly bool Fog = true;
|
||||
public object Create(ActorInitializer init) { return new Shroud(init.self, this); }
|
||||
}
|
||||
|
||||
public class Shroud
|
||||
{
|
||||
Map map;
|
||||
public ShroudInfo Info;
|
||||
Actor self;
|
||||
Map map;
|
||||
|
||||
int[,] visibleCells;
|
||||
bool[,] exploredCells;
|
||||
@@ -34,8 +37,9 @@ namespace OpenRA.Traits
|
||||
|
||||
public int Hash { get; private set; }
|
||||
|
||||
public Shroud(Actor self)
|
||||
public Shroud(Actor self, ShroudInfo info)
|
||||
{
|
||||
Info = info;
|
||||
this.self = self;
|
||||
map = self.World.Map;
|
||||
|
||||
@@ -44,6 +48,9 @@ namespace OpenRA.Traits
|
||||
foggedCells = new bool[map.MapSize.X, map.MapSize.Y];
|
||||
self.World.ActorAdded += AddActor;
|
||||
self.World.ActorRemoved += RemoveActor;
|
||||
|
||||
if (!info.Shroud)
|
||||
ExploredBounds = map.Bounds;
|
||||
}
|
||||
|
||||
void Invalidate()
|
||||
@@ -270,6 +277,9 @@ namespace OpenRA.Traits
|
||||
if (!map.IsInMap(x, y))
|
||||
return false;
|
||||
|
||||
if (!Info.Shroud)
|
||||
return true;
|
||||
|
||||
return foggedCells[x,y];
|
||||
}
|
||||
|
||||
@@ -286,6 +296,9 @@ namespace OpenRA.Traits
|
||||
if (x < 0 || x >= map.MapSize.X || y < 0 || y >= map.MapSize.Y)
|
||||
return false;
|
||||
|
||||
if (!Info.Fog)
|
||||
return true;
|
||||
|
||||
return visibleCells[x,y] != 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user