- foreach <[initial_branch_tiles]> as:i_tile: - define has_root False - define branched_tiles - define center <[i_tile].center.flag[build.center]> - define type <[center].flag[build.type]> - define branched_tiles <[branched_tiles].include[<[i_tile]>]> #if root, everything connected to this structure is fine - if |<[type]>]>: - foreach next - define nearby_tiles <[center].find_blocks_flagged[build.structure].within[5].parse[flag[build.structure]].deduplicate> - define connected_tiles <[nearby_tiles].filter[intersects[<[i_tile]>]]> - while <[connected_tiles].any> && !: - define branched_tiles <[branched_tiles].include[<[connected_tiles]>]> - define new_connected_tiles - foreach <[connected_tiles]> as:c_tile: - define center <[c_tile].center.flag[build.center]> - define type <[center].flag[build.type]> #if it's a root, then everything is chilling - if |<[type]>]>: - define has_root True - while stop #this time, the nearby tiles will INCLUDE its own tile - define nearby_tiles <[center].find_blocks_flagged[build.structure].within[5].parse[flag[build.structure]].deduplicate> - define next_tiles <[nearby_tiles].filter[intersects[<[c_tile]>]]> - define connected_tiles <[connected_tiles].include[<[next_tiles]>]> - define connected_tiles <[connected_tiles].deduplicate> - if <[has_root]>: - foreach next - narrate "remove <[branched_tiles].size> tiles"