Skip to content

Commit

Permalink
Merge pull request #18 from konstructs/feature-keep-some-saplings
Browse files Browse the repository at this point in the history
Add possibility to leave saplings
  • Loading branch information
petterarvidsson committed Dec 9, 2016
2 parents 17aa09b + 48becd3 commit 8b8d699
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ compileJava {
}

dependencies {
compile group: 'org.konstructs', name: 'konstructs-server-api', version: '0.1.6'
compile group: 'org.konstructs', name: 'konstructs-server-api', version: '0.1.19'
}
10 changes: 7 additions & 3 deletions src/main/java/org/konstructs/forest/CanATreeGrowHere.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.konstructs.forest;

import java.util.Map;
import java.util.Random;

import akka.actor.ActorRef;
import akka.actor.Props;
Expand All @@ -10,6 +11,7 @@
import konstructs.api.messages.BoxQueryResult;

class CanATreeGrowHere extends KonstructsActor {
private final Random random = new Random();
private final Position position;
private final ForestConfig config;
private final BlockTypeId leaves;
Expand Down Expand Up @@ -50,12 +52,14 @@ private void queryForCrown() {

private void canGrow() {
getContext().parent().tell(new PlantTree(position), getSelf());
getContext().stop(getSelf()); /* We are done, let's die*/
getContext().stop(getSelf()); /* We are done, let's die */
}

private void canNotGrow() {
replaceWithVacuum(saplingFilter, position); /* Remove the sapling */
getContext().stop(getSelf()); /* We are done, let's die*/
if(random.nextInt(10000) > config.getLeaveSaplingProbability()) {
replaceWithVacuum(saplingFilter, position); /* Remove the sapling */
}
getContext().stop(getSelf()); /* We are done, let's die */
}

@Override
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/konstructs/forest/ForestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ForestConfig {
private final int seedEveryGeneration;
private final int randomGrowth;
private final int leafDecayDelay;
private final int leaveSaplingProbability;

ForestConfig(Config config) {
this(config.getString("wood-block"),
Expand All @@ -45,7 +46,8 @@ public class ForestConfig {
config.getInt("max-seeds-per-generation"),
config.getInt("seed-every-generation"),
config.getInt("random-growth"),
config.getInt("leaf-decay-delay"));
config.getInt("leaf-decay-delay"),
config.getInt("leave-sapling-probability"));
}

ForestConfig(String wood,
Expand All @@ -67,7 +69,8 @@ public class ForestConfig {
int maxSeedsPerGeneration,
int seedEveryGeneration,
int randomGrowth,
int leafDecayDelay) {
int leafDecayDelay,
int leaveSaplingProbability) {
this.wood = BlockTypeId.fromString(wood);
this.leaves = BlockTypeId.fromString(leaves);
this.thinLeaves = BlockTypeId.fromString(thinLeaves);
Expand All @@ -88,6 +91,7 @@ public class ForestConfig {
this.seedEveryGeneration = seedEveryGeneration;
this.randomGrowth = randomGrowth;
this.leafDecayDelay = leafDecayDelay;
this.leaveSaplingProbability = leaveSaplingProbability;
}

public BlockTypeId getWood() {
Expand Down Expand Up @@ -150,4 +154,7 @@ public int getRandomGrowth() {
public int getLeafDecayDelay() {
return leafDecayDelay;
}
public int getLeaveSaplingProbability() {
return leaveSaplingProbability;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ konstructs {
seed-every-generation = 4
random-growth = 2
leaf-decay-delay = 5000
leave-sapling-probability = 3000
}
org/konstructs/forest/beech {
class = "org.konstructs.forest.ForestPlugin"
Expand All @@ -44,6 +45,7 @@ konstructs {
seed-every-generation = 2
random-growth = 1
leaf-decay-delay = 5000
leave-sapling-probability = 1000
}
org/konstructs/forest/birch {
class = "org.konstructs.forest.ForestPlugin"
Expand All @@ -67,6 +69,7 @@ konstructs {
seed-every-generation = 3
random-growth = 6
leaf-decay-delay = 5000
leave-sapling-probability = 2000
}
org/konstructs/block-manager {
classes {
Expand Down

0 comments on commit 8b8d699

Please sign in to comment.