change finding code, add more error logs
This commit is contained in:
parent
4086340c91
commit
a629713ed5
6
main.js
6
main.js
@ -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("#############################################################");
|
||||
};
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user