-
Notifications
You must be signed in to change notification settings - Fork 1
/
work.basic.js
52 lines (48 loc) · 1.7 KB
/
work.basic.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
let messages = require('./messages');
let objects = require('./objects');
/**
* Source work : if source job is not done, then move to source, then do the job
*
* @param creepjs
* @param creep Creep
*/
module.exports.sourceWork = function(creepjs, creep)
{
let error = creepjs.sourceWork(creep);
if (error === creepjs.NEXT_STEP) creepjs.nextStep(creep, 'targetWork');
if (error === ERR_NOT_IN_RANGE) creep.moveTo(objects.get(creep, creep.memory.source));
else if (error) creep.say('s:' + messages.error(error));
};
/**
* Target work : if target work is not done, then move to target, then do the job
*
* @param creepjs
* @param creep Creep
*/
module.exports.targetWork = function(creepjs, creep)
{
let error = creepjs.targetWork(creep);
if (error === creepjs.NEXT_STEP) creepjs.nextStep(creep, 'sourceWork');
else if (error === ERR_NOT_IN_RANGE) creep.moveTo(objects.get(creep, creep.memory.target));
else if (error) creep.say('t:' + messages.error(error));
};
/**
* Basic not planned work : search source, fill, search target, target work, then loop
*
* @param creepjs
* @param creep Creep
*/
module.exports.work = function(creepjs, creep)
{
if (!creep.memory.step) creepjs.nextStep(creep, 'spawning');
switch (creep.memory.step) {
case 'spawning': if (!creep.spawning) creepjs.nextStep(creep, 'sourceWork'); break;
case 'goToSource': creepjs.nextStep(creep, 'sourceWork'); break;
case 'goToTarget': creepjs.nextStep(creep, 'targetWork'); break;
}
switch (creep.memory.step) {
case 'sourceWork': this.sourceWork(creepjs, creep); break;
case 'targetWork': this.targetWork(creepjs, creep); break;
default: creepjs.nextStep(creep, 'spawning');
}
};