The key code for that is this:
Code:
REGION_PLANNING_HOMELAND_PRIORIZATION = 5.1, -- Homeland priorization when assigning armies to regions (only applied when actually threatened)
Actually, they increased this define very recently. I guess it was the latest patch. But it surely doesn't seem enough.
However, I think AI behavior isn't the only problem with defensive warfare. If AI were to prioritize homeland in most situations, they would get crushed most of the time as well. So defensive warfare isn't strong enough is as important as the former. Some potential improvements off the top of my head would be:
- Bringing back dynamic combat width dependent on the terrain. Removing this might still be one of the most single obnoxious changes in this game's history.
- Fixing unlimited reinforcement in foreign lands
- Undoing scorched earth being insignificant and teaching AI to use it etc.
Implementing regional manpower and levies would almost single-handedly improve the situation to a comfortable level although we know from the scope of such a change, it's not possible anymore for EU4. I'm sure it will be in EU5 though after seeing it's coming in Imperator and looking awesome.
Edit: Also, forgot to mention that one line code is only a define. I'm not an expert by a large margin but the real code is behind that define and we can't see it. Maybe the problem lies there instead of the define value. For example, it says only applied when actually threatened and maybe the coding part about the AI diagnosing the threat is flawed instead. I'm just spitballing here, I didn't even play properly after that value changed so maybe I could tell if I did or maybe you guys could tell the difference and diagnose the problem better.