40 lines
909 B
JavaScript
40 lines
909 B
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);
|
|
const jobs = [].concat(room.memory.jobs);
|
|
activeJobs.forEach(job => {
|
|
const index = jobs.indexOf(job);
|
|
if(0 <= index) jobs.splice(index,1);
|
|
});
|
|
room.memory.vacancies = jobs;
|
|
}
|
|
|