SeedsOre parameters in traitinfo

This commit is contained in:
Chris Forbes
2010-01-17 11:04:59 +13:00
parent 314880c3e1
commit 33ba3a58c5

View File

@@ -1,19 +1,32 @@

namespace OpenRa.Traits
{
class SeedsOreInfo : StatelessTraitInfo<SeedsOre> {}
class SeedsOreInfo : ITraitInfo
{
public readonly float Chance = .05f;
public readonly int Interval = 5;
public object Create(Actor self) { return new SeedsOre(); }
}
class SeedsOre : ITick
{
const double OreSeedProbability = .05; // todo: push this out into rules
int ticks;
public void Tick(Actor self)
{
for (var j = -1; j < 2; j++)
for (var i = -1; i < 2; i++)
if (Game.SharedRandom.NextDouble() < OreSeedProbability)
if (Ore.CanSpreadInto(self.Location.X + i, self.Location.Y + j))
Rules.Map.AddOre(self.Location.X + i, self.Location.Y + j);
if (--ticks <= 0)
{
var info = self.Info.Traits.Get<SeedsOreInfo>();
for (var j = -1; j < 2; j++)
for (var i = -1; i < 2; i++)
if (Game.SharedRandom.NextDouble() < info.Chance)
if (Ore.CanSpreadInto(self.Location.X + i, self.Location.Y + j))
Rules.Map.AddOre(self.Location.X + i, self.Location.Y + j);
ticks = info.Interval;
}
}
}
}