Fix ICustomTerrain to also work for resources
This commit is contained in:
@@ -20,14 +20,18 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class BridgeLoadHookInfo : TraitInfo<BridgeLoadHook> { }
|
||||
class BridgeLayerInfo : TraitInfo<BridgeLayer> { }
|
||||
|
||||
class BridgeLoadHook : ILoadWorldHook
|
||||
class BridgeLayer : ILoadWorldHook, ICustomTerrain
|
||||
{
|
||||
static void MakeBridges(World w)
|
||||
// for tricky things like bridges.
|
||||
Bridge[,] customTerrain;
|
||||
|
||||
void MakeBridges(World w)
|
||||
{
|
||||
var tl = w.Map.TopLeft;
|
||||
var br = w.Map.BottomRight;
|
||||
@@ -38,10 +42,10 @@ namespace OpenRA.Traits
|
||||
ConvertBridgeToActor(w, i, j);
|
||||
|
||||
foreach (var b in w.Actors.SelectMany(a => a.traits.WithInterface<Bridge>()))
|
||||
b.FinalizeBridges(w);
|
||||
b.FinalizeBridges(w, customTerrain);
|
||||
}
|
||||
|
||||
static void ConvertBridgeToActor(World w, int i, int j)
|
||||
void ConvertBridgeToActor(World w, int i, int j)
|
||||
{
|
||||
Log.Write("Converting bridge at {0} {1}",i,j);
|
||||
|
||||
@@ -77,15 +81,30 @@ namespace OpenRA.Traits
|
||||
{
|
||||
var a = w.CreateActor(template.Bridge, new int2(ni, nj), w.NeutralPlayer);
|
||||
var br = a.traits.Get<Bridge>();
|
||||
|
||||
foreach (var t in replacedTiles.Keys)
|
||||
customTerrain[t.X, t.Y] = br;
|
||||
|
||||
br.SetTiles(w, template, replacedTiles);
|
||||
}
|
||||
}
|
||||
|
||||
public float GetCost(int2 p, UnitMovementType umt)
|
||||
{
|
||||
if (customTerrain[p.X, p.Y] != null)
|
||||
return customTerrain[p.X,p.Y].GetCost(p,umt);
|
||||
return 1f;
|
||||
}
|
||||
|
||||
static bool IsBridge(World w, ushort t)
|
||||
{
|
||||
return w.TileSet.walk[t].Bridge != null;
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w) { MakeBridges(w); }
|
||||
public void WorldLoaded(World w)
|
||||
{
|
||||
customTerrain = new Bridge[w.Map.MapSize.X, w.Map.MapSize.Y];
|
||||
MakeBridges(w);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ namespace OpenRA.Traits
|
||||
public object Create(Actor self) { return new ResourceLayer(self); }
|
||||
}
|
||||
|
||||
public class ResourceLayer: IRenderOverlay, ILoadWorldHook
|
||||
public class ResourceLayer: IRenderOverlay, ILoadWorldHook, ICustomTerrain
|
||||
{
|
||||
SpriteRenderer sr;
|
||||
World world;
|
||||
@@ -88,18 +88,18 @@ namespace OpenRA.Traits
|
||||
content[x, y].density = GetIdealDensity(x, y);
|
||||
}
|
||||
|
||||
public float GetMovementCost(UnitMovementType umt, int2 p)
|
||||
public float GetSpeedMultiplier(UnitMovementType umt, int2 p)
|
||||
{
|
||||
if (content[p.X,p.Y].type == null)
|
||||
return 1.0f;
|
||||
return content[p.X,p.Y].type.GetMovementCost(umt);
|
||||
return content[p.X,p.Y].type.GetSpeedMultiplier(umt);
|
||||
}
|
||||
|
||||
public float GetPathCost(UnitMovementType umt, int2 p)
|
||||
public float GetCost(int2 p,UnitMovementType umt)
|
||||
{
|
||||
if (content[p.X,p.Y].type == null)
|
||||
return 1.0f;
|
||||
return content[p.X,p.Y].type.GetPathCost(umt);
|
||||
return content[p.X,p.Y].type.GetCost(umt);
|
||||
}
|
||||
|
||||
public Sprite[] ChooseContent(ResourceType t)
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace OpenRA.Traits
|
||||
int growthTicks;
|
||||
int spreadTicks;
|
||||
public ResourceTypeInfo info;
|
||||
float[] movementCost = new float[4];
|
||||
float[] movementSpeed = new float[4];
|
||||
float[] pathCost = new float[4];
|
||||
|
||||
public ResourceType(ResourceTypeInfo info)
|
||||
@@ -56,19 +56,20 @@ namespace OpenRA.Traits
|
||||
for (var umt = UnitMovementType.Foot; umt <= UnitMovementType.Float; umt++ )
|
||||
{
|
||||
// HACK: hardcode "ore" terraintype for now
|
||||
movementCost[(int)umt] = (info.MovementTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetCost(umt) : 1.0f;
|
||||
pathCost[(int)umt] = (info.PathingTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetCost(umt) : movementCost[(int)umt];
|
||||
movementSpeed[(int)umt] = (info.MovementTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetSpeedMultiplier(umt) : 1.0f;
|
||||
pathCost[(int)umt] = (info.PathingTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetCost(umt)
|
||||
: (info.MovementTerrainType != null) ? (float)Rules.TerrainTypes[TerrainType.Ore].GetCost(umt) : 1.0f;
|
||||
}
|
||||
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public float GetMovementCost(UnitMovementType umt)
|
||||
public float GetSpeedMultiplier(UnitMovementType umt)
|
||||
{
|
||||
return movementCost[(int)umt];
|
||||
return movementSpeed[(int)umt];
|
||||
}
|
||||
|
||||
public float GetPathCost(UnitMovementType umt)
|
||||
public float GetCost(UnitMovementType umt)
|
||||
{
|
||||
return pathCost[(int)umt];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user