From cbc99ae65b122121902e0387c798761cbf208cc7 Mon Sep 17 00:00:00 2001 From: Peery Date: Sun, 25 Sep 2022 01:17:20 +0200 Subject: [PATCH] SetupOverlord now builds a harvester (WIP) SetupOverlord now builds a harvester if possible with the given spawns. --- src/creeps/harvester.js | 10 +++++++--- src/hivemind/hivemind.js | 4 +++- src/overlords/setup_overlord.js | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/creeps/harvester.js b/src/creeps/harvester.js index 1610572..70637d6 100644 --- a/src/creeps/harvester.js +++ b/src/creeps/harvester.js @@ -33,10 +33,14 @@ var roleHarvester = { /** * Runs the logic and actions of the harvester - * @param {string} creep_name + * @param {Creep} creep */ - run: function(creep_name) { - console.log("roleHarvester: run() " + creep_name) + run: function(creep) { + console.log("roleHarvester: run() " + creep); + let sources = creep.room.find(FIND_SOURCES_ACTIVE); + for (let source in sources) { + console.log("Found source ", source.name); + } }, }; diff --git a/src/hivemind/hivemind.js b/src/hivemind/hivemind.js index ebfc9bd..47939b3 100644 --- a/src/hivemind/hivemind.js +++ b/src/hivemind/hivemind.js @@ -98,7 +98,9 @@ var hivemind = { let creep = Game.creeps[name]; let creep_role = creep.memory.role console.log("Hivemind: Running creep \""+name+"|"+creep_role+"\""); - // TODO run creep's role + let role = _.filter(roles, function(node) {return node.ident === creep_role})[0]; + + role.obj.run(creep); } }, }; diff --git a/src/overlords/setup_overlord.js b/src/overlords/setup_overlord.js index 49dbc8d..cebab27 100644 --- a/src/overlords/setup_overlord.js +++ b/src/overlords/setup_overlord.js @@ -24,7 +24,7 @@ setup_overlord.prototype.run = function () { // TODO somehow these aren't chang let spawn = Game.spawns[this.underlings['spawns']]; if (spawn.store[RESOURCE_ENERGY] > harvester.min_cost) { // can afford a harvester console.log("SetupOverlord: Spawn "+spawn.name+" can afford a harvester! ("+harvester.min_cost+") \\o/"); - let new_harvester_name = harvester.spawn(spawn, this.id+"-0", this.id); + let new_harvester_name = harvester.spawn(spawn, this.id+"-"+this.underlings['creeps'].length, this.id); this.add_creep(new_harvester_name); break; }