-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
101 lines (88 loc) · 3.04 KB
/
main.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
// import modules
require('prototype.creep');
require('prototype.tower');
require('prototype.spawn');
require('prototype.link');
require('traveler');
require('run.marketAnalysis');
const profiler = require('screeps-profiler');
var grafana = require('grafana-tracking');
var reaction = require('run.reaction');
// This line monkey patches the global prototypes.
profiler.enable();
module.exports.loop = function() {
const gameTime = Game.time;
profiler.wrap(function() {
// Memory.minCostOfMinerals = { H:.135, O: .07, K: .09, };
// check for memory entries of dead creeps by iterating over Memory.creeps
for (let name in Memory.creeps) {
// and checking if the creep is still alive
if (Game.creeps[name] == undefined) {
// if not, delete the memory entry
delete Memory.creeps[name];
}
}
// for each creeps
for (let name in Game.creeps) {
// run creep logic if the creep isn't spawning
if (!Game.creeps[name].spawning) {
Game.creeps[name].runRole();
}
}
// find all towers
var towers = _.filter(Game.structures, s => s.structureType == STRUCTURE_TOWER);
// for each tower
for (let tower of towers) {
// run tower logic
tower.defend();
}
var myRooms = _(Memory.stats.roomSummary).omit(_.isUndefined).omit(_.isNull).value();
// for each spawn
for (let spawnName in Game.spawns) {
if (Game.spawns[spawnName].spawning == null) {
// run spawn logic
Game.spawns[spawnName].spawnCreepsIfNecessary();
}
}
var links = _.filter(Game.structures, s => s.structureType == STRUCTURE_LINK);
// for each link in the room
for (let link of links) {
// run link logic
link.findLinkType();
}
// every tenth game tick...
if (gameTime % 10 == 0) {
// Run marketAnalysis
var terminals = _.filter(Game.structures, s => s.structureType == STRUCTURE_TERMINAL);
// for each terminal
for (let terminal of terminals) {
if (terminal.cooldown == 0) {
// run market logic
//terminal.runMarketAnalysis();
}
}
// look for rooms that need building attention
for (let room in myRooms) {
numberOfExtensions = Game.rooms[room].find(FIND_MY_STRUCTURES, {
filter: {
structureType: STRUCTURE_EXTENSION
}
});
numberOfExtensionConstructionSites = Game.rooms[room].find(FIND_CONSTRUCTION_SITES, {
filter: {
structureType: STRUCTURE_EXTENSION
}
});
totalNumberOfExtensions = numberOfExtensions.length + numberOfExtensionConstructionSites.length;
numberOfAvailableExtensions = CONTROLLER_STRUCTURES["extension"][Game.rooms[room].controller.level];
if (numberOfAvailableExtensions > totalNumberOfExtensions) {
console.log("ROOM ", room, " IS READY FOR BUILDING")
}
}
// collect grafana stats
grafana.collect_stats();
Memory.stats.cpu.used = Game.cpu.getUsed();
}
//reaction.runReaction();
});
}