d_russia_reworked_show_errors = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            check_variable = {
                var = global.russia_reworked_core_file_missing
                value = 1
                compare = greater_than_or_equals
            }
        }
        log = " [?global.russia_reworked_core_file_missing] core files missing."
        log = " You should NOT play this mod with missing core files."
        log = " Any bug happening while playing with core files missing is not our responsibility."
    }
    else = {
        log = " No core file missing."
    }

    if = {
        limit = {
            check_variable = {
                var = global.russia_reworked_noncore_file_missing
                value = 1
                compare = greater_than_or_equals
            }
        }
        log = " [?global.russia_reworked_noncore_file_missing] non-core files missing."
        log = " Playing with non-core files missing is fine, but bugs and unexpected things might still happen."
    }
    else = {
        log = " No non-core file missing."
    }

    log = " Note : The result of this might not be accurate."
    log = "           You might or might not have conflicts that we did not detect."
}

d_russia_reworked_search_errors = {
    log = "-------------------- RUSSIA REWORKED --------------------"
    log = "Russia Reworked : Starting file debugging"
    log = "---------------------------------------------------------"

    set_variable = { global.russia_reworked_core_file_missing = 0 }
    set_variable = { global.russia_reworked_noncore_file_missing = 0 }

    add_to_array = { global.russia_reworked_countries_load = AEA }
    add_to_array = { global.russia_reworked_countries_load = AFF }
    add_to_array = { global.russia_reworked_countries_load = AIN }
    add_to_array = { global.russia_reworked_countries_load = ANT }
    add_to_array = { global.russia_reworked_countries_load = ARM }
    add_to_array = { global.russia_reworked_countries_load = ASR }
    add_to_array = { global.russia_reworked_countries_load = ASY }
    add_to_array = { global.russia_reworked_countries_load = AZR }
    add_to_array = { global.russia_reworked_countries_load = BAB }
    add_to_array = { global.russia_reworked_countries_load = BLR }
    add_to_array = { global.russia_reworked_countries_load = BRR }
    add_to_array = { global.russia_reworked_countries_load = BRP }
    add_to_array = { global.russia_reworked_countries_load = CAA }
    add_to_array = { global.russia_reworked_countries_load = CAF }
    add_to_array = { global.russia_reworked_countries_load = CAI }
    add_to_array = { global.russia_reworked_countries_load = CFR }
    add_to_array = { global.russia_reworked_countries_load = CIR }
    add_to_array = { global.russia_reworked_countries_load = CLG }
    add_to_array = { global.russia_reworked_countries_load = CRI }
    add_to_array = { global.russia_reworked_countries_load = DAG }
    add_to_array = { global.russia_reworked_countries_load = EAC }
    add_to_array = { global.russia_reworked_countries_load = EAR }
    add_to_array = { global.russia_reworked_countries_load = EFR }
    add_to_array = { global.russia_reworked_countries_load = EUR }
    add_to_array = { global.russia_reworked_countries_load = FAT }
    add_to_array = { global.russia_reworked_countries_load = FSZ }
    add_to_array = { global.russia_reworked_countries_load = GEO }
    add_to_array = { global.russia_reworked_countries_load = GPM }
    add_to_array = { global.russia_reworked_countries_load = HEJ }
    add_to_array = { global.russia_reworked_countries_load = HES }
    add_to_array = { global.russia_reworked_countries_load = HIT }
    add_to_array = { global.russia_reworked_countries_load = HOS }
    add_to_array = { global.russia_reworked_countries_load = KAL }
    add_to_array = { global.russia_reworked_countries_load = KAR }
    add_to_array = { global.russia_reworked_countries_load = KAZ }
    add_to_array = { global.russia_reworked_countries_load = KMI }
    add_to_array = { global.russia_reworked_countries_load = KUB }
    add_to_array = { global.russia_reworked_countries_load = KUR }
    add_to_array = { global.russia_reworked_countries_load = KYR }
    add_to_array = { global.russia_reworked_countries_load = MDE }
    add_to_array = { global.russia_reworked_countries_load = MED }
    add_to_array = { global.russia_reworked_countries_load = MEF }
    add_to_array = { global.russia_reworked_countries_load = MES }
    add_to_array = { global.russia_reworked_countries_load = MOI }
    add_to_array = { global.russia_reworked_countries_load = NAC }
    add_to_array = { global.russia_reworked_countries_load = NAF }
    add_to_array = { global.russia_reworked_countries_load = NEJ }
    add_to_array = { global.russia_reworked_countries_load = NOV }
    add_to_array = { global.russia_reworked_countries_load = OCE }
    add_to_array = { global.russia_reworked_countries_load = ODA }
    add_to_array = { global.russia_reworked_countries_load = POM }
    add_to_array = { global.russia_reworked_countries_load = PRM }
    add_to_array = { global.russia_reworked_countries_load = PRT }
    add_to_array = { global.russia_reworked_countries_load = RUA }
    add_to_array = { global.russia_reworked_countries_load = RHI }
    add_to_array = { global.russia_reworked_countries_load = ROS }
    add_to_array = { global.russia_reworked_countries_load = RYU }
    add_to_array = { global.russia_reworked_countries_load = SAE }
    add_to_array = { global.russia_reworked_countries_load = SAI }
    add_to_array = { global.russia_reworked_countries_load = SEA }
    add_to_array = { global.russia_reworked_countries_load = SFR }
    add_to_array = { global.russia_reworked_countries_load = SHB }
    add_to_array = { global.russia_reworked_countries_load = SHI }
    add_to_array = { global.russia_reworked_countries_load = SIB }
    add_to_array = { global.russia_reworked_countries_load = SIL }
    add_to_array = { global.russia_reworked_countries_load = SOJ }
    add_to_array = { global.russia_reworked_countries_load = SOV }
    add_to_array = { global.russia_reworked_countries_load = STP }
    add_to_array = { global.russia_reworked_countries_load = SWA }
    add_to_array = { global.russia_reworked_countries_load = TAJ }
    add_to_array = { global.russia_reworked_countries_load = TAT }
    add_to_array = { global.russia_reworked_countries_load = TEU }
    add_to_array = { global.russia_reworked_countries_load = THU }
    add_to_array = { global.russia_reworked_countries_load = TMS }
    add_to_array = { global.russia_reworked_countries_load = TOK }
    add_to_array = { global.russia_reworked_countries_load = TRE }
    add_to_array = { global.russia_reworked_countries_load = UES }
    add_to_array = { global.russia_reworked_countries_load = UKR }
    add_to_array = { global.russia_reworked_countries_load = URA }
    add_to_array = { global.russia_reworked_countries_load = UZB }
    add_to_array = { global.russia_reworked_countries_load = VLG }
    add_to_array = { global.russia_reworked_countries_load = VYA }
    add_to_array = { global.russia_reworked_countries_load = TAN }
    add_to_array = { global.russia_reworked_countries_load = WAC }

    #Focus Trees
    log = "Russia Reworked : Scanning Focus Tree files"
    if = {
        limit = {
            all_of_scopes = {
                array = global.russia_reworked_soviets

                has_focus_tree = russia2_soviet_focus
            }
        }
        set_global_flag = russia_reworked_focus_loaded_sov
    }
    else = {
        for_each_scope_loop = {
            array = global.russia_reworked_soviets
            break = break_loop

            if = {
                limit = {
                    NOT = {
                        has_focus_tree = russia2_soviet_focus
                    }
                }
                log = " [THIS.GetTag] [THIS.GetName] is missing russia2_soviet_focus"
                set_country_flag = russia_rework_focus_missing_sov
                add_to_variable = { global.russia_reworked_core_file_missing = 1 }
            }
        }
    }

    if = {
        limit = {
            UKR = {
                has_focus_tree = russia2_ukraine_focus
            }
        }
        set_global_flag = russia_reworked_focus_loaded_ukr
    }
    else = {
        log = " [UKR.GetTag] [UKR.GetName] is missing russia2_ukraine_focus"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            all_of_scopes = {
                array = global.russia_reworked_continents

                has_focus_tree = russia2_continents_focus
            }
        }
        set_global_flag = russia_reworked_focus_loaded_con
    }
    else = {
        for_each_scope_loop = {
            array = global.russia_reworked_continents
            break = break_loop

            if = {
                limit = {
                    NOT = {
                        has_focus_tree = russia2_continents_focus
                    }
                }
                log = " [THIS.GetTag] [THIS.GetName] is missing russia2_continents_focus"
                set_country_flag = russia_rework_focus_missing_con
                add_to_variable = { global.russia_reworked_core_file_missing = 1 }
            }
        }
    }

    if = {
        limit = {
            any_country = {
                has_focus_tree = soviet_focus
            }
        }
        for_each_scope_loop = {
            array = global.countries
            break = break_loop

            if = {
                limit = {
                    has_focus_tree = soviet_focus
                }
                log = " [THIS.GetTag] [THIS.GetName] has soviet_focus as their focus tree"
                log = " NOTE : While this is not technically a missing file, it will most likely cause issues. This focus tree should NOT be used."
                set_country_flag = russia_rework_using_soviet_focus
                add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
            }
        }
    }

    if = {
        limit = {
            all_of_scopes = {
                array = global.russia_reworked_russian_states

                if = {
                    limit = {
                        NOT = {
                            tag = UKR
                        }
                    }
                    has_focus_tree = russian_states_focus
                }
            }
        }
        set_global_flag = russia_reworked_focus_loaded_russian_states
    }
    else = {
        for_each_scope_loop = {
            array = global.russia_reworked_russian_states
            break = break_loop

            if = {
                limit = {
                    NOT = {
                        tag = UKR
                        has_focus_tree = russian_states_focus
                    }
                }
                log = " [THIS.GetTag] [THIS.GetName] is missing russian_states_focus"
                set_country_flag = russia_rework_focus_missing_rsc
                add_to_variable = { global.russia_reworked_core_file_missing = 1 }
            }
        }
    }

    #Decisions
    log = "Russia Reworked : Scanning Decisions files"
    SOV = {
        activate_decision = SOV_russia_reworked_load_decision_russia2
        activate_decision = SOV_russia_reworked_load_decision_soviet
        activate_decision = RSC_russia_reworked_load_decision_russia2
    }
    UKR = {
        activate_decision = UKR_russia_reworked_load_decision_russia2
    }
    if = {
        limit = {
            SOV = {
                has_decision = SOV_russia_reworked_load_decision_russia2
            }
        }
        set_global_flag = russia_reworked_decision_loaded_russia
        SOV = {
            remove_decision = SOV_russia_reworked_load_decision_russia2
        }
    }
    else = {
        log = " At least one of the 2 files, russia2_russia_decision_categories.txt or russia2_russia.txt, is missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            SOV = {
                has_decision = SOV_russia_reworked_load_decision_soviet
            }
        }
        for_each_scope_loop = {
            array = global.countries
            break = break_loop

            if = {
                limit = {
                    has_focus_tree = soviet_focus
                }
                log = " [THIS.GetName] has soviet_focus as their focus tree"
                log = " NOTE : While this is not technically a missing file, it will most likely cause issues. This focus tree should NOT be used."
                set_country_flag = russia_rework_using_soviet_focus
                add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
            }
        }
        set_global_flag = russia_reworked_decision_loaded_ukraine
        UKR = {
            remove_decision = UKR_russia_reworked_load_decision_russia2
        }
    }
    else = {
        log = " At least one of the 2 files, russia2_ukraine_decision_categories.txt and russia2_ukraine.txt, is missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            SOV = {
                has_decision = RSC_russia_reworked_load_decision_russia2
            }
        }
        set_global_flag = russia_reworked_decision_loaded_russian_states
        SOV = {
            remove_decision = RSC_russia_reworked_load_decision_russia2
        }
    }
    else = {
        log = " At least one of the 2 files, russia2_russian_states_decision_categories.txt and russia2_russian_states.txt, is missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    #Ideas
    log = "Russia Reworked : Scanning Idea files"
    SOV = {
        add_ideas = {
            SOV_russia2_idea_load
            UKR_russia2_idea_load
            CRI_russia2_idea_load
            CON_russia2_idea_load
            RSC_russia2_idea_load
            soviet_idea_load
            soviet_nsb_idea_load
            tajikistan_idea_load
            turkmenistan_idea_load
            uzbekistan_idea_load
        }
    }

    if = {
        limit = {
            NOT = {
                SOV = {
                    has_idea = SOV_russia2_idea_load
                }
            }
        }
        log = " Idea file russia2_russia.txt seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }
    if = {
        limit = {
            NOT = {
                SOV = {
                    has_idea = UKR_russia2_idea_load
                }
            }
        }
        log = " Idea file russia2_ukraine.txt seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }
    if = {
        limit = {
            NOT = {
                SOV = {
                    has_idea = CRI_russia2_idea_load
                }
            }
        }
        log = " Idea file russia2_crimea.txt seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }
    if = {
        limit = {
            NOT = {
                SOV = {
                    has_idea = CON_russia2_idea_load
                }
            }
        }
        log = " Idea file russia2_continents.txt seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }
    if = {
        limit = {
            NOT = {
                SOV = {
                    has_idea = RSC_russia2_idea_load
                }
            }
        }
        log = " Idea file russia2_russian_states.txt seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }
    if = {
        limit = {
            NOT = {
                SOV = {
                    has_idea = soviet_idea_load
                }
            }
        }
        log = " Idea file soviet.txt seems to be missing"
        add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
    }
    if = {
        limit = {
            NOT = {
                SOV = {
                    has_idea = soviet_nsb_idea_load
                }
            }
        }
        log = " Idea file soviet.txt seems to be missing"
        add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
    }
    if = {
        limit = {
            NOT = {
                SOV = {
                    has_idea = tajikistan_idea_load
                }
            }
        }
        log = " Idea file tajikstan.txt has been modified"
        add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
    }
    if = {
        limit = {
            NOT = {
                SOV = {
                    has_idea = turkmenistan_idea_load
                }
            }
        }
        log = " Idea file turkmenistan.txt seems to be missing"
        add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
    }
    if = {
        limit = {
            NOT = {
                SOV = {
                    has_idea = uzbekistan_idea_load
                }
            }
        }
        log = " Idea file uzbekistan.txt seems to be missing"
        add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
    }

    SOV = {
        remove_ideas = {
            SOV_russia2_idea_load
            UKR_russia2_idea_load
            CRI_russia2_idea_load
            CON_russia2_idea_load
            RSC_russia2_idea_load
            soviet_idea_load
            soviet_nsb_idea_load
            tajikistan_idea_load
            CRI_russia2_idea_load
            turkmenistan_idea_load
            uzbekistan_idea_load
        }
    }

    #Characters
    log = "Russia Reworked : Scanning Character files"
    if = {
        limit = {
            NOT = {
                SOV = {
                    has_character = russia_reworked_load_russian_states_characters
                }
            }
        }
        log = " Character file Russia2_russian_states.txt seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                SOV = {
                    has_character = russia_reworked_load_kazak_characters
                }
            }
        }
        log = " KAZ.txt Character file has been modified"
        add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                SOV = {
                    has_character = russia_reworked_load_kyrgy_characters
                }
            }
        }
        log = " KYR.txt Character file has been modified"
        add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                SOV = {
                    has_character = russia_reworked_load_generic_characters
                }
            }
        }
        log = " Russia2_generic.txt Character file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                SOV = {
                    has_character = russia_reworked_load_russian_characters
                }
            }
        }
        log = " Russia2_SOV.txt Character file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                SOV = {
                    has_character = russia_reworked_load_ukrainian_characters
                }
            }
        }
        log = " Russia2_UKR.txt Character file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    #Events
    log = "Russia Reworked : Scanning Event files"
    SOV = {
        country_event = baltic.2092066524
        country_event = russia2_baltic.2092066524
        country_event = NSB_poland_events.2092066524
        country_event = NSB_soviet_policies_of_collective_security.2092066524
        country_event = russia2_bulgaria.2092066524
        country_event = russia2_china.2092066524
        country_event = russia2_communist_china.2092066524
        country_event = russia2_continent.2092066524
        country_event = russia2_england.2092066524
        country_event = finland.2092066524
        country_event = russia2_finland.2092066524
        country_event = russia2_france.2092066524
        country_event = russia2_generic.2092066524
        country_event = russia2_germany.2092066524
        country_event = russia2_italy.2092066524
        country_event = russia2_japan.2092066524
        country_event = russia2_manchukuo.2092066524
        country_event = russia2_mongolia.2092066524
        country_event = newsrussia2.2092066524
        country_event = russia2_poland.2092066524
        country_event = russia2_revolutions.2092066524
        country_event = russia2_romania.2092066524
        country_event = soviet.2092066524
        country_event = russia2_russia.2092066524
        country_event = russia2_spain.2092066524
        country_event = russia2_tannu.2092066524
        country_event = russia2_turkey.2092066524
        country_event = russia2_ukraine.2092066524
        country_event = russia2_america.2092066524
        country_event = russia2_yaltas.2092066524
        country_event = russia2_russian_states.2092066524
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_baltic
            }
        }
        log = " Baltic.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_baltics
            }
        }
        log = " Russia2_baltic.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_poland_nsb
            }
        }
        log = " poland_nsb.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_russia_soviet_nsb
            }
        }
        log = " soviet_nsb.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_bulgarias
            }
        }
        log = " Russia2_bulgaria.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_chinas
            }
        }
        log = " Russia2_china.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_wtt_prcs
            }
        }
        log = " Russia2_communist_china.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_continents
            }
        }
        log = " Russia2_continent.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_englands
            }
        }
        log = " Russia2_england.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_finland
            }
        }
        log = " Finland.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_finlands
            }
        }
        log = " Russia2_finland.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_frances
            }
        }
        log = " Russia2_france.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_generics
            }
        }
        log = " Russia2_generic.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_germanys
            }
        }
        log = " Russia2_germany.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_italys
            }
        }
        log = " Russia2_italy.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_japans
            }
        }
        log = " Russia2_japan.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_manchukuos
            }
        }
        log = " Russia2_manchukuo.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_mongolias
            }
        }
        log = " Russia2_mongolia.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_newsrussia2
            }
        }
        log = " Russia2_news.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_noncore_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_polands
            }
        }
        log = " Russia2_poland.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_revolutions
            }
        }
        log = " Russia2_revolution.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_romanias
            }
        }
        log = " Russia2_romania.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_soviet
            }
        }
        log = " Soviet.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_soviets
            }
        }
        log = " Russia2_soviet.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_spains
            }
        }
        log = " Russia2_spain.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_tannu
            }
        }
        log = " russia2_tannu.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_turkeys
            }
        }
        log = " Russia2_turkey.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_ukraine
            }
        }
        log = " russia2_ukraine.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_americas
            }
        }
        log = " Russia2_america.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_yaltas
            }
        }
        log = " Russia2_yalta.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_events_loaded_russian_states
            }
        }
        log = " RussianStatesRussia2.txt event file seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
    }

    #Countries
    log = "Russia Reworked : Scanning Country files"
    for_each_loop = {
        array = global.russia_reworked_countries_load
        break = break_array
        value = v
        index = i

        if = {
            limit = {
                NOT = {
                    is_in_array = {
                        array = global.russia_reworked_countries
                        value = var:v
                    }
                }
            }
            add_to_variable = { global.russia_reworked_core_file_missing = 1 }
            if = {
                limit = {
                    is_in_array = {
                        array = global.countries
                        value = var:v
                    }
                }
                log = " Country with ID [?var:v] is present ([?var:v.GetName]) but not loaded properly"
                var:v = {
                    set_country_flag = russia_rework_country_missing
                }
            }
            else = {
                log = " Country with ID [?var:v] is missing ([?var:v.GetName])"
            }
        }
    }

    #Other Files
    log = "Russia Reworked : Scanning Other files"
    add_country_leader_trait = russia2_load_trait
    if = {
        limit = {
            has_country_leader_with_trait = russia2_load_trait
        }
        remove_country_leader_trait = russia2_load_trait
        set_global_flag = russia_reworked_traits_loaded
    }
    else = {
        log = " File Russia2Traits.txt seems to be missing"
        add_to_variable = { global.russia_reworked_core_file_missing = 1 }
        set_global_flag = russia_reworked_traits_missing
    }

    if = {
        limit = {
            check_variable = {
                var = global.russia_reworked_core_file_missing
                value = 1
                compare = greater_than_or_equals
            }
        }
        set_global_flag = russia_reworked_error
        log = "Russia Reworked : [?global.russia_reworked_core_file_missing] core files missing"
        log = "Russia Reworked : [?global.russia_reworked_noncore_file_missing] non core files missing"
    }
    else_if = {
        limit = {
            check_variable = {
                var = global.russia_reworked_noncore_file_missing
                value = 1
                compare = greater_than_or_equals
            }
        }
        log = "Russia Reworked : [?global.russia_reworked_noncore_file_missing] non core files missing"
    }
    else = {
        log = "Russia Reworked : No error detected"
    }

    log = "---------------------------------------------------------"
    log = "Russia Reworked : End of debugging"
    log = "-------------------- RUSSIA REWORKED --------------------"
}

