Simplyfied the code. Ready to rebuild on top of.
This commit is contained in:
54
main.js
54
main.js
@@ -1,47 +1,27 @@
|
||||
// ########################################
|
||||
// ########## MAIN ##########
|
||||
// ########################################
|
||||
|
||||
/* ######################
|
||||
# Screeps 2022 #
|
||||
######################*/
|
||||
|
||||
const system = require("system");
|
||||
const system = require("System");
|
||||
|
||||
module.exports.loop = function () {
|
||||
if (global.compiled == undefined) {
|
||||
// Configure classes and constants
|
||||
setupClasses();
|
||||
setConstants();
|
||||
console.log("Script recompiled...");
|
||||
global.compiled = true;
|
||||
} else {
|
||||
if (global.started == undefined) {
|
||||
// After one tick of configuration, restart the system.
|
||||
system.start();
|
||||
console.log("System started...");
|
||||
global.started = true;
|
||||
}
|
||||
system.update();
|
||||
}
|
||||
if(!global.compiled) onRecompile();
|
||||
else if (!global.started) onRestart();
|
||||
else onTick();
|
||||
}
|
||||
|
||||
const creepClass = require("ClassCreep");
|
||||
const roomClass = require("ClassRoom");
|
||||
const spawnClass = require("ClassSpawn");
|
||||
|
||||
// Overwrite all game defined classes by inherited ones.
|
||||
function setupClasses() {
|
||||
creepClass.setup();
|
||||
roomClass.setup();
|
||||
spawnClass.setup();
|
||||
function onRecompile(){
|
||||
system.setup();
|
||||
console.log("Script recompiled...");
|
||||
global.compiled = true;
|
||||
}
|
||||
|
||||
// Adds additional constants to global scope
|
||||
function setConstants() {
|
||||
// The states of a room.
|
||||
global.ROOMSTATE_NEUTRAL = 0;
|
||||
global.ROOMSTATE_CAPITAL = 1;
|
||||
global.ROOMSTATE_COLONY = 2;
|
||||
global.ROOMSTATE_OUTPOST = 3;
|
||||
function onRestart(){
|
||||
system.begin();
|
||||
global.started = true;
|
||||
}
|
||||
|
||||
// The roles of creeps.
|
||||
global.ROLE_HARVESTER = 0;
|
||||
function onTick(){
|
||||
system.tick();
|
||||
}
|
||||
Reference in New Issue
Block a user