Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | 2x 4x 4x 4x 4x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x | const roleTransporter = {
run: function (creep) {
creep.say('🚚');
Iif (creep.memory.transporting && creep.store[RESOURCE_ENERGY] === 0) {
creep.memory.transporting = false;
}
Iif (!creep.memory.transporting && creep.store.getFreeCapacity() === 0) {
creep.memory.transporting = true;
}
if (creep.memory.transporting) {
// âš¡ PERFORMANCE: Per-tick caching of energy delivery targets
Eif (creep.room._deliveryTargetsTick !== Game.time) {
creep.room._deliveryTargets = creep.room.find(FIND_STRUCTURES, {
filter: (s) =>
(s.structureType === STRUCTURE_SPAWN ||
s.structureType === STRUCTURE_EXTENSION ||
s.structureType === STRUCTURE_TOWER ||
s.structureType === STRUCTURE_LAB) &&
s.store.getFreeCapacity(RESOURCE_ENERGY) > 0,
});
creep.room._deliveryTargetsTick = Game.time;
}
const targets = creep.room._deliveryTargets;
Eif (targets.length > 0) {
const closest = creep.pos.findClosestByRange(targets);
Iif (creep.transfer(closest, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(closest, { visualizePathStyle: { stroke: '#00ffff' } });
}
}
} else {
// âš¡ PERFORMANCE: Per-tick caching of withdrawal containers
Eif (creep.room._withdrawalContainersTick !== Game.time) {
creep.room._withdrawalContainers = creep.room.find(FIND_STRUCTURES, {
filter: (s) =>
s.structureType === STRUCTURE_CONTAINER && s.store[RESOURCE_ENERGY] > 0,
});
creep.room._withdrawalContainersTick = Game.time;
}
const containers = creep.room._withdrawalContainers;
const storage = creep.room.storage;
const sources = [];
Iif (storage && storage.store[RESOURCE_ENERGY] > 1000) {
sources.push(storage);
}
sources.push(...containers);
Iif (sources.length > 0) {
const closest = creep.pos.findClosestByRange(sources);
if (creep.withdraw(closest, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(closest, { visualizePathStyle: { stroke: '#ffff00' } });
}
}
}
},
};
module.exports = roleTransporter;
|