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,18 +2,30 @@ module.exports = {
setup: function () { StructureSpawn.prototype = _Spawn.prototype; }
}
class _Spawn extends StructureSpawn {
begin(){
if (!this.memory.creepCounter) this.memory.creepCounter = 0;
this.memory.init = true;
}
tick(){
if(!this.memory.init) this.begin();
if(this.room.memory.jobs.length){
const job = this.room.memory.jobs[0];
const body = [WORK, CARRY, MOVE];
const response = this.createCreep(body, "harvester", job);
if(response == OK) this.room.memory.jobs.splice(0, 1);
}
}
createHarvester() {
var body = [WORK, CARRY, MOVE];
this.createCreep(body, "harvester", Role.HARVESTER);
}
createCreep(body, name, role) {
if (this.memory.creepCounter == undefined) this.memory.creepCounter = 0;
createCreep(body, name, job) {
const response = this.spawnCreep(body, name + ": " + this.memory.creepCounter, {
memory: { job: { role: role } }
memory: { job: job }
});
if (response == OK) this.memory.creepCounter++;
return response;