fix line endings, and dealt with tower logic

This commit is contained in:
Tyrel Souza 2016-06-30 10:37:58 -04:00
parent ed4c5eb67f
commit 856706ae28
No known key found for this signature in database
GPG Key ID: 2EECB5087209E6A5
7 changed files with 263 additions and 228 deletions

View File

@ -6,19 +6,16 @@ module.exports = {
run: run
};
/*
var target = findEnemy(creep);
*/
function findEnemy (creep) {
var targets = creep.room.find(FIND_HOSTILE_CREEPS, {
function findEnemy (searcher) {
var targets = searcher.room.find(FIND_HOSTILE_CREEPS, {
filter: (c) => {
return (USERNAME_WHITELIST.indexOf(c.owner.username.toLowerCase()) === -1);
}
});
if (!targets.length) {
return creep.room.controller;
return searcher.room.controller;
}
return creep.pos.findClosestByPath(targets);
return searcher.pos.findClosestByPath(targets);
}
function run (creep) {

View File

@ -8,22 +8,22 @@ var creepRolePriority = ['harvester', 'builder', 'upgrader', 'guard'];
var creepsConfig = {
harvester: {
bodyParts: [WORK, CARRY, MOVE, MOVE, MOVE],
minimumCreeps: 3,
minimumCreeps: 4,
role: roleHarvester
},
builder: {
bodyParts: [WORK, CARRY, MOVE, MOVE],
minimumCreeps: 2,
minimumCreeps: 4,
role: roleBuilder
},
upgrader: {
bodyParts: [WORK, CARRY, CARRY, MOVE, MOVE],
minimumCreeps: 6,
minimumCreeps: 4,
role: roleUpgrader
},
guard: {
bodyParts: [TOUGH, MOVE, ATTACK, MOVE, ATTACK],
minimumCreeps: 3,
minimumCreeps: 4,
role: roleGuard,
}
};

38
structure.tower.js Normal file
View File

@ -0,0 +1,38 @@
var battle = require('battle')
//var helpers = require('helpers');
var structureTower= {
run: function(structure){
this.structure = structure;
console.log(structure, 'running Tower')
var target = battle.findEnemy(this.structure);
if(target != structure.room.controller) {
console.log('\t', this.structure, 'attacking:',target)
this.structure.attack(target);
} else {
var damagedStructure = this.findDamagedStructure();
if(damagedStructure){
console.log("repairing", damagedStructure);
this.structure.repair(damagedStructure);
}
}
},
findDamagedStructure: function(searcher){
var targets = searcher.room.find(FIND_STRUCTURES, {
filter: function(s){
if(s.structureType == STRUCTURE_TOWER){
return false;
}
if (s.hits < s.hitsMax){
return true;
}
return false;
}
});
return searcher.pos.findClosestByPath(targets);
}
}
module.exports = structureTower;