45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
const Commands = require("Commands");
|
|
const CreepClass = require("CreepClass");
|
|
const RoomClass = require("RoomClass");
|
|
const Structure = require("Structure");
|
|
|
|
module.exports.loop = function () {
|
|
if(!global.compiled) onRecompile();
|
|
else if (!global.started) onRestart();
|
|
else onTick();
|
|
}
|
|
|
|
function onRecompile(){
|
|
setupClasses();
|
|
console.log("Script recompiled...");
|
|
global.compiled = true;
|
|
}
|
|
|
|
function onRestart(){
|
|
Object.values(Game.rooms).forEach(room => room.begin());
|
|
Object.values(Game.creeps).forEach(creep => creep.begin());
|
|
Object.values(Game.structures).forEach(structure => Structure.begin(structure));
|
|
global.started = true;
|
|
}
|
|
|
|
function onTick(){
|
|
Object.values(Game.rooms).forEach(room => room.tick());
|
|
Object.values(Game.creeps).forEach(creep => creep.tick());
|
|
Object.values(Game.structures).forEach(structure => Structure.tick(structure));
|
|
if(!(Game.time % 100)) cleanUp();
|
|
}
|
|
|
|
|
|
function setupClasses(){
|
|
Commands.setup();
|
|
CreepClass.setup();
|
|
RoomClass.setup();
|
|
Structure.setup();
|
|
}
|
|
|
|
function cleanUp(){
|
|
Object.keys(Memory.rooms).forEach(roomName => { if(!Game.rooms[roomName]) Memory.rooms[roomName] = undefined; });
|
|
Object.keys(Memory.creeps).forEach(creepName => { if(!Game.creeps[creepName]) Memory.creeps[creepName] = undefined; });
|
|
}
|
|
|