DIPLOMACY_JOIN_FACTION_ENABLE_TRIGGER = {
	if = {
		limit = { has_global_flag = rt56rp_gr_bakedfaction_gflag   ROOT = { is_ai = no } }

		if = { 
			limit = { ROOT = { has_idea = classified_rank_AI   is_ai = no } } # Rank hasn't updated, no joining allowed
			
			custom_trigger_tooltip = { tooltip = dr_player_with_ai_rank1   date > 3000.01.01 }
		}
		else = {
			AND = {
				custom_trigger_tooltip = { tooltip = dr_blank }
				
				# Can't have more than 2 majors per faction except if forced through war
				if = {
					# if faction leader is one of the majors
					limit = {
						ROOT = { OR = { tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						FROM = { tag = GER }
						FROM = {
							OR = {
								is_ally_with = SOV   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = USA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						ROOT = { OR = { tag = GER   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						FROM = { tag = SOV }
						FROM = {
							OR = {
								is_ally_with = GER   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = USA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						ROOT = { OR = { tag = GER   tag = SOV   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						FROM = { tag = ENG }
						FROM = {
							OR = {
								is_ally_with = GER   is_ally_with = SOV   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = USA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						ROOT = { OR = { tag = GER   tag = SOV   tag = ENG   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						FROM = { tag = FRA }
						FROM = {
							OR = {
								is_ally_with = GER   is_ally_with = SOV   is_ally_with = ENG   is_ally_with = ITA   is_ally_with = USA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						ROOT = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						FROM = { tag = ITA }
						FROM = {
							OR = {
								is_ally_with = GER   is_ally_with = SOV   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = USA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						ROOT = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = JAP   has_idea = dr_china_major_idea } }
						FROM = { tag = USA }
						FROM = {
							OR = {
								is_ally_with = GER   is_ally_with = SOV   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						ROOT = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   has_idea = dr_china_major_idea } }
						FROM = { tag = JAP }
						FROM = {
							OR = {
								is_ally_with = GER   is_ally_with = SOV   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = USA
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						ROOT = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP } }
						FROM = { has_idea = dr_china_major_idea }
						FROM = { OR = { is_ally_with = GER   is_ally_with = SOV   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = USA   is_ally_with = JAP } }
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if you're a major and the faction you want to join has at least 2 majors
					limit = {
						ROOT = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP } }
						count_triggers = {
							amount = 2
							FROM = { is_ally_with = GER }
							FROM = { is_ally_with = SOV }
							FROM = { is_ally_with = ENG }
							FROM = { is_ally_with = FRA }
							FROM = { is_ally_with = ITA }
							FROM = { is_ally_with = USA }
							FROM = { is_ally_with = JAP }
							FROM = {
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors2   date > 3000.01.01 }
				}
				
				# Not enough room in faction
				custom_trigger_tooltip = {
					tooltip = dr_join_faction
					check_variable = { 
						var = ROOT.dr_country_score_var
						value = FROM.dr_faction_space_avail_var
						compare = less_than_or_equals
					}
				}

			}
		}

	}
}



DIPLOMACY_OFFER_JOIN_FACTION_ENABLE_TRIGGER = {
	if = {
		limit = { has_global_flag = rt56rp_gr_bakedfaction_gflag   ROOT = { is_ai = no } }

		if = { 
			limit = { FROM = { has_idea = classified_rank_AI   is_ai = no } } # Rank hasn't updated, no joining allowed
			
			custom_trigger_tooltip = { tooltip = dr_player_with_ai_rank2   date > 3000.01.01 }
		}
		else = {
			AND = {
				custom_trigger_tooltip = { tooltip = dr_blank }
				
				# Can't have more than 2 majors per faction except if forced through war
				if = {
					# if faction leader is one of the majors
					limit = {
						FROM = { OR = { tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						ROOT = { tag = GER }
						ROOT = {
							OR = {
								is_ally_with = SOV   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = USA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						FROM = { OR = { tag = GER   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						ROOT = { tag = SOV }
						ROOT = {
							OR = {
								is_ally_with = GER   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = USA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						FROM = { OR = { tag = GER   tag = SOV   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						ROOT = { tag = ENG }
						ROOT = {
							OR = {
								is_ally_with = GER   is_ally_with = SOV   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = USA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						FROM = { OR = { tag = GER   tag = SOV   tag = ENG   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						ROOT = { tag = FRA }
						ROOT = {
							OR = {
								is_ally_with = GER   is_ally_with = SOV   is_ally_with = ENG   is_ally_with = ITA   is_ally_with = USA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						FROM = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						ROOT = { tag = ITA }
						ROOT = {
							OR = {
								is_ally_with = GER   is_ally_with = SOV   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = USA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						FROM = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = JAP   has_idea = dr_china_major_idea } }
						ROOT = { tag = USA }
						ROOT = {
							OR = {
								is_ally_with = GER   is_ally_with = SOV   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = JAP
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						FROM = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   has_idea = dr_china_major_idea } }
						ROOT = { tag = JAP }
						ROOT = {
							OR = {
								is_ally_with = GER   is_ally_with = SOV   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = USA
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if faction leader is one of the majors
					limit = {
						FROM = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP } }
						ROOT = { has_idea = dr_china_major_idea }
						ROOT = { OR = { is_ally_with = GER   is_ally_with = SOV   is_ally_with = ENG   is_ally_with = FRA   is_ally_with = ITA   is_ally_with = USA   is_ally_with = JAP } }
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors1   date > 3000.01.01 }
				}
				else_if = {
					# if you're a major and the faction you want to join has at least 2 majors
					limit = {
						FROM = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						count_triggers = {
							amount = 2
							ROOT = { is_ally_with = GER }
							ROOT = { is_ally_with = SOV }
							ROOT = { is_ally_with = ENG }
							ROOT = { is_ally_with = FRA }
							ROOT = { is_ally_with = ITA }
							ROOT = { is_ally_with = USA }
							ROOT = { is_ally_with = JAP }
							ROOT = {
								any_country = { 
									has_idea = dr_china_major_idea
									is_ally_with = PREV
								}
							}
						}
					}
					custom_trigger_tooltip = { tooltip = dr_join_faction_too_many_majors2   date > 3000.01.01 }
				}

				# Not enough room in faction
				custom_trigger_tooltip = {
					tooltip = dr_join_faction
					check_variable = { 
						var = FROM.dr_country_score_var
						value = ROOT.dr_faction_space_avail_var
						compare = less_than_or_equals
					}
				}

			}
		}

	}
}