fix line endings, and dealt with tower logic
This commit is contained in:
parent
ed4c5eb67f
commit
856706ae28
11
battle.js
11
battle.js
|
@ -6,19 +6,16 @@ module.exports = {
|
||||||
run: run
|
run: run
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
function findEnemy (searcher) {
|
||||||
var target = findEnemy(creep);
|
var targets = searcher.room.find(FIND_HOSTILE_CREEPS, {
|
||||||
*/
|
|
||||||
function findEnemy (creep) {
|
|
||||||
var targets = creep.room.find(FIND_HOSTILE_CREEPS, {
|
|
||||||
filter: (c) => {
|
filter: (c) => {
|
||||||
return (USERNAME_WHITELIST.indexOf(c.owner.username.toLowerCase()) === -1);
|
return (USERNAME_WHITELIST.indexOf(c.owner.username.toLowerCase()) === -1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!targets.length) {
|
if (!targets.length) {
|
||||||
return creep.room.controller;
|
return searcher.room.controller;
|
||||||
}
|
}
|
||||||
return creep.pos.findClosestByPath(targets);
|
return searcher.pos.findClosestByPath(targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
function run (creep) {
|
function run (creep) {
|
||||||
|
|
8
main.js
8
main.js
|
@ -8,22 +8,22 @@ var creepRolePriority = ['harvester', 'builder', 'upgrader', 'guard'];
|
||||||
var creepsConfig = {
|
var creepsConfig = {
|
||||||
harvester: {
|
harvester: {
|
||||||
bodyParts: [WORK, CARRY, MOVE, MOVE, MOVE],
|
bodyParts: [WORK, CARRY, MOVE, MOVE, MOVE],
|
||||||
minimumCreeps: 3,
|
minimumCreeps: 4,
|
||||||
role: roleHarvester
|
role: roleHarvester
|
||||||
},
|
},
|
||||||
builder: {
|
builder: {
|
||||||
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
bodyParts: [WORK, CARRY, MOVE, MOVE],
|
||||||
minimumCreeps: 2,
|
minimumCreeps: 4,
|
||||||
role: roleBuilder
|
role: roleBuilder
|
||||||
},
|
},
|
||||||
upgrader: {
|
upgrader: {
|
||||||
bodyParts: [WORK, CARRY, CARRY, MOVE, MOVE],
|
bodyParts: [WORK, CARRY, CARRY, MOVE, MOVE],
|
||||||
minimumCreeps: 6,
|
minimumCreeps: 4,
|
||||||
role: roleUpgrader
|
role: roleUpgrader
|
||||||
},
|
},
|
||||||
guard: {
|
guard: {
|
||||||
bodyParts: [TOUGH, MOVE, ATTACK, MOVE, ATTACK],
|
bodyParts: [TOUGH, MOVE, ATTACK, MOVE, ATTACK],
|
||||||
minimumCreeps: 3,
|
minimumCreeps: 4,
|
||||||
role: roleGuard,
|
role: roleGuard,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
38
structure.tower.js
Normal file
38
structure.tower.js
Normal 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;
|
Loading…
Reference in New Issue
Block a user