Created supplier and builder functions

This commit is contained in:
unknown
2023-08-29 20:43:10 +02:00
parent 523a2e0005
commit 112c3c3a97
8 changed files with 239 additions and 30 deletions

View File

@@ -2,9 +2,9 @@ module.exports = {
setup: function () { Room.prototype = _Room.prototype; }
}
class _Room extends Room {
class _Room extends Room {
begin(){
roomScan(this);
roomLayoutScan(this);
jobScan(this);
vacancyScan(this);
this.memory.init = true;
@@ -12,33 +12,33 @@ class _Room extends Room {
tick(){
if(!this.memory.init) this.begin();
if(Game.time%100 === 1) vacancyScan(this);
if(!(Game.time%100)) {
vacancyScan(this);
}
}
}
function roomScan(room){
room.memory.layout = {
sources: room.find(FIND_SOURCES).map(s=>s.id)
};
function roomLayoutScan(room){
if(!room.memory.layout) room.memory.layout = {};
if(!room.memory.layout.sources) room.memory.layout.sources = room.find(FIND_SOURCES).map(s=>s.id);
room.memory.layout.containers = room.find(FIND_MY_STRUCTURES, {filter:{structureType:STRUCTURE_CONTAINER}}).map(c=>c.id);
}
function jobScan(room){
if(!room.memory.jobs) room.memory.jobs = Array(10).fill({role: Role.HARVESTER})
if(!room.memory.jobs) room.memory.jobs = [{role:Role.UPGRADER}]
.concat(Array(2).fill({role: Role.BUILDER}))
.concat(Array(5).fill({role: Role.SUPPLIER}))
.concat(room.memory.layout.sources.map(s=> {return {role: Role.MINER, source: s}}));
}
function vacancyScan(room){
const activeJobs = room.find(FIND_MY_CREEPS).map(creep=>creep.memory.job);
console.log(activeJobs.toString());
console.log(room.memory.jobs.toString());
const jobs = room.memory.jobs.filter((j)=>{
const index = activeJobs.findIndex(aj=> _.isEqual(aj,j));
if(index < 0) return true;
activeJobs.splice(index,1);
return false;
});
console.log(jobs.toString());
room.memory.vacancies = jobs;
}