##########################################################################################

### ###  ###  ##  #    ##   ##  #   #     ###   ##   ## ### ###      ###  #  # #   ###  ## 
 #  #  # #   #  # #   #  # #     # #      #  # #  # #   #   #  #     #  # #  # #   #   #   
 #  #  # ##  #  # #   #  # # ##   #       ###  ####  #  ##  #  #     ###  #  # #   ##   #  
 #  #  # #   #  # #   #  # #  #   #       #  # #  #   # #   #  #     #  # #  # #   #     # 
### ###  ###  ##  ###  ##   ##    #       ###  #  # ##  ### ###      #  #  ##  ### ### ## 

########################################################################################## 

joining_rule_non_fascist = {
	type = joining_rules
	visible = {
		NOT = { has_government = fascism }
	}
	ai_will_do = {
		base = 0
		modifier = {
			add = 1
			NOT = { has_government = fascism }
		}
		modifier = {
			add = 1
			has_government = communism
		}
	}
	trigger = {
		NOT = {
			has_government = fascism
		}
		IF = {
			limit = { NOT = { has_rule = can_join_opposite_factions } }
			has_government = FROM
		}
	}
}

joining_rule_non_democratic = {
	type = joining_rules
	visible = {
		NOT = { has_government = democratic }
	}
	ai_will_do = {
		base = 0
		modifier = {
			add = 1
			NOT = { has_government = democratic }
		}
		modifier = {
			add = 1
			has_government = fascism
		}
	}
	trigger = {
		NOT = {
			has_government = democratic 
		}
		IF = {
			limit = { NOT = { has_rule = can_join_opposite_factions } }
			has_government = FROM
		}
	}
}

joining_rule_non_communist = {
	type = joining_rules
	visible = {
		NOT = { has_government = communism }
	}
	ai_will_do = {
		base = 0
		modifier = {
			add = 1
			NOT = { has_government = communism }
		}
		modifier = {
			add = 1
			has_government = fascism
		}
	}
	available = {
		IF = {
			limit = {
				has_faction_template = faction_template_allies
			}
			NOT = {
				any_enemy_country = {
					is_major = yes
					has_government = fascism
				}
			}
		}
	}
	can_remove = {
		IF = {
			limit = {
				ROOT = { original_tag = JAP }
			}
			always = no 
		}
		ELSE = {
			always = yes 
		}
		
	}
	trigger = {
		NOT = {
			has_government = communism 
		}
		IF = {
			limit = { NOT = { has_rule = can_join_opposite_factions } }
			has_government = FROM
		}
	}
}

joining_rule_fascist_only = {
	type = joining_rules
	ai_will_do = {
		base = 0
	}
	available = {
		has_government = fascism
	}
	trigger = {
		has_government = fascism
		IF = {
			limit = { NOT = { has_rule = can_join_opposite_factions } }
			has_government = FROM
		}
	}
}

joining_rule_democratic_non_aligned = {
	type = joining_rules
	ai_will_do = {
		base = 0
	}
	available = {
		has_government = democratic
	}
	trigger = {
		OR = {
			has_government = democratic
			has_government = neutrality
		}
		IF = {
			limit = { NOT = { has_rule = can_join_opposite_factions } }
			has_government = FROM
		}
	}
}

joining_rule_same_ideology = {
	type = joining_rules
	ai_will_do = {
		base = 0
	}
	trigger = {
		has_government = FROM
	}
}

joining_rule_communist_only = {
	type = joining_rules
	ai_will_do = {
		base = 0
	}
	available = {
		has_government = communism
	}
	trigger = {
		has_government = communism
		IF = {
			limit = { NOT = { has_rule = can_join_opposite_factions } }
			has_government = FROM
		}
	}
}

joining_rule_support_percentage = {
	type = joining_rules
	ai_will_do = {
		base = 0
	}
	visible = {

	}
	trigger = {
		compare_ideology_with_faction = {
			value > 0.3
			leader = FROM
		}
		IF = {
			limit = { NOT = { has_rule = can_join_opposite_factions } }
			has_government = FROM
		}
	}
}

joining_rule_puppets_only = {
	type = joining_rules
	can_remove = {
		faction_manifest_fulfillment > 0.95
	}
	ai_will_do = {
		base = 0
	}
	trigger = {
		ROOT = { is_subject_of = FROM }
		IF = {
			limit = { NOT = { has_rule = can_join_opposite_factions } }
			has_government = FROM
		}
	}
	modifier= {
		subjects_autonomy_gain = -0.05
	}
}

#######################################################

#   #  ##  ###      ###  ### #    ##  ### ###  ##  #  #     
#   # #  # #  #     #  # #   #   #  #  #   #  #  # ## #     
# # # #### ###      ###  ##  #   ####  #   #  #  # # ##     
# # # #  # #  #     #  # #   #   #  #  #   #  #  # #  #     
 # #  #  # #  #     #  # ### ### #  #  #  ###  ##  #  #

 ######################################################     