d_russia_reworked_refresh_democratic_gui = {
    calculate_sov_gui_percentage_democratic_vote = yes
    log = "Russia Reworked debug :"
    log = " Voting progress bar refreshed."
}

d_russia_reworked_set_revolution_scale = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            OR = {
                check_variable = {
                    var = args^num
                    value = 1
                    compare = less_than
                }
                check_variable = {
                    var = args^num
                    value = 1
                    compare = greater_than
                }
            }
        }
        log = " Error :"
        log = " Expected [?1|Y0] argument, got [?args^num|R0]."
        log = " Usage : russia_reworked_set_revolution_scale {SCALE}"
        log = " SCALE : required, min:0, max:12"
    }
    else = {
        set_variable = { SOV.revolution_count = args^0 }
        set_variable = { SOV.revolution_count_gui = SOV.revolution_count }
		multiply_variable = { SOV.revolution_count_gui = 100 }
        set_variable = { SOV.revolution_final_count = 12 }
        subtract_from_variable = { SOV.revolution_final_count = SOV.revolution_count }
        clamp_variable = {
            var = SOV.revolution_count
            min = 0
            max = 12
        }
        clamp_variable = {
            var = SOV.revolution_count_gui
            min = 0
            max = 1000
        }
        clamp_variable = {
            var = SOV.revolution_final_count
            min = 0
            max = 12
        }
        log = " Set revolution scale to [?SOV.revolution_count|Y0]."
    }
}

