-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.linkFiller.js
139 lines (107 loc) · 3.82 KB
/
role.linkFiller.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var roleUpgrader = require("role.upgrader");
var linksMgr = require("mgr.links");
var collect = require("collect");
var fill = require("fill");
var roleFiller = {
/** @param {Creep} creep **/
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);
//console.log(creep.pos)
/* var targets = creep.room.find(FIND_STRUCTURES,{filter: (structure) => return (structure.structureType == STRUCTURE_STORAGE ||structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) && structure.store.getFreeCapacity() > 0});
*///finding all storage containers not spawn with space left
var linkToFill = Game.getObjectById(creep.memory.link);
if (creep.memory.storing) {
//setup link
while (!linkToFill || Memory[roomName].links.storageLink == -1) {
//find all links
var links = linksMgr.findLinksInRoom(room);
//console.log("Links" + links);
//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.carry.energy == 0) {
creep.memory.storing = false;
creep.say('⚡');
} else {
//console.log(creep.pos)
switch (creep.memory.team) {
case 0:
//var linkToFill = Game.getObjectById(creep.memory.link);
//console.log(link)
if (upgradeLink.store.getFreeCapacity(RESOURCE_ENERGY) < 50) {
collect.links(creep);
if (creep.carry.energy == creep.carryCapacity) {
creep.memory.storing = true;
creep.say('🧪');
}
} else {
if (linkToFill.store.getFreeCapacity(RESOURCE_ENERGY) > 500) {
fill.fillLinks(creep);
} else if (room.terminal && room.terminal.store.getUsedCapacity(RESOURCE_ENERGY) < 45000) {
creep.memory.mineral = RESOURCE_ENERGY;
fill.fillTerminals(creep);
} else {
creep.memory.mineral = RESOURCE_ENERGY;
fill.fillContainers(creep);
}
}
break;
case 1:
console.log("im special")
default:
//var linkToFill = Game.getObjectById(creep.memory.link);
//console.log(link)
var container = Game.getObjectById(creep.memory.container)
//console.log(container)
if (linkToFill.store.getFreeCapacity(RESOURCE_ENERGY) > 250) {
fill.fillLinks(creep);
//console.log("valid container" + Game.getObjectById(creep.memory.container).store.getUsedCapacity(RESOURCE_ENERGY)/Game.getObjectById(creep.memory.container).store.getCapacity(RESOURCE_ENERGY))
creep.memory.mineral = RESOURCE_ENERGY;
fill.fillTerminals(creep);
} else {
}
break;
}
}
} else {
//make sure memory created
creep.memory.storing = false;
//changing status
if (creep.carry.energy == creep.carryCapacity) {
creep.memory.storing = true;
creep.say('🧪');
} else {
switch (creep.memory.team) {
case 1:
console.log("Im Special")
case 0:
default:
//console.log(upgradeLink);
if (upgradeLink.store.getFreeCapacity(RESOURCE_ENERGY) < 50) {
fill.fillContainers(creep);
if (creep.carry.energy == 0) {
creep.memory.storing = false;
creep.say('⚡')
}
} else {
//if link is not full grab from container
if (linkToFill && linkToFill.store.getFreeCapacity(RESOURCE_ENERGY) < 5) {
console.log("Excess Energy in upgrade Link")
collect.links(creep);
} else {
collect.containers(creep);
}
}
}
}
}
//creep.moveTo(Game.flags["home"],{visualizePathStyle: {stroke: '#ffaa00'}});
}
};
module.exports = roleFiller;