Created
May 14, 2022 17:43
-
-
Save kbakdev/7f6829beadb75ed92b62a2c26ed720c8 to your computer and use it in GitHub Desktop.
screeps v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var roleHarvester = require('role.harvester'); | |
var roleUpgrader = require('role.upgrader'); | |
module.exports.loop = function () { | |
for(var name in Game.creeps) { | |
var creep = Game.creeps[name]; | |
if(creep.memory.role == 'harvester') { | |
roleHarvester.run(creep); | |
} | |
if(creep.memory.role == 'upgrader') { | |
roleUpgrader.run(creep); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var roleHarvester = { | |
/** @param {Creep} creep **/ | |
run: function(creep) { | |
if(creep.store.getFreeCapacity() > 0) { | |
var sources = creep.room.find(FIND_SOURCES); | |
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { | |
creep.moveTo(sources[0]); | |
} | |
} | |
else if(Game.spawns['Spawn1'].energy < Game.spawns['Spawn1'].energyCapacity) { | |
if(creep.transfer(Game.spawns['Spawn1'], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { | |
creep.moveTo(Game.spawns['Spawn1']); | |
} | |
} | |
} | |
}; | |
module.exports = roleHarvester; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var roleUpgrader = { | |
/** @param {Creep} creep **/ | |
run: function(creep) { | |
if(creep.store[RESOURCE_ENERGY] == 0) { | |
var sources = creep.room.find(FIND_SOURCES); | |
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { | |
creep.moveTo(sources[0]); | |
} | |
} | |
else { | |
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) { | |
creep.moveTo(creep.room.controller); | |
} | |
} | |
} | |
}; | |
module.exports = roleUpgrader; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment