SeedsOre parameters in traitinfo
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user