is_ai1 = { 
	is_ai = no
}

DIPLOMACY_JOIN_FACTION_ENABLE_TRIGGER = {
	if = {
		limit = {
			has_global_flag = wia_faction_limiter_enabled_gflag
		}

		if = {
			limit = {
				has_country_flag = rank_game_started
			}

			custom_trigger_tooltip = { tooltip = wia_faction_not_allowed_ai_tt   date > 3000.01.01 }
		}

		else = {
			custom_trigger_tooltip = {
				tooltip = wia_faction_not_allowed_size_tt
				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 = wia_faction_limiter_enabled_gflag
		}

		if = {
			limit = {
				has_country_flag = rank_game_started
			}

			custom_trigger_tooltip = { tooltip = wia_faction_not_allowed_ai_tt   date > 3000.01.01 }

			else = {
				custom_trigger_tooltip = {
		    		tooltip = wia_faction_not_allowed_size_tt2
		    		check_variable = { 
						var = FROM.dr_country_score_var
						value = ROOT.dr_faction_space_avail_var
						compare = less_than_or_equals
					}
		    	}
		    }
		}
	}
}

DIPLOMACY_WAR_ENABLE_TRIGGER = {
	if = {
		limit = { has_global_flag = wia_war_limiter_enabled_gflag   ROOT = { is_ai = no } }

		AND = {
			custom_trigger_tooltip = { tooltip = wia_blank }
		    if = {
		    	limit = {
		    		has_idea = classified_rank_S
		    	}
		    	if = {
		    		limit = {date < 1939.01.01}
		    		custom_trigger_tooltip = { tooltip = war_limit_s   date > 1939.01.01 }
		    	}
		    }
		    else_if = {
		    	limit = {
		    		has_idea = classified_rank_A
		    	}
		    	if = {
		    		limit = {date < 1939.01.01}
		    		custom_trigger_tooltip = { tooltip = war_limit_a   date > 1939.01.01 }
		    	}
		    }
		    else_if = {
		    	limit = {
		    		has_idea = classified_rank_B
		    	}
		    	if = {
		    		limit = {date < 1939.01.01}
		    		custom_trigger_tooltip = { tooltip = war_limit_b   date > 1939.01.01 }
		    	}
		    }
		    else_if = {
		    	limit = {
		    		has_idea = classified_rank_C
		    	}
		    	if = {
		    		limit = {date < 1939.01.01}
		    		custom_trigger_tooltip = { tooltip = war_limit_c   date > 1938.01.01 }
		    	}
		    }
		    else_if = {
		    	limit = {
		    		has_idea = classified_rank_A
		    	}
		    	if = {
		    		limit = {date < 1939.01.01}
		    		custom_trigger_tooltip = { tooltip = war_limit_d   date > 1937.01.01 }
		    	}
		    }

			if = { 
	        	limit = { 
	        		ROOT = {
	        			OR = {
	        				has_idea = classified_rank_AI
	        				AND = {
	        					NOT = { has_idea = classified_rank_S }
	        					NOT = { has_idea = classified_rank_A }
	        					NOT = { has_idea = classified_rank_B }
	        					NOT = { has_idea = classified_rank_C }
	        					NOT = { has_idea = classified_rank_D }
	        				}
	        			}
	        			is_ai = no
	        		}
	        	}
	        	custom_trigger_tooltip = { tooltip = wia_faction_not_allowed_ai_tt   date > 3000.01.01 }
	        }

			if = {
				limit = {
					check_variable = { ROOT.dr_faction_space_avail_var < -1 }
				}
				custom_trigger_tooltip = { tooltip = war_limit_oversized_faction   date > 3000.01.01 }					
			}
	    }
	}	
}