-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.builder.js
46 lines (40 loc) · 1.39 KB
/
role.builder.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
var helper = require('helper');
var foreman = require('service.foreman');
var roleBuilder = {
/** @param {Creep} creep **/
run: function(creep) {
if(creep.memory.building && creep.carry.energy == 0) {
creep.memory.building = false;
creep.say('b+');
}
if(!creep.memory.building && creep.carry.energy == creep.carryCapacity) {
creep.memory.building = true;
creep.say('b&');
}
if(creep.memory.building) {
var buildTarget = null;
buildTarget = foreman.nextThingToBuild(creep.pos, false);
if (buildTarget) {
console.log(creep.name+' build '+buildTarget.pos);
creep.say('b#');
if(creep.build(buildTarget) == ERR_NOT_IN_RANGE) {
creep.say('b->#');
creep.moveTo(buildTarget);
}
return;
}
}
else {
// var sources = creep.room.find(FIND_SOURCES);
// helper.harvestSource(creep, sources[0]);
var store = helper.findMyClosestEnergyStoreToUse(creep.pos);
if (store !== null) {
creep.say('b-load');
helper.harvestSource(creep, store, 'b');
} else {
creep.say('b-HELP Store');
}
}
}
};
module.exports = roleBuilder;