Kill ITerrainTypeModifier for explicit updating of a custom layer in the map. Functionally equivalent, but MUCH faster.
This commit is contained in:
@@ -192,13 +192,8 @@ namespace OpenRA.Traits
|
||||
{
|
||||
if (!self.World.Map.IsInMap(cell.X,cell.Y))
|
||||
return float.PositiveInfinity;
|
||||
|
||||
// Custom terrain types don't stack: pick one
|
||||
var customTerrain = self.World.WorldActor.traits.WithInterface<ITerrainTypeModifier>()
|
||||
.Select( t => t.GetTerrainType(cell) )
|
||||
.FirstOrDefault( t => t != null );
|
||||
|
||||
var type = (customTerrain != null) ? customTerrain : self.World.GetTerrainType(cell);
|
||||
|
||||
var type = self.World.GetTerrainType(cell);
|
||||
var additionalCost = self.World.WorldActor.traits.WithInterface<ITerrainCost>()
|
||||
.Select( t => t.GetTerrainCost(cell, self) ).Sum();
|
||||
|
||||
@@ -210,13 +205,8 @@ namespace OpenRA.Traits
|
||||
var unitInfo = self.Info.Traits.GetOrDefault<UnitInfo>();
|
||||
if( unitInfo == null )
|
||||
return 0f;
|
||||
|
||||
// Custom terrain types don't stack: pick one
|
||||
var customTerrain = self.World.WorldActor.traits.WithInterface<ITerrainTypeModifier>()
|
||||
.Select( t => t.GetTerrainType(cell) )
|
||||
.FirstOrDefault( t => t != null );
|
||||
|
||||
var type = (customTerrain != null) ? customTerrain : self.World.GetTerrainType(cell);
|
||||
|
||||
var type = self.World.GetTerrainType(cell);
|
||||
|
||||
var modifier = self.traits
|
||||
.WithInterface<ISpeedModifier>()
|
||||
|
||||
@@ -48,7 +48,6 @@ namespace OpenRA.Traits
|
||||
public interface IAvoidHazard { string Type { get; } }
|
||||
public interface IStoreOre { int Capacity { get; }}
|
||||
|
||||
public interface ITerrainTypeModifier { string GetTerrainType(int2 cell); }
|
||||
public interface ITerrainCost { float GetTerrainCost(int2 cell, Actor forActor); }
|
||||
|
||||
public interface IDisable { bool Disabled { get; } }
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
public class ResourceLayerInfo : TraitInfo<ResourceLayer> { }
|
||||
|
||||
public class ResourceLayer: IRenderOverlay, ILoadWorldHook, ITerrainTypeModifier
|
||||
public class ResourceLayer: IRenderOverlay, ILoadWorldHook
|
||||
{
|
||||
World world;
|
||||
|
||||
@@ -75,15 +75,7 @@ namespace OpenRA.Traits
|
||||
if (content[x, y].type != null)
|
||||
content[x, y].density = GetIdealDensity(x, y);
|
||||
}
|
||||
|
||||
public string GetTerrainType(int2 cell)
|
||||
{
|
||||
if (content[cell.X,cell.Y].type == null)
|
||||
return null;
|
||||
|
||||
return content[cell.X,cell.Y].type.info.TerrainType;
|
||||
}
|
||||
|
||||
|
||||
Sprite[] ChooseContent(ResourceType t)
|
||||
{
|
||||
return t.info.Sprites[world.SharedRandom.Next(t.info.Sprites.Length)];
|
||||
@@ -120,6 +112,8 @@ namespace OpenRA.Traits
|
||||
content[i, j].density = Math.Min(
|
||||
content[i, j].image.Length - 1,
|
||||
content[i, j].density + n);
|
||||
|
||||
world.Map.CustomTerrain[i,j] = t.info.TerrainType;
|
||||
}
|
||||
|
||||
public bool IsFull(int i, int j) { return content[i, j].density == content[i, j].image.Length - 1; }
|
||||
@@ -133,6 +127,7 @@ namespace OpenRA.Traits
|
||||
{
|
||||
content[p.X, p.Y].type = null;
|
||||
content[p.X, p.Y].image = null;
|
||||
world.Map.CustomTerrain[p.X, p.Y] = null;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user