-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspawning.decider.js
More file actions
88 lines (77 loc) · 3.05 KB
/
spawning.decider.js
File metadata and controls
88 lines (77 loc) · 3.05 KB
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
'use strict';
const CreepSpawner = require('creep.spawning');
class Decider{
constructor(spawn){
this.spawn = spawn;
}
decide(){
if(this.spawn.spawning || this.spawn.room.hasInvaderAndNoTower()){
return undefined;
}
if(!this.decided){
this.result = this.getResult();
this.decided = true;
}
return this.result;
}
getResult(){
const starter = new CreepSpawner(this.spawn, Creep.starter);
const builder = new CreepSpawner(this.spawn, Creep.builder);
let manager = this.spawn.room.getHarvestManager();
if(this.spawn.room.energyCapacityAvailable < 500){
if(starter.canSpawn()){
return starter;
}else if(builder.canSpawn()){
return builder;
}
return;
}
const transport = new CreepSpawner(this.spawn, Creep.transport);
const upgrader = new CreepSpawner(this.spawn, Creep.upgrader);
if(manager.income === 0 && manager.getStoredEnergy() < this.spawn.room.energyCapacityAvailable + transport.getCost()){
return starter;
}else if (manager.hasSourceContainer()){
if(this.countRole('transport') < 1){
return transport;
}else if(this.countRole('harvester') < manager.sources.length){
return new CreepSpawner(this.spawn, Creep.harvester);
}else if(manager.transportPower() < manager.getRequiredTransportPower()){
return transport;
}else if(this.countRole('upgrader') < 1 && upgrader.canSpawn()){
return new CreepSpawner(this.spawn, Creep.upgrader);
}
}else if(this.countRole('harvester') < manager.sources.length){
return new CreepSpawner(this.spawn, Creep.harvester);
}
if(builder.canSpawn()){
return builder;
}
if(manager.income > 0){
let cManager = this.spawn.room.getColonyManager();
if(cManager.colonies.length > 0){
let colonizer = new CreepSpawner(this.spawn, Creep.colonizer);
if(colonizer.canSpawn()){
return colonizer;
}
}
}
let rManager = this.spawn.room.getResourceManager();
if(this.spawn.room.terminal && rManager.extractor){
if(rManager.mineral.mineralAmount > 0 &&
this.countRole('mineralHarvester') < 1){
let mineralHarvester = new CreepSpawner(this.spawn, Creep.mineralHarvester);
if(mineralHarvester.canSpawn()) return mineralHarvester;
}
if(this.spawn.room.getTasks().length > 0 &&
this.countRole('taskTransport') < 1){
let taskRunner = new CreepSpawner(this.spawn, Creep.taskTransport);
if(taskRunner.canSpawn()) return taskRunner
}
}
return undefined;
}
countRole(role){
return this.spawn.room.countRole(role);
}
}
module.exports = Decider;