2020-11-09 19:31:39 -06:00
|
|
|
let mover={
|
|
|
|
run: function(creep) {
|
|
|
|
let ignorecreeps=true
|
|
|
|
if(creep.memory.lastpos==undefined || creep.memory.timeatpos==undefined){
|
|
|
|
creep.memory.lastpos = creep.pos
|
|
|
|
creep.memory.timeatpos = 0
|
|
|
|
}
|
2020-11-14 01:18:05 -06:00
|
|
|
if(creep.memory.working==undefined){
|
|
|
|
creep.memory.working=false
|
|
|
|
}
|
2020-11-09 19:31:39 -06:00
|
|
|
let lastpos = _.create(RoomPosition.prototype, creep.memory.lastpos)
|
|
|
|
if(creep.pos.isEqualTo(lastpos)){
|
|
|
|
creep.memory.timeatpos = creep.memory.timeatpos+1
|
|
|
|
if(creep.memory.timeatpos>2){
|
|
|
|
//console.log(creep.name + " " + creep.memory.timeatpos)
|
|
|
|
ignorecreeps=false
|
|
|
|
} else { }
|
|
|
|
} else { creep.memory.timeatpos=0}
|
|
|
|
let filllevel = _.sum(creep.carry)
|
|
|
|
if(creep.memory.working && filllevel == 0) {
|
|
|
|
creep.memory.working = false;
|
|
|
|
creep.say('Gathering');
|
|
|
|
}
|
|
|
|
if(!creep.memory.working && filllevel == creep.carryCapacity) {
|
|
|
|
creep.memory.working = true;
|
|
|
|
creep.say('working');
|
|
|
|
}
|
|
|
|
if(creep.memory.working){
|
|
|
|
let terminaltarget = creep.room.terminal
|
2020-11-14 01:18:05 -06:00
|
|
|
if(creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER].includes(s.structureType)) && s.energy < s.energyCapacity))}})){
|
|
|
|
let spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return (((s.structureType == STRUCTURE_EXTENSION || s.structureType == STRUCTURE_SPAWN || s.structureType == STRUCTURE_TOWER) && s.energy < s.energyCapacity))}});
|
|
|
|
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.moveTo(spawntarget,{ignoreCreeps:ignorecreeps})
|
2020-11-09 19:31:39 -06:00
|
|
|
}
|
2020-11-14 01:18:05 -06:00
|
|
|
}else if(creep.transfer(terminaltarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
|
|
|
|
creep.say('Putting Energy')
|
|
|
|
creep.travelTo(terminaltarget);
|
|
|
|
}
|
2020-11-09 19:31:39 -06:00
|
|
|
} else {
|
|
|
|
if(filllevel < creep.carryCapacity){
|
2020-11-14 01:18:05 -06:00
|
|
|
let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER ) && _.sum(s.store) >= 500) ;}});
|
2020-11-09 19:31:39 -06:00
|
|
|
if(creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE) {
|
|
|
|
creep.say('Getting Energy')
|
|
|
|
creep.travelTo(storagetarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
creep.memory.lastpos=creep.pos
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = mover;
|