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,7 +40,11 @@ module.exports.loop = function(){
var newName = Game.spawns.Spawn1.createCreep(creepsConfig[roleName].bodyParts, var newName = Game.spawns.Spawn1.createCreep(creepsConfig[roleName].bodyParts,
undefined, undefined,
{role: roleName}); {role: roleName});
console.log("Spawning", newName); if(newName == ERR_NOT_ENOUGH_ENERGY){
console.log("not enough resources to spawn");
} else {
console.log("Spawning", newName);
}
} }
} }
@ -50,5 +54,5 @@ module.exports.loop = function(){
var role = creep.memory.role; var role = creep.memory.role;
creepsConfig[role].role.run(creep); creepsConfig[role].role.run(creep);
} }
console.log("tick"); console.log("#############################################################");
}; };

View File

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

View File

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

View File

@ -18,10 +18,10 @@ var roleUpgrader = {
} }
} }
else { else {
var sources = creep.room.find(FIND_SOURCES); var source = creep.pos.findClosestByPath(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
console.log("\tmoving to", sources[0]); console.log("\tmoving to", source);
creep.moveTo(sources[0]); creep.moveTo(source);
} }
} }
} }