-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwork.spawn.js
40 lines (40 loc) · 1.43 KB
/
work.spawn.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
var spawner = require('spawn.creep');
/*
* New Spawner
*/
module.exports.run = function(debug = false) {
// Get and store the cpu
var _cpu = Game.cpu.getUsed();
// First loop through our spawns
for (var spawn in Game.spawns) {
// Set spawn, room and spawned
var _spawn = Game.spawns[spawn];
// Is this spawner already occupied?
if (_spawn.spawning) {
if (debug) { console.log('Spawner already spawning'); }
continue
}
var _room = _spawn.room;
var _spawned = false;
// Now lets loop through the roles
for (var i in ROLES) {
if (_spawned) { break; }
var role = ROLES[i];
var _role = require('role.' + role);
// Is this role enabled in this room?
if (!_room.memory.roles[role]) {
continue;
}
// If we get true back from the spawner then it spawned
if (spawner.run(spawn, role, debug)) {
if (debug) { console.log('Spawner used ' + (Game.cpu.getUsed() - _cpu).toFixed(3) + ' CPU'); }
_spawned = true;
}
// If we spawned Stop other spawns from spawning.. hopefully preventing wastefull spawns
// This will slow down reaction times of things, but necessary to stop all the wasteful spawns
if (_spawned) {
return true;
}
}
}
}