43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
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();
|
|
if(this.store.getUsedCapacity(RESOURCE_ENERGY) < 300) return;
|
|
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];
|
|
}
|
|
} |