﻿
monthly_roman_unity_effect = {
	if = {
		limit = {
			NOT = { has_global_variable = roman_unity_broken }
		}
		if = {
			limit = {
				exists = c:QBR
				exists = c:QJU
				exists = c:QSC
				exists = c:ROM
			}
			monthly_roman_ai_alliance_unification = yes
			monthly_roman_unity = {
				r = "c:ROM"
				c = "c:QSC"
			}
			monthly_roman_unity = {
				r = "c:ROM"
				c = "c:QBR"
			}
			monthly_roman_unity = {
				r = "c:ROM"
				c = "c:QJU"
			}
			monthly_roman_unity = {
				r = "c:QSC"
				c = "c:QBR"
			}
			monthly_roman_unity = {
				r = "c:QSC"
				c = "c:QJU"
			}
			monthly_roman_unity = {
				r = "c:QBR"
				c = "c:QJU"
			}
		}
	}
}

# Make all ai roman factions never ally anyone but other romans
monthly_roman_ai_alliance_unification = {
	if = {
		limit = {
			c:ROM = {
				is_ai = yes
			}
		}
		c:ROM = {
			every_allied_country = {
				limit = {
					NOR = {
						this = c:QSC
						this = c:QBR
						this = c:QJU
					}
				}
				break_alliance = prev
			}
		}
	}
	if = {
		limit = {
			c:QSC = {
				is_ai = yes
			}
		}
		c:QSC = {
			every_allied_country = {
				limit = {
					NOR = {
						this = c:ROM
						this = c:QBR
						this = c:QJU
					}
				}
				break_alliance = prev
			}
		}
	}
	if = {
		limit = {
			c:QBR = {
				is_ai = yes
			}
		}
		c:QBR = {
			every_allied_country = {
				limit = {
					NOR = {
						this = c:ROM
						this = c:QSC
						this = c:QJU
					}
				}
				break_alliance = prev
			}
		}
	}
	if = {
		limit = {
			c:QJU = {
				is_ai = yes
			}
		}
		c:QJU = {
			every_allied_country = {
				limit = {
					NOR = {
						this = c:ROM
						this = c:QSC
						this = c:QBR
					}
				}
				break_alliance = prev
			}
		}
	}
}

# If unified roman countries are not allies, are at war with each other, or have low opinion fix them all to ensure roman unity
# r = root country to check
# c = Country to check
monthly_roman_unity = {
	$r$ = {
		if = {
			limit = {
				war_with = $c$
			}
			every_current_war = {
				limit = {
					OR = {
						AND = {
							any_war_attacker = {
								this = $r$
							}
							any_war_defender = {
								this = $c$
							}
						}
						AND = {
							any_war_defender = {
								this = $r$
							}
							any_war_attacker = {
								this = $c$
							}
						}
					}
				}
				force_white_peace = THIS
				add_roman_unity_opinions = yes
			}
		}
		if = {
			limit = {
				opinion = {
					target = $c$
					value < 150
				}
			}
			add_opinion = {
			    target = $c$
			    modifier = roman_unity_opinion_boost
			}
			reverse_add_opinion = {
			    modifier = roman_unity_opinion_boost
			    target = $c$
			}
		}
		if = {
			limit = {
				NOT = { alliance_with = $c$ }
			}
			add_alliance = $c$
		}
	}
}

add_roman_unity_opinions = {
	c:ROM = {
		add_country_modifier = {
			name = roman_senate_start_mod
			duration = 18250
		}
		add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QSC
		}
		add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QBR
		}
		add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QJU
		}
		reverse_add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QSC
		}
		reverse_add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QBR
		}
		reverse_add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QJU
		}
	}
	c:QSC = {
		add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QBR
		}
		add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QJU
		}
		reverse_add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QBR
		}
		reverse_add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QJU
		}
	}
	c:QBR = {
		add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QJU
		}
		reverse_add_opinion = {
		    modifier = shares_roman_heritage_opinion
		    target = c:QJU
		}
	}
}
