summaryrefslogtreecommitdiff
path: root/src/main.js
diff options
context:
space:
mode:
authorTom Harley2018-06-26 06:48:08 +0100
committerTom Harley2018-06-26 06:48:08 +0100
commitfa5d6076ffd561b7fcbaefb122b95dea2f3f7cdf (patch)
treec95efc5c9b332862d48d4ad62d28a050cbfc0503 /src/main.js
parentUse findClosestByPath (diff)
downloadscreeps-ai-fa5d6076ffd561b7fcbaefb122b95dea2f3f7cdf.tar.gz
screeps-ai-fa5d6076ffd561b7fcbaefb122b95dea2f3f7cdf.zip

Add specific instructions for specific creep jobs.

Diffstat (limited to 'src/main.js')
-rw-r--r--src/main.js24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/main.js b/src/main.js
index e466974..f4458c3 100644
--- a/src/main.js
+++ b/src/main.js
@@ -1,7 +1,27 @@
-const harvester = require('role.harvester');
+const jobs = {
+ harvester: require('role.harvester');
+};
+
+const spawnCreep = (spawn, job, tools) => {
+ Memory.counts[job]++;
+ const name = job + Memory.counts[job];
+ spawn.spawnCreep(tools, name);
+ Game.creeps[name].memory.job = job;
+}
+
+const spawnHarvester = (spawn) => {
+ spawnCreep(spawn, 'harvester', [WORK, MOVE, CARRY]);
+}
module.exports.loop = () => {
for (const name in Game.creeps) {
- harvester.run(Game.creeps[name]);
+ const creep = Game.creeps[name];
+ const job = jobs[creep.memory.job];
+ if (job) {
+ job.run(creep);
+ } else {
+ console.err(creep.name + " is missing instructions for job "
+ + creep.memory.job);
+ }
}
}