-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrole.conqueror.js
More file actions
60 lines (54 loc) · 1.99 KB
/
role.conqueror.js
File metadata and controls
60 lines (54 loc) · 1.99 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
const spawnHelper = require('helper.spawning');
const logistic = require('helper.logistic');
const movement = require("helper.movement");
module.exports = {
name: "conqueror",
configs: function() {
var configs = [];
for(var parts = 10; parts >= 2; parts -= 1) {
let config = Array(parts).fill(WORK).concat(Array(parts).fill(CARRY)).concat(Array(parts * 2).fill(MOVE));
configs.push(config);
}
return configs;
},
run: function(creep) {
let flag = Game.flags[creep.memory.flag];
if(creep.room.name !== flag.pos.roomName) {
creep.goTo(flag, { newPathing: true });
return;
}
if(creep.room.find(FIND_MY_SPAWNS).length > 0) {
creep.memory.role = "harvester";
creep.memory.source = creep.pos.findClosestByRange(FIND_SOURCES).id;
creep.say("Spawn is there. Becoming a harvester...");
return;
}
if(creep.memory.building && creep.store.energy == 0) {
creep.memory.building = false;
}
if(!creep.memory.building && creep.store.energy == creep.store.getCapacity()) {
creep.memory.building = true;
}
if(creep.memory.building) {
this.constructStructures(creep);
}
else {
this.harvestEnergy(creep);
}
},
constructStructures: function(creep) {
var target = creep.pos.findClosestByRange(FIND_MY_CONSTRUCTION_SITES, { filter: (cs) => cs.structureType == STRUCTURE_SPAWN });
if(target) {
if(creep.build(target) == ERR_NOT_IN_RANGE) {
creep.goTo(target, { newPathing: true });
}
}
return target;
},
harvestEnergy: function(creep) {
let source = creep.pos.findClosestByRange(FIND_SOURCES_ACTIVE);
logistic.obtainEnergy(creep, source, true);
}
};
const profiler = require("screeps-profiler");
profiler.registerObject(module.exports, 'conqueror');