Skip to content

Instantly share code, notes, and snippets.

@derofim
Created March 11, 2016 22:34
Show Gist options
  • Save derofim/774fe2f48852a253cc7a to your computer and use it in GitHub Desktop.
Save derofim/774fe2f48852a253cc7a to your computer and use it in GitHub Desktop.
screeps.com
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('harvester'); // -> 'a thing'
*/
module.exports = function (creep) {
if(creep.carry.energy < creep.carryCapacity) {
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);
}
}
}
// Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Worker1' );
// Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Worker2' );
// Game.spawns.Spawn1.createCreep( [WORK, WORK, CARRY, MOVE], 'Builder1' );
// Memory.creeps.Worker1.role = 'harvester';
// Memory.creeps.Worker2.role = 'harvester';
// Memory.creeps.Builder1.role = 'builder';
// Game.spawns.Spawn1.createCreep( [TOUGH, ATTACK, MOVE, MOVE], 'Guard1', { role: 'guard' } );
var harvester = require('harvester');
module.exports.loop = function () {
for(var name in Game.creeps) {
var creep = Game.creeps[name];
if(creep.memory.role == 'guard') {
var targets = creep.room.find(FIND_HOSTILE_CREEPS);
if(targets.length) {
if(creep.attack(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
}
}
}
if(creep.memory.role == 'harvester') {
harvester(creep);
}
if(creep.memory.role == 'builder') {
if(creep.carry.energy == 0) {
if(Game.spawns.Spawn1.transferEnergy(creep) == ERR_NOT_IN_RANGE) {
creep.moveTo(Game.spawns.Spawn1);
}
}
else {
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
if(targets.length) {
if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
}
}
}
}
}
}
@derofim
Copy link
Author

derofim commented Mar 15, 2016

Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'harvester_1', { role: 'harvester' } );

@derofim
Copy link
Author

derofim commented Mar 20, 2016

Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], null, { role: 'dummy' } );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment