-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrole.mharvester.js
191 lines (182 loc) · 5.89 KB
/
role.mharvester.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
/* Mineral Harvester drone */
module.exports.role = 'mharvester';
/* sType */
module.exports.sType = 'normal';
/* Spawn Roster */
module.exports.roster = {
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 1,
7: 1,
8: 1,
};
/* Costs */
module.exports.cost = {
1 : 300,
2 : 400,
3 : 500,
4 : 1300,
5 : 1800,
6 : 1800,
7 : 1800,
8 : 1800,
};
/* Body parts */
module.exports.body = {
1 : [
WORK,
CARRY,CARRY,
MOVE,MOVE
],
2 : [
WORK,
CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE
],
3 : [
CARRY,CARRY,CARRY,CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE
],
4 : [
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
],
5 : [
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,
],
6 : [
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,
],
7 : [
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,
],
8 : [
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,
],
};
module.exports.enabled = function (room, debug = false) {
// define the room
var theRoom = Game.rooms[room];
// Find the mineral site in the room
var mineral = theRoom.find(FIND_MINERALS);
// does it have minerals?
if (theRoom.controller && theRoom.controller.level >= 6 && mineral[0].mineralAmount > 0) {
let extractors = theRoom.find(FIND_STRUCTURES, {
filter: (s) => {
return (s.structureType === STRUCTURE_EXTRACTOR)
}
});
if (extractors.length > 0) { return true; }
}
// This should be disabled
return false;
}
/**
* Harvester Role
*/
module.exports.run = function(creep) {
if (creep.isTired()) { return; }
if (!creep.memory.dying && creep.ticksToLive < 100) { creep.memory.dying = true; }
// If it's dying force it into delivery mode
if (creep.memory.dying) {
creep.say(creep.ticksToLive);
if (_.sum(creep.carry) > (creep.carryCapacity/2) || creep.ticksToLive < 50) {
creep.memory.delivering = true;
} else {
creep.memory.delivering = false;
}
}
if (creep.room.name != creep.memory.roomName) {
delete creep.memory.energyPickup;
let pos = new RoomPosition(25,25,creep.memory.roomName);
creep.travelTo(pos);
creep.say('SEEK');
return;
}
// Is the creep dropping off and empty?
if (creep.memory.delivering && _.sum(creep.carry) === 0) {
creep.memory.delivering = false;
creep.say('GET');
}
// Is the creep not delivering and full?
if (!creep.memory.delivering && _.sum(creep.carry) === creep.carryCapacity) {
creep.memory.delivering = true;
creep.say('PUT');
}
// If we're not delivering, check if we can harvest, if not and we have half energy, go and deliver
if (!creep.memory.delivering) {
// Any minerals to pickup?
let mineralResult = creep.getNearbyMinerals();
if (mineralResult === ERR_NOT_FOUND) {
// Go and empty storage instead
creep.getNearbyMinerals(true);
} else if (mineralResult === ERR_FULL) {
delete creep.memory.mineralPickup;
creep.memory.delivering = true;
}
}
// Alright at this point if we're delivering it's time to move the Creep to a drop off
if (creep.memory.delivering) {
delete creep.memory.mineralPickup;
// mineral harvester should always use the terminal
var target = creep.room.terminal;
// Did we find a target?
if (target) {
// Are we in range of the target
if (!creep.pos.inRangeTo(target,1)) {
creep.travelTo(target);
// Say because move
creep.say('>>');
}
if (creep.pos.inRangeTo(target,2)) {
// Loop through our resources
for(var resourceType in creep.carry) {
// Attempt to transfer them
if (creep.carry[resourceType] > 0) {
if (creep.transfer(target, resourceType) === ERR_NOT_IN_RANGE) {
// something went wrong
break;
} else {
creep.say('V');
}
}
}
return;
}
} else {
creep.memory.idle++;
creep.say('idle: ' + creep.memory.idle);
if (creep.memory.idle >= 10) {
// Are we in our home room?
//if (creep.room.name != creep.memory.roomName) {
// lets go home
var spawns = Game.rooms[creep.memory.roomName].find(FIND_STRUCTURES, {
filter: (i) => i.structureType == STRUCTURE_SPAWN
});
var spawn = spawns[0];
if (spawn) {
creep.travelTo(spawn);
creep.say(global.sayMove);
}
//}
}
}
}
}