Improved walking system.
This commit is contained in:
44
Screeps/main.js
Normal file
44
Screeps/main.js
Normal file
@@ -0,0 +1,44 @@
|
||||
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; });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user