Files
screeps/main.js
2023-08-24 01:48:31 +02:00

43 lines
1.3 KiB
JavaScript

// ########################################
// ########## MAIN ##########
// ########################################
const Class = require("Class");
const Job = require("Job");
const Room = require("Room");
const Structure = require("Structure");
module.exports.loop = function () {
if(!global.compiled) onRecompile();
else if (!global.started) onRestart();
else onTick();
}
function onRecompile(){
Class.setup();
Job.setup();
console.log("Script recompiled...");
global.compiled = true;
}
function onRestart(){
Object.values(Game.rooms).forEach(room => Room.begin(room));
Object.values(Game.spawns).forEach(spawn => Structure.begin(spawn));
Object.values(Game.creeps).forEach(creep => Job.begin(creep));
global.started = true;
}
function onTick(){
Object.values(Game.rooms).forEach(room => Room.tick(room));
Object.values(Game.spawns).forEach(spawn => Structure.tick(spawn));
Object.values(Game.creeps).forEach(creep => Job.tick(creep));
if(!(Game.time % 100)) cleanUp();
}
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; });
}