-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkers_guild.js
86 lines (77 loc) · 3.04 KB
/
workers_guild.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
// The Workers Guild handles the job assignment and instruction of creeps across all syndicates
var employmentOffice = {
assignJob: function(creep) {
// ----- HARVESTER JOBS ----- //
if (creep.memory.role == 'Harvester'){
if (creep.store.getFreeCapacity() == 0) {
creep.memory.job = "transfer_energy";
}
if (creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.job = "gather_energy";
}
}
// ----- BUILDER JOBS ----- //
else if (creep.memory.role == 'Builder'){
if (creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.job = 'gather_energy';
}
if (creep.store.getFreeCapacity() == 0) {
creep.memory.job = 'build';
}
}
}
}
var jobInstructor = {
transferEnergy: function (creep) {
var targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (
(structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0
);
}
});
if (targets.length > 0 && creep.room.controller.ticksToDowngrade > 100) {
if (creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], { visualizePathStyle: { stroke: '#ffffff' } });
}
}
else {
if (creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller, { visualizePathStyle: { stroke: '#ff0000' } });
}
}
},
gatherEnergy: function(creep) {
if (creep.memory.role == 'Harvester') {
var sources = creep.room.find(FIND_SOURCES);
if (_.size(Game.creeps) < _.size(sources)) {
var selectedSource = creep.pos.findClosestByPath(FIND_SOURCES);
}
else {
var selectedSource = sources[creep.memory.hash % _.size(sources)];
}
if (creep.harvest(selectedSource) == ERR_NOT_IN_RANGE) {
if (creep.moveTo(selectedSource, { visualizePathStyle: { stroke: '#ffaa00' } }) == ERR_NO_PATH) {
creep.memory.hash = creep.memory.hash + 1;
}
}
}
else if (creep.memory.role == 'Builder'){
var source = creep.pos.findClosestByRange(FIND_SOURCES);
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
creep.moveTo(source);
}
}
},
build: function(creep) {
var constructionSites = creep.room.find(FIND_CONSTRUCTION_SITES);
if (constructionSites.length) {
if (creep.build(constructionSites[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(constructionSites[0]);
}
}
}
}
module.exports.employmentOffice = employmentOffice;
module.exports.jobInstructor = jobInstructor;