screeps/main.js

48 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-06-28 20:31:39 +00:00
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleBuilder = require('role.builder');
2016-06-28 20:49:31 +00:00
var _defaultBodyParts = [WORK, CARRY, MOVE];
var _roleNames = ["harvester", "builder", "upgrader"];
var _minimums = {
harvester: 4,
builder: 2,
upgrader: 2
};
2016-06-28 20:31:39 +00:00
module.exports.loop = function(){
// Cleanup Creeps
for (var name in Memory.creeps){
if (!Game.creeps[name]){
delete Memory.creeps[name];
console.log("Clearning non-existing creep memory: ", name);
}
}
// Refactor some similar behavior for all roles
2016-06-28 20:49:31 +00:00
_roleNames.forEach(function(roleName){
2016-06-28 20:31:39 +00:00
var creepsOfKind = _.filter(Game.creeps, (creep) => creep.memory.role == roleName);
2016-06-28 20:49:31 +00:00
if (creepsOfKind.length < _minimums[roleName]){
var newName = Game.spawns.Spawn1.createCreep(_defaultBodyParts, undefined, {role: roleName});
2016-06-28 20:31:39 +00:00
console.log("Spawning new ", roleName, ": ", newName);
}
});
// Run stuff for each creep
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);
}
if (creep.memory.role == 'builder'){
roleBuilder.run(creep);
}
}
}