Remove editor-specific resource rendering.
Mods must manually move their *ResourceRenderer definitions from World onto BaseWorld to restore resource rendering in the editor.
This commit is contained in:
@@ -16,20 +16,36 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public struct ResourceLayerContents
|
||||
{
|
||||
public static readonly ResourceLayerContents Empty = default(ResourceLayerContents);
|
||||
public ResourceType Type;
|
||||
public int Density;
|
||||
}
|
||||
|
||||
public interface IResourceLayerInfo : ITraitInfoInterface { }
|
||||
|
||||
[RequireExplicitImplementation]
|
||||
public interface IResourceLayer
|
||||
{
|
||||
event Action<CPos, ResourceType> CellChanged;
|
||||
ResourceLayerContents GetResource(CPos cell);
|
||||
|
||||
bool IsVisible(CPos cell);
|
||||
}
|
||||
|
||||
[Desc("Attach this to the world actor.", "Order of the layers defines the Z sorting.")]
|
||||
public class ResourceLayerInfo : TraitInfo, Requires<ResourceTypeInfo>, Requires<BuildingInfluenceInfo>
|
||||
public class ResourceLayerInfo : TraitInfo, IResourceLayerInfo, Requires<ResourceTypeInfo>, Requires<BuildingInfluenceInfo>
|
||||
{
|
||||
public override object Create(ActorInitializer init) { return new ResourceLayer(init.Self); }
|
||||
}
|
||||
|
||||
public class ResourceLayer : IWorldLoaded
|
||||
public class ResourceLayer : IResourceLayer, IWorldLoaded
|
||||
{
|
||||
static readonly CellContents EmptyCell = default(CellContents);
|
||||
|
||||
readonly World world;
|
||||
readonly BuildingInfluence buildingInfluence;
|
||||
|
||||
protected readonly CellLayer<CellContents> Content;
|
||||
protected readonly CellLayer<ResourceLayerContents> Content;
|
||||
|
||||
public bool IsResourceLayerEmpty { get { return resCells < 1; } }
|
||||
|
||||
@@ -42,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
world = self.World;
|
||||
buildingInfluence = self.Trait<BuildingInfluence>();
|
||||
|
||||
Content = new CellLayer<CellContents>(world.Map);
|
||||
Content = new CellLayer<ResourceLayerContents>(world.Map);
|
||||
}
|
||||
|
||||
int GetAdjacentCellsWith(ResourceType t, CPos cell)
|
||||
@@ -85,7 +101,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
// Adjacent includes the current cell, so is always >= 1
|
||||
var adjacent = GetAdjacentCellsWith(type, cell);
|
||||
var density = int2.Lerp(0, type.Info.MaxDensity, adjacent, 9);
|
||||
var temp = GetResource(cell);
|
||||
var temp = Content[cell];
|
||||
temp.Density = Math.Max(density, 1);
|
||||
|
||||
Content[cell] = temp;
|
||||
@@ -120,12 +136,12 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|| (currentResourceType == null && AllowResourceAt(newResourceType, cell));
|
||||
}
|
||||
|
||||
CellContents CreateResourceCell(ResourceType t, CPos cell)
|
||||
ResourceLayerContents CreateResourceCell(ResourceType t, CPos cell)
|
||||
{
|
||||
world.Map.CustomTerrain[cell] = world.Map.Rules.TileSet.GetTerrainIndex(t.Info.TerrainType);
|
||||
++resCells;
|
||||
|
||||
return new CellContents
|
||||
return new ResourceLayerContents
|
||||
{
|
||||
Type = t
|
||||
};
|
||||
@@ -161,7 +177,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
if (--c.Density < 0)
|
||||
{
|
||||
Content[cell] = EmptyCell;
|
||||
Content[cell] = ResourceLayerContents.Empty;
|
||||
world.Map.CustomTerrain[cell] = byte.MaxValue;
|
||||
--resCells;
|
||||
}
|
||||
@@ -184,30 +200,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
--resCells;
|
||||
|
||||
// Clear cell
|
||||
Content[cell] = EmptyCell;
|
||||
Content[cell] = ResourceLayerContents.Empty;
|
||||
world.Map.CustomTerrain[cell] = byte.MaxValue;
|
||||
|
||||
if (CellChanged != null)
|
||||
CellChanged(cell, c.Type);
|
||||
}
|
||||
|
||||
public CellContents GetResource(CPos cell) { return Content[cell]; }
|
||||
public ResourceType GetResourceType(CPos cell) { return Content[cell].Type; }
|
||||
|
||||
public int GetResourceDensity(CPos cell) { return Content[cell].Density; }
|
||||
public int GetMaxResourceDensity(CPos cell)
|
||||
{
|
||||
if (Content[cell].Type == null)
|
||||
return 0;
|
||||
|
||||
return Content[cell].Type.Info.MaxDensity;
|
||||
}
|
||||
|
||||
public struct CellContents
|
||||
{
|
||||
public static readonly CellContents Empty = default(CellContents);
|
||||
public ResourceType Type;
|
||||
public int Density;
|
||||
}
|
||||
ResourceLayerContents IResourceLayer.GetResource(CPos cell) { return Content[cell]; }
|
||||
bool IResourceLayer.IsVisible(CPos cell) { return !world.FogObscures(cell); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user