-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.js
83 lines (81 loc) · 3.23 KB
/
builder.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
var builder = {
run: function(creep, mode) {
if(creep.ticksToLive < 200) creep_renew(creep);
if(creep.memory.builder && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.builder = false;
}
if(!creep.memory.builder && creep.store.getFreeCapacity() == 0) {
creep.memory.builder = true;
}
var str = creep.pos.findClosestByPath(FIND_CONSTRUCTION_SITES);
if(creep.memory.builder) {
if(creep.build(str) == ERR_NOT_IN_RANGE) {
creep.moveTo(str);
}
}
else {
if(mode == 'STORAGE') {
const targets = creep.room.find(FIND_STRUCTURES, {
filter: object => {
return (object.structureType == STRUCTURE_STORAGE) &&
object.store.energy > 0;
}
});
if(creep.withdraw(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
}
}
else if(mode == 'DROP') {
const target = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES);
if(target) {
if(creep.pickup(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
}
else if(mode == 'SOURCE') {
var sources = str.pos.findClosestByPath(FIND_SOURCES, {
filter: object => {
return object.energy != 0;
}
});
if(creep.harvest(sources) == ERR_NOT_IN_RANGE) {creep.moveTo(sources);}
}
else if(mode == 'CONTAINER') {
const target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: object => {
return (object.structureType == STRUCTURE_CONTAINER) &&
object.store.energy > creep.store.getFreeCapacity();
}
});
//targets.sort((a,b) => a.store.energy < b.store.energy);
if(creep.withdraw(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
}
}
/*
const targets = creep.room.find(FIND_STRUCTURES, {
filter: object => {
return (object.structureType == STRUCTURE_TOWER) &&
object.store.energy > 0;
}
});
targets.sort((a,b) => a.store.energy < b.store.energy);
if(creep.withdraw(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
}
*/
}
}
};
function creep_renew(creep) {
const spawn = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: structure => {
return structure.structureType == STRUCTURE_SPAWN && structure.spawning == null;
}
});
if(spawn) {
if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE) creep.moveTo(spawn);
}
}
module.exports = builder;