<commit_before>// TODO: Help build ally construction sites (without accidently steping on them)
let roleBuilder = {
    run: function(creep) {
        creep.memory.executingRole = "builder";
        
        if (creep.memory.working == false
            && creep.carryCapacityAvailable == 0) {
            creep.memory.working = true;
            creep.memory.sourceID = undefined; // can be a harvester when not working
            creep.memory.demolishStructure = undefined; // can be a demolisher
        }
        else if (creep.memory.working == true
            && (creep.carry[RESOURCE_ENERGY] == 0 
                && (creep.memory.role != "builder" 
                    || (creep.carry[RESOURCE_POWER] || 0) == 0))) {
            creep.memory.working = false;
            creep.memory.constructionSite = undefined;
            creep.memory.repairStructure = undefined; // can be a repairer when working
            creep.memory.depositStructure = undefined; // can be a harvester when working
        }
        
        if (creep.memory.working == true) {
            let constructionSiteID = _.get(creep.memory, ["constructionSite", "id"], undefined);
            let constructionSite = Game.getObjectById(constructionSiteID);
            let constructionSiteMemPos = _.get(creep.memory, ["constructionSite", "pos"], undefined);
            let repairStructureID = _.get(creep.memory, ["repairStructure", "id"], undefined);
            if (constructionSite == undefined && constructionSiteMemPos != undefined) {
                let constructionSiteMemRoomName = _.get(creep.memory, ["constructionSite", "pos", "roomName"], undefined); 
                if (Game.rooms[constructionSiteMemRoomName] == undefined) {
                    constructionSitePos = RoomPositionFromObject(constructionSiteMemPos);
                    creep.travelTo(constructionSitePos, {
                        range: 3
                    });
                    creep.say(travelToIcons(creep) + constructionSitePos.roomName, true);
                    return;
                }
                else if (repairStructureID == undefined) {
                    creep.memory.constructionSite = undefined;
                    let newRampart = creep.pos.findClosestByRange(FIND_MY_STRUCTURES, {
                        filter: (s) => (s.hits <= RAMPART_DECAY_AMOUNT
                            && s.structureType == STRUCTURE_RAMPART
                    )});
                    if (newRampart != undefined) {
                        creep.memory.repairStructure = { 
                            id: newRampart.id
                            , pos: newRampart.pos
                        };
                        creep.say(ICONS["wait00"] + ICONS["repair"] + ICONS[STRUCTURE_RAMPART], true);
                        return; // need to wait till next tick to repair it for some reason
                    }
                }
            }
            
            if (repairStructureID != undefined) {
                ROLES["repairer"].run(creep);
                return;
            }
            
            if (constructionSite == undefined
                && _.size(Game.constructionSites) > 0
                && (creep.carry[RESOURCE_POWER] || 0) == 0) {
                let roomConstructionSites = creep.room.find(FIND_MY_CONSTRUCTION_SITES);
                /*
                if (roomConstructionSites.length == 0) { // TODO: Change this block to check if there's any in rooms the creep can reasonably reach with construction sites needing to be built in them
                    for (let roomID in Game.rooms) {
                        if (roomID != creep.room.name) {
                            roomConstructionSites = Game.rooms[roomID].find(FIND_MY_CONSTRUCTION_SITES);
                            if (roomConstructionSites.length > 0) {
                                break;
                            }
                        }
                    }
                }
                */
                if (roomConstructionSites.length > 0) {
                    if (_.get(Memory.rooms, [creep.room.name, "buildOrderFILO"], false) == true) {
                        constructionSite = roomConstructionSites[roomConstructionSites.length - 1]; // TODO: Get max based on id instead
                        creep.memory.constructionSite = { 
                            id: constructionSite.id
                            , pos: constructionSite.pos
                        };
                    }
                    else {
                        let priorityQueue = [STRUCTURE_SPAWN, 
                                             STRUCTURE_EXTENSION, 
                                             STRUCTURE_CONTAINER, 
                                             STRUCTURE_STORAGE, 
                                             STRUCTURE_RAMPART, 
                                             STRUCTURE_WALL, 
                                             STRUCTURE_TOWER, 
                                             STRUCTURE_ROAD, 
                                             STRUCTURE_LINK, 
                                             STRUCTURE_EXTRACTOR, 
                                             STRUCTURE_LAB, 
                                             STRUCTURE_TERMINAL, 
                                             STRUCTURE_OBSERVER, 
                                             STRUCTURE_POWER_SPAWN, 
                                             STRUCTURE_NUKER];
                        let i = 0;
                        do {
                            constructionSite = creep.pos.findClosestByRange(roomConstructionSites, {
                                filter: function(c) {
                                    return c.structureType == priorityQueue[i]
                            }});
                            ++i;
                        }
                        while (i < priorityQueue.length
                            && constructionSite == undefined); // TODO: Change this to a for...of loop with a break case for when constructionSite != undefined
                        
                        if (constructionSite != undefined) {
                            creep.memory.constructionSite = { 
                                id: constructionSite.id
                                , pos: constructionSite.pos
                            };
                        }
                        else {
                            creep.memory.constructionSite = undefined;
                        }
                    }
                }
                else {
                    creep.memory.constructionSite = undefined;
                }
            }
            
            if(constructionSite != undefined) {
                let err = creep.build(constructionSite);<commit_msg>Added TODO for including STRUCTURE_FACTORY in build order.<commit_after>// TODO: Help build ally construction sites (without accidently steping on them)
let roleBuilder = {
    run: function(creep) {
        creep.memory.executingRole = "builder";
        
        if (creep.memory.working == false
            && creep.carryCapacityAvailable == 0) {
            creep.memory.working = true;
            creep.memory.sourceID = undefined; // can be a harvester when not working
            creep.memory.demolishStructure = undefined; // can be a demolisher
        }
        else if (creep.memory.working == true
            && (creep.carry[RESOURCE_ENERGY] == 0 
                && (creep.memory.role != "builder" 
                    || (creep.carry[RESOURCE_POWER] || 0) == 0))) {
            creep.memory.working = false;
            creep.memory.constructionSite = undefined;
            creep.memory.repairStructure = undefined; // can be a repairer when working
            creep.memory.depositStructure = undefined; // can be a harvester when working
        }
        
        if (creep.memory.working == true) {
            let constructionSiteID = _.get(creep.memory, ["constructionSite", "id"], undefined);
            let constructionSite = Game.getObjectById(constructionSiteID);
            let constructionSiteMemPos = _.get(creep.memory, ["constructionSite", "pos"], undefined);
            let repairStructureID = _.get(creep.memory, ["repairStructure", "id"], undefined);
            if (constructionSite == undefined && constructionSiteMemPos != undefined) {
                let constructionSiteMemRoomName = _.get(creep.memory, ["constructionSite", "pos", "roomName"], undefined); 
                if (Game.rooms[constructionSiteMemRoomName] == undefined) {
                    constructionSitePos = RoomPositionFromObject(constructionSiteMemPos);
                    creep.travelTo(constructionSitePos, {
                        range: 3
                    });
                    creep.say(travelToIcons(creep) + constructionSitePos.roomName, true);
                    return;
                }
                else if (repairStructureID == undefined) {
                    creep.memory.constructionSite = undefined;
                    let newRampart = creep.pos.findClosestByRange(FIND_MY_STRUCTURES, {
                        filter: (s) => (s.hits <= RAMPART_DECAY_AMOUNT
                            && s.structureType == STRUCTURE_RAMPART
                    )});
                    if (newRampart != undefined) {
                        creep.memory.repairStructure = { 
                            id: newRampart.id
                            , pos: newRampart.pos
                        };
                        creep.say(ICONS["wait00"] + ICONS["repair"] + ICONS[STRUCTURE_RAMPART], true);
                        return; // need to wait till next tick to repair it for some reason
                    }
                }
            }
            
            if (repairStructureID != undefined) {
                ROLES["repairer"].run(creep);
                return;
            }
            
            if (constructionSite == undefined
                && _.size(Game.constructionSites) > 0
                && (creep.carry[RESOURCE_POWER] || 0) == 0) {
                let roomConstructionSites = creep.room.find(FIND_MY_CONSTRUCTION_SITES);
                /*
                if (roomConstructionSites.length == 0) { // TODO: Change this block to check if there's any in rooms the creep can reasonably reach with construction sites needing to be built in them
                    for (let roomID in Game.rooms) {
                        if (roomID != creep.room.name) {
                            roomConstructionSites = Game.rooms[roomID].find(FIND_MY_CONSTRUCTION_SITES);
                            if (roomConstructionSites.length > 0) {
                                break;
                            }
                        }
                    }
                }
                */
                if (roomConstructionSites.length > 0) {
                    if (_.get(Memory.rooms, [creep.room.name, "buildOrderFILO"], false) == true) {
                        constructionSite = roomConstructionSites[roomConstructionSites.length - 1]; // TODO: Get max based on id instead
                        creep.memory.constructionSite = { 
                            id: constructionSite.id
                            , pos: constructionSite.pos
                        };
                    }
                    else {
                        let priorityQueue = [STRUCTURE_SPAWN, 
                                             STRUCTURE_EXTENSION, 
                                             STRUCTURE_CONTAINER, 
                                             STRUCTURE_STORAGE, 
                                             STRUCTURE_RAMPART, 
                                             STRUCTURE_WALL, 
                                             STRUCTURE_TOWER, 
                                             STRUCTURE_ROAD, 
                                             STRUCTURE_LINK, 
                                             STRUCTURE_EXTRACTOR, 
                                             STRUCTURE_LAB, 
                                             STRUCTURE_TERMINAL, 
                                             STRUCTURE_OBSERVER, 
                                             STRUCTURE_POWER_SPAWN, 
                                             STRUCTURE_NUKER]; // TODO: Add STRUCTURE_FACTORY
                        let i = 0;
                        do {
                            constructionSite = creep.pos.findClosestByRange(roomConstructionSites, {
                                filter: function(c) {
                                    return c.structureType == priorityQueue[i]
                            }});
                            ++i;
                        }
                        while (i < priorityQueue.length
                            && constructionSite == undefined); // TODO: Change this to a for...of loop with a break case for when constructionSite != undefined
                        
                        if (constructionSite != undefined) {
                            creep.memory.constructionSite = { 
                                id: constructionSite.id
                                , pos: constructionSite.pos
                            };
                        }
                        else {
                            creep.memory.constructionSite = undefined;
                        }
                    }
                }
                else {
                    creep.memory.constructionSite = undefined;
                }
            }
            
            if(constructionSite != undefined) {
                let err = creep.build(constructionSite);
{'fraction_non_alphanumeric': 0.07730382879604018, 'fraction_numerical': 0.0021837239772892706, 'mean_word_length': 1.0582771535580524, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 62, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '736303', 'n_tokens_mistral': 3155, 'n_tokens_neox': 2972, 'n_words': 629}