Fixes & Resources support
This commit is contained in:
@@ -88,16 +88,12 @@ namespace OpenRA.FileFormats
|
|||||||
public byte[] GetBytes(TileReference<ushort,byte> r)
|
public byte[] GetBytes(TileReference<ushort,byte> r)
|
||||||
{
|
{
|
||||||
Terrain tile;
|
Terrain tile;
|
||||||
Log.Write("Attempting to load tile {0} {1}",r.type,r.image);
|
|
||||||
try {
|
try {
|
||||||
if( tiles.TryGetValue( r.type, out tile ) )
|
if( tiles.TryGetValue( r.type, out tile ) )
|
||||||
return tile.TileBitmapBytes[ r.image ];
|
return tile.TileBitmapBytes[ r.image ];
|
||||||
}
|
}
|
||||||
catch (System.ArgumentOutOfRangeException)
|
catch (System.ArgumentOutOfRangeException) { }
|
||||||
{
|
|
||||||
tiles.TryGetValue( 0xfffe, out tile );
|
|
||||||
return tile.TileBitmapBytes[ 0 ];
|
|
||||||
}
|
|
||||||
byte[] missingTile = new byte[ 24 * 24 ];
|
byte[] missingTile = new byte[ 24 * 24 ];
|
||||||
for( int i = 0 ; i < missingTile.Length ; i++ )
|
for( int i = 0 ; i < missingTile.Length ; i++ )
|
||||||
missingTile[ i ] = 0x36;
|
missingTile[ i ] = 0x36;
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ namespace OpenRA.Graphics
|
|||||||
public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset)
|
public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset)
|
||||||
{
|
{
|
||||||
var terrain = new Bitmap(map.MapSize.X, map.MapSize.Y);
|
var terrain = new Bitmap(map.MapSize.X, map.MapSize.Y);
|
||||||
for (var y = 0; y < map.MapSize.Y; y++)
|
for (var x = 0; x < map.MapSize.X; x++)
|
||||||
for (var x = 0; x < map.MapSize.X; x++)
|
for (var y = 0; y < map.MapSize.Y; y++)
|
||||||
terrain.SetPixel(x, y, map.IsInMap(x, y)
|
terrain.SetPixel(x, y, map.IsInMap(x, y)
|
||||||
? Color.FromArgb(alpha, terrainTypeColors[map.Theater].ColorForTerrainType(tileset.GetTerrainType(map.MapTiles[x, y])))
|
? Color.FromArgb(alpha, terrainTypeColors[map.Theater].ColorForTerrainType(tileset.GetTerrainType(map.MapTiles[x, y])))
|
||||||
: shroudColor);
|
: shroudColor);
|
||||||
@@ -117,8 +117,8 @@ namespace OpenRA.Graphics
|
|||||||
var res = world.WorldActor.traits.Get<ResourceLayer>();
|
var res = world.WorldActor.traits.Get<ResourceLayer>();
|
||||||
|
|
||||||
oreLayer = new Bitmap(terrain);
|
oreLayer = new Bitmap(terrain);
|
||||||
for (var y = world.Map.TopLeft.Y; y < world.Map.BottomRight.Y; y++)
|
for (var x = world.Map.TopLeft.X; x < world.Map.BottomRight.X; x++)
|
||||||
for (var x = world.Map.TopLeft.X; x < world.Map.BottomRight.X; x++)
|
for (var y = world.Map.TopLeft.Y; y < world.Map.BottomRight.Y; y++)
|
||||||
if (res.GetResource(new int2(x,y)) != null)
|
if (res.GetResource(new int2(x,y)) != null)
|
||||||
oreLayer.SetPixel(x, y, Color.FromArgb(alpha, terrainTypeColors[world.Map.Theater].ColorForTerrainType(TerrainType.Ore)));
|
oreLayer.SetPixel(x, y, Color.FromArgb(alpha, terrainTypeColors[world.Map.Theater].ColorForTerrainType(TerrainType.Ore)));
|
||||||
}
|
}
|
||||||
@@ -140,8 +140,8 @@ namespace OpenRA.Graphics
|
|||||||
*(c + (a.Actor.Location.Y * bitmapData.Stride >> 2) + a.Actor.Location.X) =
|
*(c + (a.Actor.Location.Y * bitmapData.Stride >> 2) + a.Actor.Location.X) =
|
||||||
Color.FromArgb(alpha, a.Actor.Owner.Color).ToArgb();
|
Color.FromArgb(alpha, a.Actor.Owner.Color).ToArgb();
|
||||||
|
|
||||||
for (var y = world.Map.BottomRight.Y; y < world.Map.YOffset + world.Map.BottomRight.Y; y++)
|
for (var x = world.Map.TopLeft.X; x < world.Map.BottomRight.X; x++)
|
||||||
for (var x = world.Map.TopLeft.X; x < world.Map.BottomRight.X; x++)
|
for (var y = world.Map.TopLeft.Y; y < world.Map.BottomRight.Y; y++)
|
||||||
{
|
{
|
||||||
if (!world.LocalPlayer.Shroud.DisplayOnRadar(x, y))
|
if (!world.LocalPlayer.Shroud.DisplayOnRadar(x, y))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,11 +50,10 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
int nv = 0;
|
int nv = 0;
|
||||||
int ni = 0;
|
int ni = 0;
|
||||||
for( int i = map.TopLeft.X ; i < map.BottomRight.X; i++ )
|
for( int j = map.TopLeft.Y ; j < map.BottomRight.Y; j++ )
|
||||||
for( int j = map.TopLeft.Y ; j < map.BottomRight.Y; j++ )
|
for( int i = map.TopLeft.X ; i < map.BottomRight.X; i++ )
|
||||||
{
|
{
|
||||||
Log.Write("{0} {1}",i,j);
|
Sprite tile = tileMapping[map.MapTiles[i, j]];
|
||||||
Sprite tile = tileMapping[map.MapTiles[i, j]];
|
|
||||||
// TODO: The zero below should explicitly refer to the terrain palette, but this code is called
|
// TODO: The zero below should explicitly refer to the terrain palette, but this code is called
|
||||||
// before the palettes are created
|
// before the palettes are created
|
||||||
Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni, tile.size);
|
Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni, tile.size);
|
||||||
|
|||||||
@@ -28,17 +28,9 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
public object Create(Actor self) { return new ResourceLayer(self); }
|
public object Create(Actor self) { return new ResourceLayer(self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ResourceLayer// : IRenderOverlay, ILoadWorldHook
|
public class ResourceLayer: IRenderOverlay, ILoadWorldHook
|
||||||
{
|
{
|
||||||
public ResourceLayer(Actor self) {}
|
|
||||||
public void Destroy(int2 p){}
|
|
||||||
public ResourceTypeInfo GetResource(int2 p) {return null;}
|
|
||||||
public ResourceTypeInfo Harvest(int2 p) {return null;}
|
|
||||||
public void AddResource(ResourceTypeInfo info, int i, int j, int n) {}
|
|
||||||
public void Grow(ResourceTypeInfo info) {}
|
|
||||||
public void Spread(ResourceTypeInfo info) {}
|
|
||||||
/*
|
|
||||||
SpriteRenderer sr;
|
SpriteRenderer sr;
|
||||||
World w;
|
World w;
|
||||||
|
|
||||||
@@ -73,7 +65,7 @@ namespace OpenRA.Traits
|
|||||||
public void WorldLoaded(World w)
|
public void WorldLoaded(World w)
|
||||||
{
|
{
|
||||||
this.w = w;
|
this.w = w;
|
||||||
content = new CellContents[w.Map.MapSize, w.Map.MapSize];
|
content = new CellContents[w.Map.MapSize.X, w.Map.MapSize.Y];
|
||||||
|
|
||||||
resourceTypes = w.WorldActor.Info.Traits.WithInterface<ResourceTypeInfo>().ToArray();
|
resourceTypes = w.WorldActor.Info.Traits.WithInterface<ResourceTypeInfo>().ToArray();
|
||||||
foreach (var rt in resourceTypes)
|
foreach (var rt in resourceTypes)
|
||||||
@@ -81,11 +73,11 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
var map = w.Map;
|
var map = w.Map;
|
||||||
|
|
||||||
for (int y = map.YOffset; y < map.YOffset + map.Height; y++)
|
for (int x = map.XOffset; x < map.XOffset + map.Width; x++)
|
||||||
for (int x = map.XOffset; x < map.XOffset + map.Width; x++)
|
for (int y = map.YOffset; y < map.YOffset + map.Height; y++)
|
||||||
{
|
{
|
||||||
content[x,y].type = resourceTypes.FirstOrDefault(
|
content[x,y].type = resourceTypes.FirstOrDefault(
|
||||||
r => r.Overlays.Contains(w.Map.MapTiles[x, y].overlay));
|
r => r.ResourceType == w.Map.MapResources[x,y].type);
|
||||||
if (content[x, y].type != null)
|
if (content[x, y].type != null)
|
||||||
content[x, y].image = ChooseContent(content[x, y].type);
|
content[x, y].image = ChooseContent(content[x, y].type);
|
||||||
}
|
}
|
||||||
@@ -157,17 +149,14 @@ namespace OpenRA.Traits
|
|||||||
public void Grow(ResourceTypeInfo info)
|
public void Grow(ResourceTypeInfo info)
|
||||||
{
|
{
|
||||||
var map = w.Map;
|
var map = w.Map;
|
||||||
var mini = map.XOffset; var maxi = map.XOffset + map.Width;
|
var newDensity = new byte[map.MapSize.X, map.MapSize.Y];
|
||||||
var minj = map.YOffset; var maxj = map.YOffset + map.Height;
|
for (int i = map.TopLeft.X; i < map.BottomRight.X; i++)
|
||||||
|
for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++)
|
||||||
var newDensity = new byte[map.MapSize, map.MapSize];
|
|
||||||
for (int j = minj; j < maxj; j++)
|
|
||||||
for (int i = mini; i < maxi; i++)
|
|
||||||
if (content[i, j].type == info)
|
if (content[i, j].type == info)
|
||||||
newDensity[i, j] = (byte)GetIdealDensity(i, j);
|
newDensity[i, j] = (byte)GetIdealDensity(i, j);
|
||||||
|
|
||||||
for (int j = minj; j < maxj; j++)
|
for (int i = map.TopLeft.X; i < map.BottomRight.X; i++)
|
||||||
for (int i = mini; i < maxi; i++)
|
for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++)
|
||||||
if (content[i, j].type == info && content[i, j].density < newDensity[i, j])
|
if (content[i, j].type == info && content[i, j].density < newDensity[i, j])
|
||||||
++content[i, j].density;
|
++content[i, j].density;
|
||||||
}
|
}
|
||||||
@@ -179,16 +168,16 @@ namespace OpenRA.Traits
|
|||||||
var mini = map.XOffset; var maxi = map.XOffset + map.Width;
|
var mini = map.XOffset; var maxi = map.XOffset + map.Width;
|
||||||
var minj = map.YOffset; var maxj = map.YOffset + map.Height;
|
var minj = map.YOffset; var maxj = map.YOffset + map.Height;
|
||||||
|
|
||||||
var growMask = new bool[map.MapSize, map.MapSize];
|
var growMask = new bool[map.MapSize.X, map.MapSize.Y];
|
||||||
for (int j = minj; j < maxj; j++)
|
for (int i = map.TopLeft.X; i < map.BottomRight.X; i++)
|
||||||
for (int i = mini; i < maxi; i++)
|
for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++)
|
||||||
if (content[i,j].type == null
|
if (content[i,j].type == null
|
||||||
&& GetAdjacentCellsWith(info, i,j ) > 0
|
&& GetAdjacentCellsWith(info, i,j ) > 0
|
||||||
&& w.IsCellBuildable(new int2(i, j), false))
|
&& w.IsCellBuildable(new int2(i, j), false))
|
||||||
growMask[i, j] = true;
|
growMask[i, j] = true;
|
||||||
|
|
||||||
for (int j = minj; j < maxj; j++)
|
for (int i = map.TopLeft.X; i < map.BottomRight.X; i++)
|
||||||
for (int i = mini; i < maxi; i++)
|
for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++)
|
||||||
if (growMask[i, j])
|
if (growMask[i, j])
|
||||||
{
|
{
|
||||||
content[i, j].type = info;
|
content[i, j].type = info;
|
||||||
@@ -206,6 +195,5 @@ namespace OpenRA.Traits
|
|||||||
public Sprite[] image;
|
public Sprite[] image;
|
||||||
public int density;
|
public int density;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
public class ResourceTypeInfo : ITraitInfo
|
public class ResourceTypeInfo : ITraitInfo
|
||||||
{
|
{
|
||||||
public readonly string[] Overlays = { };
|
|
||||||
public readonly string[] SpriteNames = { };
|
public readonly string[] SpriteNames = { };
|
||||||
public readonly string Palette = "terrain";
|
public readonly string Palette = "terrain";
|
||||||
|
public readonly int ResourceType = 1;
|
||||||
|
|
||||||
public readonly int ValuePerUnit = 0;
|
public readonly int ValuePerUnit = 0;
|
||||||
public readonly string Name = null;
|
public readonly string Name = null;
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ World:
|
|||||||
OverlayTypes: barb
|
OverlayTypes: barb
|
||||||
ResourceLayer:
|
ResourceLayer:
|
||||||
ResourceType@green-tib:
|
ResourceType@green-tib:
|
||||||
Overlays: ti1,ti2,ti3,ti4,ti5,ti6,ti7,ti8,ti9,ti10,ti11,ti12
|
ResourceType: 1
|
||||||
Palette: terrain
|
Palette: terrain
|
||||||
SpriteNames: ti1,ti2,ti3,ti4,ti5,ti6,ti7,ti8,ti9,ti10,ti11,ti12
|
SpriteNames: ti1,ti2,ti3,ti4,ti5,ti6,ti7,ti8,ti9,ti10,ti11,ti12
|
||||||
ValuePerUnit: 30
|
ValuePerUnit: 30
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ World:
|
|||||||
OverlayTypes: barb
|
OverlayTypes: barb
|
||||||
ResourceLayer:
|
ResourceLayer:
|
||||||
ResourceType@ore:
|
ResourceType@ore:
|
||||||
Overlays: gold01,gold02,gold03,gold04
|
ResourceType: 1
|
||||||
Palette: terrain
|
Palette: terrain
|
||||||
SpriteNames: gold01,gold02,gold03,gold04
|
SpriteNames: gold01,gold02,gold03,gold04
|
||||||
ValuePerUnit: 25
|
ValuePerUnit: 25
|
||||||
@@ -240,7 +240,7 @@ World:
|
|||||||
GrowthInterval: 1.2
|
GrowthInterval: 1.2
|
||||||
SpreadInterval: 2.0
|
SpreadInterval: 2.0
|
||||||
ResourceType@gem:
|
ResourceType@gem:
|
||||||
Overlays: gem01,gem02,gem03,gem04
|
ResourceType: 1
|
||||||
Palette: terrain
|
Palette: terrain
|
||||||
SpriteNames: gem01,gem02,gem03,gem04
|
SpriteNames: gem01,gem02,gem03,gem04
|
||||||
ValuePerUnit: 50
|
ValuePerUnit: 50
|
||||||
|
|||||||
Reference in New Issue
Block a user