-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathactionLorry.js
116 lines (100 loc) · 5.1 KB
/
actionLorry.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
module.exports = {
/**
* развозит энергию по спавнам и/или заполняет все контенеры из стораджа
* @param {Creep} creep
*/
run:function(creep){
let startCpu = Game.cpu.getUsed();
let elapsed;
if(creep.carry.energy === creep.carryCapacity){
creep.memory.working = true;
}
else if(creep.carry.energy === 0){
creep.memory.working = false;
}
if(creep.carry.energy === 0 || !creep.memory.working){
let target;
creep.memory.action = 'looking for Energy';
//если есть стораджи и в них есть что брать
if (creep.room.controller.level > 3) {
target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => s.structureType === STRUCTURE_LINK && s.energy > 0
});
creep.memory.getFrom = STRUCTURE_LINK;
if (!target) {
target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => s.structureType === STRUCTURE_STORAGE && s.store[RESOURCE_ENERGY] < s.storeCapacity
});
creep.memory.getFrom = STRUCTURE_STORAGE;
}
//если нет стораджей, идем в линки, если есть, конечно
}
else{
// если нет ничего выше перечисленного, идем в контенеры и берем оттуда энергию
if(!target){
target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => s.structureType === STRUCTURE_CONTAINER && s.store[RESOURCE_ENERGY] > 0
});
creep.memory.getFrom = STRUCTURE_CONTAINER;
}
}
if(target !== undefined){
let actRes = creep.withdraw(target, RESOURCE_ENERGY);
if (actRes === ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
if( Memory.noticeSettings !== undefined && Memory.noticeSettings['noticeCPU'] === true && Memory.noticeSettings['noticeCPULevel']) {
elapsed = Game.cpu.getUsed() - startCpu;
if (elapsed > Memory.noticeSettings['noticeCPULevel']) {
creep.say(Math.round(elapsed,2)+'%');
// console.log('[CPU]-> creep.harvest action: mine energy, cpu usage:' + elapsed);
}
}
}
if(creep.memory.working){
creep.memory.action = 'transfer Energy';
let structure;
//все экстеншены ДОЛЖНЫ быть заполнены!
structure = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => s.structureType === STRUCTURE_EXTENSION && s.energy < s.energyCapacity
});
if(!structure && creep.memory.getFrom !== STRUCTURE_CONTAINER){
structure = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => s.structureType === STRUCTURE_CONTAINER && s.store[RESOURCE_ENERGY] < s.storeCapacity
});
}
//если позволяет развитие, то таскаем в контейнеры
if(!structure && creep.room.controller.level > 3){
//заполнили контейнеры, заполняем сторадж
if(!structure && creep.memory.getFrom !== STRUCTURE_STORAGE){
structure = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => s.structureType === STRUCTURE_STORAGE && s.store[RESOURCE_ENERGY] < s.storeCapacity
});
}
}
// ищем ближийший накопитель
if(!structure){
structure = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => (s.structureType === STRUCTURE_SPAWN || s.structureType === STRUCTURE_TOWER) && s.energy < s.energyCapacity
});
}
if (structure !== undefined) {
if (creep.transfer(structure, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(structure);
}
//creep.memory.targetID = structure.id;
}
else{
console.log('[notice] -> '+creep.id+' not found empty container for energy');
}
if( Memory.noticeSettings !== undefined && Memory.noticeSettings['noticeCPU']=== true && Memory.noticeSettings['noticeCPULevel']) {
elapsed = Game.cpu.getUsed() - startCpu;
if (elapsed > Memory.noticeSettings['noticeCPULevel']) {
creep.say(Math.round(elapsed,2)+'%');
// console.log('[CPU]-> creep.harvest action: transfer energy, cpu usage:' + elapsed);
}
}
}
}
};