You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
screeps/default/role.filler.js

76 lines
2.6 KiB

const common = require('common')
module.exports = {
name: 'filler',
prio: 4,
getCount: colonyRoom => {
if (colonyRoom.memory.spawnContainers.length === 0) {
return 0
}
if (colonyRoom.controller.level < 5) {
return 1
}
return 2
},
minRcl: 2,
bodies: [
[CARRY, CARRY, MOVE],
[CARRY, CARRY, MOVE, CARRY, CARRY, MOVE],
[CARRY, CARRY, MOVE, CARRY, CARRY, MOVE, CARRY, CARRY, MOVE],
[CARRY, CARRY, MOVE, CARRY, CARRY, MOVE, CARRY, CARRY, MOVE, CARRY, CARRY, MOVE],
],
tick (creep) {
if (creep.store.getFreeCapacity(RESOURCE_ENERGY) === 0) {
creep.memory.loading = false
}
else if (creep.store[RESOURCE_ENERGY] < 50) {
creep.memory.loading = true
}
if (creep.memory.loading) {
let target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: s => {
return (s.structureType === STRUCTURE_STORAGE || s.structureType === STRUCTURE_CONTAINER)
&& s.store[RESOURCE_ENERGY] > Math.min(creep.store.getFreeCapacity(RESOURCE_ENERGY), 100)
}
})
if (target) {
if (creep.withdraw(target, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#f7e180'}})
}
} else {
// creep.moveTo(creep.pos.findClosestByRange(FIND_FLAGS, {filter: flag => flag.name.startsWith('idle')}), {visualizePathStyle: {stroke: '#ff0000'}});
if (creep.store[RESOURCE_ENERGY] > 0) {
creep.memory.loading = false
}
return 'idle'
}
}
else {
let target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: s => (
s.structureType === STRUCTURE_EXTENSION
|| s.structureType === STRUCTURE_SPAWN
)
&& s.store.getFreeCapacity(RESOURCE_ENERGY) > 0
})
if (!target && creep.room.storage && creep.room.storage.store[RESOURCE_ENERGY] > 1e5) {
target = Game.getObjectById(creep.room.memory.storageLink)
if (target && target.store.getFreeCapacity(RESOURCE_ENERGY) === 0 && creep.pos.getRangeTo(target) === 1) {
target = undefined
}
}
if (target) {
if (creep.transfer(target, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#00ff0f'}});
}
} else {
// creep.moveTo(creep.pos.findClosestByRange(FIND_FLAGS, {filter: flag => flag.name.startsWith('idle')}), {visualizePathStyle: {stroke: '#ff0000'}});
if (creep.store.getFreeCapacity(RESOURCE_ENERGY) > 0) {
creep.memory.loading = true
}
return 'idle'
}
}
}
};