-
Notifications
You must be signed in to change notification settings - Fork 0
/
structure.link.js
40 lines (36 loc) · 1.7 KB
/
structure.link.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
var Cache = require('help.cache');
var Const = require('help.constants');
var Utils = require('help.functions');
module.exports = {
run: function(room, cache ) {
if(Game.time % Const.LINK_RUN_DELAY == 0) {
var links = Utils.findStructuresByType(room, STRUCTURE_LINK);
if(_.isUndefined(Memory.rooms[room.name].links)){
Memory.rooms[room.name].links = {};
}
var controllerLink = undefined;
var storageLink = undefined;
for(link of links) {
if(link.pos.findInRange(FIND_MY_STRUCTURES, 5, {filter: function(s) { return s.structureType == STRUCTURE_CONTROLLER } } ) >= 0 ) {
storageLink = link;
Memory.rooms[room.name].links.storageLink = link.id;
cache.set(room.name+'_StorageLink', link);
continue;
}
if(link.pos.findInRange(FIND_MY_STRUCTURES, 5, {filter: function(s) { return s.structureType == STRUCTURE_STORAGE } } ) >= 0 ) {
controllerLink = link;
Memory.rooms[room.name].links.controllerLink = link.id;
cache.set(room.name+'_ControllerLink', link);
continue;
}
}
if(controllerLink == undefined || storageLink == undefined){
return;
}
if(//((controllerLink.energy / controllerLink.energyCapacity) < (1-Const.LINK_SEND_THRESHOLD)) &&
((storageLink.energy / storageLink.energyCapacity) > Const.LINK_SEND_THRESHOLD)) {
storageLink.transferEnergy(controllerLink);
}
}
}
};