joining_rule_has_no_war = {
	type = joining_rules
	ai_will_do = {
		base = 0
		modifier = {
			add = 3
			has_government = neutrality
			has_war = no 
		}
	}
	trigger = {
		has_war = no
	}
	modifier = {
		improve_relations_maintain_cost_factor = -0.1
	}
}

joining_rule_has_no_offensive_war = {
	type = joining_rules
	ai_will_do = {
		base = 0
		modifier = {
			add = 2
			NOT = { tag = ENG }
			NOT = { tag = USA }
			OR = {
				has_government = democratic
				has_government = neutrality
			}
		}
	}
	trigger = {
		has_offensive_war = no
	}
	modifier = {
		defensive_war_stability_factor = 0.15
	}
}

########################################################

 ##  ###  ##   ##  ###   ##  ###  #  # ###  ##   ##  #   
#    #   #  # #    #  # #  # #  # #  #  #  #  # #  # #   
# ## ##  #  # # ## ###  #### ###  ####  #  #    #### #   
#  # #   #  # #  # #  # #  # #    #  #  #  #  # #  # #   
 ##  ###  ##   ##  #  # #  # #    #  # ###  ##  #  # ###

######################################################## 

joining_rule_neighbors_only = {
	type = joining_rules
	ai_will_do = {
		base = 0
		modifier = {
			add = 1
			has_government = neutrality
			has_war = no 
		}
	}
	
	trigger = {
		any_neighbor_country = {
			is_in_faction_with = FROM
		}
	}
	modifier = {
		enemy_justify_war_goal_time = 0.2
	}
}

joining_rule_same_continent_only = {
	type = joining_rules
	ai_will_do = {
		base = 0
	}
	can_remove = {
		faction_manifest_fulfillment > 0.75
	}
	trigger = {
		ROOT = { is_on_same_continent_as = FROM }
	}
	modifier = {
		enemy_justify_war_goal_time = 0.1
	}
}

joining_rule_africa_only = {
	type = joining_rules
	visible = {
		capital_scope = {
			is_on_continent = africa
		}
	}
	can_remove = {
		faction_manifest_fulfillment > 0.95
	}
	ai_will_do = {
		base = 0
		modifier = {
			add = 1
			is_faction_leader = yes 
			capital_scope = { is_on_continent = africa }
		}
	}

	trigger = {
		capital_scope = {
			is_on_continent = africa
		}
	}
	modifier = {
		enemy_justify_war_goal_time = 0.1
	}
}

joining_rule_americas_only = {
	type = joining_rules
	visible = {
		capital_scope = {
			OR = {
				is_on_continent = north_america
				is_on_continent = south_america
			}
		}
	}
	can_remove = {
		faction_manifest_fulfillment > 0.95
	}
	ai_will_do = {
		base = 0
	}

	trigger = {
		capital_scope = {
			OR = {
				is_on_continent = north_america
				is_on_continent = south_america
			}
		}
	}
	modifier = {
		enemy_justify_war_goal_time = 0.1
	}
}

joining_rule_china_only = {
	type = joining_rules
	visible = {
		capital_scope = {
			OR = {
				is_core_of = CHI
				is_core_of = PRC
			}
		}
	}
	can_remove = {
		faction_manifest_fulfillment > 0.95
	}
	ai_will_do = {
		base = 0
	}

	modifier = {
		army_core_defence_factor = 0.05
	}

	trigger = {
		custom_trigger_tooltip = {
			tooltip = has_chinese_capital_state_tt
			capital_scope = {
				OR = {
					is_core_of = CHI
					is_core_of = PRC
				}
			}
		}
	}
}

joining_rule_nordics_only = {
	type = joining_rules
	visible = {
		capital_scope = {
			OR = {
				region = 275 
				region = 10
				region = 11
				region = 192
				region = 276
				region = 191
				region = 277
				region = 278
				region = 13
				region = 161
				region = 36 
				region = 45 
				region = 12
				region = 265 
			}
		}
	}
	can_remove = {
		faction_manifest_fulfillment > 0.85
	}
	ai_will_do = {
		base = 0
	}

	modifier = {
		army_core_defence_factor = 0.05
	}

	trigger = {
		custom_trigger_tooltip = {
			tooltip = has_nordic_capital_state_tt
			capital_scope = {
				OR = {
					region = 275 
					region = 10
					region = 11
					region = 192
					region = 276
					region = 191
					region = 277
					region = 278
					region = 13
					region = 161
					region = 36 
					region = 45 
					region = 12
					region = 265 
				}
			}
		}
	}
}

