@@ 8,17 8,17 @@ const roles = {
args: [RESOURCE_ENERGY]
}
}),
- needed: room => active("worker") < room.controller.level + 1,
+ needed: room => active("worker") < room.controller.level,
run: creep => {
switch (creep.memory.method) {
case "withdraw":
case "pickup":
case "harvest":
if (creep.store.getFreeCapacity(RESOURCE_ENERGY) === 0) {
- const transfer = creep.pos.findClosestByRange(FIND_MY_STRUCTURES, {
- filter: structure => [STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER].some(type => structure.structureType === type)
- && structure.store.getFreeCapacity(RESOURCE_ENERGY) !== 0
+ const transfer = creep.pos.findClosestByRange(FIND_STRUCTURES, {
+ filter: structure => [STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER].some(type => structure.structureType === type && structure.store.getFreeCapacity(RESOURCE_ENERGY) !== 0)
})
+ console.log(transfer)
const build = !transfer && creep.pos.findClosestByRange(FIND_MY_CONSTRUCTION_SITES)
return creep.memory = {
method: transfer ? "transfer" : build ? "build" : "upgradeController",
@@ 31,15 31,14 @@ const roles = {
})
const pickup = !withdraw && creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES)
return creep.memory = {
- method: withdraw ? "withdraw" : pickup && pickup.amount > creep.store.getFreeCapacity(RESOURCE_ENERGY) ? "pickup" : "harvest",
- target: withdraw && withdraw.id || pickup && pickup.amount > creep.store.getFreeCapacity(RESOURCE_ENERGY) && pickup.id || creep.pos.findClosestByRange(FIND_SOURCES).id,
+ method: withdraw && withdraw.store.getUsedCapacity(RESOURCE_ENERGY) > creep.store.getFreeCapacity(RESOURCE_ENERGY) ? "withdraw" : pickup && pickup.amount > creep.store.getFreeCapacity(RESOURCE_ENERGY) ? "pickup" : "harvest",
+ target: withdraw && withdraw.store.getUsedCapacity(RESOURCE_ENERGY) > creep.store.getFreeCapacity(RESOURCE_ENERGY) && withdraw.id || pickup && pickup.amount > creep.store.getFreeCapacity(RESOURCE_ENERGY) && pickup.id || creep.pos.findClosestByRange(FIND_SOURCES).id,
args: withdraw ? [RESOURCE_ENERGY] : []
}
}
case "transfer":
- if (!creep.pos.findClosestByRange(FIND_MY_STRUCTURES, {
- filter: structure => [STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER].some(type => structure.structureType === type)
- && structure.store.getFreeCapacity(RESOURCE_ENERGY) !== 0
+ if (!creep.pos.findClosestByRange(FIND_STRUCTURES, {
+ filter: structure => [STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER].some(type => structure.structureType === type && structure.store.getFreeCapacity(RESOURCE_ENERGY) !== 0)
})) {
const build = creep.pos.findClosestByRange(FIND_MY_CONSTRUCTION_SITES)
return creep.memory = {
@@ 50,10 49,10 @@ const roles = {
}
case "build":
if (creep.store.getUsedCapacity(RESOURCE_ENERGY) === 0) {
- const withdraw = creep.pos.findClosestByRange(FIND_STRUCTURES, {
+ const pickup = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES)
+ const withdraw = !pickup && creep.pos.findClosestByRange(FIND_STRUCTURES, {
filter: structure => [STRUCTURE_CONTAINER, STRUCTURE_STORAGE].some(type => structure.structureType === type)
})
- const pickup = !withdraw && creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES)
return creep.memory = {
method: withdraw ? "withdraw" : pickup && pickup.amount > creep.store.getFreeCapacity(RESOURCE_ENERGY) ? "pickup" : "harvest",
target: withdraw && withdraw.id || pickup && pickup.id || creep.pos.findClosestByRange(FIND_SOURCES).id,
@@ 61,7 60,7 @@ const roles = {
}
} else {
const build = creep.pos.findClosestByRange(FIND_MY_CONSTRUCTION_SITES)
- creep.memory = {
+ return creep.memory = {
method: build ? "build" : "upgradeController",
target: build && build.id || creep.room.controller.id,
args: []