module.exports = { tickInit () { for (let room of Object.values(Game.rooms)) { if (room.memory.controllerLink && !Game.getObjectById(room.memory.controllerLink)) { delete room.memory.controllerLink } if (room.memory.storageLink && !Game.getObjectById(room.memory.storageLink)) { delete room.memory.storageLink } if (!room.controller.my) { continue } if (!room.memory.controllerLink) { let links = room.controller.pos.findInRange(FIND_STRUCTURES, 5, {filter: s => s.structureType === STRUCTURE_LINK}) if (links.length) { room.memory.controllerLink = links[0].id return } } if (!room.memory.storageLink && room.storage) { let links = room.storage.pos.findInRange(FIND_STRUCTURES, 2, {filter: s => s.structureType === STRUCTURE_LINK}) if (links.length) { room.memory.storageLink = links[0].id return } } } }, tick (link) { if (link.room.memory.controllerLink === link.id) { return } if (link.room.memory.controllerLink && !link.store.getFreeCapacity(RESOURCE_ENERGY)) { let targetLink = Game.getObjectById(link.room.memory.controllerLink) if (targetLink.store.getFreeCapacity(RESOURCE_ENERGY) > 770) { link.transferEnergy(targetLink) } } } }