joining_rule_balkans_only = {
	type = joining_rules

	visible = {
		OR = {
			original_tag = HUN
			original_tag = AUS
			original_tag = ROM 
			original_tag = TUR 
			original_tag = GRE 
			capital_scope = {
				OR = {
					state = 102
					state = 853
					state = 103
					state = 109
					state = 104
					state = 804
					state = 45
					state = 764
					state = 107
					state = 108
					state = 803
					state = 105
					state = 802
					state = 106
					state = 970
					state = 934
					state = 44
					state = 805
					state = 163
					state = 852
					state = 736
					state = 48
					state = 212
					state = 801
					state = 211
					state = 77
					state = 971
					state = 184
					state = 731
					state = 185
					state = 47
					state = 186
					state = 46
					state = 81
					state = 82
					state = 83
					state = 84
					state = 76
					state = 79
					state = 766
					state = 78
					state = 80
					state = 341
					state = 797  
				}
			}
		}
		
	}
	can_remove = {
		faction_manifest_fulfillment > 0.85
	}
	ai_will_do = {
		base = 0
	}

	modifier = {
		army_core_defence_factor = 0.05
	}

	trigger = {
		custom_trigger_tooltip = {
			tooltip = has_balkan_capital_state_tt
			capital_scope = {
				OR = {
					state = 102
					state = 853
					state = 103
					state = 109
					state = 104
					state = 804
					state = 45
					state = 764
					state = 107
					state = 108
					state = 803
					state = 105
					state = 802
					state = 106
					state = 970
					state = 934
					state = 44
					state = 805
					state = 163
					state = 852
					state = 736
					state = 48
					state = 212
					state = 801
					state = 211
					state = 77
					state = 971
					state = 184
					state = 731
					state = 185
					state = 47
					state = 186
					state = 46
					state = 81
					state = 82
					state = 83
					state = 84
					state = 76
					state = 79
					state = 766
					state = 78
					state = 80
					state = 341
					state = 797  
				}
			}
		}
	}
}

joining_rule_baltics_only = {
	type = joining_rules
	visible = {
		capital_scope = {
			OR = {
				region = 37
				state = 763 
				state = 784  
				state = 208  
				state = 209   
			}
		}
	}
	can_remove = {
		faction_manifest_fulfillment > 0.85
	}
	ai_will_do = {
		base = 0
	}

	modifier = {
		army_core_defence_factor = 0.05
	}

	trigger = {
		custom_trigger_tooltip = {
			tooltip = has_baltic_capital_state_tt
			capital_scope = {
				OR = {
					region = 37
					state = 763 
					state = 784  
					state = 208  
					state = 209   
				}
			}
		}
	}
}

joining_rule_islamic_only = {
	type = joining_rules
	visible = {
		OR = {
			original_tag = SAU
			original_tag = OMA
			original_tag = YEM
			original_tag = IRQ
			original_tag = PER
			original_tag = FSA
			original_tag = JOR
			original_tag = PAL
			original_tag = SYR
			original_tag = LEB
			original_tag = TUR
			original_tag = QAT
			original_tag = BHR
			original_tag = UAE
			original_tag = EGY
			original_tag = SUD
			original_tag = LBA
			original_tag = TUN
			original_tag = ALG
			original_tag = MOR
			original_tag = RIF
			original_tag = MAL
			original_tag = INS
			original_tag = MLD
			original_tag = BAN
			original_tag = PAK
			original_tag = WES
			original_tag = MRT
			original_tag = SOK
			original_tag = MLI
			original_tag = NGR
			original_tag = NGA
			original_tag = SOM
			original_tag = AFA
			original_tag = AZR
			original_tag = DAG
			original_tag = CIN
			original_tag = ALB
			original_tag = TAT
			original_tag = BSK
			original_tag = BUK
			original_tag = KHI
			original_tag = UZB
			original_tag = KAZ
			original_tag = TAJ
			original_tag = KYR
			original_tag = TMS
			original_tag = KKP
			original_tag = SIN
			original_tag = KAS                  
			original_tag = CRI              
			original_tag = KOS              
			original_tag = KUR      
			original_tag = BLC      
			original_tag = IMO      
			original_tag = KLT      
			original_tag = KBK      
			original_tag = DJI      
			original_tag = HAR      
			original_tag = SEN      
			original_tag = GAM      
			original_tag = GNB      
			original_tag = SIE      
			original_tag = VOL      
			original_tag = GNA      
			original_tag = XSM      
			original_tag = SIK
			original_tag = KHM
			original_tag = GSM
			original_tag = NXM
			original_tag = KUM
			original_tag = SAB
			original_tag = BRN
			original_tag = CHM  
			original_tag = AFG
		}
	}
	can_remove = {
		faction_manifest_fulfillment > 0.75
	}
	ai_will_do = {
		base = 0
	}

	modifier = {
		stability_factor = 0.05
	}

	trigger = {
		custom_trigger_tooltip = {
			tooltip = is_islamic_country_tt
			OR = {
				original_tag = SAU
				original_tag = OMA
				original_tag = YEM
				original_tag = IRQ
				original_tag = PER
				original_tag = FSA
				original_tag = JOR
				original_tag = PAL
				original_tag = SYR
				original_tag = LEB
				original_tag = TUR
				original_tag = QAT
				original_tag = BHR
				original_tag = UAE
				original_tag = EGY
				original_tag = SUD
				original_tag = LBA
				original_tag = TUN
				original_tag = ALG
				original_tag = MOR
				original_tag = RIF
				original_tag = MAL
				original_tag = INS
				original_tag = MLD
				original_tag = BAN
				original_tag = PAK
				original_tag = WES
				original_tag = MRT
				original_tag = SOK
				original_tag = MLI
				original_tag = NGR
				original_tag = NGA
				original_tag = SOM
				original_tag = AFA
				original_tag = AZR
				original_tag = DAG
				original_tag = CIN
				original_tag = ALB
				original_tag = TAT
				original_tag = BSK
				original_tag = BUK
				original_tag = KHI
				original_tag = UZB
				original_tag = KAZ
				original_tag = TAJ
				original_tag = KYR
				original_tag = TMS
				original_tag = KKP
				original_tag = SIN
				original_tag = KAS                  
				original_tag = CRI              
				original_tag = KOS              
				original_tag = KUR      
				original_tag = BLC      
				original_tag = IMO      
				original_tag = KLT      
				original_tag = KBK      
				original_tag = DJI      
				original_tag = HAR      
				original_tag = SEN      
				original_tag = GAM      
				original_tag = GNB      
				original_tag = SIE      
				original_tag = VOL      
				original_tag = GNA      
				original_tag = XSM      
				original_tag = SIK
				original_tag = KHM
				original_tag = GSM
				original_tag = NXM
				original_tag = KUM
				original_tag = SAB
				original_tag = BRN
				original_tag = CHM  
				original_tag = AFG
			}
		}
	}
}

