added random name generator so you can see what they are

This commit is contained in:
Tyrel Souza 2016-06-28 22:12:51 -04:00
parent 3b4cd13dad
commit cf4be001c4
2 changed files with 32 additions and 6 deletions

14
helpers.js Normal file
View File

@ -0,0 +1,14 @@
/**
* Created by tsouza on 6/28/2016.
*/
var helpers = {
generateName: function(role){
return role + '_xxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
};
module.exports = helpers;

24
main.js
View File

@ -1,27 +1,30 @@
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleBuilder = require('role.builder');
var helpers = require('helpers');
var creepRolePriority = ['harvester', 'builder', 'upgrader'];
var creepsConfig = {
harvester: {
bodyParts: [WORK, CARRY, MOVE, MOVE],
minimumCreeps: 2,
minimumCreeps: 3,
role: roleHarvester
},
builder: {
bodyParts: [WORK, CARRY, MOVE, MOVE],
minimumCreeps: 2,
minimumCreeps: 3,
role: roleBuilder
},
upgrader: {
bodyParts: [WORK, CARRY, MOVE, MOVE],
minimumCreeps: 2,
minimumCreeps: 3,
role: roleUpgrader
}
};
module.exports.loop = function(){
console.log(' ');
// Cleanup Creeps
for (var name in Memory.creeps){
if (!Game.creeps[name]){
@ -35,10 +38,11 @@ module.exports.loop = function(){
for (var i in creepRolePriority){
var roleName = creepRolePriority[i];
var defaults = creepsConfig[roleName];
var creepsOfKind = _.filter(Game.creeps, (creep) => {return creep.memory.role == roleName});
if (creepsOfKind.length < creepsConfig[roleName].minimumCreeps){
var newName = Game.spawns.Spawn1.createCreep(creepsConfig[roleName].bodyParts,
undefined,
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");
@ -49,10 +53,18 @@ module.exports.loop = function(){
}
// Run stuff for each creep
var roleCounts = {
builder: 0,
harvester: 0,
upgrader: 0
}
for (var name in Game.creeps){
var creep = Game.creeps[name];
var role = creep.memory.role;
roleCounts[role] += 1;
creepsConfig[role].role.run(creep);
}
console.log(JSON.stringify(roleCounts));
console.log("#############################################################");
};