-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.storageLinkMgr.js
67 lines (56 loc) · 2.65 KB
/
role.storageLinkMgr.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
var roleUpgrader = require("role.upgrader");
var linksMgr = require("mgr.links");
var collect = require("collect");
var fill = require("fill");
var storageLinkMgr = {
run: function (creep) {
var room = creep.room;
var roomName = room.name;
var upgradeLink = Game.getObjectById(Memory[roomName].links.upgradeLink);
var storageLink = Game.getObjectById(Memory[roomName].links.storageLink);
var linkToFill = Game.getObjectById(creep.memory.link);
if (!linkToFill || Memory[roomName].links.storageLink == -1) {
//runs when the first linkFiller has energy and is looking to fill a link
links = linksMgr.findLinksInRoom(room);
//sort by closest
links.sort((a, b) => creep.pos.getRangeTo(a) - creep.pos.getRangeTo(b));
//console.log(links);
creep.memory.link = links[0].id;
Memory[roomName].links.storageLink = creep.memory.link;
}
if (creep.memory.managing) {
if (creep.carry.energy == 0) {
creep.memory.managing = false;
} else {
//check if upgradeLink and storageLink has more than half energy
if (upgradeLink && storageLink
&& upgradeLink.store.getUsedCapacity(RESOURCE_ENERGY) > (upgradeLink.store.getCapacity(RESOURCE_ENERGY) / 2) + 100
&& storageLink.store.getUsedCapacity(RESOURCE_ENERGY) > (storageLink.store.getCapacity(RESOURCE_ENERGY) / 2) + 100) {
fill.fillContainers(creep)
} else {
fill.fillLinks(creep);
}
}
} else {
//start
creep.memory.managing = false;
if (creep.carry.energy == creep.carryCapacity) {
creep.memory.managing = true;
} else {
//check if upgradeLink and storageLink has more than half energy
if (upgradeLink && storageLink
&& upgradeLink.store.getUsedCapacity(RESOURCE_ENERGY) > ((upgradeLink.store.getCapacity(RESOURCE_ENERGY) / 2) + 100)
&& storageLink.store.getUsedCapacity(RESOURCE_ENERGY) > ((storageLink.store.getCapacity(RESOURCE_ENERGY) / 2) + 100)) {
creep.memory.link = storageLink.id;
// console.log("Take from link")
collect.links(creep);
} else {
//base condition
collect.containers(creep)
//since upgrade Link isnt full, take energy from storage out
}
}
}
}
};
module.exports = storageLinkMgr;