-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.scavenger.js
32 lines (30 loc) · 1.05 KB
/
role.scavenger.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"use strict";
var jobScavenge = require('job.scavenge');
module.exports = {
run: function(creep) {
if(creep.memory[MEMORY_JOB] != JOB_SCAVENGE && creep.carry.energy == 0) {
if (!creep.isAtDestinationRoom()) {
creep.moveToDestination();
return;
}
creep.memory[MEMORY_JOB] = JOB_SCAVENGE;
return;
} else if(creep.memory[MEMORY_JOB] == JOB_SCAVENGE && creep.carry.energy == creep.carryCapacity) {
creep.memory[MEMORY_JOB] = JOB_RETURN;
creep.memory[MEMORY_CONTAINER] = undefined;
}
if(creep.memory[MEMORY_JOB] == JOB_SCAVENGE) {
if (!jobScavenge.run(creep)) {
if (creep.carry.energy > 0) {
creep.memory[MEMORY_JOB] = JOB_RETURN;
}
}
}
if(creep.memory[MEMORY_JOB] == JOB_RETURN) {
var result = creep.returnToStorage();
if (!result) {
creep.memory[MEMORY_JOB] = JOB_SCAVENGE;
}
}
}
};