Created
November 21, 2014 00:03
-
-
Save Olical/40b67a60b96c9cd446e6 to your computer and use it in GitHub Desktop.
Screeps hervester swarm - http://screeps.com
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
var _ = require('lodash'); | |
function countType(type) { | |
return _.size(_.filter(Game.creeps, function (creep, creepName) { | |
return creepName.split('_')[0] === type; | |
})); | |
} | |
function build(spawn, type, attrNames) { | |
var attrs = attrNames.map(function (name) { | |
return Game[name.toUpperCase()]; | |
}); | |
var id = countType(type) + 1; | |
spawn.createCreep(attrs, type + '_' + id); | |
} | |
module.exports = { | |
worker: function (spawn) { | |
build(spawn, 'worker', ['work', 'move', 'carry']); | |
} | |
}; |
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
function harvest(creep) { | |
var spawn = creep.pos.findNearest(Game.MY_SPAWNS); | |
if (creep.energy < creep.energyCapacity) { | |
var source = creep.pos.findNearest(Game.SOURCES); | |
if (source) { | |
creep.moveTo(source); | |
creep.harvest(source); | |
} | |
} | |
else { | |
creep.moveTo(spawn); | |
creep.transferEnergy(spawn); | |
} | |
} | |
module.exports = harvest; |
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
var harvest = require('harvest'); | |
var factory = require('factory'); | |
var _ = require('lodash'); | |
_.mapValues(Game.creeps, harvest); | |
if (_.size(Game.creeps) < 10 && Game.spawns.Spawn1) { | |
factory.worker(Game.spawns.Spawn1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment