-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.builder.js
49 lines (45 loc) · 1.79 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
var roleUpgrader = require('role.upgrader');
var Utils = require('help.functions');
require('prototype.Creep')();
module.exports = {
// a function to run the logic for this role
run: function(creep) {
if(creep.spawning){ return;}
if(creep.memory.imHome == false)
{ creep.moveToHomeRoom();}
// if creep is trying to complete a constructionSite but has no energy left
switch(creep.carry.energy)
{ case 0: creep.memory.working = false; break;
case creep.carryCapacity: creep.memory.working = true; break;
}
// if creep is supposed to complete a constructionSite
if (creep.memory.working == true) {
// find closest constructionSite
// if(!_.isUndefined(creep.pos.findInRange(FIND_SOURCES, 1))){
// creep.move()
// }
var constructionSite = creep.pos.findClosestByPath(FIND_CONSTRUCTION_SITES);
// if one is found
if (constructionSite != undefined) {
// try to build, if the constructionSite is not in range
if (creep.build(constructionSite) == ERR_NOT_IN_RANGE) {
// move towards the constructionSite
creep.moveTo(constructionSite)//, [{reusePath}];
}
}
// if no constructionSite is found
else {
// go upgrading the controller
// if(creep.room.controller.my)
roleUpgrader.run(creep);
// else;
// creep.memory.role = 'remote';
}
}
// if creep is supposed to harvest energy from source
else {
// find closest source
Utils.harvest(creep, null);
}
}
};