Fix withdraw amount calculations
This commit is contained in:
parent
0176c85df4
commit
f8031af424
2 changed files with 5 additions and 2 deletions
|
|
@ -46,13 +46,16 @@ export const runWithdraw = profiler.registerFN(
|
||||||
const capacity = creep.store.getFreeCapacity(opts.resource);
|
const capacity = creep.store.getFreeCapacity(opts.resource);
|
||||||
const amount = Math.min(opts.amount ?? capacity,
|
const amount = Math.min(opts.amount ?? capacity,
|
||||||
opts.limit ?? capacity - creep.store.getUsedCapacity(opts.resource));
|
opts.limit ?? capacity - creep.store.getUsedCapacity(opts.resource));
|
||||||
|
const amountS = target != null && "store" in target
|
||||||
|
? target.store.getUsedCapacity(opts.resource)
|
||||||
|
: amount;
|
||||||
|
|
||||||
if (amount <= 0) {
|
if (amount <= 0) {
|
||||||
return TaskStatus.DONE;
|
return TaskStatus.DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target == null
|
if (target == null
|
||||||
|| creep.withdraw(target, opts.resource, amount) === ERR_NOT_IN_RANGE) {
|
|| creep.withdraw(target, opts.resource, amountS) === ERR_NOT_IN_RANGE) {
|
||||||
creep.travelTo(task.targetPos);
|
creep.travelTo(task.targetPos);
|
||||||
return TaskStatus.IN_PROGRESS;
|
return TaskStatus.IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import "../deps/Traveler/Traveler.js";
|
import "../deps/Traveler/Traveler.ts";
|
||||||
import "../deps/Traveler/index.d.ts";
|
import "../deps/Traveler/index.d.ts";
|
||||||
import "./Proto";
|
import "./Proto";
|
||||||
import profiler from "screeps-profiler";
|
import profiler from "screeps-profiler";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue