63 lines
2.3 KiB
JavaScript
63 lines
2.3 KiB
JavaScript
var idler = require('idle.base');
|
|
var harvester = require('energy.harvest');
|
|
var collector = require('energy.storage');
|
|
|
|
var roleUpgrader = {
|
|
|
|
/**
|
|
@param {Creep} creep
|
|
@param {int} behaviourLevel
|
|
**/
|
|
run: function(creep, behaviourLevel) {
|
|
switch (creep.memory.state) {
|
|
case "idle":
|
|
idler.do_idle(creep);
|
|
if (creep.room.controller.progress < creep.room.controller.progressTotal){
|
|
// If there are any buildings to upgrade, switch back to the upgrading state
|
|
idler.clear_idle(creep);
|
|
creep.memory.state = "upgrade_structure";
|
|
creep.say("upgrading");
|
|
}
|
|
if (creep.store.getFreeCapacity() > 0) {
|
|
// If we are not full with energy, switch to the get_energy state
|
|
idler.clear_idle(creep);
|
|
creep.memory.state = "get_energy";
|
|
creep.say('Reloading...');
|
|
}
|
|
break;
|
|
|
|
case "upgrade_structure":
|
|
if (creep.room.controller.progress < creep.room.controller.progressTotal){
|
|
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
|
|
creep.moveTo(creep.room.controller, {visualizePathStyle: {stroke: '#ffffff'}});
|
|
}
|
|
} else {
|
|
// Else, go idle
|
|
creep.memory.state = "idle";
|
|
creep.say('idling');
|
|
}
|
|
if (creep.store.getUsedCapacity() == 0) {
|
|
// If we have no energy, switch to the get_energy state
|
|
creep.memory.state = "get_energy";
|
|
creep.say('Reloading...');
|
|
}
|
|
break;
|
|
|
|
case "get_energy":
|
|
var energy_source;
|
|
if(behaviourLevel >= 2) {
|
|
energy_source = collector;
|
|
} else {
|
|
energy_source = harvester;
|
|
}
|
|
energy_source.do_collect(creep, "upgrade_structure", "Upgrading...");
|
|
break;
|
|
|
|
default:
|
|
creep.memory.state = "get_energy";
|
|
creep.say("Reloading...");
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = roleUpgrader; |