wew lad
This commit is contained in:
@@ -17,5 +17,22 @@
|
|||||||
|
|
||||||
package tenor;
|
package tenor;
|
||||||
|
|
||||||
public class ActuallyCraftTask {
|
public class ActuallyCraftTask extends TaskLeaf implements ISingularTask {
|
||||||
|
|
||||||
|
public final CraftingTask parent;
|
||||||
|
|
||||||
|
public ActuallyCraftTask(CraftingTask parent) {
|
||||||
|
this.parent = parent;
|
||||||
|
addParent(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double cost() {
|
||||||
|
return 420;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double priority() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,16 +21,22 @@ import java.util.List;
|
|||||||
|
|
||||||
public class AquireCraftingItems extends QuantizedTaskNode implements ClaimProvider {
|
public class AquireCraftingItems extends QuantizedTaskNode implements ClaimProvider {
|
||||||
|
|
||||||
CraftingTask output;
|
final CraftingTask parent;
|
||||||
|
final QuantizedToQuantizedTaskRelationship parentRelationship;
|
||||||
|
|
||||||
public AquireCraftingItems() {
|
public AquireCraftingItems(CraftingTask parent) {
|
||||||
super(DependencyType.PARALLEL_ALL);
|
super(DependencyType.PARALLEL_ALL);
|
||||||
|
this.parent = parent;
|
||||||
|
this.parentRelationship = createRelationshipToParent(parent);
|
||||||
|
addParent(parentRelationship);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double priorityAllocatedTo(IQuantizedParentTaskRelationship child, int quantity) {
|
public double priorityAllocatedTo(IQuantizedParentTaskRelationship child, int quantity) {
|
||||||
AquireItemTask resource = (AquireItemTask) child.childTask(); // all our dependents are aquire item tasks
|
AquireItemTask resource = (AquireItemTask) child.childTask(); // all our dependents are aquire item tasks
|
||||||
int amount = output.inputSizeFor(resource);
|
int amount = parent.inputSizeFor(resource);
|
||||||
|
|
||||||
// they could provide us with quantity
|
// they could provide us with quantity
|
||||||
int actualQuantity = (int) Math.ceil(quantity * 1.0D / amount);
|
int actualQuantity = (int) Math.ceil(quantity * 1.0D / amount);
|
||||||
@@ -41,22 +47,42 @@ public class AquireCraftingItems extends QuantizedTaskNode implements ClaimProvi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQuantityRelationship priority() {
|
public IQuantityRelationship priority() {
|
||||||
return ((List<IQuantizedChildTaskRelationship>) (Object) parentTasks()).get(0)::allocatedPriority; // gamer style
|
return parentRelationship::allocatedPriority; // gamer style
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQuantityRelationship cost() {
|
public IQuantityRelationship cost() {
|
||||||
return null;
|
return x -> {
|
||||||
|
// cost to get x copies of these items
|
||||||
|
double sum = 0;
|
||||||
|
for (QuantizedToQuantizedTaskRelationship resource : (List<QuantizedToQuantizedTaskRelationship>) (Object) childTasks()) {
|
||||||
|
int amountPerCraft = parent.inputSizeFor((AquireItemTask) resource.childTask());
|
||||||
|
int totalAmountNeeded = x * amountPerCraft;
|
||||||
|
|
||||||
|
int amountForUs = resource.quantityCompleted();
|
||||||
|
totalAmountNeeded -= amountForUs;
|
||||||
|
|
||||||
|
if (totalAmountNeeded <= 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
sum += resource.cost().value(totalAmountNeeded);
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int quantityCompletedForParent(IQuantizedChildTaskRelationship relationship) {
|
public int quantityCompletedForParent(IQuantizedChildTaskRelationship relationship) {
|
||||||
|
if (relationship != parentRelationship) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
// our only parent is the crafting task
|
// our only parent is the crafting task
|
||||||
int minCompletion = Integer.MAX_VALUE;
|
int minCompletion = Integer.MAX_VALUE;
|
||||||
for (IQuantizedChildTaskRelationship resource : (List<IQuantizedChildTaskRelationship>) (Object) childTasks()) {
|
for (IQuantizedChildTaskRelationship resource : (List<IQuantizedChildTaskRelationship>) (Object) childTasks()) {
|
||||||
int amountForUs = resource.quantityCompleted();
|
int amountForUs = resource.quantityCompleted();
|
||||||
|
|
||||||
int amountPerCraft = output.inputSizeFor((AquireItemTask) resource.childTask());
|
int amountPerCraft = parent.inputSizeFor((AquireItemTask) resource.childTask());
|
||||||
|
|
||||||
int actualQuantity = (int) Math.ceil(amountForUs * 1.0D / amountPerCraft);
|
int actualQuantity = (int) Math.ceil(amountForUs * 1.0D / amountPerCraft);
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,25 @@ public class CraftingTask extends QuantizedTaskNode {
|
|||||||
|
|
||||||
int outputQuantity;
|
int outputQuantity;
|
||||||
List<Tuple<AquireItemTask, Integer>> recipe;
|
List<Tuple<AquireItemTask, Integer>> recipe;
|
||||||
AquireCraftingItems inputs;
|
|
||||||
|
|
||||||
public CraftingTask() {
|
final AquireCraftingItems inputs;
|
||||||
|
final GetToCraftingTableTask step2;
|
||||||
|
final ActuallyCraftTask step3;
|
||||||
|
|
||||||
|
final AquireItemTask parent;
|
||||||
|
final QuantizedToQuantizedTaskRelationship parentRelationship;
|
||||||
|
|
||||||
|
public CraftingTask(AquireItemTask parent) {
|
||||||
super(DependencyType.SERIAL);
|
super(DependencyType.SERIAL);
|
||||||
|
this.inputs = new AquireCraftingItems(this); // this adds the relationship
|
||||||
|
this.step2 = GetToCraftingTableTask.INSTANCE;
|
||||||
|
step2.addParent(this);
|
||||||
|
this.step3 = new ActuallyCraftTask(this);
|
||||||
|
|
||||||
|
this.parent = parent;
|
||||||
|
this.parentRelationship = createRelationshipToParent(parent);
|
||||||
|
addParent(parentRelationship);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -40,11 +55,7 @@ public class CraftingTask extends QuantizedTaskNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IQuantityRelationship priority() {
|
public IQuantityRelationship priority() {
|
||||||
if (parentTasks().size() != 1) {
|
return parentRelationship::allocatedPriority;
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
// TODO this is a short circuit
|
|
||||||
return ((IQuantizedTask) (parentTasks().get(0).parentTask())).priority();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Baritone.
|
||||||
|
*
|
||||||
|
* Baritone is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Baritone is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package tenor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetToCraftingTableTask extends TaskLeaf implements ISingularTask {
|
||||||
|
public static final GetToCraftingTableTask INSTANCE = new GetToCraftingTableTask(); // ? idk
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double cost() {
|
||||||
|
return 69;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double priority() {
|
||||||
|
List<ISingularChildTaskRelationship> parentTasks = (List) parentTasks(); // pog
|
||||||
|
return parentTasks.stream().mapToDouble(ISingularChildTaskRelationship::allocatedPriority).sum();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,4 +32,16 @@ public interface IQuantizedTask extends ITask {
|
|||||||
IQuantityRelationship priority();
|
IQuantityRelationship priority();
|
||||||
|
|
||||||
IQuantityRelationship cost();
|
IQuantityRelationship cost();
|
||||||
|
|
||||||
|
default IQuantizedChildTaskRelationship<? extends ITaskNodeBase> createRelationshipToParent(ITaskNodeBase parent) {
|
||||||
|
if (parent instanceof IQuantizedTask) {
|
||||||
|
return new QuantizedToQuantizedTaskRelationship((QuantizedTaskNode) parent, this, parent.type());
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedOperationException("SingularToQuantized must be constructed manually since it needs a quantity");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
default QuantizedToQuantizedTaskRelationship createRelationshipToParent(QuantizedTaskNode parent) {
|
||||||
|
return new QuantizedToQuantizedTaskRelationship(parent, this, parent.type());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,15 @@
|
|||||||
package tenor;
|
package tenor;
|
||||||
|
|
||||||
public interface ISingularTask extends ITask {
|
public interface ISingularTask extends ITask {
|
||||||
|
|
||||||
double priorityAllocatedToChild(ISingularParentTaskRelationship relationship);
|
|
||||||
|
|
||||||
double cost();
|
double cost();
|
||||||
|
|
||||||
|
double priority();
|
||||||
|
|
||||||
|
default ISingularChildTaskRelationship<? extends ITaskNodeBase> createRelationshipToParent(ITaskNodeBase parent) {
|
||||||
|
if (parent instanceof IQuantizedTask) {
|
||||||
|
return new QuantizedToSingularTaskRelationship((QuantizedTaskNode) parent, this, parent.type());
|
||||||
|
} else {
|
||||||
|
return new SingularToSingularTaskRelationship((SingularTaskNode) parent, this, parent.type());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,5 +22,5 @@ package tenor;
|
|||||||
* @since 10/30/2018
|
* @since 10/30/2018
|
||||||
*/
|
*/
|
||||||
public interface ISingularTaskNode extends ITaskNodeBase, ISingularTask {
|
public interface ISingularTaskNode extends ITaskNodeBase, ISingularTask {
|
||||||
|
double priorityAllocatedToChild(ISingularParentTaskRelationship relationship);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,4 +22,12 @@ import java.util.List;
|
|||||||
public interface ITask {
|
public interface ITask {
|
||||||
|
|
||||||
List<ITaskRelationshipBase> parentTasks();
|
List<ITaskRelationshipBase> parentTasks();
|
||||||
|
|
||||||
|
ITaskRelationshipBase createRelationshipToParent(ITaskNodeBase parent);
|
||||||
|
|
||||||
|
void addParent(ITaskRelationshipBase relationship);
|
||||||
|
|
||||||
|
default void addParent(ITaskNodeBase parent) {
|
||||||
|
addParent(createRelationshipToParent(parent));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,4 +24,6 @@ public interface ITaskNodeBase extends ITask {
|
|||||||
List<ITaskRelationshipBase> childTasks();
|
List<ITaskRelationshipBase> childTasks();
|
||||||
|
|
||||||
DependencyType type();
|
DependencyType type();
|
||||||
|
|
||||||
|
void addChild(ITaskRelationshipBase relationship);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,4 +22,6 @@ public interface ITaskRelationshipBase<P extends ITaskNodeBase, C extends ITask>
|
|||||||
P parentTask();
|
P parentTask();
|
||||||
|
|
||||||
C childTask();
|
C childTask();
|
||||||
|
|
||||||
|
DependencyType type();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,5 +23,27 @@ public abstract class QuantizedTaskNode extends TaskNode implements IQuantizedTa
|
|||||||
super(type);
|
super(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the child task were able to provide this amount, how much priority would that be?
|
||||||
public abstract double priorityAllocatedTo(IQuantizedParentTaskRelationship child, int quantity);
|
public abstract double priorityAllocatedTo(IQuantizedParentTaskRelationship child, int quantity);
|
||||||
|
|
||||||
|
public int quantityExecutingInto(QuantizedToSingularTaskRelationship child) {
|
||||||
|
if (type() != DependencyType.SERIAL) {
|
||||||
|
throw new UnsupportedOperationException(this + " " + child);
|
||||||
|
}
|
||||||
|
// need to calculate from scratch
|
||||||
|
int ind = childTasks().indexOf(child);
|
||||||
|
if (ind <= 0) {
|
||||||
|
throw new IllegalStateException(childTasks() + "");
|
||||||
|
}
|
||||||
|
int minQuantity = -1;
|
||||||
|
for (int i = 0; i < childTasks().indexOf(child); i++) {
|
||||||
|
QuantizedToQuantizedTaskRelationship relationship = (QuantizedToQuantizedTaskRelationship) childTasks().get(i);
|
||||||
|
ClaimProvider claim = (ClaimProvider) relationship.childTask();
|
||||||
|
int amt = claim.quantityCompletedForParent(relationship);
|
||||||
|
if (minQuantity == -1 || amt < minQuantity) {
|
||||||
|
minQuantity = amt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return minQuantity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ public class QuantizedToQuantizedTaskRelationship
|
|||||||
extends TaskRelationship<QuantizedTaskNode, IQuantizedTask>
|
extends TaskRelationship<QuantizedTaskNode, IQuantizedTask>
|
||||||
implements IQuantizedChildTaskRelationship<QuantizedTaskNode>, IQuantizedParentTaskRelationship<IQuantizedTask> {
|
implements IQuantizedChildTaskRelationship<QuantizedTaskNode>, IQuantizedParentTaskRelationship<IQuantizedTask> {
|
||||||
|
|
||||||
|
public QuantizedToQuantizedTaskRelationship(QuantizedTaskNode parent, IQuantizedTask child, DependencyType type) {
|
||||||
|
super(parent, child, type);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double allocatedPriority(int quantity) {
|
public double allocatedPriority(int quantity) {
|
||||||
return parentTask().priorityAllocatedTo(this, quantity);
|
return parentTask().priorityAllocatedTo(this, quantity);
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ public class QuantizedToSingularTaskRelationship
|
|||||||
extends TaskRelationship<QuantizedTaskNode, ISingularTask>
|
extends TaskRelationship<QuantizedTaskNode, ISingularTask>
|
||||||
implements ISingularChildTaskRelationship<QuantizedTaskNode>, IQuantizedParentTaskRelationship<ISingularTask> {
|
implements ISingularChildTaskRelationship<QuantizedTaskNode>, IQuantizedParentTaskRelationship<ISingularTask> {
|
||||||
|
|
||||||
|
public QuantizedToSingularTaskRelationship(QuantizedTaskNode parent, ISingularTask child, DependencyType type) {
|
||||||
|
super(parent, child, type);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQuantityRelationship cost() {
|
public IQuantityRelationship cost() {
|
||||||
return x -> childTask().cost();
|
return x -> childTask().cost();
|
||||||
@@ -28,6 +32,6 @@ public class QuantizedToSingularTaskRelationship
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double allocatedPriority() {
|
public double allocatedPriority() {
|
||||||
throw new UnsupportedOperationException("Cannot allocate priority from quantized parent to singular child");
|
return parentTask().priorityAllocatedTo(this, parentTask().quantityExecutingInto(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,12 @@ public class SingularToQuantizedTaskRelationship
|
|||||||
extends TaskRelationship<SingularTaskNode, IQuantizedTask>
|
extends TaskRelationship<SingularTaskNode, IQuantizedTask>
|
||||||
implements IQuantizedChildTaskRelationship<SingularTaskNode>, ISingularParentTaskRelationship<IQuantizedTask> {
|
implements IQuantizedChildTaskRelationship<SingularTaskNode>, ISingularParentTaskRelationship<IQuantizedTask> {
|
||||||
|
|
||||||
int quantityRequired;
|
public int quantityRequired;
|
||||||
|
|
||||||
|
public SingularToQuantizedTaskRelationship(SingularTaskNode parent, IQuantizedTask child, DependencyType type, int quantityRequired) {
|
||||||
|
super(parent, child, type);
|
||||||
|
this.quantityRequired = quantityRequired;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double allocatedPriority(int quantity) {
|
public double allocatedPriority(int quantity) {
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ public class SingularToSingularTaskRelationship
|
|||||||
extends TaskRelationship<SingularTaskNode, ISingularTask>
|
extends TaskRelationship<SingularTaskNode, ISingularTask>
|
||||||
implements ISingularChildTaskRelationship<SingularTaskNode>, ISingularParentTaskRelationship<ISingularTask> {
|
implements ISingularChildTaskRelationship<SingularTaskNode>, ISingularParentTaskRelationship<ISingularTask> {
|
||||||
|
|
||||||
|
public SingularToSingularTaskRelationship(SingularTaskNode parent, ISingularTask child, DependencyType type) {
|
||||||
|
super(parent, child, type);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double allocatedPriority() {
|
public double allocatedPriority() {
|
||||||
return parentTask().priorityAllocatedToChild(this);
|
return parentTask().priorityAllocatedToChild(this);
|
||||||
|
|||||||
@@ -23,7 +23,17 @@ public abstract class Task implements ITask {
|
|||||||
|
|
||||||
List<ITaskRelationshipBase> parentRelationships;
|
List<ITaskRelationshipBase> parentRelationships;
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<ITaskRelationshipBase> parentTasks() {
|
public List<ITaskRelationshipBase> parentTasks() {
|
||||||
return parentRelationships;
|
return parentRelationships;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addParent(ITaskRelationshipBase relationship) {
|
||||||
|
if (relationship.childTask() != this) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
relationship.parentTask().addChild(relationship);
|
||||||
|
parentRelationships.add(relationship);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,5 +17,5 @@
|
|||||||
|
|
||||||
package tenor;
|
package tenor;
|
||||||
|
|
||||||
public class TaskLeaf extends Task {
|
public abstract class TaskLeaf extends Task {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import java.util.List;
|
|||||||
public abstract class TaskNode extends Task implements ITaskNodeBase {
|
public abstract class TaskNode extends Task implements ITaskNodeBase {
|
||||||
|
|
||||||
List<ITaskRelationshipBase> childRelationships;
|
List<ITaskRelationshipBase> childRelationships;
|
||||||
DependencyType type;
|
public final DependencyType type;
|
||||||
|
|
||||||
public TaskNode(DependencyType type) {
|
public TaskNode(DependencyType type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -35,4 +35,14 @@ public abstract class TaskNode extends Task implements ITaskNodeBase {
|
|||||||
public DependencyType type() {
|
public DependencyType type() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addChild(ITaskRelationshipBase relationship) {
|
||||||
|
if (relationship.parentTask() != this) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
if (relationship.type() != type) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
childRelationships.add(relationship);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,18 @@ package tenor;
|
|||||||
|
|
||||||
public class TaskRelationship<P extends ITaskNodeBase, C extends ITask> implements ITaskRelationshipBase<P, C> {
|
public class TaskRelationship<P extends ITaskNodeBase, C extends ITask> implements ITaskRelationshipBase<P, C> {
|
||||||
|
|
||||||
P parent;
|
public final P parent;
|
||||||
C child;
|
public final C child;
|
||||||
DependencyType type;
|
public final DependencyType type;
|
||||||
|
|
||||||
|
public TaskRelationship(P parent, C child, DependencyType type) {
|
||||||
|
this.parent = parent;
|
||||||
|
this.child = child;
|
||||||
|
this.type = type;
|
||||||
|
if (parent.type() != type) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public P parentTask() {
|
public P parentTask() {
|
||||||
@@ -32,4 +41,9 @@ public class TaskRelationship<P extends ITaskNodeBase, C extends ITask> implemen
|
|||||||
public C childTask() {
|
public C childTask() {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DependencyType type() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user