diff --git a/section1/role.harvester.js b/section1/role.harvester.js index 8cb4b8a..79dc6ea 100644 --- a/section1/role.harvester.js +++ b/section1/role.harvester.js @@ -2,7 +2,7 @@ var roleHarvester = { /** @param {Creep} creep **/ run: function(creep) { - if(creep.carry.energy < creep.carryCapacity) { + if(creep.store.getFreeCapacity() > 0) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0]); diff --git a/section2/role.harvester.js b/section2/role.harvester.js index bf5d4b7..2d2a5a5 100644 --- a/section2/role.harvester.js +++ b/section2/role.harvester.js @@ -2,7 +2,7 @@ var roleHarvester = { /** @param {Creep} creep **/ run: function(creep) { - if(creep.carry.energy < creep.carryCapacity) { + if(creep.store.getFreeCapacity() > 0) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0]); diff --git a/section2/role.upgrader.js b/section2/role.upgrader.js index 5c3ba14..9b406b2 100644 --- a/section2/role.upgrader.js +++ b/section2/role.upgrader.js @@ -2,7 +2,7 @@ var roleUpgrader = { /** @param {Creep} creep **/ run: function(creep) { - if(creep.carry.energy == 0) { + if(creep.store[RESOURCE_ENERGY] == 0) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0]); diff --git a/section3/role.builder.js b/section3/role.builder.js index b97c341..1cbd361 100644 --- a/section3/role.builder.js +++ b/section3/role.builder.js @@ -3,11 +3,11 @@ var roleBuilder = { /** @param {Creep} creep **/ run: function(creep) { - if(creep.memory.building && creep.carry.energy == 0) { + if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) { creep.memory.building = false; creep.say('🔄 harvest'); } - if(!creep.memory.building && creep.carry.energy == creep.carryCapacity) { + if(!creep.memory.building && creep.store.getFreeCapacity() == 0) { creep.memory.building = true; creep.say('🚧 build'); } diff --git a/section3/role.harvester.js b/section3/role.harvester.js index d14dd56..8e8618e 100644 --- a/section3/role.harvester.js +++ b/section3/role.harvester.js @@ -2,7 +2,7 @@ var roleHarvester = { /** @param {Creep} creep **/ run: function(creep) { - if(creep.carry.energy < creep.carryCapacity) { + if(creep.store.getFreeCapacity() > 0) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); @@ -12,7 +12,7 @@ var roleHarvester = { var targets = creep.room.find(FIND_STRUCTURES, { filter: (structure) => { return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && - structure.energy < structure.energyCapacity; + structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0; } }); if(targets.length > 0) { diff --git a/section4/main.js b/section4/main.js index b3bf661..1b2ac21 100644 --- a/section4/main.js +++ b/section4/main.js @@ -14,8 +14,10 @@ module.exports.loop = function () { console.log('Harvesters: ' + harvesters.length); if(harvesters.length < 2) { - var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,MOVE], undefined, {role: 'harvester'}); + var newName = 'Harvester' + Game.time; console.log('Spawning new harvester: ' + newName); + Game.spawns['Spawn1'].spawnCreep([WORK,CARRY,MOVE], newName, + {memory: {role: 'harvester'}}); } if(Game.spawns['Spawn1'].spawning) { diff --git a/section4/role.harvester.js b/section4/role.harvester.js index d14dd56..8e8618e 100644 --- a/section4/role.harvester.js +++ b/section4/role.harvester.js @@ -2,7 +2,7 @@ var roleHarvester = { /** @param {Creep} creep **/ run: function(creep) { - if(creep.carry.energy < creep.carryCapacity) { + if(creep.store.getFreeCapacity() > 0) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); @@ -12,7 +12,7 @@ var roleHarvester = { var targets = creep.room.find(FIND_STRUCTURES, { filter: (structure) => { return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && - structure.energy < structure.energyCapacity; + structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0; } }); if(targets.length > 0) { diff --git a/section4/role.upgrader.js b/section4/role.upgrader.js index 8003c0e..f95aafa 100644 --- a/section4/role.upgrader.js +++ b/section4/role.upgrader.js @@ -3,11 +3,11 @@ var roleUpgrader = { /** @param {Creep} creep **/ run: function(creep) { - if(creep.memory.upgrading && creep.carry.energy == 0) { + if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) { creep.memory.upgrading = false; creep.say('🔄 harvest'); } - if(!creep.memory.upgrading && creep.carry.energy == creep.carryCapacity) { + if(!creep.memory.upgrading && creep.store.getFreeCapacity() == 0) { creep.memory.upgrading = true; creep.say('⚡ upgrade'); } diff --git a/section5/role.builder.js b/section5/role.builder.js index b97c341..1cbd361 100644 --- a/section5/role.builder.js +++ b/section5/role.builder.js @@ -3,11 +3,11 @@ var roleBuilder = { /** @param {Creep} creep **/ run: function(creep) { - if(creep.memory.building && creep.carry.energy == 0) { + if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) { creep.memory.building = false; creep.say('🔄 harvest'); } - if(!creep.memory.building && creep.carry.energy == creep.carryCapacity) { + if(!creep.memory.building && creep.store.getFreeCapacity() == 0) { creep.memory.building = true; creep.say('🚧 build'); } diff --git a/section5/role.harvester.js b/section5/role.harvester.js index e6d1bc3..8963f0d 100644 --- a/section5/role.harvester.js +++ b/section5/role.harvester.js @@ -2,7 +2,7 @@ var roleHarvester = { /** @param {Creep} creep **/ run: function(creep) { - if(creep.carry.energy < creep.carryCapacity) { + if(creep.store.getFreeCapacity() > 0) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); @@ -13,7 +13,8 @@ var roleHarvester = { filter: (structure) => { return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN || - structure.structureType == STRUCTURE_TOWER) && structure.energy < structure.energyCapacity; + structure.structureType == STRUCTURE_TOWER) && + structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0; } }); if(targets.length > 0) { diff --git a/section5/role.upgrader.js b/section5/role.upgrader.js index 8003c0e..f95aafa 100644 --- a/section5/role.upgrader.js +++ b/section5/role.upgrader.js @@ -3,11 +3,11 @@ var roleUpgrader = { /** @param {Creep} creep **/ run: function(creep) { - if(creep.memory.upgrading && creep.carry.energy == 0) { + if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) { creep.memory.upgrading = false; creep.say('🔄 harvest'); } - if(!creep.memory.upgrading && creep.carry.energy == creep.carryCapacity) { + if(!creep.memory.upgrading && creep.store.getFreeCapacity() == 0) { creep.memory.upgrading = true; creep.say('⚡ upgrade'); }