2016-06-29 17:21:09 +00:00
|
|
|
var roleHarvester = require('role.harvester');
|
|
|
|
var roleUpgrader = require('role.upgrader');
|
|
|
|
var roleBuilder = require('role.builder');
|
|
|
|
var roleGuard = require('role.guard');
|
|
|
|
var helpers = require('helpers');
|
|
|
|
|
|
|
|
var creepRolePriority = ['harvester', 'builder', 'upgrader', 'guard'];
|
|
|
|
var creepsConfig = {
|
|
|
|
harvester: {
|
|
|
|
bodyParts: [WORK, CARRY, MOVE, MOVE, MOVE],
|
2016-06-29 18:42:30 +00:00
|
|
|
minimumCreeps: 3,
|
2016-06-29 17:21:09 +00:00
|
|
|
role: roleHarvester
|
|
|
|
},
|
|
|
|
builder: {
|
|
|
|
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
2016-06-30 00:52:07 +00:00
|
|
|
minimumCreeps: 1,
|
2016-06-29 17:21:09 +00:00
|
|
|
role: roleBuilder
|
|
|
|
},
|
|
|
|
upgrader: {
|
|
|
|
bodyParts: [WORK, CARRY, MOVE, MOVE, MOVE],
|
2016-06-29 18:42:30 +00:00
|
|
|
minimumCreeps: 4,
|
2016-06-29 17:21:09 +00:00
|
|
|
role: roleUpgrader
|
|
|
|
},
|
|
|
|
guard: {
|
|
|
|
bodyParts: [TOUGH, MOVE, ATTACK, MOVE, ATTACK],
|
2016-06-29 18:42:30 +00:00
|
|
|
minimumCreeps: 3,
|
2016-06-30 00:52:07 +00:00
|
|
|
role: roleGuard,
|
2016-06-29 17:21:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.loop = function(){
|
|
|
|
console.log(' ');
|
|
|
|
// Cleanup Creeps
|
|
|
|
for (var name in Memory.creeps){
|
|
|
|
if (!Game.creeps[name]){
|
|
|
|
delete Memory.creeps[name];
|
|
|
|
console.log("Cleaning non-existing creep memory: ", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refactor some similar behavior for all roles
|
|
|
|
for (var i in creepRolePriority){
|
|
|
|
var roleName = creepRolePriority[i];
|
|
|
|
var defaults = creepsConfig[roleName];
|
|
|
|
|
|
|
|
let creepsOfKind = _.filter(Game.creeps, (creep) => {return creep.memory.role == roleName});
|
|
|
|
if (creepsOfKind.length < defaults.minimumCreeps){
|
|
|
|
var newName = Game.spawns.Spawn1.createCreep(defaults.bodyParts,
|
|
|
|
helpers.generateName(roleName), // Make names show the roles. Change me to undefined if this gets annoying.
|
|
|
|
{role: roleName});
|
|
|
|
if(newName == ERR_NOT_ENOUGH_ENERGY){
|
|
|
|
console.log("not enough resources to spawn");
|
|
|
|
} else {
|
|
|
|
console.log("Spawning", newName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run stuff for each creep
|
2016-06-29 18:42:30 +00:00
|
|
|
var roleCounts = { builder: 0, harvester: 0, upgrader: 0, guard: 0 }
|
|
|
|
var expected = { builder: 0, harvester: 0, upgrader: 0, guard: 0 }
|
2016-06-29 17:21:09 +00:00
|
|
|
for (var name in Game.creeps){
|
|
|
|
var creep = Game.creeps[name];
|
|
|
|
var role = creep.memory.role;
|
|
|
|
roleCounts[role] += 1;
|
|
|
|
creepsConfig[role].role.run(creep);
|
|
|
|
|
|
|
|
}
|
2016-06-29 18:42:30 +00:00
|
|
|
for (var role in creepsConfig){
|
|
|
|
expected[role] = creepsConfig[role].minimumCreeps;
|
|
|
|
}
|
|
|
|
console.log("current:", JSON.stringify(roleCounts));
|
|
|
|
console.log("expect: ", JSON.stringify(expected));
|
2016-06-29 17:21:09 +00:00
|
|
|
console.log("#############################################################");
|
2016-06-29 18:42:30 +00:00
|
|
|
};
|