Remove FootprintUtils
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
var buildingInfo = actor.TraitInfoOrDefault<BuildingInfo>();
|
||||
if (buildingInfo != null)
|
||||
{
|
||||
locationOffset = -FootprintUtils.AdjustForBuildingSize(buildingInfo);
|
||||
previewOffset = FootprintUtils.CenterOffset(world, buildingInfo);
|
||||
locationOffset = -buildingInfo.LocationOffset();
|
||||
previewOffset = buildingInfo.CenterOffset(world);
|
||||
}
|
||||
|
||||
var td = new TypeDictionary();
|
||||
|
||||
@@ -279,7 +279,6 @@
|
||||
<Compile Include="Traits\Buildings\BuildingInfluence.cs" />
|
||||
<Compile Include="Traits\Buildings\BuildingUtils.cs" />
|
||||
<Compile Include="Traits\Buildings\Exit.cs" />
|
||||
<Compile Include="Traits\Buildings\FootprintUtils.cs" />
|
||||
<Compile Include="Traits\Buildings\FreeActor.cs" />
|
||||
<Compile Include="Traits\Buildings\Gate.cs" />
|
||||
<Compile Include="Traits\Buildings\LineBuild.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<PlugInfo>();
|
||||
if (plugInfo != null)
|
||||
@@ -163,8 +163,8 @@ namespace OpenRA.Mods.Common.Orders
|
||||
public IEnumerable<IRenderable> 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<IRenderActorPreviewInfo>()
|
||||
preview = actor.TraitInfos<IRenderActorPreviewInfo>()
|
||||
.SelectMany(rpi => rpi.RenderPreview(init))
|
||||
.ToArray();
|
||||
|
||||
|
||||
@@ -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<bool>(() => huts[0] == huts[1] && (neighbours[0] == null || neighbours[1] == null));
|
||||
building = self.Info.TraitInfo<BuildingInfo>();
|
||||
buildingInfo = self.Info.TraitInfo<BuildingInfo>();
|
||||
}
|
||||
|
||||
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)),
|
||||
|
||||
@@ -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<CPos> Tiles(Actor a)
|
||||
{
|
||||
var info = a.Info.TraitInfo<BuildingInfo>();
|
||||
return info.Tiles(a.Location);
|
||||
}
|
||||
|
||||
public static IEnumerable<CPos> FrozenUnderFogTiles(Actor a)
|
||||
{
|
||||
var info = a.Info.TraitInfo<BuildingInfo>();
|
||||
return info.FrozenUnderFogTiles(a);
|
||||
}
|
||||
|
||||
public static IEnumerable<CPos> UnpathableTiles(string name, BuildingInfo buildingInfo, CPos position)
|
||||
{
|
||||
return buildingInfo.UnpathableTiles(position);
|
||||
}
|
||||
|
||||
public static IEnumerable<CPos> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
bridgeLayer = self.World.WorldActor.Trait<BridgeLayer>();
|
||||
var buildingInfo = self.Info.TraitInfo<BuildingInfo>();
|
||||
cells = FootprintUtils.PathableTiles(self.Info.Name, buildingInfo, self.Location);
|
||||
cells = buildingInfo.PathableTiles(self.Location);
|
||||
}
|
||||
|
||||
void UpdateTerrain(Actor self, byte terrainIndex)
|
||||
|
||||
@@ -66,7 +66,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
dudesValue = 0;
|
||||
}
|
||||
|
||||
var eligibleLocations = FootprintUtils.Tiles(self).ToList();
|
||||
var buildingInfo = self.Info.TraitInfoOrDefault<BuildingInfo>();
|
||||
|
||||
var eligibleLocations = buildingInfo != null ? buildingInfo.Tiles(self.Location).ToList() : new List<CPos>();
|
||||
var actorTypes = info.ActorTypes.Select(a => new { Name = a, Cost = self.World.Map.Rules.Actors[a].TraitInfo<ValuedInfo>().Cost }).ToList();
|
||||
|
||||
while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue))
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var buildingInfo = target.Info.TraitInfoOrDefault<BuildingInfo>();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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<int>());
|
||||
|
||||
|
||||
@@ -63,7 +63,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var shroudInfo = init.World.Map.Rules.Actors["player"].TraitInfo<ShroudInfo>();
|
||||
var exploredMap = init.World.LobbyInfo.GlobalSettings.OptionOrDefault("explored", shroudInfo.ExploredMapEnabled);
|
||||
startsRevealed = exploredMap && init.Contains<SpawnedByMapInit>() && !init.Contains<HiddenUnderFogInit>();
|
||||
var footprintCells = FootprintUtils.FrozenUnderFogTiles(init.Self).ToList();
|
||||
var buildingInfo = init.Self.Info.TraitInfoOrDefault<BuildingInfo>();
|
||||
var footprintCells = buildingInfo != null ? buildingInfo.FrozenUnderFogTiles(init.Self.Location).ToList() : new List<CPos>() { init.Self.Location };
|
||||
footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Gate>();
|
||||
}
|
||||
|
||||
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() { }
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits.Render
|
||||
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);
|
||||
|
||||
var bi = init.Actor.TraitInfo<BuildingInfo>();
|
||||
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<BuildingInfo>();
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -44,14 +44,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public void Add(Actor b)
|
||||
{
|
||||
var buildingInfo = b.Info.TraitInfo<BuildingInfo>();
|
||||
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<BuildingInfo>();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
var buildingInfo = Info.TraitInfoOrDefault<BuildingInfo>();
|
||||
if (buildingInfo != null)
|
||||
offset = FootprintUtils.CenterOffset(world, buildingInfo);
|
||||
offset = buildingInfo.CenterOffset(world);
|
||||
|
||||
return world.Map.CenterOfSubCell(cell, subCell) + offset;
|
||||
}
|
||||
|
||||
@@ -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<BuildableTerrainLayer>();
|
||||
bi = self.World.WorldActor.Trait<BuildingInfluence>();
|
||||
template = self.World.Map.Rules.TileSet.Templates[info.Template];
|
||||
buildingInfo = self.Info.TraitInfo<BuildingInfo>();
|
||||
}
|
||||
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user