yz_civilian_transfer = {            #民工转移
    add_offsite_building = {
        type = industrial_complex
        level = one_time_ompression_for_civilian_factories
    }
    every_controlled_state = {
        #add_to_array = {
        #    array = tem_use_arry_for_civilian_factroies
        #    value = THIS
        #}
        #add_to_array = {
        #    array = tem_use_arry_for_civilian_factroies_number
        #    value = THIS.industrial_complex
        #}
        clr_state_flag = yz_this_state_has_been_search                     #清除遍历标志
    }
    #set_variable = {
    #    YZ_for_break_flag = 0
    #}
    set_temp_variable = {
        YZ_break = 0
    }
    set_variable = {
        total_move_for_this = 0
    }
    while_loop_effect = {                                                   #大家可能看不懂我这里在写什么，没事，我也看不懂——2025，8.25，21：57，伊尔诺
        #set_temp_variable = {
        #    YZ_for_break_flag = 0
        #}
        #break = YZ_for_break_flag                                            #while(YZ_for_break_flag)   在钢丝的wiki中是说退出循环用"break = <temp_variable>"，令临时变量不为0
        limit = {                                                             #即可退出循环，但事实上在蠢驴自己写的代码中是很少使用break的，个人猜测有作用域的问题，也有一些莫名其妙的
            #has_country_flag = YZ_industry_ompression_start_flag             #问题，比如蠢驴的“set_occupation_law”就是完全没用但还是写在wiki上，在蠢驴自己写的代码中都是
            #check_variable = {                                               #“set_occupation_law_where_available”/*这里我可能拼错了，但是我懒得去查了*/，这里也同理
            #    YZ_for_break_flag = 0                                        #蠢驴自己写的代码中结束循环都是用的limit中的条件，所以我也这么写
            #}                                                                #——2025，8.26，21：29，伊尔诺
            check_variable = {
                var = YZ_break
                value = 0
                compare = equals
            }
        }
        random_owned_controlled_state = {
            limit = {
                not = {
                    has_state_flag = yz_this_state_has_been_search                #防止省份被重复遍历
                }
                industrial_complex > 0
            }
            add_to_variable = {
                ROOT.total_move_for_this = THIS.building_level@industrial_complex
            }
            set_variable = {
                these_land_has_far = THIS.building_level@industrial_complex
            }
            if = {                                                          #统计这一次转移后是否超过计划值
                limit = {
                    check_variable = {
                        var = ROOT.total_move_for_this                                    #这里的“ROOT.”是代表作用域，因为现在是在state里，而“total_move_for_this”在country里，所以要
                        value = ROOT.one_time_ompression_for_civilian_factories           #“ROOT.”，否则这里无法获取变量的值，而且从这里我们可以了解到一个关键的信息：
                        compare = greater_than                                            #对于未初始化的变量的比较，P语言会总是抛出true——2025，8.26，21：08，伊尔诺
                    }
                }
                set_variable = {
                    over_amount_that_we_ompression = ROOT.total_move_for_this
                }
                subtract_from_variable = {
                    var = over_amount_that_we_ompression
                    value = ROOT.one_time_ompression_for_civilian_factories
                }
                #ROOT = {                                                                    #若全部转移就超过，则只转移缺额
                #    add_offsite_building = {
                #        type = industrial_complex                                           #其实这里可以就在这里添加地图外工厂，正如我上面所说，这里的“level”里没有注意到作用域
                #        level = over_amount_that_we_ompression                              #这一行可以改成"level = ROOT.over_amount_that_we_ompression" 
                #    }                                                                       #但是我不推荐这么做，因为这样会徒增计算量——2025，8.26，21：15，伊尔诺
                #}
                remove_building = {
                    type = industrial_complex
                    level = over_amount_that_we_ompression
                }
                #ROOT = {                                                              #这里是我当初为了检查代码是否生效写的，ROOT、PREV和FROM可以看出我当初根本没有找到根本问题
                #    country_event = start_event.2                                     #2025，8.26，21：05，伊尔诺
                #}
                #PREV = {
                #    country_event = start_event.2
                #}
                #FROM = {
                #    country_event = start_event.2
                #}
                set_temp_variable = {
                    YZ_for_break_flag = 1
                }
                set_temp_variable = {
                    YZ_break = 1
                }
            }
            else_if = {                                         #恰到好处，全部转移，同时停止循环
                limit = {
                    check_variable = {
                        var = ROOT.total_move_for_this
                        value = ROOT.one_time_ompression_for_civilian_factories
                        compare = equals
                    }
                }
                #ROOT = {
                #    add_offsite_building = {
                #        type = industrial_complex
                #        level = these_land_has_far
                #    }
                #}
                remove_building = {
                    type = industrial_complex
                    level = THIS.building_level@industrial_complex
                }
                #ROOT = {
                #    country_event = start_event.2
                #}
                #PREV = {
                #    country_event = start_event.2
                #}
                #FROM = {
                #    country_event = start_event.2
                #}
                set_temp_variable = {
                    YZ_for_break_flag = 1
                }
                set_temp_variable = {
                    YZ_break = 1
                }
            }
            else = {                                  #不足，全部转移，并继续循环
                #ROOT = {
                #    add_offsite_building = {
                #        type = industrial_complex
                #        level = these_land_has_far
                #    }
                #}
                remove_building = {
                    type = industrial_complex
                    level = THIS.building_level@industrial_complex
                }
                #ROOT = {
                #    country_event = start_event.2
                #}
            }
            set_state_flag = yz_this_state_has_been_search
        } # end random_owned_controlled_state
    } # end while_loop_effect
} # end effect
yz_arma_transfer = {            #军工转移
    add_offsite_building = {
        type = arms_factory
        level = one_time_ompression_for_arma_factories
    }   
    every_controlled_state = {
        clr_state_flag = yz_this_state_has_been_search                     #清除遍历标志
    }
    #set_variable = {
    #    YZ_for_break_flag = 0
    #}
    set_temp_variable = {
        YZ_break = 0
    }
    set_variable = {
        total_move_for_this = 0
    }
    while_loop_effect = {                                                      #这里的算法和下面的都是一样的，不用看了
        limit = {
            check_variable = {
                var = YZ_break
                value = 0
                compare = equals
            }
        }
        random_owned_controlled_state = {
            limit = {
                not = {
                    has_state_flag = yz_this_state_has_been_search                #防止省份被重复历遍
                }
                arms_factory > 0
            }
            add_to_variable = {
                ROOT.total_move_for_this = THIS.building_level@arms_factory
            }
            set_variable = {
                these_land_has_far = THIS.building_level@arms_factory
            }
            if = {                                                          #统计这一次转移后是否超过计划值
                limit = {
                    check_variable = {
                        var = ROOT.total_move_for_this
                        value = ROOT.one_time_ompression_for_arma_factories
                        compare = greater_than
                    }
                }
                set_variable = {
                    over_amount_that_we_ompression = ROOT.total_move_for_this
                }
                subtract_from_variable = {
                    var = over_amount_that_we_ompression
                    value = ROOT.one_time_ompression_for_arma_factories
                }
                remove_building = {
                    type = arms_factory
                    level = over_amount_that_we_ompression
                }
                set_temp_variable = {
                    YZ_for_break_flag = 1
                }
                set_temp_variable = {
                    YZ_break = 1
                }
            }
            else_if = {                                         #恰到好处，全部转移，同时停止循环
                limit = {
                    check_variable = {
                        var = ROOT.total_move_for_this
                        value = ROOT.one_time_ompression_for_arma_factories
                        compare = equals
                    }
                }
                remove_building = {
                    type = arms_factory
                    level = THIS.building_level@arms_factory
                }
                set_temp_variable = {
                    YZ_for_break_flag = 1
                }
                set_temp_variable = {
                    YZ_break = 1
                }
            }
            else = {                                  #不足，全部转移，并继续循环
                remove_building = {
                    type = arms_factory
                    level = THIS.building_level@arms_factory
                }
            }
            set_state_flag = yz_this_state_has_been_search
        }
    }
}
yz_dockyard_transfer = {            #军工转移
    add_offsite_building = {
        type = dockyard
        level = one_time_ompression_for_dockyard
    }
    every_controlled_state = {
        clr_state_flag = yz_this_state_has_been_search                     #清除遍历标志
    }
    #set_variable = {
    #    YZ_for_break_flag = 0
    #}
    set_temp_variable = {
        YZ_break = 0
    }
    set_variable = {
        total_move_for_this = 0
    }
    while_loop_effect = {                                                   
        limit = {
            check_variable = {
                var = YZ_break
                value = 0
                compare = equals
            }
        }
        random_owned_controlled_state = {
            limit = {
                not = {
                    has_state_flag = yz_this_state_has_been_search                #防止省份被重复历遍
                }
                dockyard > 0
            }
            add_to_variable = {
                ROOT.total_move_for_this = THIS.building_level@dockyard
            }
            set_variable = {
                these_land_has_far = THIS.building_level@dockyard
            }
            if = {                                                          #统计这一次转移后是否超过计划值
                limit = {
                    check_variable = {
                        var = ROOT.total_move_for_this
                        value = ROOT.one_time_ompression_for_dockyard
                        compare = greater_than
                    }
                }
                set_variable = {
                    over_amount_that_we_ompression = ROOT.total_move_for_this
                }
                subtract_from_variable = {
                    var = over_amount_that_we_ompression
                    value = ROOT.one_time_ompression_for_dockyard
                }
                remove_building = {
                    type = dockyard
                    level = over_amount_that_we_ompression
                }
                set_temp_variable = {
                    YZ_for_break_flag = 1
                }
                set_temp_variable = {
                    YZ_break = 1
                }
            }
            else_if = {                                         #恰到好处，全部转移，同时停止循环
                limit = {
                    check_variable = {
                        var = ROOT.total_move_for_this
                        value = ROOT.one_time_ompression_for_dockyard
                        compare = equals
                    }
                }
                remove_building = {
                    type = dockyard
                    level = THIS.building_level@dockyard
                }
                set_temp_variable = {
                    YZ_for_break_flag = 1
                }
                set_temp_variable = {
                    YZ_break = 1
                }
            }
            else = {                                  #不足，全部转移，并继续循环
                remove_building = {
                    type = dockyard
                    level = THIS.building_level@dockyard
                }
            }
            set_state_flag = yz_this_state_has_been_search
        }
    }
}