-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.builder.js
65 lines (55 loc) · 2.22 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// var checkedOutSource = 0
var creepHarvest = require('creep.harvest');
var roleDoctor = require('role.doctor');
var roleBuilder = {
/**
* run - description
*
* @param {type} creep description
* @return {type} description
*/
run: function(creep) {
if(creep.memory.building === undefined) {
creep.memory.building = creep.store.getUsedCapacity() > 30
}
if(creep.memory.building && creep.store.getUsedCapacity() == 0) {
creep.memory.building = false;
creep.say('🔄 harvest');
}
if(!creep.memory.building && creep.store.getFreeCapacity() == 0) {
creep.memory.building = true;
creep.say('🚧 build');
}
if(creep.memory.building) {
var target = creep.pos.findClosestByPath(FIND_CONSTRUCTION_SITES);
creep.memory.harvestTargetSourceId = undefined
creep.memory.harvestTargetSourceIndex = undefined
if(target) { // have construction site
if(creep.build(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffb752'}});
// creep.say('↘️ To ' + targets[0].)
}
} else if (!roleDoctor.repairJob(creep)) { // else if try repair something
// nothing to repair
var counter = 0
for (let name in Game.creeps) {
let creep = Game.creeps[name]
if (creep.memory.role == 'builder') { counter++ }
}
if (counter <= 1) {
console.log('role.builder: last builder, ' + creep.name + ' so moving it to Spawn 1')
creep.moveTo(Game.spawns['Spawn1'], {visualizePathStyle: {stroke: '#fafafa'}}) // just move out of the way
} else {
console.log('role.builder: ' +creep.name + ' not doing anything, erasing his memory💾')
creep.memory = undefined
}
} else {
// builder went repaired something
}
}
else { // not building, so go harvest
creepHarvest.run(creep)
}
}
};
module.exports = roleBuilder;