d_russia_reworked_annex_cores = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            is_debug = yes
        }
        every_state = {
            limit = {
                is_core_of = FROM
                NOT = {
                    is_owned_by = FROM
                }
            }
            FROM = {
                transfer_state = PREV
            }
            log = " Transfered [THIS.GetName] to [FROM.GetNameDef]."
        }
    }
    else = {
        log = " Error :"
        log = " Only allowed in debug mode!"
    }
}

d_russia_reworked_annex_claims = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            is_debug = yes
        }
        every_state = {
            limit = {
                is_claimed_by = FROM
                NOT = {
                    is_owned_by = FROM
                }
            }
            FROM = {
                transfer_state = PREV
            }
            log = " Transfered [THIS.GetName] to [FROM.GetNameDef]."
        }
    }
    else = {
        log = " Error :"
        log = " Only allowed in debug mode!"
    }
}

d_russia_reworked_annex_puppets = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            is_debug = yes
        }
        every_other_country = {
            limit = {
                is_subject_of = FROM
            }
            FROM = {
                annex_country = {
                    target = PREV
                    transfer_troops = yes
                }
            }
            log = " Annexed [THIS.GetName]."
        }
    }
    else = {
        log = " Error :"
        log = " Only allowed in debug mode!"
    }
}

d_russia_reworked_battle_royale = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            NOT = {
                has_global_flag = russia_reworked_battle_royale_allowed
            }
        }
        set_global_flag = russia_reworked_battle_royale_allowed
        log = " Are you sure? There is no going back!"
        log = " Launch this console command again to confirm."
        log = " Make sure to pause the game (it might lag for a moment)."
    }
    else_if = {
        limit = {
            has_global_flag = russia_reworked_battle_royale_launched
        }
        log = " The battle royale has already been launched."
    }
    else_if = {
        limit = {
            NOT = {
                any_of_scopes = {
                    array = global.russia_reworked_russian_states

                    exists = yes
                }
            }
        }
        log = " Not enough countries exist to launch a battle royale."
    }
    else = {
        for_each_scope_loop = {
            array = global.russia_reworked_russian_states

            if = {
                limit = {
                    exists = yes
                }
                if = {
                    limit = {
                        is_in_faction = yes
                    }
                    leave_faction = yes
                }
                if = {
                    limit = {
                        is_subject = yes
                    }
                    OVERLORD = {
                        set_autonomy = {
                            target = PREV
                            autonomy_state = autonomy_free
                        }
                    }
                }
            }
        }

        for_each_scope_loop = {
            array = global.russia_reworked_russian_states

            if = {
                limit = {
                    exists = yes
                }
                for_each_scope_loop = {
                    array = global.russia_reworked_russian_states

                    if = {
                        limit = {
                            exists = yes
                            NOT = {
                                tag = PREV
                                has_war_with = PREV
                                is_subject = yes
                                is_in_faction = yes
                            }
                        }
                        PREV = {
                            declare_war_on = {
                                target = PREV
                                type = annex_everything
                            }
                        }
                    }
                }
            }
        }
        set_global_flag = russia_reworked_battle_royale_launched
        log = " Battle Royale begins!"
    }
}

