﻿### Toggle Title Selected / Deselected ###
DI_selected_title_toggle = {
    scope = character # Player Character

    saved_scopes = {
        title # Title to pin
    }

    effect = {
        save_scope_as = player

        if = {
            limit = {
                is_target_in_variable_list = {
                    name = DI_selected_titles
                    target = scope:title
                }
            }
            scope:player = {
                remove_list_variable = {
                    name = DI_selected_titles
                    target = scope:title
                }

                change_variable = { name = DI_selected_count subtract = 1 }
            }
        }
        else = {
            scope:player = {
                add_to_variable_list = {
                    name = DI_selected_titles
                    target = scope:title
                }

                change_variable = { name = DI_selected_count add = 1 }
            }
        }
    }
}

### Unpin Title ###
DI_unpin_title = {
    scope = character # Player Character

    saved_scopes = {
        title # Title to unpin
    }

    effect = {
        save_scope_as = player

        remove_list_variable = {
            name = DI_pinned_titles
            target = scope:title
        }

        change_variable = { name = DI_pinned_count subtract = 1 }

        if = {
            limit = {
                is_target_in_variable_list = {
                    name = DI_selected_titles
                    target = scope:title
                }
            }

            change_variable = { name = DI_selected_count subtract = 1 }
        }

        remove_list_variable = {
            name = DI_selected_titles
            target = scope:title
        }
    }
}

### Check if title is selected ###
DI_title_selected = {
    scope = character # Player Character

    saved_scopes = {
        title # Title to check
    }

    is_valid = {
        is_target_in_variable_list = {
            name = DI_selected_titles
            target = scope:title
        }
    }
}

### Check if hiding titles ###
DI_titles_hide_toggle_on = {
    scope = character # Player Character

    is_valid = {
        has_variable = DI_titles_hide
    }
}

### Check if selected titles exists ###
DI_selected_titles_exists = {
    scope = character # Player Character

    is_valid = {
        has_variable_list = DI_selected_titles
    }
}

### Claim Titles ###
DI_claim_titles_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_selected_titles
            save_scope_as = title

            scope:player = {
                add_pressed_claim = scope:title
            }
        }
    }
}

### Take Titles ###
DI_take_titles_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_selected_titles
            save_scope_as = title

            scope:player = {
                get_title = scope:title
            }
        }
    }
}

### Destroy Titles ###
DI_destroy_titles_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_selected_titles
            save_scope_as = title

            scope:player = {
                destroy_title = scope:title
            }
        }
    }
}

### Create Dejure Liege Titles ###
DI_create_dejure_liege_title_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        scope:player = {
            every_in_list = {
                variable = DI_selected_titles
                save_scope_as = title

                limit = {
                    this.de_jure_liege = {
                        is_title_created = no
                    }
                }

                scope:player = {
                    get_title = scope:title.de_jure_liege
                }
            }
        }
    }
}

### Create direct de jure vassals of each selected title ###
DI_create_direct_dejure_vassals_sgui = {
    scope = character  # Player

    effect = {
        save_scope_as = player

        scope:player = {
            every_in_list = {
                variable = DI_selected_titles
                save_scope_as = title

                every_in_de_jure_hierarchy = {
                    save_scope_as = dj_title
                    limit = {
                        de_jure_liege = { this = scope:title }  # direct child only
                        is_title_created = no
                        tier >= county
                    }
                    scope:player = { get_title = scope:dj_title }
                }
            }
        }
    }
}

### Recursively create all dejure titles attached to selected title ###
DI_create_dejure_tree_sgui = {
    scope = character  # Player

    effect = {
        save_scope_as = player

        scope:player = {
            every_in_list = {
                variable = DI_selected_titles
                save_scope_as = title

                every_this_title_or_de_jure_above = {
                    save_scope_as = up_title

                    if = {
                        limit = {
                            is_title_created = no
                        }

                        scope:player = { get_title = scope:up_title }
                    }

                    every_in_de_jure_hierarchy = {
                        save_scope_as = down_title
                        limit = {
                            NOT = { this = scope:up_title }
                            is_title_created = no
                            tier >= county
                        }

                        scope:player = { get_title = scope:down_title }
                    }
                }
            }
        }
    }
}


### Load Title Manager Dropdown ###
DI_load_title_manager_dropdown = {
    scope = character # Player Character

    is_valid = {
        NOT = { has_global_variable_list = DI_title_manager_filter_choices }
    }

    effect = {
        save_scope_as = player

        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:sort_rank }
        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:all }
        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:hide }
        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:DI_hegemony }
        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:Empire }
        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:Kingdom }
        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:Duchy }
        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:County }
        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:pinned_characters }
        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:unpin_selected }
        add_to_global_variable_list = { name = DI_title_manager_filter_choices target = flag:clear_pinned }
    }
}

### Apply Title Manager Filter Choice ###
DI_apply_title_manager_filter_choice = {
    scope = character # Player Character

    saved_scopes = {
        filter_choice # Filter choice to apply
    }

    effect = {
        save_scope_as = player

        if = {
            limit = { scope:filter_choice = flag:sort_rank }

            if = {
                limit = {
                    NOT = { has_variable = DI_sort_descending }
                    NOT = { has_variable = DI_sort_ascending }
                }

                set_variable = DI_sort_descending
            }

            if = {
                limit = { has_variable = DI_sort_descending }

                ordered_in_list = {
                    variable = DI_pinned_titles
                    max = 10000
                    order_by = tier
                    scope:player = {
                        add_to_variable_list = {
                            name = DI_sorted_titles
                            target = prev
                        }
                    }
                }

                remove_variable = DI_sort_descending
                set_variable = DI_sort_ascending
            }
            else_if = {
                limit = { has_variable = DI_sort_ascending }

                ordered_in_list = {
                    variable = DI_pinned_titles
                    max = 10000
                    order_by = {
                        value = tier
                        multiply = -1
                    }
                    scope:player = {
                        add_to_variable_list = {
                            name = DI_sorted_titles
                            target = prev
                        }
                    }
                }

                remove_variable = DI_sort_ascending
                set_variable = DI_sort_descending
            }

            clear_variable_list = DI_pinned_titles
            every_in_list = {
                variable = DI_sorted_titles
                save_scope_as = title

                scope:player = {
                    add_to_variable_list = {
                        name = DI_pinned_titles
                        target = scope:title
                    }
                }
            }
            clear_variable_list = DI_sorted_titles
        }
        else_if = {
            limit = { scope:filter_choice = flag:all }

            if = {
                limit = { has_variable_list = DI_selected_titles }

                clear_variable_list = DI_selected_titles
            }
            else = {
                every_in_list = {
                    variable = DI_pinned_titles
                    save_scope_as = title

                    scope:player = {
                        add_to_variable_list = {
                            name = DI_selected_titles
                            target = scope:title
                        }
                    }
                }
            }
        }
        else_if = {
            limit = { scope:filter_choice = flag:hide }

            if = {
                limit = { has_variable = DI_titles_hide }

                remove_variable = DI_titles_hide
            }
            else = {
                set_variable = DI_titles_hide
            }
        }
        else_if = {
            limit = { scope:filter_choice = flag:DI_hegemony }

            clear_variable_list = DI_selected_titles

            # Select all hegemony titles
            every_in_list = {
                variable = DI_pinned_titles
                limit = {
                    tier = tier_hegemony
                }
                save_scope_as = title

                scope:player = {
                    add_to_variable_list = {
                        name = DI_selected_titles
                        target = scope:title
                    }
                }
            }
        }
        else_if = {
            limit = { scope:filter_choice = flag:Empire }

            clear_variable_list = DI_selected_titles

            # Select all empire titles
            every_in_list = {
                variable = DI_pinned_titles
                limit = {
                    tier = tier_empire
                }
                save_scope_as = title

                scope:player = {
                    add_to_variable_list = {
                        name = DI_selected_titles
                        target = scope:title
                    }
                }
            }
        }
        else_if = {
            limit = { scope:filter_choice = flag:Kingdom }

            clear_variable_list = DI_selected_titles

            # Select all kingdom titles
            every_in_list = {
                variable = DI_pinned_titles
                limit = {
                    tier = tier_kingdom
                }
                save_scope_as = title

                scope:player = {
                    add_to_variable_list = {
                        name = DI_selected_titles
                        target = scope:title
                    }
                }
            }
        }
        else_if = {
            limit = { scope:filter_choice = flag:Duchy }

            clear_variable_list = DI_selected_titles

            # Select all duchy titles
            every_in_list = {
                variable = DI_pinned_titles
                limit = {
                    tier = tier_duchy
                }
                save_scope_as = title

                scope:player = {
                    add_to_variable_list = {
                        name = DI_selected_titles
                        target = scope:title
                    }
                }
            }
        }
        else_if = {
            limit = { scope:filter_choice = flag:County }

            clear_variable_list = DI_selected_titles

            # Select all county titles
            every_in_list = {
                variable = DI_pinned_titles
                limit = {
                    tier = tier_county
                }
                save_scope_as = title

                scope:player = {
                    add_to_variable_list = {
                        name = DI_selected_titles
                        target = scope:title
                    }
                }
            }
        }
        else_if = {
            limit = { scope:filter_choice = flag:pinned_characters }

            clear_variable_list = DI_selected_titles

            # Select all titles held by pinned characters
            every_living_character = {
                limit = { has_character_flag = pinned_for_edit }

                every_held_title = {
                    limit = {
                        tier > tier_barony
                    }
                    save_scope_as = title

                    scope:player = {
                        add_to_variable_list = {
                            name = DI_pinned_titles
                            target = scope:title
                        }
                        add_to_variable_list = {
                            name = DI_selected_titles
                            target = scope:title
                        }
                    }
                }
            }
        }
        else_if = {
            limit = { scope:filter_choice = flag:unpin_selected }

            every_in_list = {
                variable = DI_selected_titles
                save_scope_as = title

                scope:player = {
                    remove_list_variable = {
                        name = DI_pinned_titles
                        target = scope:title
                    }
                    remove_list_variable = {
                        name = DI_selected_titles
                        target = scope:title
                    }
                }
            }
        }
        else_if = {
            limit = { scope:filter_choice = flag:clear_pinned }

            clear_variable_list = DI_pinned_titles
            clear_variable_list = DI_selected_titles
        }

        DI_recount_title_counters = yes
    }
}

### Load Province Dropdown ###
DI_load_province_dropdown = {
    scope = character # Player Character

    is_valid = {
        NOT = { has_global_variable_list = DI_province_filter_choices }
    }

    effect = {
        save_scope_as = player

        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:all }
        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:hide }
        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:capital }
        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:castle }
        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:temple }
        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:city }
        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:tribal }
        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:DI_nomad }
        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:DI_herder }
        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:DI_temple_citadel }
        add_to_global_variable_list = { name = DI_province_filter_choices target = flag:empty }
    }
}

### Apply Filter Choice ###
DI_apply_province_filter_choice = {
    scope = character # Player Character

    saved_scopes = {
        filter_choice # Filter choice to apply
    }

    effect = {
        save_scope_as = player

        if = {
            limit = { scope:filter_choice = flag:all }

            if = {
                limit = { has_variable_list = DI_action_provinces }

                clear_variable_list = DI_action_provinces
            }
            else = {
                every_in_list = {
                    variable = DI_selected_titles_provinces
                    save_scope_as = province

                    scope:player = {
                        add_to_variable_list = {
                            name = DI_action_provinces
                            target = scope:province
                        }
                    }
                }

                if = {
                    limit = {
                        has_variable = DI_provinces_hide
                    }
                    clear_variable_list = DI_shown_provinces

                    every_in_list = {
                        variable = DI_selected_titles_provinces
                        save_scope_as = province

                        scope:player = {
                            add_to_variable_list = {
                                name = DI_shown_provinces
                                target = scope:province
                            }
                        }
                    }
                }
            }
        }
        else_if = {
            limit = {
                scope:filter_choice = flag:hide
            }
            if = {
                limit = {
                    has_variable_list = DI_action_provinces
                }
                clear_variable_list = DI_shown_provinces

                if = {
                    limit = {
                        has_variable = DI_provinces_hide
                    }
                    remove_variable = DI_provinces_hide

                    every_in_list = {
                        variable = DI_selected_titles_provinces
                        save_scope_as = province

                        scope:player = {
                            add_to_variable_list = {
                                name = DI_shown_provinces
                                target = scope:province
                            }
                        }
                    }
                }
                else = {
                    set_variable = DI_provinces_hide

                    every_in_list = {
                        variable = DI_action_provinces
                        save_scope_as = province

                        scope:player = {
                            add_to_variable_list = {
                                name = DI_shown_provinces
                                target = scope:province
                            }
                        }
                    }
                }
            }
            else = {
                if = {
                    limit = {
                        has_variable = DI_provinces_hide
                    }
                    remove_variable = DI_provinces_hide
                    clear_variable_list = DI_shown_provinces

                    every_in_list = {
                        variable = DI_selected_titles_provinces
                        save_scope_as = province

                        scope:player = {
                            add_to_variable_list = {
                                name = DI_shown_provinces
                                target = scope:province
                            }
                        }
                    }
                }
                else = {
                    every_in_list = {
                        variable = DI_selected_titles_provinces
                        save_scope_as = province

                        scope:player = {
                            add_to_variable_list = {
                                name = DI_shown_provinces
                                target = scope:province
                            }
                        }
                    }
                }
            }
        }
        else_if = {
            limit = {
                scope:filter_choice = flag:capital
            }
            clear_variable_list = DI_action_provinces
            if = {
                limit = {
                    has_variable = DI_provinces_hide
                }
                clear_variable_list = DI_shown_provinces
            }

            every_in_list = {
                variable = DI_selected_titles_provinces
                save_scope_as = province

                # Evaluate the capital check IN the province scope
                scope:province = {
                    if = {
                        limit = { is_county_capital = yes }   # <-- this is the key bit
                        scope:player = {
                            add_to_variable_list = { name = DI_action_provinces target = scope:province }
                            if = {
                                limit = {
                                    has_variable = DI_provinces_hide
                                }
                                add_to_variable_list = {
                                    name = DI_shown_provinces
                                    target = scope:province
                                }
                            }
                        }
                    }
                }
            }
        }
        # ---------- castle ----------
        else_if = {
            limit = { scope:filter_choice = flag:castle }
            clear_variable_list = DI_action_provinces
            if = { limit = { has_variable = DI_provinces_hide } clear_variable_list = DI_shown_provinces }

            every_in_list = {
                variable = DI_selected_titles_provinces
                save_scope_as = province
                scope:province = {
                    if = {
                        limit = { has_holding_type = castle_holding }     # or castle_holding if your build expects it
                        scope:player = {
                            add_to_variable_list = { name = DI_action_provinces target = scope:province }
                            if = { limit = { has_variable = DI_provinces_hide } add_to_variable_list = { name = DI_shown_provinces target = scope:province } }
                        }
                    }
                }
            }
        }

        # ---------- temple ----------
        else_if = {
            limit = { scope:filter_choice = flag:temple }
            clear_variable_list = DI_action_provinces
            if = { limit = { has_variable = DI_provinces_hide } clear_variable_list = DI_shown_provinces }

            every_in_list = {
                variable = DI_selected_titles_provinces
                save_scope_as = province
                scope:province = {
                    if = {
                        limit = { has_holding_type = church_holding }
                        scope:player = {
                            add_to_variable_list = { name = DI_action_provinces target = scope:province }
                            if = { limit = { has_variable = DI_provinces_hide } add_to_variable_list = { name = DI_shown_provinces target = scope:province } }
                        }
                    }
                }
            }
        }

        # ---------- city ----------
        else_if = {
            limit = { scope:filter_choice = flag:city }
            clear_variable_list = DI_action_provinces
            if = { limit = { has_variable = DI_provinces_hide } clear_variable_list = DI_shown_provinces }

            every_in_list = {
                variable = DI_selected_titles_provinces
                save_scope_as = province
                scope:province = {
                    if = {
                        limit = { has_holding_type = city_holding }
                        scope:player = {
                            add_to_variable_list = { name = DI_action_provinces target = scope:province }
                            if = { limit = { has_variable = DI_provinces_hide } add_to_variable_list = { name = DI_shown_provinces target = scope:province } }
                        }
                    }
                }
            }
        }

        # ---------- tribal ----------
        else_if = {
            limit = { scope:filter_choice = flag:tribal }
            clear_variable_list = DI_action_provinces
            if = { limit = { has_variable = DI_provinces_hide } clear_variable_list = DI_shown_provinces }

            every_in_list = {
                variable = DI_selected_titles_provinces
                save_scope_as = province
                scope:province = {
                    if = {
                        limit = { has_holding_type = tribal_holding }
                        scope:player = {
                            add_to_variable_list = { name = DI_action_provinces target = scope:province }
                            if = { limit = { has_variable = DI_provinces_hide } add_to_variable_list = { name = DI_shown_provinces target = scope:province } }
                        }
                    }
                }
            }
        }

        # ---------- nomad ----------
        else_if = {
            limit = { scope:filter_choice = flag:DI_nomad }
            clear_variable_list = DI_action_provinces
            if = { limit = { has_variable = DI_provinces_hide } clear_variable_list = DI_shown_provinces }

            every_in_list = {
                variable = DI_selected_titles_provinces
                save_scope_as = province
                scope:province = {
                    if = {
                        limit = { has_holding_type = nomad_holding }
                        scope:player = {
                            add_to_variable_list = { name = DI_action_provinces target = scope:province }
                            if = { limit = { has_variable = DI_provinces_hide } add_to_variable_list = { name = DI_shown_provinces target = scope:province } }
                        }
                    }
                }
            }
        }

        # ---------- herder ----------
        else_if = {
            limit = { scope:filter_choice = flag:DI_herder }
            clear_variable_list = DI_action_provinces
            if = { limit = { has_variable = DI_provinces_hide } clear_variable_list = DI_shown_provinces }

            every_in_list = {
                variable = DI_selected_titles_provinces
                save_scope_as = province
                scope:province = {
                    if = {
                        limit = { has_holding_type = herder_holding }
                        scope:player = {
                            add_to_variable_list = { name = DI_action_provinces target = scope:province }
                            if = { limit = { has_variable = DI_provinces_hide } add_to_variable_list = { name = DI_shown_provinces target = scope:province } }
                        }
                    }
                }
            }
        }

        # ---------- temple citadel ----------
        else_if = {
            limit = { scope:filter_choice = flag:DI_temple_citadel }
            clear_variable_list = DI_action_provinces
            if = { limit = { has_variable = DI_provinces_hide } clear_variable_list = DI_shown_provinces }

            every_in_list = {
                variable = DI_selected_titles_provinces
                save_scope_as = province
                scope:province = {
                    if = {
                        limit = { has_holding_type = temple_citadel_holding }
                        scope:player = {
                            add_to_variable_list = { name = DI_action_provinces target = scope:province }
                            if = { limit = { has_variable = DI_provinces_hide } add_to_variable_list = { name = DI_shown_provinces target = scope:province } }
                        }
                    }
                }
            }
        }

        # ---------- empty ----------
        else_if = {
            limit = { scope:filter_choice = flag:empty }
            clear_variable_list = DI_action_provinces
            if = { limit = { has_variable = DI_provinces_hide } clear_variable_list = DI_shown_provinces }

            every_in_list = {
                variable = DI_selected_titles_provinces
                save_scope_as = province
                scope:province = {
                    if = {
                        limit = { has_holding = no }
                        scope:player = {
                            add_to_variable_list = { name = DI_action_provinces target = scope:province }
                            if = { limit = { has_variable = DI_provinces_hide } add_to_variable_list = { name = DI_shown_provinces target = scope:province } }
                        }
                    }
                }
            }
        }
    }
}

### Deselect Province ###
DI_toggle_action_province = {
    scope = character # Player Character

    saved_scopes = {
        province # Province to deselect
    }

    effect = {
        save_scope_as = player
        # Else, toggle the province in DI_action_provinces
        if = {
            limit = {
                is_target_in_variable_list = {
                    name = DI_action_provinces
                    target = scope:province
                }
            }
            scope:player = {
                remove_list_variable = {
                    name = DI_action_provinces
                    target = scope:province
                }
                if = {
                    limit = {
                        has_variable = DI_provinces_hide
                    }
                    remove_list_variable = {
                        name = DI_shown_provinces
                        target = scope:province
                    }
                }
            }
        }
        else = {
            scope:player = {
                add_to_variable_list = {
                    name = DI_action_provinces
                    target = scope:province
                }
                if = {
                    limit = {
                        has_variable = DI_provinces_hide
                    }
                    remove_list_variable = {
                        name = DI_shown_provinces
                        target = scope:province
                    }
                }
            }
        }

        if = {
            limit = {
                has_variable = DI_provinces_hide
                NOT = { has_variable_list = DI_shown_provinces }
            }
            remove_variable = DI_provinces_hide

            every_in_list = {
                variable = DI_selected_titles_provinces
                save_scope_as = province

                scope:player = {
                    add_to_variable_list = {
                        name = DI_shown_provinces
                        target = scope:province
                    }
                }
            }
        }
    }
}

### Check Province In List ###
DI_is_action_province = {
    scope = character # Player Character

    saved_scopes = {
        province # Province to check
    }

    is_valid = {
        is_target_in_variable_list = {
            name = DI_action_provinces
            target = scope:province
        }
    }
}

### Select Culture ###
DI_title_manager_culture = {
    scope = character # Player Character

    saved_scopes = {
        selected_culture # Culture to select
    }

    effect = {
        save_scope_as = player

        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        scope:DI_story = {
            set_variable = {
                name = DI_title_manager_culture
                value = scope:selected_culture
            }
        }
    }
}

### Select Religion ###
DI_title_manager_religion = {
    scope = character # Player Character

    saved_scopes = {
        selected_faith # Religion to select
    }

    effect = {
        save_scope_as = player

        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        scope:DI_story = {
            set_variable = {
                name = DI_title_manager_religion
                value = scope:selected_faith
            }
        }
    }
}

### Convert Religion ###
DI_convert_titles_faith_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        scope:DI_story = {
            var:DI_title_manager_religion = { save_scope_as = DI_selected_religion }
        }

        every_in_list = {
            variable = DI_selected_titles
            save_scope_as = title
            if = {
                limit = {
                    tier = tier_county
                }
                set_county_faith = scope:DI_selected_religion
            }
            else_if = {
                limit = {
                    tier > tier_county
                }
                every_de_jure_county = {
                    set_county_faith = scope:DI_selected_religion
                }
            }
        }
    }
}

### Convert Culture ###
DI_convert_titles_culture_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        scope:DI_story = {
            var:DI_title_manager_culture = { save_scope_as = DI_selected_culture }
        }

        every_in_list = {
            variable = DI_selected_titles
            save_scope_as = title
            if = {
                limit = {
                    tier = tier_county
                }
                set_county_culture = scope:DI_selected_culture
            }
            else_if = {
                limit = {
                    tier > tier_county
                }
                every_de_jure_county = {
                    set_county_culture = scope:DI_selected_culture
                }
            }
        }
    }
}

### DI_select_dejure_title ###
DI_select_dejure_title = {
    scope = character # Player Character

    saved_scopes = {
        title # Title to select
    }

    effect = {
        save_scope_as = player

        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        scope:DI_story = {
            set_variable = {
                name = DI_title_manager_dejure
                value = scope:title
            }
        }
    }
}

### DI_titles_dejure_sgui ###
DI_convert_titles_dejure_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        random_owned_story = {
            limit = {
                story_type = DI_misc_variables_story
            }
            save_scope_as = DI_story
        }

        scope:DI_story = {
            var:DI_title_manager_dejure = { save_scope_as = DI_selected_dejure }
        }

        every_in_list = {
            variable = DI_selected_titles
            save_scope_as = title
            if = {
                limit = {
                    tier = {
                        value = scope:DI_selected_dejure.tier
                        subtract = 1
                    }
                }
                set_de_jure_liege_title = scope:DI_selected_dejure
            }
        }
    }
}

### DI_province_list_load ###
DI_province_list_load = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        clear_variable_list = DI_selected_titles_provinces
        clear_variable_list = DI_shown_provinces
        clear_variable_list = DI_action_provinces

        every_in_list = {
            variable = DI_selected_titles
            save_scope_as = title
            if = {
                limit = {
                    tier = tier_county
                }
                every_county_province = {
                    save_scope_as = province

                    scope:player = {
                        add_to_variable_list = {
                            name = DI_selected_titles_provinces
                            target = scope:province
                        }

                        add_to_variable_list = {
                            name = DI_action_provinces
                            target = scope:province
                        }

                        add_to_variable_list = {
                            name = DI_shown_provinces
                            target = scope:province
                        }
                    }
                }
            }
            else_if = {
                limit = {
                    tier < tier_empire
                }
                every_de_jure_county = {
                    every_county_province = {
                        save_scope_as = province

                        scope:player = {
                            add_to_variable_list = {
                                name = DI_selected_titles_provinces
                                target = scope:province
                            }

                            add_to_variable_list = {
                                name = DI_action_provinces
                                target = scope:province
                            }

                            add_to_variable_list = {
                                name = DI_shown_provinces
                                target = scope:province
                            }
                        }
                    }
                }
            }
        }
    }
}

DI_set_county_capital_sgui = {
    scope = character
    saved_scopes = {
        province
        barony
    }

    is_valid = {
        scope:province = { is_county_capital = no }
    }

    effect = {
        scope:barony = { set_capital_barony = yes }
    }
}

DI_remove_holding_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_action_provinces
            limit = {
                is_county_capital = no
            }

            save_scope_as = province

            scope:province = {
                remove_holding = yes

                ### City Buildings
                if = { limit = { has_building = city_04 } remove_building = city_04 }
                else_if = { limit = { has_building = city_03 } remove_building = city_03 }
                else_if = { limit = { has_building = city_02 } remove_building = city_02 }
                else_if = { limit = { has_building = city_01 } remove_building = city_01 }

                ### Castle Buildings
                if = { limit = { has_building = castle_04 } remove_building = castle_04 }
                else_if = { limit = { has_building = castle_03 } remove_building = castle_03 }
                else_if = { limit = { has_building = castle_02 } remove_building = castle_02 }
                else_if = { limit = { has_building = castle_01 } remove_building = castle_01 }

                ### Church Buildings
                if = { limit = { has_building = temple_01 } remove_building = temple_01 }
                else_if = { limit = { has_building = temple_02 } remove_building = temple_02 }
                else_if = { limit = { has_building = temple_03 } remove_building = temple_03 }
                else_if = { limit = { has_building = temple_04 } remove_building = temple_04 }

                ### Tribal Buildings
                if = { limit = { has_building = tribe_01 } remove_building = tribe_01 }
                else_if = { limit = { has_building = tribe_02 } remove_building = tribe_02 }

                ### Temple Citadel Buildings
                if = { limit = { has_building = temple_citadel_01 } remove_building = temple_citadel_01 }
                else_if = { limit = { has_building = temple_citadel_02 } remove_building = temple_citadel_02 }
                else_if = { limit = { has_building = temple_citadel_03 } remove_building = temple_citadel_03 }
                else_if = { limit = { has_building = temple_citadel_04 } remove_building = temple_citadel_04 }
            }
        }
    }
}

DI_add_building_slot_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_action_provinces
            save_scope_as = province

            scope:province = {
                add_province_modifier = add_building_slot
            }
        }
    }
}

DI_remove_building_slot_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_action_provinces
            save_scope_as = province

            scope:province = {
                remove_province_modifier = add_building_slot
            }
        }
    }
}

DI_set_holding_type_sgui = {
    scope = character # Player Character

    saved_scopes = {
        holding_type # Holding type flag
    }

    effect = {
        save_scope_as = player

        if = {
            limit = {
                scope:holding_type = flag:castle_holding
            }

            every_in_list = {
                variable = DI_action_provinces
                save_scope_as = province

                scope:province = {
                    if = {
                        limit = {
                            province_has_no_holding_trigger = yes
                        }

                        begin_create_holding = castle_holding
                    }
                    set_holding_type = castle_holding
                }
            }
        }
        else_if = {
            limit = {
                scope:holding_type = flag:city_holding
            }

            every_in_list = {
                variable = DI_action_provinces
                save_scope_as = province

                scope:province = {
                    if = {
                        limit = {
                            province_has_no_holding_trigger = yes
                        }

                        begin_create_holding = city_holding
                    }
                    set_holding_type = city_holding
                }
            }
        }
        else_if = {
            limit = {
                scope:holding_type = flag:church_holding
            }

            every_in_list = {
                variable = DI_action_provinces
                save_scope_as = province

                scope:province = {
                    if = {
                        limit = {
                            province_has_no_holding_trigger = yes
                        }

                        begin_create_holding = church_holding
                    }
                    set_holding_type = church_holding
                }
            }
        }
        else_if = {
            limit = {
                scope:holding_type = flag:tribal_holding
            }

            every_in_list = {
                variable = DI_action_provinces
                save_scope_as = province

                scope:province = {
                    if = {
                        limit = {
                            province_has_no_holding_trigger = yes
                        }

                        begin_create_holding = tribal_holding
                    }
                    set_holding_type = tribal_holding
                }
            }
        }
        #--- Nomad Holding ---#
        else_if = {
            limit = {
                scope:holding_type = flag:nomad_holding
            }

            every_in_list = {
                variable = DI_action_provinces
                save_scope_as = province

                scope:province = {
                    if = {
                        limit = {
                            province_has_no_holding_trigger = yes
                        }

                        begin_create_holding = nomad_holding
                    }
                    set_holding_type = nomad_holding
                }
            }
        }

        #--- Herder Holding ---#
        else_if = {
            limit = {
                scope:holding_type = flag:herder_holding
            }

            every_in_list = {
                variable = DI_action_provinces
                save_scope_as = province

                scope:province = {
                    if = {
                        limit = {
                            province_has_no_holding_trigger = yes
                        }

                        begin_create_holding = herder_holding
                    }
                    set_holding_type = herder_holding
                }
            }
        }

        #--- Temple Citadel Holding ---#
        else_if = {
            limit = {
                scope:holding_type = flag:temple_citadel_holding
            }

            every_in_list = {
                variable = DI_action_provinces
                save_scope_as = province

                scope:province = {
                    if = {
                        limit = {
                            province_has_no_holding_trigger = yes
                        }

                        begin_create_holding = temple_citadel_holding
                    }
                    set_holding_type = temple_citadel_holding
                }
            }
        }
    }
}

DI_generate_buildings_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_action_provinces
            save_scope_as = province

            scope:province = {
                generate_building = yes
            }
        }
    }
}

# AUTO-GENERATED — do not edit by hand
# Helpers for building ops

