Allow maps/mods to properly disable fog or shroud (or both).

This commit is contained in:
Paul Chote
2013-04-11 22:29:51 +12:00
parent 2c680a1831
commit 400ad49de0
12 changed files with 77 additions and 93 deletions

View File

@@ -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 { }
}

View File

@@ -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;
}