arkhometha / Historical-Project-Mod

A mod for Victoria 2 - Heart of Darkness 3.04
157 stars 52 forks source link

[BUG] Possible race condition in dismantlement #183

Open moretrim opened 4 years ago

moretrim commented 4 years ago

This one is going to be a bit tough because of the following:

It appears that under some conditions eligible colonial countries can be annexed twice, by separate countries, during dismantlement. An example where Dahomey is submitting to both Germany and Italy:

Italy and Germany annexing Dahomey

If you look at the event log, you’ll notice that two copies of Ultimatum event in charge of the annexation are being fired on the same day. I asked for & got a game.log to take a closer look at the timeline. During a different dismantlement:

double annexation

In general the pattern seems to be:

As a proof of concept, I tweaked the option in 96095 to the following:

option = {
    name = "EVT96095OPTA"

    # N.b. move this up front
    random_country = {
        limit = {
            is_vassal = no
            NOT = { has_country_modifier = considering_colonial_offer }
            THIS = {
                # N.b. new safety
                NOT = { has_country_modifier = considering_colonial_offer }
                overlord = { has_country_modifier = being_dismantled }
            }
            OR = {
                neighbour = THIS
                AND = {
                    THIS = { num_of_ports = 1 }
                    num_of_ports = 1
                }
            }
            OR = {
                is_greater_power = yes
                is_secondary_power = yes
            }
            OR = {
                AND = {
                    truce_with = FROM
                    has_country_modifier = dismantling_country
                }
                AND = {
                    THIS = { overlord = { has_country_modifier = international_pariah } }
                    has_country_flag = coalition_member
                }
            }
        }
        add_country_modifier = { name = considering_colonial_offer duration = 2 }
        random_list = {
            25 = { country_event = 96096 }
            25 = { country_event = { id = 96096 days = 1 } }
            25 = { country_event = { id = 96096 days = 2 } }
            25 = { country_event = { id = 96096 days = 3 } }
        }
    }

    random_owned = {
        limit = { owner = { NOT = { has_country_flag = colony_to_be_annexed_flag } } }
        owner = { set_country_flag = colony_to_be_annexed_flag }
    }
    random_owned = {
        limit = { owner = { NOT = { has_country_modifier = colony_to_be_annexed } } }
        owner = { add_country_modifier = { name = colony_to_be_annexed duration = 385 } }
    }

    # random_owned = {
        # limit = { is_core = FROM }
        # owner = { all_core = { remove_core = FROM } }
    # }

    random_owned = {
        limit = { owner = { is_vassal = no } }
        owner = { FROM = { create_vassal = THIS } }
    }

    # N.b. put safety in place
    random_list = {
        10 = { add_country_modifier = { name = considering_colonial_offer duration = 30 } }
        10 = { add_country_modifier = { name = considering_colonial_offer duration = 40 } }
        10 = { add_country_modifier = { name = considering_colonial_offer duration = 50 } }
        10 = { add_country_modifier = { name = considering_colonial_offer duration = 60 } }
        10 = { add_country_modifier = { name = considering_colonial_offer duration = 70 } }
        10 = { add_country_modifier = { name = considering_colonial_offer duration = 80 } }
        10 = { add_country_modifier = { name = considering_colonial_offer duration = 90 } }
        10 = { add_country_modifier = { name = considering_colonial_offer duration = 100 } }
        10 = { add_country_modifier = { name = considering_colonial_offer duration = 110 } }
        10 = { add_country_modifier = { name = considering_colonial_offer duration = 120 } }
    }
}

The intent is that an eligible colony only extends one offer at a time. This seems to be working on the other player’s end. This is little more than a proof-of-concept however because on paper this can make dismantlements take longer to complete. Let me know what you think.