<commit_before>// @todo Try to have different targets.
// @todo Use energy from storage.
// @todo Walls and ramparts should be repaired to the same amount, not percentage.

var creepGeneral = require('creep.general');
var utilities = require('utilities');

var wallHealth = {
    0: 1,
    1: 5000,
    2: 30000,
    3: 100000,
    4: 300000,
    5: 1000000,
    6: 2000000,
    7: 5000000,
    8: 300000000,
};

/**
 * Collects information about all damaged buildings in the current room.
 */
Creep.prototype.getAvailableRepairTargets = function () {
    var creep = this;
    var options = [];

    var targets = creep.room.find(FIND_STRUCTURES, {
        filter: (structure) => structure.hits < structure.hitsMax
    });

    for (var i in targets) {
        var target = targets[i];

        var option = {
            priority: 4,
            weight: 1 - target.hits / target.hitsMax, // @todo Also factor in distance.
            type: 'structure',
            object: target,
        };

        var maxHealth = target.hitsMax;
        if (target.structureType == STRUCTURE_WALL || target.structureType == STRUCTURE_RAMPART) {
            option.priority--;

            // Walls and ramparts get repaired up to a certain health level.
            maxHealth = wallHealth[target.room.controller.level];
            if (target.hits >= maxHealth) {
                // Skip this.
                continue;
            }
            option.weight = 1 - target.hits / maxHealth;
            option.maxHealth = maxHealth;
        }

        if (target.hits / maxHealth > 0.9) {
            option.priority--;
        }
        if (target.hits / maxHealth < 0.2) {
            option.priority++;
        }

        // Roads are not that important, repair only when low.
        if (target.structureType == STRUCTURE_ROAD) {
            option.priority--;
        }<commit_msg>repair roads sooner if they are about to expire<commit_after>// @todo Try to have different targets.
// @todo Use energy from storage.
// @todo Walls and ramparts should be repaired to the same amount, not percentage.

var creepGeneral = require('creep.general');
var utilities = require('utilities');

var wallHealth = {
    0: 1,
    1: 5000,
    2: 30000,
    3: 100000,
    4: 300000,
    5: 1000000,
    6: 2000000,
    7: 5000000,
    8: 300000000,
};

/**
 * Collects information about all damaged buildings in the current room.
 */
Creep.prototype.getAvailableRepairTargets = function () {
    var creep = this;
    var options = [];

    var targets = creep.room.find(FIND_STRUCTURES, {
        filter: (structure) => structure.hits < structure.hitsMax
    });

    for (var i in targets) {
        var target = targets[i];

        var option = {
            priority: 4,
            weight: 1 - target.hits / target.hitsMax, // @todo Also factor in distance.
            type: 'structure',
            object: target,
        };

        var maxHealth = target.hitsMax;
        if (target.structureType == STRUCTURE_WALL || target.structureType == STRUCTURE_RAMPART) {
            option.priority--;

            // Walls and ramparts get repaired up to a certain health level.
            maxHealth = wallHealth[target.room.controller.level];
            if (target.hits >= maxHealth) {
                // Skip this.
                continue;
            }
            option.weight = 1 - target.hits / maxHealth;
            option.maxHealth = maxHealth;
        }

        if (target.hits / maxHealth > 0.9) {
            option.priority--;
        }
        if (target.hits / maxHealth < 0.2) {
            option.priority++;
        }

        // Roads are not that important, repair only when low.
        if (target.structureType == STRUCTURE_ROAD && target.hits > 1000) {
            option.priority--;
        }
{'fraction_non_alphanumeric': 0.10825013137151865, 'fraction_numerical': 0.03678402522333158, 'mean_word_length': 1.8667168674698795, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '1599459', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1079, 'n_words': 324}