﻿population_transfer_source = {
    kind = directed
    cost = 10

    icon = "gfx/interface/icons/treaty_articles/population_transfer_source.dds"

    flags = {
        can_be_enforced
        can_be_renegotiated
        giftable
    }

    maintenance_paid_by = source_country
    usage_limit = once_per_treaty

    required_inputs = {
        state
        quantity
    }

    visible = {
        is_revolutionary = no
    }

    possible = {
        scope:other_country = {
            is_revolutionary = no
        }
    }

    state_valid_trigger = {
        scope:input = {
            owner = root
            is_under_colonization = no
        }
    }

    quantity_min_value = {
        value = 1
    }

    quantity_max_value = {
        value = 100
    }

    can_ratify = {
        scope:source_country = {
            custom_tooltip = {
                text = POPULATION_TRANSFER_SOURCE_STATE_REQUIRED
                scope:article ?= { exists = input_state }
            }
        }
        scope:article ?= {
            exists = input_state
            exists = input_quantity
        }
    }

    on_entry_into_force = {
        scope:article_options = {
            target_country = {
                set_variable = {
                    name = population_transfer_source_state
                    value = scope:article_options.input_state
                }
                set_variable = {
                    name = population_transfer_quantity
                    value = scope:article_options.input_quantity
                }
                population_transfer_try_execute = yes
            }
        }
    }

    on_withdrawal = {}
    on_break = {
        scope:withdrawing_country = {
            change_relations = {
                country = scope:non_withdrawing_country
                value = -10
            }
        }
    }

    ai = {
        treaty_categories = { other }
        evaluation_chance = { value = 0 }
        article_ai_usage = { offer request }

        combined_acceptance_cap_max = 100

        inherent_accept_score = {
            value = 0

            if = {
                limit = {
                    scope:source_country ?= this
                    exists = scope:article.input_state
                    exists = scope:article.input_quantity
                    total_population > 0
                }
                subtract = {
                    desc = POPULATION_TRANSFER_GIVE_ACCEPTANCE
                    value = scope:article.input_state.state_population
                    multiply = scope:article.input_quantity
                    divide = 100
                    divide = total_population
                    multiply = 500
                }
            }
            else_if = {
                limit = {
                    scope:target_country ?= this
                    exists = scope:article.input_state
                    exists = scope:article.input_quantity
                    total_population > 0
                }
                add = {
                    desc = POPULATION_TRANSFER_RECEIVE_ACCEPTANCE
                    value = scope:article.input_state.state_population
                    multiply = scope:article.input_quantity
                    divide = 100
                    divide = total_population
                    multiply = 500
                }
            }
        }
    }
}

population_transfer_destination = {
    kind = directed
    cost = 10

    icon = "gfx/interface/icons/treaty_articles/population_transfer_destination.dds"

    flags = {
        can_be_enforced
        can_be_renegotiated
        giftable
    }

    maintenance_paid_by = source_country
    usage_limit = once_per_treaty

    required_inputs = {
        state
    }

    visible = {
        is_revolutionary = no
    }

    possible = {
        scope:other_country = {
            is_revolutionary = no
        }
    }

    state_valid_trigger = {
        scope:input = {
            owner = root
            is_under_colonization = no
        }
    }

    can_ratify = {
        scope:source_country = {
            custom_tooltip = {
                text = POPULATION_TRANSFER_DESTINATION_STATE_REQUIRED
                scope:article ?= { exists = input_state }
            }
        }
        scope:article ?= {
            exists = input_state
        }
    }

    on_entry_into_force = {
        scope:article_options = {
            source_country = {
                set_variable = {
                    name = population_transfer_target_state
                    value = scope:article_options.input_state
                }
                population_transfer_try_execute = yes
            }
        }
    }
    on_withdrawal = {}
    on_break = {}

    ai = {
        treaty_categories = { other }
        evaluation_chance = { value = 0 }
        article_ai_usage = { offer request }
        inherent_accept_score = { value = 0 }
    }
}
