2020-11-09 19:31:39 -06:00
|
|
|
//'use strict';
|
|
|
|
let Phase1Worker = {
|
|
|
|
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-10 01:29:27 -06:00
|
|
|
if(creep.memory.assignedroom==undefined){
|
|
|
|
creep.memory.assignedroom=creep.room.name
|
|
|
|
}
|
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 road = creep.pos.lookFor(LOOK_STRUCTURES);
|
|
|
|
let filllevel = _.sum(creep.carry)
|
2022-05-23 15:59:00 -05:00
|
|
|
if(creep.room.name == creep.memory.assignedroom){
|
|
|
|
if(creep.memory.working && filllevel == 0) {
|
|
|
|
creep.memory.working = false;
|
|
|
|
creep.say('Gathering');
|
2020-11-09 19:31:39 -06:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
if(!creep.memory.working && creep.carry.energy == creep.carryCapacity) {
|
|
|
|
creep.memory.working = true;
|
|
|
|
creep.say('working');
|
2020-11-17 10:30:13 -06:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
if(creep.memory.working){
|
|
|
|
let look=creep.pos.lookFor(LOOK_STRUCTURES)
|
|
|
|
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL ) && _.sum(s.store) < s.store.getCapacity()) ;}});
|
|
|
|
if(creep.room.memory.NeedsRecharge==1){
|
2022-05-06 16:48:12 -05:00
|
|
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
2022-05-23 15:59:00 -05:00
|
|
|
creep.say(creep.room.controller.ticksToDowngrade + " of " + CONTROLLER_DOWNGRADE[creep.room.controller.level] * .2)
|
|
|
|
creep.moveTo(creep.room.controller)
|
|
|
|
}
|
|
|
|
} else if((creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_SPAWN, STRUCTURE_EXTENSION, STRUCTURE_TOWER,STRUCTURE_LINK].includes(s.structureType)) && s.energy < s.energyCapacity))}}))&& (creep.room.memory.movercount<1||creep.room.memory.movercount==undefined)){
|
|
|
|
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})
|
|
|
|
}
|
|
|
|
} else if(creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ((([STRUCTURE_RAMPART].includes(s.structureType)) && s.hits < 20000))}})){
|
|
|
|
let ramparttarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return (((s.structureType == STRUCTURE_RAMPART) && s.hits < s.hitsMax))}});
|
|
|
|
if(creep.repair(ramparttarget) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.moveTo(ramparttarget,{ignoreCreeps:ignorecreeps})
|
|
|
|
}
|
|
|
|
} else if(creep.room.memory.currentconstruction){
|
|
|
|
target = Game.getObjectById(creep.room.memory.currentconstruction.id)
|
|
|
|
creep.moveTo(target,{ignoreCreeps:ignorecreeps})
|
|
|
|
if(creep.build(target) == ERR_NOT_IN_RANGE) {
|
|
|
|
if (road.length > 0) {creep.repair(road);}
|
|
|
|
creep.moveTo(target,{ignoreCreeps:ignorecreeps})
|
|
|
|
}
|
|
|
|
} else if(storagetargets && creep.room.storage&& creep.room.controller.level*125000> creep.room.storage.store.getUsedCapacity('energy')){
|
|
|
|
if(creep.transfer(storagetargets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
|
|
if (road.length > 0) {creep.repair(road);}
|
|
|
|
creep.moveTo(storagetargets,{ignoreCreeps:ignorecreeps})
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.say('MTRC')
|
|
|
|
if (road.length > 0) {creep.repair(road);}
|
|
|
|
creep.moveTo(Game.rooms[creep.memory.assignedroom].controller,{ignoreCreeps:ignorecreeps})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (creep.pos.findClosestByRange(FIND_MY_SPAWNS) && (creep.ticksToLive < 300 || creep.ticksToLive <= creep.memory.renewto) && (Game.rooms[creep.room.name].find(FIND_MY_SPAWNS, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}})) ) {
|
|
|
|
if(creep.memory.renewto == undefined){
|
|
|
|
creep.memory.renewto = 1200
|
|
|
|
} else {
|
|
|
|
if(creep.ticksToLive >= creep.memory.renewto){
|
|
|
|
delete creep.memory.renewto
|
|
|
|
}
|
|
|
|
}
|
|
|
|
creep.say('renewing')
|
|
|
|
console.log(creep.name + ": " + creep.ticksToLive + " " + creep.memory.renewto)
|
|
|
|
let spawn = creep.pos.findClosestByRange(FIND_MY_SPAWNS)
|
|
|
|
if(spawn != undefined && spawn!= null){
|
|
|
|
if(creep.room.memory.NeedsRecharge==1 && creep.carry.energy>0){
|
|
|
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
|
|
|
creep.say(creep.room.controller.ticksToDowngrade + " of " + (CONTROLLER_DOWNGRADE[creep.room.controller.level] * .2))
|
|
|
|
creep.moveTo(creep.room.controller)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
creep.transfer(spawn, RESOURCE_ENERGY)
|
|
|
|
if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE){
|
|
|
|
creep.say('MVSP')
|
|
|
|
creep.moveTo(spawn);
|
|
|
|
}
|
2022-05-06 16:48:12 -05:00
|
|
|
}
|
|
|
|
} else {
|
2022-05-23 15:59:00 -05:00
|
|
|
creep.memory.renewto=1
|
2022-05-06 16:48:12 -05:00
|
|
|
}
|
2020-11-30 03:41:26 -06:00
|
|
|
} else {
|
2022-05-23 15:59:00 -05:00
|
|
|
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>200)}});
|
|
|
|
let tombstone = creep.pos.findClosestByRange(FIND_TOMBSTONES, {filter: (r) =>{return ( r.store[RESOURCE_ENERGY]>200)}});
|
|
|
|
let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0});
|
|
|
|
let spawn= creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => {return ( s.structureType == STRUCTURE_SPAWN)}});
|
|
|
|
//console.log(tombstone)
|
|
|
|
if((droppedenergy == undefined || droppedenergy==null) && (tombstone==undefined || tombstone==null) && (spawn!=undefined || spawn!=null) && (ruins==undefined || ruins==null)){
|
|
|
|
creep.say("1")
|
|
|
|
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
|
|
|
let mysource=Game.getObjectById(creep.memory.destsource.id)
|
|
|
|
try{
|
|
|
|
//console.log(creep.room.memory.creepcounts)
|
|
|
|
if((mysource.energy==0 || ((creep.room.memory.creepcounts.sourceminer!=null ||creep.room.memory.creepcounts.sourceminer!=undefined )))){
|
|
|
|
creep.say("2.1")
|
|
|
|
//creep.say("No Energy Left to get")
|
|
|
|
let storagetarget = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_LINK) && s.store.getUsedCapacity('energy') >= 100) ;}});
|
|
|
|
if(storagetarget===undefined || storagetarget==null){
|
|
|
|
creep.say('2.2')
|
|
|
|
storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE) && s.store.getUsedCapacity('energy') >= creep.room.controller.level * 125000) ;}});
|
|
|
|
if((storagetarget===undefined || storagetarget==null) && creep.room.terminal && creep.room.terminal.store.getUsedCapacity('energy') > 100000){
|
|
|
|
creep.say('2.3')
|
|
|
|
storagetarget=creep.room.terminal
|
|
|
|
}
|
2022-05-04 08:30:12 -05:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
//console.log(Game.getObjectById(storagetarget.id))
|
|
|
|
if((storagetarget != undefined || storagetarget != null)){
|
|
|
|
if( creep.withdraw(storagetarget,RESOURCE_ENERGY)== ERR_NOT_IN_RANGE){
|
|
|
|
creep.say('3')
|
|
|
|
//creep.say('Getting Energy')
|
|
|
|
creep.travelTo(storagetarget);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
|
|
|
|
creep.moveTo(mysource,{ignoreCreeps:ignorecreeps})
|
|
|
|
}
|
|
|
|
creep.say("NSE-Ming")
|
2022-05-16 13:27:01 -05:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
}else {
|
2022-05-06 16:48:12 -05:00
|
|
|
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
|
|
|
|
creep.moveTo(mysource,{ignoreCreeps:ignorecreeps})
|
|
|
|
}
|
2020-11-14 01:18:05 -06:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
} catch(e){
|
|
|
|
console.log(e)
|
2020-11-14 01:18:05 -06:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
} else {
|
|
|
|
if(droppedenergy){
|
|
|
|
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
|
|
|
|
if(global.verbosity>0){
|
|
|
|
creep.say("MTDE");
|
|
|
|
}
|
|
|
|
creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps})
|
2020-11-14 01:18:05 -06:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
} else if (tombstone) {
|
|
|
|
if(creep.withdraw(tombstone,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
|
|
if(global.verbosity>0){
|
|
|
|
creep.say("MTTS");
|
|
|
|
}
|
|
|
|
creep.moveTo(tombstone.pos,{ignoreCreeps:ignorecreeps})
|
2022-05-16 13:27:01 -05:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
} else if (ruins){
|
|
|
|
if(creep.withdraw(ruins,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
2022-05-16 13:27:01 -05:00
|
|
|
if(global.verbosity>0){
|
|
|
|
creep.say("MTTS");
|
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
creep.moveTo(ruins,{ignoreCreeps:ignorecreeps})
|
2022-05-16 13:27:01 -05:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
} else if(spawn==null || spawn==undefined){
|
|
|
|
storagetarget=creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE)) ;}});
|
|
|
|
if(storagetarget){
|
|
|
|
if(creep.withdraw(storagetarget,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
|
|
|
if(global.verbosity>0){
|
|
|
|
creep.say("MTTS");
|
|
|
|
}
|
|
|
|
creep.moveTo(storagetarget,{ignoreCreeps:ignorecreeps})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
let mysource=Game.getObjectById(creep.memory.destsource.id)
|
|
|
|
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
|
|
|
|
creep.moveTo(mysource,{ignoreCreeps:ignorecreeps})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
creep.say("IDK")
|
2022-05-16 13:27:01 -05:00
|
|
|
}
|
2020-11-14 01:18:05 -06:00
|
|
|
}
|
2020-11-09 19:31:39 -06:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
creep.memory.lastpos=creep.pos
|
|
|
|
} else {
|
|
|
|
creep.moveTo(Game.rooms[creep.memory.assignedroom].controller)
|
2020-11-09 19:31:39 -06:00
|
|
|
}
|
2022-05-23 15:59:00 -05:00
|
|
|
}
|
2020-11-09 19:31:39 -06:00
|
|
|
};
|
|
|
|
module.exports = Phase1Worker;
|