From 04e5edc811b646165a896209c4b0211d9bf745e2 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 4 Aug 2013 19:07:33 +1200 Subject: [PATCH] Rewrite bib to match new FrozenUnderFog capabilities. --- OpenRA.Mods.RA/Buildings/BibLayer.cs | 122 ++++++++++++++++----------- mods/cnc/rules/structures.yaml | 11 +++ mods/cnc/rules/system.yaml | 1 - mods/d2k/rules/defaults.yaml | 1 - mods/d2k/rules/structures.yaml | 30 ++++++- mods/d2k/rules/system.yaml | 3 - mods/ra/maps/Fort-Lonestar/map.yaml | 1 + mods/ra/rules/civilian.yaml | 3 + mods/ra/rules/structures.yaml | 14 +++ mods/ra/rules/system.yaml | 1 - mods/ts/rules/structures.yaml | 5 -- mods/ts/rules/system.yaml | 1 - 12 files changed, 126 insertions(+), 67 deletions(-) diff --git a/OpenRA.Mods.RA/Buildings/BibLayer.cs b/OpenRA.Mods.RA/Buildings/BibLayer.cs index ce4711c1ea..503d7dc400 100755 --- a/OpenRA.Mods.RA/Buildings/BibLayer.cs +++ b/OpenRA.Mods.RA/Buildings/BibLayer.cs @@ -20,72 +20,40 @@ namespace OpenRA.Mods.RA.Buildings { class BibLayerInfo : ITraitInfo { - public readonly string[] BibTypes = { "bib3", "bib2", "bib1" }; - public readonly int[] BibWidths = { 2, 3, 4 }; - public readonly bool FrozenUnderFog = false; - public object Create(ActorInitializer init) { return new BibLayer(init.self, this); } + public object Create(ActorInitializer init) { return new BibLayer(init.self); } } struct CachedBib { - public Dictionary> Tiles; + public Dictionary Tiles; public IEnumerable Footprint; public bool Visible; + public bool Immediate; } - class BibLayer : IRenderOverlay, IWorldLoaded, ITickRender + class BibLayer : IRenderOverlay, ITickRender { World world; - BibLayerInfo info; Dictionary visible; Dictionary dirty; - Sprite[][] bibSprites; + Cache sprites; - public BibLayer(Actor self, BibLayerInfo info) + public BibLayer(Actor self) { - this.info = info; - bibSprites = info.BibTypes.Select(x => Game.modData.SpriteLoader.LoadAllSprites(x)).ToArray(); - - self.World.ActorAdded += a => DoBib(a, true); - self.World.ActorRemoved += a => DoBib(a, false); - } - - public void WorldLoaded(World w) - { - world = w; + world = self.World; visible = new Dictionary(); dirty = new Dictionary(); + sprites = new Cache(x => Game.modData.SpriteLoader.LoadAllSprites(x)); } - public void DoBib(Actor b, bool isAdd) + public void Update(Actor a, CachedBib bib) { - if (!b.HasTrait()) - return; + dirty[a] = bib; + } - var buildingInfo = b.Info.Traits.Get(); - var size = buildingInfo.Dimensions.X; - var bibOffset = buildingInfo.Dimensions.Y - 1; - - var bib = Array.IndexOf(info.BibWidths, size); - if (bib < 0) - { - Log.Write("debug", "Cannot bib {0}-wide building {1}", size, b.Info.Name); - return; - } - - dirty[b] = new CachedBib() - { - Footprint = FootprintUtils.Tiles(b), - Tiles = new Dictionary>(), - Visible = isAdd - }; - - for (var i = 0; i < 2 * size; i++) - { - var cell = b.Location + new CVec(i % size, i / size + bibOffset); - var tile = new TileReference((byte)(bib + 1), (byte) i); - dirty[b].Tiles.Add(cell, tile); - } + public Sprite[] LoadSprites(string bibType) + { + return sprites[bibType]; } public void TickRender(WorldRenderer wr, Actor self) @@ -93,7 +61,7 @@ namespace OpenRA.Mods.RA.Buildings var remove = new List(); foreach (var kv in dirty) { - if (!info.FrozenUnderFog || kv.Value.Footprint.Any(c => !self.World.FogObscures(c))) + if (kv.Value.Immediate || kv.Value.Footprint.Any(c => !self.World.FogObscures(c))) { if (kv.Value.Visible) visible[kv.Key] = kv.Value; @@ -119,16 +87,68 @@ namespace OpenRA.Mods.RA.Buildings { if (!cliprect.Contains(kv.Key.X, kv.Key.Y)) continue; + if (world.ShroudObscures(kv.Key)) continue; - var tile = bibSprites[kv.Value.type - 1][kv.Value.index]; - tile.DrawAt(wr.ScreenPxPosition(kv.Key.CenterPosition) - 0.5f * tile.size, pal); + kv.Value.DrawAt(wr.ScreenPxPosition(kv.Key.CenterPosition) - 0.5f * kv.Value.size, pal); } } } } - public class BibInfo : TraitInfo, Requires { } - public class Bib { } + public class BibInfo : ITraitInfo, Requires + { + public readonly string Sprite = "bib3"; + + public object Create(ActorInitializer init) { return new Bib(init.self, this); } + } + + public class Bib : INotifyAddedToWorld, INotifyRemovedFromWorld + { + readonly BibInfo info; + readonly BibLayer bibLayer; + bool firstAdd; + + public Bib(Actor self, BibInfo info) + { + this.info = info; + bibLayer = self.World.WorldActor.Trait(); + firstAdd = true; + } + + void DoBib(Actor self, bool add) + { + var buildingInfo = self.Info.Traits.Get(); + var size = buildingInfo.Dimensions.X; + var bibOffset = buildingInfo.Dimensions.Y - 1; + var sprites = bibLayer.LoadSprites(info.Sprite); + + if (sprites.Length != 2*size) + throw new InvalidOperationException("{0} is an invalid bib for a {1}-wide building".F(info.Sprite, size)); + + var immediate = !self.HasTrait() || + (firstAdd && self.Info.Traits.GetOrDefault().StartsRevealed); + + var dirty = new CachedBib() + { + Footprint = FootprintUtils.Tiles(self), + Tiles = new Dictionary(), + Visible = add, + Immediate = immediate + }; + + for (var i = 0; i < 2 * size; i++) + { + var cell = self.Location + new CVec(i % size, i / size + bibOffset); + dirty.Tiles.Add(cell, sprites[i]); + } + + firstAdd = false; + bibLayer.Update(self, dirty); + } + + public void AddedToWorld(Actor self) { DoBib(self, true); } + public void RemovedFromWorld(Actor self) { DoBib(self, false); } + } } diff --git a/mods/cnc/rules/structures.yaml b/mods/cnc/rules/structures.yaml index 178bf52614..e9ec07d07a 100644 --- a/mods/cnc/rules/structures.yaml +++ b/mods/cnc/rules/structures.yaml @@ -23,6 +23,7 @@ FACT: RevealsShroud: Range: 10 Bib: + Sprite: bib2 Production: Produces: Building,Defense Transforms: @@ -72,6 +73,7 @@ NUKE: RevealsShroud: Range: 4 Bib: + Sprite: bib3 NUK2: Inherits: ^Building @@ -96,6 +98,7 @@ NUK2: RevealsShroud: Range: 4 Bib: + Sprite: bib3 PROC: Inherits: ^Building @@ -118,6 +121,7 @@ PROC: RevealsShroud: Range: 6 Bib: + Sprite: bib2 TiberiumRefinery: DockOffset: 0,2 TickRate: 15 @@ -191,6 +195,7 @@ PYLE: RevealsShroud: Range: 5 Bib: + Sprite: bib3 RallyPoint: Exit@1: SpawnOffset: -10,2 @@ -230,6 +235,7 @@ HAND: RevealsShroud: Range: 5 Bib: + Sprite: bib3 RallyPoint: Exit@1: SpawnOffset: 12,24 @@ -266,6 +272,7 @@ AFLD: RevealsShroud: Range: 7 Bib: + Sprite: bib1 RallyPoint: RallyPoint: 4,2 BelowUnits: @@ -305,6 +312,7 @@ WEAP: RevealsShroud: Range: 4 Bib: + Sprite: bib2 -RenderBuilding: RenderBuildingWarFactory: RallyPoint: @@ -381,6 +389,7 @@ HQ: RevealsShroud: Range: 10 Bib: + Sprite: bib3 ProvidesRadar: RenderDetectionCircle: DetectCloaked: @@ -445,6 +454,7 @@ EYE: RevealsShroud: Range: 10 Bib: + Sprite: bib3 ProvidesRadar: RenderDetectionCircle: DetectCloaked: @@ -485,6 +495,7 @@ TMPL: RevealsShroud: Range: 6 Bib: + Sprite: bib2 NukePower: Image: atomicnh ChargeTime: 300 diff --git a/mods/cnc/rules/system.yaml b/mods/cnc/rules/system.yaml index 73b3d5e5ec..18506ba034 100644 --- a/mods/cnc/rules/system.yaml +++ b/mods/cnc/rules/system.yaml @@ -276,7 +276,6 @@ World: ProductionQueueFromSelection: ProductionTabsWidget: PRODUCTION_TABS BibLayer: - FrozenUnderFog: true DomainIndex: ResourceLayer: ResourceClaimLayer: diff --git a/mods/d2k/rules/defaults.yaml b/mods/d2k/rules/defaults.yaml index af1f33ef81..367d800a60 100644 --- a/mods/d2k/rules/defaults.yaml +++ b/mods/d2k/rules/defaults.yaml @@ -230,7 +230,6 @@ Sellable: GivesBounty: DebugMuzzlePositions: - Bib: Guardable: Range: 3 BodyOrientation: diff --git a/mods/d2k/rules/structures.yaml b/mods/d2k/rules/structures.yaml index 2f0dd202b2..cfdcb23cbd 100644 --- a/mods/d2k/rules/structures.yaml +++ b/mods/d2k/rules/structures.yaml @@ -5,6 +5,8 @@ Footprint: xxx xxx Dimensions: 3,2 Adjacent: 4 + Bib: + Sprite: bib3x Buildable: Queue: Building BuildPaletteOrder: 1000 @@ -51,6 +53,8 @@ Power: 100 Footprint: xx xx Dimensions: 2,2 + Bib: + Sprite: bib2x Health: HP: 400 Armor: @@ -78,6 +82,8 @@ Power: -20 Footprint: =x xx Dimensions: 2,2 + Bib: + Sprite: bib2x Health: HP: 800 Armor: @@ -119,6 +125,8 @@ Power: -30 Footprint: xxx x== Dimensions: 3,2 + Bib: + Sprite: bib3x Health: HP: 900 Armor: @@ -173,7 +181,6 @@ PipCount: 5 Capacity: 2000 -EmitInfantryOnSell: - -Bib: ^LIGHT: Inherits: ^Building @@ -193,6 +200,8 @@ Power: -20 Footprint: xxx xx= Dimensions: 3,2 + Bib: + Sprite: bib3x Health: HP: 750 Armor: @@ -230,6 +239,8 @@ Power: -30 Footprint: _x_ xxx =xx Dimensions: 3,3 + Bib: + Sprite: bib3x Health: HP: 1500 Armor: @@ -269,6 +280,8 @@ Power: -40 Footprint: xxx xxx Dimensions: 3,2 + Bib: + Sprite: bib3x Health: HP: 1000 Armor: @@ -298,6 +311,8 @@ Power: -40 Footprint: xxx x=x =x= Dimensions: 3,3 + Bib: + Sprite: bib3x Health: HP: 1000 Armor: @@ -420,7 +435,6 @@ GUNTOWER: RenderDetectionCircle: DetectCloaked: Range: 5 - -Bib: GUNTOWER.Husk: Inherits: ^TowerHusk @@ -479,7 +493,6 @@ ROCKETTOWER: RenderDetectionCircle: DetectCloaked: Range: 6 - -Bib: ROCKETTOWER.Husk: Inherits: ^TowerHusk @@ -520,7 +533,6 @@ REPAIR: ValuePercentage: 50 RallyPoint: RallyPoint: 1,3 - -Bib: ^HIGHTECH: Inherits: ^Building @@ -540,6 +552,8 @@ REPAIR: Power: -40 Footprint: _x_ xxx xxx Dimensions: 3,3 + Bib: + Sprite: bib3x Health: HP: 1500 Armor: @@ -580,6 +594,8 @@ RESEARCH: Power: -40 Footprint: xxx xxx Dimensions: 3,2 + Bib: + Sprite: bib3x Health: HP: 1000 Armor: @@ -607,6 +623,8 @@ RESEARCH: Power: -50 Footprint: _x_ xxx =xx Dimensions: 3,3 + Bib: + Sprite: bib3x Health: HP: 2000 Armor: @@ -628,6 +646,8 @@ SIETCH: Footprint: xx xx Dimensions: 2,2 TerrainTypes: Cliff + Bib: + Sprite: bib2x Health: HP: 400 Armor: @@ -652,6 +672,8 @@ PALACEC: Building: Footprint: xxx xxx Dimensions: 3,2 + Bib: + Sprite: bib3x RenderBuilding: HasMakeAnimation: false diff --git a/mods/d2k/rules/system.yaml b/mods/d2k/rules/system.yaml index 80c271f178..240dfc6826 100644 --- a/mods/d2k/rules/system.yaml +++ b/mods/d2k/rules/system.yaml @@ -355,9 +355,6 @@ World: Name: Ordos Race: ordos BibLayer: - BibTypes: bib3x, bib2x - BibWidths: 3, 2 - FrozenUnderFog: true DomainIndex: ResourceLayer: ResourceClaimLayer: diff --git a/mods/ra/maps/Fort-Lonestar/map.yaml b/mods/ra/maps/Fort-Lonestar/map.yaml index ae6717ca6c..a047367bd4 100644 --- a/mods/ra/maps/Fort-Lonestar/map.yaml +++ b/mods/ra/maps/Fort-Lonestar/map.yaml @@ -521,6 +521,7 @@ Rules: Armor: Type: Wood Bib: + Sprite: bib3 RevealsShroud: Range: 3 Capturable: diff --git a/mods/ra/rules/civilian.yaml b/mods/ra/rules/civilian.yaml index 9ab9f9dcfe..2b961ce769 100644 --- a/mods/ra/rules/civilian.yaml +++ b/mods/ra/rules/civilian.yaml @@ -69,6 +69,7 @@ FCOM: RevealsShroud: Range: 10 Bib: + Sprite: bib3 HOSP: Inherits: ^TechBuilding @@ -300,6 +301,7 @@ MISS: Tooltip: Name: Technology Center Bib: + Sprite: bib2 BIO: Inherits: ^TechBuilding @@ -319,6 +321,7 @@ OILB: Health: HP: 1000 Bib: + Sprite: bib3 RevealsShroud: Range: 3 Capturable: diff --git a/mods/ra/rules/structures.yaml b/mods/ra/rules/structures.yaml index 5bcd057356..b1e3476f22 100644 --- a/mods/ra/rules/structures.yaml +++ b/mods/ra/rules/structures.yaml @@ -372,6 +372,7 @@ DOME: RevealsShroud: Range: 10 Bib: + Sprite: bib3 ProvidesRadar: IronCurtainable: Infiltratable: @@ -844,6 +845,7 @@ ATEK: RevealsShroud: Range: 10 Bib: + Sprite: bib3 IronCurtainable: GpsPower: Image: gpssicon @@ -880,6 +882,7 @@ WEAP: RevealsShroud: Range: 4 Bib: + Sprite: bib2 -RenderBuilding: RenderBuildingWarFactory: RallyPoint: @@ -909,6 +912,7 @@ FACT: RevealsShroud: Range: 5 Bib: + Sprite: bib2 Production: Produces: Building,Defense IronCurtainable: @@ -952,6 +956,7 @@ PROC: RevealsShroud: Range: 6 Bib: + Sprite: bib2 OreRefinery: StoresOre: PipCount: 17 @@ -1027,6 +1032,7 @@ HPAD: RevealsShroud: Range: 5 Bib: + Sprite: bib3 Exit@1: SpawnOffset: 0,-6 ExitCell: 0,0 @@ -1114,6 +1120,7 @@ POWR: RevealsShroud: Range: 4 Bib: + Sprite: bib3 IronCurtainable: DeadBuildingState: @@ -1143,6 +1150,7 @@ APWR: RevealsShroud: Range: 4 Bib: + Sprite: bib2 IronCurtainable: DeadBuildingState: @@ -1172,6 +1180,7 @@ STEK: RevealsShroud: Range: 4 Bib: + Sprite: bib2 IronCurtainable: BARR: @@ -1198,6 +1207,7 @@ BARR: RevealsShroud: Range: 5 Bib: + Sprite: bib3 RallyPoint: Exit@1: SpawnOffset: -4,19 @@ -1235,6 +1245,7 @@ TENT: RevealsShroud: Range: 5 Bib: + Sprite: bib3 RallyPoint: Exit@1: SpawnOffset: -1,19 @@ -1317,6 +1328,7 @@ FACF: RevealsShroud: Range: 4 Bib: + Sprite: bib2 RenderBuilding: Image: FACT Fake: @@ -1346,6 +1358,7 @@ WEAF: RevealsShroud: Range: 4 Bib: + Sprite: bib2 -RenderBuilding: RenderBuildingWarFactory: Image: WEAP @@ -1438,6 +1451,7 @@ DOMF: RevealsShroud: Range: 4 Bib: + Sprite: bib3 RenderBuilding: Image: DOME Fake: diff --git a/mods/ra/rules/system.yaml b/mods/ra/rules/system.yaml index ab3d213a11..d93ff73c0b 100644 --- a/mods/ra/rules/system.yaml +++ b/mods/ra/rules/system.yaml @@ -611,7 +611,6 @@ World: Name: Soviet Race: soviet BibLayer: - FrozenUnderFog: true DomainIndex: ResourceLayer: ResourceClaimLayer: diff --git a/mods/ts/rules/structures.yaml b/mods/ts/rules/structures.yaml index c8a080b9a0..c446623d7e 100644 --- a/mods/ts/rules/structures.yaml +++ b/mods/ts/rules/structures.yaml @@ -14,7 +14,6 @@ GACNST: Type: Wood RevealsShroud: Range: 5 - Bib: Production: Produces: Building,Defense Valued: @@ -58,7 +57,6 @@ GAPOWR: Type: Wood RevealsShroud: Range: 4 - Bib: GAPILE: Inherits: ^Building @@ -84,7 +82,6 @@ GAPILE: Type: Wood RevealsShroud: Range: 5 - Bib: # RallyPoint: #TODO: setup sequences Exit@1: SpawnOffset: -64,64,0 @@ -117,7 +114,6 @@ GAWEAP: HP: 1000 RevealsShroud: Range: 4 - Bib: -RenderBuilding: RenderBuildingWarFactory: # RallyPoint: # TODO: setup sequences @@ -302,7 +298,6 @@ GASPOT: # TODO: has moving spotlights Type: Wood RevealsShroud: Range: 4 - Bib: RenderDetectionCircle: DetectCloaked: Range: 3 diff --git a/mods/ts/rules/system.yaml b/mods/ts/rules/system.yaml index 86b8ccedc2..9900500350 100644 --- a/mods/ts/rules/system.yaml +++ b/mods/ts/rules/system.yaml @@ -111,7 +111,6 @@ World: Race: nod ResourceLayer: ResourceClaimLayer: -# BibLayer: # TODO: file not found: bib3 DebugOverlay: SpawnMapActors: CreateMPPlayers: