Created miner, made harvester pick resources and added reset commands.

This commit is contained in:
Douwe Ravers
2023-08-26 16:57:38 +02:00
parent 76650e22ac
commit e294ad29fe
13 changed files with 310 additions and 136 deletions

42
StructureSpawnClass.js Normal file
View File

@@ -0,0 +1,42 @@
module.exports = {
setup: function () { StructureSpawn.prototype = _StructureSpawn.prototype; }
}
class _StructureSpawn extends StructureSpawn {
begin(){
if (!this.memory.creepCounter) this.memory.creepCounter = 0;
this.memory.init = true;
}
tick(){
if(!this.memory.init) this.begin();
const job = this.room.memory.vacancies.pop();
if(job){
const name = getJobName(job.role);
const body = getBodyByJob(job.role);
if(this.createCreep(job, name, body) != OK) this.room.memory.vacancies.push(job);
}
}
createCreep(job, name, body) {
const response = this.spawnCreep(body, name + ": " + this.memory.creepCounter, {
memory: { job: job }
});
if (response == OK) this.memory.creepCounter++;
return response;
}
}
function getJobName(role){
switch (role) {
case Role.HARVESTER: return "Harvy";
case Role.MINER: return "minny";
}
}
function getBodyByJob(role){
switch (role) {
case Role.HARVESTER: return [WORK, CARRY, MOVE, MOVE];
case Role.MINER: return [WORK, WORK, MOVE];
}
}