removed TileReference.density
This commit is contained in:
@@ -49,17 +49,16 @@ namespace OpenRA.Traits.Activities
|
||||
var harv = self.traits.Get<Harvester>();
|
||||
var renderUnit = self.traits.Get<RenderUnit>(); /* better have one of these! */
|
||||
|
||||
var isGem = false;
|
||||
if (!self.World.Map.ContainsResource(self.Location) ||
|
||||
!self.World.Map.Harvest(self.Location, out isGem))
|
||||
var resource = self.World.WorldActor.traits.Get<ResourceLayer>().Harvest(self.Location);
|
||||
if (resource == null)
|
||||
return false;
|
||||
|
||||
|
||||
if (renderUnit.anim.CurrentSequence.Name != "harvest")
|
||||
{
|
||||
isHarvesting = true;
|
||||
renderUnit.PlayCustomAnimation(self, "harvest", () => isHarvesting = false);
|
||||
}
|
||||
harv.AcceptResource(isGem);
|
||||
harv.AcceptResource(resource);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -47,9 +47,10 @@ namespace OpenRA.Traits
|
||||
public bool IsFull { get { return oreCarried + gemsCarried == self.Info.Traits.Get<HarvesterInfo>().BailCount; } }
|
||||
public bool IsEmpty { get { return oreCarried == 0 && gemsCarried == 0; } }
|
||||
|
||||
public void AcceptResource(bool isGem)
|
||||
public void AcceptResource(ResourceTypeInfo type)
|
||||
{
|
||||
if (isGem) gemsCarried++;
|
||||
// FIXME: harvester probably needs to know *exactly* what it is carrying.
|
||||
if (type.Name == "Gems") gemsCarried++;
|
||||
else oreCarried++;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,16 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class SeedsOreInfo : ITraitInfo
|
||||
{
|
||||
public readonly float Chance = .05f;
|
||||
public readonly int Interval = 5;
|
||||
public readonly string ResourceType = "Ore";
|
||||
|
||||
public object Create(Actor self) { return new SeedsOre(); }
|
||||
}
|
||||
@@ -37,12 +41,20 @@ namespace OpenRA.Traits
|
||||
if (--ticks <= 0)
|
||||
{
|
||||
var info = self.Info.Traits.Get<SeedsOreInfo>();
|
||||
var resourceType = self.World.WorldActor.Info.Traits
|
||||
.WithInterface<ResourceTypeInfo>()
|
||||
.FirstOrDefault(t => t.Name == info.ResourceType);
|
||||
|
||||
if (resourceType == null)
|
||||
throw new InvalidOperationException("No such resource type `{0}`".F(info.ResourceType));
|
||||
|
||||
var resLayer = self.World.WorldActor.traits.Get<ResourceLayer>();
|
||||
|
||||
for (var j = -1; j < 2; j++)
|
||||
for (var i = -1; i < 2; i++)
|
||||
if (self.World.SharedRandom.NextDouble() < info.Chance)
|
||||
if (self.World.OreCanSpreadInto(self.Location.X + i, self.Location.Y + j))
|
||||
self.World.Map.AddOre(self.Location.X + i, self.Location.Y + j);
|
||||
if (self.World.IsCellBuildable(self.Location + new int2(i, j), UnitMovementType.Wheel))
|
||||
resLayer.AddResource(resourceType, self.Location.X + i, self.Location.Y + j, 1);
|
||||
|
||||
ticks = info.Interval;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace OpenRA.Traits
|
||||
info.Chance);
|
||||
|
||||
if (info.Grows)
|
||||
Ore.GrowOre(self.World, self.World.SharedRandom);
|
||||
Ore.GrowOre(self.World);
|
||||
|
||||
self.World.Minimap.InvalidateOre();
|
||||
remainingTicks = (int)(info.Interval * 60 * 25);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
using System;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
@@ -31,6 +32,7 @@ namespace OpenRA.Traits
|
||||
class ResourceLayer : IRenderOverlay, ILoadWorldHook
|
||||
{
|
||||
SpriteRenderer sr;
|
||||
World w;
|
||||
|
||||
public ResourceTypeInfo[] resourceTypes;
|
||||
public CellContents[,] content = new CellContents[128, 128];
|
||||
@@ -62,6 +64,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public void WorldLoaded(World w)
|
||||
{
|
||||
this.w = w;
|
||||
resourceTypes = w.WorldActor.Info.Traits.WithInterface<ResourceTypeInfo>().ToArray();
|
||||
foreach (var rt in resourceTypes)
|
||||
rt.Sprites = rt.SpriteNames.Select(a => SpriteSheetBuilder.LoadAllSprites(a)).ToArray();
|
||||
@@ -74,7 +77,7 @@ namespace OpenRA.Traits
|
||||
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);
|
||||
content[x, y].image = ChooseContent(content[x, y].type);
|
||||
}
|
||||
|
||||
for (int y = map.YOffset; y < map.YOffset + map.Height; y++)
|
||||
@@ -84,7 +87,7 @@ namespace OpenRA.Traits
|
||||
content[x, y].image.Length) / 9;
|
||||
}
|
||||
|
||||
public Sprite[] ChooseContent(World w, ResourceTypeInfo info)
|
||||
public Sprite[] ChooseContent(ResourceTypeInfo info)
|
||||
{
|
||||
return info.Sprites[w.SharedRandom.Next(info.Sprites.Length)];
|
||||
}
|
||||
@@ -99,6 +102,33 @@ namespace OpenRA.Traits
|
||||
return sum;
|
||||
}
|
||||
|
||||
public void AddResource(ResourceTypeInfo info, int i, int j, int n)
|
||||
{
|
||||
if (content[i, j].type == null)
|
||||
{
|
||||
content[i, j].type = info;
|
||||
content[i, j].image = ChooseContent(info);
|
||||
content[i, j].density = -1;
|
||||
}
|
||||
|
||||
if (content[i, j].type != info)
|
||||
return;
|
||||
|
||||
content[i, j].density = Math.Min(
|
||||
content[i, j].image.Length - 1,
|
||||
content[i, j].density + n);
|
||||
}
|
||||
|
||||
public ResourceTypeInfo Harvest(int2 p)
|
||||
{
|
||||
var type = content[p.X,p.Y].type;
|
||||
if (type == null) return null;
|
||||
|
||||
if (--content[p.X, p.Y].density < 0)
|
||||
content[p.X, p.Y].type = null;
|
||||
return type;
|
||||
}
|
||||
|
||||
public struct CellContents
|
||||
{
|
||||
public ResourceTypeInfo type;
|
||||
|
||||
@@ -22,7 +22,7 @@ using OpenRA.Graphics;
|
||||
using System.Collections.Generic;
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class ResourceTypeInfo : ITraitInfo
|
||||
public class ResourceTypeInfo : ITraitInfo
|
||||
{
|
||||
public readonly int[] Overlays = { };
|
||||
public readonly string[] SpriteNames = { };
|
||||
|
||||
Reference in New Issue
Block a user