-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrole.hauler.js
240 lines (231 loc) · 8.18 KB
/
role.hauler.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
var DBG = false;
// Remote Hauler Drone
module.exports.role = 'hauler';
// Core Type
module.exports.sType = 'remote';
// Roster (max number we want per room)
module.exports.roster = {
1: 0,
2: 0,
3: 0,
4: 1,
5: 1,
6: 1,
7: 1,
8: 1,
};
// Costs (human readability mostly, likely to nuke this soon)
module.exports.cost = {
1 : 300,
2 : 450,
3 : 650,
4 : 1250,
5 : 1250,
6 : 1250,
7 : 1250,
8 : 1250,
};
// Body parts array for each RCL level
module.exports.body = {
1 : [
// WORK,
CARRY,CARRY,
MOVE,MOVE
],
2 : [
// WORK,
CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE
],
3 : [
// WORK,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,MOVE
],
4 : [
// WORK,
CARRY,CARRY,CARRY,CARRY,CARRY,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
],
5 : [
// WORK,
CARRY,CARRY,CARRY,CARRY,CARRY,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
],
6 : [
// WORK,
CARRY,CARRY,CARRY,CARRY,CARRY,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
],
7 : [
// WORK,
CARRY,CARRY,CARRY,CARRY,CARRY,
CARRY,CARRY,CARRY,CARRY,CARRY,
CARRY,CARRY,CARRY,CARRY,CARRY,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE
],
8 : [
// WORK,
CARRY,CARRY,CARRY,CARRY,CARRY,
CARRY,CARRY,CARRY,CARRY,CARRY,
CARRY,CARRY,CARRY,CARRY,CARRY,
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE,
MOVE,MOVE,MOVE,MOVE,MOVE
],
};
// Multiplier
module.exports.multiplier = 1;
// Enabled flag
module.exports.enabled = function (room, debug = false) {
// Turn off if room is discharging with supergraders
if (Game.rooms[room].memory.charging === false) { return false; }
// Get the flags
var flags = _.filter(Game.flags, (flag) => flag.color === global.flagColor['haul']);
// No remote flags, return false
if (flags.length === 0) { return false; }
return true;
}
// The main run method
module.exports.run = function(creep, debug = false) {
// Now if we're spawning just return
if (creep.isTired()) {
new RoomVisual(creep.pos.roomName).circle(creep.pos, {
radius: .45, fill: "transparent", stroke: 'aqua', strokeWidth: .15, opacity: .3
});
return;
}
// Is it dying?
if (!creep.memory.dying && creep.ticksToLive <= 100) {
creep.memory.dying = true;
}
if (!creep.canDo(CARRY)) {
DBG && console.log('[' +creep.name+'] Creep damaged seeking repair:' + JSON.stringify(creep.pos));
return;
}
// Logic is as follows. If empty, head to remote room, if in remote room and empty, find resources as normal
// if full, return to home room, if in home room drop resources off
// If travelling with resources we should run a repair on the road we're on as we go
// First are we empty, if we are we should be heading to remote
if (_.sum(creep.carry) === 0) {
// Set Seek to true
creep.memory.seek = true;
}
if (_.sum(creep.carry) >= creep.carryCapacity && creep.carryCapacity > 0) {
delete creep.memory.seek;
delete creep.memory.arrived;
delete creep.memory.energyPickup;
delete creep.memory.remoteRoom;
}
var moved = false;
// Are we seeking?
if (creep.memory.seek) {
if (creep.room.name === creep.memory.remoteRoom) { creep.memory.arrived = true; }
if (!creep.memory.arrived) {
DBG && console.log(creep.name + ' Creep has not arrived');
// If we have cleared the remoteRoom (which we should after every successful pickup)
if (!creep.memory.remoteRoom) {
creep.memory.remoteRoom = Memory.remoteRoom;
DBG && console.log('['+creep.name+'] setting hauler remote room ' + creep.memory.remoteRoom);
}
DBG && console.log('['+creep.name+'] Hauler Not in remote room ' + creep.memory.remoteRoom);
if (creep.memory.remoteRoom == '-Infinity') { delete creep.memory.remoteRoom; }
if (creep.memory.remoteRoom) {
let pos = new RoomPosition(25,25,creep.memory.remoteRoom);
// Lets head to the remoteRoom
creep.travelTo(pos);
var moved = true;
}
} else {
DBG && console.log(creep.name + ' Creep has arrived seeking energy');
if (creep.getNearbyEnergy() === ERR_FULL) {
delete creep.memory.seek;
delete creep.memory.energyPickup;
}
}
}
// Alright now the code for if we're not seeking
if (!creep.memory.seek) {
// If we don't have a room to deliver to yet (which we should reset after every drop off)
if (!creep.memory.roomName) {
creep.memory.roomName = Memory.myRoom;
DBG && console.log('['+creep.name+'] setting hauler home room');
}
DBG && console.log('['+creep.name+'] Hauler full going home');
// We need to be heading home are we in our home room yet?
if (creep.room.name != creep.memory.roomName) {
// We're not in the room yet, we need to seek the room's controller
const spawns = Game.rooms[creep.memory.roomName].find(FIND_STRUCTURES, {
filter: (i) => i.structureType === STRUCTURE_SPAWN
});
// Get the first spawn
const spawn = spawns[0];
// If we have one
if (spawn) {
// Lets go to it
creep.travelTo(spawn);
var moved = true;
}
} else {
// We're already in the room lets dump our resources on the storage
var target = creep.room.storage;
// Does it have storage?
if (!target) {
// no.. okay lets dump it in a container
target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (i) => i.structureType === STRUCTURE_CONTAINER && _.sum(i.store) < i.storeCapacity
});
}
// Did we find a target?
if (target) {
// Loop through everything we're carrying
for (var i in creep.carry) {
// Do we have any?
if (creep.carry[i] > 0) {
// attempt to transfer
if (creep.transfer(target, i) == ERR_NOT_IN_RANGE) {
// Lets go to it
creep.travelTo(target);
var moved = true;
break;
} else {
creep.say(global.sayDrop);
// Reset Target
delete creep.memory.roomName; // Comment out to Temporarily make haulers just deliver to their own room Curious as to what it'l do
}
}
}
} else {
// no where to drop it off. lets just dump it in this room and let the home creeps deal with it
for (var i in creep.carry) {
if (creep.carry[i] > 0) {
creep.drop(i);
creep.say(global.sayDrop);
delete creep.memory.roomName;
}
}
}
}
}
if (moved) { creep.say(global.sayMove); }
// If we moved and we have energy we should run a repair/build/seed on any road we're standing on
if (moved && creep.carry.energy > 0) {
// Turn off roadCheck for haulers, they should be optimised enough without this I think (might be worth checking how swamps affect this)
// creep.roadCheck(true);
}
}