added creep config file

This commit is contained in:
Tyrel Souza 2016-07-05 10:36:43 -04:00
parent b34776552a
commit ee75b48814
No known key found for this signature in database
GPG Key ID: 2EECB5087209E6A5
7 changed files with 157 additions and 136 deletions

View File

@ -1,5 +1,5 @@
// usernames are all lowercase, we compare with to lower
var USERNAME_WHITELIST = ['chrisinajar', 'ho0ber', 'fractaloop', 'n7-anthony', 'overra', 'tyrel', 'fervens'];
var USERNAME_WHITELIST = ['chrisinajar', 'ho0ber', 'fractaloop', 'n7-anthony', 'overra', 'tyrel', 'fervens', 'devdaniel'];
module.exports = {
findEnemy: findEnemy,

27
creeps.config.js Normal file
View File

@ -0,0 +1,27 @@
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleBuilder = require('role.builder');
var roleGuard = require('role.guard');
module.exports = {
harvester: {
bodyParts: [WORK,WORK, CARRY,CARRY, MOVE, MOVE],
minimumCreeps: 4,
role: roleHarvester
},
builder: {
bodyParts: [WORK, CARRY, CARRY, CARRY, MOVE, MOVE],
minimumCreeps: 0,
role: roleBuilder
},
upgrader: {
bodyParts: [WORK, CARRY, WORK, MOVE, CARRY, MOVE, MOVE],
minimumCreeps: 4,
role: roleUpgrader
},
guard: {
bodyParts: [TOUGH, MOVE, ATTACK, MOVE, ATTACK],
minimumCreeps: 0,
role: roleGuard,
}
};

35
main.js
View File

@ -1,32 +1,7 @@
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleBuilder = require('role.builder');
var roleGuard = require('role.guard');
var structureTower = require('structure.tower');
var creepsConfig = require('creeps.config');
var helpers = require('helpers');
var creepRolePriority = ['harvester', 'builder', 'upgrader', 'guard'];
var creepsConfig = {
harvester: {
bodyParts: [WORK, CARRY, MOVE, MOVE, MOVE],
minimumCreeps: 4,
role: roleHarvester
},
builder: {
bodyParts: [WORK, CARRY, CARRY, MOVE],
minimumCreeps: 5,
role: roleBuilder
},
upgrader: {
bodyParts: [WORK, CARRY, CARRY, MOVE, MOVE],
minimumCreeps: 2,
role: roleUpgrader
},
guard: {
bodyParts: [TOUGH, MOVE, ATTACK, MOVE, ATTACK],
minimumCreeps: 4,
role: roleGuard,
}
};
module.exports.loop = function(){
@ -37,7 +12,6 @@ module.exports.loop = function(){
delete Memory.creeps[name];
console.log('Cleaning non-existing creep memory:', name);
}
}
// Refactor some similar behavior for all roles
@ -58,6 +32,11 @@ module.exports.loop = function(){
}
}
var tower = Game.getObjectById('577683641404f96570a580d2');
if(tower) {
structureTower.run(tower);
}
// Run stuff for each creep
var roleCounts = {harvester: 0, builder: 0, upgrader: 0, guard: 0};
var expected = _(creepsConfig).mapValues('minimumCreeps');

View File

@ -1,3 +1,5 @@
var BreakException= {};
var roleBuilder = {
@ -16,9 +18,10 @@ var roleBuilder = {
creep.moveTo(targets[0]);
}
} else {
var sources = creep.room.find(FIND_SOURCES);
if (creep.harvest(sources[0]) == ERR_NOT_IN_RANGE){
creep.moveTo(sources[0]);
var source = creep.pos.findClosestByPath(FIND_SOURCES);
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
console.log('\tmoving to', source);
creep.moveTo(source);
}
}
@ -26,3 +29,4 @@ var roleBuilder = {
}
};
module.exports = roleBuilder;

View File

@ -17,7 +17,6 @@ var roleGuard = {
run: function(creep){
this.creep = creep;
this.lastFlag = helpers.getLastFlag("patrol_");
console.log(creep, 'running Guard')
creep.memory.patrolDestination = creep.memory.patrolDestination || 1;
var target = battle.findEnemy(creep);
if(target != creep.room.controller && creep.hits > creep.hitsMax - 500 /* no more attack */) {

View File

@ -13,7 +13,8 @@ var roleHarvester = {
else {
var targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_EXTENSION
return (structure.structureType == STRUCTURE_CONTAINER
|| structure.structureType == STRUCTURE_EXTENSION
|| structure.structureType == STRUCTURE_SPAWN
|| structure.structureType == STRUCTURE_TOWER
) && structure.energy < structure.energyCapacity;
@ -24,9 +25,13 @@ var roleHarvester = {
console.log('\tmoving to', targets[0]);
creep.moveTo(targets[0]);
}
} else {
creep.moveTo(Game.spawns.Spawn1);
}
}
}
};
module.exports = roleHarvester;

View File

@ -16,10 +16,17 @@ var roleUpgrader = {
}
else {
var source = creep.pos.findClosestByPath(FIND_SOURCES);
console.log(source);
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
creep.moveTo(source);
}
}
}
};