Rewriting from scratch. Fixing old code is just less fun.

This commit is contained in:
DouweRavers
2022-04-29 01:45:27 +02:00
parent 5494f6fb17
commit 3e962ed04a
15 changed files with 159 additions and 974 deletions

62
main.js
View File

@@ -3,38 +3,42 @@
# Screeps 2022 #
######################*/
const spawns = require("spawns");
const creeps = require("creeps");
const towers = require("towers");
const ai_main = require("ai_main");
const system = require("system");
const system = require("_system");
module.exports.loop = function () {
// New system
if (global.started == undefined) {
if (global.compiled == undefined) {
// Configure classes and constants
setupClasses();
setConstants();
console.log("Script recompiled...");
global.started = true;
system.start();
}
system.update();
// Old system
ai_main.run();
towers.run();
spawns.run();
if (Game.time % 60 == 0) {
clear_dead_creeps_from_memory();
}
}
function clear_dead_creeps_from_memory() {
for (var cr in Memory.creeps) {
if (Game.creeps[cr] == null) {
delete (Memory.creeps[cr]);
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();
}
}
const creepClass = require("ClassCreep");
const roomClass = require("ClassRoom");
const spawnClass = require("ClassSpawn");
// Overwrite all game defined classes by mine inherited ones.
function setupClasses() {
creepClass.setup();
roomClass.setup();
spawnClass.setup();
}
// 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;
}