d_russia_reworked_battle_royale_with_sov = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            SOV = {
                exists = yes
            }
        }
        if = {
            limit = {
                NOT = {
                    has_global_flag = russia_reworked_battle_royale_allowed
                }
            }
            set_global_flag = russia_reworked_battle_royale_allowed
            log = " Are you sure? There is no going back!"
            log = " Launch this console command again to confirm."
            log = " Make sure to pause the game (it might lag for a moment)."
        }
        else_if = {
            limit = {
                has_global_flag = russia_reworked_battle_royale_launched
            }
            log = " The battle royale has already been launched."
        }
        else_if = {
            limit = {
                NOT = {
                    any_of_scopes = {
                        array = global.russia_reworked_russian_states

                        exists = yes
                    }
                }
            }
            log = " Not enough countries exist to launch a battle royale."
        }
        else = {
            add_to_array = { global.russia_reworked_russian_states = SOV }
            for_each_scope_loop = {
                array = global.russia_reworked_russian_states

                if = {
                    limit = {
                        exists = yes
                    }
                    if = {
                        limit = {
                            is_in_faction = yes
                        }
                        leave_faction = yes
                    }
                    if = {
                        limit = {
                            is_subject = yes
                        }
                        OVERLORD = {
                            set_autonomy = {
                                target = PREV
                                autonomy_state = autonomy_free
                            }
                        }
                    }
                }
            }

            for_each_scope_loop = {
                array = global.russia_reworked_russian_states

                if = {
                    limit = {
                        exists = yes
                    }
                    for_each_scope_loop = {
                        array = global.russia_reworked_russian_states

                        if = {
                            limit = {
                                exists = yes
                                NOT = {
                                    tag = PREV
                                    has_war_with = PREV
                                    is_subject = yes
                                    is_in_faction = yes
                                }
                            }
                            PREV = {
                                declare_war_on = {
                                    target = PREV
                                    type = annex_everything
                                }
                            }
                        }
                    }
                }
            }
            remove_from_array = { global.russia_reworked_russian_states = SOV }
            set_global_flag = russia_reworked_battle_royale_launched
            log = " Battle Royale begins!"
        }
    }
    else = {
        log = " [SOV.GetNameDefCap] doesn't exist!"
    }
}

