added ResourceType; mostly works, except for growth & consumption
This commit is contained in:
@@ -30,7 +30,7 @@ namespace OpenRA.Traits
|
||||
public object Create(Actor self) { return new OreGrowth(); }
|
||||
}
|
||||
|
||||
class OreGrowth : ITick, ILoadWorldHook
|
||||
class OreGrowth : ITick
|
||||
{
|
||||
int remainingTicks;
|
||||
|
||||
@@ -52,10 +52,5 @@ namespace OpenRA.Traits
|
||||
remainingTicks = (int)(info.Interval * 60 * 25);
|
||||
}
|
||||
}
|
||||
|
||||
public void WorldLoaded(World w)
|
||||
{
|
||||
Ore.InitOreDensity(w.Map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
@@ -26,23 +25,18 @@ namespace OpenRA.Traits
|
||||
{
|
||||
class ResourceLayerInfo : ITraitInfo
|
||||
{
|
||||
public readonly string[] SpriteNames = { };
|
||||
public readonly int[] OverlayIndices = { };
|
||||
public readonly string Palette = "terrain";
|
||||
public object Create(Actor self) { return new ResourceLayer(self, this); }
|
||||
public object Create(Actor self) { return new ResourceLayer(self); }
|
||||
}
|
||||
|
||||
class ResourceLayer : IRenderOverlay, ILoadWorldHook
|
||||
{
|
||||
ResourceLayerInfo info;
|
||||
Sprite[][] sprites;
|
||||
CellContents[,] content = new CellContents[128,128];
|
||||
SpriteRenderer sr;
|
||||
|
||||
public ResourceLayer(Actor self, ResourceLayerInfo info)
|
||||
public ResourceTypeInfo[] resourceTypes;
|
||||
public CellContents[,] content = new CellContents[128, 128];
|
||||
|
||||
public ResourceLayer(Actor self)
|
||||
{
|
||||
this.info = info;
|
||||
sprites = info.SpriteNames.Select( f => SpriteSheetBuilder.LoadAllSprites(f)).ToArray();
|
||||
sr = new SpriteRenderer( Game.renderer, true );
|
||||
}
|
||||
|
||||
@@ -55,10 +49,12 @@ namespace OpenRA.Traits
|
||||
for (int x = map.XOffset; x < map.XOffset + map.Width; x++)
|
||||
{
|
||||
if (!shroud.IsExplored(new int2(x, y))) continue;
|
||||
if (content[x, y].contents != null)
|
||||
sr.DrawSprite(content[x, y].contents[content[x, y].density],
|
||||
|
||||
var c = content[x, y];
|
||||
if (c.image != null)
|
||||
sr.DrawSprite(c.image[c.density],
|
||||
Game.CellSize * new int2(x, y),
|
||||
info.Palette);
|
||||
c.type.Palette);
|
||||
}
|
||||
|
||||
sr.Flush();
|
||||
@@ -66,22 +62,47 @@ namespace OpenRA.Traits
|
||||
|
||||
public void WorldLoaded(World w)
|
||||
{
|
||||
resourceTypes = w.WorldActor.Info.Traits.WithInterface<ResourceTypeInfo>().ToArray();
|
||||
foreach (var rt in resourceTypes)
|
||||
rt.Sprites = rt.SpriteNames.Select(a => SpriteSheetBuilder.LoadAllSprites(a)).ToArray();
|
||||
|
||||
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++)
|
||||
if (info.OverlayIndices.Contains(w.Map.MapTiles[x, y].overlay))
|
||||
content[x, y].contents = ChooseContent(w, w.Map.MapTiles[x, y].overlay);
|
||||
{
|
||||
content[x,y].type = resourceTypes.FirstOrDefault(
|
||||
r => r.Overlays.Contains(w.Map.MapTiles[x, y].overlay));
|
||||
if (content[x, y].type != null)
|
||||
content[x, y].image = ChooseContent(w, content[x, y].type);
|
||||
}
|
||||
|
||||
for (int y = map.YOffset; y < map.YOffset + map.Height; y++)
|
||||
for (int x = map.XOffset; x < map.XOffset + map.Width; x++)
|
||||
if (content[x, y].type != null)
|
||||
content[x, y].density = (GetAdjacentCellsWith(content[x, y].type, x, y) *
|
||||
content[x, y].image.Length) / 9;
|
||||
}
|
||||
|
||||
Sprite[] ChooseContent(World w, int overlay)
|
||||
public Sprite[] ChooseContent(World w, ResourceTypeInfo info)
|
||||
{
|
||||
return sprites[w.SharedRandom.Next(sprites.Length)];
|
||||
return info.Sprites[w.SharedRandom.Next(info.Sprites.Length)];
|
||||
}
|
||||
|
||||
public int GetAdjacentCellsWith(ResourceTypeInfo info, int i, int j)
|
||||
{
|
||||
int sum = 0;
|
||||
for (var u = -1; u < 2; u++)
|
||||
for (var v = -1; v < 2; v++)
|
||||
if (content[i+u, j+v].type == info)
|
||||
++sum;
|
||||
return sum;
|
||||
}
|
||||
|
||||
public struct CellContents
|
||||
{
|
||||
public Sprite[] contents;
|
||||
public ResourceTypeInfo type;
|
||||
public Sprite[] image;
|
||||
public int density;
|
||||
}
|
||||
}
|
||||
|
||||
39
OpenRA.Game/Traits/World/ResourceType.cs
Normal file
39
OpenRA.Game/Traits/World/ResourceType.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
*
|
||||
* OpenRA is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* OpenRA is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Graphics;
|
||||
using System.Collections.Generic;
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class ResourceTypeInfo : ITraitInfo
|
||||
{
|
||||
public readonly int[] Overlays = { };
|
||||
public readonly string[] SpriteNames = { };
|
||||
public readonly string Palette = "terrain";
|
||||
public readonly int ValuePerUnit = 0;
|
||||
public readonly string Name = null;
|
||||
|
||||
public Sprite[][] Sprites;
|
||||
|
||||
public object Create(Actor self) { return new ResourceType(); }
|
||||
}
|
||||
|
||||
class ResourceType { }
|
||||
}
|
||||
Reference in New Issue
Block a user