screeps/main.js

49 lines
1.5 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 21:00:10 +00:00
var creepsConfig = {
harvester: {
bodyParts: [WORK, CARRY, MOVE],
minimumCreeps: 4,
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-28 21:00:10 +00:00
bodyParts: [WORK, CARRY, MOVE],
minimumCreeps: 2,
2016-06-28 21:17:03 +00:00
role: roleBuilder
2016-06-28 21:00:10 +00:00
},
upgrader: {
bodyParts: [WORK, CARRY, MOVE],
minimumCreeps: 2,
2016-06-28 21:17:03 +00:00
role: roleUpgrader
2016-06-28 21:00:10 +00:00
}
}
2016-06-28 21:17:03 +00:00
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
2016-06-28 21:00:10 +00:00
for (var roleName in creepsConfig){
2016-06-28 20:31:39 +00:00
var creepsOfKind = _.filter(Game.creeps, (creep) => creep.memory.role == roleName);
2016-06-28 21:00:10 +00:00
if (creepsOfKind.length < creepsConfig[roleName].minimumCreeps){
2016-06-28 21:17:03 +00:00
var newName = Game.spawns.Spawn1.createCreep(creepsConfig[roleName].bodyParts,
undefined,
{role: roleName});
2016-06-28 20:31:39 +00:00
console.log("Spawning new ", roleName, ": ", newName);
}
2016-06-28 21:00:10 +00:00
};
2016-06-28 20:31:39 +00:00
// Run stuff for each creep
for (var name in Game.creeps){
var creep = Game.creeps[name];
2016-06-28 21:00:10 +00:00
var role = creep.memory.role;
2016-06-28 21:17:03 +00:00
creepsConfig[role].role.run(creep);
2016-06-28 20:31:39 +00:00
}
}