-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrole.builder.js
58 lines (58 loc) · 2.23 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
/**
* @author Nicolas Durant
* @email [email protected]
* @create date 2019-12-01 21:59:53
* @modify date 2019-12-03 11:13:17
* @desc Role for screeps that should build construction sites.
*/
var _UPGRADER = require('role.upgrader');
module.exports = {
/**
* The function that is defining the creeps behavior.
*
* @param {any} creep - Creep Object
*
* @memberOf Upgrader
*/
run: function (creep){
// room controller that we sent the upgrader to
const roomController = creep.room.controller;
// the creep is fully packed
if (creep.memory.idle && creep.store.getUsedCapacity() === creep.store.getCapacity()){
creep.say('Harvested👍')
creep.memory.idle = false;
}
// if the creep is empty or has not the idle memory yet
else if (!creep.memory.idle && creep.store.getUsedCapacity() === 0){
creep.say('Deposited👍')
creep.memory.idle = true;
}
// if the creep is idle, we sent it to the next source that is still harvestable (ACTIVE)
if (creep.memory.idle) {
const target = creep.pos.findClosestByRange(FIND_SOURCES_ACTIVE);
if (creep.harvest(target) === ERR_NOT_IN_RANGE){
if (creep.memory.status != 'to_work'){
creep.say('To work 🤮')
creep.memory.status = `to_work`
}
creep.moveTo(target, {reusePath: 5});
}
}
// else we sent it to the next construction site to transfer energy
else {
const constructionSite = creep.pos.findClosestByPath(FIND_CONSTRUCTION_SITES);
if (constructionSite) {
if (creep.build(constructionSite) === ERR_NOT_IN_RANGE){
if (creep.memory.status != 'to_build'){
creep.say('To Build 🔨')
creep.memory.status = `to_build`
}
creep.moveTo(constructionSite, {reusePath: 5});
}
}// if there are no more constructions to be build atm, we make the creep an upgrader
else{
_UPGRADER.run(creep);
}
}
}
};