arkhometha / Historical-Project-Mod

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

[BUG] CB invalidation in crisis wars #164

Open moretrim opened 4 years ago

moretrim commented 4 years ago

Sometimes, CBs added by during the crisis process turn out to be invalid. This means that when the crisis war does break out, they vanish into thin air the next day. If the crisis CB was the only thing on the table, as per the usual game rules this means that the war typically automatically ends in a white peace.

This can be extremely frustrating when what was about to be a highly sought-after crisis great war fizzles. Unfortunately this can be tough to debug:

[...] the main problem is not having a save where this is consistently happening for me to test on

Here is hopefully such a save, where 1897 player Wales holds a big chunk of the USA. (Don't ask.) There is an ongoing crisis for Pennsylvania that the rump, landlocked United States does not border: when the crisis breaks out, the CB is invalidated.

I recommend the following two debug decisions to help:

crisis_in_pennsylvania = {
    potential = {}
    allow = {}

    effect = {
        USA = {
            remove_country_modifier = recent_crisis
        }

        # I swear, state scopes...
        #USA_223 = {
        #   flashpoint_tension = 100
        #}
        223 = {
            state_scope = {
                flashpoint_tension = 100
            }
        }
    }

    ai_will_do = { factor = 0 }
}

precipitate_crisis = {
    potential = {}
    allow = {}

    effect = {
        add_crisis_temperature = 100
    }

    ai_will_do = { factor = 0 }
}

precipitate_crisis is helpful in speeding up an ongoing crisis, crisis_in_pennsylvania is for fomenting a new one just where it says on the tin.

edit: this also requires tweaking the following define during testing (e.g. set it to 0):

https://github.com/arkhometha/Historical-Project-Mod/blob/09afcba51fb953097dbce5b5c424f87e32ac5cc0/HPM/common/defines.lua#L575

For my part, I noticed that moving this block:

https://github.com/arkhometha/Historical-Project-Mod/blob/09afcba51fb953097dbce5b5c424f87e32ac5cc0/HPM/common/cb_types.txt#L4017-L4024

from acquire_state (N.b.: the CB used in reunification crises!) to acquire_core_state without changing anything else results the game still using acquire_state. in reunification hotspots being stuck at 100% tension. Seemingly a crisis using acquire_core_state is unable to fire as things are.

arkhometha commented 4 years ago

Hi @moretrim, thanks for the save. I managed to catch and fix two bugs related to CB cancellation during crisis: one from NNM and one from HPM. The one from HPM, yours, happens because the state in crisis - Philadelphia - is for some reason (likely because it's coastal, despite the lack of ports) a valid flashpoint. Since it's not neighbouring any state of the US nor has a port, the state was not a valid target for the AI. The solution is to make it so the AI can skip these requirements if they have a core there and are at war with the province owner. This can lead to potential border gore, but the other solution - making the CB like acquire_state and capable of "skipping" a state could reduce that but could also lead to the bug happening in another situation.

I tested the allowed_states_in_crisis for the acquire_core_state CB and it didn't solve a thing, the game apparently ignored that part. Which is weird.

Thanks for the debug code and the save, both were very helpful!

moretrim commented 4 years ago

I had the idle thought to try & duplicate acquire_state into a fresh acquire_state_in_crisis CB, keeping the allowed_states_in_crisis trigger while disabling that of the original. The idea being that if a character-for-character copy (save for the name) doesn't work, then nothing else will.

I have similar result as yours: the trigger does not seem to matter for crises, acquire_state is always used. That makes it really painful to mod that CB, so I'm guessing it's either the tweak you did or the nuclear option: leave acquire_state to perform crisis duties, roll out a custom CB that can be as restricted as desired. Obviously that's a staggering amount of work just to get around the current situation, so I don't recommend it.

On a whim I had a look at the internal strings of v2game.exe and strangely enough there is an occurrence of acquire_core_state but not acquire_state. Such a negative result is not as meaningful as a positive result would be however.

(I've edited the issue to reflect that one of the crisis defines should be tweaked, and I added the results it leads to.)

moretrim commented 4 years ago

Here is a save for a liberation crisis for a non-existing Sudan, in case it’s helpful for debugging the Liberate Country CB. Some quick research of mine:

https://github.com/arkhometha/Historical-Project-Mod/blob/7345909e6d8e43d39255909e6ff0cf239c3d8f3a/HPM/common/cb_types.txt#L2184-L2191

According to debug cb_use, this is the limiting factor. The disjunction holds during the crisis, but that changes once war breaks out. At that point the crisis has ended and Sudan is not in the war, since it doesn’t exist.

I noticed by peeking at a save file that in such a situation Sudan does end up with the recent_crisis modifier. I haven’t investigated any further because I ran out of time, I don’t remember either if has_country_modifier works on non-existing country.

Later edit

I’m starting to think that all uses of involved_in_crisis = yes are dubious. Any disjunction that they hold by themselves during a crisis are likely going to be false once war breaks you. Here’s an example I found from a liberation crisis for a Russian-held Poland:

https://github.com/arkhometha/Historical-Project-Mod/blob/a181b6c01ed76b460bb4a21cb2cedc4aa0c35836/HPM/common/cb_types.txt#L2397-L2403

As the target of the crisis, Poland is involved and the condition holds true. Once war breaks out the crisis is internally over, and because Poland is a cultural union and wasn’t on the map the CB fizzled in quick order.

As I understand it the usual way to go about these things is to add consummate uses of war_with = THIS. However liberate_country features many special cases, so I’m afraid this would make the CB really unintuitive to use. Essentially it would end up having one set of restrictive rules for fabrication, and one set of relaxed rules for adding the CB while at war.

For the particular case of liberate_country, it might make sense to turn it into a non-constructing CB for crises and decision/event code—one without the special cases. Then have a constructing CB to pull the duties of normal fabrication. (This may be worth its own issue.) I’m willing to give this a try if that makes sense.