diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj index cd5b6fd65c..fd0685b6a6 100644 --- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj +++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj @@ -77,6 +77,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/Buildings/Bib.cs b/OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs similarity index 87% rename from OpenRA.Mods.Common/Traits/Buildings/Bib.cs rename to OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs index 23a9d72804..6d3f15c179 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Bib.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs @@ -12,18 +12,21 @@ using System.Collections.Generic; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; +using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits.Render; using OpenRA.Traits; -namespace OpenRA.Mods.Common.Traits +namespace OpenRA.Mods.Cnc.Traits { - public class BibInfo : ITraitInfo, Requires, IRenderActorPreviewSpritesInfo, IActorPreviewInitInfo, Requires + public class WithBuildingBibInfo : ITraitInfo, Requires, IRenderActorPreviewSpritesInfo, IActorPreviewInitInfo, Requires { [SequenceReference] public readonly string Sequence = "bib"; + [PaletteReference] public readonly string Palette = TileSet.TerrainPaletteInternalName; + public readonly bool HasMinibib = false; - public object Create(ActorInitializer init) { return new Bib(init.Self, this); } + public object Create(ActorInitializer init) { return new WithBuildingBib(init.Self, this); } public IEnumerable RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) { @@ -35,10 +38,10 @@ namespace OpenRA.Mods.Common.Traits var bi = init.Actor.TraitInfo(); - var width = bi.Dimensions.X; - var bibOffset = bi.Dimensions.Y - 1; - var centerOffset = FootprintUtils.CenterOffset(init.World, bi); var rows = HasMinibib ? 1 : 2; + var width = bi.Dimensions.X; + var bibOffset = bi.Dimensions.Y - rows; + var centerOffset = FootprintUtils.CenterOffset(init.World, bi); var map = init.World.Map; var location = CPos.Zero; @@ -71,14 +74,14 @@ namespace OpenRA.Mods.Common.Traits } } - public class Bib : INotifyAddedToWorld, INotifyRemovedFromWorld + public class WithBuildingBib : INotifyAddedToWorld, INotifyRemovedFromWorld { - readonly BibInfo info; + readonly WithBuildingBibInfo info; readonly RenderSprites rs; readonly BuildingInfo bi; readonly List anims = new List(); - public Bib(Actor self, BibInfo info) + public WithBuildingBib(Actor self, WithBuildingBibInfo info) { this.info = info; rs = self.Trait(); @@ -87,11 +90,11 @@ namespace OpenRA.Mods.Common.Traits public void AddedToWorld(Actor self) { + var rows = info.HasMinibib ? 1 : 2; var width = bi.Dimensions.X; - var bibOffset = bi.Dimensions.Y - 1; + var bibOffset = bi.Dimensions.Y - rows; var centerOffset = FootprintUtils.CenterOffset(self.World, bi); var location = self.Location; - var rows = info.HasMinibib ? 1 : 2; var map = self.World.Map; for (var i = 0; i < rows * width; i++) diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 2ab7f4b10c..803ae9d383 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -277,7 +277,6 @@ - diff --git a/OpenRA.Mods.Common/Traits/Buildings/Building.cs b/OpenRA.Mods.Common/Traits/Buildings/Building.cs index dc2af54558..89b2bbc28a 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Building.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Building.cs @@ -36,6 +36,9 @@ namespace OpenRA.Mods.Common.Traits public readonly CVec Dimensions = new CVec(1, 1); + [Desc("Shift center of the actor by this offset.")] + public readonly WVec LocalCenterOffset = WVec.Zero; + public readonly bool RequiresBaseProvider = false; public readonly bool AllowInvalidPlacement = false; @@ -84,9 +87,6 @@ namespace OpenRA.Mods.Common.Traits return false; var buildingMaxBounds = Dimensions; - var bibInfo = world.Map.Rules.Actors[buildingName].TraitInfoOrDefault(); - if (bibInfo != null && !bibInfo.HasMinibib) - buildingMaxBounds += new CVec(0, 1); var scanStart = world.Map.Clamp(topLeft - new CVec(Adjacent, Adjacent)); var scanEnd = world.Map.Clamp(topLeft + buildingMaxBounds + new CVec(Adjacent, Adjacent)); diff --git a/OpenRA.Mods.Common/Traits/Buildings/FootprintUtils.cs b/OpenRA.Mods.Common/Traits/Buildings/FootprintUtils.cs index 8b0ba36d5f..a8c2237b1f 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/FootprintUtils.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/FootprintUtils.cs @@ -20,16 +20,8 @@ namespace OpenRA.Mods.Common.Traits public static IEnumerable Tiles(Ruleset rules, string name, BuildingInfo buildingInfo, CPos topLeft, bool includePassable = false) { var dim = buildingInfo.Dimensions; - var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x)); - var bibInfo = rules.Actors[name].TraitInfoOrDefault(); - if (bibInfo != null && !bibInfo.HasMinibib) - { - dim += new CVec(0, 1); - footprint = footprint.Concat(new char[dim.X]); - } - return TilesWhere(name, dim, footprint.ToArray(), a => includePassable || a != '_').Select(t => t + topLeft); } @@ -78,8 +70,9 @@ namespace OpenRA.Mods.Common.Traits public static WVec CenterOffset(World w, BuildingInfo buildingInfo) { var dim = buildingInfo.Dimensions; + var localOffset = buildingInfo.LocalCenterOffset; var off = (w.Map.CenterOfCell(new CPos(dim.X, dim.Y)) - w.Map.CenterOfCell(new CPos(1, 1))) / 2; - return off - new WVec(0, 0, off.Z); + return (off - new WVec(0, 0, off.Z)) + localOffset; } } }