Fixes & Resources support

This commit is contained in:
Paul Chote
2010-04-01 22:02:04 +13:00
committed by Bob
parent 705e3eb2f6
commit c366b7c7fc
7 changed files with 32 additions and 49 deletions

View File

@@ -88,16 +88,12 @@ namespace OpenRA.FileFormats
public byte[] GetBytes(TileReference<ushort,byte> r)
{
Terrain tile;
Log.Write("Attempting to load tile {0} {1}",r.type,r.image);
try {
if( tiles.TryGetValue( r.type, out tile ) )
return tile.TileBitmapBytes[ r.image ];
}
catch (System.ArgumentOutOfRangeException)
{
tiles.TryGetValue( 0xfffe, out tile );
return tile.TileBitmapBytes[ 0 ];
}
catch (System.ArgumentOutOfRangeException) { }
byte[] missingTile = new byte[ 24 * 24 ];
for( int i = 0 ; i < missingTile.Length ; i++ )
missingTile[ i ] = 0x36;

View File

@@ -89,8 +89,8 @@ namespace OpenRA.Graphics
public static Bitmap RenderTerrainBitmap(Map map, TileSet tileset)
{
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 y = 0; y < map.MapSize.Y; y++)
terrain.SetPixel(x, y, map.IsInMap(x, y)
? Color.FromArgb(alpha, terrainTypeColors[map.Theater].ColorForTerrainType(tileset.GetTerrainType(map.MapTiles[x, y])))
: shroudColor);
@@ -117,8 +117,8 @@ namespace OpenRA.Graphics
var res = world.WorldActor.traits.Get<ResourceLayer>();
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 y = world.Map.TopLeft.Y; y < world.Map.BottomRight.Y; y++)
if (res.GetResource(new int2(x,y)) != null)
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) =
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 y = world.Map.TopLeft.Y; y < world.Map.BottomRight.Y; y++)
{
if (!world.LocalPlayer.Shroud.DisplayOnRadar(x, y))
{

View File

@@ -50,10 +50,9 @@ namespace OpenRA.Graphics
int nv = 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 i = map.TopLeft.X ; i < map.BottomRight.X; i++ )
{
Log.Write("{0} {1}",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
// before the palettes are created

View File

@@ -29,16 +29,8 @@ namespace OpenRA.Traits
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;
World w;
@@ -73,7 +65,7 @@ namespace OpenRA.Traits
public void WorldLoaded(World 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();
foreach (var rt in resourceTypes)
@@ -81,11 +73,11 @@ namespace OpenRA.Traits
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 y = map.YOffset; y < map.YOffset + map.Height; y++)
{
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)
content[x, y].image = ChooseContent(content[x, y].type);
}
@@ -157,17 +149,14 @@ namespace OpenRA.Traits
public void Grow(ResourceTypeInfo info)
{
var map = w.Map;
var mini = map.XOffset; var maxi = map.XOffset + map.Width;
var minj = map.YOffset; var maxj = map.YOffset + map.Height;
var newDensity = new byte[map.MapSize, map.MapSize];
for (int j = minj; j < maxj; j++)
for (int i = mini; i < maxi; i++)
var newDensity = new byte[map.MapSize.X, map.MapSize.Y];
for (int i = map.TopLeft.X; i < map.BottomRight.X; i++)
for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++)
if (content[i, j].type == info)
newDensity[i, j] = (byte)GetIdealDensity(i, j);
for (int j = minj; j < maxj; j++)
for (int i = mini; i < maxi; i++)
for (int i = map.TopLeft.X; i < map.BottomRight.X; 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])
++content[i, j].density;
}
@@ -179,16 +168,16 @@ namespace OpenRA.Traits
var mini = map.XOffset; var maxi = map.XOffset + map.Width;
var minj = map.YOffset; var maxj = map.YOffset + map.Height;
var growMask = new bool[map.MapSize, map.MapSize];
for (int j = minj; j < maxj; j++)
for (int i = mini; i < maxi; i++)
var growMask = new bool[map.MapSize.X, map.MapSize.Y];
for (int i = map.TopLeft.X; i < map.BottomRight.X; i++)
for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++)
if (content[i,j].type == null
&& GetAdjacentCellsWith(info, i,j ) > 0
&& w.IsCellBuildable(new int2(i, j), false))
growMask[i, j] = true;
for (int j = minj; j < maxj; j++)
for (int i = mini; i < maxi; i++)
for (int i = map.TopLeft.X; i < map.BottomRight.X; i++)
for (int j = map.TopLeft.Y; j < map.BottomRight.Y; j++)
if (growMask[i, j])
{
content[i, j].type = info;
@@ -206,6 +195,5 @@ namespace OpenRA.Traits
public Sprite[] image;
public int density;
}
*/
}
}

View File

@@ -24,9 +24,9 @@ namespace OpenRA.Traits
{
public class ResourceTypeInfo : ITraitInfo
{
public readonly string[] Overlays = { };
public readonly string[] SpriteNames = { };
public readonly string Palette = "terrain";
public readonly int ResourceType = 1;
public readonly int ValuePerUnit = 0;
public readonly string Name = null;

View File

@@ -209,7 +209,7 @@ World:
OverlayTypes: barb
ResourceLayer:
ResourceType@green-tib:
Overlays: ti1,ti2,ti3,ti4,ti5,ti6,ti7,ti8,ti9,ti10,ti11,ti12
ResourceType: 1
Palette: terrain
SpriteNames: ti1,ti2,ti3,ti4,ti5,ti6,ti7,ti8,ti9,ti10,ti11,ti12
ValuePerUnit: 30

View File

@@ -232,7 +232,7 @@ World:
OverlayTypes: barb
ResourceLayer:
ResourceType@ore:
Overlays: gold01,gold02,gold03,gold04
ResourceType: 1
Palette: terrain
SpriteNames: gold01,gold02,gold03,gold04
ValuePerUnit: 25
@@ -240,7 +240,7 @@ World:
GrowthInterval: 1.2
SpreadInterval: 2.0
ResourceType@gem:
Overlays: gem01,gem02,gem03,gem04
ResourceType: 1
Palette: terrain
SpriteNames: gem01,gem02,gem03,gem04
ValuePerUnit: 50