<commit_before>let mod = new ActionObj('Repair');
module.exports = mod;

//Build rampart maintain it to threshold
mod.nextTarget = function() {
    return Util.Mark.handleMark(this.creep, creep => {
        //First repair structure except rampart(which will be handled in maintain action)
        //  and wall(whose priority is low)
        const target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
            filter: function(o) {
                return o.structureType!=STRUCTURE_WALL && o.structureType!=STRUCTURE_RAMPART;
            }
        });
        if(!target) {
            //Now we can find low hits wall
            return creep.pos.findClosestByRange(Util.War.getWallsForMaintain(creep.room));
        } else {
            return target;
        }
    }, this.actionName);
};

mod.loop = function(creep) {
    return this.loop0(creep, (creep, target) => {
        const result = creep.repair(target);
        if(result == ERR_NOT_IN_RANGE) {
            creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
        } else if(result == OK) {
            if(target.structureType==STRUCTURE_WALL && Util.War.canReleaseWall(target.hits)) {
                Util.Mark.unmarkTarget(creep, this.actionName);
            } else if(target.hits==target.hitsMax) {
                Util.Mark.unmarkTarget(creep, this.actionName);
            }
        } 
    });
};<commit_msg>fixed target finding logic so builder will not try to repair container, controller etc.<commit_after>let mod = new ActionObj('Repair');
module.exports = mod;

mod.nextTarget = function() {
    return Util.Mark.handleMark(this.creep, creep => {
        //First repair structure except rampart(which will be handled in maintain action)
        //  and wall(whose priority is low)
        const target = creep.pos.findClosestByRange(FIND_MY_STRUCTURES, {
            filter: function(o) {
                //return o.structureType!=STRUCTURE_WALL && o.structureType!=STRUCTURE_RAMPART
                // && o.structureType!=STRUCTURE_CONTAINER;
                return o.structureType!=STRUCTURE_RAMPART && o.hits<o.hitsMax;
            }
        });
        if(!target) {
            //Now we can find low hits wall
            return creep.pos.findClosestByRange(Util.War.getWallsForMaintain(creep.room));
        } else {
            return target;
        }
    }, this.actionName);
};

mod.loop = function(creep) {
    return this.loop0(creep, (creep, target) => {
        //console.log('Loop repair action whose target is '+JSON.stringify(target));
        const result = creep.repair(target);
        if(result == ERR_NOT_IN_RANGE) {
            creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
        } else if(result == OK) {
            if(target.structureType==STRUCTURE_WALL && Util.War.canReleaseWall(target.hits)) {
                Util.Mark.unmarkTarget(creep, this.actionName);
            } else if(target.hits==target.hitsMax) {
                Util.Mark.unmarkTarget(creep, this.actionName);
            }
        } 
    });
};
{'fraction_non_alphanumeric': 0.12176759410801964, 'fraction_numerical': 0.0006546644844517185, 'mean_word_length': 2.347207009857612, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, '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': '6303674', 'n_tokens_mistral': 916, 'n_tokens_neox': 909, 'n_words': 180}