diff --git a/OpenRA.Game/Graphics/OverlayRenderer.cs b/OpenRA.Game/Graphics/OverlayRenderer.cs index cf56db58b5..55adb33de9 100755 --- a/OpenRA.Game/Graphics/OverlayRenderer.cs +++ b/OpenRA.Game/Graphics/OverlayRenderer.cs @@ -72,18 +72,18 @@ namespace OpenRA.Graphics Game.CellSize * (float2)location, "terrain"); } - var o = tr.overlay; - if (o < overlaySprites.Length) - { - var location = new int2(x, y); - var sprites = overlaySprites[o]; - var spriteIndex = 0; - if (Ore.overlayIsFence[o]) spriteIndex = NearbyFences(x, y); - else if (Ore.overlayIsOre[o]) spriteIndex = map.MapTiles[x,y].density - 1; - else if (Ore.overlayIsGems[o]) spriteIndex = map.MapTiles[x,y].density - 1; - spriteRenderer.DrawSprite(sprites[spriteIndex], - Game.CellSize * (float2)location, "terrain"); - } + //var o = tr.overlay; + //if (o < overlaySprites.Length) + //{ + // var location = new int2(x, y); + // var sprites = overlaySprites[o]; + // var spriteIndex = 0; + // if (Ore.overlayIsFence[o]) spriteIndex = NearbyFences(x, y); + // else if (Ore.overlayIsOre[o]) spriteIndex = map.MapTiles[x,y].density - 1; + // else if (Ore.overlayIsGems[o]) spriteIndex = map.MapTiles[x,y].density - 1; + // spriteRenderer.DrawSprite(sprites[spriteIndex], + // Game.CellSize * (float2)location, "terrain"); + //} } spriteRenderer.Flush(); diff --git a/OpenRA.Game/Graphics/TerrainRenderer.cs b/OpenRA.Game/Graphics/TerrainRenderer.cs index 17d9e9f490..c456dd312f 100644 --- a/OpenRA.Game/Graphics/TerrainRenderer.cs +++ b/OpenRA.Game/Graphics/TerrainRenderer.cs @@ -21,6 +21,7 @@ using System.Drawing; using OpenRA.FileFormats; using OpenRA.FileFormats.Graphics; +using OpenRA.Traits; namespace OpenRA.Graphics { @@ -104,6 +105,9 @@ namespace OpenRA.Graphics new Range(indicesPerRow * firstRow, indicesPerRow * lastRow), terrainSheet.Texture, PrimitiveType.TriangleList, renderer.SpriteShader)); + foreach (var r in Game.world.WorldActor.traits.WithInterface()) + r.Render(); + overlayRenderer.Draw(); } } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 5a5d754c42..a72530894c 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -1,4 +1,4 @@ - + Debug @@ -216,6 +216,7 @@ + @@ -253,6 +254,7 @@ + diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index e1007137a3..513856ccad 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -140,4 +140,6 @@ namespace OpenRA.Traits bool Pressed { get; } void OnClick(); } + + public interface IRenderOverlay { void Render(); } } diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs new file mode 100644 index 0000000000..ac7ed0b317 --- /dev/null +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -0,0 +1,88 @@ +#region Copyright & License Information +/* + * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. + * This file is part of OpenRA. + * + * OpenRA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * OpenRA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OpenRA. If not, see . + */ +#endregion + +using System; +using System.Linq; +using OpenRA.Graphics; + +namespace OpenRA.Traits +{ + class ResourceLayerInfo : ITraitInfo + { + public readonly string[] SpriteNames = { }; + public readonly int[] OverlayIndices = { }; + public readonly string Palette = "terrain"; + public object Create(Actor self) { return new ResourceLayer(self, this); } + } + + class ResourceLayer : IRenderOverlay, ILoadWorldHook + { + ResourceLayerInfo info; + Sprite[][] sprites; + CellContents[,] content = new CellContents[128,128]; + SpriteRenderer sr; + + public ResourceLayer(Actor self, ResourceLayerInfo info) + { + this.info = info; + sprites = info.SpriteNames.Select( f => SpriteSheetBuilder.LoadAllSprites(f)).ToArray(); + sr = new SpriteRenderer( Game.renderer, true ); + } + + public void Render() + { + var shroud = Game.world.LocalPlayer.Shroud; + var map = Game.world.Map; + + for (int y = map.YOffset; y < map.YOffset + map.Height; y++) + for (int x = map.XOffset; x < map.XOffset + map.Width; x++) + { + if (!shroud.IsExplored(new int2(x, y))) continue; + if (content[x, y].contents != null) + sr.DrawSprite(content[x, y].contents[content[x, y].density], + Game.CellSize * new int2(x, y), + info.Palette); + } + + sr.Flush(); + } + + public void WorldLoaded(World w) + { + var map = w.Map; + + for (int y = map.YOffset; y < map.YOffset + map.Height; y++) + for (int x = map.XOffset; x < map.XOffset + map.Width; x++) + if (info.OverlayIndices.Contains(w.Map.MapTiles[x, y].overlay)) + content[x, y].contents = ChooseContent(w, w.Map.MapTiles[x, y].overlay); + } + + Sprite[] ChooseContent(World w, int overlay) + { + return sprites[w.SharedRandom.Next(sprites.Length)]; + } + + public struct CellContents + { + public Sprite[] contents; + public int density; + } + } +} diff --git a/OpenRA.Game/Traits/World/WallLoadHook.cs b/OpenRA.Game/Traits/World/WallLoadHook.cs new file mode 100644 index 0000000000..806179183e --- /dev/null +++ b/OpenRA.Game/Traits/World/WallLoadHook.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenRA.Traits +{ + class WallLoadHookInfo : ITraitInfo + { + public readonly int[] OverlayIndices = { }; + public readonly string ActorType = "brik"; + + public object Create(Actor self) { return new WallLoadHook( self, this ); } + } + + class WallLoadHook : ILoadWorldHook + { + WallLoadHookInfo info; + public WallLoadHook(Actor self, WallLoadHookInfo info) + { + this.info = info; + } + + public void WorldLoaded(World w) + { + var map = w.Map; + + for (int y = map.YOffset; y < map.YOffset + map.Height; y++) + for (int x = map.XOffset; x < map.XOffset + map.Width; x++) + if (info.OverlayIndices.Contains(w.Map.MapTiles[x, y].overlay)) + w.CreateActor(info.ActorType, new int2(x, y), w.players[0]); // todo: neutral player or null? + } + } +} diff --git a/mods/cnc/chem.shp b/mods/cnc/chem.shp new file mode 100644 index 0000000000..8116e742c7 Binary files /dev/null and b/mods/cnc/chem.shp differ diff --git a/mods/cnc/flame.shp b/mods/cnc/flame.shp new file mode 100644 index 0000000000..d7a7ce418e Binary files /dev/null and b/mods/cnc/flame.shp differ diff --git a/mods/cnc/system.yaml b/mods/cnc/system.yaml index 456b89fb9b..a20142ddf6 100644 --- a/mods/cnc/system.yaml +++ b/mods/cnc/system.yaml @@ -165,4 +165,8 @@ World: Name: Nod Race: nod SellButton: - RepairButton: \ No newline at end of file + RepairButton: + ResourceLayer: + OverlayIndices: 5,6,7,8,9,10,11,12 + Palette: player + SpriteNames: ti1,ti2,ti3,ti4,ti5,ti6,ti7,ti8,ti9,ti10,ti11,ti12 diff --git a/mods/cnc/ti1.tem b/mods/cnc/ti1.tem new file mode 100644 index 0000000000..44c875b337 Binary files /dev/null and b/mods/cnc/ti1.tem differ diff --git a/mods/cnc/ti10.tem b/mods/cnc/ti10.tem new file mode 100644 index 0000000000..455ae272bc Binary files /dev/null and b/mods/cnc/ti10.tem differ diff --git a/mods/cnc/ti11.tem b/mods/cnc/ti11.tem new file mode 100644 index 0000000000..5efe14ac83 Binary files /dev/null and b/mods/cnc/ti11.tem differ diff --git a/mods/cnc/ti12.tem b/mods/cnc/ti12.tem new file mode 100644 index 0000000000..c8edbd7059 Binary files /dev/null and b/mods/cnc/ti12.tem differ diff --git a/mods/cnc/ti2.tem b/mods/cnc/ti2.tem new file mode 100644 index 0000000000..16128647be Binary files /dev/null and b/mods/cnc/ti2.tem differ diff --git a/mods/cnc/ti3.tem b/mods/cnc/ti3.tem new file mode 100644 index 0000000000..0c12c8f414 Binary files /dev/null and b/mods/cnc/ti3.tem differ diff --git a/mods/cnc/ti4.tem b/mods/cnc/ti4.tem new file mode 100644 index 0000000000..3ecc6e643a Binary files /dev/null and b/mods/cnc/ti4.tem differ diff --git a/mods/cnc/ti5.tem b/mods/cnc/ti5.tem new file mode 100644 index 0000000000..95f87dba09 Binary files /dev/null and b/mods/cnc/ti5.tem differ diff --git a/mods/cnc/ti6.tem b/mods/cnc/ti6.tem new file mode 100644 index 0000000000..df53dc11aa Binary files /dev/null and b/mods/cnc/ti6.tem differ diff --git a/mods/cnc/ti7.tem b/mods/cnc/ti7.tem new file mode 100644 index 0000000000..ca4d772340 Binary files /dev/null and b/mods/cnc/ti7.tem differ diff --git a/mods/cnc/ti8.tem b/mods/cnc/ti8.tem new file mode 100644 index 0000000000..95cecd04b3 Binary files /dev/null and b/mods/cnc/ti8.tem differ diff --git a/mods/cnc/ti9.tem b/mods/cnc/ti9.tem new file mode 100644 index 0000000000..d8240ddf38 Binary files /dev/null and b/mods/cnc/ti9.tem differ diff --git a/mods/ra/rules.yaml b/mods/ra/rules.yaml index 6d7e6c569a..03132a1fb3 100644 --- a/mods/ra/rules.yaml +++ b/mods/ra/rules.yaml @@ -216,6 +216,24 @@ World: SellButton: RepairButton: PowerDownButton: + WallLoadHook@sbag: + ActorType: sbag + OverlayIndices: 0,24 + WallLoadHook@cycl: + ActorType: cycl + OverlayIndices: 1 + WallLoadHook@brik: + ActorType: brik + OverlayIndices: 2 + WallLoadHook@fenc: + ActorType: fenc + OverlayIndices: 3 + WallLoadHook@wood: + ActorType: wood + OverlayIndices: 4 + WallLoadHook@barb: + ActorType: barb + OverlayIndices: 23 MGG: GeneratesGap: