From 511fb4e6bd8a5e736f91b1af676eec94257be462 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Tue, 15 Oct 2019 02:14:27 +0100 Subject: Various changes to pathfinding --- src/main.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/main.js') diff --git a/src/main.js b/src/main.js index 398ce5c..a4ff3b9 100644 --- a/src/main.js +++ b/src/main.js @@ -1,3 +1,5 @@ +// vim: tw=80 ts=2 sw=2 et + const jobs = { harvester: require('role.harvester'), upgrader: require('role.upgrader'), @@ -6,20 +8,28 @@ const jobs = { offender: require('role.offender') }; +Memory.counts = {}; + module.exports.loop = () => { - for (const job in Memory.counts) { + for (const job in jobs) { Memory.counts[job] = 0; } - for (const name in Game.creeps) { - const creep = Game.creeps[name]; - const job = jobs[creep.memory.job]; - Memory.counts[creep.memory.job]++; - if (job) { - job.run(creep); + + for (const name in Memory.creeps) { + if (!Game.creeps[name]) { + delete Memory.creeps[name]; } else { - error.log(`${creep.name} cannot find ${creep.memory.job} instructions`); + const creep = Game.creeps[name]; + const job = jobs[creep.memory.job]; + Memory.counts[creep.memory.job]++; + if (job) { + job.run(creep); + } else { + creep.error(`cannot find ${creep.memory.job} instructions`); + } } } + for (const name in Game.spawns) { jobs.spawner.run(Game.spawns[name]); } -- cgit v1.2.1