old source files of 2018-2020.

This commit is contained in:
Douwe Ravers
2022-04-15 14:29:07 +02:00
parent 0985358150
commit 85215ebd97
20 changed files with 676 additions and 795 deletions

43
job_upgrader.js Normal file
View File

@@ -0,0 +1,43 @@
/* #######################################################
# Deliver energy to spawns, controller and extencions #
####################################################### */
module.exports = {
do: function(creep){
// Memory creation
if(creep.memory.restock == undefined) creep.memory.restock = true;
if(creep.memory.target == undefined) creep.memory.target = null;
// Job implementation
if(creep.memory.restock){
if(creep.memory.target == null){
if(creep.room.storage != null && 1000 < creep.room.storage.store.getUsedCapacity(RESOURCE_ENERGY)) creep.memory.target = creep.room.storage.id;
else {
var container = creep.pos.findClosestByPath(FIND_STRUCTURES,
{filter: (s)=>(s.structureType == STRUCTURE_CONTAINER
&& 0 < s.store.getUsedCapacity(RESOURCE_ENERGY))});
if(container != null) creep.memory.target = container.id;
}
}
var target = Game.getObjectById(creep.memory.target);
if(creep.withdraw(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) creep.moveTo(target);
if(target != null && target.store.getUsedCapacity(RESOURCE_ENERGY) < creep.store.getFreeCapacity(RESOURCE_ENERGY)*0.4) creep.memory.target = null;
if(creep.store.getFreeCapacity(RESOURCE_ENERGY) == 0){
creep.memory.restock = false;
creep.memory.target = null;
}
} else {
if(creep.memory.target == null){ // aquire target
var structure = structure = creep.room.controller;
creep.memory.target = structure.id;
}
var target = Game.getObjectById(creep.memory.target);
if(creep.transfer(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) creep.moveTo(target);
if(creep.store.getUsedCapacity(RESOURCE_ENERGY) == 0){
creep.memory.restock = true;
creep.memory.target = null;
}
}
}
};