<commit_before>var mod = {};
module.exports = mod;

mod.loop = function() {
    const flags = _.filter(Game.flags, o => FlagUtil.upgrading.examine(o));
    for(const flag of flags) {
        const room = flag.room;
        if(room) {
            //We do have vision
            this.queueCreeps(room);
        } else {
            //No vision
            // but this flag should only place in base room!
            console.log(`Found upgrading(base) flag[${flag.name}] in no-vision room[${flag.roomName}]!`);
        }
    }
};

//Upgrader and keeper
mod.queueCreeps = function(room) {
    //=== Role count ===
    const cnt = room.cachedRoleCount();

    //Only spawn keeper if storage present
    //spawn keeper first, so there will be energy source for upgrader
    if(room.storage && cnt.total[C.KEEPER] === 0) {
        room.queue.normal.push(C.KEEPER);
        cnt.queue[C.KEEPER]++;
        cnt.total[C.KEEPER]++;
    }

    //Only spawn upgrader if there is no structures need to be build
    const energyForSpawnCapacity = room.energyCapacityAvailable;
    const dynamicMaxExtraAmount = Setup[C.UPGRADER].dynamicExtraAmount(room);
    const totalEnergyNeed = 650+dynamicMaxExtraAmount*700;
    //Currently energy capacity can't afford single bigger creep
    // so let's add amount of upgraders
    let upgraderAmount = Math.floor(totalEnergyNeed/energyForSpawnCapacity);
    upgraderAmount = Math.min(3, upgraderAmount); // 3 at most, more creep more cpu and more crowded
    const needBuildStructures = room.cachedFind(FIND_CONSTRUCTION_SITES);
    if(needBuildStructures.length === 0 && room.controller.container) {
        if(cnt.total[C.UPGRADER] < upgraderAmount) {
            room.queue.normal.push(C.UPGRADER);
            cnt.queue[C.UPGRADER]++;
            cnt.total[C.UPGRADER]++;
        }
    }
};<commit_msg>only spawn 1 upgrader if there is no stoorage<commit_after>var mod = {};
module.exports = mod;

mod.loop = function() {
    const flags = _.filter(Game.flags, o => FlagUtil.upgrading.examine(o));
    for(const flag of flags) {
        const room = flag.room;
        if(room) {
            //We do have vision
            this.queueCreeps(room);
        } else {
            //No vision
            // but this flag should only place in base room!
            console.log(`Found upgrading(base) flag[${flag.name}] in no-vision room[${flag.roomName}]!`);
        }
    }
};

//Upgrader and keeper
mod.queueCreeps = function(room) {
    //=== Role count ===
    const cnt = room.cachedRoleCount();

    //Only spawn keeper if storage present
    //spawn keeper first, so there will be energy source for upgrader
    if(room.storage && cnt.total[C.KEEPER] === 0) {
        room.queue.normal.push(C.KEEPER);
        cnt.queue[C.KEEPER]++;
        cnt.total[C.KEEPER]++;
    }

    let upgraderAmount = 1;
    if(room.storage) {
        const energyForSpawnCapacity = room.energyCapacityAvailable;
        const dynamicMaxExtraAmount = Setup[C.UPGRADER].dynamicExtraAmount(room);
        const totalEnergyNeed = 650+dynamicMaxExtraAmount*700;
        //Currently energy capacity can't afford single bigger creep
        // so let's add amount of upgraders
        upgraderAmount = Math.floor(totalEnergyNeed/energyForSpawnCapacity);
        upgraderAmount = Math.min(3, upgraderAmount); // 3 at most, more creep more cpu and more crowded
    }
    const needBuildStructures = room.cachedFind(FIND_CONSTRUCTION_SITES);
    //Only spawn upgrader if there is no structures need to be build
    if(needBuildStructures.length === 0 && room.controller.container) {
        if(cnt.total[C.UPGRADER] < upgraderAmount) {
            room.queue.normal.push(C.UPGRADER);
            cnt.queue[C.UPGRADER]++;
            cnt.total[C.UPGRADER]++;
        }
    }
};
{'fraction_non_alphanumeric': 0.11980957418672308, 'fraction_numerical': 0.0058185665167944985, 'mean_word_length': 2.6087786259541983, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7281796', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1146, 'n_words': 285}