-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.enemyRoomHauler.js
79 lines (76 loc) · 2.57 KB
/
role.enemyRoomHauler.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module.exports = {
// a function to run the logic for this role
/** @param {Creep} creep */
run: function(creep) {
const totalCarryAmount = _.sum(creep.carry);
// if target is defined and creep is not in target room
if (creep.memory.target != undefined &&
creep.room.name != creep.memory.target &&
creep.memory.working == false) {
// find exit to target room
var exit = creep.room.findExitTo(creep.memory.target);
// move to exit
creep.travelTo(creep.pos.findClosestByRange(exit));
// return the function to not do anything else
return;
}
// if creep is bringing energy to a structure but has no energy left
if (creep.memory.working == true && totalCarryAmount == 0) {
if(creep.ticksToLive > 200){
// switch state
creep.memory.working = false;
}
else{
creep.suicide();
}
}
// if creep is picking up energy but is full
else if (creep.memory.working == false && totalCarryAmount == creep.carryCapacity) {
// switch state
creep.memory.working = true;
}
// if creep is supposed to transfer minerals to a structure
if (creep.memory.working == true) {
if(creep.room.name == creep.memory.home){
var terminal = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: s => (s.structureType == STRUCTURE_TERMINAL)
});
if(terminal != undefined){
if (creep.transfer(terminal, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
// move towards it
creep.travelTo(terminal);
}
}
}
// if not in target room
else {
// find exit to target room
var exit = creep.room.findExitTo(creep.memory.home);
// move to exit
creep.travelTo(creep.pos.findClosestByRange(exit));
}
}
// if creep is supposed to get energy
else {
// if creep is in target room
if (creep.room.name == creep.memory.target) {
var enemyTerminal = creep.pos.findClosestByPath(FIND_HOSTILE_STRUCTURES, {
filter: s => (s.structureType == STRUCTURE_TERMINAL)
});
if(enemyTerminal != undefined){
if (creep.withdraw(enemyTerminal, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
// move towards it
creep.travelTo(enemyTerminal);
}
}
}
// if not in target room
else {
// find exit to target room
var exit = creep.room.findExitTo(creep.memory.target);
// move to exit
creep.travelTo(creep.pos.findClosestByRange(exit));
}
}
}
};