'use strict';

// Autogenerated code
require('_generated');

for (var i in AI.extensions.library) {
    for (var j in AI.extensions.library[i]) {
        AI[j] = AI.extensions.library[i][j];
    }
}

function setupSpawn(spawn) {
    Memory.spawns[spawn] = {};
    Memory.spawns[spawn].spawnPriorityQueue = [];
    Memory.spawns[spawn].spawnQueue = [];
}

function firstTurn() {
    for (var item in Memory) {
        if (item === "creeps") {
            for (var sub in Memory.creeps) {
                delete Memory.creeps[sub];
            }
            continue;
        }
        if (item === "permanent") continue;
        delete Memory[item];
    }

    Memory.spawnQueue = AI.settings.spawnQueue;
    Memory.spawnPriorityQueue = AI.settings.spawnPriorityQueue;
    Memory.spawns = {};
    Memory.sources = {};

    console.log('Controller: Memory reset');
}

function setup() {
    for (var spawn in Game.spawns) {
        if (typeof Memory.spawns[spawn] !== "object") {
            setupSpawn(spawn);
        }
    }
}

module.exports = function() {
    if (AI.isFirstTurn()) firstTurn();
    setup();
};
@@ -189,24 +189,219 @@
 %5D;%0A    %7D%0A%7D%0A%0A
+AI.reset = function() %7B%0A    for (var i in AI.extensions.library) %7B%0A        if (typeof AI.extensions.library%5Bi%5D === %22function%22) %7B%0A            AI.extensions.library%5Bi%5D.reset();%0A        %7D%0A    %7D%0A%7D;%0A%0A
 function set

Add AI.reset to reset libraries in AI scope