Finished first tutorial
This commit is contained in:
parent
974898ac4b
commit
63c65c4a2b
@ -1,3 +1,9 @@
|
||||
var roleHarvester = require('role.harvester');
|
||||
|
||||
module.exports.loop = function () {
|
||||
|
||||
for(var name in Game.creeps) {
|
||||
var creep = Game.creeps[name];
|
||||
roleHarvester.run(creep);
|
||||
}
|
||||
}
|
28
screeps.com/tutorial-1/role.harvester.js
Normal file
28
screeps.com/tutorial-1/role.harvester.js
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Module code goes here. Use 'module.exports' to export things:
|
||||
* module.exports.thing = 'a thing';
|
||||
*
|
||||
* You can import it from another modules like this:
|
||||
* var mod = require('role.harvester');
|
||||
* mod.thing == 'a thing'; // true
|
||||
*/
|
||||
|
||||
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(creep.transfer(Game.spawns['Spawn1'], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
|
||||
creep.moveTo(Game.spawns['Spawn1']);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = roleHarvester;
|
Loading…
Reference in New Issue
Block a user