joining_rule_hispanic_only = {
	type = joining_rules
	visible = {
		OR = {
			original_tag = MEX
			original_tag = RIG
			original_tag = YUC
			original_tag = ARG
			original_tag = CHL
			original_tag = PRU
			original_tag = PAR
			original_tag = URG
			original_tag = BOL
			original_tag = ECU
			original_tag = COL
			original_tag = VEN
			original_tag = PAN
			original_tag = PUE
			original_tag = DOM
			original_tag = CUB
			original_tag = PAN
			original_tag = COS
			original_tag = NIC
			original_tag = HON
			original_tag = ELS
			original_tag = EQG
			original_tag = SPR
		}
	}
	can_remove = {
		faction_manifest_fulfillment > 0.7
	}
	ai_will_do = {
		base = 0
	}

	modifier = {
		war_support_factor = 0.05
	}

	trigger = {
		custom_trigger_tooltip = {
			tooltip = is_hispanic_country_tt
			OR = {
				original_tag = MEX
				original_tag = RIG
				original_tag = YUC
				original_tag = ARG
				original_tag = CHL
				original_tag = PRU
				original_tag = PAR
				original_tag = URG
				original_tag = BOL
				original_tag = ECU
				original_tag = COL
				original_tag = VEN
				original_tag = PAN
				original_tag = PUE
				original_tag = DOM
				original_tag = CUB
				original_tag = PAN
				original_tag = COS
				original_tag = NIC
				original_tag = HON
				original_tag = ELS
				original_tag = EQG
				original_tag = SPR
			}
		}
	}
}

joining_rule_east_asia_only = {
	type = joining_rules
	ai_will_do = {
		base = 0
	}
	visible = {
		OR = {
			original_tag = JAP
			original_tag = KOR
			WTT_is_chinese_country = yes 
		}
	}
	can_remove = {
		faction_manifest_fulfillment > 0.95	
	}
	trigger = {
		OR = {
			original_tag = JAP
			original_tag = KOR
			WTT_is_chinese_country = yes 
		}
	}
}

joining_rule_asia_pacific_ocenania_only = {
	type = joining_rules
	ai_will_do = {
		base = 0
	}
	visible = {
		OR = {
			capital_scope = { is_on_continent = asia }
			capital_scope = { is_on_continent = australia }
		}
	}
	
	trigger = {
		OR = {
			capital_scope = { is_on_continent = asia }
			capital_scope = { is_on_continent = australia }
		}
	}
}

joining_rule_asia_only = {
	type = joining_rules
	ai_will_do = {
		base = 0
	}
	visible = {
		capital_scope = { is_on_continent = asia }
			
	}
	
	trigger = {
		capital_scope = { is_on_continent = asia }
	}
}
