From 9d465342f58fa0a67dd43f9a30abaa88d5540467 Mon Sep 17 00:00:00 2001 From: Artem Chivchalov Date: Mon, 6 Feb 2017 17:29:32 +0300 Subject: [PATCH 1/3] Add visualizations --- section3/role.builder.js | 8 ++++---- section3/role.harvester.js | 12 ++++++------ section4/main.js | 11 ++++++++++- section4/role.harvester.js | 12 ++++++------ section4/role.upgrader.js | 8 ++++---- section5/role.builder.js | 8 ++++---- section5/role.harvester.js | 14 +++++++------- section5/role.upgrader.js | 8 ++++---- 8 files changed, 45 insertions(+), 36 deletions(-) diff --git a/section3/role.builder.js b/section3/role.builder.js index 19a96b5..b97c341 100644 --- a/section3/role.builder.js +++ b/section3/role.builder.js @@ -5,25 +5,25 @@ var roleBuilder = { if(creep.memory.building && creep.carry.energy == 0) { creep.memory.building = false; - creep.say('harvesting'); + creep.say('🔄 harvest'); } if(!creep.memory.building && creep.carry.energy == creep.carryCapacity) { creep.memory.building = true; - creep.say('building'); + creep.say('🚧 build'); } if(creep.memory.building) { var targets = creep.room.find(FIND_CONSTRUCTION_SITES); if(targets.length) { if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) { - creep.moveTo(targets[0]); + creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); } } } else { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { - creep.moveTo(sources[0]); + creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } } } diff --git a/section3/role.harvester.js b/section3/role.harvester.js index d5bda0e..d14dd56 100644 --- a/section3/role.harvester.js +++ b/section3/role.harvester.js @@ -5,19 +5,19 @@ var roleHarvester = { 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]); + creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } } else { var targets = creep.room.find(FIND_STRUCTURES, { - filter: (structure) => { - return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && - structure.energy < structure.energyCapacity; - } + filter: (structure) => { + return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && + structure.energy < structure.energyCapacity; + } }); if(targets.length > 0) { if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { - creep.moveTo(targets[0]); + creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); } } } diff --git a/section4/main.js b/section4/main.js index 4989b43..b3bf661 100644 --- a/section4/main.js +++ b/section4/main.js @@ -18,6 +18,15 @@ module.exports.loop = function () { console.log('Spawning new harvester: ' + newName); } + if(Game.spawns['Spawn1'].spawning) { + var spawningCreep = Game.creeps[Game.spawns['Spawn1'].spawning.name]; + Game.spawns['Spawn1'].room.visual.text( + '🛠️' + spawningCreep.memory.role, + Game.spawns['Spawn1'].pos.x + 1, + Game.spawns['Spawn1'].pos.y, + {align: 'left', opacity: 0.8}); + } + for(var name in Game.creeps) { var creep = Game.creeps[name]; if(creep.memory.role == 'harvester') { @@ -27,4 +36,4 @@ module.exports.loop = function () { roleUpgrader.run(creep); } } -} +} \ No newline at end of file diff --git a/section4/role.harvester.js b/section4/role.harvester.js index d5bda0e..d14dd56 100644 --- a/section4/role.harvester.js +++ b/section4/role.harvester.js @@ -5,19 +5,19 @@ var roleHarvester = { 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]); + creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } } else { var targets = creep.room.find(FIND_STRUCTURES, { - filter: (structure) => { - return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && - structure.energy < structure.energyCapacity; - } + filter: (structure) => { + return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && + structure.energy < structure.energyCapacity; + } }); if(targets.length > 0) { if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { - creep.moveTo(targets[0]); + creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); } } } diff --git a/section4/role.upgrader.js b/section4/role.upgrader.js index ecad44c..8003c0e 100644 --- a/section4/role.upgrader.js +++ b/section4/role.upgrader.js @@ -5,22 +5,22 @@ var roleUpgrader = { if(creep.memory.upgrading && creep.carry.energy == 0) { creep.memory.upgrading = false; - creep.say('harvesting'); + creep.say('🔄 harvest'); } if(!creep.memory.upgrading && creep.carry.energy == creep.carryCapacity) { creep.memory.upgrading = true; - creep.say('upgrading'); + creep.say('⚡ upgrade'); } if(creep.memory.upgrading) { if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) { - creep.moveTo(creep.room.controller); + creep.moveTo(creep.room.controller, {visualizePathStyle: {stroke: '#ffffff'}}); } } else { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { - creep.moveTo(sources[0]); + creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } } } diff --git a/section5/role.builder.js b/section5/role.builder.js index 19a96b5..b97c341 100644 --- a/section5/role.builder.js +++ b/section5/role.builder.js @@ -5,25 +5,25 @@ var roleBuilder = { if(creep.memory.building && creep.carry.energy == 0) { creep.memory.building = false; - creep.say('harvesting'); + creep.say('🔄 harvest'); } if(!creep.memory.building && creep.carry.energy == creep.carryCapacity) { creep.memory.building = true; - creep.say('building'); + creep.say('🚧 build'); } if(creep.memory.building) { var targets = creep.room.find(FIND_CONSTRUCTION_SITES); if(targets.length) { if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) { - creep.moveTo(targets[0]); + creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); } } } else { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { - creep.moveTo(sources[0]); + creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } } } diff --git a/section5/role.harvester.js b/section5/role.harvester.js index f72e8b8..e6d1bc3 100644 --- a/section5/role.harvester.js +++ b/section5/role.harvester.js @@ -5,20 +5,20 @@ var roleHarvester = { 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]); + creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } } else { var targets = creep.room.find(FIND_STRUCTURES, { - filter: (structure) => { - return (structure.structureType == STRUCTURE_EXTENSION || - structure.structureType == STRUCTURE_SPAWN || - structure.structureType == STRUCTURE_TOWER) && structure.energy < structure.energyCapacity; - } + filter: (structure) => { + return (structure.structureType == STRUCTURE_EXTENSION || + structure.structureType == STRUCTURE_SPAWN || + structure.structureType == STRUCTURE_TOWER) && structure.energy < structure.energyCapacity; + } }); if(targets.length > 0) { if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { - creep.moveTo(targets[0]); + creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}}); } } } diff --git a/section5/role.upgrader.js b/section5/role.upgrader.js index ecad44c..8003c0e 100644 --- a/section5/role.upgrader.js +++ b/section5/role.upgrader.js @@ -5,22 +5,22 @@ var roleUpgrader = { if(creep.memory.upgrading && creep.carry.energy == 0) { creep.memory.upgrading = false; - creep.say('harvesting'); + creep.say('🔄 harvest'); } if(!creep.memory.upgrading && creep.carry.energy == creep.carryCapacity) { creep.memory.upgrading = true; - creep.say('upgrading'); + creep.say('⚡ upgrade'); } if(creep.memory.upgrading) { if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) { - creep.moveTo(creep.room.controller); + creep.moveTo(creep.room.controller, {visualizePathStyle: {stroke: '#ffffff'}}); } } else { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { - creep.moveTo(sources[0]); + creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}}); } } } From 8327df748685fe09354961e7f773b3d41a867d08 Mon Sep 17 00:00:00 2001 From: Artem Chivchalov Date: Thu, 28 Sep 2017 11:29:34 +0300 Subject: [PATCH 2/3] replace `createCreep` with `spawnCreep` --- section4/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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) { From 0fc8e9d2d6fe55415d39cf1a0118297480e275f3 Mon Sep 17 00:00:00 2001 From: Artem Chivchalov Date: Wed, 23 Oct 2019 15:08:22 +0300 Subject: [PATCH 3/3] update to new store format --- section1/role.harvester.js | 2 +- section2/role.harvester.js | 2 +- section2/role.upgrader.js | 2 +- section3/role.builder.js | 4 ++-- section3/role.harvester.js | 4 ++-- section4/role.harvester.js | 4 ++-- section4/role.upgrader.js | 4 ++-- section5/role.builder.js | 4 ++-- section5/role.harvester.js | 5 +++-- section5/role.upgrader.js | 4 ++-- 10 files changed, 18 insertions(+), 17 deletions(-) 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/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'); }