-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
88 lines (84 loc) · 2.91 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
if(Game.cpu.bucket < 500) { throw new Error('Super Low Bucket, Recovery Mode Activated'); }
// DEFAULT
// Main imports these should be cached
require('game.constants'); // Game consts
require('global.stuff'); // Settings and stuff
require('global.colours'); // Colours various variables
require('global.speech'); // Colours various variables
require('global.friends'); // The global friend list
var Traveler = require('Traveler');
// Get the prototypes
var protoypes = [
require('prototype.roomposition'),
require('prototype.structures'),
require('prototype.sources'),
require('prototype.room'),
require('prototype.creep'),
require('prototype.spawn'),
];
// var i = protoypes.length;
// while(i--) {
// protoypes[i]();
// }
var spawner = require('work.spawn');
var movement = require('work.movement');
var cleaner = require('work.cleaner');
var towers = require('work.towers');
var counter = require('work.counter');
var screepsplus = require('screepsplus');
// Load the new Queue
const q = require('prototype.queue');
global.Queue = new q.Queue();
global.feedEnabled = false;
// const profiler = require('screeps-profiler');
// profiler.enable();
/**
* Main game loop, call all other functions from here
*/
module.exports.loop = function () {
//profiler.wrap(function() { // Start of profiler wrapper
var debug = false;
// Only need these once every 10 ticks
if (Game.time % 10 == 0) {
cleaner.run(debug);
if (feedEnabled) {
counter.runRoomFeed();
} else {
counter.clearRoomFeed();
}
}
// Run the source setups once every 50 ticks
if (Game.time % 50 == 0) {
var miner = require('role.energyMiner');
var extractor = require('role.extractor');
pause(52);
miner.setup();
pause(54);
extractor.setup();
}
// Only need these once every 5 ticks
if (Game.time % 5 == 0) {
// Setup rooms before we run the spawner
pause(60);
counter.setupRoomRoles(debug);
console.log(Game.time + ':CPU:{' + Game.cpu.tickLimit + '} ' + '{' + Game.cpu.bucket + '}' + counter.run(debug) + ' {' + Game.cpu.getUsed().toFixed(3) + '}');
let Before = Game.cpu.getUsed();
pause(64);
if (global.Queue.process()) { console.log('Queue spawned a creep'); } else { console.log('Running old spawner'); spawner.run(debug); }
let After = Game.cpu.getUsed() - Before;
console.log('Spawners used:' + After + ' CPU');
pause(68);
global.haulerSetup();
pause(70);
}
pause(72);
movement.run(debug);
pause(74);
towers.run(debug);
pause(76);
screepsplus.collect_stats();
Memory.stats.cpu.used = Game.cpu.getUsed();
pause(79);
console.log(Game.time + ':CPU:{' + Game.cpu.tickLimit + '} ' + '{' + Game.cpu.bucket + '} {' + Game.cpu.getUsed().toFixed(3) + '}');
//}); // End of profiler wrapper
}