d_russia_reworked_debug_output = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            is_debug = yes
        }
        #Whatever to test here
        set_variable = { SOV.date_test = global.date }
        log = " Date : [?SOV.date_test.GetDateString]"
        log = " GetCurrentSelectedIndexNationalObligationsIcon : [FROM.GetCurrentSelectedIndexNationalObligationsIcon]"
    }
    else = {
        log = " Error :"
        log = " Only allowed in debug mode!"
    }
}

d_russia_reworked_lock_all_templates = {
    log = "Russia Reworked debug :"
    country_lock_all_division_template = yes
    log = " Templates locked."
}

d_russia_reworked_unlock_all_templates = {
    log = "Russia Reworked debug :"
    country_lock_all_division_template = no
    log = " Templates unlocked."
}

d_russia_reworked_is_in_array_scw_debug = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            is_debug = yes
        }
        if = {
            limit = {
                check_variable = {
                    var = args^num
                    value = 0
                    compare = greater_than
                }
            }
            if = {
                limit = {
                    is_in_array = { global.russian_scw_participants = var:args^0 }
                }
                log = " True"
            }
            else = {
                log = " False"
            }
        }
        else = {
            if = {
                limit = {
                    is_in_array = { global.russian_scw_participants = SOV }
                }
                log = " SOV : True"
            }
            else = {
                log = " SOV : False"
            }
            if = {
                limit = {
                    is_in_array = { global.russian_scw_participants = SOJ }
                }
                log = " SOJ : True"
            }
            else = {
                log = " SOJ : False"
            }
            if = {
                limit = {
                    is_in_array = { global.russian_scw_participants = UKR }
                }
                log = " UKR : True"
            }
            else = {
                log = " UKR : False"
            }
        }
    }
    else = {
        log = " Error :"
        log = " Only allowed in debug mode!"
    }
}

