Created
March 9, 2018 15:25
-
-
Save 2tunnels/5cd00f54a1a4597c8b5ad34ea9e295fa to your computer and use it in GitHub Desktop.
Screeps
This file contains hidden or 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
| // Spawn harvester | |
| Game.spawns.Spawn_1.spawnCreep([WORK, CARRY, MOVE], `Harvester_${Game.time}`, {memory: {role: 'harvester'}}); | |
| // Loop has issues. | |
| // If spawn is full, harvester will stop. | |
| module.exports.loop = function () { | |
| const creep1 = Game.creeps['Harvester{Game.time}']; | |
| if (creep1.carry[RESOURCE_ENERGY] === creep1.carryCapacity) { | |
| console.log(`${creep1.name} is full`); | |
| const target = creep1.pos.findClosestByRange(FIND_MY_SPAWNS); | |
| if(target) { | |
| if(creep1.transfer(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { | |
| creep1.moveTo(target); | |
| } | |
| } | |
| } else { | |
| console.log(`${creep1.name} is not full`); | |
| const target = creep1.pos.findClosestByRange(FIND_SOURCES_ACTIVE); | |
| if(target) { | |
| if(creep1.harvest(target) == ERR_NOT_IN_RANGE) { | |
| creep1.moveTo(target); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment