-
Notifications
You must be signed in to change notification settings - Fork 0
/
mgr.js
151 lines (133 loc) · 5.97 KB
/
mgr.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
var collect = require("collect");
var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleRepairer = require("role.repairer");
var roleSettler = require("role.settler");
var roleImporter = require("role.importer");
var towerGuard = require("role.towerGuard");
var roleFiller = require("role.filler");
var roleScavenger = require("role.scavenger")
var roleDefender = require("role.scavenger");
var roleSourceFarmer = require("role.sourceFarmer");
var roleLinkUpgrader = require("role.linkUpgrader");
var roleStorageLinkMgr = require("role.storageLinkMgr");
var roleMiner = require("role.miner");
var roles = require("roles");
var linksMgr = require("mgr.links");
var mgr = {
runRoles: function (myRoom) {
//run each role
for (var name in Game.creeps) {
var creep = Game.creeps[name];
if (!creep.spawning) {
//room creeps
if (creep.room.controller && creep.room.controller.my) {
switch (creep.memory.role) {
case "settler":
roleSettler.run(creep);
break;
case "importer":
roleImporter.run(creep);
break;
case "miner":
//console.log(creep.room)
//if(creep.room)
roleMiner.run(creep);
break;
case "harvester":
roleHarvester.run(creep);
break;
case "builder":
roles.builder(creep);
//roleBuilder.run(creep);
break;
case "repairer":
//creep.memory.dest = false;
roleRepairer.run(creep);
break;
case "filler":
roleFiller.run(creep);
break;
case "scavenger":
roleDefender.run(creep)
break;
case "towerGuard":
towerGuard.run(creep)
break;
case "sourceFarmer":
roleSourceFarmer.run(creep);
break;
case "linkFiller": //deprecated
creep.memory.role = "storageLinkMgr";
roleStorageLinkMgr.run(creep);
case "storageLinkMgr":
roleStorageLinkMgr.run(creep);
break;
case "upgrader":
var links = linksMgr.findLinksInRoom(creep.room);
if (links.length < 2) {
//if less than 2 links in a room, become a regular upgrader
roleUpgrader.run(creep);
break;
} else {
creep.memory.role = "linkUpgrader";
if (creep.memory.link == null) {
creep.memory.link = Memory[creep.room.name].links.upgradeLink;
}
}
case "linkUpgrader":
//console.log(creep.room.controller.level)
//room max level
if (creep.room.controller.level == 8) {
// console.log("Ticks until upgraders are needed: " + creep.room.controller.ticksToDowngrade)
//about to downgrade
if (creep.room.controller.ticksToDowngrade < 1000) {
roleLinkUpgrader.run(creep);
break;
} else {
if (Memory[creep.room.name].links.upgradeLink == -1) {
roleLinkUpgrader.run(creep)
} else {
// console.log("What to do?");
//roleLinkUpgrader.run(creep);
roleRepairer.run(creep);
break;
}
}
} else {
roleLinkUpgrader.run(creep);
break;
}
case "collector":
collect.dead.run(creep);
break;
case "settler":
roleSettler.run(creep);
break;
case "importer":
roleImporter.run(creep);
break;
default:
creep.memory.role = "sourceFarmer";
creep.memory.team = 0;
roleSourceFarmer.run(creep);
break;
}
} else {
switch (creep.memory.role) {
case "settler":
roleSettler.run(creep);
break;
case "importer":
roleImporter.run(creep);
break;
default:
//creep.memory.role = "settler"
break;
}
}
}
}
}
};
module.exports = mgr;