Remove FootprintUtils

This commit is contained in:
reaperrr
2017-07-01 17:44:24 +02:00
committed by abcdefg30
parent 46dc827d46
commit fdb3866238
18 changed files with 35 additions and 83 deletions

View File

@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Cnc.Traits
public override void AddedToWorld(Actor self) public override void AddedToWorld(Actor self)
{ {
base.AddedToWorld(self); base.AddedToWorld(self);
blockedPositions = FootprintUtils.Tiles(self); blockedPositions = info.Tiles(self.Location);
} }
} }
} }

View File

@@ -41,7 +41,7 @@ namespace OpenRA.Mods.Cnc.Traits
var rows = HasMinibib ? 1 : 2; var rows = HasMinibib ? 1 : 2;
var width = bi.Dimensions.X; var width = bi.Dimensions.X;
var bibOffset = bi.Dimensions.Y - rows; 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 map = init.World.Map;
var location = CPos.Zero; var location = CPos.Zero;
@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Cnc.Traits
var rows = info.HasMinibib ? 1 : 2; var rows = info.HasMinibib ? 1 : 2;
var width = bi.Dimensions.X; var width = bi.Dimensions.X;
var bibOffset = bi.Dimensions.Y - rows; var bibOffset = bi.Dimensions.Y - rows;
var centerOffset = FootprintUtils.CenterOffset(self.World, bi); var centerOffset = bi.CenterOffset(self.World);
var location = self.Location; var location = self.Location;
var map = self.World.Map; var map = self.World.Map;

View File

@@ -50,8 +50,8 @@ namespace OpenRA.Mods.Common.Widgets
var buildingInfo = actor.TraitInfoOrDefault<BuildingInfo>(); var buildingInfo = actor.TraitInfoOrDefault<BuildingInfo>();
if (buildingInfo != null) if (buildingInfo != null)
{ {
locationOffset = -FootprintUtils.AdjustForBuildingSize(buildingInfo); locationOffset = -buildingInfo.LocationOffset();
previewOffset = FootprintUtils.CenterOffset(world, buildingInfo); previewOffset = buildingInfo.CenterOffset(world);
} }
var td = new TypeDictionary(); var td = new TypeDictionary();

View File

@@ -279,7 +279,6 @@
<Compile Include="Traits\Buildings\BuildingInfluence.cs" /> <Compile Include="Traits\Buildings\BuildingInfluence.cs" />
<Compile Include="Traits\Buildings\BuildingUtils.cs" /> <Compile Include="Traits\Buildings\BuildingUtils.cs" />
<Compile Include="Traits\Buildings\Exit.cs" /> <Compile Include="Traits\Buildings\Exit.cs" />
<Compile Include="Traits\Buildings\FootprintUtils.cs" />
<Compile Include="Traits\Buildings\FreeActor.cs" /> <Compile Include="Traits\Buildings\FreeActor.cs" />
<Compile Include="Traits\Buildings\Gate.cs" /> <Compile Include="Traits\Buildings\Gate.cs" />
<Compile Include="Traits\Buildings\LineBuild.cs" /> <Compile Include="Traits\Buildings\LineBuild.cs" />

View File

