change finding code, add more error logs

This commit is contained in:
Tyrel Souza 2016-06-28 21:28:33 -04:00
parent 4086340c91
commit a629713ed5
4 changed files with 21 additions and 19 deletions

View File

@ -40,9 +40,13 @@ module.exports.loop = function(){
var newName = Game.spawns.Spawn1.createCreep(creepsConfig[roleName].bodyParts,
undefined,
{role: roleName});
if(newName == ERR_NOT_ENOUGH_ENERGY){
console.log("not enough resources to spawn");
} else {
console.log("Spawning", newName);
}
}
}
// Run stuff for each creep
for (var name in Game.creeps){
@ -50,5 +54,5 @@ module.exports.loop = function(){
var role = creep.memory.role;
creepsConfig[role].role.run(creep);
}
console.log("tick");
console.log("#############################################################");
};

View File

@ -10,15 +10,14 @@ var roleBuilder = {
creep.memory.building = true;
}
if (creep.memory.building){
console.log("\t","isBuilding");
var targets = creep.room.find(FIND_CONSTRUCTION_SITES, {
filter: (target) => {
return target.energy < target.energyCapacity;
}
});
console.log("")
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
console.log("\tis building");
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
let transerErrorCode = creep.transfer(targets[0], RESOURCE_ENERGY);
if(transerErrorCode == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
} else if (transerErrorCode == ERR_INVALID_TARGET){
console.log("\tError, invalid Target");
}
} else {

View File

@ -4,11 +4,10 @@ var roleHarvester = {
run: function(creep) {
console.log(creep, "running Harvest");
if(creep.carry.energy < creep.carryCapacity) {
var sources = creep.room.find(FIND_SOURCES);
// var source = Game.getObjectById("576a9c8257110ab231d8934b");
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
console.log(creep, "moving to", sources[0]);
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);
}
}
else {

View File

@ -18,10 +18,10 @@ var roleUpgrader = {
}
}
else {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
console.log("\tmoving to", sources[0]);
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);
}
}
}