-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrole.remoteharvester.js
55 lines (49 loc) · 2.03 KB
/
srole.remoteharvester.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
53
54
55
var helper = require('helper');
var serviceCodex = require('service.codex');
var roleRemoteHarvester = {
spawn: function(spawner, memory) {
//spawner.createCreep([MOVE,MOVE,MOVE,WORK,WORK,CARRY,CARRY,CARRY,CARRY,CARRY,CARRY], undefined, memory);
spawner.createCreep([MOVE,WORK,CARRY,CARRY,CARRY,CARRY], undefined, memory);
//spawner.createCreep([MOVE,WORK,CARRY,CARRY,CARRY], undefined, memory);
},
/** @param {Creep} creep **/
run: function(creep) {
var basePos = Game.flags[creep.memory.flagBase].pos;
var remotePos = Game.flags[creep.memory.flagRemote].pos;
var drinkhere = null;
try {
drinkhere = helper.findClosestRawSource(remotePos);
} catch (ex) {
}
if (creep.memory.gather) {
if (creep.carry.energy < creep.carryCapacity) {
creep.say('Rh+');
if (drinkhere === null) {
creep.moveTo(drinkhere);
return;
} else if (helper.getEnergyFrom(creep, drinkhere) == ERR_NOT_IN_RANGE) {
creep.say('Rh->+');
creep.moveTo(drinkhere);
}
} else {
creep.say('Rh/');
creep.memory.gather = false;
}
} else {
creep.memory.gather = false;
if (creep.carry.energy == 0) {
creep.say('Rh\\');
creep.memory.gather = true;
} else {
var target = basePos.findClosestByRange(FIND_MY_STRUCTURES, {filter: (s) => (s.structureType === STRUCTURE_STORAGE)});
// var target = basePos.findClosestByPath(FIND_STRUCTURES, {filter: (s) => (s.structureType === STRUCTURE_CONTROLLER)});
creep.say('Rh@');
if (helper.putEnergyInto(creep, target) == ERR_NOT_IN_RANGE) {
creep.say('Rh->@');
creep.moveTo(target.pos);
}
}
}
}
};
module.exports = roleRemoteHarvester;