@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Orders
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{ {
var orderType = "PlaceBuilding"; var orderType = "PlaceBuilding";
var topLeft = cell - FootprintUtils.AdjustForBuildingSize(buildingInfo); var topLeft = cell - buildingInfo.LocationOffset();
var plugInfo = world.Map.Rules.Actors[building].TraitInfoOrDefault<PlugInfo>(); var plugInfo = world.Map.Rules.Actors[building].TraitInfoOrDefault<PlugInfo>();
if (plugInfo != null) if (plugInfo != null)
@@ -163,8 +163,8 @@ namespace OpenRA.Mods.Common.Orders
public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world) public IEnumerable<IRenderable> RenderAboveShroud(WorldRenderer wr, World world)
{ {
var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos); var xy = wr.Viewport.ViewToWorld(Viewport.LastMousePos);
var topLeft = xy - FootprintUtils.AdjustForBuildingSize(buildingInfo); var topLeft = xy - buildingInfo.LocationOffset();
var offset = world.Map.CenterOfCell(topLeft) + FootprintUtils.CenterOffset(world, buildingInfo); var offset = world.Map.CenterOfCell(topLeft) + buildingInfo.CenterOffset(world);
var rules = world.Map.Rules; var rules = world.Map.Rules;
var actorInfo = rules.Actors[building]; var actorInfo = rules.Actors[building];
@@ -211,7 +211,7 @@ namespace OpenRA.Mods.Common.Orders
td.Add(o); td.Add(o);
var init = new ActorPreviewInitializer(actor, wr, td); var init = new ActorPreviewInitializer(actor, wr, td);
preview = rules.Actors[building].TraitInfos<IRenderActorPreviewInfo>() preview = actor.TraitInfos<IRenderActorPreviewInfo>()
.SelectMany(rpi => rpi.RenderPreview(init)) .SelectMany(rpi => rpi.RenderPreview(init))
.ToArray(); .ToArray();

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Mods.Common.Traits
class Bridge : IRender, INotifyDamageStateChanged class Bridge : IRender, INotifyDamageStateChanged
{ {
readonly BuildingInfo building; readonly BuildingInfo buildingInfo;
readonly Bridge[] neighbours = new Bridge[2]; readonly Bridge[] neighbours = new Bridge[2];
readonly LegacyBridgeHut[] huts = new LegacyBridgeHut[2]; // Huts before this / first & after this / last readonly LegacyBridgeHut[] huts = new LegacyBridgeHut[2]; // Huts before this / first & after this / last
readonly Health health; readonly Health health;
@@ -99,7 +99,7 @@ namespace OpenRA.Mods.Common.Traits
this.info = info; this.info = info;
type = self.Info.Name; type = self.Info.Name;
isDangling = new Lazy<bool>(() => huts[0] == huts[1] && (neighbours[0] == null || neighbours[1] == null)); 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]; } 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) 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( return footprint.Select(c => (IRenderable)(new SpriteRenderable(
wr.Theater.TileSprite(new TerrainTile(template, c.Value)), wr.Theater.TileSprite(new TerrainTile(template, c.Value)),

View File

@@ -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);
}
}
}

View File

@@ -117,7 +117,7 @@ namespace OpenRA.Mods.Common.Traits
public override void AddedToWorld(Actor self) public override void AddedToWorld(Actor self)
{ {
base.AddedToWorld(self); base.AddedToWorld(self);
blockedPositions = FootprintUtils.Tiles(self); blockedPositions = Info.Tiles(self.Location);
} }
bool IsBlocked() bool IsBlocked()

View File

@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Common.Traits
bridgeLayer = self.World.WorldActor.Trait<BridgeLayer>(); bridgeLayer = self.World.WorldActor.Trait<BridgeLayer>();
var buildingInfo = self.Info.TraitInfo<BuildingInfo>(); 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) void UpdateTerrain(Actor self, byte terrainIndex)

View File

@@ -66,7 +66,9 @@ namespace OpenRA.Mods.Common.Traits
dudesValue = 0; 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(); 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)) while (eligibleLocations.Count > 0 && actorTypes.Any(a => a.Cost <= dudesValue))

View File

@@ -108,7 +108,7 @@ namespace OpenRA.Mods.Common.Traits
var buildingInfo = target.Info.TraitInfoOrDefault<BuildingInfo>(); var buildingInfo = target.Info.TraitInfoOrDefault<BuildingInfo>();
if (buildingInfo != null) 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))) if (footprint.All(c => self.World.ShroudObscures(c)))
return false; return false;
} }

View File

@@ -93,7 +93,7 @@ namespace OpenRA.Mods.Common.Traits
if (Info.Type == ExplosionType.Footprint && buildingInfo != null) 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) foreach (var c in cells)
weapon.Impact(Target.FromPos(self.World.Map.CenterOfCell(c)), e.Attacker, Enumerable.Empty<int>()); weapon.Impact(Target.FromPos(self.World.Map.CenterOfCell(c)), e.Attacker, Enumerable.Empty<int>());

View File

@@ -63,7 +63,8 @@ namespace OpenRA.Mods.Common.Traits
var shroudInfo = init.World.Map.Rules.Actors["player"].TraitInfo<ShroudInfo>(); var shroudInfo = init.World.Map.Rules.Actors["player"].TraitInfo<ShroudInfo>();
var exploredMap = init.World.LobbyInfo.GlobalSettings.OptionOrDefault("explored", shroudInfo.ExploredMapEnabled); var exploredMap = init.World.LobbyInfo.GlobalSettings.OptionOrDefault("explored", shroudInfo.ExploredMapEnabled);
startsRevealed = exploredMap && init.Contains<SpawnedByMapInit>() && !init.Contains<HiddenUnderFogInit>(); 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(); footprint = footprintCells.SelectMany(c => map.ProjectedCellsCovering(c.ToMPos(map))).ToArray();
} }

View File

