Created supplier and builder functions
This commit is contained in:
24
RoomClass.js
24
RoomClass.js
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user