DI_remove_buildings_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_action_provinces
            save_scope_as = province

            scope:province = {
                if = { limit = { has_building_or_higher = city_02 } add_building = city_01 }
                if = { limit = { has_building_or_higher = city_03 } add_building = city_01 }
                if = { limit = { has_building_or_higher = city_04 } add_building = city_01 }
                if = { limit = { has_building_or_higher = castle_02 } add_building = castle_01 }
                if = { limit = { has_building_or_higher = castle_03 } add_building = castle_01 }
                if = { limit = { has_building_or_higher = castle_04 } add_building = castle_01 }
                if = { limit = { has_building_or_higher = temple_02 } add_building = temple_01 }
                if = { limit = { has_building_or_higher = temple_03 } add_building = temple_01 }
                if = { limit = { has_building_or_higher = temple_04 } add_building = temple_01 }
                if = { limit = { has_building_or_higher = tribe_02 } add_building = tribe_01 }

                if = { limit = { has_building = al_qarawiyyin_university_01 } remove_building = al_qarawiyyin_university_01 }
                if = { limit = { has_building = alamut_castle_02 } remove_building = alamut_castle_02 }
                else_if = { limit = { has_building = alamut_castle_01 } remove_building = alamut_castle_01 }
                if = { limit = { has_building = alcazar_of_segovia_01 } remove_building = alcazar_of_segovia_01 }
                if = { limit = { has_building = alhambra_02 } remove_building = alhambra_02 }
                else_if = { limit = { has_building = alhambra_01 } remove_building = alhambra_01 }
                if = { limit = { has_building = aljaferia_palace_01 } remove_building = aljaferia_palace_01 }
                if = { limit = { has_building = allaq_mines_04 } remove_building = allaq_mines_04 }
                else_if = { limit = { has_building = allaq_mines_03 } remove_building = allaq_mines_03 }
                else_if = { limit = { has_building = allaq_mines_02 } remove_building = allaq_mines_02 }
                else_if = { limit = { has_building = allaq_mines_01 } remove_building = allaq_mines_01 }
                if = { limit = { has_building = ananda_temple_01 } remove_building = ananda_temple_01 }
                if = { limit = { has_building = angkor_wat_01 } remove_building = angkor_wat_01 }
                if = { limit = { has_building = archery_ranges_03 } remove_building = archery_ranges_03 }
                else_if = { limit = { has_building = archery_ranges_02 } remove_building = archery_ranges_02 }
                else_if = { limit = { has_building = archery_ranges_01 } remove_building = archery_ranges_01 }
                if = { limit = { has_building = argentiera_mines_04 } remove_building = argentiera_mines_04 }
                else_if = { limit = { has_building = argentiera_mines_03 } remove_building = argentiera_mines_03 }
                else_if = { limit = { has_building = argentiera_mines_02 } remove_building = argentiera_mines_02 }
                else_if = { limit = { has_building = argentiera_mines_01 } remove_building = argentiera_mines_01 }
                if = { limit = { has_building = ark_of_bukhara_01 } remove_building = ark_of_bukhara_01 }
                if = { limit = { has_building = assassin_castle_01 } remove_building = assassin_castle_01 }
                if = { limit = { has_building = aurelian_walls_01 } remove_building = aurelian_walls_01 }
                DI_remove_building_type_effect = { BUILDING = barracks }
                if = { limit = { has_building = besakih_temple_01 } remove_building = besakih_temple_01 }
                if = { limit = { has_building = beta_giyorgis_01 } remove_building = beta_giyorgis_01 }
                if = { limit = { has_building = blacksmiths_03 } remove_building = blacksmiths_03 }
                else_if = { limit = { has_building = blacksmiths_02 } remove_building = blacksmiths_02 }
                else_if = { limit = { has_building = blacksmiths_01 } remove_building = blacksmiths_01 }
                if = { limit = { has_building = borobudur_01 } remove_building = borobudur_01 }
                DI_remove_building_type_effect = { BUILDING = breweries }
                if = { limit = { has_building = brihadeeswarar_temple_01 } remove_building = brihadeeswarar_temple_01 }
                if = { limit = { has_building = buddhas_of_bamian_01 } remove_building = buddhas_of_bamian_01 }
                if = { limit = { has_building = burial_site_03 } remove_building = burial_site_03 }
                else_if = { limit = { has_building = burial_site_02 } remove_building = burial_site_02 }
                else_if = { limit = { has_building = burial_site_01 } remove_building = burial_site_01 }
                if = { limit = { has_building = burkhan_khaldun_01 } remove_building = burkhan_khaldun_01 }
                if = { limit = { has_building = byeokran_port_01 } remove_building = byeokran_port_01 }
                DI_remove_building_type_effect = { BUILDING = camel_farms }
                DI_remove_building_type_effect = { BUILDING = capital_bureau }
                DI_remove_building_type_effect = { BUILDING = caravanserai }
                if = { limit = { has_building = celestial_great_barracks_01 } remove_building = celestial_great_barracks_01 }
                DI_remove_building_type_effect = { BUILDING = cereal_fields }
                if = { limit = { has_building = cevennes_mines_04 } remove_building = cevennes_mines_04 }
                else_if = { limit = { has_building = cevennes_mines_03 } remove_building = cevennes_mines_03 }
                else_if = { limit = { has_building = cevennes_mines_02 } remove_building = cevennes_mines_02 }
                else_if = { limit = { has_building = cevennes_mines_01 } remove_building = cevennes_mines_01 }
                if = { limit = { has_building = changan_market_02 } remove_building = changan_market_02 }
                else_if = { limit = { has_building = changan_market_01 } remove_building = changan_market_01 }
                if = { limit = { has_building = charnel_grounds_03 } remove_building = charnel_grounds_03 }
                else_if = { limit = { has_building = charnel_grounds_02 } remove_building = charnel_grounds_02 }
                else_if = { limit = { has_building = charnel_grounds_01 } remove_building = charnel_grounds_01 }
                if = { limit = { has_building = chinjufu_01 } remove_building = chinjufu_01 }
                if = { limit = { has_building = citadel_of_aleppo_02 } remove_building = citadel_of_aleppo_02 }
                else_if = { limit = { has_building = citadel_of_aleppo_01 } remove_building = citadel_of_aleppo_01 }
                DI_remove_building_type_effect = { BUILDING = citadel_shrine }
                if = { limit = { has_building = citadel_thang_long_02 } remove_building = citadel_thang_long_02 }
                else_if = { limit = { has_building = citadel_thang_long_01 } remove_building = citadel_thang_long_01 }
                if = { limit = { has_building = city_wall_of_toledo_01 } remove_building = city_wall_of_toledo_01 }
                if = { limit = { has_building = cluny_abbey_02 } remove_building = cluny_abbey_02 }
                else_if = { limit = { has_building = cluny_abbey_01 } remove_building = cluny_abbey_01 }
                DI_remove_building_type_effect = { BUILDING = common_tradeport }
                if = { limit = { has_building = culai_academy_01 } remove_building = culai_academy_01 }
                DI_remove_building_type_effect = { BUILDING = curtain_walls }
                if = { limit = { has_building = damascus_mosque_01 } remove_building = damascus_mosque_01 }
                if = { limit = { has_building = danevirke_01 } remove_building = danevirke_01 }
                if = { limit = { has_building = dau_temple_01 } remove_building = dau_temple_01 }
                if = { limit = { has_building = dazaifu_01 } remove_building = dazaifu_01 }
                if = { limit = { has_building = dean_mines_04 } remove_building = dean_mines_04 }
                else_if = { limit = { has_building = dean_mines_03 } remove_building = dean_mines_03 }
                else_if = { limit = { has_building = dean_mines_02 } remove_building = dean_mines_02 }
                else_if = { limit = { has_building = dean_mines_01 } remove_building = dean_mines_01 }
                if = { limit = { has_building = dieng_plateau_01 } remove_building = dieng_plateau_01 }
                if = { limit = { has_building = doges_palace_01 } remove_building = doges_palace_01 }
                if = { limit = { has_building = dome_of_the_rock_01 } remove_building = dome_of_the_rock_01 }
                if = { limit = { has_building = dragon_kiln_03 } remove_building = dragon_kiln_03 }
                else_if = { limit = { has_building = dragon_kiln_02 } remove_building = dragon_kiln_02 }
                else_if = { limit = { has_building = dragon_kiln_01 } remove_building = dragon_kiln_01 }
                if = { limit = { has_building = drassanes_01 } remove_building = drassanes_01 }
                if = { limit = { has_building = dunhuang_market_02 } remove_building = dunhuang_market_02 }
                else_if = { limit = { has_building = dunhuang_market_01 } remove_building = dunhuang_market_01 }
                if = { limit = { has_building = duomo_florence_04 } remove_building = duomo_florence_04 }
                else_if = { limit = { has_building = duomo_florence_03 } remove_building = duomo_florence_03 }
                else_if = { limit = { has_building = duomo_florence_02 } remove_building = duomo_florence_02 }
                else_if = { limit = { has_building = duomo_florence_01 } remove_building = duomo_florence_01 }
                if = { limit = { has_building = dushan_mines_04 } remove_building = dushan_mines_04 }
                else_if = { limit = { has_building = dushan_mines_03 } remove_building = dushan_mines_03 }
                else_if = { limit = { has_building = dushan_mines_02 } remove_building = dushan_mines_02 }
                else_if = { limit = { has_building = dushan_mines_01 } remove_building = dushan_mines_01 }
                if = { limit = { has_building = dvin_shuka_02 } remove_building = dvin_shuka_02 }
                else_if = { limit = { has_building = dvin_shuka_01 } remove_building = dvin_shuka_01 }
                DI_remove_building_type_effect = { BUILDING = elephant_pens }
                if = { limit = { has_building = enryaku_ji_01 } remove_building = enryaku_ji_01 }
                if = { limit = { has_building = event_tower_of_silence_01 } remove_building = event_tower_of_silence_01 }
                if = { limit = { has_building = examination_hall_03 } remove_building = examination_hall_03 }
                else_if = { limit = { has_building = examination_hall_02 } remove_building = examination_hall_02 }
                else_if = { limit = { has_building = examination_hall_01 } remove_building = examination_hall_01 }
                if = { limit = { has_building = falak_ol_aflak_citadel_01 } remove_building = falak_ol_aflak_citadel_01 }
                if = { limit = { has_building = falun_mines_04 } remove_building = falun_mines_04 }
                else_if = { limit = { has_building = falun_mines_03 } remove_building = falun_mines_03 }
                else_if = { limit = { has_building = falun_mines_02 } remove_building = falun_mines_02 }
                else_if = { limit = { has_building = falun_mines_01 } remove_building = falun_mines_01 }
                DI_remove_building_type_effect = { BUILDING = farm_estates }
                if = { limit = { has_building = fengtian_mines_03 } remove_building = fengtian_mines_03 }
                else_if = { limit = { has_building = fengtian_mines_02 } remove_building = fengtian_mines_02 }
                else_if = { limit = { has_building = fengtian_mines_01 } remove_building = fengtian_mines_01 }
                if = { limit = { has_building = forbidden_city_01 } remove_building = forbidden_city_01 }
                if = { limit = { has_building = generic_copper_mines_04 } remove_building = generic_copper_mines_04 }
                else_if = { limit = { has_building = generic_copper_mines_03 } remove_building = generic_copper_mines_03 }
                else_if = { limit = { has_building = generic_copper_mines_02 } remove_building = generic_copper_mines_02 }
                else_if = { limit = { has_building = generic_copper_mines_01 } remove_building = generic_copper_mines_01 }
                if = { limit = { has_building = generic_gold_mines_04 } remove_building = generic_gold_mines_04 }
                else_if = { limit = { has_building = generic_gold_mines_03 } remove_building = generic_gold_mines_03 }
                else_if = { limit = { has_building = generic_gold_mines_02 } remove_building = generic_gold_mines_02 }
                else_if = { limit = { has_building = generic_gold_mines_01 } remove_building = generic_gold_mines_01 }
                if = { limit = { has_building = generic_silver_mines_04 } remove_building = generic_silver_mines_04 }
                else_if = { limit = { has_building = generic_silver_mines_03 } remove_building = generic_silver_mines_03 }
                else_if = { limit = { has_building = generic_silver_mines_02 } remove_building = generic_silver_mines_02 }
                else_if = { limit = { has_building = generic_silver_mines_01 } remove_building = generic_silver_mines_01 }
                if = { limit = { has_building = ghana_palace_01 } remove_building = ghana_palace_01 }
                if = { limit = { has_building = giant_wild_goose_pagoda_01 } remove_building = giant_wild_goose_pagoda_01 }
                if = { limit = { has_building = golden_gate_of_kiev_01 } remove_building = golden_gate_of_kiev_01 }
                if = { limit = { has_building = gongsanseong_fortress_01 } remove_building = gongsanseong_fortress_01 }
                if = { limit = { has_building = great_megalith_01 } remove_building = great_megalith_01 }
                if = { limit = { has_building = great_wall_of_gorgan_01 } remove_building = great_wall_of_gorgan_01 }
                DI_remove_building_type_effect = { BUILDING = guild_halls }
                if = { limit = { has_building = hadrians_wall_01 } remove_building = hadrians_wall_01 }
                if = { limit = { has_building = hagia_sophia_02 } remove_building = hagia_sophia_02 }
                else_if = { limit = { has_building = hagia_sophia_01 } remove_building = hagia_sophia_01 }
                if = { limit = { has_building = hakata_port_02 } remove_building = hakata_port_02 }
                else_if = { limit = { has_building = hakata_port_01 } remove_building = hakata_port_01 }
                if = { limit = { has_building = hall_of_heroes_05 } remove_building = hall_of_heroes_05 }
                else_if = { limit = { has_building = hall_of_heroes_04 } remove_building = hall_of_heroes_04 }
                else_if = { limit = { has_building = hall_of_heroes_03 } remove_building = hall_of_heroes_03 }
                else_if = { limit = { has_building = hall_of_heroes_02 } remove_building = hall_of_heroes_02 }
                else_if = { limit = { has_building = hall_of_heroes_01 } remove_building = hall_of_heroes_01 }
                if = { limit = { has_building = hamadan_bazaar_02 } remove_building = hamadan_bazaar_02 }
                else_if = { limit = { has_building = hamadan_bazaar_01 } remove_building = hamadan_bazaar_01 }
                if = { limit = { has_building = hanging_temple_01 } remove_building = hanging_temple_01 }
                if = { limit = { has_building = heddal_stave_church_01 } remove_building = heddal_stave_church_01 }
                if = { limit = { has_building = heian_palace_01 } remove_building = heian_palace_01 }
                if = { limit = { has_building = herat_bazaar_02 } remove_building = herat_bazaar_02 }
                else_if = { limit = { has_building = herat_bazaar_01 } remove_building = herat_bazaar_01 }
                if = { limit = { has_building = herder_camp_01 } remove_building = herder_camp_01 }
                if = { limit = { has_building = hetian_mines_04 } remove_building = hetian_mines_04 }
                else_if = { limit = { has_building = hetian_mines_03 } remove_building = hetian_mines_03 }
                else_if = { limit = { has_building = hetian_mines_02 } remove_building = hetian_mines_02 }
                else_if = { limit = { has_building = hetian_mines_01 } remove_building = hetian_mines_01 }
                DI_remove_building_type_effect = { BUILDING = hill_farms }
                DI_remove_building_type_effect = { BUILDING = hill_forts }
                DI_remove_building_type_effect = { BUILDING = hillside_grazing }
                if = { limit = { has_building = holy_site_basilica_santiago_01 } remove_building = holy_site_basilica_santiago_01 }
                if = { limit = { has_building = holy_site_buddhist_grand_temple_01 } remove_building = holy_site_buddhist_grand_temple_01 }
                if = { limit = { has_building = holy_site_canterbury_cathedral_03 } remove_building = holy_site_canterbury_cathedral_03 }
                else_if = { limit = { has_building = holy_site_canterbury_cathedral_02 } remove_building = holy_site_canterbury_cathedral_02 }
                else_if = { limit = { has_building = holy_site_canterbury_cathedral_01 } remove_building = holy_site_canterbury_cathedral_01 }
                if = { limit = { has_building = holy_site_cathedral_01 } remove_building = holy_site_cathedral_01 }
                if = { limit = { has_building = holy_site_chinese_temple_01 } remove_building = holy_site_chinese_temple_01 }
                if = { limit = { has_building = holy_site_cologne_cathedral_01 } remove_building = holy_site_cologne_cathedral_01 }
                if = { limit = { has_building = holy_site_fire_temple_01 } remove_building = holy_site_fire_temple_01 }
                if = { limit = { has_building = holy_site_great_mosque_of_cordoba_01 } remove_building = holy_site_great_mosque_of_cordoba_01 }
                if = { limit = { has_building = holy_site_great_mosque_of_djenne_01 } remove_building = holy_site_great_mosque_of_djenne_01 }
                if = { limit = { has_building = holy_site_great_mosque_of_mecca_01 } remove_building = holy_site_great_mosque_of_mecca_01 }
                if = { limit = { has_building = holy_site_great_mosque_of_samarra_01 } remove_building = holy_site_great_mosque_of_samarra_01 }
                if = { limit = { has_building = holy_site_imam_ali_mosque_01 } remove_building = holy_site_imam_ali_mosque_01 }
                if = { limit = { has_building = holy_site_indian_grand_temple_01 } remove_building = holy_site_indian_grand_temple_01 }
                if = { limit = { has_building = holy_site_japanese_temple_01 } remove_building = holy_site_japanese_temple_01 }
                if = { limit = { has_building = holy_site_mahabodhi_temple_01 } remove_building = holy_site_mahabodhi_temple_01 }
                if = { limit = { has_building = holy_site_mosque_01 } remove_building = holy_site_mosque_01 }
                if = { limit = { has_building = holy_site_other_grand_temple_01 } remove_building = holy_site_other_grand_temple_01 }
                if = { limit = { has_building = holy_site_pagan_grand_temple_01 } remove_building = holy_site_pagan_grand_temple_01 }
                if = { limit = { has_building = holy_site_prophetic_mosque_01 } remove_building = holy_site_prophetic_mosque_01 }
                if = { limit = { has_building = holy_site_se_asia_pagan_temple_01 } remove_building = holy_site_se_asia_pagan_temple_01 }
                if = { limit = { has_building = holy_wisdom_01 } remove_building = holy_wisdom_01 }
                DI_remove_building_type_effect = { BUILDING = horse_pastures }
                if = { limit = { has_building = hoshi_ryokan_01 } remove_building = hoshi_ryokan_01 }
                DI_remove_building_type_effect = { BUILDING = hospices }
                if = { limit = { has_building = hotin_fort_02 } remove_building = hotin_fort_02 }
                else_if = { limit = { has_building = hotin_fort_01 } remove_building = hotin_fort_01 }
                if = { limit = { has_building = house_of_wisdom_01 } remove_building = house_of_wisdom_01 }
                if = { limit = { has_building = hpakant_mines_04 } remove_building = hpakant_mines_04 }
                else_if = { limit = { has_building = hpakant_mines_03 } remove_building = hpakant_mines_03 }
                else_if = { limit = { has_building = hpakant_mines_02 } remove_building = hpakant_mines_02 }
                else_if = { limit = { has_building = hpakant_mines_01 } remove_building = hpakant_mines_01 }
                DI_remove_building_type_effect = { BUILDING = hunting_grounds }
                if = { limit = { has_building = hwangnyongsa_01 } remove_building = hwangnyongsa_01 }
                if = { limit = { has_building = idjang_forts_04 } remove_building = idjang_forts_04 }
                else_if = { limit = { has_building = idjang_forts_03 } remove_building = idjang_forts_03 }
                else_if = { limit = { has_building = idjang_forts_02 } remove_building = idjang_forts_02 }
                else_if = { limit = { has_building = idjang_forts_01 } remove_building = idjang_forts_01 }
                if = { limit = { has_building = ijil_mines_04 } remove_building = ijil_mines_04 }
                else_if = { limit = { has_building = ijil_mines_03 } remove_building = ijil_mines_03 }
                else_if = { limit = { has_building = ijil_mines_02 } remove_building = ijil_mines_02 }
                else_if = { limit = { has_building = ijil_mines_01 } remove_building = ijil_mines_01 }
                if = { limit = { has_building = imam_reza_shrine_01 } remove_building = imam_reza_shrine_01 }
                if = { limit = { has_building = iron_pillar_of_delhi_01 } remove_building = iron_pillar_of_delhi_01 }
                if = { limit = { has_building = iron_pillar_of_dhar_01 } remove_building = iron_pillar_of_dhar_01 }
                if = { limit = { has_building = ise_jingu_01 } remove_building = ise_jingu_01 }
                if = { limit = { has_building = itoigawa_mines_04 } remove_building = itoigawa_mines_04 }
                else_if = { limit = { has_building = itoigawa_mines_03 } remove_building = itoigawa_mines_03 }
                else_if = { limit = { has_building = itoigawa_mines_02 } remove_building = itoigawa_mines_02 }
                else_if = { limit = { has_building = itoigawa_mines_01 } remove_building = itoigawa_mines_01 }
                if = { limit = { has_building = itsukushima_jinja_02 } remove_building = itsukushima_jinja_02 }
                else_if = { limit = { has_building = itsukushima_jinja_01 } remove_building = itsukushima_jinja_01 }
                if = { limit = { has_building = jaisalmer_fort_01 } remove_building = jaisalmer_fort_01 }
                if = { limit = { has_building = jizu_shan_temples_01 } remove_building = jizu_shan_temples_01 }
                if = { limit = { has_building = jokhang_01 } remove_building = jokhang_01 }
                if = { limit = { has_building = jousting_lists_03 } remove_building = jousting_lists_03 }
                else_if = { limit = { has_building = jousting_lists_02 } remove_building = jousting_lists_02 }
                else_if = { limit = { has_building = jousting_lists_01 } remove_building = jousting_lists_01 }
                if = { limit = { has_building = kaifeng_palace_01 } remove_building = kaifeng_palace_01 }
                if = { limit = { has_building = kairouan_basins_01 } remove_building = kairouan_basins_01 }
                if = { limit = { has_building = kano_walls_01 } remove_building = kano_walls_01 }
                if = { limit = { has_building = khajuraho_01 } remove_building = khajuraho_01 }
                if = { limit = { has_building = khetri_mines_04 } remove_building = khetri_mines_04 }
                else_if = { limit = { has_building = khetri_mines_03 } remove_building = khetri_mines_03 }
                else_if = { limit = { has_building = khetri_mines_02 } remove_building = khetri_mines_02 }
                else_if = { limit = { has_building = khetri_mines_01 } remove_building = khetri_mines_01 }
                if = { limit = { has_building = khiva_bazaar_02 } remove_building = khiva_bazaar_02 }
                else_if = { limit = { has_building = khiva_bazaar_01 } remove_building = khiva_bazaar_01 }
                if = { limit = { has_building = kofuku_ji_01 } remove_building = kofuku_ji_01 }
                if = { limit = { has_building = koganeyama_mines_04 } remove_building = koganeyama_mines_04 }
                else_if = { limit = { has_building = koganeyama_mines_03 } remove_building = koganeyama_mines_03 }
                else_if = { limit = { has_building = koganeyama_mines_02 } remove_building = koganeyama_mines_02 }
                else_if = { limit = { has_building = koganeyama_mines_01 } remove_building = koganeyama_mines_01 }
                if = { limit = { has_building = kollur_mines_04 } remove_building = kollur_mines_04 }
                else_if = { limit = { has_building = kollur_mines_03 } remove_building = kollur_mines_03 }
                else_if = { limit = { has_building = kollur_mines_02 } remove_building = kollur_mines_02 }
                else_if = { limit = { has_building = kollur_mines_01 } remove_building = kollur_mines_01 }
                if = { limit = { has_building = konark_temple_01 } remove_building = konark_temple_01 }
                if = { limit = { has_building = konasamudram_mines_04 } remove_building = konasamudram_mines_04 }
                else_if = { limit = { has_building = konasamudram_mines_03 } remove_building = konasamudram_mines_03 }
                else_if = { limit = { has_building = konasamudram_mines_02 } remove_building = konasamudram_mines_02 }
                else_if = { limit = { has_building = konasamudram_mines_01 } remove_building = konasamudram_mines_01 }
                if = { limit = { has_building = kora_kora_yards_04 } remove_building = kora_kora_yards_04 }
                else_if = { limit = { has_building = kora_kora_yards_03 } remove_building = kora_kora_yards_03 }
                else_if = { limit = { has_building = kora_kora_yards_02 } remove_building = kora_kora_yards_02 }
                else_if = { limit = { has_building = kora_kora_yards_01 } remove_building = kora_kora_yards_01 }
                if = { limit = { has_building = krakatoa_01 } remove_building = krakatoa_01 }
                if = { limit = { has_building = kremnica_mines_04 } remove_building = kremnica_mines_04 }
                else_if = { limit = { has_building = kremnica_mines_03 } remove_building = kremnica_mines_03 }
                else_if = { limit = { has_building = kremnica_mines_02 } remove_building = kremnica_mines_02 }
                else_if = { limit = { has_building = kremnica_mines_01 } remove_building = kremnica_mines_01 }
                if = { limit = { has_building = kutna_hora_mines_04 } remove_building = kutna_hora_mines_04 }
                else_if = { limit = { has_building = kutna_hora_mines_03 } remove_building = kutna_hora_mines_03 }
                else_if = { limit = { has_building = kutna_hora_mines_02 } remove_building = kutna_hora_mines_02 }
                else_if = { limit = { has_building = kutna_hora_mines_01 } remove_building = kutna_hora_mines_01 }
                if = { limit = { has_building = kyz_kala_01 } remove_building = kyz_kala_01 }
                if = { limit = { has_building = lahur_bazaar_02 } remove_building = lahur_bazaar_02 }
                else_if = { limit = { has_building = lahur_bazaar_01 } remove_building = lahur_bazaar_01 }
                if = { limit = { has_building = lantian_mines_04 } remove_building = lantian_mines_04 }
                else_if = { limit = { has_building = lantian_mines_03 } remove_building = lantian_mines_03 }
                else_if = { limit = { has_building = lantian_mines_02 } remove_building = lantian_mines_02 }
                else_if = { limit = { has_building = lantian_mines_01 } remove_building = lantian_mines_01 }
                if = { limit = { has_building = leisure_palace_03 } remove_building = leisure_palace_03 }
                else_if = { limit = { has_building = leisure_palace_02 } remove_building = leisure_palace_02 }
                else_if = { limit = { has_building = leisure_palace_01 } remove_building = leisure_palace_01 }
                if = { limit = { has_building = leshan_giant_buddha_01 } remove_building = leshan_giant_buddha_01 }
                if = { limit = { has_building = lhasa_market_02 } remove_building = lhasa_market_02 }
                else_if = { limit = { has_building = lhasa_market_01 } remove_building = lhasa_market_01 }
                if = { limit = { has_building = lingyin_temple_01 } remove_building = lingyin_temple_01 }
                if = { limit = { has_building = liuhe_pagoda_01 } remove_building = liuhe_pagoda_01 }
                if = { limit = { has_building = lize_academy_01 } remove_building = lize_academy_01 }
                DI_remove_building_type_effect = { BUILDING = logging_camps }
                if = { limit = { has_building = london_bridge_01 } remove_building = london_bridge_01 }
                if = { limit = { has_building = longhouses_02 } remove_building = longhouses_02 }
                else_if = { limit = { has_building = longhouses_01 } remove_building = longhouses_01 }
                if = { limit = { has_building = lund_cathedral_01 } remove_building = lund_cathedral_01 }
                if = { limit = { has_building = maharloo_lake_01 } remove_building = maharloo_lake_01 }
                if = { limit = { has_building = mali_mines_04 } remove_building = mali_mines_04 }
                else_if = { limit = { has_building = mali_mines_03 } remove_building = mali_mines_03 }
                else_if = { limit = { has_building = mali_mines_02 } remove_building = mali_mines_02 }
                else_if = { limit = { has_building = mali_mines_01 } remove_building = mali_mines_01 }
                if = { limit = { has_building = mandala_capital_05 } remove_building = mandala_capital_05 }
                else_if = { limit = { has_building = mandala_capital_04 } remove_building = mandala_capital_04 }
                else_if = { limit = { has_building = mandala_capital_03 } remove_building = mandala_capital_03 }
                else_if = { limit = { has_building = mandala_capital_02 } remove_building = mandala_capital_02 }
                else_if = { limit = { has_building = mandala_capital_01 } remove_building = mandala_capital_01 }
                if = { limit = { has_building = maoshan_academy_01 } remove_building = maoshan_academy_01 }
                if = { limit = { has_building = march_03 } remove_building = march_03 }
                else_if = { limit = { has_building = march_02 } remove_building = march_02 }
                else_if = { limit = { has_building = march_01 } remove_building = march_01 }
                if = { limit = { has_building = market_villages_02 } remove_building = market_villages_02 }
                else_if = { limit = { has_building = market_villages_01 } remove_building = market_villages_01 }
                DI_remove_building_type_effect = { BUILDING = megalith }
                if = { limit = { has_building = meteora_02 } remove_building = meteora_02 }
                else_if = { limit = { has_building = meteora_01 } remove_building = meteora_01 }
                if = { limit = { has_building = military_academy_03 } remove_building = military_academy_03 }
                else_if = { limit = { has_building = military_academy_02 } remove_building = military_academy_02 }
                else_if = { limit = { has_building = military_academy_01 } remove_building = military_academy_01 }
                DI_remove_building_type_effect = { BUILDING = military_camps }
                if = { limit = { has_building = minarets_and_remains_of_jam_01 } remove_building = minarets_and_remains_of_jam_01 }
                if = { limit = { has_building = mogok_mines_04 } remove_building = mogok_mines_04 }
                else_if = { limit = { has_building = mogok_mines_03 } remove_building = mogok_mines_03 }
                else_if = { limit = { has_building = mogok_mines_02 } remove_building = mogok_mines_02 }
                else_if = { limit = { has_building = mogok_mines_01 } remove_building = mogok_mines_01 }
                DI_remove_building_type_effect = { BUILDING = monastic_schools }
                if = { limit = { has_building = mount_apo_01 } remove_building = mount_apo_01 }
                if = { limit = { has_building = mount_athos_03 } remove_building = mount_athos_03 }
                else_if = { limit = { has_building = mount_athos_02 } remove_building = mount_athos_02 }
                else_if = { limit = { has_building = mount_athos_01 } remove_building = mount_athos_01 }
                if = { limit = { has_building = mount_baekdu_01 } remove_building = mount_baekdu_01 }
                if = { limit = { has_building = mount_damavand_01 } remove_building = mount_damavand_01 }
                if = { limit = { has_building = mount_fuji_01 } remove_building = mount_fuji_01 }
                if = { limit = { has_building = muaro_jambi_01 } remove_building = muaro_jambi_01 }
                DI_remove_building_type_effect = { BUILDING = murex_farm }
                if = { limit = { has_building = nanhua_temple_01 } remove_building = nanhua_temple_01 }
                if = { limit = { has_building = nishapur_mines_04 } remove_building = nishapur_mines_04 }
                else_if = { limit = { has_building = nishapur_mines_03 } remove_building = nishapur_mines_03 }
                else_if = { limit = { has_building = nishapur_mines_02 } remove_building = nishapur_mines_02 }
                else_if = { limit = { has_building = nishapur_mines_01 } remove_building = nishapur_mines_01 }
                if = { limit = { has_building = nomadic_camp_01 } remove_building = nomadic_camp_01 }
                if = { limit = { has_building = notre_dame_01 } remove_building = notre_dame_01 }
                if = { limit = { has_building = oath_faithful_building_04 } remove_building = oath_faithful_building_04 }
                else_if = { limit = { has_building = oath_faithful_building_03 } remove_building = oath_faithful_building_03 }
                else_if = { limit = { has_building = oath_faithful_building_02 } remove_building = oath_faithful_building_02 }
                else_if = { limit = { has_building = oath_faithful_building_01 } remove_building = oath_faithful_building_01 }
                if = { limit = { has_building = oath_poor_building_04 } remove_building = oath_poor_building_04 }
                else_if = { limit = { has_building = oath_poor_building_03 } remove_building = oath_poor_building_03 }
                else_if = { limit = { has_building = oath_poor_building_02 } remove_building = oath_poor_building_02 }
                else_if = { limit = { has_building = oath_poor_building_01 } remove_building = oath_poor_building_01 }
                if = { limit = { has_building = oath_warriors_building_04 } remove_building = oath_warriors_building_04 }
                else_if = { limit = { has_building = oath_warriors_building_03 } remove_building = oath_warriors_building_03 }
                else_if = { limit = { has_building = oath_warriors_building_02 } remove_building = oath_warriors_building_02 }
                else_if = { limit = { has_building = oath_warriors_building_01 } remove_building = oath_warriors_building_01 }
                if = { limit = { has_building = offas_dyke_01 } remove_building = offas_dyke_01 }
                DI_remove_building_type_effect = { BUILDING = orchards }
                DI_remove_building_type_effect = { BUILDING = outposts }
                DI_remove_building_type_effect = { BUILDING = paddy_fields }
                if = { limit = { has_building = pagoda_of_fogong_temple_01 } remove_building = pagoda_of_fogong_temple_01 }
                if = { limit = { has_building = palace_of_aachen_01 } remove_building = palace_of_aachen_01 }
                if = { limit = { has_building = palace_of_ctesiphon_02 } remove_building = palace_of_ctesiphon_02 }
                else_if = { limit = { has_building = palace_of_ctesiphon_01 } remove_building = palace_of_ctesiphon_01 }
                if = { limit = { has_building = palisades_02 } remove_building = palisades_02 }
                else_if = { limit = { has_building = palisades_01 } remove_building = palisades_01 }
                if = { limit = { has_building = pansjhir_mines_04 } remove_building = pansjhir_mines_04 }
                else_if = { limit = { has_building = pansjhir_mines_03 } remove_building = pansjhir_mines_03 }
                else_if = { limit = { has_building = pansjhir_mines_02 } remove_building = pansjhir_mines_02 }
                else_if = { limit = { has_building = pansjhir_mines_01 } remove_building = pansjhir_mines_01 }
                DI_remove_building_type_effect = { BUILDING = pastures }
                DI_remove_building_type_effect = { BUILDING = peat_quarries }
                if = { limit = { has_building = petra_01 } remove_building = petra_01 }
                if = { limit = { has_building = phnom_dek_mines_04 } remove_building = phnom_dek_mines_04 }
                else_if = { limit = { has_building = phnom_dek_mines_03 } remove_building = phnom_dek_mines_03 }
                else_if = { limit = { has_building = phnom_dek_mines_02 } remove_building = phnom_dek_mines_02 }
                else_if = { limit = { has_building = phnom_dek_mines_01 } remove_building = phnom_dek_mines_01 }
                if = { limit = { has_building = phocaea_mines_04 } remove_building = phocaea_mines_04 }
                else_if = { limit = { has_building = phocaea_mines_03 } remove_building = phocaea_mines_03 }
                else_if = { limit = { has_building = phocaea_mines_02 } remove_building = phocaea_mines_02 }
                else_if = { limit = { has_building = phocaea_mines_01 } remove_building = phocaea_mines_01 }
                if = { limit = { has_building = plain_of_jars_01 } remove_building = plain_of_jars_01 }
                DI_remove_building_type_effect = { BUILDING = plantations }
                if = { limit = { has_building = po_klong_garai_01 } remove_building = po_klong_garai_01 }
                DI_remove_building_type_effect = { BUILDING = powder_magazine }
                DI_remove_building_type_effect = { BUILDING = qanats }
                if = { limit = { has_building = qianling_mausoleum_01 } remove_building = qianling_mausoleum_01 }
                if = { limit = { has_building = quanzhou_seaport_01 } remove_building = quanzhou_seaport_01 }
                DI_remove_building_type_effect = { BUILDING = quarries }
                if = { limit = { has_building = rainbow_mountains_01 } remove_building = rainbow_mountains_01 }
                if = { limit = { has_building = rammelsberg_mines_04 } remove_building = rammelsberg_mines_04 }
                else_if = { limit = { has_building = rammelsberg_mines_03 } remove_building = rammelsberg_mines_03 }
                else_if = { limit = { has_building = rammelsberg_mines_02 } remove_building = rammelsberg_mines_02 }
                else_if = { limit = { has_building = rammelsberg_mines_01 } remove_building = rammelsberg_mines_01 }
                DI_remove_building_type_effect = { BUILDING = ramparts }
                if = { limit = { has_building = ratnapura_mines_04 } remove_building = ratnapura_mines_04 }
                else_if = { limit = { has_building = ratnapura_mines_03 } remove_building = ratnapura_mines_03 }
                else_if = { limit = { has_building = ratnapura_mines_02 } remove_building = ratnapura_mines_02 }
                else_if = { limit = { has_building = ratnapura_mines_01 } remove_building = ratnapura_mines_01 }
                DI_remove_building_type_effect = { BUILDING = regimental_grounds }
                if = { limit = { has_building = rock_of_gibraltar_01 } remove_building = rock_of_gibraltar_01 }
                if = { limit = { has_building = roman_wall_of_lugo_01 } remove_building = roman_wall_of_lugo_01 }
                if = { limit = { has_building = royal_armory_03 } remove_building = royal_armory_03 }
                else_if = { limit = { has_building = royal_armory_02 } remove_building = royal_armory_02 }
                else_if = { limit = { has_building = royal_armory_01 } remove_building = royal_armory_01 }
                if = { limit = { has_building = royal_forest_03 } remove_building = royal_forest_03 }
                else_if = { limit = { has_building = royal_forest_02 } remove_building = royal_forest_02 }
                else_if = { limit = { has_building = royal_forest_01 } remove_building = royal_forest_01 }
                if = { limit = { has_building = royal_garden_03 } remove_building = royal_garden_03 }
                else_if = { limit = { has_building = royal_garden_02 } remove_building = royal_garden_02 }
                else_if = { limit = { has_building = royal_garden_01 } remove_building = royal_garden_01 }
                if = { limit = { has_building = rudnik_mines_04 } remove_building = rudnik_mines_04 }
                else_if = { limit = { has_building = rudnik_mines_03 } remove_building = rudnik_mines_03 }
                else_if = { limit = { has_building = rudnik_mines_02 } remove_building = rudnik_mines_02 }
                else_if = { limit = { has_building = rudnik_mines_01 } remove_building = rudnik_mines_01 }
                DI_remove_building_type_effect = { BUILDING = sacred_pool }
                if = { limit = { has_building = sado_mines_04 } remove_building = sado_mines_04 }
                else_if = { limit = { has_building = sado_mines_03 } remove_building = sado_mines_03 }
                else_if = { limit = { has_building = sado_mines_02 } remove_building = sado_mines_02 }
                else_if = { limit = { has_building = sado_mines_01 } remove_building = sado_mines_01 }
                if = { limit = { has_building = sar_i_sang_mines_04 } remove_building = sar_i_sang_mines_04 }
                else_if = { limit = { has_building = sar_i_sang_mines_03 } remove_building = sar_i_sang_mines_03 }
                else_if = { limit = { has_building = sar_i_sang_mines_02 } remove_building = sar_i_sang_mines_02 }
                else_if = { limit = { has_building = sar_i_sang_mines_01 } remove_building = sar_i_sang_mines_01 }
                if = { limit = { has_building = schwaz_mines_04 } remove_building = schwaz_mines_04 }
                else_if = { limit = { has_building = schwaz_mines_03 } remove_building = schwaz_mines_03 }
                else_if = { limit = { has_building = schwaz_mines_02 } remove_building = schwaz_mines_02 }
                else_if = { limit = { has_building = schwaz_mines_01 } remove_building = schwaz_mines_01 }
                DI_remove_building_type_effect = { BUILDING = scriptorium }
                if = { limit = { has_building = shah_i_zinda_02 } remove_building = shah_i_zinda_02 }
                else_if = { limit = { has_building = shah_i_zinda_01 } remove_building = shah_i_zinda_01 }
                if = { limit = { has_building = shaolin_monastery_01 } remove_building = shaolin_monastery_01 }
                if = { limit = { has_building = shigu_academy_01 } remove_building = shigu_academy_01 }
                if = { limit = { has_building = shwedagon_pagoda_01 } remove_building = shwedagon_pagoda_01 }
                if = { limit = { has_building = siderokausia_mines_04 } remove_building = siderokausia_mines_04 }
                else_if = { limit = { has_building = siderokausia_mines_03 } remove_building = siderokausia_mines_03 }
                else_if = { limit = { has_building = siderokausia_mines_02 } remove_building = siderokausia_mines_02 }
                else_if = { limit = { has_building = siderokausia_mines_01 } remove_building = siderokausia_mines_01 }
                if = { limit = { has_building = siege_works_03 } remove_building = siege_works_03 }
                else_if = { limit = { has_building = siege_works_02 } remove_building = siege_works_02 }
                else_if = { limit = { has_building = siege_works_01 } remove_building = siege_works_01 }
                DI_remove_building_type_effect = { BUILDING = smiths }
                if = { limit = { has_building = soltaniyeh_01 } remove_building = soltaniyeh_01 }
                if = { limit = { has_building = somapura_university_01 } remove_building = somapura_university_01 }
                if = { limit = { has_building = special_greenhouse_01 } remove_building = special_greenhouse_01 }
                if = { limit = { has_building = special_sicilian_parliament_01 } remove_building = special_sicilian_parliament_01 }
                DI_remove_building_type_effect = { BUILDING = spice_plantation }
                if = { limit = { has_building = srebrenica_mines_04 } remove_building = srebrenica_mines_04 }
                else_if = { limit = { has_building = srebrenica_mines_03 } remove_building = srebrenica_mines_03 }
                else_if = { limit = { has_building = srebrenica_mines_02 } remove_building = srebrenica_mines_02 }
                else_if = { limit = { has_building = srebrenica_mines_01 } remove_building = srebrenica_mines_01 }
                DI_remove_building_type_effect = { BUILDING = stables }
                if = { limit = { has_building = stilted_granaries_04 } remove_building = stilted_granaries_04 }
                else_if = { limit = { has_building = stilted_granaries_03 } remove_building = stilted_granaries_03 }
                else_if = { limit = { has_building = stilted_granaries_02 } remove_building = stilted_granaries_02 }
                else_if = { limit = { has_building = stilted_granaries_01 } remove_building = stilted_granaries_01 }
                if = { limit = { has_building = stonehenge_01 } remove_building = stonehenge_01 }
                if = { limit = { has_building = sumela_monastery_02 } remove_building = sumela_monastery_02 }
                else_if = { limit = { has_building = sumela_monastery_01 } remove_building = sumela_monastery_01 }
                if = { limit = { has_building = sunday_bazaar_02 } remove_building = sunday_bazaar_02 }
                else_if = { limit = { has_building = sunday_bazaar_01 } remove_building = sunday_bazaar_01 }
                if = { limit = { has_building = suvarnadvipa_mines_04 } remove_building = suvarnadvipa_mines_04 }
                else_if = { limit = { has_building = suvarnadvipa_mines_03 } remove_building = suvarnadvipa_mines_03 }
                else_if = { limit = { has_building = suvarnadvipa_mines_02 } remove_building = suvarnadvipa_mines_02 }
                else_if = { limit = { has_building = suvarnadvipa_mines_01 } remove_building = suvarnadvipa_mines_01 }
                if = { limit = { has_building = tada_mines_04 } remove_building = tada_mines_04 }
                else_if = { limit = { has_building = tada_mines_03 } remove_building = tada_mines_03 }
                else_if = { limit = { has_building = tada_mines_02 } remove_building = tada_mines_02 }
                else_if = { limit = { has_building = tada_mines_01 } remove_building = tada_mines_01 }
                if = { limit = { has_building = taghaza_mines_04 } remove_building = taghaza_mines_04 }
                else_if = { limit = { has_building = taghaza_mines_03 } remove_building = taghaza_mines_03 }
                else_if = { limit = { has_building = taghaza_mines_02 } remove_building = taghaza_mines_02 }
                else_if = { limit = { has_building = taghaza_mines_01 } remove_building = taghaza_mines_01 }
                if = { limit = { has_building = takkeda_mines_04 } remove_building = takkeda_mines_04 }
                else_if = { limit = { has_building = takkeda_mines_03 } remove_building = takkeda_mines_03 }
                else_if = { limit = { has_building = takkeda_mines_02 } remove_building = takkeda_mines_02 }
                else_if = { limit = { has_building = takkeda_mines_01 } remove_building = takkeda_mines_01 }
                if = { limit = { has_building = tax_assessor_03 } remove_building = tax_assessor_03 }
                else_if = { limit = { has_building = tax_assessor_02 } remove_building = tax_assessor_02 }
                else_if = { limit = { has_building = tax_assessor_01 } remove_building = tax_assessor_01 }
                if = { limit = { has_building = temple_citadel_04 } remove_building = temple_citadel_04 }
                else_if = { limit = { has_building = temple_citadel_03 } remove_building = temple_citadel_03 }
                else_if = { limit = { has_building = temple_citadel_02 } remove_building = temple_citadel_02 }
                else_if = { limit = { has_building = temple_citadel_01 } remove_building = temple_citadel_01 }
                if = { limit = { has_building = temple_in_jerusalem_01 } remove_building = temple_in_jerusalem_01 }
                if = { limit = { has_building = temple_of_uppsala_02 } remove_building = temple_of_uppsala_02 }
                else_if = { limit = { has_building = temple_of_uppsala_01 } remove_building = temple_of_uppsala_01 }
                if = { limit = { has_building = the_colosseum_01 } remove_building = the_colosseum_01 }
                if = { limit = { has_building = the_friday_mosque_01 } remove_building = the_friday_mosque_01 }
                if = { limit = { has_building = the_great_wall_04 } remove_building = the_great_wall_04 }
                else_if = { limit = { has_building = the_great_wall_03 } remove_building = the_great_wall_03 }
                else_if = { limit = { has_building = the_great_wall_02 } remove_building = the_great_wall_02 }
                else_if = { limit = { has_building = the_great_wall_01 } remove_building = the_great_wall_01 }
                if = { limit = { has_building = the_pyramids_01 } remove_building = the_pyramids_01 }
                if = { limit = { has_building = the_tower_of_london_01 } remove_building = the_tower_of_london_01 }
                if = { limit = { has_building = theodosian_walls_01 } remove_building = theodosian_walls_01 }
                if = { limit = { has_building = tiantai_monasteries_01 } remove_building = tiantai_monasteries_01 }
                if = { limit = { has_building = tomb_of_cyrus_01 } remove_building = tomb_of_cyrus_01 }
                if = { limit = { has_building = tower_of_hercules_01 } remove_building = tower_of_hercules_01 }
                if = { limit = { has_building = tower_of_silence_01 } remove_building = tower_of_silence_01 }
                if = { limit = { has_building = trepca_mines_04 } remove_building = trepca_mines_04 }
                else_if = { limit = { has_building = trepca_mines_03 } remove_building = trepca_mines_03 }
                else_if = { limit = { has_building = trepca_mines_02 } remove_building = trepca_mines_02 }
                else_if = { limit = { has_building = trepca_mines_01 } remove_building = trepca_mines_01 }
                if = { limit = { has_building = tsushima_mines_04 } remove_building = tsushima_mines_04 }
                else_if = { limit = { has_building = tsushima_mines_03 } remove_building = tsushima_mines_03 }
                else_if = { limit = { has_building = tsushima_mines_02 } remove_building = tsushima_mines_02 }
                else_if = { limit = { has_building = tsushima_mines_01 } remove_building = tsushima_mines_01 }
                if = { limit = { has_building = turda_mines_04 } remove_building = turda_mines_04 }
                else_if = { limit = { has_building = turda_mines_03 } remove_building = turda_mines_03 }
                else_if = { limit = { has_building = turda_mines_02 } remove_building = turda_mines_02 }
                else_if = { limit = { has_building = turda_mines_01 } remove_building = turda_mines_01 }
                if = { limit = { has_building = vatapi_caves_01 } remove_building = vatapi_caves_01 }
                if = { limit = { has_building = verespatak_mines_04 } remove_building = verespatak_mines_04 }
                else_if = { limit = { has_building = verespatak_mines_03 } remove_building = verespatak_mines_03 }
                else_if = { limit = { has_building = verespatak_mines_02 } remove_building = verespatak_mines_02 }
                else_if = { limit = { has_building = verespatak_mines_01 } remove_building = verespatak_mines_01 }
                DI_remove_building_type_effect = { BUILDING = vihara_halls }
                if = { limit = { has_building = visby_ringmur_01 } remove_building = visby_ringmur_01 }
                if = { limit = { has_building = visegrad_castle_01 } remove_building = visegrad_castle_01 }
                if = { limit = { has_building = walls_of_benin_01 } remove_building = walls_of_benin_01 }
                if = { limit = { has_building = walls_of_genoa_01 } remove_building = walls_of_genoa_01 }
                if = { limit = { has_building = wantilan_04 } remove_building = wantilan_04 }
                else_if = { limit = { has_building = wantilan_03 } remove_building = wantilan_03 }
                else_if = { limit = { has_building = wantilan_02 } remove_building = wantilan_02 }
                else_if = { limit = { has_building = wantilan_01 } remove_building = wantilan_01 }
                if = { limit = { has_building = war_camps_02 } remove_building = war_camps_02 }
                else_if = { limit = { has_building = war_camps_01 } remove_building = war_camps_01 }
                DI_remove_building_type_effect = { BUILDING = warrior_lodges }
                if = { limit = { has_building = wartburg_01 } remove_building = wartburg_01 }
                DI_remove_building_type_effect = { BUILDING = watchtowers }
                if = { limit = { has_building = water_temples_04 } remove_building = water_temples_04 }
                else_if = { limit = { has_building = water_temples_03 } remove_building = water_temples_03 }
                else_if = { limit = { has_building = water_temples_02 } remove_building = water_temples_02 }
                else_if = { limit = { has_building = water_temples_01 } remove_building = water_temples_01 }
                DI_remove_building_type_effect = { BUILDING = watermills }
                DI_remove_building_type_effect = { BUILDING = waterworks }
                if = { limit = { has_building = wawel_cathedral_03 } remove_building = wawel_cathedral_03 }
                else_if = { limit = { has_building = wawel_cathedral_02 } remove_building = wawel_cathedral_02 }
                else_if = { limit = { has_building = wawel_cathedral_01 } remove_building = wawel_cathedral_01 }
                if = { limit = { has_building = white_deer_grotto_academy_01 } remove_building = white_deer_grotto_academy_01 }
                DI_remove_building_type_effect = { BUILDING = wind_furnace }
                DI_remove_building_type_effect = { BUILDING = windmills }
                DI_remove_building_type_effect = { BUILDING = workshops }
                if = { limit = { has_building = wudang_mountain_temples_01 } remove_building = wudang_mountain_temples_01 }
                if = { limit = { has_building = wulingyuan_01 } remove_building = wulingyuan_01 }
                if = { limit = { has_building = xiuyan_mines_04 } remove_building = xiuyan_mines_04 }
                else_if = { limit = { has_building = xiuyan_mines_03 } remove_building = xiuyan_mines_03 }
                else_if = { limit = { has_building = xiuyan_mines_02 } remove_building = xiuyan_mines_02 }
                else_if = { limit = { has_building = xiuyan_mines_01 } remove_building = xiuyan_mines_01 }
                if = { limit = { has_building = york_walls_01 } remove_building = york_walls_01 }
                if = { limit = { has_building = yungang_grottoes_01 } remove_building = yungang_grottoes_01 }
                if = { limit = { has_building = zawar_mines_04 } remove_building = zawar_mines_04 }
                else_if = { limit = { has_building = zawar_mines_03 } remove_building = zawar_mines_03 }
                else_if = { limit = { has_building = zawar_mines_02 } remove_building = zawar_mines_02 }
                else_if = { limit = { has_building = zawar_mines_01 } remove_building = zawar_mines_01 }
            }
        }
    }
}

