old source files of 2018-2020.
This commit is contained in:
57
job_builder.js
Normal file
57
job_builder.js
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
/* #######################################################
|
||||
# Deliver energy to spawns, controller and extencions #
|
||||
####################################################### */
|
||||
|
||||
module.exports = {
|
||||
do: function(creep){
|
||||
//creep.memory.target = null;
|
||||
|
||||
// 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
|
||||
// constuction
|
||||
var structure = creep.pos.findClosestByRange(FIND_MY_CONSTRUCTION_SITES);
|
||||
|
||||
// ramparts
|
||||
if(structure == null){
|
||||
var ramparts = creep.room.find(FIND_STRUCTURES,
|
||||
{filter: (s)=>((s.structureType == STRUCTURE_RAMPART || s.structureType == STRUCTURE_WALL) && s.hits < s.hitsMax)});
|
||||
for(var ramp in ramparts){
|
||||
ramp = ramparts[ramp];
|
||||
if(structure == null || structure.hits > ramp.hits) structure = ramp;
|
||||
}
|
||||
}
|
||||
creep.memory.target = structure.id;
|
||||
}
|
||||
var target = Game.getObjectById(creep.memory.target);
|
||||
if(target == null || target.hits == target.hitsMax) creep.memory.target = null;
|
||||
if(creep.build(target) == ERR_NOT_IN_RANGE || creep.repair(target) == ERR_NOT_IN_RANGE) creep.moveTo(target);
|
||||
if(creep.store.getUsedCapacity(RESOURCE_ENERGY) == 0){
|
||||
creep.memory.restock = true;
|
||||
creep.memory.target = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user