45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
module.exports = {
|
|
setup: function () { Room.prototype = _Room.prototype; }
|
|
}
|
|
|
|
class _Room extends Room {
|
|
begin(){
|
|
roomLayoutScan(this);
|
|
jobScan(this);
|
|
vacancyScan(this);
|
|
this.memory.init = true;
|
|
}
|
|
|
|
tick(){
|
|
if(!this.memory.init) this.begin();
|
|
if(!(Game.time%100)) {
|
|
vacancyScan(this);
|
|
}
|
|
}
|
|
}
|
|
|
|
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 = [{role:Role.UPGRADER}]
|
|
.concat(Array(4).fill({role: Role.BUILDER}))
|
|
.concat(Array(2).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);
|
|
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;
|
|
});
|
|
room.memory.vacancies = jobs;
|
|
}
|
|
|