# Aggressor (ROOT); Defender (FROM)
DIPLOMACY_WAR_ENABLE_TRIGGER = {
	if = {
		limit = { has_global_flag = rt56rp_gr_bakedwar_gflag   ROOT = { is_ai = no } }

		AND = { # all conditions must be true for the declare war button to be enabled
			custom_trigger_tooltip = { tooltip = dr_blank }

			if = { # rank-based conditions (e.g. declare war dates)
				limit = { has_idea = classified_rank_X } # X RANK

				AND = {
					if = { # allowed by date to declare on ai
						limit = { AND = { FROM = { is_ai = yes }   date < 1941.01.01 } }
						custom_trigger_tooltip = { tooltip = dr_ai_war_x   date > 1941.01.01 }
					}
					if = { # allowed by date to declare on players
						limit = { AND = { FROM = { is_ai = no }   date < 1941.01.01 } }
						custom_trigger_tooltip = { tooltip = dr_player_war_x   date > 1941.01.01 }
					}
				}
				
			}
			else_if = {
				limit = { has_idea = classified_rank_S } # S RANK

				AND = {
					if = { # allowed by date to declare on ai
						limit = { AND = { FROM = { is_ai = yes }   date < 1940.01.01 } }
						custom_trigger_tooltip = { tooltip = dr_ai_war_s   date > 1940.01.01 }
					}
					if = { # allowed by date to declare on players
						limit = { AND = { FROM = { is_ai = no }   date < 1940.01.01 } }
						custom_trigger_tooltip = { tooltip = dr_player_war_s   date > 1940.01.01 }
					}
				}
			}
			else_if = {
				limit = { has_idea = classified_rank_A } # A RANK

				AND = {
					if = { # allowed by date to declare on ai
						limit = { AND = { FROM = { is_ai = yes }   date < 1938.07.01 } }
						custom_trigger_tooltip = { tooltip = dr_ai_war_a   date > 1938.07.01 }
					}
					if = { # allowed by date to declare on players
						limit = { AND = { FROM = { is_ai = no }   date < 1939.01.01 } }
						custom_trigger_tooltip = { tooltip = dr_player_war_a   date > 1939.01.01 }
					}
				}
			}
			else_if = {
				limit = { has_idea = classified_rank_B } # B RANK

				AND = {
					if = { # allowed by date to declare on ai
						limit = { AND = { FROM = { is_ai = yes }   date < 1938.01.01 } }
						custom_trigger_tooltip = { tooltip = dr_ai_war_b   date > 1938.01.01 }
					}
					if = { # allowed by date to declare on players
						limit = { AND = { FROM = { is_ai = no }   date < 1938.07.01 } }
						custom_trigger_tooltip = { tooltip = dr_player_war_b   date > 1938.07.01 }
					}
				}
			}
			else_if = {
				limit = { has_idea = classified_rank_C } # C RANK

				AND = {
					if = { # allowed by date to declare on ai
						limit = { AND = { FROM = { is_ai = yes }   date < 1937.07.01 } }
						custom_trigger_tooltip = { tooltip = dr_ai_war_c   date > 1937.07.01 }
					}
					if = { # allowed by date to declare on players
						limit = { AND = { FROM = { is_ai = no }   date < 1938.01.01 } }
						custom_trigger_tooltip = { tooltip = dr_player_war_c   date > 1938.01.01 }
					}
				}
			}
			else_if = {
				limit = { has_idea = classified_rank_D } # D RANK

				AND = {
					if = { # allowed by date to declare on ai
						limit = { AND = { FROM = { is_ai = yes }   date < 1937.01.01 } }
						custom_trigger_tooltip = { tooltip = dr_ai_war_d   date > 1937.01.01 }
					}
					if = { # allowed by date to declare on players
						limit = { AND = { FROM = { is_ai = no }   date < 1937.07.01 } }
						custom_trigger_tooltip = { tooltip = dr_player_war_d   date > 1937.07.01 }
					}
				}
			}
			else_if = {
				limit = { has_idea = classified_rank_E } # E RANK

				AND = {
					if = { # allowed by date to declare on ai
						limit = { AND = { FROM = { is_ai = yes }   date < 1936.07.01 } }
						custom_trigger_tooltip = { tooltip = dr_ai_war_e   date > 1936.07.01 }
					}
					if = { # allowed by date to declare on players
						limit = { AND = { FROM = { is_ai = no }   date < 1937.07.01 } }
						custom_trigger_tooltip = { tooltip = dr_player_war_e   date > 1937.07.01 }
					}
				}
			}
			else_if = {
				limit = { has_idea = classified_rank_F } # F RANK

				AND = {
					if = { # allowed by date to declare on ai
						limit = { AND = { FROM = { is_ai = yes }   date < 1936.01.01 } }
						custom_trigger_tooltip = { tooltip = dr_ai_war_f   date > 1936.01.01 }
					}
					if = { # allowed by date to declare on players
						limit = { AND = { FROM = { is_ai = no }   date < 1937.07.01 } }
						custom_trigger_tooltip = { tooltip = dr_player_war_f   date > 1937.07.01 }
					}
				}
			}

			if = { # would/could this lead to a major vs major war before July 1st 1939
				limit = {
					OR = {
						# major declaring on major
						AND = {
							ROOT = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
							FROM = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						}
						# allied minor declaring on allied minor
						AND = {
							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
									any_country = { 
										has_idea = dr_china_major_idea
										is_ally_with = PREV
									} 
								} 
							}
							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
									any_country = { 
										has_idea = dr_china_major_idea
										is_ally_with = PREV
									}
								}
							}
						}
						# allied minor declaring on major
						AND = {
							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
									any_country = { 
										has_idea = dr_china_major_idea
										is_ally_with = PREV
									}
								}
							}
							FROM = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
						}
						# major declaring on allied minor
						AND = {
							ROOT = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP   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
									any_country = { 
										has_idea = dr_china_major_idea
										is_ally_with = PREV
									}
								}
							}
						}
						# major declaring on minor that is guaranteed
						AND = {
							NOT = { FROM = { is_guaranteed_by = ROOT } }
							ROOT = { OR = { tag = GER   tag = SOV   tag = ENG   tag = FRA   tag = ITA   tag = USA   tag = JAP   has_idea = dr_china_major_idea } }
							FROM = {
								OR = {
									is_guaranteed_by = GER   is_guaranteed_by = SOV   is_guaranteed_by = ENG   is_guaranteed_by = FRA   is_guaranteed_by = ITA   is_guaranteed_by = USA   is_guaranteed_by = JAP
									any_country = { 
										has_idea = dr_china_major_idea
										has_guaranteed = PREV
									}
								}
							}
						}
					}
					date < 1939.07.01
				}
				custom_trigger_tooltip = { tooltip = dr_major_v_major_war   date > 1939.07.01 }
			}
			
			if = { # dogpiling
				limit = { FROM = { OR = { has_idea = rt56rp_war_declared   has_idea = rt56rp_war_attacker } } }
				custom_trigger_tooltip = { tooltip = dr_dogpiling   date > 3000.01.01 }
			}

			# faction over limit
			if = {
				limit = {
					check_variable = { ROOT.dr_faction_space_avail_var < -1 }
				}
				custom_trigger_tooltip = { tooltip = dr_war_faction_over_limit   date > 3000.01.01 }					
			}

			if = { # rank hasn't updated, no wars allowed
				limit = { 
					ROOT = {
						OR = {
							has_idea = classified_rank_AI
							AND = {
								NOT = { has_idea = classified_rank_X }
								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 }
								NOT = { has_idea = classified_rank_E }
								NOT = { has_idea = classified_rank_F }
							}
						}
						is_ai = no
					}
				}
				custom_trigger_tooltip = { tooltip = dr_player_with_ai_rank1   date > 3000.01.01 }
			}
			
		}

	}
}
