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-29 02:12:51 +00:00
|
|
|
var helpers = require('helpers');
|
2016-06-28 20:31:39 +00:00
|
|
|
|
2016-06-28 23:38:52 +00:00
|
|
|
var creepRolePriority = ['harvester', 'builder', 'upgrader'];
|
2016-06-28 21:00:10 +00:00
|
|
|
var creepsConfig = {
|
|
|
|
harvester: {
|
2016-06-29 01:52:40 +00:00
|
|
|
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
2016-06-29 02:12:51 +00:00
|
|
|
minimumCreeps: 3,
|
2016-06-28 21:17:03 +00:00
|
|
|
role: roleHarvester
|
2016-06-28 21:00:10 +00:00
|
|
|
},
|
2016-06-28 21:17:03 +00:00
|
|
|
builder: {
|
2016-06-29 01:52:40 +00:00
|
|
|
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
2016-06-29 02:12:51 +00:00
|
|
|
minimumCreeps: 3,
|
2016-06-28 21:17:03 +00:00
|
|
|
role: roleBuilder
|
2016-06-28 21:00:10 +00:00
|
|
|
},
|
|
|
|
upgrader: {
|
2016-06-29 01:52:40 +00:00
|
|
|
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
2016-06-29 02:12:51 +00:00
|
|
|
minimumCreeps: 3,
|
2016-06-28 21:17:03 +00:00
|
|
|
role: roleUpgrader
|
2016-06-28 21:00:10 +00:00
|
|
|
}
|
2016-06-28 23:51:04 +00:00
|
|
|
};
|
2016-06-28 21:17:03 +00:00
|
|
|
|
2016-06-29 02:12:51 +00:00
|
|
|
|
2016-06-28 20:31:39 +00:00
|
|
|
module.exports.loop = function(){
|
2016-06-29 02:12:51 +00:00
|
|
|
console.log(' ');
|
2016-06-28 20:31:39 +00:00
|
|
|
// Cleanup Creeps
|
|
|
|
for (var name in Memory.creeps){
|
|
|
|
if (!Game.creeps[name]){
|
|
|
|
delete Memory.creeps[name];
|
2016-06-28 23:51:04 +00:00
|
|
|
console.log("Cleaning non-existing creep memory: ", name);
|
2016-06-28 20:31:39 +00:00
|
|
|
}
|
2016-06-28 23:38:52 +00:00
|
|
|
|
2016-06-28 20:31:39 +00:00
|
|
|
}
|
2016-06-28 20:49:31 +00:00
|
|
|
|
2016-06-28 23:38:52 +00:00
|
|
|
// Refactor some similar behavior for all roles
|
|
|
|
for (var i in creepRolePriority){
|
|
|
|
var roleName = creepRolePriority[i];
|
|
|
|
var defaults = creepsConfig[roleName];
|
2016-06-29 02:12:51 +00:00
|
|
|
|
2016-06-28 23:51:04 +00:00
|
|
|
var creepsOfKind = _.filter(Game.creeps, (creep) => {return creep.memory.role == roleName});
|
2016-06-29 02:12:51 +00:00
|
|
|
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.
|
2016-06-28 21:17:03 +00:00
|
|
|
{role: roleName});
|
2016-06-29 01:28:33 +00:00
|
|
|
if(newName == ERR_NOT_ENOUGH_ENERGY){
|
|
|
|
console.log("not enough resources to spawn");
|
|
|
|
} else {
|
|
|
|
console.log("Spawning", newName);
|
|
|
|
}
|
2016-06-28 20:31:39 +00:00
|
|
|
}
|
2016-06-28 23:38:52 +00:00
|
|
|
}
|
2016-06-28 20:31:39 +00:00
|
|
|
|
|
|
|
// Run stuff for each creep
|
2016-06-29 02:12:51 +00:00
|
|
|
var roleCounts = {
|
|
|
|
builder: 0,
|
|
|
|
harvester: 0,
|
|
|
|
upgrader: 0
|
|
|
|
}
|
2016-06-28 23:38:52 +00:00
|
|
|
for (var name in Game.creeps){
|
2016-06-28 20:31:39 +00:00
|
|
|
var creep = Game.creeps[name];
|
2016-06-28 21:00:10 +00:00
|
|
|
var role = creep.memory.role;
|
2016-06-29 02:12:51 +00:00
|
|
|
roleCounts[role] += 1;
|
2016-06-28 21:17:03 +00:00
|
|
|
creepsConfig[role].role.run(creep);
|
2016-06-29 02:12:51 +00:00
|
|
|
|
2016-06-28 20:31:39 +00:00
|
|
|
}
|
2016-06-29 02:12:51 +00:00
|
|
|
console.log(JSON.stringify(roleCounts));
|
2016-06-29 01:28:33 +00:00
|
|
|
console.log("#############################################################");
|
2016-06-28 23:51:04 +00:00
|
|
|
};
|