d_russia_reworked_clean_scw_array = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            is_debug = yes
        }
        sov_clean_scw_arrays = yes
    }
    else = {
        log = " Error :"
        log = " Only allowed in debug mode!"
    }
}

d_russia_reworked_turn_ukr_anarchist = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            is_debug = yes
        }
        if = {
            limit = {
                UKR = {
                    exists = yes
                    is_subject = no
                    NOT = {
                        has_government = anarchy
                    }
                }
            }
            UKR = {
                set_politics = {
                    ruling_party = anarchy
                    elections_allowed = no
                }
                clr_country_flag = ukr_anarchist_rebels
                custom_effect_tooltip = ukr_loses_all_cores
                custom_effect_tooltip = ukr_unlocks_anarchist_legetimacy_decisions
                add_ideas = UKR_Free_state
                add_popularity = {
                    ideology = anarchy
                    popularity = 0.5
                }
                set_global_flag = ukr_turned_anarchist_free_state
                set_temp_variable = { anarchy_support_divided_by_two = ukr.party_popularity_100@anarchy }
                divide_temp_variable = { anarchy_support_divided_by_two = 2 }
                for_each_loop = {
                    array = ukr.core_states
                    value = v
                    index = i
                    break = break_array

                    add_to_array = { ukr.temp_core_states = var:v }
                }
                for_each_loop = {
                    array = ukr.temp_core_states
                    value = v
                    index = i
                    break = break_array

                    if = {
                        limit = {
                            var:v = {
                                is_capital = yes
                                is_controlled_by = UKR
                            }
                        }
                        set_variable = { ukr.anarchist_support@var:v = 100 }
                    }
                    else = {
                        if = {
                            limit = {
                                var:v = {
                                    is_controlled_by = UKR
                                }
                            }
                            set_variable = { ukr.anarchist_support@var:v = var:anarchy_support_divided_by_two }
                        }
                        var:v = {
                            remove_core_of = UKR
                        }
                    }
                }
                ukr_update_state_cost = yes
                ukr_update_anarchist_states = yes
                ukr_update_current_view = yes
                ukr_add_daily_gain_anarchist_states = yes
                add_ideas = UKR_Anarchist_legitimacy
                for_each_scope_loop = {
                    array = global.russian_scw_participants

                    country_event = russia2_ukraine.39
                }
            }
            log = " Ukraine is now Anarchist."
        }
        else = {
            log = " Error :"
            log = " Cannot turn [UKR.GetNameDef] Anarchist at the moment."
        }
    }
    else = {
        log = " Error :"
        log = " Only allowed in debug mode!"
    }
}

