Skip to content

Commit

Permalink
Added Error Handling and Idle Army Building
Browse files Browse the repository at this point in the history
Added Error Handling and Idle Army Building
  • Loading branch information
Garethp committed Dec 5, 2014
1 parent 3830bc2 commit 6702a12
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
10 changes: 10 additions & 0 deletions factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,15 @@ module.exports ={

gatheredScreeps[type]++;
}
},

buildArmyWhileIdle: function()
{
for(var i in Game.spawns)
{
var spawn = Game.spawns[i];
if(!spawn.spawning && Memory.spawnQue.length == 0 && spawn.energy / spawn.energyCapacity >= .75)
require('spawner').spawn('archer', { }, spawn);
}
}
};
2 changes: 2 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ factory.run();

spawner.spawnNextInQue();

factory.buildArmyWhileIdle();

performRoles(Game.creeps);
2 changes: 1 addition & 1 deletion performRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ module.exports = function(creeps)

var role = Object.create(role);
role.setCreep(creep);
role.run();
try { role.run(); } catch(e) { };
}
};
6 changes: 5 additions & 1 deletion roles_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ var builder = {

//If no repairs are needed, we're just going to go find some structures to build
var targets = creep.pos.findNearest(Game.CONSTRUCTION_SITES);
if(targets !== undefined) {
if(targets) {

if(!creep.pos.isNearTo(targets))
creep.moveTo(targets);

if(creep.pos.inRangeTo(targets, 0))
creep.suicide();

creep.build(targets);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion roles_miner_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ var helper = {
});

//If we found a courier, make that courier our new target
if (courier !== null) {
if (courier !== null && !creep.pos.isNearTo(target)) {
target = courier;
target.memory.courier = true;
}
Expand Down

0 comments on commit 6702a12

Please sign in to comment.