# Scripted AI desire for peace actions.
# See documentation.info file for more detailed scripting information.

peace_ai_desires = {

    take_our_cores = {
        peace_action_type = { take_states }
        enable = {
            ROOT = { tag = ROOT.FROM } #We are negotiating for ourselves
            ROOT.FROM.FROM.FROM = { is_core_of = ROOT.FROM } #It is ours
        }
        ai_desire = 100
    }

    doesnt_control_no_claim = {
        peace_action_type = { take_states }
        enable = {
            ROOT = { tag = ROOT.FROM } #We are negotiating for ourselves
            ROOT.FROM.FROM.FROM = {
                NOT = { is_core_of = ROOT.FROM }
                NOT = { is_claimed_by = ROOT.FROM }
                NOT = { is_controlled_by = ROOT.FROM }
            }
        }
        ai_desire = -20
    }

    # Countries the ai should be more unlikely to release in a peace deal
    unlikely_countries = {
        peace_action_type = liberate
        enable = {
        }
        ai_desire = -85  # 85 percent lower desire
    }


    dont_grab_exclaves = {
        peace_action_type = take_states
        enable = {
            ROOT.FROM.FROM.FROM = {
                NOT = {
                    OR = {
                        is_claimed_by = ROOT.FROM
                        any_neighbor_state = {
                            OR = {
                                is_owned_by = ROOT.FROM
                                pc_is_state_claimed_by = ROOT.FROM
                            }
                        }
                    }
                }
            }
        }
        ai_desire = -40
    }


    do_grab_stuff_near_us = {
        peace_action_type = take_states
        enable = {
            ROOT.FROM.FROM.FROM = {
                OR = {
                    any_neighbor_state = {
                        OR = {
                            is_owned_by = ROOT.FROM
                        }
                    }
                    is_claimed_by = ROOT.FROM
                }
            }
            ROOT = {
                tag = ROOT.FROM
            }
        }
        ai_desire = 10
    }


    generic_occupies_state = {
        peace_action_type = { take_states puppet liberate force_government }

        enable = {
            FROM.FROM.FROM = { NOT = { is_controlled_by = ROOT } }
        }
        ai_desire = -10
    }

    generic_occupies_player_state = {
        peace_action_type = { take_states puppet liberate force_government }

        enable = {
            FROM.FROM.FROM = { 
                NOT = { is_controlled_by = ROOT }
                controller = {
                    pc_is_loser = no
                    is_ai = no
                }
            }
        }
        ai_desire = -20
    }


    dont_force_government_and_puppet = {
        peace_action_type = { force_government }

        enable = {
            FROM.FROM = { pc_is_puppeted_by = ROOT }
        }
        ai_desire = -200
    }

    dont_force_government_or_puppet_on_non_core = {
        peace_action_type = { puppet force_government }
        enable = {
            ROOT.FROM.FROM.FROM = {
                NOT = { is_core_of = ROOT.FROM }
            }
        }

        ai_desire = -200
    }


    minors_and_subjects_dont_liberate = {
        peace_action_type = { liberate take_states force_government puppet }
        enable = {
            ROOT = {
                NOT = { tag = ROOT.FROM }
            }
            ROOT = {
                OR = {
                    is_major = no
                    is_subject = yes
                }
            }
            ROOT.FROM.FROM.FROM = {
                NOT = {
                    OR = {
                        is_core_of = ROOT.FROM
                        is_claimed_by = ROOT.FROM
                    }
                }
            }
        }
        ai_desire = -90
    }

    it_is_a_non_coastal_adjacency = {
        peace_action_type = take_states
        enable = {
            ROOT.FROM = { tag = ROOT }
            ROOT.FROM.FROM.FROM = {
                is_coastal = no
                any_neighbor_state = {
                    is_owned_by = ROOT
                }
            }
        }
        ai_desire = 10
    }

    avoid_forcing_gov_if_ally_has_core = {
        peace_action_type = force_government
        enable = {
            ROOT.FROM.FROM.FROM = {
                any_country_with_core = {
                    exists = yes
                    pc_is_on_same_side_as = ROOT
                }
            }
        }
        ai_desire = -200
    }

    prefer_take_states_for_puppets_with_cores = {
        peace_action_type = take_states
        enable = {
            ROOT.FROM = {
                is_subject_of = ROOT
                has_civil_war = yes
            }
            ROOT.FROM.FROM.FROM = {
                is_core_of = ROOT.FROM
            }
        }
        ai_desire = 100
    }


    dont_force_government_for_puppets_with_cores = {
        peace_action_type = { force_government puppet }
        enable = {
            ROOT.FROM.FROM.FROM = {
                any_country_with_core = {
                    is_subject_of = ROOT
                    has_civil_war = yes
                }
            }
        }
        ai_desire = -100
    }


    # push countries to actually retake territory that has risen up against them
    retake_territory_from_independence_wars = {
        peace_action_type = { take_states }
        enable = {
            FROM.FROM = {
                has_war_with_wargoal_against = {
                  target = ROOT
                  type = independence_wargoal
                }

            }
        }
        ai_desire = 75
    }


    dont_change_gov_after_independence_wars = {
        peace_action_type = { force_government liberate puppet }
        enable = {
            FROM.FROM = {
                has_war_with_wargoal_against = {
                  target = ROOT
                  type = independence_wargoal
                }

            }
        }
        ai_desire = -75
    }

    no_more_spains_after_scw = {
        peace_action_type = { force_government puppet liberate }
        enable = {
            ROOT = { NOT = { original_tag = SPR } }            #But we are not originally a spain
            has_global_flag = spanish_civil_war             #And the spaindome is ongoing
            NOT = { has_global_flag = scw_over }            #But the spaindome has not yet been resolved
            ROOT.FROM.FROM = { original_tag = SPR }            #And it is being taken from an original spain
            any_country = {                                    #Any country that was an original spain is on our side
                original_tag = SPR
                pc_is_on_same_side_as = ROOT
            }
        }
        ai_desire = -200
    }

    return_the_spains = {
        peace_action_type = take_states
        enable = {
            OR = {
                any_country = {                                            #Any country that was an original spain is on our side
                    original_tag = SPR
                    pc_is_on_same_side_as = ROOT
                }
                original_tag = SPR                                        #Or we are a spain
            }
            ROOT.FROM = { original_tag = SPR }                            #A spain is the recipient
            has_global_flag = spanish_civil_war                            #The spaindome is ongoing
            NOT = { has_global_flag = scw_over }                        #But not over
            ROOT.FROM.FROM.FROM = { owner = { original_tag = SPR } }    #The state was owned by a spain
        }
        ai_desire = 60
    }

    return_puppet_cores = { #This simply has to be the highest priority.
        peace_action_type = take_states
        enable = {
            ROOT.FROM = {
                OR = {
                    is_subject_of = ROOT
                    AND = {
                        pc_is_puppeted_by = ROOT
                        NOT = { original_tag = GER } #This messes with yalta too much.
                    }
                }
            }
            ROOT.FROM.FROM.FROM = {
                is_core_of = ROOT.FROM
                NOT = { is_core_of = ROOT }
            }
        }
        ai_desire = 70 #Acceptable values
    }


    civil_war_participants_dont_accept_each_other = {
        peace_action_type = { force_government puppet liberate }
        enable = {
            ROOT = {
                has_civil_war = yes
                original_tag = FROM # has same original tag as Recipient
            }
        }
        ai_desire = -200
    }

    #############
    # Puppets
    #############

    puppets_dont_interfere_take_states = { #Puppets will focus on helping others most likely, or biidding on their own claims/cores
        peace_action_type = take_states
        enable = {
            is_subject = yes
            NOT = {
                OR = {
                    ROOT.FROM.FROM.FROM = { is_claimed_by = ROOT.FROM }
                    ROOT.FROM.FROM.FROM = { is_core_of = ROOT.FROM }
                }
            }
        }
        ai_desire = -200
    }

    puppets_dont_interfere_others = { #Puppets will not try and puppet/liberate/force-gov
        peace_action_type = { force_government puppet liberate }
        enable = {
            is_subject = yes
            OVERLORD = {
                NOT = { tag = ROOT.FROM }
            }
        }
        ai_desire = -200
    }

    #############
    # Misc
    #############

    puppet_if_another_puppet_has_core = {
        peace_action_type = puppet
        enable = {
            ROOT.FROM.FROM.FROM = {
                NOT = {
                    any_country_with_core = {
                        is_subject_of = ROOT #Not a pc subject
                    }
                }
                any_country_with_core = {
                    pc_is_puppeted_by = ROOT #Is a puppet created in PC
                }
            }
        }
        ai_desire = 30
    }

    dont_do_other_things_if_we_should_liberate = {
        peace_action_type = { take_states puppet force_government }
        enable = {
            ROOT.FROM.FROM.FROM = {
                any_country_with_core = {
                    pc_is_liberated = yes
                }
            }
        }
        ai_desire = -200 #This value has to be highly weighted to offset some other things
    }

    minors_dont_fragment_as_much = {
        peace_action_type = { puppet liberate }
        enable = {
            is_major = no
            ROOT.FROM.FROM = { pc_is_puppeted = yes }
            NOT = { ROOT.FROM.FROM = { pc_is_puppeted_by = ROOT } }
        }
        ai_desire = -100
    }

    minors_dont_puppet_or_liberate_at_all_because_you_cant_finish_the_job = {
        peace_action_type = { puppet liberate }
        enable = {
            is_major = no
            ROOT.FROM = { pc_is_liberated = no }
        }
        ai_desire = -100
    }

    majors_dont_fragment_as_much_less = {
        peace_action_type = { puppet liberate }
        enable = {
            is_major = yes
            ROOT.FROM.FROM = {
                pc_is_puppeted = yes
                NOT = { ROOT.FROM.FROM = { pc_is_puppeted_by = ROOT } }
                NOT = { original_tag = GER }
            }
        }
        ai_desire = -50
    }

    minors_follow_your_leader_when_forcing_gov = {
        peace_action_type = force_government
        enable = {
            is_major = no
            ROOT.FROM.FROM = { pc_is_forced_government = no }
        }
        ai_desire = -100
    }

    continuous_force_gov_desire = {
        peace_action_type = { force_government }
        enable = {
            FROM.FROM = { pc_is_forced_government_by = ROOT }
        }
        ai_desire = 30
    }


    continuous_puppet = {
        peace_action_type = { puppet }
        enable = {
            ROOT.FROM = { pc_is_puppeted_by = ROOT }
        }
        ai_desire = 100
    }

    leave_player_controlled_land_until_later_in_the_process = {
        peace_action_type = { take_states puppet force_government liberate }
        enable = {
            ROOT.FROM.FROM.FROM = {
                controller = {
                    is_ai = no
                }
            }
        }
        ai_desire = -10
    }

    minors_avoid_interfering_with_random_claims = {
        peace_action_type = { take_states }
        enable = {
            ROOT = { is_ai = yes }
            ROOT.FROM = {
                tag = ROOT
                is_major = no
            }
            ROOT.FROM.FROM.FROM = {
                NOT = {
                    OR = {
                        is_claimed_by = ROOT
                        is_core_of = ROOT
                    }
                }
            }
        }
        ai_desire = -80
    }

    dont_even_try_to_puppet_large_states = { ###Too messy
        peace_action_type = { puppet }

        enable = {
            ROOT.FROM.FROM = { check_variable = { num_owned_states > 30 } }
        }
        ai_desire = -200
    }

    dont_liberate_if_puppeted = { ###Too messy
        peace_action_type = { liberate }

        enable = {
            ROOT.FROM = { pc_is_puppeted = yes }
        }
        ai_desire = -200
    }

    dont_take_state_if_already_puppeted_by_us = { ###Too messy
        peace_action_type = { take_state }

        enable = {
            ROOT.FROM = { pc_is_puppeted_by = ROOT }
        }
        ai_desire = -200
    }

    puppet_their_puppets = {
        peace_action_type = { puppet }

        enable = {
            is_faction_leader = yes
            ROOT.FROM.FROM = { 
                is_subject = yes
                OR = {
                    pc_is_puppeted = no
                    pc_is_puppeted_by = ROOT
                }
                overlord = {
                    NOT = { tag = GER }
                }
            }
            ROOT.FROM.FROM.FROM = {
                NOT = { is_claimed_by = ROOT }
                NOT = { is_core_of = ROOT }
            }
        }
        ai_desire = 70
    }

    dont_force_their_puppets = {
        peace_action_type = { force_government }

        enable = {
            ROOT.FROM.FROM = { 
                is_subject = yes
            }
            ROOT.FROM.FROM.FROM = {
                NOT = { is_claimed_by = ROOT }
                NOT = { is_core_of = ROOT }
            }
        }
        ai_desire = -90
    }

}
