-
Notifications
You must be signed in to change notification settings - Fork 3
/
actionHarvestLD.js
133 lines (118 loc) · 6.36 KB
/
actionHarvestLD.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
var harvester = require('actionHarvest');
module.exports = {
/**
* мачете собирать!
* @param {Creep} creep
*/
run:function(creep){
let startCpu = Game.cpu.getUsed();
let elapsed;
if(creep.resourseRooms.length === 0){
console.log('[notice]-> no resource rooms, change action to simple harvester');
harvester.run(creep);
}
else {
if(Memory.resourceRooms === undefined){
Memory.resourceRooms = [];
for(let id in creep.resourseRooms){
Memory.resourceRooms[id] = 0;
}
}
if (creep.memory.resourceRoomID === undefined) {
for (let id in creep.resourseRooms) {
if (Memory.resourceRooms[id] < creep.resourseRooms[id]['limit']) {
creep.memory.resourceRoomID = id;
Memory.resourceRooms[id] += 1;
if( Memory.noticeSettings && Memory.noticeSettings['longHarvestNotice'] === true){
console.log('[longHarvest]-> Add ' + creep.memory.role + ' to room queue [' + creep.resourseRooms[id]['room'] + '], limit: ' + Memory.resourceRooms[id] + '/' + creep.resourseRooms[id]['limit']);
}
break;
}
}
}
if(creep.carry.energy === 0 || !creep.memory.working){
creep.memory.action = 'mine Energy';
//если в домашней комнате, топаем до места назначения
if(creep.room.name === creep.memory.roomID){
creep.memory.working = false;
let exit = creep.room.findExitTo(creep.resourseRooms[creep.memory.resourceRoomID]['room']);
let actRes = creep.moveTo(creep.pos.findClosestByRange(exit));
if (actRes === OK) {
creep.memory.action= 'traveling to ' + creep.resourseRooms[creep.memory.resourceRoomID]['room'];
return;
}
if( Memory.noticeSettings && Memory.noticeSettings['noticeCPU'] && Memory.noticeSettings['noticeCPULevel']) {
elapsed = Game.cpu.getUsed() - startCpu;
if (elapsed > Memory.noticeSettings['noticeCPULevel']) {
creep.say(Math.round(elapsed,2)+'%');
//console.log('[CPU]-> creep.harvestLD action: going another room, cpu usage:' + elapsed);
}
}
}
else{
//пока не набился битком, майнит энергию в комнате назначения
creep.memory.working = creep.mineEnergy();
if( Memory.noticeSettings && Memory.noticeSettings['noticeCPU'] && Memory.noticeSettings['noticeCPULevel']) {
elapsed = Game.cpu.getUsed() - startCpu;
if (elapsed > Memory.noticeSettings['noticeCPULevel']) {
creep.say(Math.round(elapsed,2)+'%');
//console.log('[CPU]-> creep.harvestLD action: mine energy in another room, cpu usage:' + elapsed);
}
}
}
}
if(creep.memory.working){
if(creep.room.name !== creep.memory.roomID){
let exit = creep.room.findExitTo(creep.memory.roomID);
let actRes = creep.moveTo(creep.pos.findClosestByRange(exit));
if (actRes === OK) {
creep.memory.action= 'go back to ' + creep.room.name;
}
return;
}
creep.memory.action = 'transfer Energy';
if( Memory.noticeSettings && Memory.noticeSettings['noticeCPU'] && Memory.noticeSettings['noticeCPULevel']) {
elapsed = Game.cpu.getUsed() - startCpu;
if (elapsed > Memory.noticeSettings['noticeCPULevel']) {
creep.say(Math.round(elapsed,2)+'%');
//console.log('[CPU]-> creep.harvestLD action: returning to room, cpu usage:' + elapsed);
}
}
let structure;
//все экстеншены ДОЛЖНЫ быть заполнены!
/*structure = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => s.structureType === STRUCTURE_EXTENSION && s.energy < s.energyCapacity
});*/
// если все забили, то забиваем все подряд, что еще не наполнено
if (!structure){
structure = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => ((s.structureType === STRUCTURE_SPAWN
|| s.structureType === STRUCTURE_EXTENSION
|| s.structureType === STRUCTURE_TOWER
|| s.structureType === STRUCTURE_LINK)
&& s.energy < s.energyCapacity)
|| ((s.structureType === STRUCTURE_CONTAINER) && s.store[RESOURCE_ENERGY] < s.storeCapacity)
});
}
if (structure === undefined) {
structure = creep.room.storage;
}
if (structure !== undefined) {
if (creep.transfer(structure, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(structure);
}
}
else{
console.log('[harvest]-> '+creep.id+' not found empty container for energy');
}
if( Memory.noticeSettings && Memory.noticeSettings['noticeCPU'] && Memory.noticeSettings['noticeCPULevel']) {
elapsed = Game.cpu.getUsed() - startCpu;
if (elapsed > Memory.noticeSettings['noticeCPULevel']) {
creep.say(Math.round(elapsed,2)+'%');
//console.log('[CPU]-> creep.harvestLD action: transfer energy, cpu usage:' + elapsed);
}
}
}
}
}
};