|
|
|
const common = require('common')
|
|
|
|
let idling = 0
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
idling,
|
|
|
|
name: 'upgrader',
|
|
|
|
prio: 6,
|
|
|
|
getCount: colonyRoom => {
|
|
|
|
let cc = Game.getObjectById(colonyRoom.memory.controllerContainer)
|
|
|
|
if(colonyRoom.storage) {
|
|
|
|
return Math.ceil(colonyRoom.storage.store[RESOURCE_ENERGY] / 100000)
|
|
|
|
}
|
|
|
|
else if (colonyRoom.controller.level + cc.store) {
|
|
|
|
return Math.ceil(cc.store[RESOURCE_ENERGY] / 500)
|
|
|
|
}
|
|
|
|
return colonyRoom.controller.level
|
|
|
|
},
|
|
|
|
maxExpands: 4,
|
|
|
|
baseBody: [WORK, CARRY, MOVE],
|
|
|
|
expandBody: [WORK, WORK, MOVE],
|
|
|
|
tick (creep) {
|
|
|
|
if (creep.store.getFreeCapacity(RESOURCE_ENERGY) > 0) {
|
|
|
|
let dropped = creep.pos.findInRange(FIND_DROPPED_RESOURCES, 1);
|
|
|
|
if (dropped.length > 0) {
|
|
|
|
creep.pickup(dropped[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
let target
|
|
|
|
let targets = creep.pos.findInRange(FIND_TOMBSTONES, 1, {
|
|
|
|
filter: t => t.store[RESOURCE_ENERGY] > 0
|
|
|
|
})
|
|
|
|
if (targets.length) {
|
|
|
|
target = targets[0]
|
|
|
|
}
|
|
|
|
if (!target) {
|
|
|
|
targets = creep.pos.findInRange(FIND_STRUCTURES, 1, {
|
|
|
|
filter: s => s.store && s.store[RESOURCE_ENERGY] > 0
|
|
|
|
})
|
|
|
|
if (targets.length) {
|
|
|
|
target = targets[0]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!target && creep.store[RESOURCE_ENERGY] === 0) {
|
|
|
|
target = creep.room.controller.pos.findClosestByRange(FIND_STRUCTURES, {
|
|
|
|
filter: s => s.store && s.store.getCapacity(RESOURCE_ENERGY) > 0
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (target) {
|
|
|
|
if (creep.withdraw(target, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
|
|
|
|
creep.moveTo(target)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (creep.pos.getRangeTo(creep.room.controller) > 3) {
|
|
|
|
creep.moveTo(creep.room.controller, {visualizePathStyle: {stroke: '#ffffff'}})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let actionResult = creep.upgradeController(creep.room.controller)
|
|
|
|
if (actionResult === OK) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'idle'
|
|
|
|
}
|
|
|
|
};
|