My personal screeps.com scripts, various branches/tags for various states.

role.upgrader.js 853B

123456789101112131415161718192021222324252627282930
  1. var roleUpgrader = {
  2. /** @param {Creep} creep **/
  3. run: function(creep) {
  4. if(creep.memory.upgrading && creep.carry.energy == 0) {
  5. creep.memory.upgrading = false;
  6. creep.say('harvesting');
  7. }
  8. if(!creep.memory.upgrading && creep.carry.energy == creep.carryCapacity) {
  9. creep.memory.upgrading = true;
  10. creep.say('upgrading');
  11. }
  12. if(creep.memory.upgrading) {
  13. if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
  14. creep.moveTo(creep.room.controller);
  15. }
  16. }
  17. else {
  18. var sources = creep.room.find(FIND_SOURCES);
  19. if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
  20. creep.moveTo(sources[0]);
  21. }
  22. }
  23. }
  24. };
  25. module.exports = roleUpgrader;