public int Eat() { if (GrowthTime < World.Tick) { GrowthTime = World.Tick + (uint)RandNum.Integer(MinimumRegrowth, MaximumRegrowth); return(EnergyValue); } return(0); }
public void InitialiseFlora(int coverage) { if (coverage < 0 || coverage > 100) { throw new Exception("Coverage must be a percentage between 0 and 100"); } else { var flora = new List <Flora>(); foreach (var pos in Positions) { if (pos.Altitude > 0 && RandNum.Integer(100) < coverage) { flora.Add(new Flora(this, pos.X, pos.Y)); } } Flora = flora.ToArray(); } }
static void ProcessSeed(object WorldSeed) { RandomPointsWorldSeed worldSeed = (RandomPointsWorldSeed)WorldSeed; if (RandNum.Double() > 0.1) { ThreadPool.QueueUserWorkItem(ProcessSeed, WorldSeed); return; } Point p = worldSeed.Point; Position Pos = worldSeed.ParentPositon; //worldSeed.world.GetPosition(p); for (int i = 0; i < 8; i++) { Point p2 = new Point(p.X, p.Y); switch (i) { case 0: //top right p2.X++; p2.Y--; break; case 1: //right p2.X++; break; case 2: //bottom right p2.X++; p2.Y++; break; case 3: //bottom p2.Y++; break; case 4: //bottom left p2.X--; p2.Y++; break; case 5: //left p2.X--; break; case 6: //top left p2.X--; p2.Y--; break; case 7: //top p2.Y--; break; } p2 = new Point(worldSeed.World.CheckXCoord(p2.X), worldSeed.World.CheckYCoord(p2.Y)); Position Pos2 = worldSeed.World.GetPosition(p2); if (Monitor.TryEnter(Pos2)) { if (!Pos2.Initialised) { Pos2.Initialised = true; short Step = (short)RandNum.Integer(2); //(MinStep, MaxStep); if (Step == 0) { Pos2.Altitude = (short)Pos.Altitude; } else { if (RandNum.Double() < worldSeed.WorldFormer.HighAltitudeProbability) { Pos2.Altitude = (short)(Pos.Altitude + Step); } else { Pos2.Altitude = (short)(Pos.Altitude - Step); } } Interlocked.Increment(ref worldSeed.WorldFormer.PixelsCompleted); RandomPointsWorldSeed NewWorldSeed = new RandomPointsWorldFormer.RandomPointsWorldSeed(worldSeed.World, worldSeed.WorldFormer, p2, Pos2); Interlocked.Increment(ref worldSeed.WorldFormer.WorkingThreads); ThreadPool.QueueUserWorkItem(ProcessSeed, NewWorldSeed); } Monitor.Exit(Pos2); } } Interlocked.Decrement(ref worldSeed.WorldFormer.WorkingThreads); }
public int GetRandomHeight() { return(RandNum.Integer(Height)); }
public int GetRandomWidth() { return(RandNum.Integer(Width)); }