diff --git a/OpenRA.Mods.Cnc/Traits/EnergyWall.cs b/OpenRA.Mods.Cnc/Traits/EnergyWall.cs index 067c0fd88b..b9e86c3ad7 100644 --- a/OpenRA.Mods.Cnc/Traits/EnergyWall.cs +++ b/OpenRA.Mods.Cnc/Traits/EnergyWall.cs @@ -106,7 +106,7 @@ namespace OpenRA.Mods.Cnc.Traits public override void AddedToWorld(Actor self) { base.AddedToWorld(self); - blockedPositions = FootprintUtils.Tiles(self); + blockedPositions = info.Tiles(self.Location); } } } diff --git a/OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs b/OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs index 6d3f15c179..616a738446 100644 --- a/OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs +++ b/OpenRA.Mods.Cnc/Traits/Render/WithBuildingBib.cs @@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc.Traits var rows = HasMinibib ? 1 : 2; var width = bi.Dimensions.X; var bibOffset = bi.Dimensions.Y - rows; - var centerOffset = FootprintUtils.CenterOffset(init.World, bi); + var centerOffset = bi.CenterOffset(init.World); var map = init.World.Map; var location = CPos.Zero; @@ -93,7 +93,7 @@ namespace OpenRA.Mods.Cnc.Traits var rows = info.HasMinibib ? 1 : 2; var width = bi.Dimensions.X; var bibOffset = bi.Dimensions.Y - rows; - var centerOffset = FootprintUtils.CenterOffset(self.World, bi); + var centerOffset = bi.CenterOffset(self.World); var location = self.Location; var map = self.World.Map; diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorActorBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorActorBrush.cs index d31513b7ad..82d9230989 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorActorBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorActorBrush.cs @@ -50,8 +50,8 @@ namespace OpenRA.Mods.Common.Widgets var buildingInfo = actor.TraitInfoOrDefault(); if (buildingInfo != null) { - locationOffset = -FootprintUtils.AdjustForBuildingSize(buildingInfo); - previewOffset = FootprintUtils.CenterOffset(world, buildingInfo); + locationOffset = -buildingInfo.LocationOffset(); + previewOffset = buildingInfo.CenterOffset(world); } var td = new TypeDictionary(); diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 19dc3391c4..30abca38f1 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -279,7 +279,6 @@ - diff --git a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs index 23a273457a..3d298216ac 100644 --- a/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/PlaceBuildingOrderGenerator.cs @@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Orders if (mi.Button == MouseButton.Left) { var orderType = "PlaceBuilding"; - var topLeft = cell - FootprintUtils.AdjustForBuildingSize(buildingInfo); + var topLeft = cell - buildingInfo.LocationOffset(); var plugInfo = world.Map.Rules.Actors[building].TraitInfoOrDefault(); if (plugInfo != null) @@ -163,8 +163,8 @@ namespace OpenRA.Mods.Common.Orders public IEnumerable RenderAboveShroud(WorldRenderer wr, World world) { var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); - var topLeft = xy - FootprintUtils.AdjustForBuildingSize(buildingInfo); - var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, buildingInfo); + var topLeft = xy - buildingInfo.LocationOffset(); + var offset = world.Map.CenterOfCell(topLeft) + buildingInfo.CenterOffset(world); var rules = world.Map.Rules; var actorInfo = rules.Actors[building]; @@ -211,7 +211,7 @@ namespace OpenRA.Mods.Common.Orders td.Add(o); var init = new ActorPreviewInitializer(actor, wr, td); - preview = rules.Actors[building].TraitInfos() + preview = actor.TraitInfos() .SelectMany(rpi => rpi.RenderPreview(init)) .ToArray(); diff --git a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs index 7c1844b5a6..e534ab456e 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Bridge.cs @@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Traits class Bridge : IRender, INotifyDamageStateChanged { - readonly BuildingInfo building; + readonly BuildingInfo buildingInfo; readonly Bridge[] neighbours = new Bridge[2]; readonly LegacyBridgeHut[] huts = new LegacyBridgeHut[2]; // Huts before this / first & after this / last readonly Health health; @@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Traits this.info = info; type = self.Info.Name; isDangling = new Lazy(() => huts[0] == huts[1] && (neighbours[0] == null || neighbours[1] == null)); - building = self.Info.TraitInfo(); + buildingInfo = self.Info.TraitInfo(); } public Bridge Neighbour(int direction) { return neighbours[direction]; } @@ -181,7 +181,7 @@ namespace OpenRA.Mods.Common.Traits IRenderable[] TemplateRenderables(WorldRenderer wr, PaletteReference palette, ushort template) { - var offset = FootprintUtils.CenterOffset(self.World, building).Y + 1024; + var offset = buildingInfo.CenterOffset(self.World).Y + 1024; return footprint.Select(c => (IRenderable)(new SpriteRenderable( wr.Theater.TileSprite(new TerrainTile(template, c.Value)), diff --git a/OpenRA.Mods.Common/Traits/Buildings/FootprintUtils.cs b/OpenRA.Mods.Common/Traits/Buildings/FootprintUtils.cs deleted file mode 100644 index fdd3eb8f60..0000000000 --- a/OpenRA.Mods.Common/Traits/Buildings/FootprintUtils.cs +++ /dev/null @@ -1,52 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2017 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, either version 3 of - * the License, or (at your option) any later version. For more - * information, see COPYING. - */ -#endregion - -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenRA.Mods.Common.Traits -{ - public static class FootprintUtils - { - public static IEnumerable Tiles(Actor a) - { - var info = a.Info.TraitInfo(); - return info.Tiles(a.Location); - } - - public static IEnumerable FrozenUnderFogTiles(Actor a) - { - var info = a.Info.TraitInfo(); - return info.FrozenUnderFogTiles(a); - } - - public static IEnumerable UnpathableTiles(string name, BuildingInfo buildingInfo, CPos position) - { - return buildingInfo.UnpathableTiles(position); - } - - public static IEnumerable PathableTiles(string name, BuildingInfo buildingInfo, CPos position) - { - return buildingInfo.PathableTiles(position); - } - - public static CVec AdjustForBuildingSize(BuildingInfo buildingInfo) - { - return buildingInfo.AdjustForBuildingSize(); - } - - public static WVec CenterOffset(World w, BuildingInfo buildingInfo) - { - return buildingInfo.CenterOffset(w); - } - } -} diff --git a/OpenRA.Mods.Common/Traits/Buildings/Gate.cs b/OpenRA.Mods.Common/Traits/Buildings/Gate.cs index 76691d667f..8d88203e10 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Gate.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Gate.cs @@ -117,7 +117,7 @@ namespace OpenRA.Mods.Common.Traits public override void AddedToWorld(Actor self) { base.AddedToWorld(self); - blockedPositions = FootprintUtils.Tiles(self); + blockedPositions = Info.Tiles(self.Location); } bool IsBlocked() diff --git a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs index 28b878c8b6..b91643b381 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/GroundLevelBridge.cs @@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits bridgeLayer = self.World.WorldActor.Trait(); var buildingInfo = self.Info.TraitInfo(); - cells = FootprintUtils.PathableTiles(self.Info.Name, buildingInfo, self.Location); + cells = buildingInfo.PathableTiles(self.Location); } void UpdateTerrain(Actor self, byte terrainIndex) diff --git a/OpenRA.Mods.Common/Traits/EmitInfantryOnSell.cs b/OpenRA.Mods.Common/Traits/EmitInfantryOnSell.cs index ad20558b06..65ec04e343 100644 --- a/OpenRA.Mods.Common/Traits/EmitInfantryOnSell.cs +++ b/OpenRA.Mods.Common/Traits/EmitInfantryOnSell.cs @@ -66,7 +66,9 @@ namespace OpenRA.Mods.Common.Traits dudesValue = 0; } - var eligibleLocations = FootprintUtils.Tiles(self).ToList(); + var buildingInfo = self.Info.TraitInfoOrDefault(); + + var eligibleLocations = buildingInfo != null ? buildingInfo.Tiles(self.Location).ToList() : new List(); var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].TraitInfo().Cost }).ToList(); while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue)) diff --git a/OpenRA.Mods.Common/Traits/EntersTunnels.cs b/OpenRA.Mods.Common/Traits/EntersTunnels.cs index 995d489397..637761196f 100644 --- a/OpenRA.Mods.Common/Traits/EntersTunnels.cs +++ b/OpenRA.Mods.Common/Traits/EntersTunnels.cs @@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits var buildingInfo = target.Info.TraitInfoOrDefault(); if (buildingInfo != null) { - var footprint = FootprintUtils.PathableTiles(target.Info.Name, buildingInfo, target.Location); + var footprint = buildingInfo.PathableTiles(target.Location); if (footprint.All(c => self.World.ShroudObscures(c))) return false; } diff --git a/OpenRA.Mods.Common/Traits/Explodes.cs b/OpenRA.Mods.Common/Traits/Explodes.cs index 8196bd1d99..a8ab0695f0 100644 --- a/OpenRA.Mods.Common/Traits/Explodes.cs +++ b/OpenRA.Mods.Common/Traits/Explodes.cs @@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits if (Info.Type == ExplosionType.Footprint && buildingInfo != null) { - var cells = FootprintUtils.UnpathableTiles(self.Info.Name, buildingInfo, self.Location); + var cells = buildingInfo.UnpathableTiles(self.Location); foreach (var c in cells) weapon.Impact(Target.FromPos(self.World.Map.CenterOfCell(c)), e.Attacker, Enumerable.Empty()); diff --git a/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs b/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs index a4a58ab5c9..51fac36b15 100644 --- a/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs +++ b/OpenRA.Mods.Common/Traits/Modifiers/FrozenUnderFog.cs @@ -63,7 +63,8 @@ namespace OpenRA.Mods.Common.Traits var shroudInfo = init.World.Map.Rules.Actors["player"].TraitInfo(); var exploredMap = init.World.LobbyInfo.GlobalSettings.OptionOrDefault("explored", shroudInfo.ExploredMapEnabled); startsRevealed = exploredMap && init.Contains() && !init.Contains(); - var footprintCells = FootprintUtils.FrozenUnderFogTiles(init.Self).ToList(); + var buildingInfo = init.Self.Info.TraitInfoOrDefault(); + var footprintCells = buildingInfo != null ? buildingInfo.FrozenUnderFogTiles(init.Self.Location).ToList() : new List() { init.Self.Location }; footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray(); } diff --git a/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs b/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs index 9340ab3b5b..fcdc12a4ec 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithGateSpriteBody.cs @@ -47,28 +47,28 @@ namespace OpenRA.Mods.Common.Traits.Render class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, IWallConnector, ITick { - readonly WithGateSpriteBodyInfo gateInfo; + readonly WithGateSpriteBodyInfo gateBodyInfo; readonly Gate gate; bool renderOpen; public WithGateSpriteBody(ActorInitializer init, WithGateSpriteBodyInfo info) : base(init, info, () => 0) { - gateInfo = info; + gateBodyInfo = info; gate = init.Self.Trait(); } void UpdateState(Actor self) { if (renderOpen) - DefaultAnimation.PlayRepeating(NormalizeSequence(self, gateInfo.OpenSequence)); + DefaultAnimation.PlayRepeating(NormalizeSequence(self, gateBodyInfo.OpenSequence)); else DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame); } void ITick.Tick(Actor self) { - if (gateInfo.OpenSequence == null) + if (gateBodyInfo.OpenSequence == null) return; if (gate.Position == gate.OpenPosition ^ renderOpen) @@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits.Render void UpdateNeighbours(Actor self) { - var footprint = FootprintUtils.Tiles(self).ToArray(); + var footprint = gate.Info.Tiles(self.Location).ToArray(); var adjacent = Util.ExpandFootprint(footprint, true).Except(footprint) .Where(self.World.Map.Contains).ToList(); @@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Traits.Render bool IWallConnector.AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType, out CVec facing) { facing = wallLocation - self.Location; - return wallType == gateInfo.Type && gateInfo.WallConnections.Contains(facing); + return wallType == gateBodyInfo.Type && gateBodyInfo.WallConnections.Contains(facing); } void IWallConnector.SetDirty() { } diff --git a/OpenRA.Mods.Common/Traits/Render/WithProductionDoorOverlay.cs b/OpenRA.Mods.Common/Traits/Render/WithProductionDoorOverlay.cs index 181bbc595c..2e10833667 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithProductionDoorOverlay.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithProductionDoorOverlay.cs @@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits.Render anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0); var bi = init.Actor.TraitInfo(); - var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512; // Additional 512 units move from center -> top of cell + var offset = bi.CenterOffset(init.World).Y + 512; // Additional 512 units move from center -> top of cell yield return new SpriteActorPreview(anim, () => WVec.Zero, () => offset, p, rs.Scale); } } @@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits.Render var buildingInfo = self.Info.TraitInfo(); - var offset = FootprintUtils.CenterOffset(self.World, buildingInfo).Y + 512; + var offset = buildingInfo.CenterOffset(self.World).Y + 512; renderSprites.Add(new AnimationWithOffset(door, null, () => !buildComplete, offset)); } diff --git a/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs b/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs index 2acb9b7bab..f3e8afbdf3 100644 --- a/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs @@ -44,14 +44,14 @@ namespace OpenRA.Mods.Common.Traits public void Add(Actor b) { var buildingInfo = b.Info.TraitInfo(); - foreach (var c in FootprintUtils.PathableTiles(b.Info.Name, buildingInfo, b.Location)) + foreach (var c in buildingInfo.PathableTiles(b.Location)) bridges[c] = b; } public void Remove(Actor b) { var buildingInfo = b.Info.TraitInfo(); - foreach (var c in FootprintUtils.PathableTiles(b.Info.Name, buildingInfo, b.Location)) + foreach (var c in buildingInfo.PathableTiles(b.Location)) if (bridges[c] == b) bridges[c] = null; } diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs index 6fa48d51e5..acd876a3e2 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs @@ -149,7 +149,7 @@ namespace OpenRA.Mods.Common.Traits var buildingInfo = Info.TraitInfoOrDefault(); if (buildingInfo != null) - offset = FootprintUtils.CenterOffset(world, buildingInfo); + offset = buildingInfo.CenterOffset(world); return world.Map.CenterOfSubCell(cell, subCell) + offset; } diff --git a/OpenRA.Mods.D2k/Traits/Buildings/LaysTerrain.cs b/OpenRA.Mods.D2k/Traits/Buildings/LaysTerrain.cs index 8e071d0ac0..1c96240fd7 100644 --- a/OpenRA.Mods.D2k/Traits/Buildings/LaysTerrain.cs +++ b/OpenRA.Mods.D2k/Traits/Buildings/LaysTerrain.cs @@ -38,6 +38,7 @@ namespace OpenRA.Mods.D2k.Traits readonly BuildableTerrainLayer layer; readonly BuildingInfluence bi; readonly TerrainTemplateInfo template; + readonly BuildingInfo buildingInfo; public LaysTerrain(Actor self, LaysTerrainInfo info) { @@ -45,6 +46,7 @@ namespace OpenRA.Mods.D2k.Traits layer = self.World.WorldActor.Trait(); bi = self.World.WorldActor.Trait(); template = self.World.Map.Rules.TileSet.Templates[info.Template]; + buildingInfo = self.Info.TraitInfo(); } public void AddedToWorld(Actor self) @@ -54,7 +56,7 @@ namespace OpenRA.Mods.D2k.Traits if (template.PickAny) { // Fill the footprint with random variants - foreach (var c in FootprintUtils.Tiles(self)) + foreach (var c in buildingInfo.Tiles(self.Location)) { // Only place on allowed terrain types if (!map.Contains(c) || !info.TerrainTypes.Contains(map.GetTerrainInfo(c).Type))