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 roleHarvester = require('role.harvester');
|
||||||
var roleUpgrader = require('role.upgrader');
|
var roleUpgrader = require('role.upgrader');
|
||||||
var roleBuilder = require('role.builder');
|
var roleBuilder = require('role.builder');
|
||||||
|
var helpers = require('helpers');
|
||||||
|
|
||||||
var creepRolePriority = ['harvester', 'builder', 'upgrader'];
|
var creepRolePriority = ['harvester', 'builder', 'upgrader'];
|
||||||
var creepsConfig = {
|
var creepsConfig = {
|
||||||
harvester: {
|
harvester: {
|
||||||
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
||||||
minimumCreeps: 2,
|
minimumCreeps: 3,
|
||||||
role: roleHarvester
|
role: roleHarvester
|
||||||
},
|
},
|
||||||
builder: {
|
builder: {
|
||||||
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
||||||
minimumCreeps: 2,
|
minimumCreeps: 3,
|
||||||
role: roleBuilder
|
role: roleBuilder
|
||||||
},
|
},
|
||||||
upgrader: {
|
upgrader: {
|
||||||
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
||||||
minimumCreeps: 2,
|
minimumCreeps: 3,
|
||||||
role: roleUpgrader
|
role: roleUpgrader
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports.loop = function(){
|
module.exports.loop = function(){
|
||||||
|
console.log(' ');
|
||||||
// Cleanup Creeps
|
// Cleanup Creeps
|
||||||
for (var name in Memory.creeps){
|
for (var name in Memory.creeps){
|
||||||
if (!Game.creeps[name]){
|
if (!Game.creeps[name]){
|
||||||
@ -35,10 +38,11 @@ module.exports.loop = function(){
|
|||||||
for (var i in creepRolePriority){
|
for (var i in creepRolePriority){
|
||||||
var roleName = creepRolePriority[i];
|
var roleName = creepRolePriority[i];
|
||||||
var defaults = creepsConfig[roleName];
|
var defaults = creepsConfig[roleName];
|
||||||
|
|
||||||
var creepsOfKind = _.filter(Game.creeps, (creep) => {return creep.memory.role == roleName});
|
var creepsOfKind = _.filter(Game.creeps, (creep) => {return creep.memory.role == roleName});
|
||||||
if (creepsOfKind.length < creepsConfig[roleName].minimumCreeps){
|
if (creepsOfKind.length < defaults.minimumCreeps){
|
||||||
var newName = Game.spawns.Spawn1.createCreep(creepsConfig[roleName].bodyParts,
|
var newName = Game.spawns.Spawn1.createCreep(defaults.bodyParts,
|
||||||
undefined,
|
helpers.generateName(roleName), // Make names show the roles. Change me to undefined if this gets annoying.
|
||||||
{role: roleName});
|
{role: roleName});
|
||||||
if(newName == ERR_NOT_ENOUGH_ENERGY){
|
if(newName == ERR_NOT_ENOUGH_ENERGY){
|
||||||
console.log("not enough resources to spawn");
|
console.log("not enough resources to spawn");
|
||||||
@ -49,10 +53,18 @@ module.exports.loop = function(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run stuff for each creep
|
// Run stuff for each creep
|
||||||
|
var roleCounts = {
|
||||||
|
builder: 0,
|
||||||
|
harvester: 0,
|
||||||
|
upgrader: 0
|
||||||
|
}
|
||||||
for (var name in Game.creeps){
|
for (var name in Game.creeps){
|
||||||
var creep = Game.creeps[name];
|
var creep = Game.creeps[name];
|
||||||
var role = creep.memory.role;
|
var role = creep.memory.role;
|
||||||
|
roleCounts[role] += 1;
|
||||||
creepsConfig[role].role.run(creep);
|
creepsConfig[role].role.run(creep);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
console.log(JSON.stringify(roleCounts));
|
||||||
console.log("#############################################################");
|
console.log("#############################################################");
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user