-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcleaner.constructionSites.js
36 lines (32 loc) · 1.33 KB
/
cleaner.constructionSites.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
const checkInterval = 10000;
const valuableSiteThreshold = 5000;
module.exports = class ConstructionSitesCleaner {
constructor() {
if(!Memory.constructionSitesCleaner) {
Memory.constructionSitesCleaner = {
sites: {}
}
}
this.memory = Memory.constructionSitesCleaner;
}
run() {
if(Game.time % checkInterval !== 0) return;
let previousSites = _.compact(_.map(Object.keys(this.memory.sites), (id) => Game.getObjectById(id)));
console.log("Previously had " + previousSites.length + " sites");
console.log("Now has " + Object.keys(Game.constructionSites).length + " sites");
for(let site of previousSites) {
if(site.progress === this.memory.sites[site.id]) {
console.log("No progess on " + site.id + " (" + site.structureType + "; " + site.progress + " / " + site.progressTotal +")");
if(site.progressTotal < valuableSiteThreshold) {
site.remove();
}
}
}
this.memory.sites = {};
_.forEach(Game.constructionSites, (site) => {
this.memory.sites[site.id] = site.progress;
});
}
}
const profiler = require("screeps-profiler");
profiler.registerClass(module.exports, 'ConstructionSitesCleaner');