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.
58 lines
2.1 KiB
58 lines
2.1 KiB
const common = require('common')
|
|
|
|
module.exports = {
|
|
name: 'filler',
|
|
prio: 4,
|
|
count: 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] === 0) {
|
|
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'}});
|
|
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 = creep.room.storage.pos.findClosestByRange(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_LINK})
|
|
}
|
|
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'}});
|
|
return 'idle'
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|