Improved harvester behaviour, reworked the job register system and added auto roadbuilding.

This commit is contained in:
Douwe Ravers
2023-08-25 17:30:27 +02:00
parent 8c3528419a
commit 76650e22ac
11 changed files with 113 additions and 111 deletions

View File

@@ -2,5 +2,49 @@ module.exports = {
setup: function () { Room.prototype = _Room.prototype; }
}
class _Room extends Room {}
class _Room extends Room {
begin(){
this.setJobQueue();
this.roomScan();
this.buildRoads();
this.memory.init = true;
}
tick(){
if(!this.memory.init) this.begin();
}
setJobQueue(){
if(!this.memory.jobs) this.memory.jobs = [
{ role: Role.HARVESTER },
{ role: Role.HARVESTER },
{ role: Role.HARVESTER },
{ role: Role.HARVESTER },
{ role: Role.HARVESTER }
]
}
roomScan(){
this.memory.layout = {
sources: this.find(FIND_SOURCES).map(s=>s.id)
};
}
buildRoads(){
this.memory.layout.sources.forEach(
sId => {
const source = Game.getObjectById(sId);
this.buildRoad(source, this.controller);
this.buildRoad(source, this.find(FIND_MY_STRUCTURES, { filter:{ structureType:STRUCTURE_SPAWN }})[0]);
}
)
}
buildRoad(from, to){
const path = from.pos.findPathTo(to);
path.forEach(tile => this.createConstructionSite(tile.x, tile.y, STRUCTURE_ROAD))
}
}