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

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

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

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

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

joining_rule_non_communist = {
	type = joining_rules
	visible = {
		NOT = { has_government = terrorist }
	}
	ai_will_do = {
		base = 0
		modifier = {
			add = 1
			NOT = { has_government = terrorist }
		}
		modifier = {
			add = 1
			has_government = criminal
		}
	}
	available = {
		IF = {
			limit = {
				has_faction_template = faction_template_allies
			}
			NOT = {
				any_enemy_country = {
					is_major = yes
					has_government = criminal
				}
			}
		}
	}
	can_remove = {
		
	}
	trigger = {
		NOT = {
			has_government = terrorist 
		}
		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 = criminal
	}
	trigger = {
		has_government = criminal
		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 = council
	}
	trigger = {
		OR = {
			has_government = council
			has_government = monarchy
		}
		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 = terrorist
	}
	trigger = {
		has_government = terrorist
		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 = monarchy
			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
			OR = {
				has_government = council
				has_government = monarchy
			}
		}
	}
	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 = monarchy
			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 = {
			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 = {
	}
	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
		}
	}
}

joining_rule_hispanic_only = {
	type = joining_rules
	visible = {

	}
	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
		}
	}
}

joining_rule_east_asia_only = {
	type = joining_rules
	ai_will_do = {
		base = 0
	}
	visible = {
	}
	can_remove = {
		faction_manifest_fulfillment > 0.95	
	}
	trigger = {
	}
}

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 }
	}
}