@@ -47,28 +47,28 @@ namespace OpenRA.Mods.Common.Traits.Render
class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, IWallConnector, ITick class WithGateSpriteBody : WithSpriteBody, INotifyRemovedFromWorld, IWallConnector, ITick
{ {
readonly WithGateSpriteBodyInfo gateInfo; readonly WithGateSpriteBodyInfo gateBodyInfo;
readonly Gate gate; readonly Gate gate;
bool renderOpen; bool renderOpen;
public WithGateSpriteBody(ActorInitializer init, WithGateSpriteBodyInfo info) public WithGateSpriteBody(ActorInitializer init, WithGateSpriteBodyInfo info)
: base(init, info, () => 0) : base(init, info, () => 0)
{ {
gateInfo = info; gateBodyInfo = info;
gate = init.Self.Trait<Gate>(); gate = init.Self.Trait<Gate>();
} }
void UpdateState(Actor self) void UpdateState(Actor self)
{ {
if (renderOpen) if (renderOpen)
DefaultAnimation.PlayRepeating(NormalizeSequence(self, gateInfo.OpenSequence)); DefaultAnimation.PlayRepeating(NormalizeSequence(self, gateBodyInfo.OpenSequence));
else else
DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame); DefaultAnimation.PlayFetchIndex(NormalizeSequence(self, Info.Sequence), GetGateFrame);
} }
void ITick.Tick(Actor self) void ITick.Tick(Actor self)
{ {
if (gateInfo.OpenSequence == null) if (gateBodyInfo.OpenSequence == null)
return; return;
if (gate.Position == gate.OpenPosition ^ renderOpen) if (gate.Position == gate.OpenPosition ^ renderOpen)
@@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits.Render
void UpdateNeighbours(Actor self) 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) var adjacent = Util.ExpandFootprint(footprint, true).Except(footprint)
.Where(self.World.Map.Contains).ToList(); .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) bool IWallConnector.AdjacentWallCanConnect(Actor self, CPos wallLocation, string wallType, out CVec facing)
{ {
facing = wallLocation - self.Location; facing = wallLocation - self.Location;
return wallType == gateInfo.Type && gateInfo.WallConnections.Contains(facing); return wallType == gateBodyInfo.Type && gateBodyInfo.WallConnections.Contains(facing);
} }
void IWallConnector.SetDirty() { } void IWallConnector.SetDirty() { }

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits.Render
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0); anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);
var bi = init.Actor.TraitInfo<BuildingInfo>(); 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); 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 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)); renderSprites.Add(new AnimationWithOffset(door, null, () => !buildComplete, offset));
} }

View File

@@ -44,14 +44,14 @@ namespace OpenRA.Mods.Common.Traits
public void Add(Actor b) public void Add(Actor b)
{ {
var buildingInfo = b.Info.TraitInfo<BuildingInfo>(); 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; bridges[c] = b;
} }
public void Remove(Actor b) public void Remove(Actor b)
{ {
var buildingInfo = b.Info.TraitInfo<BuildingInfo>(); 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) if (bridges[c] == b)
bridges[c] = null; bridges[c] = null;
} }

View File

@@ -149,7 +149,7 @@ namespace OpenRA.Mods.Common.Traits
var buildingInfo = Info.TraitInfoOrDefault<BuildingInfo>(); var buildingInfo = Info.TraitInfoOrDefault<BuildingInfo>();
if (buildingInfo != null) if (buildingInfo != null)
offset = FootprintUtils.CenterOffset(world, buildingInfo); offset = buildingInfo.CenterOffset(world);
return world.Map.CenterOfSubCell(cell, subCell) + offset; return world.Map.CenterOfSubCell(cell, subCell) + offset;
} }

View File

@@ -38,6 +38,7 @@ namespace OpenRA.Mods.D2k.Traits
readonly BuildableTerrainLayer layer; readonly BuildableTerrainLayer layer;
readonly BuildingInfluence bi; readonly BuildingInfluence bi;
readonly TerrainTemplateInfo template; readonly TerrainTemplateInfo template;
readonly BuildingInfo buildingInfo;
public LaysTerrain(Actor self, LaysTerrainInfo info) public LaysTerrain(Actor self, LaysTerrainInfo info)
{ {
@@ -45,6 +46,7 @@ namespace OpenRA.Mods.D2k.Traits
layer = self.World.WorldActor.Trait<BuildableTerrainLayer>(); layer = self.World.WorldActor.Trait<BuildableTerrainLayer>();
bi = self.World.WorldActor.Trait<BuildingInfluence>(); bi = self.World.WorldActor.Trait<BuildingInfluence>();
template = self.World.Map.Rules.TileSet.Templates[info.Template]; template = self.World.Map.Rules.TileSet.Templates[info.Template];
buildingInfo = self.Info.TraitInfo<BuildingInfo>();
} }
public void AddedToWorld(Actor self) public void AddedToWorld(Actor self)
@@ -54,7 +56,7 @@ namespace OpenRA.Mods.D2k.Traits
if (template.PickAny) if (template.PickAny)
{ {
// Fill the footprint with random variants // 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 // Only place on allowed terrain types
if (!map.Contains(c) || !info.TerrainTypes.Contains(map.GetTerrainInfo(c).Type)) if (!map.Contains(c) || !info.TerrainTypes.Contains(map.GetTerrainInfo(c).Type))