added random name generator so you can see what they are
This commit is contained in:
parent
3b4cd13dad
commit
cf4be001c4
14
helpers.js
Normal file
14
helpers.js
Normal 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
24
main.js
|
@ -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("#############################################################");
|
||||
};
|
Loading…
Reference in New Issue
Block a user