-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuilder.js
More file actions
48 lines (48 loc) · 1.89 KB
/
builder.js
File metadata and controls
48 lines (48 loc) · 1.89 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
"use strict";
function repairStructures(creep) {
var repairs = _.filter(creep.room.find(FIND_STRUCTURES), function (struct) { return struct.hits < struct.hitsMax - 300; });
repairs.sort(function (a, b) { return a.hits - b.hits; });
if (repairs.length) {
if (creep.repair(repairs[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(repairs[0], { visualizePathStyle: { stroke: '#9af441' } });
}
if (creep.carry.energy == 0) {
var droppedResource = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES);
collectDroppedResource(creep, droppedResource);
}
}
}
function constructStructure(creep, construction) {
if (creep.build(construction) == ERR_NOT_IN_RANGE || creep.carry.energy == 0) {
creep.moveTo(construction, { visualizePathStyle: { stroke: '#9af441' } });
}
if (creep.carry.energy == 0) {
var droppedResource = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES);
collectDroppedResource(creep, droppedResource);
creep.memory.job = "requesting_energy";
}
else {
creep.memory.job = "contructing";
}
}
function collectDroppedResource(creep, resource) {
if (creep.pickup(resource) == ERR_NOT_IN_RANGE) {
creep.moveTo(resource, { visualizePathStyle: { stroke: '#ffffff' } });
}
}
module.exports = {
run: function (creep, flag) {
var spawn = _.find(Game.spawns, function (spawn) { return spawn.room == flag.room; });
if (spawn)
creep.memory.role = "upgrader";
creep.moveTo(flag, { visualizePathStyle: { stroke: '#ffffff' } });
if (creep.room == flag.room) {
var construction = creep.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
if (construction)
constructStructure(creep, construction);
else
repairStructures(creep);
creep.moveTo(creep);
}
}
};