From 3050cff67cc93a213aa502ee75c177cb3f861c17 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 9 Dec 2013 22:09:10 +1300 Subject: [PATCH 01/11] Support concrete bibs in D2K. --- OpenRA.Mods.RA/Buildings/Bib.cs | 19 +++- mods/d2k/sequences/structures.yaml | 148 +++++++++++++++++++++++++++++ 2 files changed, 162 insertions(+), 5 deletions(-) diff --git a/OpenRA.Mods.RA/Buildings/Bib.cs b/OpenRA.Mods.RA/Buildings/Bib.cs index 6f7dd14d70..87d0364135 100755 --- a/OpenRA.Mods.RA/Buildings/Bib.cs +++ b/OpenRA.Mods.RA/Buildings/Bib.cs @@ -23,31 +23,40 @@ namespace OpenRA.Mods.RA.Buildings public object Create(ActorInitializer init) { return new Bib(init.self, this); } } - public class Bib : IRender + public class Bib : IRender, INotifyAddedToWorld { readonly BibInfo info; - readonly List tiles; + List tiles; public Bib(Actor self, BibInfo info) { this.info = info; + } + public void AddedToWorld(Actor self) + { var rs = self.Trait(); var building = self.Info.Traits.Get(); var width = building.Dimensions.X; var bibOffset = building.Dimensions.Y - 1; var centerOffset = FootprintUtils.CenterOffset(building); - + var location = self.Location; tiles = new List(); for (var i = 0; i < 2*width; i++) { var index = i; var anim = new Animation(rs.GetImage(self)); - anim.PlayFetchIndex(info.Sequence, () => index); + var cellOffset = new CVec(i % width, i / width + bibOffset); + + // Some mods may define terrain-specific bibs + var terrain = self.World.GetTerrainType(location + cellOffset); + var testSequence = info.Sequence + "-" + terrain; + var sequence = anim.HasSequence(testSequence) ? testSequence : info.Sequence; + anim.PlayFetchIndex(sequence, () => index); anim.IsDecoration = true; // Z-order is one set to the top of the footprint - var offset = new CVec(i % width, i / width + bibOffset).ToWVec() - centerOffset; + var offset = cellOffset.ToWVec() - centerOffset; tiles.Add(new AnimationWithOffset(anim, () => offset, null, -(offset.Y + centerOffset.Y + 512))); } } diff --git a/mods/d2k/sequences/structures.yaml b/mods/d2k/sequences/structures.yaml index 61995dceb0..5718e1fa0e 100644 --- a/mods/d2k/sequences/structures.yaml +++ b/mods/d2k/sequences/structures.yaml @@ -254,6 +254,10 @@ conyarda: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4046 Offset: -30,-24 @@ -388,6 +392,10 @@ starporta: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4092 Offset: -30,-24 @@ -422,6 +430,10 @@ pwra: Frames: 617, 618, 637, 638 Length: 4 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 649, 650, 669, 670 + Length: 4 + Offset: -16,-16 icon: DATA Start: 4056 Offset: -30,-24 @@ -446,6 +458,10 @@ barra: Frames: 617, 618, 637, 638 Length: 4 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 649, 650, 669, 670 + Length: 4 + Offset: -16,-16 icon: DATA Start: 4059 Offset: -30,-24 @@ -474,6 +490,10 @@ radara: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4072 Offset: -30,-24 @@ -505,6 +525,10 @@ refa: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4066 Offset: -30,-24 @@ -557,6 +581,10 @@ hightecha: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4078 Offset: -30,-24 @@ -586,6 +614,10 @@ researcha: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4099 Offset: -30,-24 @@ -615,6 +647,10 @@ researchh: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4100 Offset: -30,-24 @@ -644,6 +680,10 @@ researcho: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4101 Offset: -30,-24 @@ -668,6 +708,10 @@ palacea: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4102 Offset: -30,-24 @@ -713,6 +757,10 @@ lighta: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4081 Offset: -30,-24 @@ -758,6 +806,10 @@ heavya: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4087 Offset: -30,-24 @@ -790,6 +842,10 @@ conyardh: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4047 Offset: -30,-24 @@ -825,6 +881,10 @@ starporth: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4093 Offset: -30,-24 @@ -859,6 +919,10 @@ pwrh: Frames: 617, 618, 637, 638 Length: 4 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 649, 650, 669, 670 + Length: 4 + Offset: -16,-16 icon: DATA Start: 4057 Offset: -30,-24 @@ -883,6 +947,10 @@ barrh: Frames: 617, 618, 637, 638 Length: 4 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 649, 650, 669, 670 + Length: 4 + Offset: -16,-16 icon: DATA Start: 4060 Offset: -30,-24 @@ -911,6 +979,10 @@ radarh: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4073 Offset: -30,-24 @@ -942,6 +1014,10 @@ refh: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4067 Offset: -30,-24 @@ -994,6 +1070,10 @@ hightechh: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4079 Offset: -30,-24 @@ -1026,6 +1106,10 @@ palaceh: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4103 Offset: -30,-24 @@ -1071,6 +1155,10 @@ lighth: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4082 Offset: -30,-24 @@ -1116,6 +1204,10 @@ heavyh: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4088 Offset: -30,-24 @@ -1148,6 +1240,10 @@ conyardo: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4048 Offset: -30,-24 @@ -1183,6 +1279,10 @@ starporto: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4094 Offset: -30,-24 @@ -1218,6 +1318,10 @@ pwro: Frames: 617, 618, 637, 638 Length: 4 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 649, 650, 669, 670 + Length: 4 + Offset: -16,-16 icon: DATA Start: 4058 Offset: -30,-24 @@ -1242,6 +1346,10 @@ barro: Frames: 617, 618, 637, 638 Length: 4 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 649, 650, 669, 670 + Length: 4 + Offset: -16,-16 icon: DATA Start: 4061 Offset: -30,-24 @@ -1270,6 +1378,10 @@ radaro: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4074 Offset: -30,-24 @@ -1301,6 +1413,10 @@ refo: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4068 Offset: -30,-24 @@ -1353,6 +1469,10 @@ hightecho: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4080 Offset: -30,-24 @@ -1377,6 +1497,10 @@ palaceo: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4104 Offset: -30,-24 @@ -1422,6 +1546,10 @@ lighto: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4083 Offset: -30,-24 @@ -1467,6 +1595,10 @@ heavyo: Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4089 Offset: -30,-24 @@ -1482,6 +1614,10 @@ palacec: # TODO: unused Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: palacecicon Start: 0 make: DATA @@ -1525,6 +1661,10 @@ starportc: # TODO: unused Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA # TODO: blank Start: 4020 Offset: -30,-24 @@ -1570,6 +1710,10 @@ heavyc: # TODO: unused Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA # TODO: blank Start: 4020 Offset: -30,-24 @@ -1602,6 +1746,10 @@ conyardc: # TODO: unused Frames: 611, 612, 613, 631, 632, 633 Length: 6 Offset: -16,-16 + bib-Concrete: BLOXBASE + Frames: 643, 644, 645, 663, 664, 665 + Length: 6 + Offset: -16,-16 icon: DATA Start: 4049 Offset: -30,-24 From c098f85e6f43e81dbd98571a1c7ec0a8975ed72b Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 16 Mar 2014 19:56:20 +1300 Subject: [PATCH 02/11] Add DamagedWithoutFoundation trait for building weathering. --- OpenRA.Mods.D2k/DamagedWithoutFoundation.cs | 75 +++++++++++++++++++++ OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj | 1 + 2 files changed, 76 insertions(+) create mode 100644 OpenRA.Mods.D2k/DamagedWithoutFoundation.cs diff --git a/OpenRA.Mods.D2k/DamagedWithoutFoundation.cs b/OpenRA.Mods.D2k/DamagedWithoutFoundation.cs new file mode 100644 index 0000000000..aef6193436 --- /dev/null +++ b/OpenRA.Mods.D2k/DamagedWithoutFoundation.cs @@ -0,0 +1,75 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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; +using System.Linq; +using OpenRA.GameRules; +using OpenRA.Mods.RA.Buildings; +using OpenRA.Traits; + +namespace OpenRA.Mods.Cnc +{ + class DamagedWithoutFoundationInfo : ITraitInfo, Requires + { + [WeaponReference] + public readonly string Weapon = "weathering"; + public readonly string[] SafeTerrain = { "Concrete" }; + public readonly int DamageThreshold = 50; + + public object Create(ActorInitializer init) { return new DamagedWithoutFoundation(init.self, this); } + } + + class DamagedWithoutFoundation : ITick, ISync, INotifyAddedToWorld + { + readonly DamagedWithoutFoundationInfo info; + readonly Health health; + readonly WeaponInfo weapon; + + [Sync] int damageThreshold = 100; + [Sync] int damageTicks; + + public DamagedWithoutFoundation(Actor self, DamagedWithoutFoundationInfo info) + { + this.info = info; + health = self.Trait(); + weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()]; + } + + public void AddedToWorld(Actor self) + { + var safeTiles = 0; + var totalTiles = 0; + foreach (var kv in self.OccupiesSpace.OccupiedCells()) + { + totalTiles++; + if (info.SafeTerrain.Contains(self.World.GetTerrainType(kv.First))) + safeTiles++; + } + + damageThreshold = (info.DamageThreshold * health.MaxHP + (100 - info.DamageThreshold) * safeTiles * health.MaxHP / totalTiles) / 100; + + // Actors start with maximum damage applied + var delta = health.HP - damageThreshold; + if (delta > 0) + health.InflictDamage(self, self.World.WorldActor, delta, null, false); + } + + public void Tick(Actor self) + { + if (health.HP <= damageThreshold || --damageTicks > 0) + return; + + foreach (var w in weapon.Warheads) + health.InflictDamage(self, self.World.WorldActor, w.Damage, w, false); + + damageTicks = weapon.ROF; + } + } +} diff --git a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj index 3d78f92267..8a730f4322 100644 --- a/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj +++ b/OpenRA.Mods.D2k/OpenRA.Mods.D2k.csproj @@ -81,6 +81,7 @@ + From 50d89629a2a2bb87d08ea784140aff3168268d8a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 16 Mar 2014 22:13:07 +1300 Subject: [PATCH 03/11] Add BuildableTerrainLayer and LaysTerrain traits. --- OpenRA.Mods.RA/Buildings/LaysTerrain.cs | 88 +++++++++++++++++++ OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 2 + OpenRA.Mods.RA/World/BuildableTerrainLayer.cs | 82 +++++++++++++++++ 3 files changed, 172 insertions(+) create mode 100755 OpenRA.Mods.RA/Buildings/LaysTerrain.cs create mode 100644 OpenRA.Mods.RA/World/BuildableTerrainLayer.cs diff --git a/OpenRA.Mods.RA/Buildings/LaysTerrain.cs b/OpenRA.Mods.RA/Buildings/LaysTerrain.cs new file mode 100755 index 0000000000..c7455458f9 --- /dev/null +++ b/OpenRA.Mods.RA/Buildings/LaysTerrain.cs @@ -0,0 +1,88 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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.Collections.Generic; +using System.Linq; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA.Buildings +{ + public class LaysTerrainInfo : ITraitInfo, Requires, Requires + { + [Desc("The terrain template to place. If the template is PickAny, then" + + "the actor footprint will be filled with this tile.")] + public readonly ushort Template = 0; + + [Desc("The terrain types that this template will be placed on")] + public readonly string[] TerrainTypes = {}; + + [Desc("Offset relative to the actor TopLeft. Not used if the template is PickAny")] + public readonly CVec Offset = CVec.Zero; + + public object Create(ActorInitializer init) { return new LaysTerrain(init.self, this); } + } + + public class LaysTerrain : INotifyAddedToWorld + { + readonly LaysTerrainInfo info; + readonly BuildableTerrainLayer layer; + readonly BuildingInfluence bi; + readonly TileTemplate template; + + public LaysTerrain(Actor self, LaysTerrainInfo info) + { + this.info = info; + layer = self.World.WorldActor.Trait(); + bi = self.World.WorldActor.Trait(); + template = self.World.TileSet.Templates[info.Template]; + } + + public void AddedToWorld(Actor self) + { + if (template.PickAny) + { + // Fill the footprint with random variants + foreach (var c in FootprintUtils.Tiles(self)) + { + // Only place on allowed terrain types + if (!info.TerrainTypes.Contains(self.World.GetTerrainType(c))) + continue; + + // Don't place under other buildings or custom terrain + if (bi.GetBuildingAt(c) != self || self.World.Map.CustomTerrain[c.X, c.Y] != null) + continue; + + var index = template.Tiles.Keys.Random(Game.CosmeticRandom); + layer.AddTile(c, new TileReference(template.Id, index)); + } + + return; + } + + var origin = self.Location + info.Offset; + foreach (var i in template.Tiles.Keys) + { + var c = origin + new CVec(i % template.Size.X, i / template.Size.X); + + // Only place on allowed terrain types + if (!info.TerrainTypes.Contains(self.World.GetTerrainType(c))) + continue; + + // Don't place under other buildings or custom terrain + if (bi.GetBuildingAt(c) != self || self.World.Map.CustomTerrain[c.X, c.Y] != null) + continue; + + layer.AddTile(c, new TileReference(template.Id, i)); + } + } + } +} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index e88021fff3..cef7e49b34 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -482,6 +482,8 @@ + + diff --git a/OpenRA.Mods.RA/World/BuildableTerrainLayer.cs b/OpenRA.Mods.RA/World/BuildableTerrainLayer.cs new file mode 100644 index 0000000000..b8be9a45d4 --- /dev/null +++ b/OpenRA.Mods.RA/World/BuildableTerrainLayer.cs @@ -0,0 +1,82 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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; +using System.Collections.Generic; +using System.Linq; +using OpenRA.FileFormats; +using OpenRA.Graphics; +using OpenRA.Mods.RA.Effects; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + public class BuildableTerrainLayerInfo : TraitInfo { } + public class BuildableTerrainLayer : IRenderOverlay, IWorldLoaded, ITickRender + { + Dictionary tiles; + Dictionary dirty; + Theater theater; + TileSet tileset; + Map map; + + public void WorldLoaded(World w, WorldRenderer wr) + { + theater = wr.Theater; + tileset = w.TileSet; + map = w.Map; + tiles = new Dictionary(); + dirty = new Dictionary(); + } + + public void AddTile(CPos cell, TileReference tile) + { + map.CustomTerrain[cell.X, cell.Y] = tileset.GetTerrainType(tile); + + // Terrain tiles define their origin at the topleft + var s = theater.TileSprite(tile); + dirty[cell] = new Sprite(s.sheet, s.bounds, float2.Zero, s.channel, s.blendMode); + } + + public void TickRender(WorldRenderer wr, Actor self) + { + var remove = new List(); + foreach (var kv in dirty) + { + if (!self.World.FogObscures(kv.Key)) + { + tiles[kv.Key] = kv.Value; + remove.Add(kv.Key); + } + } + + foreach (var r in remove) + dirty.Remove(r); + } + + public void Render(WorldRenderer wr) + { + var cliprect = wr.Viewport.CellBounds; + var pal = wr.Palette("terrain"); + + foreach (var kv in tiles) + { + if (!cliprect.Contains(kv.Key.X, kv.Key.Y)) + continue; + + if (wr.world.ShroudObscures(kv.Key)) + continue; + + new SpriteRenderable(kv.Value, kv.Key.CenterPosition, + WVec.Zero, -511, pal, 1f, true).Render(wr); + } + } + } +} From cc34a40ebc146f89382575a4e3679f2fa45752a0 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 16 Mar 2014 23:20:09 +1300 Subject: [PATCH 04/11] Add RemoveImmediately trait for things that should only exist for one tick. --- OpenRA.Mods.RA/OpenRA.Mods.RA.csproj | 1 + OpenRA.Mods.RA/RemoveImmediately.cs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 OpenRA.Mods.RA/RemoveImmediately.cs diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index cef7e49b34..c19a7a5305 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -484,6 +484,7 @@ + diff --git a/OpenRA.Mods.RA/RemoveImmediately.cs b/OpenRA.Mods.RA/RemoveImmediately.cs new file mode 100644 index 0000000000..e3181a4b14 --- /dev/null +++ b/OpenRA.Mods.RA/RemoveImmediately.cs @@ -0,0 +1,22 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + public class RemoveImmediatelyInfo : TraitInfo {} + + public class RemoveImmediately : INotifyAddedToWorld + { + public void AddedToWorld(Actor self) { self.Destroy(); } + } +} From e6c041e53f5679c6a6ac967eb060b13407908864 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 16 Mar 2014 23:12:46 +1300 Subject: [PATCH 05/11] Fix PBOG and Building to support concrete placement. --- OpenRA.Mods.RA/Buildings/Building.cs | 1 + OpenRA.Mods.RA/Buildings/Util.cs | 3 +++ .../Orders/PlaceBuildingOrderGenerator.cs | 14 ++++++++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.RA/Buildings/Building.cs b/OpenRA.Mods.RA/Buildings/Building.cs index 60a3490dd5..85d27ad1e6 100755 --- a/OpenRA.Mods.RA/Buildings/Building.cs +++ b/OpenRA.Mods.RA/Buildings/Building.cs @@ -32,6 +32,7 @@ namespace OpenRA.Mods.RA.Buildings public readonly string Footprint = "x"; public readonly int2 Dimensions = new int2(1, 1); public readonly bool RequiresBaseProvider = false; + public readonly bool AllowInvalidPlacement = false; public readonly string[] BuildSounds = {"placbldg.aud", "build5.aud"}; public readonly string[] SellSounds = {"cashturn.aud"}; diff --git a/OpenRA.Mods.RA/Buildings/Util.cs b/OpenRA.Mods.RA/Buildings/Util.cs index eda571bde6..acea2349b5 100755 --- a/OpenRA.Mods.RA/Buildings/Util.cs +++ b/OpenRA.Mods.RA/Buildings/Util.cs @@ -31,6 +31,9 @@ namespace OpenRA.Mods.RA.Buildings public static bool CanPlaceBuilding(this World world, string name, BuildingInfo building, CPos topLeft, Actor toIgnore) { + if (building.AllowInvalidPlacement) + return true; + var res = world.WorldActor.Trait(); return FootprintUtils.Tiles(name, building, topLeft).All( t => world.Map.IsInMap(t.X, t.Y) && res.GetResource(t) == null && diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index 3c5d95ddb1..17e012eb64 100644 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -90,11 +90,17 @@ namespace OpenRA.Mods.RA.Orders { if (!initialized) { - var rbi = Rules.Info[Building].Traits.Get(); - var palette = rbi.Palette ?? (Producer.Owner != null ? - rbi.PlayerPalette + Producer.Owner.InternalName : null); + var rbi = Rules.Info[Building].Traits.GetOrDefault(); + if (rbi == null) + preview = new IRenderable[0]; + else + { + var palette = rbi.Palette ?? (Producer.Owner != null ? + rbi.PlayerPalette + Producer.Owner.InternalName : null); + + preview = rbi.RenderPreview(Rules.Info[Building], wr.Palette(palette)); + } - preview = rbi.RenderPreview(Rules.Info[Building], wr.Palette(palette)); initialized = true; } From 9f3130474395cf08f4aebdd8082b016094a8a017 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 16 Mar 2014 23:23:23 +1300 Subject: [PATCH 06/11] Don't notify when the world attacks your base. --- OpenRA.Mods.RA/Player/BaseAttackNotifier.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs b/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs index 8a9b02d40f..273eeec2c4 100644 --- a/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs +++ b/OpenRA.Mods.RA/Player/BaseAttackNotifier.cs @@ -49,6 +49,9 @@ namespace OpenRA.Mods.RA if (e.Attacker.Owner == self.Owner) return; + if (e.Attacker == self.World.WorldActor) + return; + if (e.Attacker.Owner.IsAlliedWith(self.Owner) && e.Damage <= 0) return; From 52e27f036a6ab4a8217d6d53abf6ad2c2692e39a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 16 Mar 2014 22:41:58 +1300 Subject: [PATCH 07/11] Add buildable concrete and weathering to D2k. Fixes #2249. --- mods/d2k/rules/defaults.yaml | 2 +- mods/d2k/rules/structures.yaml | 42 ++++++++++++++++++++++++++++++ mods/d2k/rules/system-world.yaml | 1 + mods/d2k/sequences/structures.yaml | 10 +++++++ mods/d2k/weapons.yaml | 4 +++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/mods/d2k/rules/defaults.yaml b/mods/d2k/rules/defaults.yaml index ebebf2ec35..84e67a1cd0 100644 --- a/mods/d2k/rules/defaults.yaml +++ b/mods/d2k/rules/defaults.yaml @@ -263,4 +263,4 @@ Huntable: LuaScriptEvents: Demolishable: - + DamagedWithoutFoundation: diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index 5d3ecb80f3..9af5cca8d4 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -1,3 +1,42 @@ +^CONCRETE: + Building: + Adjacent: 4 + TerrainTypes: Rock + BuildSounds: BUILD1.WAV + AllowInvalidPlacement: true + LaysTerrain: + Template: 88 + TerrainTypes: Rock + Tooltip: + Name: Concrete + Description: Provides a strong foundation that prevents\ndamage from the terrain. + RenderSprites: + RemoveImmediately: + +CONCRETEA: + Inherits: ^CONCRETE + Building: + Footprint: xx xx + Dimensions: 2,2 + Buildable: + Queue: Building + BuildPaletteOrder:10 + Owner: atreides, harkonnen, ordos + Valued: + Cost: 20 + +CONCRETEB: + Inherits: ^CONCRETE + Building: + Footprint: xxx xxx xxx + Dimensions: 3,3 + Buildable: + Queue: Building + BuildPaletteOrder: 10 + Owner: atreides, harkonnen, ordos + Valued: + Cost: 50 + ^CONYARD: Inherits: ^Building Building: @@ -5,6 +44,9 @@ Footprint: xxx xxx Dimensions: 3,2 Adjacent: 4 + LaysTerrain: + TerrainTypes: Rock + Template: 88 Bib: Buildable: Queue: Building diff --git a/mods/d2k/rules/system-world.yaml b/mods/d2k/rules/system-world.yaml index c63fc1c0cb..9dad3f83ee 100644 --- a/mods/d2k/rules/system-world.yaml +++ b/mods/d2k/rules/system-world.yaml @@ -88,6 +88,7 @@ World: Race: ordos DomainIndex: PathfinderDebugOverlay: + BuildableTerrainLayer: D2kResourceLayer: ResourceClaimLayer: ResourceType@Spice: diff --git a/mods/d2k/sequences/structures.yaml b/mods/d2k/sequences/structures.yaml index 5718e1fa0e..119d4eb75f 100644 --- a/mods/d2k/sequences/structures.yaml +++ b/mods/d2k/sequences/structures.yaml @@ -1,3 +1,13 @@ +concretea: + icon: DATA + Start:4050 + Offset: -30,-24 + +concreteb: + icon: DATA + Start:4053 + Offset: -30,-24 + walla: idle: DATA Frames: 2527, 2530, 2528, 2538, 2531, 2532, 2542, 2535, 2529, 2539, 2533, 2534, 2540, 2536, 2537, 2541 diff --git a/mods/d2k/weapons.yaml b/mods/d2k/weapons.yaml index 8447341035..848cfdb788 100644 --- a/mods/d2k/weapons.yaml +++ b/mods/d2k/weapons.yaml @@ -621,3 +621,7 @@ Grenade: Damage: 60 ImpactSound: EXPLLG5.WAV +Weathering: + ROF: 100 + Warhead: + Damage: 5 \ No newline at end of file From e367ce44576c49b4f2dc0acecfcd77777a6727f1 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 18 Mar 2014 15:24:05 +1300 Subject: [PATCH 08/11] Fix BuildingInfluence style nits. --- OpenRA.Mods.RA/Buildings/BuildingInfluence.cs | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs b/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs index be31f43dd2..1f2c4a423c 100755 --- a/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs +++ b/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs @@ -1,6 +1,6 @@ #region Copyright & License Information /* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) + * Copyright 2007-2014 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, @@ -14,7 +14,7 @@ namespace OpenRA.Mods.RA.Buildings { public class BuildingInfluenceInfo : ITraitInfo { - public object Create( ActorInitializer init ) { return new BuildingInfluence( init.world ); } + public object Create(ActorInitializer init) { return new BuildingInfluence(init.world); } } public class BuildingInfluence @@ -22,30 +22,39 @@ namespace OpenRA.Mods.RA.Buildings Actor[,] influence; Map map; - public BuildingInfluence( World world ) + public BuildingInfluence(World world) { map = world.Map; influence = new Actor[map.MapSize.X, map.MapSize.Y]; - world.ActorAdded += - a => { if (a.HasTrait()) - ChangeInfluence(a, a.Trait(), true); }; - world.ActorRemoved += - a => { if (a.HasTrait()) - ChangeInfluence(a, a.Trait(), false); }; + world.ActorAdded += a => + { + var b = a.TraitOrDefault(); + if (b != null) + ChangeInfluence(a, b, true); + }; + + world.ActorRemoved += a => + { + var b = a.TraitOrDefault(); + if (b != null) + ChangeInfluence(a, b, false); + }; } - void ChangeInfluence( Actor a, Building building, bool isAdd ) + void ChangeInfluence(Actor a, Building building, bool isAdd) { - foreach( var u in FootprintUtils.Tiles( a.Info.Name, a.Info.Traits.Get(), a.Location ) ) - if( map.IsInMap( u ) ) - influence[ u.X, u.Y ] = isAdd ? a : null; + foreach (var u in FootprintUtils.Tiles(a.Info.Name, building.Info, a.Location)) + if (map.IsInMap(u)) + influence[u.X, u.Y] = isAdd ? a : null; } public Actor GetBuildingAt(CPos cell) { - if (!map.IsInMap(cell)) return null; + if (!map.IsInMap(cell)) + return null; + return influence[cell.X, cell.Y]; } } From 972f3ae8dc247cdae2ee80f8f4efd9bd172e0038 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 18 Mar 2014 15:21:44 +1300 Subject: [PATCH 09/11] Don't stomp over other building's influence. --- OpenRA.Mods.RA/Buildings/BuildingInfluence.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs b/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs index 1f2c4a423c..3c1a8c1254 100755 --- a/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs +++ b/OpenRA.Mods.RA/Buildings/BuildingInfluence.cs @@ -31,23 +31,24 @@ namespace OpenRA.Mods.RA.Buildings world.ActorAdded += a => { var b = a.TraitOrDefault(); - if (b != null) - ChangeInfluence(a, b, true); + if (b == null) + return; + + foreach (var u in FootprintUtils.Tiles(a.Info.Name, b.Info, a.Location)) + if (map.IsInMap(u) && influence[u.X, u.Y] == null) + influence[u.X, u.Y] = a; }; world.ActorRemoved += a => { var b = a.TraitOrDefault(); - if (b != null) - ChangeInfluence(a, b, false); - }; - } + if (b == null) + return; - void ChangeInfluence(Actor a, Building building, bool isAdd) - { - foreach (var u in FootprintUtils.Tiles(a.Info.Name, building.Info, a.Location)) - if (map.IsInMap(u)) - influence[u.X, u.Y] = isAdd ? a : null; + foreach (var u in FootprintUtils.Tiles(a.Info.Name, b.Info, a.Location)) + if (map.IsInMap(u) && influence[u.X, u.Y] == a) + influence[u.X, u.Y] = null; + }; } public Actor GetBuildingAt(CPos cell) From c01c5ff72d39aeebe1e531980a472b520b39d250 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 18 Mar 2014 15:28:00 +1300 Subject: [PATCH 10/11] Actors outside the world can't grant buildable area. --- OpenRA.Mods.RA/Buildings/Building.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/Buildings/Building.cs b/OpenRA.Mods.RA/Buildings/Building.cs index 85d27ad1e6..5ead5ea237 100755 --- a/OpenRA.Mods.RA/Buildings/Building.cs +++ b/OpenRA.Mods.RA/Buildings/Building.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.RA.Buildings { var pos = new CPos(x, y); var at = bi.GetBuildingAt(pos); - if (at == null || !at.HasTrait()) + if (at == null || !at.IsInWorld || !at.HasTrait()) continue; if (at.Owner == p || (allyBuildRadius && at.Owner.Stances[p] == Stance.Ally)) From 90519a37a9a782d40a7493a3b23d412be640c249 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 18 Mar 2014 15:40:10 +1300 Subject: [PATCH 11/11] Update changelog. --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index e621ad2388..914b091344 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -34,6 +34,7 @@ NEW: Removed the build radius restrictions. Added the BLOXXMAS terrain tiles from the 1.06 patch. Saboteur can now plant C4 on vehicles. + Added concrete plates and building weathering. Red Alert: Chinook rotors now counter-rotate. Transports will now open their doors when at shore.