-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread.schedule.js
105 lines (102 loc) · 5.11 KB
/
thread.schedule.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const BOOT_SCREEPS = 5;
function newTaskTarget(target) {
this.id = target.id;
this.pos = {};
this.pos.room = target.pos.roomName;
this.pos.x = target.pos.x;
this.pos.y = target.pos.y;
}
let Export = {
run: function () {
for (let name in Game.creeps) {
let creep = Game.creeps[name];
if (!creep.memory.task) {
if (creep.store.getUsedCapacity() != 0) {
let random = _.random(3);
for (const putName of global.PUT_SEQUENCE) {
/*
if (putName == "repaire" && random == 3) {
if (_.size(Game.creeps) < BOOT_SCREEPS) continue;
let target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: object => object.hits < object.hitsMax
});
if (target == null) continue;
creep.memory.task = {};
creep.memory.task.type = "repaire";
creep.memory.task.target = new newTaskTarget(target);
break;
}
*/
if (putName == "build" && random == 3) {
if (_.size(Game.creeps) < BOOT_SCREEPS) continue;
let target = creep.pos.findClosestByPath(FIND_MY_CONSTRUCTION_SITES);
if (target == null) continue;
creep.memory.task = {};
creep.memory.task.type = "build";
creep.memory.task.target = new newTaskTarget(target);
break;
}
if (putName == "tower" && random >= 2) {
if (_.size(Game.creeps) < BOOT_SCREEPS) continue;
let target = creep.pos.findClosestByPath(FIND_MY_STRUCTURES, {
filter: (structure) => {
return structure.structureType == STRUCTURE_TOWER &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
}
});
if (target == null) continue;
creep.memory.task = {};
creep.memory.task.type = "put";
creep.memory.task.target = new newTaskTarget(target);
break;
}
if (putName == "spawn" && random >= 1) {
//if (_.size(Game.creeps) > BOOT_SCREEPS) continue;
let target = creep.pos.findClosestByPath(FIND_MY_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN) &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
}
});
if (target == null) continue;
creep.memory.task = {};
creep.memory.task.type = "put";
creep.memory.task.target = new newTaskTarget(target);
break;
}
if (putName == "controller") {
let target = creep.room.controller;
if (target == null) continue;
creep.memory.task = {};
creep.memory.task.type = "put";
creep.memory.task.target = new newTaskTarget(target);
break;
}
}
} else {
for (const getName of global.GET_SEQUENCE) {
if (getName == "tombstone") {
let target = creep.pos.findClosestByPath(FIND_TOMBSTONES, {
filter: object => object.store.getUsedCapacity() > 0
});
if (target == null) continue;
creep.memory.task = {};
creep.memory.task.type = "get";
creep.memory.task.target = new newTaskTarget(target);
break;
}
if (getName == "source") {
let target = creep.pos.findClosestByPath(FIND_SOURCES_ACTIVE);
if (target == null) continue;
creep.memory.task = {};
creep.memory.task.type = "get";
creep.memory.task.target = new newTaskTarget(target);
break;
}
}
}
}
}
}
}
module.exports = Export;