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 public class ShroudRenderer
{ {
Map map; Map map;
ShroudInfo shroudInfo;
Sprite[] shadowBits = Game.modData.SpriteLoader.LoadAllSprites("shadow"); Sprite[] shadowBits = Game.modData.SpriteLoader.LoadAllSprites("shadow");
Sprite[,] sprites, fogSprites; Sprite[,] sprites, fogSprites;
int shroudHash; int shroudHash;
@@ -46,6 +47,7 @@ namespace OpenRA.Graphics
public ShroudRenderer(World world) public ShroudRenderer(World world)
{ {
this.map = world.Map; this.map = world.Map;
shroudInfo = Rules.Info["player"].Traits.Get<ShroudInfo>();
sprites = new Sprite[map.MapSize.X, map.MapSize.Y]; sprites = new Sprite[map.MapSize.X, map.MapSize.Y];
fogSprites = 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) if (initializePalettes)
{ {
fogPalette = wr.Palette("fog"); if (shroudInfo.Fog)
fogPalette = wr.Palette("fog");
shroudPalette = wr.Palette("shroud"); shroudPalette = wr.Palette("shroud");
initializePalettes = false; initializePalettes = false;
} }
@@ -158,8 +161,11 @@ namespace OpenRA.Graphics
GenerateSprites(shroud); GenerateSprites(shroud);
var clipRect = Game.viewport.WorldBounds(wr.world); var clipRect = Game.viewport.WorldBounds(wr.world);
// We draw the shroud when disabled to hide the sharp map edges
DrawShroud(wr, clipRect, sprites, shroudPalette); DrawShroud(wr, clipRect, sprites, shroudPalette);
if (wr.world.WorldActor.HasTrait<Fog>())
if (shroudInfo.Fog)
DrawShroud(wr, clipRect, fogSprites, fogPalette); DrawShroud(wr, clipRect, fogSprites, fogPalette);
} }

View File

@@ -182,7 +182,6 @@
<Compile Include="Traits\ValidateOrder.cs" /> <Compile Include="Traits\ValidateOrder.cs" />
<Compile Include="Traits\Waypoint.cs" /> <Compile Include="Traits\Waypoint.cs" />
<Compile Include="Traits\World\Country.cs" /> <Compile Include="Traits\World\Country.cs" />
<Compile Include="Traits\World\Fog.cs" />
<Compile Include="Traits\World\PlayerColorPalette.cs" /> <Compile Include="Traits\World\PlayerColorPalette.cs" />
<Compile Include="Traits\World\ResourceLayer.cs" /> <Compile Include="Traits\World\ResourceLayer.cs" />
<Compile Include="Traits\World\ResourceType.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 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 public class Shroud
{ {
Map map; public ShroudInfo Info;
Actor self; Actor self;
Map map;
int[,] visibleCells; int[,] visibleCells;
bool[,] exploredCells; bool[,] exploredCells;
@@ -34,8 +37,9 @@ namespace OpenRA.Traits
public int Hash { get; private set; } public int Hash { get; private set; }
public Shroud(Actor self) public Shroud(Actor self, ShroudInfo info)
{ {
Info = info;
this.self = self; this.self = self;
map = self.World.Map; map = self.World.Map;
@@ -44,6 +48,9 @@ namespace OpenRA.Traits
foggedCells = new bool[map.MapSize.X, map.MapSize.Y]; foggedCells = new bool[map.MapSize.X, map.MapSize.Y];
self.World.ActorAdded += AddActor; self.World.ActorAdded += AddActor;
self.World.ActorRemoved += RemoveActor; self.World.ActorRemoved += RemoveActor;
if (!info.Shroud)
ExploredBounds = map.Bounds;
} }
void Invalidate() void Invalidate()
@@ -270,6 +277,9 @@ namespace OpenRA.Traits
if (!map.IsInMap(x, y)) if (!map.IsInMap(x, y))
return false; return false;
if (!Info.Shroud)
return true;
return foggedCells[x,y]; return foggedCells[x,y];
} }
@@ -286,6 +296,9 @@ namespace OpenRA.Traits
if (x < 0 || x >= map.MapSize.X || y < 0 || y >= map.MapSize.Y) if (x < 0 || x >= map.MapSize.X || y < 0 || y >= map.MapSize.Y)
return false; return false;
if (!Info.Fog)
return true;
return visibleCells[x,y] != 0; 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="Widgets\Logic\CheatsLogic.cs" />
<Compile Include="CloakPaletteEffect.cs" /> <Compile Include="CloakPaletteEffect.cs" />
<Compile Include="Widgets\ColorPreviewManagerWidget.cs" /> <Compile Include="Widgets\ColorPreviewManagerWidget.cs" />
<Compile Include="FogPalette.cs" />
<Compile Include="Infiltrates.cs" /> <Compile Include="Infiltrates.cs" />
<Compile Include="Armament.cs" /> <Compile Include="Armament.cs" />
<Compile Include="DebugMuzzlePositions.cs" /> <Compile Include="DebugMuzzlePositions.cs" />

View File

@@ -15,11 +15,17 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
public enum ShroudPaletteType { Shroud, Fog, Combined };
[Desc("Adds the hard-coded shroud palette to the game")] [Desc("Adds the hard-coded shroud palette to the game")]
class ShroudPaletteInfo : ITraitInfo class ShroudPaletteInfo : ITraitInfo
{ {
[Desc("internal palette name")] [Desc("Internal palette name")]
public readonly string Name = "shroud"; public readonly string Name = "shroud";
[Desc("Palette type")]
public readonly ShroudPaletteType Type = ShroudPaletteType.Combined;
public object Create(ActorInitializer init) { return new ShroudPalette(this); } public object Create(ActorInitializer init) { return new ShroudPalette(this); }
} }
@@ -31,16 +37,37 @@ namespace OpenRA.Mods.RA
public void InitPalette(WorldRenderer wr) public void InitPalette(WorldRenderer wr)
{ {
var c = new[] { var c = info.Type == ShroudPaletteType.Shroud ? Shroud :
Color.Transparent, Color.Green, info.Type == ShroudPaletteType.Fog ? Fog : Combined;
Color.Blue, Color.Yellow,
Color.Black,
Color.FromArgb(128,0,0,0),
Color.Transparent,
Color.Transparent
};
wr.AddPalette(info.Name, new Palette(Exts.MakeArray(256, i => (uint)c[i % 8].ToArgb())), false); 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,
Color.FromArgb(128,0,0,0),
Color.Transparent,
Color.Transparent
};
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: DebugResourceOre:
DebugResourceOreCapacity: DebugResourceOreCapacity:
Shroud: Shroud:
Fog: false
BaseAttackNotifier: BaseAttackNotifier:
PlayerStatistics: PlayerStatistics:
@@ -159,7 +160,6 @@ World:
B: 0 B: 0
A: 180 A: 180
ShroudPalette: ShroudPalette:
FogPalette:
Country@gdi: Country@gdi:
Name: GDI Name: GDI
Race: gdi Race: gdi

View File

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

View File

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

View File

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

View File

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