mirror of
https://github.com/paradizelost/screeps.git
synced 2024-11-25 02:14:44 -06:00
93 lines
5.0 KiB
JavaScript
93 lines
5.0 KiB
JavaScript
//'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
|
|
}
|
|
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}
|
|
|
|
let road = creep.pos.lookFor(LOOK_STRUCTURES);
|
|
let filllevel = _.sum(creep.carry)
|
|
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){
|
|
let look=creep.pos.lookFor(LOOK_STRUCTURES)
|
|
let storagetargets = creep.pos.findClosestByRange(FIND_STRUCTURES, {filter: (s) => {return ((s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_TERMINAL ) && _.sum(s.store) < s.storeCapacity) ;}});
|
|
if(creep.room.memory.NeedsRecharge==1){
|
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
|
creep.say('!MTRC!')
|
|
creep.say(creep.room.controller.ticksToDowngrade)
|
|
creep.moveTo(creep.room.controller)
|
|
}
|
|
} else 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})
|
|
}
|
|
} 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.pos.findClosestByRange(FIND_CONSTRUCTION_SITES)){
|
|
target = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES)
|
|
if(creep.build(target) == ERR_NOT_IN_RANGE) {
|
|
if (road.length > 0) {creep.repair(road);}
|
|
creep.moveTo(target,{ignoreCreeps:ignorecreeps})
|
|
}
|
|
} else if(storagetargets){
|
|
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.memory.assignedroom=creep.room.name
|
|
creep.moveTo(Game.rooms[creep.memory.assignedroom].controller,{ignoreCreeps:ignorecreeps})
|
|
}
|
|
}
|
|
} else {
|
|
let droppedenergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES, {filter: (r) =>{return ( r.resourceType==RESOURCE_ENERGY&& r.amount>200)}});
|
|
if(droppedenergy == undefined){
|
|
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
|
|
let mysource=Game.getObjectById(creep.memory.destsource.id)
|
|
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE){
|
|
creep.moveTo(mysource,{ignoreCreeps:ignorecreeps})
|
|
}
|
|
} else {
|
|
if(creep.pickup(droppedenergy) == ERR_NOT_IN_RANGE) {
|
|
if(global.verbosity>0){
|
|
creep.say("MTDE");
|
|
}
|
|
|
|
creep.moveTo(droppedenergy,{ignoreCreeps:ignorecreeps})
|
|
|
|
}
|
|
}
|
|
}
|
|
creep.memory.lastpos=creep.pos
|
|
}
|
|
};
|
|
module.exports = Phase1Worker;
|