DI_max_building_upgrades_sgui = {
    scope = character # Player Character

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_action_provinces
            save_scope_as = province

            if = { limit = { has_building_or_higher = al_qarawiyyin_university_01 NOT = { has_building = al_qarawiyyin_university_01 } } add_building = al_qarawiyyin_university_01 }
            if = { limit = { has_building_or_higher = alamut_castle_01 NOT = { has_building = alamut_castle_02 } } add_building = alamut_castle_02 }
            if = { limit = { has_building_or_higher = alcazar_of_segovia_01 NOT = { has_building = alcazar_of_segovia_01 } } add_building = alcazar_of_segovia_01 }
            if = { limit = { has_building_or_higher = alhambra_01 NOT = { has_building = alhambra_02 } } add_building = alhambra_02 }
            if = { limit = { has_building_or_higher = aljaferia_palace_01 NOT = { has_building = aljaferia_palace_01 } } add_building = aljaferia_palace_01 }
            if = { limit = { has_building_or_higher = allaq_mines_01 NOT = { has_building = allaq_mines_04 } } add_building = allaq_mines_04 }
            if = { limit = { has_building_or_higher = ananda_temple_01 NOT = { has_building = ananda_temple_01 } } add_building = ananda_temple_01 }
            if = { limit = { has_building_or_higher = angkor_wat_01 NOT = { has_building = angkor_wat_01 } } add_building = angkor_wat_01 }
            if = { limit = { has_building_or_higher = archery_ranges_01 NOT = { has_building = archery_ranges_03 } } add_building = archery_ranges_03 }
            if = { limit = { has_building_or_higher = argentiera_mines_01 NOT = { has_building = argentiera_mines_04 } } add_building = argentiera_mines_04 }
            if = { limit = { has_building_or_higher = ark_of_bukhara_01 NOT = { has_building = ark_of_bukhara_01 } } add_building = ark_of_bukhara_01 }
            if = { limit = { has_building_or_higher = assassin_castle_01 NOT = { has_building = assassin_castle_01 } } add_building = assassin_castle_01 }
            if = { limit = { has_building_or_higher = aurelian_walls_01 NOT = { has_building = aurelian_walls_01 } } add_building = aurelian_walls_01 }
            if = { limit = { has_building_or_higher = barracks_01 NOT = { has_building = barracks_08 } } add_building = barracks_08 }
            if = { limit = { has_building_or_higher = besakih_temple_01 NOT = { has_building = besakih_temple_01 } } add_building = besakih_temple_01 }
            if = { limit = { has_building_or_higher = beta_giyorgis_01 NOT = { has_building = beta_giyorgis_01 } } add_building = beta_giyorgis_01 }
            if = { limit = { has_building_or_higher = blacksmiths_01 NOT = { has_building = blacksmiths_03 } } add_building = blacksmiths_03 }
            if = { limit = { has_building_or_higher = borobudur_01 NOT = { has_building = borobudur_01 } } add_building = borobudur_01 }
            if = { limit = { has_building_or_higher = breweries_01 NOT = { has_building = breweries_08 } } add_building = breweries_08 }
            if = { limit = { has_building_or_higher = brihadeeswarar_temple_01 NOT = { has_building = brihadeeswarar_temple_01 } } add_building = brihadeeswarar_temple_01 }
            if = { limit = { has_building_or_higher = buddhas_of_bamian_01 NOT = { has_building = buddhas_of_bamian_01 } } add_building = buddhas_of_bamian_01 }
            if = { limit = { has_building_or_higher = burial_site_01 NOT = { has_building = burial_site_03 } } add_building = burial_site_03 }
            if = { limit = { has_building_or_higher = burkhan_khaldun_01 NOT = { has_building = burkhan_khaldun_01 } } add_building = burkhan_khaldun_01 }
            if = { limit = { has_building_or_higher = byeokran_port_01 NOT = { has_building = byeokran_port_01 } } add_building = byeokran_port_01 }
            if = { limit = { has_building_or_higher = camel_farms_01 NOT = { has_building = camel_farms_08 } } add_building = camel_farms_08 }
            if = { limit = { has_building_or_higher = capital_bureau_01 NOT = { has_building = capital_bureau_08 } } add_building = capital_bureau_08 }
            if = { limit = { has_building_or_higher = caravanserai_01 NOT = { has_building = caravanserai_08 } } add_building = caravanserai_08 }
            if = { limit = { has_building_or_higher = castle_01 NOT = { has_building = castle_04 } } add_building = castle_04 }
            if = { limit = { has_building_or_higher = celestial_great_barracks_01 NOT = { has_building = celestial_great_barracks_01 } } add_building = celestial_great_barracks_01 }
            if = { limit = { has_building_or_higher = cereal_fields_01 NOT = { has_building = cereal_fields_08 } } add_building = cereal_fields_08 }
            if = { limit = { has_building_or_higher = cevennes_mines_01 NOT = { has_building = cevennes_mines_04 } } add_building = cevennes_mines_04 }
            if = { limit = { has_building_or_higher = changan_market_01 NOT = { has_building = changan_market_02 } } add_building = changan_market_02 }
            if = { limit = { has_building_or_higher = charnel_grounds_01 NOT = { has_building = charnel_grounds_03 } } add_building = charnel_grounds_03 }
            if = { limit = { has_building_or_higher = chinjufu_01 NOT = { has_building = chinjufu_01 } } add_building = chinjufu_01 }
            if = { limit = { has_building_or_higher = citadel_of_aleppo_01 NOT = { has_building = citadel_of_aleppo_02 } } add_building = citadel_of_aleppo_02 }
            if = { limit = { has_building_or_higher = citadel_shrine_01 NOT = { has_building = citadel_shrine_08 } } add_building = citadel_shrine_08 }
            if = { limit = { has_building_or_higher = citadel_thang_long_01 NOT = { has_building = citadel_thang_long_02 } } add_building = citadel_thang_long_02 }
            if = { limit = { has_building_or_higher = city_01 NOT = { has_building = city_04 } } add_building = city_04 }
            if = { limit = { has_building_or_higher = city_wall_of_toledo_01 NOT = { has_building = city_wall_of_toledo_01 } } add_building = city_wall_of_toledo_01 }
            if = { limit = { has_building_or_higher = cluny_abbey_01 NOT = { has_building = cluny_abbey_02 } } add_building = cluny_abbey_02 }
            if = { limit = { has_building_or_higher = common_tradeport_01 NOT = { has_building = common_tradeport_08 } } add_building = common_tradeport_08 }
            if = { limit = { has_building_or_higher = culai_academy_01 NOT = { has_building = culai_academy_01 } } add_building = culai_academy_01 }
            if = { limit = { has_building_or_higher = curtain_walls_01 NOT = { has_building = curtain_walls_08 } } add_building = curtain_walls_08 }
            if = { limit = { has_building_or_higher = damascus_mosque_01 NOT = { has_building = damascus_mosque_01 } } add_building = damascus_mosque_01 }
            if = { limit = { has_building_or_higher = danevirke_01 NOT = { has_building = danevirke_01 } } add_building = danevirke_01 }
            if = { limit = { has_building_or_higher = dau_temple_01 NOT = { has_building = dau_temple_01 } } add_building = dau_temple_01 }
            if = { limit = { has_building_or_higher = dazaifu_01 NOT = { has_building = dazaifu_01 } } add_building = dazaifu_01 }
            if = { limit = { has_building_or_higher = dean_mines_01 NOT = { has_building = dean_mines_04 } } add_building = dean_mines_04 }
            if = { limit = { has_building_or_higher = dieng_plateau_01 NOT = { has_building = dieng_plateau_01 } } add_building = dieng_plateau_01 }
            if = { limit = { has_building_or_higher = doges_palace_01 NOT = { has_building = doges_palace_01 } } add_building = doges_palace_01 }
            if = { limit = { has_building_or_higher = dome_of_the_rock_01 NOT = { has_building = dome_of_the_rock_01 } } add_building = dome_of_the_rock_01 }
            if = { limit = { has_building_or_higher = dragon_kiln_01 NOT = { has_building = dragon_kiln_03 } } add_building = dragon_kiln_03 }
            if = { limit = { has_building_or_higher = drassanes_01 NOT = { has_building = drassanes_01 } } add_building = drassanes_01 }
            if = { limit = { has_building_or_higher = dunhuang_market_01 NOT = { has_building = dunhuang_market_02 } } add_building = dunhuang_market_02 }
            if = { limit = { has_building_or_higher = duomo_florence_01 NOT = { has_building = duomo_florence_04 } } add_building = duomo_florence_04 }
            if = { limit = { has_building_or_higher = dushan_mines_01 NOT = { has_building = dushan_mines_04 } } add_building = dushan_mines_04 }
            if = { limit = { has_building_or_higher = dvin_shuka_01 NOT = { has_building = dvin_shuka_02 } } add_building = dvin_shuka_02 }
            if = { limit = { has_building_or_higher = elephant_pens_01 NOT = { has_building = elephant_pens_08 } } add_building = elephant_pens_08 }
            if = { limit = { has_building_or_higher = enryaku_ji_01 NOT = { has_building = enryaku_ji_01 } } add_building = enryaku_ji_01 }
            if = { limit = { has_building_or_higher = event_tower_of_silence_01 NOT = { has_building = event_tower_of_silence_01 } } add_building = event_tower_of_silence_01 }
            if = { limit = { has_building_or_higher = examination_hall_01 NOT = { has_building = examination_hall_03 } } add_building = examination_hall_03 }
            if = { limit = { has_building_or_higher = falak_ol_aflak_citadel_01 NOT = { has_building = falak_ol_aflak_citadel_01 } } add_building = falak_ol_aflak_citadel_01 }
            if = { limit = { has_building_or_higher = falun_mines_01 NOT = { has_building = falun_mines_04 } } add_building = falun_mines_04 }
            if = { limit = { has_building_or_higher = farm_estates_01 NOT = { has_building = farm_estates_08 } } add_building = farm_estates_08 }
            if = { limit = { has_building_or_higher = fengtian_mines_01 NOT = { has_building = fengtian_mines_03 } } add_building = fengtian_mines_03 }
            if = { limit = { has_building_or_higher = forbidden_city_01 NOT = { has_building = forbidden_city_01 } } add_building = forbidden_city_01 }
            if = { limit = { has_building_or_higher = generic_copper_mines_01 NOT = { has_building = generic_copper_mines_04 } } add_building = generic_copper_mines_04 }
            if = { limit = { has_building_or_higher = generic_gold_mines_01 NOT = { has_building = generic_gold_mines_04 } } add_building = generic_gold_mines_04 }
            if = { limit = { has_building_or_higher = generic_silver_mines_01 NOT = { has_building = generic_silver_mines_04 } } add_building = generic_silver_mines_04 }
            if = { limit = { has_building_or_higher = ghana_palace_01 NOT = { has_building = ghana_palace_01 } } add_building = ghana_palace_01 }
            if = { limit = { has_building_or_higher = giant_wild_goose_pagoda_01 NOT = { has_building = giant_wild_goose_pagoda_01 } } add_building = giant_wild_goose_pagoda_01 }
            if = { limit = { has_building_or_higher = golden_gate_of_kiev_01 NOT = { has_building = golden_gate_of_kiev_01 } } add_building = golden_gate_of_kiev_01 }
            if = { limit = { has_building_or_higher = gongsanseong_fortress_01 NOT = { has_building = gongsanseong_fortress_01 } } add_building = gongsanseong_fortress_01 }
            if = { limit = { has_building_or_higher = great_megalith_01 NOT = { has_building = great_megalith_01 } } add_building = great_megalith_01 }
            if = { limit = { has_building_or_higher = great_wall_of_gorgan_01 NOT = { has_building = great_wall_of_gorgan_01 } } add_building = great_wall_of_gorgan_01 }
            if = { limit = { has_building_or_higher = guild_halls_01 NOT = { has_building = guild_halls_08 } } add_building = guild_halls_08 }
            if = { limit = { has_building_or_higher = hadrians_wall_01 NOT = { has_building = hadrians_wall_01 } } add_building = hadrians_wall_01 }
            if = { limit = { has_building_or_higher = hagia_sophia_01 NOT = { has_building = hagia_sophia_02 } } add_building = hagia_sophia_02 }
            if = { limit = { has_building_or_higher = hakata_port_01 NOT = { has_building = hakata_port_02 } } add_building = hakata_port_02 }
            if = { limit = { has_building_or_higher = hall_of_heroes_01 NOT = { has_building = hall_of_heroes_05 } } add_building = hall_of_heroes_05 }
            if = { limit = { has_building_or_higher = hamadan_bazaar_01 NOT = { has_building = hamadan_bazaar_02 } } add_building = hamadan_bazaar_02 }
            if = { limit = { has_building_or_higher = hanging_temple_01 NOT = { has_building = hanging_temple_01 } } add_building = hanging_temple_01 }
            if = { limit = { has_building_or_higher = heddal_stave_church_01 NOT = { has_building = heddal_stave_church_01 } } add_building = heddal_stave_church_01 }
            if = { limit = { has_building_or_higher = heian_palace_01 NOT = { has_building = heian_palace_01 } } add_building = heian_palace_01 }
            if = { limit = { has_building_or_higher = herat_bazaar_01 NOT = { has_building = herat_bazaar_02 } } add_building = herat_bazaar_02 }
            if = { limit = { has_building_or_higher = herder_camp_01 NOT = { has_building = herder_camp_01 } } add_building = herder_camp_01 }
            if = { limit = { has_building_or_higher = hetian_mines_01 NOT = { has_building = hetian_mines_04 } } add_building = hetian_mines_04 }
            if = { limit = { has_building_or_higher = hill_farms_01 NOT = { has_building = hill_farms_08 } } add_building = hill_farms_08 }
            if = { limit = { has_building_or_higher = hill_forts_01 NOT = { has_building = hill_forts_08 } } add_building = hill_forts_08 }
            if = { limit = { has_building_or_higher = hillside_grazing_01 NOT = { has_building = hillside_grazing_08 } } add_building = hillside_grazing_08 }
            if = { limit = { has_building_or_higher = holy_site_basilica_santiago_01 NOT = { has_building = holy_site_basilica_santiago_01 } } add_building = holy_site_basilica_santiago_01 }
            if = { limit = { has_building_or_higher = holy_site_buddhist_grand_temple_01 NOT = { has_building = holy_site_buddhist_grand_temple_01 } } add_building = holy_site_buddhist_grand_temple_01 }
            if = { limit = { has_building_or_higher = holy_site_canterbury_cathedral_01 NOT = { has_building = holy_site_canterbury_cathedral_03 } } add_building = holy_site_canterbury_cathedral_03 }
            if = { limit = { has_building_or_higher = holy_site_cathedral_01 NOT = { has_building = holy_site_cathedral_01 } } add_building = holy_site_cathedral_01 }
            if = { limit = { has_building_or_higher = holy_site_chinese_temple_01 NOT = { has_building = holy_site_chinese_temple_01 } } add_building = holy_site_chinese_temple_01 }
            if = { limit = { has_building_or_higher = holy_site_cologne_cathedral_01 NOT = { has_building = holy_site_cologne_cathedral_01 } } add_building = holy_site_cologne_cathedral_01 }
            if = { limit = { has_building_or_higher = holy_site_fire_temple_01 NOT = { has_building = holy_site_fire_temple_01 } } add_building = holy_site_fire_temple_01 }
            if = { limit = { has_building_or_higher = holy_site_great_mosque_of_cordoba_01 NOT = { has_building = holy_site_great_mosque_of_cordoba_01 } } add_building = holy_site_great_mosque_of_cordoba_01 }
            if = { limit = { has_building_or_higher = holy_site_great_mosque_of_djenne_01 NOT = { has_building = holy_site_great_mosque_of_djenne_01 } } add_building = holy_site_great_mosque_of_djenne_01 }
            if = { limit = { has_building_or_higher = holy_site_great_mosque_of_mecca_01 NOT = { has_building = holy_site_great_mosque_of_mecca_01 } } add_building = holy_site_great_mosque_of_mecca_01 }
            if = { limit = { has_building_or_higher = holy_site_great_mosque_of_samarra_01 NOT = { has_building = holy_site_great_mosque_of_samarra_01 } } add_building = holy_site_great_mosque_of_samarra_01 }
            if = { limit = { has_building_or_higher = holy_site_imam_ali_mosque_01 NOT = { has_building = holy_site_imam_ali_mosque_01 } } add_building = holy_site_imam_ali_mosque_01 }
            if = { limit = { has_building_or_higher = holy_site_indian_grand_temple_01 NOT = { has_building = holy_site_indian_grand_temple_01 } } add_building = holy_site_indian_grand_temple_01 }
            if = { limit = { has_building_or_higher = holy_site_japanese_temple_01 NOT = { has_building = holy_site_japanese_temple_01 } } add_building = holy_site_japanese_temple_01 }
            if = { limit = { has_building_or_higher = holy_site_mahabodhi_temple_01 NOT = { has_building = holy_site_mahabodhi_temple_01 } } add_building = holy_site_mahabodhi_temple_01 }
            if = { limit = { has_building_or_higher = holy_site_mosque_01 NOT = { has_building = holy_site_mosque_01 } } add_building = holy_site_mosque_01 }
            if = { limit = { has_building_or_higher = holy_site_other_grand_temple_01 NOT = { has_building = holy_site_other_grand_temple_01 } } add_building = holy_site_other_grand_temple_01 }
            if = { limit = { has_building_or_higher = holy_site_pagan_grand_temple_01 NOT = { has_building = holy_site_pagan_grand_temple_01 } } add_building = holy_site_pagan_grand_temple_01 }
            if = { limit = { has_building_or_higher = holy_site_prophetic_mosque_01 NOT = { has_building = holy_site_prophetic_mosque_01 } } add_building = holy_site_prophetic_mosque_01 }
            if = { limit = { has_building_or_higher = holy_site_se_asia_pagan_temple_01 NOT = { has_building = holy_site_se_asia_pagan_temple_01 } } add_building = holy_site_se_asia_pagan_temple_01 }
            if = { limit = { has_building_or_higher = holy_wisdom_01 NOT = { has_building = holy_wisdom_01 } } add_building = holy_wisdom_01 }
            if = { limit = { has_building_or_higher = horse_pastures_01 NOT = { has_building = horse_pastures_08 } } add_building = horse_pastures_08 }
            if = { limit = { has_building_or_higher = hoshi_ryokan_01 NOT = { has_building = hoshi_ryokan_01 } } add_building = hoshi_ryokan_01 }
            if = { limit = { has_building_or_higher = hospices_01 NOT = { has_building = hospices_08 } } add_building = hospices_08 }
            if = { limit = { has_building_or_higher = hotin_fort_01 NOT = { has_building = hotin_fort_02 } } add_building = hotin_fort_02 }
            if = { limit = { has_building_or_higher = house_of_wisdom_01 NOT = { has_building = house_of_wisdom_01 } } add_building = house_of_wisdom_01 }
            if = { limit = { has_building_or_higher = hpakant_mines_01 NOT = { has_building = hpakant_mines_04 } } add_building = hpakant_mines_04 }
            if = { limit = { has_building_or_higher = hunting_grounds_01 NOT = { has_building = hunting_grounds_08 } } add_building = hunting_grounds_08 }
            if = { limit = { has_building_or_higher = hwangnyongsa_01 NOT = { has_building = hwangnyongsa_01 } } add_building = hwangnyongsa_01 }
            if = { limit = { has_building_or_higher = idjang_forts_01 NOT = { has_building = idjang_forts_04 } } add_building = idjang_forts_04 }
            if = { limit = { has_building_or_higher = ijil_mines_01 NOT = { has_building = ijil_mines_04 } } add_building = ijil_mines_04 }
            if = { limit = { has_building_or_higher = imam_reza_shrine_01 NOT = { has_building = imam_reza_shrine_01 } } add_building = imam_reza_shrine_01 }
            if = { limit = { has_building_or_higher = iron_pillar_of_delhi_01 NOT = { has_building = iron_pillar_of_delhi_01 } } add_building = iron_pillar_of_delhi_01 }
            if = { limit = { has_building_or_higher = iron_pillar_of_dhar_01 NOT = { has_building = iron_pillar_of_dhar_01 } } add_building = iron_pillar_of_dhar_01 }
            if = { limit = { has_building_or_higher = ise_jingu_01 NOT = { has_building = ise_jingu_01 } } add_building = ise_jingu_01 }
            if = { limit = { has_building_or_higher = itoigawa_mines_01 NOT = { has_building = itoigawa_mines_04 } } add_building = itoigawa_mines_04 }
            if = { limit = { has_building_or_higher = itsukushima_jinja_01 NOT = { has_building = itsukushima_jinja_02 } } add_building = itsukushima_jinja_02 }
            if = { limit = { has_building_or_higher = jaisalmer_fort_01 NOT = { has_building = jaisalmer_fort_01 } } add_building = jaisalmer_fort_01 }
            if = { limit = { has_building_or_higher = jizu_shan_temples_01 NOT = { has_building = jizu_shan_temples_01 } } add_building = jizu_shan_temples_01 }
            if = { limit = { has_building_or_higher = jokhang_01 NOT = { has_building = jokhang_01 } } add_building = jokhang_01 }
            if = { limit = { has_building_or_higher = jousting_lists_01 NOT = { has_building = jousting_lists_03 } } add_building = jousting_lists_03 }
            if = { limit = { has_building_or_higher = kaifeng_palace_01 NOT = { has_building = kaifeng_palace_01 } } add_building = kaifeng_palace_01 }
            if = { limit = { has_building_or_higher = kairouan_basins_01 NOT = { has_building = kairouan_basins_01 } } add_building = kairouan_basins_01 }
            if = { limit = { has_building_or_higher = kano_walls_01 NOT = { has_building = kano_walls_01 } } add_building = kano_walls_01 }
            if = { limit = { has_building_or_higher = khajuraho_01 NOT = { has_building = khajuraho_01 } } add_building = khajuraho_01 }
            if = { limit = { has_building_or_higher = khetri_mines_01 NOT = { has_building = khetri_mines_04 } } add_building = khetri_mines_04 }
            if = { limit = { has_building_or_higher = khiva_bazaar_01 NOT = { has_building = khiva_bazaar_02 } } add_building = khiva_bazaar_02 }
            if = { limit = { has_building_or_higher = kofuku_ji_01 NOT = { has_building = kofuku_ji_01 } } add_building = kofuku_ji_01 }
            if = { limit = { has_building_or_higher = koganeyama_mines_01 NOT = { has_building = koganeyama_mines_04 } } add_building = koganeyama_mines_04 }
            if = { limit = { has_building_or_higher = kollur_mines_01 NOT = { has_building = kollur_mines_04 } } add_building = kollur_mines_04 }
            if = { limit = { has_building_or_higher = konark_temple_01 NOT = { has_building = konark_temple_01 } } add_building = konark_temple_01 }
            if = { limit = { has_building_or_higher = konasamudram_mines_01 NOT = { has_building = konasamudram_mines_04 } } add_building = konasamudram_mines_04 }
            if = { limit = { has_building_or_higher = kora_kora_yards_01 NOT = { has_building = kora_kora_yards_04 } } add_building = kora_kora_yards_04 }
            if = { limit = { has_building_or_higher = krakatoa_01 NOT = { has_building = krakatoa_01 } } add_building = krakatoa_01 }
            if = { limit = { has_building_or_higher = kremnica_mines_01 NOT = { has_building = kremnica_mines_04 } } add_building = kremnica_mines_04 }
            if = { limit = { has_building_or_higher = kutna_hora_mines_01 NOT = { has_building = kutna_hora_mines_04 } } add_building = kutna_hora_mines_04 }
            if = { limit = { has_building_or_higher = kyz_kala_01 NOT = { has_building = kyz_kala_01 } } add_building = kyz_kala_01 }
            if = { limit = { has_building_or_higher = lahur_bazaar_01 NOT = { has_building = lahur_bazaar_02 } } add_building = lahur_bazaar_02 }
            if = { limit = { has_building_or_higher = lantian_mines_01 NOT = { has_building = lantian_mines_04 } } add_building = lantian_mines_04 }
            if = { limit = { has_building_or_higher = leisure_palace_01 NOT = { has_building = leisure_palace_03 } } add_building = leisure_palace_03 }
            if = { limit = { has_building_or_higher = leshan_giant_buddha_01 NOT = { has_building = leshan_giant_buddha_01 } } add_building = leshan_giant_buddha_01 }
            if = { limit = { has_building_or_higher = lhasa_market_01 NOT = { has_building = lhasa_market_02 } } add_building = lhasa_market_02 }
            if = { limit = { has_building_or_higher = lingyin_temple_01 NOT = { has_building = lingyin_temple_01 } } add_building = lingyin_temple_01 }
            if = { limit = { has_building_or_higher = liuhe_pagoda_01 NOT = { has_building = liuhe_pagoda_01 } } add_building = liuhe_pagoda_01 }
            if = { limit = { has_building_or_higher = lize_academy_01 NOT = { has_building = lize_academy_01 } } add_building = lize_academy_01 }
            if = { limit = { has_building_or_higher = logging_camps_01 NOT = { has_building = logging_camps_08 } } add_building = logging_camps_08 }
            if = { limit = { has_building_or_higher = london_bridge_01 NOT = { has_building = london_bridge_01 } } add_building = london_bridge_01 }
            if = { limit = { has_building_or_higher = longhouses_01 NOT = { has_building = longhouses_02 } } add_building = longhouses_02 }
            if = { limit = { has_building_or_higher = lund_cathedral_01 NOT = { has_building = lund_cathedral_01 } } add_building = lund_cathedral_01 }
            if = { limit = { has_building_or_higher = maharloo_lake_01 NOT = { has_building = maharloo_lake_01 } } add_building = maharloo_lake_01 }
            if = { limit = { has_building_or_higher = mali_mines_01 NOT = { has_building = mali_mines_04 } } add_building = mali_mines_04 }
            if = { limit = { has_building_or_higher = mandala_capital_01 NOT = { has_building = mandala_capital_05 } } add_building = mandala_capital_05 }
            if = { limit = { has_building_or_higher = maoshan_academy_01 NOT = { has_building = maoshan_academy_01 } } add_building = maoshan_academy_01 }
            if = { limit = { has_building_or_higher = march_01 NOT = { has_building = march_03 } } add_building = march_03 }
            if = { limit = { has_building_or_higher = market_villages_01 NOT = { has_building = market_villages_02 } } add_building = market_villages_02 }
            if = { limit = { has_building_or_higher = megalith_01 NOT = { has_building = megalith_08 } } add_building = megalith_08 }
            if = { limit = { has_building_or_higher = meteora_01 NOT = { has_building = meteora_02 } } add_building = meteora_02 }
            if = { limit = { has_building_or_higher = military_academy_01 NOT = { has_building = military_academy_03 } } add_building = military_academy_03 }
            if = { limit = { has_building_or_higher = military_camps_01 NOT = { has_building = military_camps_08 } } add_building = military_camps_08 }
            if = { limit = { has_building_or_higher = minarets_and_remains_of_jam_01 NOT = { has_building = minarets_and_remains_of_jam_01 } } add_building = minarets_and_remains_of_jam_01 }
            if = { limit = { has_building_or_higher = mogok_mines_01 NOT = { has_building = mogok_mines_04 } } add_building = mogok_mines_04 }
            if = { limit = { has_building_or_higher = monastic_schools_01 NOT = { has_building = monastic_schools_08 } } add_building = monastic_schools_08 }
            if = { limit = { has_building_or_higher = mount_apo_01 NOT = { has_building = mount_apo_01 } } add_building = mount_apo_01 }
            if = { limit = { has_building_or_higher = mount_athos_01 NOT = { has_building = mount_athos_03 } } add_building = mount_athos_03 }
            if = { limit = { has_building_or_higher = mount_baekdu_01 NOT = { has_building = mount_baekdu_01 } } add_building = mount_baekdu_01 }
            if = { limit = { has_building_or_higher = mount_damavand_01 NOT = { has_building = mount_damavand_01 } } add_building = mount_damavand_01 }
            if = { limit = { has_building_or_higher = mount_fuji_01 NOT = { has_building = mount_fuji_01 } } add_building = mount_fuji_01 }
            if = { limit = { has_building_or_higher = muaro_jambi_01 NOT = { has_building = muaro_jambi_01 } } add_building = muaro_jambi_01 }
            if = { limit = { has_building_or_higher = murex_farm_01 NOT = { has_building = murex_farm_08 } } add_building = murex_farm_08 }
            if = { limit = { has_building_or_higher = nanhua_temple_01 NOT = { has_building = nanhua_temple_01 } } add_building = nanhua_temple_01 }
            if = { limit = { has_building_or_higher = nishapur_mines_01 NOT = { has_building = nishapur_mines_04 } } add_building = nishapur_mines_04 }
            if = { limit = { has_building_or_higher = nomadic_camp_01 NOT = { has_building = nomadic_camp_01 } } add_building = nomadic_camp_01 }
            if = { limit = { has_building_or_higher = notre_dame_01 NOT = { has_building = notre_dame_01 } } add_building = notre_dame_01 }
            if = { limit = { has_building_or_higher = oath_faithful_building_01 NOT = { has_building = oath_faithful_building_04 } } add_building = oath_faithful_building_04 }
            if = { limit = { has_building_or_higher = oath_poor_building_01 NOT = { has_building = oath_poor_building_04 } } add_building = oath_poor_building_04 }
            if = { limit = { has_building_or_higher = oath_warriors_building_01 NOT = { has_building = oath_warriors_building_04 } } add_building = oath_warriors_building_04 }
            if = { limit = { has_building_or_higher = offas_dyke_01 NOT = { has_building = offas_dyke_01 } } add_building = offas_dyke_01 }
            if = { limit = { has_building_or_higher = orchards_01 NOT = { has_building = orchards_08 } } add_building = orchards_08 }
            if = { limit = { has_building_or_higher = outposts_01 NOT = { has_building = outposts_08 } } add_building = outposts_08 }
            if = { limit = { has_building_or_higher = paddy_fields_01 NOT = { has_building = paddy_fields_08 } } add_building = paddy_fields_08 }
            if = { limit = { has_building_or_higher = pagoda_of_fogong_temple_01 NOT = { has_building = pagoda_of_fogong_temple_01 } } add_building = pagoda_of_fogong_temple_01 }
            if = { limit = { has_building_or_higher = palace_of_aachen_01 NOT = { has_building = palace_of_aachen_01 } } add_building = palace_of_aachen_01 }
            if = { limit = { has_building_or_higher = palace_of_ctesiphon_01 NOT = { has_building = palace_of_ctesiphon_02 } } add_building = palace_of_ctesiphon_02 }
            if = { limit = { has_building_or_higher = palisades_01 NOT = { has_building = palisades_02 } } add_building = palisades_02 }
            if = { limit = { has_building_or_higher = pansjhir_mines_01 NOT = { has_building = pansjhir_mines_04 } } add_building = pansjhir_mines_04 }
            if = { limit = { has_building_or_higher = pastures_01 NOT = { has_building = pastures_08 } } add_building = pastures_08 }
            if = { limit = { has_building_or_higher = peat_quarries_01 NOT = { has_building = peat_quarries_08 } } add_building = peat_quarries_08 }
            if = { limit = { has_building_or_higher = petra_01 NOT = { has_building = petra_01 } } add_building = petra_01 }
            if = { limit = { has_building_or_higher = phnom_dek_mines_01 NOT = { has_building = phnom_dek_mines_04 } } add_building = phnom_dek_mines_04 }
            if = { limit = { has_building_or_higher = phocaea_mines_01 NOT = { has_building = phocaea_mines_04 } } add_building = phocaea_mines_04 }
            if = { limit = { has_building_or_higher = plain_of_jars_01 NOT = { has_building = plain_of_jars_01 } } add_building = plain_of_jars_01 }
            if = { limit = { has_building_or_higher = plantations_01 NOT = { has_building = plantations_08 } } add_building = plantations_08 }
            if = { limit = { has_building_or_higher = po_klong_garai_01 NOT = { has_building = po_klong_garai_01 } } add_building = po_klong_garai_01 }
            if = { limit = { has_building_or_higher = powder_magazine_01 NOT = { has_building = powder_magazine_08 } } add_building = powder_magazine_08 }
            if = { limit = { has_building_or_higher = qanats_01 NOT = { has_building = qanats_08 } } add_building = qanats_08 }
            if = { limit = { has_building_or_higher = qianling_mausoleum_01 NOT = { has_building = qianling_mausoleum_01 } } add_building = qianling_mausoleum_01 }
            if = { limit = { has_building_or_higher = quanzhou_seaport_01 NOT = { has_building = quanzhou_seaport_01 } } add_building = quanzhou_seaport_01 }
            if = { limit = { has_building_or_higher = quarries_01 NOT = { has_building = quarries_08 } } add_building = quarries_08 }
            if = { limit = { has_building_or_higher = rainbow_mountains_01 NOT = { has_building = rainbow_mountains_01 } } add_building = rainbow_mountains_01 }
            if = { limit = { has_building_or_higher = rammelsberg_mines_01 NOT = { has_building = rammelsberg_mines_04 } } add_building = rammelsberg_mines_04 }
            if = { limit = { has_building_or_higher = ramparts_01 NOT = { has_building = ramparts_08 } } add_building = ramparts_08 }
            if = { limit = { has_building_or_higher = ratnapura_mines_01 NOT = { has_building = ratnapura_mines_04 } } add_building = ratnapura_mines_04 }
            if = { limit = { has_building_or_higher = regimental_grounds_01 NOT = { has_building = regimental_grounds_08 } } add_building = regimental_grounds_08 }
            if = { limit = { has_building_or_higher = rock_of_gibraltar_01 NOT = { has_building = rock_of_gibraltar_01 } } add_building = rock_of_gibraltar_01 }
            if = { limit = { has_building_or_higher = roman_wall_of_lugo_01 NOT = { has_building = roman_wall_of_lugo_01 } } add_building = roman_wall_of_lugo_01 }
            if = { limit = { has_building_or_higher = royal_armory_01 NOT = { has_building = royal_armory_03 } } add_building = royal_armory_03 }
            if = { limit = { has_building_or_higher = royal_forest_01 NOT = { has_building = royal_forest_03 } } add_building = royal_forest_03 }
            if = { limit = { has_building_or_higher = royal_garden_01 NOT = { has_building = royal_garden_03 } } add_building = royal_garden_03 }
            if = { limit = { has_building_or_higher = rudnik_mines_01 NOT = { has_building = rudnik_mines_04 } } add_building = rudnik_mines_04 }
            if = { limit = { has_building_or_higher = sacred_pool_01 NOT = { has_building = sacred_pool_08 } } add_building = sacred_pool_08 }
            if = { limit = { has_building_or_higher = sado_mines_01 NOT = { has_building = sado_mines_04 } } add_building = sado_mines_04 }
            if = { limit = { has_building_or_higher = sar_i_sang_mines_01 NOT = { has_building = sar_i_sang_mines_04 } } add_building = sar_i_sang_mines_04 }
            if = { limit = { has_building_or_higher = schwaz_mines_01 NOT = { has_building = schwaz_mines_04 } } add_building = schwaz_mines_04 }
            if = { limit = { has_building_or_higher = scriptorium_01 NOT = { has_building = scriptorium_08 } } add_building = scriptorium_08 }
            if = { limit = { has_building_or_higher = shah_i_zinda_01 NOT = { has_building = shah_i_zinda_02 } } add_building = shah_i_zinda_02 }
            if = { limit = { has_building_or_higher = shaolin_monastery_01 NOT = { has_building = shaolin_monastery_01 } } add_building = shaolin_monastery_01 }
            if = { limit = { has_building_or_higher = shigu_academy_01 NOT = { has_building = shigu_academy_01 } } add_building = shigu_academy_01 }
            if = { limit = { has_building_or_higher = shwedagon_pagoda_01 NOT = { has_building = shwedagon_pagoda_01 } } add_building = shwedagon_pagoda_01 }
            if = { limit = { has_building_or_higher = siderokausia_mines_01 NOT = { has_building = siderokausia_mines_04 } } add_building = siderokausia_mines_04 }
            if = { limit = { has_building_or_higher = siege_works_01 NOT = { has_building = siege_works_03 } } add_building = siege_works_03 }
            if = { limit = { has_building_or_higher = smiths_01 NOT = { has_building = smiths_08 } } add_building = smiths_08 }
            if = { limit = { has_building_or_higher = soltaniyeh_01 NOT = { has_building = soltaniyeh_01 } } add_building = soltaniyeh_01 }
            if = { limit = { has_building_or_higher = somapura_university_01 NOT = { has_building = somapura_university_01 } } add_building = somapura_university_01 }
            if = { limit = { has_building_or_higher = special_greenhouse_01 NOT = { has_building = special_greenhouse_01 } } add_building = special_greenhouse_01 }
            if = { limit = { has_building_or_higher = special_sicilian_parliament_01 NOT = { has_building = special_sicilian_parliament_01 } } add_building = special_sicilian_parliament_01 }
            if = { limit = { has_building_or_higher = spice_plantation_01 NOT = { has_building = spice_plantation_08 } } add_building = spice_plantation_08 }
            if = { limit = { has_building_or_higher = srebrenica_mines_01 NOT = { has_building = srebrenica_mines_04 } } add_building = srebrenica_mines_04 }
            if = { limit = { has_building_or_higher = stables_01 NOT = { has_building = stables_08 } } add_building = stables_08 }
            if = { limit = { has_building_or_higher = stilted_granaries_01 NOT = { has_building = stilted_granaries_04 } } add_building = stilted_granaries_04 }
            if = { limit = { has_building_or_higher = stonehenge_01 NOT = { has_building = stonehenge_01 } } add_building = stonehenge_01 }
            if = { limit = { has_building_or_higher = sumela_monastery_01 NOT = { has_building = sumela_monastery_02 } } add_building = sumela_monastery_02 }
            if = { limit = { has_building_or_higher = sunday_bazaar_01 NOT = { has_building = sunday_bazaar_02 } } add_building = sunday_bazaar_02 }
            if = { limit = { has_building_or_higher = suvarnadvipa_mines_01 NOT = { has_building = suvarnadvipa_mines_04 } } add_building = suvarnadvipa_mines_04 }
            if = { limit = { has_building_or_higher = tada_mines_01 NOT = { has_building = tada_mines_04 } } add_building = tada_mines_04 }
            if = { limit = { has_building_or_higher = taghaza_mines_01 NOT = { has_building = taghaza_mines_04 } } add_building = taghaza_mines_04 }
            if = { limit = { has_building_or_higher = takkeda_mines_01 NOT = { has_building = takkeda_mines_04 } } add_building = takkeda_mines_04 }
            if = { limit = { has_building_or_higher = tax_assessor_01 NOT = { has_building = tax_assessor_03 } } add_building = tax_assessor_03 }
            if = { limit = { has_building_or_higher = temple_01 NOT = { has_building = temple_04 } } add_building = temple_04 }
            if = { limit = { has_building_or_higher = temple_citadel_01 NOT = { has_building = temple_citadel_04 } } add_building = temple_citadel_04 }
            if = { limit = { has_building_or_higher = temple_in_jerusalem_01 NOT = { has_building = temple_in_jerusalem_01 } } add_building = temple_in_jerusalem_01 }
            if = { limit = { has_building_or_higher = temple_of_uppsala_01 NOT = { has_building = temple_of_uppsala_02 } } add_building = temple_of_uppsala_02 }
            if = { limit = { has_building_or_higher = the_colosseum_01 NOT = { has_building = the_colosseum_01 } } add_building = the_colosseum_01 }
            if = { limit = { has_building_or_higher = the_friday_mosque_01 NOT = { has_building = the_friday_mosque_01 } } add_building = the_friday_mosque_01 }
            if = { limit = { has_building_or_higher = the_great_wall_01 NOT = { has_building = the_great_wall_04 } } add_building = the_great_wall_04 }
            if = { limit = { has_building_or_higher = the_pyramids_01 NOT = { has_building = the_pyramids_01 } } add_building = the_pyramids_01 }
            if = { limit = { has_building_or_higher = the_tower_of_london_01 NOT = { has_building = the_tower_of_london_01 } } add_building = the_tower_of_london_01 }
            if = { limit = { has_building_or_higher = theodosian_walls_01 NOT = { has_building = theodosian_walls_01 } } add_building = theodosian_walls_01 }
            if = { limit = { has_building_or_higher = tiantai_monasteries_01 NOT = { has_building = tiantai_monasteries_01 } } add_building = tiantai_monasteries_01 }
            if = { limit = { has_building_or_higher = tomb_of_cyrus_01 NOT = { has_building = tomb_of_cyrus_01 } } add_building = tomb_of_cyrus_01 }
            if = { limit = { has_building_or_higher = tower_of_hercules_01 NOT = { has_building = tower_of_hercules_01 } } add_building = tower_of_hercules_01 }
            if = { limit = { has_building_or_higher = tower_of_silence_01 NOT = { has_building = tower_of_silence_01 } } add_building = tower_of_silence_01 }
            if = { limit = { has_building_or_higher = trepca_mines_01 NOT = { has_building = trepca_mines_04 } } add_building = trepca_mines_04 }
            if = { limit = { has_building_or_higher = tribe_01 NOT = { has_building = tribe_02 } } add_building = tribe_02 }
            if = { limit = { has_building_or_higher = tsushima_mines_01 NOT = { has_building = tsushima_mines_04 } } add_building = tsushima_mines_04 }
            if = { limit = { has_building_or_higher = turda_mines_01 NOT = { has_building = turda_mines_04 } } add_building = turda_mines_04 }
            if = { limit = { has_building_or_higher = vatapi_caves_01 NOT = { has_building = vatapi_caves_01 } } add_building = vatapi_caves_01 }
            if = { limit = { has_building_or_higher = verespatak_mines_01 NOT = { has_building = verespatak_mines_04 } } add_building = verespatak_mines_04 }
            if = { limit = { has_building_or_higher = vihara_halls_01 NOT = { has_building = vihara_halls_08 } } add_building = vihara_halls_08 }
            if = { limit = { has_building_or_higher = visby_ringmur_01 NOT = { has_building = visby_ringmur_01 } } add_building = visby_ringmur_01 }
            if = { limit = { has_building_or_higher = visegrad_castle_01 NOT = { has_building = visegrad_castle_01 } } add_building = visegrad_castle_01 }
            if = { limit = { has_building_or_higher = walls_of_benin_01 NOT = { has_building = walls_of_benin_01 } } add_building = walls_of_benin_01 }
            if = { limit = { has_building_or_higher = walls_of_genoa_01 NOT = { has_building = walls_of_genoa_01 } } add_building = walls_of_genoa_01 }
            if = { limit = { has_building_or_higher = wantilan_01 NOT = { has_building = wantilan_04 } } add_building = wantilan_04 }
            if = { limit = { has_building_or_higher = war_camps_01 NOT = { has_building = war_camps_02 } } add_building = war_camps_02 }
            if = { limit = { has_building_or_higher = warrior_lodges_01 NOT = { has_building = warrior_lodges_08 } } add_building = warrior_lodges_08 }
            if = { limit = { has_building_or_higher = wartburg_01 NOT = { has_building = wartburg_01 } } add_building = wartburg_01 }
            if = { limit = { has_building_or_higher = watchtowers_01 NOT = { has_building = watchtowers_08 } } add_building = watchtowers_08 }
            if = { limit = { has_building_or_higher = water_temples_01 NOT = { has_building = water_temples_04 } } add_building = water_temples_04 }
            if = { limit = { has_building_or_higher = watermills_01 NOT = { has_building = watermills_08 } } add_building = watermills_08 }
            if = { limit = { has_building_or_higher = waterworks_01 NOT = { has_building = waterworks_08 } } add_building = waterworks_08 }
            if = { limit = { has_building_or_higher = wawel_cathedral_01 NOT = { has_building = wawel_cathedral_03 } } add_building = wawel_cathedral_03 }
            if = { limit = { has_building_or_higher = white_deer_grotto_academy_01 NOT = { has_building = white_deer_grotto_academy_01 } } add_building = white_deer_grotto_academy_01 }
            if = { limit = { has_building_or_higher = wind_furnace_01 NOT = { has_building = wind_furnace_08 } } add_building = wind_furnace_08 }
            if = { limit = { has_building_or_higher = windmills_01 NOT = { has_building = windmills_08 } } add_building = windmills_08 }
            if = { limit = { has_building_or_higher = workshops_01 NOT = { has_building = workshops_08 } } add_building = workshops_08 }
            if = { limit = { has_building_or_higher = wudang_mountain_temples_01 NOT = { has_building = wudang_mountain_temples_01 } } add_building = wudang_mountain_temples_01 }
            if = { limit = { has_building_or_higher = wulingyuan_01 NOT = { has_building = wulingyuan_01 } } add_building = wulingyuan_01 }
            if = { limit = { has_building_or_higher = xiuyan_mines_01 NOT = { has_building = xiuyan_mines_04 } } add_building = xiuyan_mines_04 }
            if = { limit = { has_building_or_higher = york_walls_01 NOT = { has_building = york_walls_01 } } add_building = york_walls_01 }
            if = { limit = { has_building_or_higher = yungang_grottoes_01 NOT = { has_building = yungang_grottoes_01 } } add_building = yungang_grottoes_01 }
            if = { limit = { has_building_or_higher = zawar_mines_01 NOT = { has_building = zawar_mines_04 } } add_building = zawar_mines_04 }
        }
    }
}