d_russia_reworked_display_debug_variable = {
    log = "Russia Reworked debug :"
    log = " [USA.GetNameDefCap] : [?USA.max_available_manpower_k|0]"
    log = " [SOV.GetNameDefCap] : [?SOV.max_available_manpower_k]"
    log = " [FRA.GetNameDefCap] : [?FRA.max_available_manpower_k]"
    log = " [GER.GetNameDefCap] : [?GER.max_available_manpower_k]"
    log = " [ITA.GetNameDefCap] : [?ITA.max_available_manpower_k|0]"
    log = " [JAP.GetNameDefCap] : [?JAP.max_available_manpower_k]"
    log = " [ENG.GetNameDefCap] : [?ENG.max_available_manpower_k]"
    log = " [ROOT.GetNameDefCap] : [?max_available_manpower_k]"
}

d_russia_reworked_tsar_bomba_nuke_debug = {
    log = "Russia Reworked debug :"
    if = {
        limit = {
            OR = {
                check_variable = {
                    var = args^num
                    value = 1
                    compare = less_than
                }
                check_variable = {
                    var = args^num
                    value = 2
                    compare = greater_than
                }
            }
        }
        log = " Error :"
        log = " Expected [?1|Y0] or [?2|Y0] arguments, got [?args^num|R0]."
        log = " Usage : russia_reworked_tsar_bomba_nuke_debug {STATE_ID} {NUMBER_OF_NUKES}"
        log = " STATE_ID : required"
        log = " NUMBER_OF_NUKES : optional, default:3, min:1, max:100"
    }
    else = {
        if = {
            limit = {
                any_state = {
                    state = var:args^0
                }
            }
            log = " Beginning total annihilation of [?args^0.GetName]..."
            FROM = {
                set_temp_variable = { nuke_drop = 3 }
                if = {
                    limit = {
                        check_variable = {
                            var = args^1
                            value = 0
                            compare = greater_than
                        }
                    }
                    set_temp_variable = { nuke_drop = args^1 }
                    clamp_temp_variable = {
                        var = nuke_drop
                        min = 1
                        max = 100
                    }
                    round_temp_variable = nuke_drop
                }
                set_temp_variable = { nuke_count = 0 }

                while_loop_effect = {
                    break = break_loop
                    limit = {
                        check_variable = {
                            var = nuke_count
                            value = var:nuke_drop
                            compare = less_than
                        }
                    }

                    launch_nuke = {
                        state = var:args^0
                        use_nuke = no
                    }
                    var:args^0 = {
                        set_temp_variable = { population_loss_count = state_population_k@var:args^0 }
                        multiply_temp_variable = { population_loss_count = 0.01 }
                        if = {
                            limit = {
                                # Avoid integer overflow
                                check_variable = {
                                    var = population_loss_count
                                    value = 2140
                                    compare = greater_than_or_equals
                                }
                            }
                            set_temp_variable = { population_loss_count = 2140000 }
                        }
                        else = {
                            multiply_temp_variable = { population_loss_count = -1000 }
                        }
                        add_manpower = var:population_loss_count
                    }
                    add_to_temp_variable = { nuke_count = 1 }
                }
                log = " Done! Unpause the game."
            }
        }
        else = {
            log = " Error :"
            log = " Argument given ([?args^0]) is not a valid state ID."
            log = " Usage : russia_reworked_tsar_bomba_nuke_debug {STATE_ID} {NUMBER_OF_NUKES}"
            log = " STATE_ID : required"
            log = " NUMBER_OF_NUKES : optional, default:3, min:1, max:100"
        }
    }
}

d_russia_reworked_display_russian_states = {
    log = "Russia Reworked debug :"
    log = " Russian states tags :"

    for_each_scope_loop = {
        array = global.russia_reworked_russian_states

        log = " tag = [THIS.GetTag]"
    }
}

d_russia_reworked_display_russian_states_array = {
    log = "Russia Reworked debug :"
    log = " Russian states tags :"

    for_each_scope_loop = {
        array = global.russia_reworked_russian_states

        log = "\"[THIS.GetTag]\","
    }
}

d_russia_reworked_transfer_sou_array_to_soj = {
    log = "Russia Reworked debug :"

    for_each_scope_loop = {
        array = global.russian_scw_participants_sou

        add_to_array = { global.russian_scw_participants_soj = THIS }
    }

    log = " global.russian_scw_participants_soj^num = [?global.russian_scw_participants_soj^num]"
    log = " Done."
}