path cutoff and setting refactor and control

This commit is contained in:
Leijurv 2018-08-19 13:18:48 -07:00
parent 922671c77d
commit 8db6438d16
No known key found for this signature in database
GPG Key ID: 44A3EA646EADAC6A
6 changed files with 68 additions and 10 deletions

View File

@ -30,14 +30,14 @@ import java.util.*;
*/
public class Settings {
public Setting<Boolean> allowBreak = new Setting<>(true);
public Setting<Boolean> allowPlaceThrowaway = new Setting<>(true);
public Setting<Boolean> allowSprint = new Setting<>(true);
public Setting<Boolean> allowPlace = new Setting<>(true);
/**
* It doesn't actually take twenty ticks to place a block, this cost is so high
* because we want to generally conserve blocks which might be limited
*/
public Setting<Double> blockPlacementPenalty = new Setting<>(20D);
public Setting<Boolean> allowWaterBucketFall = new Setting<>(true);
public Setting<Boolean> allowSprint = new Setting<>(true);
public Setting<List<Item>> acceptableThrowawayItems = new Setting<>(Arrays.asList(
Item.getItemFromBlock(Blocks.DIRT),
Item.getItemFromBlock(Blocks.COBBLESTONE),
@ -48,10 +48,11 @@ public class Settings {
// obscure internal A* settings that you probably don't want to change
public Setting<Integer> pathingMaxChunkBorderFetch = new Setting<>(50);
public Setting<Boolean> backtrackCostFavor = new Setting<>(true); // see issue #18
public Setting<Double> backtrackCostFavoringCoefficient = new Setting<>(0.9); // see issue #18
public Setting<Boolean> minimumImprovementRepropagation = new Setting<>(true);
public Setting<Boolean> cutoffAtLoadBoundary = new Setting<>(true);
public Setting<Double> pathCutoffFactor = new Setting<>(0.7);
public Setting<Integer> pathCutoffMinimumLength = new Setting<>(70);
public Setting<Number> pathTimeoutMS = new Setting<>(4000L);
@ -61,7 +62,7 @@ public class Settings {
public Setting<Boolean> chuckCaching = new Setting<>(false);
public Setting<Integer> planningTickLookAhead = new Setting<>(150);/**/
public Setting<Integer> planningTickLookAhead = new Setting<>(150);
public Setting<Boolean> chatDebug = new Setting<>(true);
public Setting<Boolean> chatControl = new Setting<>(true); // probably false in impact
@ -73,7 +74,7 @@ public class Settings {
public Setting<Boolean> fadePath = new Setting<>(false); // give this a better name in the UI, like "better path fps" idk
public final Map<String, Setting<?>> byName;
public final Map<String, Setting<?>> byLowerName;
public final List<Setting<?>> allSettings;
public class Setting<T> {
@ -118,6 +119,7 @@ public class Settings {
Setting<?> setting = (Setting<? extends Object>) field.get(this);
String name = field.getName();
setting.name = name;
name = name.toLowerCase();
if (tmpByName.containsKey(name)) {
throw new IllegalStateException("Duplicate setting name");
}
@ -128,7 +130,7 @@ public class Settings {
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
byName = Collections.unmodifiableMap(tmpByName);
byLowerName = Collections.unmodifiableMap(tmpByName);
allSettings = Collections.unmodifiableList(tmpAll);
}

View File

@ -205,7 +205,7 @@ public class PathingBehavior extends Behavior {
if (Baritone.settings().cutoffAtLoadBoundary.get()) {
path = path.map(IPath::cutoffAtLoadedChunks);
}
path.map(PathExecutor::new).ifPresent(p -> {
path.map(p -> p.staticCutoff(goal)).map(PathExecutor::new).ifPresent(p -> {
synchronized (pathPlanLock) {
if (current == null) {
current = p;

View File

@ -93,8 +93,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper {
long lastPrintout = 0;
int numNodes = 0;
int numEmptyChunk = 0;
boolean favoring = favoredPositions.isPresent() && Baritone.settings().backtrackCostFavor.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
boolean cache = Baritone.settings().chuckCaching.get();
boolean favoring = favoredPositions.isPresent();
boolean cache = Baritone.settings().chuckCaching.get(); // grab all settings beforehand so that changing settings during pathing doesn't cause a crash or unpredictable behavior
int pathingMaxChunkBorderFetch = Baritone.settings().pathingMaxChunkBorderFetch.get();
double favorCoeff = Baritone.settings().backtrackCostFavoringCoefficient.get();
boolean minimumImprovementRepropagation = Baritone.settings().minimumImprovementRepropagation.get();

View File

@ -46,7 +46,7 @@ public class CalculationContext implements Helper {
public CalculationContext(ToolSet toolSet) {
player().setSprinting(true);
this.toolSet = toolSet;
this.hasThrowaway = Baritone.settings().allowPlaceThrowaway.get() && MovementHelper.throwaway(false);
this.hasThrowaway = Baritone.settings().allowPlace.get() && MovementHelper.throwaway(false);
this.hasWaterBucket = Baritone.settings().allowWaterBucketFall.get() && InventoryPlayer.isHotbar(player().inventory.getSlotFor(STACK_BUCKET_WATER)) && !world().provider.isNether();
this.canSprint = Baritone.settings().allowSprint.get() && player().getFoodStats().getFoodLevel() > 6;
this.placeBlockCost = Baritone.settings().blockPlacementPenalty.get();

View File

@ -17,6 +17,8 @@
package baritone.bot.pathing.path;
import baritone.bot.Baritone;
import baritone.bot.pathing.goals.Goal;
import baritone.bot.pathing.movement.Movement;
import baritone.bot.utils.Helper;
import baritone.bot.utils.Utils;
@ -135,4 +137,16 @@ public interface IPath extends Helper {
return this;
}
default IPath staticCutoff(Goal destination) {
if (length() < Baritone.settings().pathCutoffMinimumLength.get()) {
return this;
}
if (destination == null || destination.isInGoal(getDest())) {
return this;
}
double factor = Baritone.settings().pathCutoffFactor.get();
int newLength = (int) (length() * factor);
displayChatMessageRaw("Static cutoff " + length() + " to " + newLength);
return new CutoffPath(this, newLength);
}
}

View File

@ -55,6 +55,9 @@ public class ExampleBaritoneControl extends Behavior {
return;
}
String msg = event.getMessage();
if (msg.startsWith("/")) {
msg = msg.substring(1);
}
if (msg.toLowerCase().startsWith("goal")) {
event.cancel();
String[] params = msg.toLowerCase().substring(4).trim().split(" ");
@ -145,5 +148,44 @@ public class ExampleBaritoneControl extends Behavior {
return;
}
}
if (msg.toLowerCase().equals("baritone") || msg.toLowerCase().equals("settings")) {
for (Settings.Setting<?> setting : Baritone.settings().allSettings) {
displayChatMessageRaw(setting.toString());
}
event.cancel();
return;
}
if (msg.contains(" ")) {
String[] data = msg.split(" ");
if (data.length == 2) {
Settings.Setting setting = Baritone.settings().byLowerName.get(data[0].toLowerCase());
if (setting != null) {
try {
if (setting.value.getClass() == Long.class) {
setting.value = Long.parseLong(data[1]);
}
if (setting.value.getClass() == Integer.class) {
setting.value = Integer.parseInt(data[1]);
}
if (setting.value.getClass() == Double.class) {
setting.value = Double.parseDouble(data[1]);
}
} catch (NumberFormatException e) {
displayChatMessageRaw("Unable to parse " + data[1]);
event.cancel();
return;
}
displayChatMessageRaw(setting.toString());
event.cancel();
return;
}
}
}
if (Baritone.settings().byLowerName.containsKey(msg.toLowerCase())) {
Settings.Setting<?> setting = Baritone.settings().byLowerName.get(msg.toLowerCase());
displayChatMessageRaw(setting.toString());
event.cancel();
return;
}
}
}