45 lines
1.0 KiB
JavaScript
45 lines
1.0 KiB
JavaScript
module.exports = {
|
|
setup: function () { Room.prototype = _Room.prototype; }
|
|
}
|
|
|
|
class _Room extends Room {
|
|
begin(){
|
|
roomScan(this);
|
|
jobScan(this);
|
|
vacancyScan(this);
|
|
this.memory.init = true;
|
|
}
|
|
|
|
tick(){
|
|
if(!this.memory.init) this.begin();
|
|
if(Game.time%100 === 1) vacancyScan(this);
|
|
}
|
|
}
|
|
|
|
function roomScan(room){
|
|
room.memory.layout = {
|
|
sources: room.find(FIND_SOURCES).map(s=>s.id)
|
|
};
|
|
}
|
|
|
|
function jobScan(room){
|
|
if(!room.memory.jobs) room.memory.jobs = Array(10).fill({role: Role.HARVESTER})
|
|
.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;
|
|
}
|
|
|