-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreep.maintainBuild.js
More file actions
71 lines (70 loc) · 2.61 KB
/
Creep.maintainBuild.js
File metadata and controls
71 lines (70 loc) · 2.61 KB
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
var CreepBuild = function(input) {
var constructionSite, creep, repairTarget;
var workBodyparts = this.getActiveBodyparts(WORK);
var myConstructionSites = this.room.memory.found.myConstructionSites;
var foundStructures = this.room.memory.found.structures;
constructionSite = this.pos.findClosestByRange(myConstructionSites);
if(input.activeRepair) {
repairTarget = this.pos.findClosestByRange(foundStructures, {
filter: function(structure) {
if(structure.hits < structure.hitsMax) {
if(structure.hitsMax - structure.hits > REPAIR_POWER * workBodyparts) {
if(input.structures.indexOf(structure.structureType) != -1) {
if(structure.structureType === STRUCTURE_RAMPART) {
if(structure.hits > 100000) {
return false;
} else {
return true;
}
} else {
return true;
}
}
}
}
}
});
}
var closestConstructionSiteDistance = this.pos.getRangeTo(constructionSite);
var closestRepairTargetDistance = this.pos.getRangeTo(repairTarget);
//console.log(closestConstructionSiteDistance);
//console.log(closestRepairTargetDistance);
var target;
if(closestConstructionSiteDistance >= 0 && closestRepairTargetDistance >= 0) {
if (closestConstructionSiteDistance <= closestRepairTargetDistance) {
target = constructionSite;
if(target) {
if(this.build(target) == ERR_NOT_IN_RANGE) {
this.moveTo(target);
}
}
} else {
target = repairTarget;
if(target) {
if(this.repair(target) == ERR_NOT_IN_RANGE) {
this.moveTo(target);
}
}
}
} else if(closestConstructionSiteDistance >= 0) {
target = constructionSite;
if(target) {
if(this.build(target) == ERR_NOT_IN_RANGE) {
this.moveTo(target);
}
}
} else if(closestRepairTargetDistance >= 0) {
target = repairTarget;
if(target) {
if(this.repair(target) == ERR_NOT_IN_RANGE) {
this.moveTo(target);
}
}
}
if(target) {
return OK;
} else {
return ERR_NOT_FOUND;
}
};
module.exports = CreepBuild;