-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame_spawner.js
55 lines (51 loc) · 1.56 KB
/
game_spawner.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
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('spawner'); // -> 'a thing'
*/
var build_manager = require('manage_builders');
var miner_manager = require('manage_miners');
var fighter_manager = require('manage_fighters');
function getFreeSpawns(room) {
var spawns = room.find(Game.MY_SPAWNS);
var free_spawns = {};
for (var spawn_index in spawns) {
var spawn = spawns[spawn_index];
free_spawns.spawn = spawn.energy;
}
return free_spawns;
}
module.exports.getFreeSpawns = getFreeSpawns;
function spawnAtBest(room, screep) {
var current_energy = 0;
var best_spawn;
var spawns = room.find(Game.MY_SPAWNS);
for (var spawn_index in spawns) {
var spawn = spawns[spawn_index];
if(!best_spawn && canSpawnAt(spawn, screep)) {
if (spawn.energy > current_energy) {
current_energy = spawn.energy;
best_spawn = spawn;
}
}
}
if (best_spawn) {
spawnAtSpecific(best_spawn, screep);
}
}
module.exports.spawnAtBest = spawnAtBest;
function spawnAtSpecific(spawn, screep) {
if(!spawn.spawning) {
var NAME;
spawn.createCreep(screep.body,
NAME,
screep.mem);
}
}
module.exports.spawnAtSpecific = spawnAtSpecific;
function canSpawnAt(spawn, screep) {
return (spawn.energy >= Memory.costs[screep.s_name]);
}
module.exports.canSpawnAt = canSpawnAt;