I just want to point out that none of the roles were set at .length < 0 when I actually tried the code.
Posts made by NanoCraft
-
RE: Setting creep spawn que priority order
-
Setting creep spawn que priority order
I am having a lot of trouble the game spawning less important creeps before harvesters which thereby results in my population dying out. I have tried to formulate a priority order in my code but it has no worked so far. Would someone be able to help me with what I am doing wrong? I tried nesting 'if' and 'else if' statements before my code but this did not work. I also tried:
let stage1 = _(Game.creeps).filter( { memory: { role: 'harvester' } } ).size(4);
let stage2 = _(Game.creeps).filter( { memory: { role: 'extender' } } ).size(2);
if(stage1 === false) { if(harvesters.length < 4) { var newName = 'harvester' + Game.time; console.log('Spawning new harvester: ' + newName); Game.spawns['Spawn1'].spawnCreep([WORK,WORK,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE], newName, {memory: {role: 'harvester'}}); }} else if (stage1 === true) { if(extenders.length < 0) { var newName = 'extender' + Game.time; console.log('Spawning new extender: ' + newName); Game.spawns['Spawn1'].spawnCreep([CARRY,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE,MOVE], newName, {memory: {role: 'extender'}}); }} if(stage1 & stage2 === true) { if(southharvesters.length < 0) { var newName = 'southharvester' + Game.time; console.log('Spawning new southharvester: ' + newName); Game.spawns['Spawn1'].spawnCreep([WORK,WORK,CARRY,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE], newName, {memory: {role: 'southharvester'}}); }}
This pattern I continued on through all my different creep roles in order of priority but it did not work although no error message came up. Is there a particular way in javascript which is best to create priority ques? Thanks for your help.
-
RE: Harvesting from multiple sources within a room
@famine Thanks for pointing me in the right direction, I used let. The code is a bit-long winded - I am surprised it worked tbh - but it did
run: function(creep) { let prospect = new RoomPosition(34,4, 'W57S45'); let home = new RoomPosition(16,34, 'W57S44'); if(creep.memory.prospecting && (!creep.pos.isNearTo(prospect) || creep.carry.energy === creep.carryCapacity)) { creep.memory.prospecting = false; creep.say('⛏ seeking'); } if(!creep.memory.prospecting && (creep.carry.energy < creep.carryCapacity && creep.pos.isNearTo(prospect))) { creep.memory.prospecting = true; creep.say('Container'); } if(creep.memory.prospecting) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } } if(!creep.memory.prospecting && creep.carry.energy < creep.carryCapacity) { creep.moveTo(prospect) } else if (!creep.memory.prospecting && creep.carry.energy === creep.carryCapacity) { creep.moveTo(home); var targets = creep.pos.findClosestByPath(FIND_STRUCTURES, { filter: (s) => (s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE) && s.store.energy < s.storeCapacity }); if(targets) { if(creep.transfer(targets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(targets, {visualizePathStyle: {stroke: '#ffffff'}}); } } }
-
RE: Transferring energy to storage
@wtfrank @Saruss @famine Thanks a lot for the explanation guys now I understand why it is different and the code is working all good also.
-
Transferring energy to storage
Why is the coding excessively cryptic? It seems that the command which works fine when transferring energy to STRUCTURE_EXTENSION does not also work for STRUCTURE_STORAGE or CONTAINER. Any help would be great, see my current code below:
run: function(creep) { if(creep.carry.energy < creep.carryCapacity) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[1]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[1], {visualizePathStyle: {stroke: '#ffaa00'}}); } } else { var targets = creep.pos.findClosestByPath(FIND_STRUCTURES, { filter: (s) => (s.structureType == STRUCTURE_STORAGE) && s.energy < s.energyCapacity }); if(targets) { if(creep.transfer(targets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(targets, {visualizePathStyle: {stroke: '#ffffff'}});
-
RE: Harvesting from multiple sources within a room
Thanks a great deal for your help guys, I managed to use your advice to get the harvesters to use both sources in my room currently just be writing sources[1] but I will work on upgrading to a dedicated stationary miner soon. Currently, I am having trouble getting my distance harvester to reliably go to a neighbouring room and harvest a source there. It goes there sometimes (with some variations of the code below but not consistently). If anyone could give me any advice on how to tweak it I would be very grateful:
var roleDistanceharvester = {
/** @param {Creep} creep **/ run: function(creep) { if(creep.carry.energy < creep.carryCapacity) { var prospect = creep.moveTo(new RoomPosition(20,1, 'W57S45'))}; if((creep.pos.isEqualTo(20,1, 'W57S45') || creep.pos.isNearTo(20,1, 'W57S45')) && creep.carry.energy < creep.carryCapacity) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } } else { if(creep.carry.energy = creep.carryCapacity) { const stores = creep.pos.findClosestByPath(FIND_STRUCTURES, { filter: (s) => (s.structureType == STRUCTURE_EXTENSION || s.structureType == STRUCTURE_SPAWN || s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE) && s.energy < s.energyCapacity}); var targets = creep.moveTo(new RoomPosition(12,16, 'W57S44')); if(stores) { if(creep.transfer(stores, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(stores, {visualizePathStyle: {stroke: '#ffffff'}}); } } } }
} }; module.exports = roleDistanceharvester;
-
Harvesting from multiple sources within a room
I cannot understand how to use a source's Id to create a designated team of harvesters to go to that resource instead of the one closest to my spawn. Currently, all my harvesters only go to the primary source using this code:
run: function(creep) { if(creep.carry.energy < creep.carryCapacity) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } }
Please, could someone help me understand how I can store a particular source's Id into memory and then instruct a separate team of harvesters to go to that source? I have created a new role - role.southharvester - but cannot formulate the code to get it to harvest the other source.
-
RE: Defining Individual sources
I am struggling with this exact same problem. Currently, my creeps only harvest from one resource using creep.room.find(FIND_SOURCES). I want to create a team that harvests the other source in my room but can't find any instruction on how to order the creeps to go to a particular source ID. Did you get any further in sorting this out?