screeps/role.phase0worker.js

77 lines
3.6 KiB
JavaScript
Raw Normal View History

2020-11-09 19:31:39 -06:00
//'use strict';
let Phase0Worker = {
run: function(creep) {
2022-05-09 17:03:22 -05:00
let ignorecreeps=true
if(creep.memory.lastpos==undefined || creep.memory.timeatpos==undefined){
creep.memory.lastpos = creep.pos
creep.memory.timeatpos = 0
}
if(creep.memory.assignedroom==undefined){
creep.memory.assignedroom=creep.room.name
}
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}
2020-11-09 19:31:39 -06:00
let filllevel = _.sum(creep.carry)
2020-11-10 01:29:27 -06:00
//creep.say(creep.room.memory.maphits[creep.pos.x + '-' + creep.pos.y].hits)
2020-11-09 19:31:39 -06:00
if(creep.memory.working && filllevel == 0) {
creep.memory.working = false;
creep.say('Gathering');
}
if(!creep.memory.working && creep.carry.energy == creep.carryCapacity) {
creep.memory.working = true;
creep.say('working');
}
if(creep.memory.working){
if(creep.room.controller.ticksToDowngrade<3100){
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.say('!MTRC!')
creep.travelTo(creep.room.controller);
}
} else if(creep.room.energyAvailable < creep.room.energyCapacityAvailable ){
let spawntarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {filter: (structure) => {return (((structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity))}});
if(creep.transfer(spawntarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.travelTo(spawntarget);
}
} else {
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.say('MTRC')
creep.travelTo(creep.room.controller);
}
}
} else {
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: {resourceType: RESOURCE_ENERGY}});
2022-05-09 17:03:22 -05:00
let ruins=creep.pos.findClosestByRange(FIND_RUINS, {filter: ruin => ruin.store.getUsedCapacity(RESOURCE_ENERGY) > 0});
if(droppedenergy == undefined && ruins==undefined){
2020-11-09 19:31:39 -06:00
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
let mysource=Game.getObjectById(creep.memory.destsource.id)
//mysource=creep.pos.findClosestByRange( FIND_SOURCES )
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
creep.travelTo(mysource);
}
} else {
2022-05-09 17:03:22 -05:00
if(droppedenergy){
2020-11-09 19:31:39 -06:00
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
creep.say("MTDE");
}
creep.travelTo(droppedenergy);
2022-05-09 17:03:22 -05:00
} } else {
if(creep.withdraw(ruins,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
if(global.verbosity>0){
creep.say("MTRU");
}
creep.moveTo(ruins,{ignoreCreeps:ignorecreeps})
}
}
2020-11-09 19:31:39 -06:00
}
}
}
};
module.exports = Phase0Worker;