Remove bib-related hacks from Building and FootprintUtils

This commit is contained in:
reaperrr
2017-06-28 14:10:04 +02:00
parent 9b137afa6d
commit 3200f4fb0f
5 changed files with 20 additions and 24 deletions

View File

@@ -77,6 +77,7 @@
<Compile Include="Activities\VoxelHarvesterDockSequence.cs" /> <Compile Include="Activities\VoxelHarvesterDockSequence.cs" />
<Compile Include="SpriteLoaders\TmpTSLoader.cs" /> <Compile Include="SpriteLoaders\TmpTSLoader.cs" />
<Compile Include="Traits\Buildings\TiberianSunRefinery.cs" /> <Compile Include="Traits\Buildings\TiberianSunRefinery.cs" />
<Compile Include="Traits\Render\WithBuildingBib.cs" />
<Compile Include="Traits\Render\WithDockingOverlay.cs" /> <Compile Include="Traits\Render\WithDockingOverlay.cs" />
<Compile Include="Traits\Render\WithPermanentInjury.cs" /> <Compile Include="Traits\Render\WithPermanentInjury.cs" />
<Compile Include="Traits\Render\WithVoxelWalkerBody.cs" /> <Compile Include="Traits\Render\WithVoxelWalkerBody.cs" />

View File

@@ -12,18 +12,21 @@
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics; using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Mods.Common.Traits.Render; using OpenRA.Mods.Common.Traits.Render;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Cnc.Traits
{ {
public class BibInfo : ITraitInfo, Requires<BuildingInfo>, IRenderActorPreviewSpritesInfo, IActorPreviewInitInfo, Requires<RenderSpritesInfo> public class WithBuildingBibInfo : ITraitInfo, Requires<BuildingInfo>, IRenderActorPreviewSpritesInfo, IActorPreviewInitInfo, Requires<RenderSpritesInfo>
{ {
[SequenceReference] public readonly string Sequence = "bib"; [SequenceReference] public readonly string Sequence = "bib";
[PaletteReference] public readonly string Palette = TileSet.TerrainPaletteInternalName; [PaletteReference] public readonly string Palette = TileSet.TerrainPaletteInternalName;
public readonly bool HasMinibib = false; 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<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p) public IEnumerable<IActorPreview> 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<BuildingInfo>(); var bi = init.Actor.TraitInfo<BuildingInfo>();
var width = bi.Dimensions.X;
var bibOffset = bi.Dimensions.Y - 1;
var centerOffset = FootprintUtils.CenterOffset(init.World, bi);
var rows = HasMinibib ? 1 : 2; 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 map = init.World.Map;
var location = CPos.Zero; 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 RenderSprites rs;
readonly BuildingInfo bi; readonly BuildingInfo bi;
readonly List<AnimationWithOffset> anims = new List<AnimationWithOffset>(); readonly List<AnimationWithOffset> anims = new List<AnimationWithOffset>();
public Bib(Actor self, BibInfo info) public WithBuildingBib(Actor self, WithBuildingBibInfo info)
{ {
this.info = info; this.info = info;
rs = self.Trait<RenderSprites>(); rs = self.Trait<RenderSprites>();
@@ -87,11 +90,11 @@ namespace OpenRA.Mods.Common.Traits
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
{ {
var rows = info.HasMinibib ? 1 : 2;
var width = bi.Dimensions.X; 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 centerOffset = FootprintUtils.CenterOffset(self.World, bi);
var location = self.Location; var location = self.Location;
var rows = info.HasMinibib ? 1 : 2;
var map = self.World.Map; var map = self.World.Map;
for (var i = 0; i < rows * width; i++) for (var i = 0; i < rows * width; i++)

View File

@@ -277,7 +277,6 @@
<Compile Include="Traits\Buildable.cs" /> <Compile Include="Traits\Buildable.cs" />
<Compile Include="Traits\Buildings\BaseBuilding.cs" /> <Compile Include="Traits\Buildings\BaseBuilding.cs" />
<Compile Include="Traits\Buildings\BaseProvider.cs" /> <Compile Include="Traits\Buildings\BaseProvider.cs" />
<Compile Include="Traits\Buildings\Bib.cs" />
<Compile Include="Traits\Buildings\Bridge.cs" /> <Compile Include="Traits\Buildings\Bridge.cs" />
<Compile Include="Traits\Buildings\LegacyBridgeHut.cs" /> <Compile Include="Traits\Buildings\LegacyBridgeHut.cs" />
<Compile Include="Traits\Buildings\Building.cs" /> <Compile Include="Traits\Buildings\Building.cs" />

View File

@@ -36,6 +36,9 @@ namespace OpenRA.Mods.Common.Traits
public readonly CVec Dimensions = new CVec(1, 1); 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 RequiresBaseProvider = false;
public readonly bool AllowInvalidPlacement = false; public readonly bool AllowInvalidPlacement = false;
@@ -84,9 +87,6 @@ namespace OpenRA.Mods.Common.Traits
return false; return false;
var buildingMaxBounds = Dimensions; var buildingMaxBounds = Dimensions;
var bibInfo = world.Map.Rules.Actors[buildingName].TraitInfoOrDefault<BibInfo>();
if (bibInfo != null && !bibInfo.HasMinibib)
buildingMaxBounds += new CVec(0, 1);
var scanStart = world.Map.Clamp(topLeft - new CVec(Adjacent, Adjacent)); var scanStart = world.Map.Clamp(topLeft - new CVec(Adjacent, Adjacent));
var scanEnd = world.Map.Clamp(topLeft + buildingMaxBounds + new CVec(Adjacent, Adjacent)); var scanEnd = world.Map.Clamp(topLeft + buildingMaxBounds + new CVec(Adjacent, Adjacent));

View File

@@ -20,16 +20,8 @@ namespace OpenRA.Mods.Common.Traits
public static IEnumerable<CPos> Tiles(Ruleset rules, string name, BuildingInfo buildingInfo, CPos topLeft, bool includePassable = false) public static IEnumerable<CPos> Tiles(Ruleset rules, string name, BuildingInfo buildingInfo, CPos topLeft, bool includePassable = false)
{ {
var dim = buildingInfo.Dimensions; var dim = buildingInfo.Dimensions;
var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x)); var footprint = buildingInfo.Footprint.Where(x => !char.IsWhiteSpace(x));
var bibInfo = rules.Actors[name].TraitInfoOrDefault<BibInfo>();
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); 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) public static WVec CenterOffset(World w, BuildingInfo buildingInfo)
{ {
var dim = buildingInfo.Dimensions; 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; 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;
} }
} }
} }