Created miner, made harvester pick resources and added reset commands.

This commit is contained in:
Douwe Ravers
2023-08-26 16:57:38 +02:00
parent 76650e22ac
commit e294ad29fe
13 changed files with 310 additions and 136 deletions

30
main.js
View File

@@ -1,11 +1,7 @@
// ########################################
// ########## MAIN ##########
// ########################################
const creepClass = require("ClassCreep");
const roomClass = require("ClassRoom");
const spawnClass = require("ClassSpawn");
const Commands = require("Commands");
const CreepClass = require("CreepClass");
const RoomClass = require("RoomClass");
const Structure = require("Structure");
module.exports.loop = function () {
if(!global.compiled) onRecompile();
@@ -13,28 +9,34 @@ module.exports.loop = function () {
else onTick();
}
function onRecompile(){
creepClass.setup();
roomClass.setup();
spawnClass.setup();
function onRecompile(){
setupClasses();
console.log("Script recompiled...");
global.compiled = true;
}
function onRestart(){
Object.values(Game.rooms).forEach(room => room.begin());
Object.values(Game.spawns).forEach(spawn => spawn.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.spawns).forEach(spawn => spawn.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; });