Created supplier and builder functions
This commit is contained in:
@@ -3,6 +3,26 @@ module.exports = {
|
||||
},
|
||||
|
||||
tick(creep){
|
||||
|
||||
if(!creep.pos.isNearTo(creep.room.controller)) { creep.moveTo(creep.room.controller); return; }
|
||||
if(creep.store.getUsedCapacity(RESOURCE_ENERGY) == 0) { getOrWaitForEnergy(creep); return; }
|
||||
creep.upgradeController(creep.room.controller);
|
||||
}
|
||||
}
|
||||
|
||||
function getOrWaitForEnergy(creep){
|
||||
if(!creep.memory.container) scanForContainer(creep);
|
||||
if(creep.memory.container) getEnergyFromContainer(creep);
|
||||
}
|
||||
|
||||
function getEnergyFromContainer(creep){
|
||||
const container = Game.getObjectById(creep.memory.container);
|
||||
if(creep.withdraw(container, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) creep.moveTo(container);
|
||||
}
|
||||
|
||||
// duplicate see miner
|
||||
function scanForContainer(creep){
|
||||
const container = creep.room.controller.pos.findInRange(FIND_STRUCTURES, 1, {
|
||||
filter:{structureType:STRUCTURE_CONTAINER}
|
||||
})[0];
|
||||
if(container) creep.memory.container = container.id;
|
||||
}
|
||||
Reference in New Issue
Block a user