DI_construct_building_sgui = {
    scope = character # Player Character

    saved_scopes = {
        building_type # Flag of Building Type to construct
    }

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_action_provinces
            save_scope_as = province

            scope:province = {



                if = {
                    limit = {
                        OR = {
                            scope:building_type = flag:city_01
                            scope:building_type = flag:city_02
                            scope:building_type = flag:city_03
                            scope:building_type = flag:city_04
                        }
                        NOT = { has_building_or_higher = city_01 }
                    }
                    set_holding_type = city_holding
                }


                if = {
                    limit = {
                        OR = {
                            scope:building_type = flag:castle_01
                            scope:building_type = flag:castle_02
                            scope:building_type = flag:castle_03
                            scope:building_type = flag:castle_04
                        }
                        NOT = { has_building_or_higher = castle_01 }
                    }
                    set_holding_type = castle_holding
                }


                if = {
                    limit = {
                        OR = {
                            scope:building_type = flag:temple_01
                            scope:building_type = flag:temple_02
                            scope:building_type = flag:temple_03
                            scope:building_type = flag:temple_04
                        }
                        NOT = { has_building_or_higher = temple_01 }
                    }
                    set_holding_type = church_holding
                }


                if = {
                    limit = {
                        OR = {
                            scope:building_type = flag:tribe_01
                            scope:building_type = flag:tribe_02
                        }
                        NOT = { has_building_or_higher = tribe_01 }
                    }
                    set_holding_type = tribal_holding
                }
                switch = {
                    trigger = scope:building_type
                    flag:castle_01 = { add_building = castle_01 }
                    flag:castle_02 = { add_building = castle_02 }
                    flag:castle_03 = { add_building = castle_03 }
                    flag:castle_04 = { add_building = castle_04 }
                    flag:city_01 = { add_building = city_01 }
                    flag:city_02 = { add_building = city_02 }
                    flag:city_03 = { add_building = city_03 }
                    flag:city_04 = { add_building = city_04 }
                    flag:guild_halls_01 = { add_building = guild_halls_01 }
                    flag:guild_halls_02 = { add_building = guild_halls_02 }
                    flag:guild_halls_03 = { add_building = guild_halls_03 }
                    flag:guild_halls_04 = { add_building = guild_halls_04 }
                    flag:guild_halls_05 = { add_building = guild_halls_05 }
                    flag:guild_halls_06 = { add_building = guild_halls_06 }
                    flag:guild_halls_07 = { add_building = guild_halls_07 }
                    flag:guild_halls_08 = { add_building = guild_halls_08 }
                    flag:nomadic_camp_01 = { add_building = nomadic_camp_01 }
                    flag:herder_camp_01 = { add_building = herder_camp_01 }
                    flag:temple_01 = { add_building = temple_01 }
                    flag:temple_02 = { add_building = temple_02 }
                    flag:temple_03 = { add_building = temple_03 }
                    flag:temple_04 = { add_building = temple_04 }
                    flag:scriptorium_01 = { add_building = scriptorium_01 }
                    flag:scriptorium_02 = { add_building = scriptorium_02 }
                    flag:scriptorium_03 = { add_building = scriptorium_03 }
                    flag:scriptorium_04 = { add_building = scriptorium_04 }
                    flag:scriptorium_05 = { add_building = scriptorium_05 }
                    flag:scriptorium_06 = { add_building = scriptorium_06 }
                    flag:scriptorium_07 = { add_building = scriptorium_07 }
                    flag:scriptorium_08 = { add_building = scriptorium_08 }
                    flag:monastic_schools_01 = { add_building = monastic_schools_01 }
                    flag:monastic_schools_02 = { add_building = monastic_schools_02 }
                    flag:monastic_schools_03 = { add_building = monastic_schools_03 }
                    flag:monastic_schools_04 = { add_building = monastic_schools_04 }
                    flag:monastic_schools_05 = { add_building = monastic_schools_05 }
                    flag:monastic_schools_06 = { add_building = monastic_schools_06 }
                    flag:monastic_schools_07 = { add_building = monastic_schools_07 }
                    flag:monastic_schools_08 = { add_building = monastic_schools_08 }
                    flag:megalith_01 = { add_building = megalith_01 }
                    flag:megalith_02 = { add_building = megalith_02 }
                    flag:megalith_03 = { add_building = megalith_03 }
                    flag:megalith_04 = { add_building = megalith_04 }
                    flag:megalith_05 = { add_building = megalith_05 }
                    flag:megalith_06 = { add_building = megalith_06 }
                    flag:megalith_07 = { add_building = megalith_07 }
                    flag:megalith_08 = { add_building = megalith_08 }
                    flag:breweries_01 = { add_building = breweries_01 }
                    flag:breweries_02 = { add_building = breweries_02 }
                    flag:breweries_03 = { add_building = breweries_03 }
                    flag:breweries_04 = { add_building = breweries_04 }
                    flag:breweries_05 = { add_building = breweries_05 }
                    flag:breweries_06 = { add_building = breweries_06 }
                    flag:breweries_07 = { add_building = breweries_07 }
                    flag:breweries_08 = { add_building = breweries_08 }
                    flag:tribe_01 = { add_building = tribe_01 }
                    flag:tribe_02 = { add_building = tribe_02 }
                    flag:longhouses_01 = { add_building = longhouses_01 }
                    flag:longhouses_02 = { add_building = longhouses_02 }
                    flag:war_camps_01 = { add_building = war_camps_01 }
                    flag:war_camps_02 = { add_building = war_camps_02 }
                    flag:palisades_01 = { add_building = palisades_01 }
                    flag:palisades_02 = { add_building = palisades_02 }
                    flag:market_villages_01 = { add_building = market_villages_01 }
                    flag:market_villages_02 = { add_building = market_villages_02 }
                    flag:idjang_forts_01 = { add_building = idjang_forts_01 }
                    flag:idjang_forts_02 = { add_building = idjang_forts_02 }
                    flag:idjang_forts_03 = { add_building = idjang_forts_03 }
                    flag:idjang_forts_04 = { add_building = idjang_forts_04 }
                    flag:wantilan_01 = { add_building = wantilan_01 }
                    flag:wantilan_02 = { add_building = wantilan_02 }
                    flag:wantilan_03 = { add_building = wantilan_03 }
                    flag:wantilan_04 = { add_building = wantilan_04 }
                    flag:kora_kora_yards_01 = { add_building = kora_kora_yards_01 }
                    flag:kora_kora_yards_02 = { add_building = kora_kora_yards_02 }
                    flag:kora_kora_yards_03 = { add_building = kora_kora_yards_03 }
                    flag:kora_kora_yards_04 = { add_building = kora_kora_yards_04 }
                    flag:water_temples_01 = { add_building = water_temples_01 }
                    flag:water_temples_02 = { add_building = water_temples_02 }
                    flag:water_temples_03 = { add_building = water_temples_03 }
                    flag:water_temples_04 = { add_building = water_temples_04 }
                    flag:stilted_granaries_01 = { add_building = stilted_granaries_01 }
                    flag:stilted_granaries_02 = { add_building = stilted_granaries_02 }
                    flag:stilted_granaries_03 = { add_building = stilted_granaries_03 }
                    flag:stilted_granaries_04 = { add_building = stilted_granaries_04 }
                    flag:temple_citadel_01 = { add_building = temple_citadel_01 }
                    flag:temple_citadel_02 = { add_building = temple_citadel_02 }
                    flag:temple_citadel_03 = { add_building = temple_citadel_03 }
                    flag:temple_citadel_04 = { add_building = temple_citadel_04 }
                    flag:citadel_shrine_01 = { add_building = citadel_shrine_01 }
                    flag:citadel_shrine_02 = { add_building = citadel_shrine_02 }
                    flag:citadel_shrine_03 = { add_building = citadel_shrine_03 }
                    flag:citadel_shrine_04 = { add_building = citadel_shrine_04 }
                    flag:citadel_shrine_05 = { add_building = citadel_shrine_05 }
                    flag:citadel_shrine_06 = { add_building = citadel_shrine_06 }
                    flag:citadel_shrine_07 = { add_building = citadel_shrine_07 }
                    flag:citadel_shrine_08 = { add_building = citadel_shrine_08 }
                    flag:sacred_pool_01 = { add_building = sacred_pool_01 }
                    flag:sacred_pool_02 = { add_building = sacred_pool_02 }
                    flag:sacred_pool_03 = { add_building = sacred_pool_03 }
                    flag:sacred_pool_04 = { add_building = sacred_pool_04 }
                    flag:sacred_pool_05 = { add_building = sacred_pool_05 }
                    flag:sacred_pool_06 = { add_building = sacred_pool_06 }
                    flag:sacred_pool_07 = { add_building = sacred_pool_07 }
                    flag:sacred_pool_08 = { add_building = sacred_pool_08 }
                    flag:vihara_halls_01 = { add_building = vihara_halls_01 }
                    flag:vihara_halls_02 = { add_building = vihara_halls_02 }
                    flag:vihara_halls_03 = { add_building = vihara_halls_03 }
                    flag:vihara_halls_04 = { add_building = vihara_halls_04 }
                    flag:vihara_halls_05 = { add_building = vihara_halls_05 }
                    flag:vihara_halls_06 = { add_building = vihara_halls_06 }
                    flag:vihara_halls_07 = { add_building = vihara_halls_07 }
                    flag:vihara_halls_08 = { add_building = vihara_halls_08 }
                    flag:capital_bureau_01 = { add_building = capital_bureau_01 }
                    flag:capital_bureau_02 = { add_building = capital_bureau_02 }
                    flag:capital_bureau_03 = { add_building = capital_bureau_03 }
                    flag:capital_bureau_04 = { add_building = capital_bureau_04 }
                    flag:capital_bureau_05 = { add_building = capital_bureau_05 }
                    flag:capital_bureau_06 = { add_building = capital_bureau_06 }
                    flag:capital_bureau_07 = { add_building = capital_bureau_07 }
                    flag:capital_bureau_08 = { add_building = capital_bureau_08 }
                    flag:hospices_01 = { add_building = hospices_01 }
                    flag:hospices_02 = { add_building = hospices_02 }
                    flag:hospices_03 = { add_building = hospices_03 }
                    flag:hospices_04 = { add_building = hospices_04 }
                    flag:hospices_05 = { add_building = hospices_05 }
                    flag:hospices_06 = { add_building = hospices_06 }
                    flag:hospices_07 = { add_building = hospices_07 }
                    flag:hospices_08 = { add_building = hospices_08 }
                    flag:dragon_kiln_01 = { add_building = dragon_kiln_01 }
                    flag:dragon_kiln_02 = { add_building = dragon_kiln_02 }
                    flag:dragon_kiln_03 = { add_building = dragon_kiln_03 }
                    flag:examination_hall_01 = { add_building = examination_hall_01 }
                    flag:examination_hall_02 = { add_building = examination_hall_02 }
                    flag:examination_hall_03 = { add_building = examination_hall_03 }
                    flag:tower_of_silence_01 = { add_building = tower_of_silence_01 }
                    flag:charnel_grounds_01 = { add_building = charnel_grounds_01 }
                    flag:charnel_grounds_02 = { add_building = charnel_grounds_02 }
                    flag:charnel_grounds_03 = { add_building = charnel_grounds_03 }
                    flag:burial_site_01 = { add_building = burial_site_01 }
                    flag:burial_site_02 = { add_building = burial_site_02 }
                    flag:burial_site_03 = { add_building = burial_site_03 }
                    flag:royal_garden_01 = { add_building = royal_garden_01 }
                    flag:royal_garden_02 = { add_building = royal_garden_02 }
                    flag:royal_garden_03 = { add_building = royal_garden_03 }
                    flag:military_academy_01 = { add_building = military_academy_01 }
                    flag:military_academy_02 = { add_building = military_academy_02 }
                    flag:military_academy_03 = { add_building = military_academy_03 }
                    flag:march_01 = { add_building = march_01 }
                    flag:march_02 = { add_building = march_02 }
                    flag:march_03 = { add_building = march_03 }
                    flag:siege_works_01 = { add_building = siege_works_01 }
                    flag:siege_works_02 = { add_building = siege_works_02 }
                    flag:siege_works_03 = { add_building = siege_works_03 }
                    flag:royal_armory_01 = { add_building = royal_armory_01 }
                    flag:royal_armory_02 = { add_building = royal_armory_02 }
                    flag:royal_armory_03 = { add_building = royal_armory_03 }
                    flag:jousting_lists_01 = { add_building = jousting_lists_01 }
                    flag:jousting_lists_02 = { add_building = jousting_lists_02 }
                    flag:jousting_lists_03 = { add_building = jousting_lists_03 }
                    flag:blacksmiths_01 = { add_building = blacksmiths_01 }
                    flag:blacksmiths_02 = { add_building = blacksmiths_02 }
                    flag:blacksmiths_03 = { add_building = blacksmiths_03 }
                    flag:archery_ranges_01 = { add_building = archery_ranges_01 }
                    flag:archery_ranges_02 = { add_building = archery_ranges_02 }
                    flag:archery_ranges_03 = { add_building = archery_ranges_03 }
                    flag:tax_assessor_01 = { add_building = tax_assessor_01 }
                    flag:tax_assessor_02 = { add_building = tax_assessor_02 }
                    flag:tax_assessor_03 = { add_building = tax_assessor_03 }
                    flag:leisure_palace_01 = { add_building = leisure_palace_01 }
                    flag:leisure_palace_02 = { add_building = leisure_palace_02 }
                    flag:leisure_palace_03 = { add_building = leisure_palace_03 }
                    flag:royal_forest_01 = { add_building = royal_forest_01 }
                    flag:royal_forest_02 = { add_building = royal_forest_02 }
                    flag:royal_forest_03 = { add_building = royal_forest_03 }
                    flag:great_megalith_01 = { add_building = great_megalith_01 }
                    flag:caravanserai_01 = { add_building = caravanserai_01 }
                    flag:caravanserai_02 = { add_building = caravanserai_02 }
                    flag:caravanserai_03 = { add_building = caravanserai_03 }
                    flag:caravanserai_04 = { add_building = caravanserai_04 }
                    flag:caravanserai_05 = { add_building = caravanserai_05 }
                    flag:caravanserai_06 = { add_building = caravanserai_06 }
                    flag:caravanserai_07 = { add_building = caravanserai_07 }
                    flag:caravanserai_08 = { add_building = caravanserai_08 }
                    flag:watermills_01 = { add_building = watermills_01 }
                    flag:watermills_02 = { add_building = watermills_02 }
                    flag:watermills_03 = { add_building = watermills_03 }
                    flag:watermills_04 = { add_building = watermills_04 }
                    flag:watermills_05 = { add_building = watermills_05 }
                    flag:watermills_06 = { add_building = watermills_06 }
                    flag:watermills_07 = { add_building = watermills_07 }
                    flag:watermills_08 = { add_building = watermills_08 }
                    flag:windmills_01 = { add_building = windmills_01 }
                    flag:windmills_02 = { add_building = windmills_02 }
                    flag:windmills_03 = { add_building = windmills_03 }
                    flag:windmills_04 = { add_building = windmills_04 }
                    flag:windmills_05 = { add_building = windmills_05 }
                    flag:windmills_06 = { add_building = windmills_06 }
                    flag:windmills_07 = { add_building = windmills_07 }
                    flag:windmills_08 = { add_building = windmills_08 }
                    flag:qanats_01 = { add_building = qanats_01 }
                    flag:qanats_02 = { add_building = qanats_02 }
                    flag:qanats_03 = { add_building = qanats_03 }
                    flag:qanats_04 = { add_building = qanats_04 }
                    flag:qanats_05 = { add_building = qanats_05 }
                    flag:qanats_06 = { add_building = qanats_06 }
                    flag:qanats_07 = { add_building = qanats_07 }
                    flag:qanats_08 = { add_building = qanats_08 }
                    flag:murex_farm_01 = { add_building = murex_farm_01 }
                    flag:murex_farm_02 = { add_building = murex_farm_02 }
                    flag:murex_farm_03 = { add_building = murex_farm_03 }
                    flag:murex_farm_04 = { add_building = murex_farm_04 }
                    flag:murex_farm_05 = { add_building = murex_farm_05 }
                    flag:murex_farm_06 = { add_building = murex_farm_06 }
                    flag:murex_farm_07 = { add_building = murex_farm_07 }
                    flag:murex_farm_08 = { add_building = murex_farm_08 }
                    flag:paddy_fields_01 = { add_building = paddy_fields_01 }
                    flag:paddy_fields_02 = { add_building = paddy_fields_02 }
                    flag:paddy_fields_03 = { add_building = paddy_fields_03 }
                    flag:paddy_fields_04 = { add_building = paddy_fields_04 }
                    flag:paddy_fields_05 = { add_building = paddy_fields_05 }
                    flag:paddy_fields_06 = { add_building = paddy_fields_06 }
                    flag:paddy_fields_07 = { add_building = paddy_fields_07 }
                    flag:paddy_fields_08 = { add_building = paddy_fields_08 }
                    flag:spice_plantation_01 = { add_building = spice_plantation_01 }
                    flag:spice_plantation_02 = { add_building = spice_plantation_02 }
                    flag:spice_plantation_03 = { add_building = spice_plantation_03 }
                    flag:spice_plantation_04 = { add_building = spice_plantation_04 }
                    flag:spice_plantation_05 = { add_building = spice_plantation_05 }
                    flag:spice_plantation_06 = { add_building = spice_plantation_06 }
                    flag:spice_plantation_07 = { add_building = spice_plantation_07 }
                    flag:spice_plantation_08 = { add_building = spice_plantation_08 }
                    flag:waterworks_01 = { add_building = waterworks_01 }
                    flag:waterworks_02 = { add_building = waterworks_02 }
                    flag:waterworks_03 = { add_building = waterworks_03 }
                    flag:waterworks_04 = { add_building = waterworks_04 }
                    flag:waterworks_05 = { add_building = waterworks_05 }
                    flag:waterworks_06 = { add_building = waterworks_06 }
                    flag:waterworks_07 = { add_building = waterworks_07 }
                    flag:waterworks_08 = { add_building = waterworks_08 }
                    flag:common_tradeport_01 = { add_building = common_tradeport_01 }
                    flag:common_tradeport_02 = { add_building = common_tradeport_02 }
                    flag:common_tradeport_03 = { add_building = common_tradeport_03 }
                    flag:common_tradeport_04 = { add_building = common_tradeport_04 }
                    flag:common_tradeport_05 = { add_building = common_tradeport_05 }
                    flag:common_tradeport_06 = { add_building = common_tradeport_06 }
                    flag:common_tradeport_07 = { add_building = common_tradeport_07 }
                    flag:common_tradeport_08 = { add_building = common_tradeport_08 }
                    flag:pastures_01 = { add_building = pastures_01 }
                    flag:pastures_02 = { add_building = pastures_02 }
                    flag:pastures_03 = { add_building = pastures_03 }
                    flag:pastures_04 = { add_building = pastures_04 }
                    flag:pastures_05 = { add_building = pastures_05 }
                    flag:pastures_06 = { add_building = pastures_06 }
                    flag:pastures_07 = { add_building = pastures_07 }
                    flag:pastures_08 = { add_building = pastures_08 }
                    flag:hunting_grounds_01 = { add_building = hunting_grounds_01 }
                    flag:hunting_grounds_02 = { add_building = hunting_grounds_02 }
                    flag:hunting_grounds_03 = { add_building = hunting_grounds_03 }
                    flag:hunting_grounds_04 = { add_building = hunting_grounds_04 }
                    flag:hunting_grounds_05 = { add_building = hunting_grounds_05 }
                    flag:hunting_grounds_06 = { add_building = hunting_grounds_06 }
                    flag:hunting_grounds_07 = { add_building = hunting_grounds_07 }
                    flag:hunting_grounds_08 = { add_building = hunting_grounds_08 }
                    flag:orchards_01 = { add_building = orchards_01 }
                    flag:orchards_02 = { add_building = orchards_02 }
                    flag:orchards_03 = { add_building = orchards_03 }
                    flag:orchards_04 = { add_building = orchards_04 }
                    flag:orchards_05 = { add_building = orchards_05 }
                    flag:orchards_06 = { add_building = orchards_06 }
                    flag:orchards_07 = { add_building = orchards_07 }
                    flag:orchards_08 = { add_building = orchards_08 }
                    flag:farm_estates_01 = { add_building = farm_estates_01 }
                    flag:farm_estates_02 = { add_building = farm_estates_02 }
                    flag:farm_estates_03 = { add_building = farm_estates_03 }
                    flag:farm_estates_04 = { add_building = farm_estates_04 }
                    flag:farm_estates_05 = { add_building = farm_estates_05 }
                    flag:farm_estates_06 = { add_building = farm_estates_06 }
                    flag:farm_estates_07 = { add_building = farm_estates_07 }
                    flag:farm_estates_08 = { add_building = farm_estates_08 }
                    flag:cereal_fields_01 = { add_building = cereal_fields_01 }
                    flag:cereal_fields_02 = { add_building = cereal_fields_02 }
                    flag:cereal_fields_03 = { add_building = cereal_fields_03 }
                    flag:cereal_fields_04 = { add_building = cereal_fields_04 }
                    flag:cereal_fields_05 = { add_building = cereal_fields_05 }
                    flag:cereal_fields_06 = { add_building = cereal_fields_06 }
                    flag:cereal_fields_07 = { add_building = cereal_fields_07 }
                    flag:cereal_fields_08 = { add_building = cereal_fields_08 }
                    flag:logging_camps_01 = { add_building = logging_camps_01 }
                    flag:logging_camps_02 = { add_building = logging_camps_02 }
                    flag:logging_camps_03 = { add_building = logging_camps_03 }
                    flag:logging_camps_04 = { add_building = logging_camps_04 }
                    flag:logging_camps_05 = { add_building = logging_camps_05 }
                    flag:logging_camps_06 = { add_building = logging_camps_06 }
                    flag:logging_camps_07 = { add_building = logging_camps_07 }
                    flag:logging_camps_08 = { add_building = logging_camps_08 }
                    flag:peat_quarries_01 = { add_building = peat_quarries_01 }
                    flag:peat_quarries_02 = { add_building = peat_quarries_02 }
                    flag:peat_quarries_03 = { add_building = peat_quarries_03 }
                    flag:peat_quarries_04 = { add_building = peat_quarries_04 }
                    flag:peat_quarries_05 = { add_building = peat_quarries_05 }
                    flag:peat_quarries_06 = { add_building = peat_quarries_06 }
                    flag:peat_quarries_07 = { add_building = peat_quarries_07 }
                    flag:peat_quarries_08 = { add_building = peat_quarries_08 }
                    flag:hill_farms_01 = { add_building = hill_farms_01 }
                    flag:hill_farms_02 = { add_building = hill_farms_02 }
                    flag:hill_farms_03 = { add_building = hill_farms_03 }
                    flag:hill_farms_04 = { add_building = hill_farms_04 }
                    flag:hill_farms_05 = { add_building = hill_farms_05 }
                    flag:hill_farms_06 = { add_building = hill_farms_06 }
                    flag:hill_farms_07 = { add_building = hill_farms_07 }
                    flag:hill_farms_08 = { add_building = hill_farms_08 }
                    flag:elephant_pens_01 = { add_building = elephant_pens_01 }
                    flag:elephant_pens_02 = { add_building = elephant_pens_02 }
                    flag:elephant_pens_03 = { add_building = elephant_pens_03 }
                    flag:elephant_pens_04 = { add_building = elephant_pens_04 }
                    flag:elephant_pens_05 = { add_building = elephant_pens_05 }
                    flag:elephant_pens_06 = { add_building = elephant_pens_06 }
                    flag:elephant_pens_07 = { add_building = elephant_pens_07 }
                    flag:elephant_pens_08 = { add_building = elephant_pens_08 }
                    flag:plantations_01 = { add_building = plantations_01 }
                    flag:plantations_02 = { add_building = plantations_02 }
                    flag:plantations_03 = { add_building = plantations_03 }
                    flag:plantations_04 = { add_building = plantations_04 }
                    flag:plantations_05 = { add_building = plantations_05 }
                    flag:plantations_06 = { add_building = plantations_06 }
                    flag:plantations_07 = { add_building = plantations_07 }
                    flag:plantations_08 = { add_building = plantations_08 }
                    flag:quarries_01 = { add_building = quarries_01 }
                    flag:quarries_02 = { add_building = quarries_02 }
                    flag:quarries_03 = { add_building = quarries_03 }
                    flag:quarries_04 = { add_building = quarries_04 }
                    flag:quarries_05 = { add_building = quarries_05 }
                    flag:quarries_06 = { add_building = quarries_06 }
                    flag:quarries_07 = { add_building = quarries_07 }
                    flag:quarries_08 = { add_building = quarries_08 }
                    flag:ramparts_01 = { add_building = ramparts_01 }
                    flag:ramparts_02 = { add_building = ramparts_02 }
                    flag:ramparts_03 = { add_building = ramparts_03 }
                    flag:ramparts_04 = { add_building = ramparts_04 }
                    flag:ramparts_05 = { add_building = ramparts_05 }
                    flag:ramparts_06 = { add_building = ramparts_06 }
                    flag:ramparts_07 = { add_building = ramparts_07 }
                    flag:ramparts_08 = { add_building = ramparts_08 }
                    flag:curtain_walls_01 = { add_building = curtain_walls_01 }
                    flag:curtain_walls_02 = { add_building = curtain_walls_02 }
                    flag:curtain_walls_03 = { add_building = curtain_walls_03 }
                    flag:curtain_walls_04 = { add_building = curtain_walls_04 }
                    flag:curtain_walls_05 = { add_building = curtain_walls_05 }
                    flag:curtain_walls_06 = { add_building = curtain_walls_06 }
                    flag:curtain_walls_07 = { add_building = curtain_walls_07 }
                    flag:curtain_walls_08 = { add_building = curtain_walls_08 }
                    flag:watchtowers_01 = { add_building = watchtowers_01 }
                    flag:watchtowers_02 = { add_building = watchtowers_02 }
                    flag:watchtowers_03 = { add_building = watchtowers_03 }
                    flag:watchtowers_04 = { add_building = watchtowers_04 }
                    flag:watchtowers_05 = { add_building = watchtowers_05 }
                    flag:watchtowers_06 = { add_building = watchtowers_06 }
                    flag:watchtowers_07 = { add_building = watchtowers_07 }
                    flag:watchtowers_08 = { add_building = watchtowers_08 }
                    flag:hill_forts_01 = { add_building = hill_forts_01 }
                    flag:hill_forts_02 = { add_building = hill_forts_02 }
                    flag:hill_forts_03 = { add_building = hill_forts_03 }
                    flag:hill_forts_04 = { add_building = hill_forts_04 }
                    flag:hill_forts_05 = { add_building = hill_forts_05 }
                    flag:hill_forts_06 = { add_building = hill_forts_06 }
                    flag:hill_forts_07 = { add_building = hill_forts_07 }
                    flag:hill_forts_08 = { add_building = hill_forts_08 }
                    flag:wind_furnace_01 = { add_building = wind_furnace_01 }
                    flag:wind_furnace_02 = { add_building = wind_furnace_02 }
                    flag:wind_furnace_03 = { add_building = wind_furnace_03 }
                    flag:wind_furnace_04 = { add_building = wind_furnace_04 }
                    flag:wind_furnace_05 = { add_building = wind_furnace_05 }
                    flag:wind_furnace_06 = { add_building = wind_furnace_06 }
                    flag:wind_furnace_07 = { add_building = wind_furnace_07 }
                    flag:wind_furnace_08 = { add_building = wind_furnace_08 }
                    flag:powder_magazine_01 = { add_building = powder_magazine_01 }
                    flag:powder_magazine_02 = { add_building = powder_magazine_02 }
                    flag:powder_magazine_03 = { add_building = powder_magazine_03 }
                    flag:powder_magazine_04 = { add_building = powder_magazine_04 }
                    flag:powder_magazine_05 = { add_building = powder_magazine_05 }
                    flag:powder_magazine_06 = { add_building = powder_magazine_06 }
                    flag:powder_magazine_07 = { add_building = powder_magazine_07 }
                    flag:powder_magazine_08 = { add_building = powder_magazine_08 }
                    flag:workshops_01 = { add_building = workshops_01 }
                    flag:workshops_02 = { add_building = workshops_02 }
                    flag:workshops_03 = { add_building = workshops_03 }
                    flag:workshops_04 = { add_building = workshops_04 }
                    flag:workshops_05 = { add_building = workshops_05 }
                    flag:workshops_06 = { add_building = workshops_06 }
                    flag:workshops_07 = { add_building = workshops_07 }
                    flag:workshops_08 = { add_building = workshops_08 }
                    flag:horse_pastures_01 = { add_building = horse_pastures_01 }
                    flag:horse_pastures_02 = { add_building = horse_pastures_02 }
                    flag:horse_pastures_03 = { add_building = horse_pastures_03 }
                    flag:horse_pastures_04 = { add_building = horse_pastures_04 }
                    flag:horse_pastures_05 = { add_building = horse_pastures_05 }
                    flag:horse_pastures_06 = { add_building = horse_pastures_06 }
                    flag:horse_pastures_07 = { add_building = horse_pastures_07 }
                    flag:horse_pastures_08 = { add_building = horse_pastures_08 }
                    flag:hillside_grazing_01 = { add_building = hillside_grazing_01 }
                    flag:hillside_grazing_02 = { add_building = hillside_grazing_02 }
                    flag:hillside_grazing_03 = { add_building = hillside_grazing_03 }
                    flag:hillside_grazing_04 = { add_building = hillside_grazing_04 }
                    flag:hillside_grazing_05 = { add_building = hillside_grazing_05 }
                    flag:hillside_grazing_06 = { add_building = hillside_grazing_06 }
                    flag:hillside_grazing_07 = { add_building = hillside_grazing_07 }
                    flag:hillside_grazing_08 = { add_building = hillside_grazing_08 }
                    flag:warrior_lodges_01 = { add_building = warrior_lodges_01 }
                    flag:warrior_lodges_02 = { add_building = warrior_lodges_02 }
                    flag:warrior_lodges_03 = { add_building = warrior_lodges_03 }
                    flag:warrior_lodges_04 = { add_building = warrior_lodges_04 }
                    flag:warrior_lodges_05 = { add_building = warrior_lodges_05 }
                    flag:warrior_lodges_06 = { add_building = warrior_lodges_06 }
                    flag:warrior_lodges_07 = { add_building = warrior_lodges_07 }
                    flag:warrior_lodges_08 = { add_building = warrior_lodges_08 }
                    flag:military_camps_01 = { add_building = military_camps_01 }
                    flag:military_camps_02 = { add_building = military_camps_02 }
                    flag:military_camps_03 = { add_building = military_camps_03 }
                    flag:military_camps_04 = { add_building = military_camps_04 }
                    flag:military_camps_05 = { add_building = military_camps_05 }
                    flag:military_camps_06 = { add_building = military_camps_06 }
                    flag:military_camps_07 = { add_building = military_camps_07 }
                    flag:military_camps_08 = { add_building = military_camps_08 }
                    flag:regimental_grounds_01 = { add_building = regimental_grounds_01 }
                    flag:regimental_grounds_02 = { add_building = regimental_grounds_02 }
                    flag:regimental_grounds_03 = { add_building = regimental_grounds_03 }
                    flag:regimental_grounds_04 = { add_building = regimental_grounds_04 }
                    flag:regimental_grounds_05 = { add_building = regimental_grounds_05 }
                    flag:regimental_grounds_06 = { add_building = regimental_grounds_06 }
                    flag:regimental_grounds_07 = { add_building = regimental_grounds_07 }
                    flag:regimental_grounds_08 = { add_building = regimental_grounds_08 }
                    flag:outposts_01 = { add_building = outposts_01 }
                    flag:outposts_02 = { add_building = outposts_02 }
                    flag:outposts_03 = { add_building = outposts_03 }
                    flag:outposts_04 = { add_building = outposts_04 }
                    flag:outposts_05 = { add_building = outposts_05 }
                    flag:outposts_06 = { add_building = outposts_06 }
                    flag:outposts_07 = { add_building = outposts_07 }
                    flag:outposts_08 = { add_building = outposts_08 }
                    flag:barracks_01 = { add_building = barracks_01 }
                    flag:barracks_02 = { add_building = barracks_02 }
                    flag:barracks_03 = { add_building = barracks_03 }
                    flag:barracks_04 = { add_building = barracks_04 }
                    flag:barracks_05 = { add_building = barracks_05 }
                    flag:barracks_06 = { add_building = barracks_06 }
                    flag:barracks_07 = { add_building = barracks_07 }
                    flag:barracks_08 = { add_building = barracks_08 }
                    flag:camel_farms_01 = { add_building = camel_farms_01 }
                    flag:camel_farms_02 = { add_building = camel_farms_02 }
                    flag:camel_farms_03 = { add_building = camel_farms_03 }
                    flag:camel_farms_04 = { add_building = camel_farms_04 }
                    flag:camel_farms_05 = { add_building = camel_farms_05 }
                    flag:camel_farms_06 = { add_building = camel_farms_06 }
                    flag:camel_farms_07 = { add_building = camel_farms_07 }
                    flag:camel_farms_08 = { add_building = camel_farms_08 }
                    flag:stables_01 = { add_building = stables_01 }
                    flag:stables_02 = { add_building = stables_02 }
                    flag:stables_03 = { add_building = stables_03 }
                    flag:stables_04 = { add_building = stables_04 }
                    flag:stables_05 = { add_building = stables_05 }
                    flag:stables_06 = { add_building = stables_06 }
                    flag:stables_07 = { add_building = stables_07 }
                    flag:stables_08 = { add_building = stables_08 }
                    flag:smiths_01 = { add_building = smiths_01 }
                    flag:smiths_02 = { add_building = smiths_02 }
                    flag:smiths_03 = { add_building = smiths_03 }
                    flag:smiths_04 = { add_building = smiths_04 }
                    flag:smiths_05 = { add_building = smiths_05 }
                    flag:smiths_06 = { add_building = smiths_06 }
                    flag:smiths_07 = { add_building = smiths_07 }
                    flag:smiths_08 = { add_building = smiths_08 }
                    flag:oath_warriors_building_01 = { add_building = oath_warriors_building_01 }
                    flag:oath_warriors_building_02 = { add_building = oath_warriors_building_02 }
                    flag:oath_warriors_building_03 = { add_building = oath_warriors_building_03 }
                    flag:oath_warriors_building_04 = { add_building = oath_warriors_building_04 }
                    flag:oath_faithful_building_01 = { add_building = oath_faithful_building_01 }
                    flag:oath_faithful_building_02 = { add_building = oath_faithful_building_02 }
                    flag:oath_faithful_building_03 = { add_building = oath_faithful_building_03 }
                    flag:oath_faithful_building_04 = { add_building = oath_faithful_building_04 }
                    flag:oath_poor_building_01 = { add_building = oath_poor_building_01 }
                    flag:oath_poor_building_02 = { add_building = oath_poor_building_02 }
                    flag:oath_poor_building_03 = { add_building = oath_poor_building_03 }
                    flag:oath_poor_building_04 = { add_building = oath_poor_building_04 }
                    flag:mandala_capital_01 = { add_building = mandala_capital_01 }
                    flag:mandala_capital_02 = { add_building = mandala_capital_02 }
                    flag:mandala_capital_03 = { add_building = mandala_capital_03 }
                    flag:mandala_capital_04 = { add_building = mandala_capital_04 }
                    flag:mandala_capital_05 = { add_building = mandala_capital_05 }
                    flag:celestial_great_barracks_01 = { add_building = celestial_great_barracks_01 }
                    flag:the_great_wall_01 = { add_building = the_great_wall_01 }
                    flag:the_great_wall_02 = { add_building = the_great_wall_02 }
                    flag:the_great_wall_03 = { add_building = the_great_wall_03 }
                    flag:the_great_wall_04 = { add_building = the_great_wall_04 }
                    flag:holy_site_cathedral_01 = { add_building = holy_site_cathedral_01 }
                    flag:holy_site_mosque_01 = { add_building = holy_site_mosque_01 }
                    flag:holy_site_fire_temple_01 = { add_building = holy_site_fire_temple_01 }
                    flag:holy_site_pagan_grand_temple_01 = { add_building = holy_site_pagan_grand_temple_01 }
                    flag:holy_site_indian_grand_temple_01 = { add_building = holy_site_indian_grand_temple_01 }
                    flag:holy_site_buddhist_grand_temple_01 = { add_building = holy_site_buddhist_grand_temple_01 }
                    flag:holy_site_japanese_temple_01 = { add_building = holy_site_japanese_temple_01 }
                    flag:holy_site_chinese_temple_01 = { add_building = holy_site_chinese_temple_01 }
                    flag:holy_site_se_asia_pagan_temple_01 = { add_building = holy_site_se_asia_pagan_temple_01 }
                    flag:holy_site_other_grand_temple_01 = { add_building = holy_site_other_grand_temple_01 }
                    flag:holy_site_mahabodhi_temple_01 = { add_building = holy_site_mahabodhi_temple_01 }
                    flag:holy_site_imam_ali_mosque_01 = { add_building = holy_site_imam_ali_mosque_01 }
                    flag:holy_site_great_mosque_of_mecca_01 = { add_building = holy_site_great_mosque_of_mecca_01 }
                    flag:holy_site_great_mosque_of_cordoba_01 = { add_building = holy_site_great_mosque_of_cordoba_01 }
                    flag:holy_site_great_mosque_of_djenne_01 = { add_building = holy_site_great_mosque_of_djenne_01 }
                    flag:holy_site_great_mosque_of_samarra_01 = { add_building = holy_site_great_mosque_of_samarra_01 }
                    flag:holy_site_cologne_cathedral_01 = { add_building = holy_site_cologne_cathedral_01 }
                    flag:holy_site_canterbury_cathedral_01 = { add_building = holy_site_canterbury_cathedral_01 }
                    flag:holy_site_canterbury_cathedral_02 = { add_building = holy_site_canterbury_cathedral_02 }
                    flag:holy_site_canterbury_cathedral_03 = { add_building = holy_site_canterbury_cathedral_03 }
                    flag:holy_site_prophetic_mosque_01 = { add_building = holy_site_prophetic_mosque_01 }
                    flag:doges_palace_01 = { add_building = doges_palace_01 }
                    flag:walls_of_genoa_01 = { add_building = walls_of_genoa_01 }
                    flag:visby_ringmur_01 = { add_building = visby_ringmur_01 }
                    flag:walls_of_benin_01 = { add_building = walls_of_benin_01 }
                    flag:theodosian_walls_01 = { add_building = theodosian_walls_01 }
                    flag:aurelian_walls_01 = { add_building = aurelian_walls_01 }
                    flag:the_colosseum_01 = { add_building = the_colosseum_01 }
                    flag:iron_pillar_of_delhi_01 = { add_building = iron_pillar_of_delhi_01 }
                    flag:iron_pillar_of_dhar_01 = { add_building = iron_pillar_of_dhar_01 }
                    flag:the_pyramids_01 = { add_building = the_pyramids_01 }
                    flag:stonehenge_01 = { add_building = stonehenge_01 }
                    flag:offas_dyke_01 = { add_building = offas_dyke_01 }
                    flag:hadrians_wall_01 = { add_building = hadrians_wall_01 }
                    flag:petra_01 = { add_building = petra_01 }
                    flag:buddhas_of_bamian_01 = { add_building = buddhas_of_bamian_01 }
                    flag:alhambra_01 = { add_building = alhambra_01 }
                    flag:alhambra_02 = { add_building = alhambra_02 }
                    flag:citadel_of_aleppo_01 = { add_building = citadel_of_aleppo_01 }
                    flag:citadel_of_aleppo_02 = { add_building = citadel_of_aleppo_02 }
                    flag:house_of_wisdom_01 = { add_building = house_of_wisdom_01 }
                    flag:the_tower_of_london_01 = { add_building = the_tower_of_london_01 }
                    flag:london_bridge_01 = { add_building = london_bridge_01 }
                    flag:notre_dame_01 = { add_building = notre_dame_01 }
                    flag:brihadeeswarar_temple_01 = { add_building = brihadeeswarar_temple_01 }
                    flag:shwedagon_pagoda_01 = { add_building = shwedagon_pagoda_01 }
                    flag:ananda_temple_01 = { add_building = ananda_temple_01 }
                    flag:the_friday_mosque_01 = { add_building = the_friday_mosque_01 }
                    flag:khajuraho_01 = { add_building = khajuraho_01 }
                    flag:palace_of_aachen_01 = { add_building = palace_of_aachen_01 }
                    flag:hagia_sophia_01 = { add_building = hagia_sophia_01 }
                    flag:hagia_sophia_02 = { add_building = hagia_sophia_02 }
                    flag:dome_of_the_rock_01 = { add_building = dome_of_the_rock_01 }
                    flag:temple_in_jerusalem_01 = { add_building = temple_in_jerusalem_01 }
                    flag:hall_of_heroes_01 = { add_building = hall_of_heroes_01 }
                    flag:hall_of_heroes_02 = { add_building = hall_of_heroes_02 }
                    flag:hall_of_heroes_03 = { add_building = hall_of_heroes_03 }
                    flag:hall_of_heroes_04 = { add_building = hall_of_heroes_04 }
                    flag:hall_of_heroes_05 = { add_building = hall_of_heroes_05 }
                    flag:special_sicilian_parliament_01 = { add_building = special_sicilian_parliament_01 }
                    flag:special_greenhouse_01 = { add_building = special_greenhouse_01 }
                    flag:hotin_fort_01 = { add_building = hotin_fort_01 }
                    flag:hotin_fort_02 = { add_building = hotin_fort_02 }
                    flag:golden_gate_of_kiev_01 = { add_building = golden_gate_of_kiev_01 }
                    flag:heddal_stave_church_01 = { add_building = heddal_stave_church_01 }
                    flag:temple_of_uppsala_01 = { add_building = temple_of_uppsala_01 }
                    flag:temple_of_uppsala_02 = { add_building = temple_of_uppsala_02 }
                    flag:lund_cathedral_01 = { add_building = lund_cathedral_01 }
                    flag:danevirke_01 = { add_building = danevirke_01 }
                    flag:roman_wall_of_lugo_01 = { add_building = roman_wall_of_lugo_01 }
                    flag:rock_of_gibraltar_01 = { add_building = rock_of_gibraltar_01 }
                    flag:aljaferia_palace_01 = { add_building = aljaferia_palace_01 }
                    flag:tower_of_hercules_01 = { add_building = tower_of_hercules_01 }
                    flag:city_wall_of_toledo_01 = { add_building = city_wall_of_toledo_01 }
                    flag:alcazar_of_segovia_01 = { add_building = alcazar_of_segovia_01 }
                    flag:holy_site_basilica_santiago_01 = { add_building = holy_site_basilica_santiago_01 }
                    flag:imam_reza_shrine_01 = { add_building = imam_reza_shrine_01 }
                    flag:soltaniyeh_01 = { add_building = soltaniyeh_01 }
                    flag:palace_of_ctesiphon_01 = { add_building = palace_of_ctesiphon_01 }
                    flag:palace_of_ctesiphon_02 = { add_building = palace_of_ctesiphon_02 }
                    flag:falak_ol_aflak_citadel_01 = { add_building = falak_ol_aflak_citadel_01 }
                    flag:minarets_and_remains_of_jam_01 = { add_building = minarets_and_remains_of_jam_01 }
                    flag:great_wall_of_gorgan_01 = { add_building = great_wall_of_gorgan_01 }
                    flag:maharloo_lake_01 = { add_building = maharloo_lake_01 }
                    flag:rainbow_mountains_01 = { add_building = rainbow_mountains_01 }
                    flag:mount_damavand_01 = { add_building = mount_damavand_01 }
                    flag:tomb_of_cyrus_01 = { add_building = tomb_of_cyrus_01 }
                    flag:ark_of_bukhara_01 = { add_building = ark_of_bukhara_01 }
                    flag:shah_i_zinda_01 = { add_building = shah_i_zinda_01 }
                    flag:shah_i_zinda_02 = { add_building = shah_i_zinda_02 }
                    flag:alamut_castle_01 = { add_building = alamut_castle_01 }
                    flag:alamut_castle_02 = { add_building = alamut_castle_02 }
                    flag:assassin_castle_01 = { add_building = assassin_castle_01 }
                    flag:event_tower_of_silence_01 = { add_building = event_tower_of_silence_01 }
                    flag:sumela_monastery_01 = { add_building = sumela_monastery_01 }
                    flag:sumela_monastery_02 = { add_building = sumela_monastery_02 }
                    flag:meteora_01 = { add_building = meteora_01 }
                    flag:meteora_02 = { add_building = meteora_02 }
                    flag:mount_athos_01 = { add_building = mount_athos_01 }
                    flag:mount_athos_02 = { add_building = mount_athos_02 }
                    flag:mount_athos_03 = { add_building = mount_athos_03 }
                    flag:burkhan_khaldun_01 = { add_building = burkhan_khaldun_01 }
                    flag:wulingyuan_01 = { add_building = wulingyuan_01 }
                    flag:leshan_giant_buddha_01 = { add_building = leshan_giant_buddha_01 }
                    flag:yungang_grottoes_01 = { add_building = yungang_grottoes_01 }
                    flag:wudang_mountain_temples_01 = { add_building = wudang_mountain_temples_01 }
                    flag:shaolin_monastery_01 = { add_building = shaolin_monastery_01 }
                    flag:lingyin_temple_01 = { add_building = lingyin_temple_01 }
                    flag:giant_wild_goose_pagoda_01 = { add_building = giant_wild_goose_pagoda_01 }
                    flag:kaifeng_palace_01 = { add_building = kaifeng_palace_01 }
                    flag:forbidden_city_01 = { add_building = forbidden_city_01 }
                    flag:qianling_mausoleum_01 = { add_building = qianling_mausoleum_01 }
                    flag:quanzhou_seaport_01 = { add_building = quanzhou_seaport_01 }
                    flag:angkor_wat_01 = { add_building = angkor_wat_01 }
                    flag:citadel_thang_long_01 = { add_building = citadel_thang_long_01 }
                    flag:citadel_thang_long_02 = { add_building = citadel_thang_long_02 }
                    flag:po_klong_garai_01 = { add_building = po_klong_garai_01 }
                    flag:krakatoa_01 = { add_building = krakatoa_01 }
                    flag:borobudur_01 = { add_building = borobudur_01 }
                    flag:hoshi_ryokan_01 = { add_building = hoshi_ryokan_01 }
                    flag:herat_bazaar_01 = { add_building = herat_bazaar_01 }
                    flag:herat_bazaar_02 = { add_building = herat_bazaar_02 }
                    flag:dvin_shuka_01 = { add_building = dvin_shuka_01 }
                    flag:dvin_shuka_02 = { add_building = dvin_shuka_02 }
                    flag:lhasa_market_01 = { add_building = lhasa_market_01 }
                    flag:lhasa_market_02 = { add_building = lhasa_market_02 }
                    flag:khiva_bazaar_01 = { add_building = khiva_bazaar_01 }
                    flag:khiva_bazaar_02 = { add_building = khiva_bazaar_02 }
                    flag:changan_market_01 = { add_building = changan_market_01 }
                    flag:changan_market_02 = { add_building = changan_market_02 }
                    flag:lahur_bazaar_01 = { add_building = lahur_bazaar_01 }
                    flag:lahur_bazaar_02 = { add_building = lahur_bazaar_02 }
                    flag:hamadan_bazaar_01 = { add_building = hamadan_bazaar_01 }
                    flag:hamadan_bazaar_02 = { add_building = hamadan_bazaar_02 }
                    flag:dunhuang_market_01 = { add_building = dunhuang_market_01 }
                    flag:dunhuang_market_02 = { add_building = dunhuang_market_02 }
                    flag:sunday_bazaar_01 = { add_building = sunday_bazaar_01 }
                    flag:sunday_bazaar_02 = { add_building = sunday_bazaar_02 }
                    flag:mount_fuji_01 = { add_building = mount_fuji_01 }
                    flag:itsukushima_jinja_01 = { add_building = itsukushima_jinja_01 }
                    flag:itsukushima_jinja_02 = { add_building = itsukushima_jinja_02 }
                    flag:heian_palace_01 = { add_building = heian_palace_01 }
                    flag:ise_jingu_01 = { add_building = ise_jingu_01 }
                    flag:kofuku_ji_01 = { add_building = kofuku_ji_01 }
                    flag:enryaku_ji_01 = { add_building = enryaku_ji_01 }
                    flag:dazaifu_01 = { add_building = dazaifu_01 }
                    flag:chinjufu_01 = { add_building = chinjufu_01 }
                    flag:hakata_port_01 = { add_building = hakata_port_01 }
                    flag:hakata_port_02 = { add_building = hakata_port_02 }
                    flag:hwangnyongsa_01 = { add_building = hwangnyongsa_01 }
                    flag:byeokran_port_01 = { add_building = byeokran_port_01 }
                    flag:mount_baekdu_01 = { add_building = mount_baekdu_01 }
                    flag:dau_temple_01 = { add_building = dau_temple_01 }
                    flag:liuhe_pagoda_01 = { add_building = liuhe_pagoda_01 }
                    flag:muaro_jambi_01 = { add_building = muaro_jambi_01 }
                    flag:hanging_temple_01 = { add_building = hanging_temple_01 }
                    flag:pagoda_of_fogong_temple_01 = { add_building = pagoda_of_fogong_temple_01 }
                    flag:plain_of_jars_01 = { add_building = plain_of_jars_01 }
                    flag:dieng_plateau_01 = { add_building = dieng_plateau_01 }
                    flag:mount_apo_01 = { add_building = mount_apo_01 }
                    flag:besakih_temple_01 = { add_building = besakih_temple_01 }
                    flag:gongsanseong_fortress_01 = { add_building = gongsanseong_fortress_01 }
                    flag:white_deer_grotto_academy_01 = { add_building = white_deer_grotto_academy_01 }
                    flag:shigu_academy_01 = { add_building = shigu_academy_01 }
                    flag:culai_academy_01 = { add_building = culai_academy_01 }
                    flag:lize_academy_01 = { add_building = lize_academy_01 }
                    flag:maoshan_academy_01 = { add_building = maoshan_academy_01 }
                    flag:tiantai_monasteries_01 = { add_building = tiantai_monasteries_01 }
                    flag:jizu_shan_temples_01 = { add_building = jizu_shan_temples_01 }
                    flag:nanhua_temple_01 = { add_building = nanhua_temple_01 }
                    flag:generic_copper_mines_01 = { add_building = generic_copper_mines_01 }
                    flag:generic_copper_mines_02 = { add_building = generic_copper_mines_02 }
                    flag:generic_copper_mines_03 = { add_building = generic_copper_mines_03 }
                    flag:generic_copper_mines_04 = { add_building = generic_copper_mines_04 }
                    flag:generic_silver_mines_01 = { add_building = generic_silver_mines_01 }
                    flag:generic_silver_mines_02 = { add_building = generic_silver_mines_02 }
                    flag:generic_silver_mines_03 = { add_building = generic_silver_mines_03 }
                    flag:generic_silver_mines_04 = { add_building = generic_silver_mines_04 }
                    flag:generic_gold_mines_01 = { add_building = generic_gold_mines_01 }
                    flag:generic_gold_mines_02 = { add_building = generic_gold_mines_02 }
                    flag:generic_gold_mines_03 = { add_building = generic_gold_mines_03 }
                    flag:generic_gold_mines_04 = { add_building = generic_gold_mines_04 }
                    flag:rammelsberg_mines_01 = { add_building = rammelsberg_mines_01 }
                    flag:rammelsberg_mines_02 = { add_building = rammelsberg_mines_02 }
                    flag:rammelsberg_mines_03 = { add_building = rammelsberg_mines_03 }
                    flag:rammelsberg_mines_04 = { add_building = rammelsberg_mines_04 }
                    flag:kutna_hora_mines_01 = { add_building = kutna_hora_mines_01 }
                    flag:kutna_hora_mines_02 = { add_building = kutna_hora_mines_02 }
                    flag:kutna_hora_mines_03 = { add_building = kutna_hora_mines_03 }
                    flag:kutna_hora_mines_04 = { add_building = kutna_hora_mines_04 }
                    flag:kremnica_mines_01 = { add_building = kremnica_mines_01 }
                    flag:kremnica_mines_02 = { add_building = kremnica_mines_02 }
                    flag:kremnica_mines_03 = { add_building = kremnica_mines_03 }
                    flag:kremnica_mines_04 = { add_building = kremnica_mines_04 }
                    flag:falun_mines_01 = { add_building = falun_mines_01 }
                    flag:falun_mines_02 = { add_building = falun_mines_02 }
                    flag:falun_mines_03 = { add_building = falun_mines_03 }
                    flag:falun_mines_04 = { add_building = falun_mines_04 }
                    flag:schwaz_mines_01 = { add_building = schwaz_mines_01 }
                    flag:schwaz_mines_02 = { add_building = schwaz_mines_02 }
                    flag:schwaz_mines_03 = { add_building = schwaz_mines_03 }
                    flag:schwaz_mines_04 = { add_building = schwaz_mines_04 }
                    flag:argentiera_mines_01 = { add_building = argentiera_mines_01 }
                    flag:argentiera_mines_02 = { add_building = argentiera_mines_02 }
                    flag:argentiera_mines_03 = { add_building = argentiera_mines_03 }
                    flag:argentiera_mines_04 = { add_building = argentiera_mines_04 }
                    flag:kollur_mines_01 = { add_building = kollur_mines_01 }
                    flag:kollur_mines_02 = { add_building = kollur_mines_02 }
                    flag:kollur_mines_03 = { add_building = kollur_mines_03 }
                    flag:kollur_mines_04 = { add_building = kollur_mines_04 }
                    flag:siderokausia_mines_01 = { add_building = siderokausia_mines_01 }
                    flag:siderokausia_mines_02 = { add_building = siderokausia_mines_02 }
                    flag:siderokausia_mines_03 = { add_building = siderokausia_mines_03 }
                    flag:siderokausia_mines_04 = { add_building = siderokausia_mines_04 }
                    flag:mali_mines_01 = { add_building = mali_mines_01 }
                    flag:mali_mines_02 = { add_building = mali_mines_02 }
                    flag:mali_mines_03 = { add_building = mali_mines_03 }
                    flag:mali_mines_04 = { add_building = mali_mines_04 }
                    flag:konasamudram_mines_01 = { add_building = konasamudram_mines_01 }
                    flag:konasamudram_mines_02 = { add_building = konasamudram_mines_02 }
                    flag:konasamudram_mines_03 = { add_building = konasamudram_mines_03 }
                    flag:konasamudram_mines_04 = { add_building = konasamudram_mines_04 }
                    flag:dean_mines_01 = { add_building = dean_mines_01 }
                    flag:dean_mines_02 = { add_building = dean_mines_02 }
                    flag:dean_mines_03 = { add_building = dean_mines_03 }
                    flag:dean_mines_04 = { add_building = dean_mines_04 }
                    flag:phnom_dek_mines_01 = { add_building = phnom_dek_mines_01 }
                    flag:phnom_dek_mines_02 = { add_building = phnom_dek_mines_02 }
                    flag:phnom_dek_mines_03 = { add_building = phnom_dek_mines_03 }
                    flag:phnom_dek_mines_04 = { add_building = phnom_dek_mines_04 }
                    flag:zawar_mines_01 = { add_building = zawar_mines_01 }
                    flag:zawar_mines_02 = { add_building = zawar_mines_02 }
                    flag:zawar_mines_03 = { add_building = zawar_mines_03 }
                    flag:zawar_mines_04 = { add_building = zawar_mines_04 }
                    flag:takkeda_mines_01 = { add_building = takkeda_mines_01 }
                    flag:takkeda_mines_02 = { add_building = takkeda_mines_02 }
                    flag:takkeda_mines_03 = { add_building = takkeda_mines_03 }
                    flag:takkeda_mines_04 = { add_building = takkeda_mines_04 }
                    flag:khetri_mines_01 = { add_building = khetri_mines_01 }
                    flag:khetri_mines_02 = { add_building = khetri_mines_02 }
                    flag:khetri_mines_03 = { add_building = khetri_mines_03 }
                    flag:khetri_mines_04 = { add_building = khetri_mines_04 }
                    flag:taghaza_mines_01 = { add_building = taghaza_mines_01 }
                    flag:taghaza_mines_02 = { add_building = taghaza_mines_02 }
                    flag:taghaza_mines_03 = { add_building = taghaza_mines_03 }
                    flag:taghaza_mines_04 = { add_building = taghaza_mines_04 }
                    flag:ijil_mines_01 = { add_building = ijil_mines_01 }
                    flag:ijil_mines_02 = { add_building = ijil_mines_02 }
                    flag:ijil_mines_03 = { add_building = ijil_mines_03 }
                    flag:ijil_mines_04 = { add_building = ijil_mines_04 }
                    flag:turda_mines_01 = { add_building = turda_mines_01 }
                    flag:turda_mines_02 = { add_building = turda_mines_02 }
                    flag:turda_mines_03 = { add_building = turda_mines_03 }
                    flag:turda_mines_04 = { add_building = turda_mines_04 }
                    flag:phocaea_mines_01 = { add_building = phocaea_mines_01 }
                    flag:phocaea_mines_02 = { add_building = phocaea_mines_02 }
                    flag:phocaea_mines_03 = { add_building = phocaea_mines_03 }
                    flag:phocaea_mines_04 = { add_building = phocaea_mines_04 }
                    flag:pansjhir_mines_01 = { add_building = pansjhir_mines_01 }
                    flag:pansjhir_mines_02 = { add_building = pansjhir_mines_02 }
                    flag:pansjhir_mines_03 = { add_building = pansjhir_mines_03 }
                    flag:pansjhir_mines_04 = { add_building = pansjhir_mines_04 }
                    flag:trepca_mines_01 = { add_building = trepca_mines_01 }
                    flag:trepca_mines_02 = { add_building = trepca_mines_02 }
                    flag:trepca_mines_03 = { add_building = trepca_mines_03 }
                    flag:trepca_mines_04 = { add_building = trepca_mines_04 }
                    flag:rudnik_mines_01 = { add_building = rudnik_mines_01 }
                    flag:rudnik_mines_02 = { add_building = rudnik_mines_02 }
                    flag:rudnik_mines_03 = { add_building = rudnik_mines_03 }
                    flag:rudnik_mines_04 = { add_building = rudnik_mines_04 }
                    flag:cevennes_mines_01 = { add_building = cevennes_mines_01 }
                    flag:cevennes_mines_02 = { add_building = cevennes_mines_02 }
                    flag:cevennes_mines_03 = { add_building = cevennes_mines_03 }
                    flag:cevennes_mines_04 = { add_building = cevennes_mines_04 }
                    flag:hetian_mines_01 = { add_building = hetian_mines_01 }
                    flag:hetian_mines_02 = { add_building = hetian_mines_02 }
                    flag:hetian_mines_03 = { add_building = hetian_mines_03 }
                    flag:hetian_mines_04 = { add_building = hetian_mines_04 }
                    flag:dushan_mines_01 = { add_building = dushan_mines_01 }
                    flag:dushan_mines_02 = { add_building = dushan_mines_02 }
                    flag:dushan_mines_03 = { add_building = dushan_mines_03 }
                    flag:dushan_mines_04 = { add_building = dushan_mines_04 }
                    flag:xiuyan_mines_01 = { add_building = xiuyan_mines_01 }
                    flag:xiuyan_mines_02 = { add_building = xiuyan_mines_02 }
                    flag:xiuyan_mines_03 = { add_building = xiuyan_mines_03 }
                    flag:xiuyan_mines_04 = { add_building = xiuyan_mines_04 }
                    flag:itoigawa_mines_01 = { add_building = itoigawa_mines_01 }
                    flag:itoigawa_mines_02 = { add_building = itoigawa_mines_02 }
                    flag:itoigawa_mines_03 = { add_building = itoigawa_mines_03 }
                    flag:itoigawa_mines_04 = { add_building = itoigawa_mines_04 }
                    flag:lantian_mines_01 = { add_building = lantian_mines_01 }
                    flag:lantian_mines_02 = { add_building = lantian_mines_02 }
                    flag:lantian_mines_03 = { add_building = lantian_mines_03 }
                    flag:lantian_mines_04 = { add_building = lantian_mines_04 }
                    flag:fengtian_mines_01 = { add_building = fengtian_mines_01 }
                    flag:fengtian_mines_02 = { add_building = fengtian_mines_02 }
                    flag:fengtian_mines_03 = { add_building = fengtian_mines_03 }
                    flag:hpakant_mines_01 = { add_building = hpakant_mines_01 }
                    flag:hpakant_mines_02 = { add_building = hpakant_mines_02 }
                    flag:hpakant_mines_03 = { add_building = hpakant_mines_03 }
                    flag:hpakant_mines_04 = { add_building = hpakant_mines_04 }
                    flag:allaq_mines_01 = { add_building = allaq_mines_01 }
                    flag:allaq_mines_02 = { add_building = allaq_mines_02 }
                    flag:allaq_mines_03 = { add_building = allaq_mines_03 }
                    flag:allaq_mines_04 = { add_building = allaq_mines_04 }
                    flag:verespatak_mines_01 = { add_building = verespatak_mines_01 }
                    flag:verespatak_mines_02 = { add_building = verespatak_mines_02 }
                    flag:verespatak_mines_03 = { add_building = verespatak_mines_03 }
                    flag:verespatak_mines_04 = { add_building = verespatak_mines_04 }
                    flag:suvarnadvipa_mines_01 = { add_building = suvarnadvipa_mines_01 }
                    flag:suvarnadvipa_mines_02 = { add_building = suvarnadvipa_mines_02 }
                    flag:suvarnadvipa_mines_03 = { add_building = suvarnadvipa_mines_03 }
                    flag:suvarnadvipa_mines_04 = { add_building = suvarnadvipa_mines_04 }
                    flag:nishapur_mines_01 = { add_building = nishapur_mines_01 }
                    flag:nishapur_mines_02 = { add_building = nishapur_mines_02 }
                    flag:nishapur_mines_03 = { add_building = nishapur_mines_03 }
                    flag:nishapur_mines_04 = { add_building = nishapur_mines_04 }
                    flag:srebrenica_mines_01 = { add_building = srebrenica_mines_01 }
                    flag:srebrenica_mines_02 = { add_building = srebrenica_mines_02 }
                    flag:srebrenica_mines_03 = { add_building = srebrenica_mines_03 }
                    flag:srebrenica_mines_04 = { add_building = srebrenica_mines_04 }
                    flag:ratnapura_mines_01 = { add_building = ratnapura_mines_01 }
                    flag:ratnapura_mines_02 = { add_building = ratnapura_mines_02 }
                    flag:ratnapura_mines_03 = { add_building = ratnapura_mines_03 }
                    flag:ratnapura_mines_04 = { add_building = ratnapura_mines_04 }
                    flag:sar_i_sang_mines_01 = { add_building = sar_i_sang_mines_01 }
                    flag:sar_i_sang_mines_02 = { add_building = sar_i_sang_mines_02 }
                    flag:sar_i_sang_mines_03 = { add_building = sar_i_sang_mines_03 }
                    flag:sar_i_sang_mines_04 = { add_building = sar_i_sang_mines_04 }
                    flag:mogok_mines_01 = { add_building = mogok_mines_01 }
                    flag:mogok_mines_02 = { add_building = mogok_mines_02 }
                    flag:mogok_mines_03 = { add_building = mogok_mines_03 }
                    flag:mogok_mines_04 = { add_building = mogok_mines_04 }
                    flag:koganeyama_mines_01 = { add_building = koganeyama_mines_01 }
                    flag:koganeyama_mines_02 = { add_building = koganeyama_mines_02 }
                    flag:koganeyama_mines_03 = { add_building = koganeyama_mines_03 }
                    flag:koganeyama_mines_04 = { add_building = koganeyama_mines_04 }
                    flag:tsushima_mines_01 = { add_building = tsushima_mines_01 }
                    flag:tsushima_mines_02 = { add_building = tsushima_mines_02 }
                    flag:tsushima_mines_03 = { add_building = tsushima_mines_03 }
                    flag:tsushima_mines_04 = { add_building = tsushima_mines_04 }
                    flag:sado_mines_01 = { add_building = sado_mines_01 }
                    flag:sado_mines_02 = { add_building = sado_mines_02 }
                    flag:sado_mines_03 = { add_building = sado_mines_03 }
                    flag:sado_mines_04 = { add_building = sado_mines_04 }
                    flag:tada_mines_01 = { add_building = tada_mines_01 }
                    flag:tada_mines_02 = { add_building = tada_mines_02 }
                    flag:tada_mines_03 = { add_building = tada_mines_03 }
                    flag:tada_mines_04 = { add_building = tada_mines_04 }
                    flag:drassanes_01 = { add_building = drassanes_01 }
                    flag:kyz_kala_01 = { add_building = kyz_kala_01 }
                    flag:cluny_abbey_01 = { add_building = cluny_abbey_01 }
                    flag:cluny_abbey_02 = { add_building = cluny_abbey_02 }
                    flag:york_walls_01 = { add_building = york_walls_01 }
                    flag:damascus_mosque_01 = { add_building = damascus_mosque_01 }
                    flag:jokhang_01 = { add_building = jokhang_01 }
                    flag:wartburg_01 = { add_building = wartburg_01 }
                    flag:beta_giyorgis_01 = { add_building = beta_giyorgis_01 }
                    flag:holy_wisdom_01 = { add_building = holy_wisdom_01 }
                    flag:kano_walls_01 = { add_building = kano_walls_01 }
                    flag:somapura_university_01 = { add_building = somapura_university_01 }
                    flag:duomo_florence_01 = { add_building = duomo_florence_01 }
                    flag:duomo_florence_02 = { add_building = duomo_florence_02 }
                    flag:duomo_florence_03 = { add_building = duomo_florence_03 }
                    flag:duomo_florence_04 = { add_building = duomo_florence_04 }
                    flag:konark_temple_01 = { add_building = konark_temple_01 }
                    flag:al_qarawiyyin_university_01 = { add_building = al_qarawiyyin_university_01 }
                    flag:kairouan_basins_01 = { add_building = kairouan_basins_01 }
                    flag:ghana_palace_01 = { add_building = ghana_palace_01 }
                    flag:visegrad_castle_01 = { add_building = visegrad_castle_01 }
                    flag:wawel_cathedral_01 = { add_building = wawel_cathedral_01 }
                    flag:wawel_cathedral_02 = { add_building = wawel_cathedral_02 }
                    flag:wawel_cathedral_03 = { add_building = wawel_cathedral_03 }
                    flag:vatapi_caves_01 = { add_building = vatapi_caves_01 }
                    flag:jaisalmer_fort_01 = { add_building = jaisalmer_fort_01 }
                }
            }
        }
    }
}

