Example #1
0
 /// <summary>
 /// Replace the specified old entity with the new in the specified forest.
 /// </summary>
 /// <param name="forest"></param>
 /// <param name="newEntity"></param>
 /// <param name="oldEntity"></param>
 protected virtual void ReplaceEntity(Forest forest, ForestEntity newEntity, ForestEntity oldEntity)
 {
     // Remove the old entity from its current location.
     forest.RemoveEntity(newEntity);
     newEntity.Location = oldEntity.Location;
     forest.AddEntity(newEntity);
 }
Example #2
0
 /// <summary>
 /// Attempt to spread a sapling from the tree.
 /// </summary>
 /// <param name="forest"></param>
 /// <param name="currentTick"></param>
 protected virtual void SpreadSapling(Forest forest, long currentTick)
 {
     // With a 10% chance, create a sapling at an adjacent empty space.
     if (_r.Next(100) / 100.0f < SaplingProbability)
     {
         ForestEntity[] adj        = GetAdjacentEntities(forest);
         ForestEntity   firstEmpty = adj.FirstOrDefault((e) => e.IsEmpty);
         if (firstEmpty != null)
         {
             // First empty space. Create a sapling here.
             Sapling sapling = new Sapling();
             sapling.Location = firstEmpty.Location;
             forest.AddEntity(sapling);
         }
     }
 }
Example #3
0
 protected override void DoTick(Forest forest, long currentTick)
 {
     for (int i = 0; i < _movesPerMonth; i++)
     {
         ForestEntity[] adj          = GetAdjacentEntities(forest);
         ForestEntity   pickedEntity = adj[_r.Next(adj.Length)];
         // Lumberjacks will chop down trees, but only if they're not saplings.
         if (typeof(Tree).IsAssignableFrom(pickedEntity.GetType()) && !(pickedEntity is Sapling))
         {
             Tree tree = (Tree)pickedEntity;
             _logs += tree.Chop();
             ReplaceEntity(forest, this, tree);
             break;
         }
         else if (pickedEntity.IsEmpty)
         {
             // Move here if its an empty location.
             ReplaceEntity(forest, this, pickedEntity);
         }
     }
 }
Example #4
0
 protected override void DoTick(Forest forest, long currentTick)
 {
     for (int i = 0; i < _movesPerMonth; i++)
     {
         ForestEntity[] adj          = GetAdjacentEntities(forest);
         ForestEntity   pickedEntity = adj[_r.Next(adj.Length)];
         // Bears will maw lumberjacks if they come across them.
         if (typeof(LumberJack).IsAssignableFrom(pickedEntity.GetType()))
         {
             LumberJack l = (LumberJack)pickedEntity;
             Maulings++;
             ReplaceEntity(forest, this, l);
             break;
         }
         else if (pickedEntity.IsEmpty)
         {
             // Move here if its an empty location.
             ReplaceEntity(forest, this, pickedEntity);
         }
     }
 }