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

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

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

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