DI_destroy_building_sgui = {
    scope = character # Player Character

    saved_scopes = {
        building_type # Flag of Building Base to destroy
    }

    effect = {
        save_scope_as = player

        every_in_list = {
            variable = DI_action_provinces
            save_scope_as = province

            scope:province = {
                switch = {
                    trigger = scope:building_type
                    flag:al_qarawiyyin_university = {
                        if = { limit = { has_building = al_qarawiyyin_university_01 } remove_building = al_qarawiyyin_university_01 }
                    }
                    flag:alamut_castle = {
                        if = { limit = { has_building = alamut_castle_02 } remove_building = alamut_castle_02 }
                        else_if = { limit = { has_building = alamut_castle_01 } remove_building = alamut_castle_01 }
                    }
                    flag:alcazar_of_segovia = {
                        if = { limit = { has_building = alcazar_of_segovia_01 } remove_building = alcazar_of_segovia_01 }
                    }
                    flag:alhambra = {
                        if = { limit = { has_building = alhambra_02 } remove_building = alhambra_02 }
                        else_if = { limit = { has_building = alhambra_01 } remove_building = alhambra_01 }
                    }
                    flag:aljaferia_palace = {
                        if = { limit = { has_building = aljaferia_palace_01 } remove_building = aljaferia_palace_01 }
                    }
                    flag:allaq_mines = {
                        if = { limit = { has_building = allaq_mines_04 } remove_building = allaq_mines_04 }
                        else_if = { limit = { has_building = allaq_mines_03 } remove_building = allaq_mines_03 }
                        else_if = { limit = { has_building = allaq_mines_02 } remove_building = allaq_mines_02 }
                        else_if = { limit = { has_building = allaq_mines_01 } remove_building = allaq_mines_01 }
                    }
                    flag:ananda_temple = {
                        if = { limit = { has_building = ananda_temple_01 } remove_building = ananda_temple_01 }
                    }
                    flag:angkor_wat = {
                        if = { limit = { has_building = angkor_wat_01 } remove_building = angkor_wat_01 }
                    }
                    flag:archery_ranges = {
                        if = { limit = { has_building = archery_ranges_03 } remove_building = archery_ranges_03 }
                        else_if = { limit = { has_building = archery_ranges_02 } remove_building = archery_ranges_02 }
                        else_if = { limit = { has_building = archery_ranges_01 } remove_building = archery_ranges_01 }
                    }
                    flag:argentiera_mines = {
                        if = { limit = { has_building = argentiera_mines_04 } remove_building = argentiera_mines_04 }
                        else_if = { limit = { has_building = argentiera_mines_03 } remove_building = argentiera_mines_03 }
                        else_if = { limit = { has_building = argentiera_mines_02 } remove_building = argentiera_mines_02 }
                        else_if = { limit = { has_building = argentiera_mines_01 } remove_building = argentiera_mines_01 }
                    }
                    flag:ark_of_bukhara = {
                        if = { limit = { has_building = ark_of_bukhara_01 } remove_building = ark_of_bukhara_01 }
                    }
                    flag:assassin_castle = {
                        if = { limit = { has_building = assassin_castle_01 } remove_building = assassin_castle_01 }
                    }
                    flag:aurelian_walls = {
                        if = { limit = { has_building = aurelian_walls_01 } remove_building = aurelian_walls_01 }
                    }
                    flag:barracks = { DI_remove_building_type_effect = { BUILDING = barracks } }
                    flag:besakih_temple = {
                        if = { limit = { has_building = besakih_temple_01 } remove_building = besakih_temple_01 }
                    }
                    flag:beta_giyorgis = {
                        if = { limit = { has_building = beta_giyorgis_01 } remove_building = beta_giyorgis_01 }
                    }
                    flag:blacksmiths = {
                        if = { limit = { has_building = blacksmiths_03 } remove_building = blacksmiths_03 }
                        else_if = { limit = { has_building = blacksmiths_02 } remove_building = blacksmiths_02 }
                        else_if = { limit = { has_building = blacksmiths_01 } remove_building = blacksmiths_01 }
                    }
                    flag:borobudur = {
                        if = { limit = { has_building = borobudur_01 } remove_building = borobudur_01 }
                    }
                    flag:breweries = { DI_remove_building_type_effect = { BUILDING = breweries } }
                    flag:brihadeeswarar_temple = {
                        if = { limit = { has_building = brihadeeswarar_temple_01 } remove_building = brihadeeswarar_temple_01 }
                    }
                    flag:buddhas_of_bamian = {
                        if = { limit = { has_building = buddhas_of_bamian_01 } remove_building = buddhas_of_bamian_01 }
                    }
                    flag:burial_site = {
                        if = { limit = { has_building = burial_site_03 } remove_building = burial_site_03 }
                        else_if = { limit = { has_building = burial_site_02 } remove_building = burial_site_02 }
                        else_if = { limit = { has_building = burial_site_01 } remove_building = burial_site_01 }
                    }
                    flag:burkhan_khaldun = {
                        if = { limit = { has_building = burkhan_khaldun_01 } remove_building = burkhan_khaldun_01 }
                    }
                    flag:byeokran_port = {
                        if = { limit = { has_building = byeokran_port_01 } remove_building = byeokran_port_01 }
                    }
                    flag:camel_farms = { DI_remove_building_type_effect = { BUILDING = camel_farms } }
                    flag:capital_bureau = { DI_remove_building_type_effect = { BUILDING = capital_bureau } }
                    flag:caravanserai = { DI_remove_building_type_effect = { BUILDING = caravanserai } }
                    flag:castle = { add_building = castle_01 }
                    flag:celestial_great_barracks = {
                        if = { limit = { has_building = celestial_great_barracks_01 } remove_building = celestial_great_barracks_01 }
                    }
                    flag:cereal_fields = { DI_remove_building_type_effect = { BUILDING = cereal_fields } }
                    flag:cevennes_mines = {
                        if = { limit = { has_building = cevennes_mines_04 } remove_building = cevennes_mines_04 }
                        else_if = { limit = { has_building = cevennes_mines_03 } remove_building = cevennes_mines_03 }
                        else_if = { limit = { has_building = cevennes_mines_02 } remove_building = cevennes_mines_02 }
                        else_if = { limit = { has_building = cevennes_mines_01 } remove_building = cevennes_mines_01 }
                    }
                    flag:changan_market = {
                        if = { limit = { has_building = changan_market_02 } remove_building = changan_market_02 }
                        else_if = { limit = { has_building = changan_market_01 } remove_building = changan_market_01 }
                    }
                    flag:charnel_grounds = {
                        if = { limit = { has_building = charnel_grounds_03 } remove_building = charnel_grounds_03 }
                        else_if = { limit = { has_building = charnel_grounds_02 } remove_building = charnel_grounds_02 }
                        else_if = { limit = { has_building = charnel_grounds_01 } remove_building = charnel_grounds_01 }
                    }
                    flag:chinjufu = {
                        if = { limit = { has_building = chinjufu_01 } remove_building = chinjufu_01 }
                    }
                    flag:citadel_of_aleppo = {
                        if = { limit = { has_building = citadel_of_aleppo_02 } remove_building = citadel_of_aleppo_02 }
                        else_if = { limit = { has_building = citadel_of_aleppo_01 } remove_building = citadel_of_aleppo_01 }
                    }
                    flag:citadel_shrine = { DI_remove_building_type_effect = { BUILDING = citadel_shrine } }
                    flag:citadel_thang_long = {
                        if = { limit = { has_building = citadel_thang_long_02 } remove_building = citadel_thang_long_02 }
                        else_if = { limit = { has_building = citadel_thang_long_01 } remove_building = citadel_thang_long_01 }
                    }
                    flag:city = { add_building = city_01 }
                    flag:city_wall_of_toledo = {
                        if = { limit = { has_building = city_wall_of_toledo_01 } remove_building = city_wall_of_toledo_01 }
                    }
                    flag:cluny_abbey = {
                        if = { limit = { has_building = cluny_abbey_02 } remove_building = cluny_abbey_02 }
                        else_if = { limit = { has_building = cluny_abbey_01 } remove_building = cluny_abbey_01 }
                    }
                    flag:common_tradeport = { DI_remove_building_type_effect = { BUILDING = common_tradeport } }
                    flag:culai_academy = {
                        if = { limit = { has_building = culai_academy_01 } remove_building = culai_academy_01 }
                    }
                    flag:curtain_walls = { DI_remove_building_type_effect = { BUILDING = curtain_walls } }
                    flag:damascus_mosque = {
                        if = { limit = { has_building = damascus_mosque_01 } remove_building = damascus_mosque_01 }
                    }
                    flag:danevirke = {
                        if = { limit = { has_building = danevirke_01 } remove_building = danevirke_01 }
                    }
                    flag:dau_temple = {
                        if = { limit = { has_building = dau_temple_01 } remove_building = dau_temple_01 }
                    }
                    flag:dazaifu = {
                        if = { limit = { has_building = dazaifu_01 } remove_building = dazaifu_01 }
                    }
                    flag:dean_mines = {
                        if = { limit = { has_building = dean_mines_04 } remove_building = dean_mines_04 }
                        else_if = { limit = { has_building = dean_mines_03 } remove_building = dean_mines_03 }
                        else_if = { limit = { has_building = dean_mines_02 } remove_building = dean_mines_02 }
                        else_if = { limit = { has_building = dean_mines_01 } remove_building = dean_mines_01 }
                    }
                    flag:dieng_plateau = {
                        if = { limit = { has_building = dieng_plateau_01 } remove_building = dieng_plateau_01 }
                    }
                    flag:doges_palace = {
                        if = { limit = { has_building = doges_palace_01 } remove_building = doges_palace_01 }
                    }
                    flag:dome_of_the_rock = {
                        if = { limit = { has_building = dome_of_the_rock_01 } remove_building = dome_of_the_rock_01 }
                    }
                    flag:dragon_kiln = {
                        if = { limit = { has_building = dragon_kiln_03 } remove_building = dragon_kiln_03 }
                        else_if = { limit = { has_building = dragon_kiln_02 } remove_building = dragon_kiln_02 }
                        else_if = { limit = { has_building = dragon_kiln_01 } remove_building = dragon_kiln_01 }
                    }
                    flag:drassanes = {
                        if = { limit = { has_building = drassanes_01 } remove_building = drassanes_01 }
                    }
                    flag:dunhuang_market = {
                        if = { limit = { has_building = dunhuang_market_02 } remove_building = dunhuang_market_02 }
                        else_if = { limit = { has_building = dunhuang_market_01 } remove_building = dunhuang_market_01 }
                    }
                    flag:duomo_florence = {
                        if = { limit = { has_building = duomo_florence_04 } remove_building = duomo_florence_04 }
                        else_if = { limit = { has_building = duomo_florence_03 } remove_building = duomo_florence_03 }
                        else_if = { limit = { has_building = duomo_florence_02 } remove_building = duomo_florence_02 }
                        else_if = { limit = { has_building = duomo_florence_01 } remove_building = duomo_florence_01 }
                    }
                    flag:dushan_mines = {
                        if = { limit = { has_building = dushan_mines_04 } remove_building = dushan_mines_04 }
                        else_if = { limit = { has_building = dushan_mines_03 } remove_building = dushan_mines_03 }
                        else_if = { limit = { has_building = dushan_mines_02 } remove_building = dushan_mines_02 }
                        else_if = { limit = { has_building = dushan_mines_01 } remove_building = dushan_mines_01 }
                    }
                    flag:dvin_shuka = {
                        if = { limit = { has_building = dvin_shuka_02 } remove_building = dvin_shuka_02 }
                        else_if = { limit = { has_building = dvin_shuka_01 } remove_building = dvin_shuka_01 }
                    }
                    flag:elephant_pens = { DI_remove_building_type_effect = { BUILDING = elephant_pens } }
                    flag:enryaku_ji = {
                        if = { limit = { has_building = enryaku_ji_01 } remove_building = enryaku_ji_01 }
                    }
                    flag:event_tower_of_silence = {
                        if = { limit = { has_building = event_tower_of_silence_01 } remove_building = event_tower_of_silence_01 }
                    }
                    flag:examination_hall = {
                        if = { limit = { has_building = examination_hall_03 } remove_building = examination_hall_03 }
                        else_if = { limit = { has_building = examination_hall_02 } remove_building = examination_hall_02 }
                        else_if = { limit = { has_building = examination_hall_01 } remove_building = examination_hall_01 }
                    }
                    flag:falak_ol_aflak_citadel = {
                        if = { limit = { has_building = falak_ol_aflak_citadel_01 } remove_building = falak_ol_aflak_citadel_01 }
                    }
                    flag:falun_mines = {
                        if = { limit = { has_building = falun_mines_04 } remove_building = falun_mines_04 }
                        else_if = { limit = { has_building = falun_mines_03 } remove_building = falun_mines_03 }
                        else_if = { limit = { has_building = falun_mines_02 } remove_building = falun_mines_02 }
                        else_if = { limit = { has_building = falun_mines_01 } remove_building = falun_mines_01 }
                    }
                    flag:farm_estates = { DI_remove_building_type_effect = { BUILDING = farm_estates } }
                    flag:fengtian_mines = {
                        if = { limit = { has_building = fengtian_mines_03 } remove_building = fengtian_mines_03 }
                        else_if = { limit = { has_building = fengtian_mines_02 } remove_building = fengtian_mines_02 }
                        else_if = { limit = { has_building = fengtian_mines_01 } remove_building = fengtian_mines_01 }
                    }
                    flag:forbidden_city = {
                        if = { limit = { has_building = forbidden_city_01 } remove_building = forbidden_city_01 }
                    }
                    flag:generic_copper_mines = {
                        if = { limit = { has_building = generic_copper_mines_04 } remove_building = generic_copper_mines_04 }
                        else_if = { limit = { has_building = generic_copper_mines_03 } remove_building = generic_copper_mines_03 }
                        else_if = { limit = { has_building = generic_copper_mines_02 } remove_building = generic_copper_mines_02 }
                        else_if = { limit = { has_building = generic_copper_mines_01 } remove_building = generic_copper_mines_01 }
                    }
                    flag:generic_gold_mines = {
                        if = { limit = { has_building = generic_gold_mines_04 } remove_building = generic_gold_mines_04 }
                        else_if = { limit = { has_building = generic_gold_mines_03 } remove_building = generic_gold_mines_03 }
                        else_if = { limit = { has_building = generic_gold_mines_02 } remove_building = generic_gold_mines_02 }
                        else_if = { limit = { has_building = generic_gold_mines_01 } remove_building = generic_gold_mines_01 }
                    }
                    flag:generic_silver_mines = {
                        if = { limit = { has_building = generic_silver_mines_04 } remove_building = generic_silver_mines_04 }
                        else_if = { limit = { has_building = generic_silver_mines_03 } remove_building = generic_silver_mines_03 }
                        else_if = { limit = { has_building = generic_silver_mines_02 } remove_building = generic_silver_mines_02 }
                        else_if = { limit = { has_building = generic_silver_mines_01 } remove_building = generic_silver_mines_01 }
                    }
                    flag:ghana_palace = {
                        if = { limit = { has_building = ghana_palace_01 } remove_building = ghana_palace_01 }
                    }
                    flag:giant_wild_goose_pagoda = {
                        if = { limit = { has_building = giant_wild_goose_pagoda_01 } remove_building = giant_wild_goose_pagoda_01 }
                    }
                    flag:golden_gate_of_kiev = {
                        if = { limit = { has_building = golden_gate_of_kiev_01 } remove_building = golden_gate_of_kiev_01 }
                    }
                    flag:gongsanseong_fortress = {
                        if = { limit = { has_building = gongsanseong_fortress_01 } remove_building = gongsanseong_fortress_01 }
                    }
                    flag:great_megalith = {
                        if = { limit = { has_building = great_megalith_01 } remove_building = great_megalith_01 }
                    }
                    flag:great_wall_of_gorgan = {
                        if = { limit = { has_building = great_wall_of_gorgan_01 } remove_building = great_wall_of_gorgan_01 }
                    }
                    flag:guild_halls = { DI_remove_building_type_effect = { BUILDING = guild_halls } }
                    flag:hadrians_wall = {
                        if = { limit = { has_building = hadrians_wall_01 } remove_building = hadrians_wall_01 }
                    }
                    flag:hagia_sophia = {
                        if = { limit = { has_building = hagia_sophia_02 } remove_building = hagia_sophia_02 }
                        else_if = { limit = { has_building = hagia_sophia_01 } remove_building = hagia_sophia_01 }
                    }
                    flag:hakata_port = {
                        if = { limit = { has_building = hakata_port_02 } remove_building = hakata_port_02 }
                        else_if = { limit = { has_building = hakata_port_01 } remove_building = hakata_port_01 }
                    }
                    flag:hall_of_heroes = {
                        if = { limit = { has_building = hall_of_heroes_05 } remove_building = hall_of_heroes_05 }
                        else_if = { limit = { has_building = hall_of_heroes_04 } remove_building = hall_of_heroes_04 }
                        else_if = { limit = { has_building = hall_of_heroes_03 } remove_building = hall_of_heroes_03 }
                        else_if = { limit = { has_building = hall_of_heroes_02 } remove_building = hall_of_heroes_02 }
                        else_if = { limit = { has_building = hall_of_heroes_01 } remove_building = hall_of_heroes_01 }
                    }
                    flag:hamadan_bazaar = {
                        if = { limit = { has_building = hamadan_bazaar_02 } remove_building = hamadan_bazaar_02 }
                        else_if = { limit = { has_building = hamadan_bazaar_01 } remove_building = hamadan_bazaar_01 }
                    }
                    flag:hanging_temple = {
                        if = { limit = { has_building = hanging_temple_01 } remove_building = hanging_temple_01 }
                    }
                    flag:heddal_stave_church = {
                        if = { limit = { has_building = heddal_stave_church_01 } remove_building = heddal_stave_church_01 }
                    }
                    flag:heian_palace = {
                        if = { limit = { has_building = heian_palace_01 } remove_building = heian_palace_01 }
                    }
                    flag:herat_bazaar = {
                        if = { limit = { has_building = herat_bazaar_02 } remove_building = herat_bazaar_02 }
                        else_if = { limit = { has_building = herat_bazaar_01 } remove_building = herat_bazaar_01 }
                    }
                    flag:herder_camp = {
                        if = { limit = { has_building = herder_camp_01 } remove_building = herder_camp_01 }
                    }
                    flag:hetian_mines = {
                        if = { limit = { has_building = hetian_mines_04 } remove_building = hetian_mines_04 }
                        else_if = { limit = { has_building = hetian_mines_03 } remove_building = hetian_mines_03 }
                        else_if = { limit = { has_building = hetian_mines_02 } remove_building = hetian_mines_02 }
                        else_if = { limit = { has_building = hetian_mines_01 } remove_building = hetian_mines_01 }
                    }
                    flag:hill_farms = { DI_remove_building_type_effect = { BUILDING = hill_farms } }
                    flag:hill_forts = { DI_remove_building_type_effect = { BUILDING = hill_forts } }
                    flag:hillside_grazing = { DI_remove_building_type_effect = { BUILDING = hillside_grazing } }
                    flag:holy_site_basilica_santiago = {
                        if = { limit = { has_building = holy_site_basilica_santiago_01 } remove_building = holy_site_basilica_santiago_01 }
                    }
                    flag:holy_site_buddhist_grand_temple = {
                        if = { limit = { has_building = holy_site_buddhist_grand_temple_01 } remove_building = holy_site_buddhist_grand_temple_01 }
                    }
                    flag:holy_site_canterbury_cathedral = {
                        if = { limit = { has_building = holy_site_canterbury_cathedral_03 } remove_building = holy_site_canterbury_cathedral_03 }
                        else_if = { limit = { has_building = holy_site_canterbury_cathedral_02 } remove_building = holy_site_canterbury_cathedral_02 }
                        else_if = { limit = { has_building = holy_site_canterbury_cathedral_01 } remove_building = holy_site_canterbury_cathedral_01 }
                    }
                    flag:holy_site_cathedral = {
                        if = { limit = { has_building = holy_site_cathedral_01 } remove_building = holy_site_cathedral_01 }
                    }
                    flag:holy_site_chinese_temple = {
                        if = { limit = { has_building = holy_site_chinese_temple_01 } remove_building = holy_site_chinese_temple_01 }
                    }
                    flag:holy_site_cologne_cathedral = {
                        if = { limit = { has_building = holy_site_cologne_cathedral_01 } remove_building = holy_site_cologne_cathedral_01 }
                    }
                    flag:holy_site_fire_temple = {
                        if = { limit = { has_building = holy_site_fire_temple_01 } remove_building = holy_site_fire_temple_01 }
                    }
                    flag:holy_site_great_mosque_of_cordoba = {
                        if = { limit = { has_building = holy_site_great_mosque_of_cordoba_01 } remove_building = holy_site_great_mosque_of_cordoba_01 }
                    }
                    flag:holy_site_great_mosque_of_djenne = {
                        if = { limit = { has_building = holy_site_great_mosque_of_djenne_01 } remove_building = holy_site_great_mosque_of_djenne_01 }
                    }
                    flag:holy_site_great_mosque_of_mecca = {
                        if = { limit = { has_building = holy_site_great_mosque_of_mecca_01 } remove_building = holy_site_great_mosque_of_mecca_01 }
                    }
                    flag:holy_site_great_mosque_of_samarra = {
                        if = { limit = { has_building = holy_site_great_mosque_of_samarra_01 } remove_building = holy_site_great_mosque_of_samarra_01 }
                    }
                    flag:holy_site_imam_ali_mosque = {
                        if = { limit = { has_building = holy_site_imam_ali_mosque_01 } remove_building = holy_site_imam_ali_mosque_01 }
                    }
                    flag:holy_site_indian_grand_temple = {
                        if = { limit = { has_building = holy_site_indian_grand_temple_01 } remove_building = holy_site_indian_grand_temple_01 }
                    }
                    flag:holy_site_japanese_temple = {
                        if = { limit = { has_building = holy_site_japanese_temple_01 } remove_building = holy_site_japanese_temple_01 }
                    }
                    flag:holy_site_mahabodhi_temple = {
                        if = { limit = { has_building = holy_site_mahabodhi_temple_01 } remove_building = holy_site_mahabodhi_temple_01 }
                    }
                    flag:holy_site_mosque = {
                        if = { limit = { has_building = holy_site_mosque_01 } remove_building = holy_site_mosque_01 }
                    }
                    flag:holy_site_other_grand_temple = {
                        if = { limit = { has_building = holy_site_other_grand_temple_01 } remove_building = holy_site_other_grand_temple_01 }
                    }
                    flag:holy_site_pagan_grand_temple = {
                        if = { limit = { has_building = holy_site_pagan_grand_temple_01 } remove_building = holy_site_pagan_grand_temple_01 }
                    }
                    flag:holy_site_prophetic_mosque = {
                        if = { limit = { has_building = holy_site_prophetic_mosque_01 } remove_building = holy_site_prophetic_mosque_01 }
                    }
                    flag:holy_site_se_asia_pagan_temple = {
                        if = { limit = { has_building = holy_site_se_asia_pagan_temple_01 } remove_building = holy_site_se_asia_pagan_temple_01 }
                    }
                    flag:holy_wisdom = {
                        if = { limit = { has_building = holy_wisdom_01 } remove_building = holy_wisdom_01 }
                    }
                    flag:horse_pastures = { DI_remove_building_type_effect = { BUILDING = horse_pastures } }
                    flag:hoshi_ryokan = {
                        if = { limit = { has_building = hoshi_ryokan_01 } remove_building = hoshi_ryokan_01 }
                    }
                    flag:hospices = { DI_remove_building_type_effect = { BUILDING = hospices } }
                    flag:hotin_fort = {
                        if = { limit = { has_building = hotin_fort_02 } remove_building = hotin_fort_02 }
                        else_if = { limit = { has_building = hotin_fort_01 } remove_building = hotin_fort_01 }
                    }
                    flag:house_of_wisdom = {
                        if = { limit = { has_building = house_of_wisdom_01 } remove_building = house_of_wisdom_01 }
                    }
                    flag:hpakant_mines = {
                        if = { limit = { has_building = hpakant_mines_04 } remove_building = hpakant_mines_04 }
                        else_if = { limit = { has_building = hpakant_mines_03 } remove_building = hpakant_mines_03 }
                        else_if = { limit = { has_building = hpakant_mines_02 } remove_building = hpakant_mines_02 }
                        else_if = { limit = { has_building = hpakant_mines_01 } remove_building = hpakant_mines_01 }
                    }
                    flag:hunting_grounds = { DI_remove_building_type_effect = { BUILDING = hunting_grounds } }
                    flag:hwangnyongsa = {
                        if = { limit = { has_building = hwangnyongsa_01 } remove_building = hwangnyongsa_01 }
                    }
                    flag:idjang_forts = {
                        if = { limit = { has_building = idjang_forts_04 } remove_building = idjang_forts_04 }
                        else_if = { limit = { has_building = idjang_forts_03 } remove_building = idjang_forts_03 }
                        else_if = { limit = { has_building = idjang_forts_02 } remove_building = idjang_forts_02 }
                        else_if = { limit = { has_building = idjang_forts_01 } remove_building = idjang_forts_01 }
                    }
                    flag:ijil_mines = {
                        if = { limit = { has_building = ijil_mines_04 } remove_building = ijil_mines_04 }
                        else_if = { limit = { has_building = ijil_mines_03 } remove_building = ijil_mines_03 }
                        else_if = { limit = { has_building = ijil_mines_02 } remove_building = ijil_mines_02 }
                        else_if = { limit = { has_building = ijil_mines_01 } remove_building = ijil_mines_01 }
                    }
                    flag:imam_reza_shrine = {
                        if = { limit = { has_building = imam_reza_shrine_01 } remove_building = imam_reza_shrine_01 }
                    }
                    flag:iron_pillar_of_delhi = {
                        if = { limit = { has_building = iron_pillar_of_delhi_01 } remove_building = iron_pillar_of_delhi_01 }
                    }
                    flag:iron_pillar_of_dhar = {
                        if = { limit = { has_building = iron_pillar_of_dhar_01 } remove_building = iron_pillar_of_dhar_01 }
                    }
                    flag:ise_jingu = {
                        if = { limit = { has_building = ise_jingu_01 } remove_building = ise_jingu_01 }
                    }
                    flag:itoigawa_mines = {
                        if = { limit = { has_building = itoigawa_mines_04 } remove_building = itoigawa_mines_04 }
                        else_if = { limit = { has_building = itoigawa_mines_03 } remove_building = itoigawa_mines_03 }
                        else_if = { limit = { has_building = itoigawa_mines_02 } remove_building = itoigawa_mines_02 }
                        else_if = { limit = { has_building = itoigawa_mines_01 } remove_building = itoigawa_mines_01 }
                    }
                    flag:itsukushima_jinja = {
                        if = { limit = { has_building = itsukushima_jinja_02 } remove_building = itsukushima_jinja_02 }
                        else_if = { limit = { has_building = itsukushima_jinja_01 } remove_building = itsukushima_jinja_01 }
                    }
                    flag:jaisalmer_fort = {
                        if = { limit = { has_building = jaisalmer_fort_01 } remove_building = jaisalmer_fort_01 }
                    }
                    flag:jizu_shan_temples = {
                        if = { limit = { has_building = jizu_shan_temples_01 } remove_building = jizu_shan_temples_01 }
                    }
                    flag:jokhang = {
                        if = { limit = { has_building = jokhang_01 } remove_building = jokhang_01 }
                    }
                    flag:jousting_lists = {
                        if = { limit = { has_building = jousting_lists_03 } remove_building = jousting_lists_03 }
                        else_if = { limit = { has_building = jousting_lists_02 } remove_building = jousting_lists_02 }
                        else_if = { limit = { has_building = jousting_lists_01 } remove_building = jousting_lists_01 }
                    }
                    flag:kaifeng_palace = {
                        if = { limit = { has_building = kaifeng_palace_01 } remove_building = kaifeng_palace_01 }
                    }
                    flag:kairouan_basins = {
                        if = { limit = { has_building = kairouan_basins_01 } remove_building = kairouan_basins_01 }
                    }
                    flag:kano_walls = {
                        if = { limit = { has_building = kano_walls_01 } remove_building = kano_walls_01 }
                    }
                    flag:khajuraho = {
                        if = { limit = { has_building = khajuraho_01 } remove_building = khajuraho_01 }
                    }
                    flag:khetri_mines = {
                        if = { limit = { has_building = khetri_mines_04 } remove_building = khetri_mines_04 }
                        else_if = { limit = { has_building = khetri_mines_03 } remove_building = khetri_mines_03 }
                        else_if = { limit = { has_building = khetri_mines_02 } remove_building = khetri_mines_02 }
                        else_if = { limit = { has_building = khetri_mines_01 } remove_building = khetri_mines_01 }
                    }
                    flag:khiva_bazaar = {
                        if = { limit = { has_building = khiva_bazaar_02 } remove_building = khiva_bazaar_02 }
                        else_if = { limit = { has_building = khiva_bazaar_01 } remove_building = khiva_bazaar_01 }
                    }
                    flag:kofuku_ji = {
                        if = { limit = { has_building = kofuku_ji_01 } remove_building = kofuku_ji_01 }
                    }
                    flag:koganeyama_mines = {
                        if = { limit = { has_building = koganeyama_mines_04 } remove_building = koganeyama_mines_04 }
                        else_if = { limit = { has_building = koganeyama_mines_03 } remove_building = koganeyama_mines_03 }
                        else_if = { limit = { has_building = koganeyama_mines_02 } remove_building = koganeyama_mines_02 }
                        else_if = { limit = { has_building = koganeyama_mines_01 } remove_building = koganeyama_mines_01 }
                    }
                    flag:kollur_mines = {
                        if = { limit = { has_building = kollur_mines_04 } remove_building = kollur_mines_04 }
                        else_if = { limit = { has_building = kollur_mines_03 } remove_building = kollur_mines_03 }
                        else_if = { limit = { has_building = kollur_mines_02 } remove_building = kollur_mines_02 }
                        else_if = { limit = { has_building = kollur_mines_01 } remove_building = kollur_mines_01 }
                    }
                    flag:konark_temple = {
                        if = { limit = { has_building = konark_temple_01 } remove_building = konark_temple_01 }
                    }
                    flag:konasamudram_mines = {
                        if = { limit = { has_building = konasamudram_mines_04 } remove_building = konasamudram_mines_04 }
                        else_if = { limit = { has_building = konasamudram_mines_03 } remove_building = konasamudram_mines_03 }
                        else_if = { limit = { has_building = konasamudram_mines_02 } remove_building = konasamudram_mines_02 }
                        else_if = { limit = { has_building = konasamudram_mines_01 } remove_building = konasamudram_mines_01 }
                    }
                    flag:kora_kora_yards = {
                        if = { limit = { has_building = kora_kora_yards_04 } remove_building = kora_kora_yards_04 }
                        else_if = { limit = { has_building = kora_kora_yards_03 } remove_building = kora_kora_yards_03 }
                        else_if = { limit = { has_building = kora_kora_yards_02 } remove_building = kora_kora_yards_02 }
                        else_if = { limit = { has_building = kora_kora_yards_01 } remove_building = kora_kora_yards_01 }
                    }
                    flag:krakatoa = {
                        if = { limit = { has_building = krakatoa_01 } remove_building = krakatoa_01 }
                    }
                    flag:kremnica_mines = {
                        if = { limit = { has_building = kremnica_mines_04 } remove_building = kremnica_mines_04 }
                        else_if = { limit = { has_building = kremnica_mines_03 } remove_building = kremnica_mines_03 }
                        else_if = { limit = { has_building = kremnica_mines_02 } remove_building = kremnica_mines_02 }
                        else_if = { limit = { has_building = kremnica_mines_01 } remove_building = kremnica_mines_01 }
                    }
                    flag:kutna_hora_mines = {
                        if = { limit = { has_building = kutna_hora_mines_04 } remove_building = kutna_hora_mines_04 }
                        else_if = { limit = { has_building = kutna_hora_mines_03 } remove_building = kutna_hora_mines_03 }
                        else_if = { limit = { has_building = kutna_hora_mines_02 } remove_building = kutna_hora_mines_02 }
                        else_if = { limit = { has_building = kutna_hora_mines_01 } remove_building = kutna_hora_mines_01 }
                    }
                    flag:kyz_kala = {
                        if = { limit = { has_building = kyz_kala_01 } remove_building = kyz_kala_01 }
                    }
                    flag:lahur_bazaar = {
                        if = { limit = { has_building = lahur_bazaar_02 } remove_building = lahur_bazaar_02 }
                        else_if = { limit = { has_building = lahur_bazaar_01 } remove_building = lahur_bazaar_01 }
                    }
                    flag:lantian_mines = {
                        if = { limit = { has_building = lantian_mines_04 } remove_building = lantian_mines_04 }
                        else_if = { limit = { has_building = lantian_mines_03 } remove_building = lantian_mines_03 }
                        else_if = { limit = { has_building = lantian_mines_02 } remove_building = lantian_mines_02 }
                        else_if = { limit = { has_building = lantian_mines_01 } remove_building = lantian_mines_01 }
                    }
                    flag:leisure_palace = {
                        if = { limit = { has_building = leisure_palace_03 } remove_building = leisure_palace_03 }
                        else_if = { limit = { has_building = leisure_palace_02 } remove_building = leisure_palace_02 }
                        else_if = { limit = { has_building = leisure_palace_01 } remove_building = leisure_palace_01 }
                    }
                    flag:leshan_giant_buddha = {
                        if = { limit = { has_building = leshan_giant_buddha_01 } remove_building = leshan_giant_buddha_01 }
                    }
                    flag:lhasa_market = {
                        if = { limit = { has_building = lhasa_market_02 } remove_building = lhasa_market_02 }
                        else_if = { limit = { has_building = lhasa_market_01 } remove_building = lhasa_market_01 }
                    }
                    flag:lingyin_temple = {
                        if = { limit = { has_building = lingyin_temple_01 } remove_building = lingyin_temple_01 }
                    }
                    flag:liuhe_pagoda = {
                        if = { limit = { has_building = liuhe_pagoda_01 } remove_building = liuhe_pagoda_01 }
                    }
                    flag:lize_academy = {
                        if = { limit = { has_building = lize_academy_01 } remove_building = lize_academy_01 }
                    }
                    flag:logging_camps = { DI_remove_building_type_effect = { BUILDING = logging_camps } }
                    flag:london_bridge = {
                        if = { limit = { has_building = london_bridge_01 } remove_building = london_bridge_01 }
                    }
                    flag:longhouses = {
                        if = { limit = { has_building = longhouses_02 } remove_building = longhouses_02 }
                        else_if = { limit = { has_building = longhouses_01 } remove_building = longhouses_01 }
                    }
                    flag:lund_cathedral = {
                        if = { limit = { has_building = lund_cathedral_01 } remove_building = lund_cathedral_01 }
                    }
                    flag:maharloo_lake = {
                        if = { limit = { has_building = maharloo_lake_01 } remove_building = maharloo_lake_01 }
                    }
                    flag:mali_mines = {
                        if = { limit = { has_building = mali_mines_04 } remove_building = mali_mines_04 }
                        else_if = { limit = { has_building = mali_mines_03 } remove_building = mali_mines_03 }
                        else_if = { limit = { has_building = mali_mines_02 } remove_building = mali_mines_02 }
                        else_if = { limit = { has_building = mali_mines_01 } remove_building = mali_mines_01 }
                    }
                    flag:mandala_capital = {
                        if = { limit = { has_building = mandala_capital_05 } remove_building = mandala_capital_05 }
                        else_if = { limit = { has_building = mandala_capital_04 } remove_building = mandala_capital_04 }
                        else_if = { limit = { has_building = mandala_capital_03 } remove_building = mandala_capital_03 }
                        else_if = { limit = { has_building = mandala_capital_02 } remove_building = mandala_capital_02 }
                        else_if = { limit = { has_building = mandala_capital_01 } remove_building = mandala_capital_01 }
                    }
                    flag:maoshan_academy = {
                        if = { limit = { has_building = maoshan_academy_01 } remove_building = maoshan_academy_01 }
                    }
                    flag:march = {
                        if = { limit = { has_building = march_03 } remove_building = march_03 }
                        else_if = { limit = { has_building = march_02 } remove_building = march_02 }
                        else_if = { limit = { has_building = march_01 } remove_building = march_01 }
                    }
                    flag:market_villages = {
                        if = { limit = { has_building = market_villages_02 } remove_building = market_villages_02 }
                        else_if = { limit = { has_building = market_villages_01 } remove_building = market_villages_01 }
                    }
                    flag:megalith = { DI_remove_building_type_effect = { BUILDING = megalith } }
                    flag:meteora = {
                        if = { limit = { has_building = meteora_02 } remove_building = meteora_02 }
                        else_if = { limit = { has_building = meteora_01 } remove_building = meteora_01 }
                    }
                    flag:military_academy = {
                        if = { limit = { has_building = military_academy_03 } remove_building = military_academy_03 }
                        else_if = { limit = { has_building = military_academy_02 } remove_building = military_academy_02 }
                        else_if = { limit = { has_building = military_academy_01 } remove_building = military_academy_01 }
                    }
                    flag:military_camps = { DI_remove_building_type_effect = { BUILDING = military_camps } }
                    flag:minarets_and_remains_of_jam = {
                        if = { limit = { has_building = minarets_and_remains_of_jam_01 } remove_building = minarets_and_remains_of_jam_01 }
                    }
                    flag:mogok_mines = {
                        if = { limit = { has_building = mogok_mines_04 } remove_building = mogok_mines_04 }
                        else_if = { limit = { has_building = mogok_mines_03 } remove_building = mogok_mines_03 }
                        else_if = { limit = { has_building = mogok_mines_02 } remove_building = mogok_mines_02 }
                        else_if = { limit = { has_building = mogok_mines_01 } remove_building = mogok_mines_01 }
                    }
                    flag:monastic_schools = { DI_remove_building_type_effect = { BUILDING = monastic_schools } }
                    flag:mount_apo = {
                        if = { limit = { has_building = mount_apo_01 } remove_building = mount_apo_01 }
                    }
                    flag:mount_athos = {
                        if = { limit = { has_building = mount_athos_03 } remove_building = mount_athos_03 }
                        else_if = { limit = { has_building = mount_athos_02 } remove_building = mount_athos_02 }
                        else_if = { limit = { has_building = mount_athos_01 } remove_building = mount_athos_01 }
                    }
                    flag:mount_baekdu = {
                        if = { limit = { has_building = mount_baekdu_01 } remove_building = mount_baekdu_01 }
                    }
                    flag:mount_damavand = {
                        if = { limit = { has_building = mount_damavand_01 } remove_building = mount_damavand_01 }
                    }
                    flag:mount_fuji = {
                        if = { limit = { has_building = mount_fuji_01 } remove_building = mount_fuji_01 }
                    }
                    flag:muaro_jambi = {
                        if = { limit = { has_building = muaro_jambi_01 } remove_building = muaro_jambi_01 }
                    }
                    flag:murex_farm = { DI_remove_building_type_effect = { BUILDING = murex_farm } }
                    flag:nanhua_temple = {
                        if = { limit = { has_building = nanhua_temple_01 } remove_building = nanhua_temple_01 }
                    }
                    flag:nishapur_mines = {
                        if = { limit = { has_building = nishapur_mines_04 } remove_building = nishapur_mines_04 }
                        else_if = { limit = { has_building = nishapur_mines_03 } remove_building = nishapur_mines_03 }
                        else_if = { limit = { has_building = nishapur_mines_02 } remove_building = nishapur_mines_02 }
                        else_if = { limit = { has_building = nishapur_mines_01 } remove_building = nishapur_mines_01 }
                    }
                    flag:nomadic_camp = {
                        if = { limit = { has_building = nomadic_camp_01 } remove_building = nomadic_camp_01 }
                    }
                    flag:notre_dame = {
                        if = { limit = { has_building = notre_dame_01 } remove_building = notre_dame_01 }
                    }
                    flag:oath_faithful_building = {
                        if = { limit = { has_building = oath_faithful_building_04 } remove_building = oath_faithful_building_04 }
                        else_if = { limit = { has_building = oath_faithful_building_03 } remove_building = oath_faithful_building_03 }
                        else_if = { limit = { has_building = oath_faithful_building_02 } remove_building = oath_faithful_building_02 }
                        else_if = { limit = { has_building = oath_faithful_building_01 } remove_building = oath_faithful_building_01 }
                    }
                    flag:oath_poor_building = {
                        if = { limit = { has_building = oath_poor_building_04 } remove_building = oath_poor_building_04 }
                        else_if = { limit = { has_building = oath_poor_building_03 } remove_building = oath_poor_building_03 }
                        else_if = { limit = { has_building = oath_poor_building_02 } remove_building = oath_poor_building_02 }
                        else_if = { limit = { has_building = oath_poor_building_01 } remove_building = oath_poor_building_01 }
                    }
                    flag:oath_warriors_building = {
                        if = { limit = { has_building = oath_warriors_building_04 } remove_building = oath_warriors_building_04 }
                        else_if = { limit = { has_building = oath_warriors_building_03 } remove_building = oath_warriors_building_03 }
                        else_if = { limit = { has_building = oath_warriors_building_02 } remove_building = oath_warriors_building_02 }
                        else_if = { limit = { has_building = oath_warriors_building_01 } remove_building = oath_warriors_building_01 }
                    }
                    flag:offas_dyke = {
                        if = { limit = { has_building = offas_dyke_01 } remove_building = offas_dyke_01 }
                    }
                    flag:orchards = { DI_remove_building_type_effect = { BUILDING = orchards } }
                    flag:outposts = { DI_remove_building_type_effect = { BUILDING = outposts } }
                    flag:paddy_fields = { DI_remove_building_type_effect = { BUILDING = paddy_fields } }
                    flag:pagoda_of_fogong_temple = {
                        if = { limit = { has_building = pagoda_of_fogong_temple_01 } remove_building = pagoda_of_fogong_temple_01 }
                    }
                    flag:palace_of_aachen = {
                        if = { limit = { has_building = palace_of_aachen_01 } remove_building = palace_of_aachen_01 }
                    }
                    flag:palace_of_ctesiphon = {
                        if = { limit = { has_building = palace_of_ctesiphon_02 } remove_building = palace_of_ctesiphon_02 }
                        else_if = { limit = { has_building = palace_of_ctesiphon_01 } remove_building = palace_of_ctesiphon_01 }
                    }
                    flag:palisades = {
                        if = { limit = { has_building = palisades_02 } remove_building = palisades_02 }
                        else_if = { limit = { has_building = palisades_01 } remove_building = palisades_01 }
                    }
                    flag:pansjhir_mines = {
                        if = { limit = { has_building = pansjhir_mines_04 } remove_building = pansjhir_mines_04 }
                        else_if = { limit = { has_building = pansjhir_mines_03 } remove_building = pansjhir_mines_03 }
                        else_if = { limit = { has_building = pansjhir_mines_02 } remove_building = pansjhir_mines_02 }
                        else_if = { limit = { has_building = pansjhir_mines_01 } remove_building = pansjhir_mines_01 }
                    }
                    flag:pastures = { DI_remove_building_type_effect = { BUILDING = pastures } }
                    flag:peat_quarries = { DI_remove_building_type_effect = { BUILDING = peat_quarries } }
                    flag:petra = {
                        if = { limit = { has_building = petra_01 } remove_building = petra_01 }
                    }
                    flag:phnom_dek_mines = {
                        if = { limit = { has_building = phnom_dek_mines_04 } remove_building = phnom_dek_mines_04 }
                        else_if = { limit = { has_building = phnom_dek_mines_03 } remove_building = phnom_dek_mines_03 }
                        else_if = { limit = { has_building = phnom_dek_mines_02 } remove_building = phnom_dek_mines_02 }
                        else_if = { limit = { has_building = phnom_dek_mines_01 } remove_building = phnom_dek_mines_01 }
                    }
                    flag:phocaea_mines = {
                        if = { limit = { has_building = phocaea_mines_04 } remove_building = phocaea_mines_04 }
                        else_if = { limit = { has_building = phocaea_mines_03 } remove_building = phocaea_mines_03 }
                        else_if = { limit = { has_building = phocaea_mines_02 } remove_building = phocaea_mines_02 }
                        else_if = { limit = { has_building = phocaea_mines_01 } remove_building = phocaea_mines_01 }
                    }
                    flag:plain_of_jars = {
                        if = { limit = { has_building = plain_of_jars_01 } remove_building = plain_of_jars_01 }
                    }
                    flag:plantations = { DI_remove_building_type_effect = { BUILDING = plantations } }
                    flag:po_klong_garai = {
                        if = { limit = { has_building = po_klong_garai_01 } remove_building = po_klong_garai_01 }
                    }
                    flag:powder_magazine = { DI_remove_building_type_effect = { BUILDING = powder_magazine } }
                    flag:qanats = { DI_remove_building_type_effect = { BUILDING = qanats } }
                    flag:qianling_mausoleum = {
                        if = { limit = { has_building = qianling_mausoleum_01 } remove_building = qianling_mausoleum_01 }
                    }
                    flag:quanzhou_seaport = {
                        if = { limit = { has_building = quanzhou_seaport_01 } remove_building = quanzhou_seaport_01 }
                    }
                    flag:quarries = { DI_remove_building_type_effect = { BUILDING = quarries } }
                    flag:rainbow_mountains = {
                        if = { limit = { has_building = rainbow_mountains_01 } remove_building = rainbow_mountains_01 }
                    }
                    flag:rammelsberg_mines = {
                        if = { limit = { has_building = rammelsberg_mines_04 } remove_building = rammelsberg_mines_04 }
                        else_if = { limit = { has_building = rammelsberg_mines_03 } remove_building = rammelsberg_mines_03 }
                        else_if = { limit = { has_building = rammelsberg_mines_02 } remove_building = rammelsberg_mines_02 }
                        else_if = { limit = { has_building = rammelsberg_mines_01 } remove_building = rammelsberg_mines_01 }
                    }
                    flag:ramparts = { DI_remove_building_type_effect = { BUILDING = ramparts } }
                    flag:ratnapura_mines = {
                        if = { limit = { has_building = ratnapura_mines_04 } remove_building = ratnapura_mines_04 }
                        else_if = { limit = { has_building = ratnapura_mines_03 } remove_building = ratnapura_mines_03 }
                        else_if = { limit = { has_building = ratnapura_mines_02 } remove_building = ratnapura_mines_02 }
                        else_if = { limit = { has_building = ratnapura_mines_01 } remove_building = ratnapura_mines_01 }
                    }
                    flag:regimental_grounds = { DI_remove_building_type_effect = { BUILDING = regimental_grounds } }
                    flag:rock_of_gibraltar = {
                        if = { limit = { has_building = rock_of_gibraltar_01 } remove_building = rock_of_gibraltar_01 }
                    }
                    flag:roman_wall_of_lugo = {
                        if = { limit = { has_building = roman_wall_of_lugo_01 } remove_building = roman_wall_of_lugo_01 }
                    }
                    flag:royal_armory = {
                        if = { limit = { has_building = royal_armory_03 } remove_building = royal_armory_03 }
                        else_if = { limit = { has_building = royal_armory_02 } remove_building = royal_armory_02 }
                        else_if = { limit = { has_building = royal_armory_01 } remove_building = royal_armory_01 }
                    }
                    flag:royal_forest = {
                        if = { limit = { has_building = royal_forest_03 } remove_building = royal_forest_03 }
                        else_if = { limit = { has_building = royal_forest_02 } remove_building = royal_forest_02 }
                        else_if = { limit = { has_building = royal_forest_01 } remove_building = royal_forest_01 }
                    }
                    flag:royal_garden = {
                        if = { limit = { has_building = royal_garden_03 } remove_building = royal_garden_03 }
                        else_if = { limit = { has_building = royal_garden_02 } remove_building = royal_garden_02 }
                        else_if = { limit = { has_building = royal_garden_01 } remove_building = royal_garden_01 }
                    }
                    flag:rudnik_mines = {
                        if = { limit = { has_building = rudnik_mines_04 } remove_building = rudnik_mines_04 }
                        else_if = { limit = { has_building = rudnik_mines_03 } remove_building = rudnik_mines_03 }
                        else_if = { limit = { has_building = rudnik_mines_02 } remove_building = rudnik_mines_02 }
                        else_if = { limit = { has_building = rudnik_mines_01 } remove_building = rudnik_mines_01 }
                    }
                    flag:sacred_pool = { DI_remove_building_type_effect = { BUILDING = sacred_pool } }
                    flag:sado_mines = {
                        if = { limit = { has_building = sado_mines_04 } remove_building = sado_mines_04 }
                        else_if = { limit = { has_building = sado_mines_03 } remove_building = sado_mines_03 }
                        else_if = { limit = { has_building = sado_mines_02 } remove_building = sado_mines_02 }
                        else_if = { limit = { has_building = sado_mines_01 } remove_building = sado_mines_01 }
                    }
                    flag:sar_i_sang_mines = {
                        if = { limit = { has_building = sar_i_sang_mines_04 } remove_building = sar_i_sang_mines_04 }
                        else_if = { limit = { has_building = sar_i_sang_mines_03 } remove_building = sar_i_sang_mines_03 }
                        else_if = { limit = { has_building = sar_i_sang_mines_02 } remove_building = sar_i_sang_mines_02 }
                        else_if = { limit = { has_building = sar_i_sang_mines_01 } remove_building = sar_i_sang_mines_01 }
                    }
                    flag:schwaz_mines = {
                        if = { limit = { has_building = schwaz_mines_04 } remove_building = schwaz_mines_04 }
                        else_if = { limit = { has_building = schwaz_mines_03 } remove_building = schwaz_mines_03 }
                        else_if = { limit = { has_building = schwaz_mines_02 } remove_building = schwaz_mines_02 }
                        else_if = { limit = { has_building = schwaz_mines_01 } remove_building = schwaz_mines_01 }
                    }
                    flag:scriptorium = { DI_remove_building_type_effect = { BUILDING = scriptorium } }
                    flag:shah_i_zinda = {
                        if = { limit = { has_building = shah_i_zinda_02 } remove_building = shah_i_zinda_02 }
                        else_if = { limit = { has_building = shah_i_zinda_01 } remove_building = shah_i_zinda_01 }
                    }
                    flag:shaolin_monastery = {
                        if = { limit = { has_building = shaolin_monastery_01 } remove_building = shaolin_monastery_01 }
                    }
                    flag:shigu_academy = {
                        if = { limit = { has_building = shigu_academy_01 } remove_building = shigu_academy_01 }
                    }
                    flag:shwedagon_pagoda = {
                        if = { limit = { has_building = shwedagon_pagoda_01 } remove_building = shwedagon_pagoda_01 }
                    }
                    flag:siderokausia_mines = {
                        if = { limit = { has_building = siderokausia_mines_04 } remove_building = siderokausia_mines_04 }
                        else_if = { limit = { has_building = siderokausia_mines_03 } remove_building = siderokausia_mines_03 }
                        else_if = { limit = { has_building = siderokausia_mines_02 } remove_building = siderokausia_mines_02 }
                        else_if = { limit = { has_building = siderokausia_mines_01 } remove_building = siderokausia_mines_01 }
                    }
                    flag:siege_works = {
                        if = { limit = { has_building = siege_works_03 } remove_building = siege_works_03 }
                        else_if = { limit = { has_building = siege_works_02 } remove_building = siege_works_02 }
                        else_if = { limit = { has_building = siege_works_01 } remove_building = siege_works_01 }
                    }
                    flag:smiths = { DI_remove_building_type_effect = { BUILDING = smiths } }
                    flag:soltaniyeh = {
                        if = { limit = { has_building = soltaniyeh_01 } remove_building = soltaniyeh_01 }
                    }
                    flag:somapura_university = {
                        if = { limit = { has_building = somapura_university_01 } remove_building = somapura_university_01 }
                    }
                    flag:special_greenhouse = {
                        if = { limit = { has_building = special_greenhouse_01 } remove_building = special_greenhouse_01 }
                    }
                    flag:special_sicilian_parliament = {
                        if = { limit = { has_building = special_sicilian_parliament_01 } remove_building = special_sicilian_parliament_01 }
                    }
                    flag:spice_plantation = { DI_remove_building_type_effect = { BUILDING = spice_plantation } }
                    flag:srebrenica_mines = {
                        if = { limit = { has_building = srebrenica_mines_04 } remove_building = srebrenica_mines_04 }
                        else_if = { limit = { has_building = srebrenica_mines_03 } remove_building = srebrenica_mines_03 }
                        else_if = { limit = { has_building = srebrenica_mines_02 } remove_building = srebrenica_mines_02 }
                        else_if = { limit = { has_building = srebrenica_mines_01 } remove_building = srebrenica_mines_01 }
                    }
                    flag:stables = { DI_remove_building_type_effect = { BUILDING = stables } }
                    flag:stilted_granaries = {
                        if = { limit = { has_building = stilted_granaries_04 } remove_building = stilted_granaries_04 }
                        else_if = { limit = { has_building = stilted_granaries_03 } remove_building = stilted_granaries_03 }
                        else_if = { limit = { has_building = stilted_granaries_02 } remove_building = stilted_granaries_02 }
                        else_if = { limit = { has_building = stilted_granaries_01 } remove_building = stilted_granaries_01 }
                    }
                    flag:stonehenge = {
                        if = { limit = { has_building = stonehenge_01 } remove_building = stonehenge_01 }
                    }
                    flag:sumela_monastery = {
                        if = { limit = { has_building = sumela_monastery_02 } remove_building = sumela_monastery_02 }
                        else_if = { limit = { has_building = sumela_monastery_01 } remove_building = sumela_monastery_01 }
                    }
                    flag:sunday_bazaar = {
                        if = { limit = { has_building = sunday_bazaar_02 } remove_building = sunday_bazaar_02 }
                        else_if = { limit = { has_building = sunday_bazaar_01 } remove_building = sunday_bazaar_01 }
                    }
                    flag:suvarnadvipa_mines = {
                        if = { limit = { has_building = suvarnadvipa_mines_04 } remove_building = suvarnadvipa_mines_04 }
                        else_if = { limit = { has_building = suvarnadvipa_mines_03 } remove_building = suvarnadvipa_mines_03 }
                        else_if = { limit = { has_building = suvarnadvipa_mines_02 } remove_building = suvarnadvipa_mines_02 }
                        else_if = { limit = { has_building = suvarnadvipa_mines_01 } remove_building = suvarnadvipa_mines_01 }
                    }
                    flag:tada_mines = {
                        if = { limit = { has_building = tada_mines_04 } remove_building = tada_mines_04 }
                        else_if = { limit = { has_building = tada_mines_03 } remove_building = tada_mines_03 }
                        else_if = { limit = { has_building = tada_mines_02 } remove_building = tada_mines_02 }
                        else_if = { limit = { has_building = tada_mines_01 } remove_building = tada_mines_01 }
                    }
                    flag:taghaza_mines = {
                        if = { limit = { has_building = taghaza_mines_04 } remove_building = taghaza_mines_04 }
                        else_if = { limit = { has_building = taghaza_mines_03 } remove_building = taghaza_mines_03 }
                        else_if = { limit = { has_building = taghaza_mines_02 } remove_building = taghaza_mines_02 }
                        else_if = { limit = { has_building = taghaza_mines_01 } remove_building = taghaza_mines_01 }
                    }
                    flag:takkeda_mines = {
                        if = { limit = { has_building = takkeda_mines_04 } remove_building = takkeda_mines_04 }
                        else_if = { limit = { has_building = takkeda_mines_03 } remove_building = takkeda_mines_03 }
                        else_if = { limit = { has_building = takkeda_mines_02 } remove_building = takkeda_mines_02 }
                        else_if = { limit = { has_building = takkeda_mines_01 } remove_building = takkeda_mines_01 }
                    }
                    flag:tax_assessor = {
                        if = { limit = { has_building = tax_assessor_03 } remove_building = tax_assessor_03 }
                        else_if = { limit = { has_building = tax_assessor_02 } remove_building = tax_assessor_02 }
                        else_if = { limit = { has_building = tax_assessor_01 } remove_building = tax_assessor_01 }
                    }
                    flag:temple = { add_building = temple_01 }
                    flag:temple_citadel = {
                        if = { limit = { has_building = temple_citadel_04 } remove_building = temple_citadel_04 }
                        else_if = { limit = { has_building = temple_citadel_03 } remove_building = temple_citadel_03 }
                        else_if = { limit = { has_building = temple_citadel_02 } remove_building = temple_citadel_02 }
                        else_if = { limit = { has_building = temple_citadel_01 } remove_building = temple_citadel_01 }
                    }
                    flag:temple_in_jerusalem = {
                        if = { limit = { has_building = temple_in_jerusalem_01 } remove_building = temple_in_jerusalem_01 }
                    }
                    flag:temple_of_uppsala = {
                        if = { limit = { has_building = temple_of_uppsala_02 } remove_building = temple_of_uppsala_02 }
                        else_if = { limit = { has_building = temple_of_uppsala_01 } remove_building = temple_of_uppsala_01 }
                    }
                    flag:the_colosseum = {
                        if = { limit = { has_building = the_colosseum_01 } remove_building = the_colosseum_01 }
                    }
                    flag:the_friday_mosque = {
                        if = { limit = { has_building = the_friday_mosque_01 } remove_building = the_friday_mosque_01 }
                    }
                    flag:the_great_wall = {
                        if = { limit = { has_building = the_great_wall_04 } remove_building = the_great_wall_04 }
                        else_if = { limit = { has_building = the_great_wall_03 } remove_building = the_great_wall_03 }
                        else_if = { limit = { has_building = the_great_wall_02 } remove_building = the_great_wall_02 }
                        else_if = { limit = { has_building = the_great_wall_01 } remove_building = the_great_wall_01 }
                    }
                    flag:the_pyramids = {
                        if = { limit = { has_building = the_pyramids_01 } remove_building = the_pyramids_01 }
                    }
                    flag:the_tower_of_london = {
                        if = { limit = { has_building = the_tower_of_london_01 } remove_building = the_tower_of_london_01 }
                    }
                    flag:theodosian_walls = {
                        if = { limit = { has_building = theodosian_walls_01 } remove_building = theodosian_walls_01 }
                    }
                    flag:tiantai_monasteries = {
                        if = { limit = { has_building = tiantai_monasteries_01 } remove_building = tiantai_monasteries_01 }
                    }
                    flag:tomb_of_cyrus = {
                        if = { limit = { has_building = tomb_of_cyrus_01 } remove_building = tomb_of_cyrus_01 }
                    }
                    flag:tower_of_hercules = {
                        if = { limit = { has_building = tower_of_hercules_01 } remove_building = tower_of_hercules_01 }
                    }
                    flag:tower_of_silence = {
                        if = { limit = { has_building = tower_of_silence_01 } remove_building = tower_of_silence_01 }
                    }
                    flag:trepca_mines = {
                        if = { limit = { has_building = trepca_mines_04 } remove_building = trepca_mines_04 }
                        else_if = { limit = { has_building = trepca_mines_03 } remove_building = trepca_mines_03 }
                        else_if = { limit = { has_building = trepca_mines_02 } remove_building = trepca_mines_02 }
                        else_if = { limit = { has_building = trepca_mines_01 } remove_building = trepca_mines_01 }
                    }
                    flag:tribe = { add_building = tribe_01 }
                    flag:tsushima_mines = {
                        if = { limit = { has_building = tsushima_mines_04 } remove_building = tsushima_mines_04 }
                        else_if = { limit = { has_building = tsushima_mines_03 } remove_building = tsushima_mines_03 }
                        else_if = { limit = { has_building = tsushima_mines_02 } remove_building = tsushima_mines_02 }
                        else_if = { limit = { has_building = tsushima_mines_01 } remove_building = tsushima_mines_01 }
                    }
                    flag:turda_mines = {
                        if = { limit = { has_building = turda_mines_04 } remove_building = turda_mines_04 }
                        else_if = { limit = { has_building = turda_mines_03 } remove_building = turda_mines_03 }
                        else_if = { limit = { has_building = turda_mines_02 } remove_building = turda_mines_02 }
                        else_if = { limit = { has_building = turda_mines_01 } remove_building = turda_mines_01 }
                    }
                    flag:vatapi_caves = {
                        if = { limit = { has_building = vatapi_caves_01 } remove_building = vatapi_caves_01 }
                    }
                    flag:verespatak_mines = {
                        if = { limit = { has_building = verespatak_mines_04 } remove_building = verespatak_mines_04 }
                        else_if = { limit = { has_building = verespatak_mines_03 } remove_building = verespatak_mines_03 }
                        else_if = { limit = { has_building = verespatak_mines_02 } remove_building = verespatak_mines_02 }
                        else_if = { limit = { has_building = verespatak_mines_01 } remove_building = verespatak_mines_01 }
                    }
                    flag:vihara_halls = { DI_remove_building_type_effect = { BUILDING = vihara_halls } }
                    flag:visby_ringmur = {
                        if = { limit = { has_building = visby_ringmur_01 } remove_building = visby_ringmur_01 }
                    }
                    flag:visegrad_castle = {
                        if = { limit = { has_building = visegrad_castle_01 } remove_building = visegrad_castle_01 }
                    }
                    flag:walls_of_benin = {
                        if = { limit = { has_building = walls_of_benin_01 } remove_building = walls_of_benin_01 }
                    }
                    flag:walls_of_genoa = {
                        if = { limit = { has_building = walls_of_genoa_01 } remove_building = walls_of_genoa_01 }
                    }
                    flag:wantilan = {
                        if = { limit = { has_building = wantilan_04 } remove_building = wantilan_04 }
                        else_if = { limit = { has_building = wantilan_03 } remove_building = wantilan_03 }
                        else_if = { limit = { has_building = wantilan_02 } remove_building = wantilan_02 }
                        else_if = { limit = { has_building = wantilan_01 } remove_building = wantilan_01 }
                    }
                    flag:war_camps = {
                        if = { limit = { has_building = war_camps_02 } remove_building = war_camps_02 }
                        else_if = { limit = { has_building = war_camps_01 } remove_building = war_camps_01 }
                    }
                    flag:warrior_lodges = { DI_remove_building_type_effect = { BUILDING = warrior_lodges } }
                    flag:wartburg = {
                        if = { limit = { has_building = wartburg_01 } remove_building = wartburg_01 }
                    }
                    flag:watchtowers = { DI_remove_building_type_effect = { BUILDING = watchtowers } }
                    flag:water_temples = {
                        if = { limit = { has_building = water_temples_04 } remove_building = water_temples_04 }
                        else_if = { limit = { has_building = water_temples_03 } remove_building = water_temples_03 }
                        else_if = { limit = { has_building = water_temples_02 } remove_building = water_temples_02 }
                        else_if = { limit = { has_building = water_temples_01 } remove_building = water_temples_01 }
                    }
                    flag:watermills = { DI_remove_building_type_effect = { BUILDING = watermills } }
                    flag:waterworks = { DI_remove_building_type_effect = { BUILDING = waterworks } }
                    flag:wawel_cathedral = {
                        if = { limit = { has_building = wawel_cathedral_03 } remove_building = wawel_cathedral_03 }
                        else_if = { limit = { has_building = wawel_cathedral_02 } remove_building = wawel_cathedral_02 }
                        else_if = { limit = { has_building = wawel_cathedral_01 } remove_building = wawel_cathedral_01 }
                    }
                    flag:white_deer_grotto_academy = {
                        if = { limit = { has_building = white_deer_grotto_academy_01 } remove_building = white_deer_grotto_academy_01 }
                    }
                    flag:wind_furnace = { DI_remove_building_type_effect = { BUILDING = wind_furnace } }
                    flag:windmills = { DI_remove_building_type_effect = { BUILDING = windmills } }
                    flag:workshops = { DI_remove_building_type_effect = { BUILDING = workshops } }
                    flag:wudang_mountain_temples = {
                        if = { limit = { has_building = wudang_mountain_temples_01 } remove_building = wudang_mountain_temples_01 }
                    }
                    flag:wulingyuan = {
                        if = { limit = { has_building = wulingyuan_01 } remove_building = wulingyuan_01 }
                    }
                    flag:xiuyan_mines = {
                        if = { limit = { has_building = xiuyan_mines_04 } remove_building = xiuyan_mines_04 }
                        else_if = { limit = { has_building = xiuyan_mines_03 } remove_building = xiuyan_mines_03 }
                        else_if = { limit = { has_building = xiuyan_mines_02 } remove_building = xiuyan_mines_02 }
                        else_if = { limit = { has_building = xiuyan_mines_01 } remove_building = xiuyan_mines_01 }
                    }
                    flag:york_walls = {
                        if = { limit = { has_building = york_walls_01 } remove_building = york_walls_01 }
                    }
                    flag:yungang_grottoes = {
                        if = { limit = { has_building = yungang_grottoes_01 } remove_building = yungang_grottoes_01 }
                    }
                    flag:zawar_mines = {
                        if = { limit = { has_building = zawar_mines_04 } remove_building = zawar_mines_04 }
                        else_if = { limit = { has_building = zawar_mines_03 } remove_building = zawar_mines_03 }
                        else_if = { limit = { has_building = zawar_mines_02 } remove_building = zawar_mines_02 }
                        else_if = { limit = { has_building = zawar_mines_01 } remove_building = zawar_mines_01 }
                    }
                }
            }
        }
    }
}