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

@@ -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,6 +152,7 @@ namespace OpenRA.Graphics
{
if (initializePalettes)
{
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);
}

View File

@@ -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" />

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

View File

@@ -1,46 +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 System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
[Desc("Adds the hard-coded fog palette to the game")]
class FogPaletteInfo : ITraitInfo
{
[Desc("internal palette name")]
public readonly string Name = "fog";
public object Create(ActorInitializer init) { return new FogPalette(this); }
}
class FogPalette : IPalette
{
readonly FogPaletteInfo info;
public FogPalette(FogPaletteInfo info) { this.info = info; }
public void InitPalette(WorldRenderer wr)
{
var c = new[] {
Color.Transparent, Color.Green,
Color.Blue, Color.Yellow,
Color.FromArgb(128,0,0,0),
Color.FromArgb(128,0,0,0),
Color.FromArgb(128,0,0,0),
Color.FromArgb(64,0,0,0)
};
wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (uint)c[i % 8].ToArgb())), false);
}
}
}

View File

@@ -416,7 +416,6 @@
<Compile Include="Widgets\Logic\CheatsLogic.cs" />
<Compile Include="CloakPaletteEffect.cs" />
<Compile Include="Widgets\ColorPreviewManagerWidget.cs" />
<Compile Include="FogPalette.cs" />
<Compile Include="Infiltrates.cs" />
<Compile Include="Armament.cs" />
<Compile Include="DebugMuzzlePositions.cs" />

View File

@@ -15,11 +15,17 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
public enum ShroudPaletteType { Shroud, Fog, Combined };
[Desc("Adds the hard-coded shroud palette to the game")]
class ShroudPaletteInfo : ITraitInfo
{
[Desc("internal palette name")]
[Desc("Internal palette name")]
public readonly string Name = "shroud";
[Desc("Palette type")]
public readonly ShroudPaletteType Type = ShroudPaletteType.Combined;
public object Create(ActorInitializer init) { return new ShroudPalette(this); }
}
@@ -31,7 +37,13 @@ namespace OpenRA.Mods.RA
public void InitPalette(WorldRenderer wr)
{
var c = new[] {
var c = info.Type == ShroudPaletteType.Shroud ? Shroud :
info.Type == ShroudPaletteType.Fog ? Fog : Combined;
wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (uint)c[i % 8].ToArgb())), false);
}
static Color[] Shroud = new[] {
Color.Transparent, Color.Green,
Color.Blue, Color.Yellow,
Color.Black,
@@ -40,7 +52,22 @@ namespace OpenRA.Mods.RA
Color.Transparent
};
wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (uint)c[i % 8].ToArgb())), false);
}
static Color[] Fog = new[] {
Color.Transparent, Color.Green,
Color.Blue, Color.Yellow,
Color.FromArgb(128,0,0,0),
Color.FromArgb(128,0,0,0),
Color.FromArgb(128,0,0,0),
Color.FromArgb(64,0,0,0)
};
static Color[] Combined = new[] {
Color.Transparent, Color.Green,
Color.Blue, Color.Yellow,
Color.Black,
Color.FromArgb(192,0,0,0),
Color.FromArgb(128,0,0,0),
Color.FromArgb(64,0,0,0)
};
}
}

View File

@@ -95,6 +95,7 @@ Player:
DebugResourceOre:
DebugResourceOreCapacity:
Shroud:
Fog: false
BaseAttackNotifier:
PlayerStatistics:
@@ -159,7 +160,6 @@ World:
B: 0
A: 180
ShroudPalette:
FogPalette:
Country@gdi:
Name: GDI
Race: gdi

View File

@@ -257,8 +257,11 @@ World:
G: 0
B: 0
A: 180
ShroudPalette:
FogPalette:
ShroudPalette@shroud:
Type: Shroud
ShroudPalette@fog:
Name: fog
Type: Fog
Country@gdi:
Name: GDI
Race: gdi
@@ -306,7 +309,6 @@ World:
MPStartLocations:
SpatialBins:
BinSize: 4
Fog:
CrateSpawner:
Minimum: 1
Maximum: 6

View File

@@ -340,8 +340,11 @@ World:
G: 0
B: 0
A: 180
ShroudPalette:
FogPalette:
ShroudPalette@shroud:
Type: Shroud
ShroudPalette@fog:
Name: fog
Type: Fog
Country@Atreides:
Name: Atreides
Race: atreides
@@ -388,7 +391,6 @@ World:
Faction: ordos
SpatialBins:
BinSize: 4
Fog:
PathFinder:
ValidateOrder:
DebugPauseState:

View File

@@ -122,6 +122,7 @@ Player:
DebugResourceOreCapacity:
GpsWatcher:
Shroud:
Fog: false
BaseAttackNotifier:
PlayerStatistics:
@@ -193,7 +194,6 @@ World:
B: 0
A: 180
ShroudPalette:
FogPalette:
Country@0:
Name: Allies
Race: allies

View File

@@ -574,8 +574,11 @@ World:
G: 0
B: 0
A: 180
ShroudPalette:
FogPalette:
ShroudPalette@shroud:
Type: Shroud
ShroudPalette@fog:
Name: fog
Type: Fog
Country@0:
Name: Allies
Race: allies
@@ -621,7 +624,6 @@ World:
SpawnMPUnits:
SpatialBins:
BinSize: 4
Fog:
PathFinder:
ValidateOrder:
DebugPauseState: