-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroles.js
143 lines (126 loc) · 3.09 KB
/
roles.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var fill = require("fill");
var memMgr = require("mgr.memory");
var collect = require("collect");
var roles = {
builder: function (creep) {
var room = creep.room;
var roomName = room.name;
var targets = {};
//Build or collect
if(creep.memory.building){
//changing status
if (creep.store.getUsedCapacity() == 0) {
creep.memory.building = false;
creep.say('⚡');
} else {
//make sure a destination exists in creep memory
if (!creep.memory.dest) {
//find all construction sites in room memory
memMgr.updateConstructionMem(room);
var targets = []
for (var site in Memory[roomName].constructionSites.all) {
targets.push(Game.getObjectById(Memory[roomName].constructionSites.all[site].id));
}
//console.log("targets in " + roomName + " " + targets);
//if no construction sites, try to repair something
if (!targets || targets.length == 0) {
//hopefully sets a destination
//roleRepairer.run(creep)
console.log("decide action in builder")
} else {
//depending on team set target destination
switch (creep.memory.team) {
case 1:
creep.memory.dest = targets[targets.length - 1].id;
break;
case 0:
default:
creep.memory.dest = targets[0].id;
break;
}
}
}
//check if destination became invalid
var dest = Game.getObjectById(creep.memory.dest);
//console.log(dest.pos)
if (!dest || dest.hits > 0) {
creep.memory.dest = null;
//console.log(creep.name + " cannot find work in " + roomName)
//roleRepairer.run(creep)
console.log("decide action in builder")
} else {
var status = creep.build(dest);
switch (status) {
case 0:
//worked
break;
case -9:
creep.moveTo(dest);
break;
default:
console.log(status + " error building in " + roomName);
break;
}
}
}
}else{
//make sure memory created
creep.memory.building = false;
//changing status
if (creep.store.getFreeCapacity() == 0) {
creep.memory.building = true;
creep.say('🚧');
//TODO: fix?
creep.memory.dest = false;
} else {
collect.containers.run(creep);
}
}
}
,
defender: function (creep) {
}
,
filler: function (creep) {
}
,
harvester: function (creep) {
}
,
importer: function (creep) {
}
,
linkFiller: function (creep) {
}
,
linkUpgrader: function (creep) {
}
,
miner: function (creep) {
}
,
recoverer: function (creep) {
}
,
repairer: function (creep) {
}
,
scavenger: function (creep) {
}
,
settler: function (creep) {
}
,
sourceFarmer: function (creep) {
}
,
storageLink: function (creep) {
}
,
towerGuard: function (creep) {
}
,
upgrader: function (creep) {
}
};
module.exports = roles;