has_selected_any_idea_group = {
	any_of = {
		array = selected_idea_groups
		value = value_temp
		index = index_temp
		NOT = { check_variable = { value_temp = 0 } }
	}
}

can_select_any_idea_group = {
	OR = {
		is_ai = no
		AND = {
			is_ai = yes
			NOT = { has_global_flag = eu4_like_ideas_ai_disabled }
			OR = {
				AND = {
					NOT = { has_global_flag = eu4_like_ideas_ai_only_majors }
					NOT = { has_global_flag = eu4_like_ideas_ai_only_minors }
					OR = {
						NOT = { has_global_flag = eu4_like_ideas_ai_idea_usage_delayed }
						AND = {
							has_global_flag = eu4_like_ideas_ai_idea_usage_delayed
							meta_trigger = {
								text = {
									date > [DATE]
								}
								DATE = "[?global.eu4_like_ideas_AI_idea_usage_delay.GetDateStringNoHour]"
							}
						}
					}
				}
				AND = {
					is_major = yes
					has_global_flag = eu4_like_ideas_ai_only_majors
					OR = {
						NOT = { has_global_flag = eu4_like_ideas_ai_idea_usage_delayed }
						AND = {
							has_global_flag = eu4_like_ideas_ai_idea_usage_delayed
							meta_trigger = {
								text = {
									date > [DATE]
								}
								DATE = "[?global.eu4_like_ideas_AI_idea_usage_delay.GetDateStringNoHour]"
							}
						}
					}
				}
				AND = {
					is_major = no
					has_global_flag = eu4_like_ideas_ai_only_minors
					OR = {
						NOT = { has_global_flag = eu4_like_ideas_ai_idea_usage_delayed }
						AND = {
							has_global_flag = eu4_like_ideas_ai_idea_usage_delayed
							meta_trigger = {
								text = {
									date > [DATE]
								}
								DATE = "[?global.eu4_like_ideas_AI_idea_usage_delay.GetDateStringNoHour]"
							}
						}
					}
				}
			}
		}
	}
	OR = {
		AND = {
			has_global_flag = eu4_like_ideas_test_flag
			is_in_array = { selected_idea_groups = 0 }
		}
		AND = {
			check_variable = { selected_idea_groups^0 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_1.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { selected_idea_groups^1 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_2.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 2 }
			check_variable = { selected_idea_groups^2 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_3.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 2 }
			check_variable = { selected_idea_groups^3 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_4.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 4 }
			check_variable = { selected_idea_groups^4 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_5.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 4 }
			check_variable = { selected_idea_groups^5 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_6.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 6 }
			check_variable = { selected_idea_groups^6 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_7.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 6 }
			check_variable = { selected_idea_groups^7 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_8.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 8 }
			check_variable = { selected_idea_groups^8 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_9.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 8 }
			check_variable = { selected_idea_groups^9 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_10.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 10 }
			check_variable = { selected_idea_groups^10 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_11.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 10 }
			check_variable = { selected_idea_groups^11 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_12.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 12 }
			check_variable = { selected_idea_groups^12 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_13.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 12 }
			check_variable = { selected_idea_groups^13 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_14.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 14 }
			check_variable = { selected_idea_groups^14 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_15.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 14 }
			check_variable = { selected_idea_groups^15 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_16.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 16 }
			check_variable = { selected_idea_groups^16 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_17.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 16 }
			check_variable = { selected_idea_groups^17 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_18.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 18 }
			check_variable = { selected_idea_groups^18 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_19.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 18 }
			check_variable = { selected_idea_groups^19 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_20.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 20 }
			check_variable = { selected_idea_groups^20 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_21.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 20 }
			check_variable = { selected_idea_groups^21 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_22.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 22 }
			check_variable = { selected_idea_groups^22 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_23.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 22 }
			check_variable = { selected_idea_groups^23 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_24.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 24 }
			check_variable = { selected_idea_groups^24 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_25.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 24 }
			check_variable = { selected_idea_groups^25 = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_26.GetDateStringNoHour]"
			}
		}
	}
}

can_select_any_idea = {
	OR = {
		is_ai = no
		AND = {
			is_ai = yes
			NOT = { has_global_flag = eu4_like_ideas_ai_disabled }
			NOT = { AI_might_want_to_change_to_a_better_economy_law = yes }
			NOT = { AI_might_want_to_change_to_a_better_conscription_law = yes }
			OR = {
				AND = {
					NOT = { has_global_flag = eu4_like_ideas_ai_only_majors }
					NOT = { has_global_flag = eu4_like_ideas_ai_only_minors }
					OR = {
						NOT = { has_global_flag = eu4_like_ideas_ai_idea_usage_delayed }
						AND = {
							has_global_flag = eu4_like_ideas_ai_idea_usage_delayed
							meta_trigger = {
								text = {
									date > [DATE]
								}
								DATE = "[?global.eu4_like_ideas_AI_idea_usage_delay.GetDateStringNoHour]"
							}
						}
					}
				}
				AND = {
					is_major = yes
					has_global_flag = eu4_like_ideas_ai_only_majors
					OR = {
						NOT = { has_global_flag = eu4_like_ideas_ai_idea_usage_delayed }
						AND = {
							has_global_flag = eu4_like_ideas_ai_idea_usage_delayed
							meta_trigger = {
								text = {
									date > [DATE]
								}
								DATE = "[?global.eu4_like_ideas_AI_idea_usage_delay.GetDateStringNoHour]"
							}
						}
					}
				}
				AND = {
					is_major = no
					has_global_flag = eu4_like_ideas_ai_only_minors
					OR = {
						NOT = { has_global_flag = eu4_like_ideas_ai_idea_usage_delayed }
						AND = {
							has_global_flag = eu4_like_ideas_ai_idea_usage_delayed
							meta_trigger = {
								text = {
									date > [DATE]
								}
								DATE = "[?global.eu4_like_ideas_AI_idea_usage_delay.GetDateStringNoHour]"
							}
						}
					}
				}
			}
		}
	}
	has_political_power > idea_cost_var
	OR = {
		AND = {
			NOT = { check_variable = { selected_idea_groups^0 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^0]"
			}
		}
		AND = {
			NOT = { check_variable = { selected_idea_groups^1 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^1]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 2 }
			NOT = { check_variable = { selected_idea_groups^2 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^2]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 2 }
			NOT = { check_variable = { selected_idea_groups^3 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^3]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 4 }
			NOT = { check_variable = { selected_idea_groups^4 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^4]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 4 }
			NOT = { check_variable = { selected_idea_groups^5 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^5]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 6 }
			NOT = { check_variable = { selected_idea_groups^6 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^6]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 6 }
			NOT = { check_variable = { selected_idea_groups^7 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^7]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 8 }
			NOT = { check_variable = { selected_idea_groups^8 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^8]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 8 }
			NOT = { check_variable = { selected_idea_groups^9 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^9]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 10 }
			NOT = { check_variable = { selected_idea_groups^10 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^10]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 10 }
			NOT = { check_variable = { selected_idea_groups^11 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^11]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 12 }
			NOT = { check_variable = { selected_idea_groups^12 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^12]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 12 }
			NOT = { check_variable = { selected_idea_groups^13 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^13]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 14 }
			NOT = { check_variable = { selected_idea_groups^14 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^14]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 14 }
			NOT = { check_variable = { selected_idea_groups^15 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^15]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 16 }
			NOT = { check_variable = { selected_idea_groups^16 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^16]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 16 }
			NOT = { check_variable = { selected_idea_groups^17 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^17]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 18 }
			NOT = { check_variable = { selected_idea_groups^18 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^18]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 18 }
			NOT = { check_variable = { selected_idea_groups^19 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^19]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 20 }
			NOT = { check_variable = { selected_idea_groups^20 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^20]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 20 }
			NOT = { check_variable = { selected_idea_groups^21 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^21]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 22 }
			NOT = { check_variable = { selected_idea_groups^22 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^22]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 22 }
			NOT = { check_variable = { selected_idea_groups^23 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^23]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 24 }
			NOT = { check_variable = { selected_idea_groups^24 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^24]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 24 }
			NOT = { check_variable = { selected_idea_groups^25 = 0 } }
			meta_trigger = {
				text = {
					check_variable = { completed_ideas_of_group_[GROUP] < 7 }
				}
				GROUP = "[?selected_idea_groups^25]"
			}
		}
	}
}

AI_is_set_to_become_communist = {
	OR = {
		AND = {
			tag = SOV
			OR = {
				has_game_rule = {
					rule = SOV_ai_behavior
					option = DEFAULT
				}
				has_game_rule = {
					rule = SOV_ai_behavior
					option = HISTORICAL
				}
				has_game_rule = {
					rule = SOV_ai_behavior
					option = LEFT_OPPOSITION
				}
				has_game_rule = {
					rule = SOV_ai_behavior
					option = LEFT_OPPOSITION_COOPERATIVE
				}
				has_game_rule = {
					rule = SOV_ai_behavior
					option = RIGHT_OPPOSITION
				}
				has_game_rule = {
					rule = SOV_ai_behavior
					option = RIGHT_OPPOSITION_COOPERATIVE
				}
				has_country_flag = SOV_AI_RANDOM_COMMUNIST_HISTORICAL
				has_country_flag = SOV_AI_RANDOM_COMMUNIST_LEFT_OPPOSITION
				has_country_flag = SOV_AI_RANDOM_COMMUNIST_LEFT_OPPOSITION_COOPERATIVE
				has_country_flag = SOV_AI_RANDOM_COMMUNIST_RIGHT_OPPOSITION
				has_country_flag = SOV_AI_RANDOM_COMMUNIST_RIGHT_OPPOSITION_COOPERATIVE
			}
		}
		AND = {
			tag = JAP
			OR = {
				has_game_rule = {
					rule = JAP_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = JAP_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = FRA
			OR = {
				has_game_rule = {
					rule = FRA_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = FRA_AI_COMMUNIST
			}
		}
		AND = {
			tag = POL
			OR = {
				has_game_rule = {
					rule = POL_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = POL_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = AST
			OR = {
				has_game_rule = {
					rule = AST_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = AST_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = CAN
			OR = {
				has_game_rule = {
					rule = CAN_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = CAN_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = SAF
			OR = {
				has_game_rule = {
					rule = SAF_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = SAF_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = NZL
			OR = {
				has_game_rule = {
					rule = NZL_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = NZL_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = RAJ
			OR = {
				has_game_rule = {
					rule = RAJ_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = RAJ_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = HUN
			OR = {
				has_game_rule = {
					rule = HUN_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = HUN_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = ROM
			OR = {
				has_game_rule = {
					rule = ROM_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = ROM_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = YUG
			OR = {
				has_game_rule = {
					rule = YUG_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = YUG_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = CZE
			OR = {
				has_game_rule = {
					rule = CZE_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = CZE_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = PRC
			OR = {
				has_game_rule = {
					rule = PRC_ai_behavior
					option = HISTORICAL
				}
				has_country_flag = PRC_AI_RANDOM_HISTORICAL
			}
		}
		AND = {
			tag = ENG
			OR = {
				has_game_rule = {
					rule = ENG_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = ENG_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = USA
			OR = {
				has_game_rule = {
					rule = USA_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = USA_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = HOL
			OR = {
				has_game_rule = {
					rule = HOL_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = HOL_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = MEX
			OR = {
				has_game_rule = {
					rule = MEX_ai_behavior
					option = SOVIET_REPUBLIC
				}
				has_game_rule = {
					rule = MEX_ai_behavior
					option = CARDENISMO
				}
				has_country_flag = MEX_AI_SOVIET_REPUBLIC
				has_country_flag = MEX_AI_CARDENISMO
			}
		}
		AND = {
			tag = SPR
			OR = {
				has_game_rule = {
					rule = SPR_ai_behavior
					option = ANARCHIST
				}
				has_game_rule = {
					rule = SPR_ai_behavior
					option = INDEPENDENT_COMMUNIST
				}
				has_game_rule = {
					rule = SPR_ai_behavior
					option = STALINIST
				}
				has_country_flag = SPR_AI_RANDOM_ANARCHIST
				has_country_flag = SPR_AI_RANDOM_INDEPENDENT_COMMUNIST
				has_country_flag = SPR_AI_RANDOM_STALINIST
			}
		}
		AND = {
			tag = POR
			OR = {
				has_game_rule = {
					rule = POR_ai_behavior
					option = COMMUNIST_COMINTERN
				}
				has_game_rule = {
					rule = POR_ai_behavior
					option = COMMUNIST_INDEPENDENT
				}
				has_country_flag = POR_AI_RANDOM_COMMUNIST_COMINTERN
				has_country_flag = POR_AI_RANDOM_COMMUNIST_INDEPENDENT
			}
		}
		AND = {
			tag = GRE
			OR = {
				has_game_rule = {
					rule = GRE_ai_behavior
					option = COMMUNIST
				}
				has_game_rule = {
					rule = GRE_ai_behavior
					option = COMMUNIST_ALTERNATE
				}
				has_country_flag = GRE_AI_RANDOM_COMMUNIST
				has_country_flag = GRE_AI_RANDOM_COMMUNIST_ALTERNATE
			}
		}
		AND = {
			tag = BUL
			OR = {
				has_game_rule = {
					rule = BUL_ai_behavior
					option = COMMUNIST
				}
				has_game_rule = {
					rule = BUL_ai_behavior
					option = COMMUNIST_BALKAN_FEDERATION
				}
				has_country_flag = BUL_AI_RANDOM_COMMUNIST
				has_country_flag = BUL_AI_RANDOM_COMMUNIST_BALKAN_FEDERATION
			}
		}
		AND = {
			tag = TUR
			OR = {
				has_game_rule = {
					rule = TUR_ai_behavior
					option = COMMUNIST_TUR_AI
				}
				has_game_rule = {
					rule = TUR_ai_behavior
					option = TUR_COMMUNISM_ALTERNATE
				}
				has_country_flag = TUR_AI_RANDOM_COMMUNISM
				has_country_flag = TUR_AI_RANDOM_COMMUNISM_ALTERNATE
			}
		}
		AND = {
			tag = LIT
			OR = {
				has_game_rule = {
					rule = LIT_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = LIT_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = LAT
			OR = {
				has_game_rule = {
					rule = LAT_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = LAT_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = EST
			OR = {
				has_game_rule = {
					rule = EST_ai_behavior
					option = COMMUNIST
				}
				has_country_flag = EST_AI_RANDOM_COMMUNIST
			}
		}
		AND = {
			tag = ITA
			OR = {
				has_game_rule = {
					rule = ITA_ai_behavior
					option = ITA_COMMUNIST_PLAN
				}
				has_country_flag = ITA_AI_RANDOM_COMMUNIST_PLAN
			}
		}
		AND = {
			tag = ETH
			OR = {
				has_game_rule = {
					rule = ETH_ai_behavior
					option = STALINIST
				}
				has_game_rule = {
					rule = ETH_ai_behavior
					option = ANARCHIST
				}
				has_country_flag = ETH_AI_RANDOM_STALINIST
				has_country_flag = ETH_AI_RANDOM_ANARCHIST
			}
		}
	}
}

AI_is_set_to_become_democratic = {
	OR = {
		AND = {
			tag = GER
			OR = {
				has_game_rule = {
					rule = GER_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = GER_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = JAP
			OR = {
				has_game_rule = {
					rule = JAP_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = JAP_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = FRA
			OR = {
				has_game_rule = {
					rule = FRA_ai_behavior
					option = DEMOCRATIC_HISTORICAL
				}
				has_game_rule = {
					rule = FRA_ai_behavior
					option = DEMOCRATIC_ALTERNATE
				}
				has_country_flag = FRA_AI_RANDOM_DEMOCRATIC_ALTERNATE
				has_country_flag = FRA_AI_DEMOCRATIC_HISTORICAL
			}
		}
		AND = {
			tag = POL
			OR = {
				has_game_rule = {
					rule = POL_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = POL_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = AST
			OR = {
				has_game_rule = {
					rule = AST_ai_behavior
					option = DEMOCRATIC_HISTORICAL
				}
				has_game_rule = {
					rule = AST_ai_behavior
					option = DEMOCRATIC_ALTERNATE
				}
				has_country_flag = AST_AI_RANDOM_DEMOCRATIC_ALTERNATE
				has_country_flag = AST_AI_DEMOCRATIC_HISTORICAL
			}
		}
		AND = {
			tag = CAN
			OR = {
				has_game_rule = {
					rule = CAN_ai_behavior
					option = DEMOCRATIC_HISTORICAL
				}
				has_game_rule = {
					rule = CAN_ai_behavior
					option = DEMOCRATIC_ALTERNATE
				}
				has_country_flag = CAN_AI_RANDOM_DEMOCRATIC_ALTERNATE
				has_country_flag = CAN_AI_DEMOCRATIC_HISTORICAL
			}
		}
		AND = {
			tag = SAF
			OR = {
				has_game_rule = {
					rule = SAF_ai_behavior
					option = DEMOCRATIC_HISTORICAL
				}
				has_game_rule = {
					rule = SAF_ai_behavior
					option = DEMOCRATIC_ALTERNATE
				}
				has_country_flag = SAF_AI_RANDOM_DEMOCRATIC_ALTERNATE
				has_country_flag = SAF_AI_DEMOCRATIC_HISTORICAL
			}
		}
		AND = {
			tag = NZL
			OR = {
				has_game_rule = {
					rule = NZL_ai_behavior
					option = DEMOCRATIC_HISTORICAL
				}
				has_game_rule = {
					rule = NZL_ai_behavior
					option = DEMOCRATIC_ALTERNATE
				}
				has_country_flag = NZL_AI_RANDOM_DEMOCRATIC_ALTERNATE
				has_country_flag = NZL_AI_DEMOCRATIC_HISTORICAL
			}
		}
		AND = {
			tag = RAJ
			OR = {
				has_game_rule = {
					rule = RAJ_ai_behavior
					option = DEMOCRATIC_HISTORICAL
				}
				has_country_flag = RAJ_AI_DEMOCRATIC_HISTORICAL
			}
		}
		AND = {
			tag = HUN
			OR = {
				has_game_rule = {
					rule = HUN_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = HUN_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = ROM
			OR = {
				has_game_rule = {
					rule = ROM_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = ROM_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = YUG
			OR = {
				has_game_rule = {
					rule = YUG_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = YUG_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = CZE
			OR = {
				has_game_rule = {
					rule = CZE_ai_behavior
					option = DEMOCRATIC
				}
				has_game_rule = {
					rule = CZE_ai_behavior
					option = DEMOCRATIC_ALTERNATE
				}
				has_game_rule = {
					rule = CZE_ai_behavior
					option = HISTORICAL
				}
				has_country_flag = CZE_AI_RANDOM_DEMOCRATIC
				has_country_flag = CZE_AI_RANDOM_DEMOCRATIC_ALTERNATE
				has_country_flag = CZE_AI_RANDOM_HISTORICAL
			}
		}
		AND = {
			tag = ENG
			OR = {
				has_game_rule = {
					rule = ENG_ai_behavior
					option = DEMOCRATIC_HISTORICAL
				}
				has_game_rule = {
					rule = ENG_ai_behavior
					option = DEMOCRATIC_ALTERNATE
				}
				has_country_flag = ENG_AI_RANDOM_DEMOCRATIC_ALTERNATE
				has_country_flag = ENG_AI_DEMOCRATIC_HISTORICAL
			}
		}
		AND = {
			tag = USA
			OR = {
				has_game_rule = {
					rule = USA_ai_behavior
					option = DEMOCRATIC_HISTORICAL
				}
				has_game_rule = {
					rule = USA_ai_behavior
					option = DEMOCRATIC_ALTERNATE
				}
				has_country_flag = USA_AI_RANDOM_DEMOCRATIC_ALTERNATE
				has_country_flag = USA_AI_DEMOCRATIC_HISTORICAL
			}
		}
		AND = {
			tag = HOL
			OR = {
				has_game_rule = {
					rule = HOL_ai_behavior
					option = DEMOCRATIC_HISTORICAL
				}
				has_game_rule = {
					rule = HOL_ai_behavior
					option = DEMOCRATIC_ALTERNATE_1
				}
				has_game_rule = {
					rule = HOL_ai_behavior
					option = DEMOCRATIC_ALTERNATE_2
				}
				has_game_rule = {
					rule = HOL_ai_behavior
					option = DEMOCRATIC_ALTERNATE_3
				}
				has_country_flag = HOL_AI_RANDOM_DEMOCRATIC_HISTORICAL
				has_country_flag = HOL_AI_RANDOM_DEMOCRATIC_ALTERNATE_1
				has_country_flag = HOL_AI_RANDOM_DEMOCRATIC_ALTERNATE_2
				has_country_flag = HOL_AI_RANDOM_DEMOCRATIC_ALTERNATE_3
			}
		}
		AND = {
			tag = MEX
			OR = {
				has_game_rule = {
					rule = MEX_ai_behavior
					option = SECULAR_REPUBLIC
				}
				has_game_rule = {
					rule = MEX_ai_behavior
					option = SOCIAL_CATHOLICISM
				}
				has_country_flag = MEX_AI_SECULAR_REPUBLIC
				has_country_flag = MEX_AI_SOCIAL_CATHOLICISM
			}
		}
		AND = {
			tag = SPR
			OR = {
				has_game_rule = {
					rule = SPR_ai_behavior
					option = SECOND_REPUBLIC
				}
				has_country_flag = SPR_AI_RANDOM_SECOND_REPUBLIC
			}
		}
		AND = {
			tag = POR
			OR = {
				has_game_rule = {
					rule = POR_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = POR_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = GRE
			OR = {
				has_game_rule = {
					rule = GRE_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = GRE_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = BUL
			OR = {
				has_game_rule = {
					rule = BUL_ai_behavior
					option = DEMOCRATIC_SOCIALIST
				}
				has_game_rule = {
					rule = BUL_ai_behavior
					option = DEMOCRATIC_LIBERAL
				}
				has_country_flag = BUL_AI_RANDOM_DEMOCRATIC_LIBERAL
				has_country_flag = BUL_AI_RANDOM_DEMOCRATIC_SOCIALIST
			}
		}
		AND = {
			tag = TUR
			OR = {
				has_game_rule = {
					rule = TUR_ai_behavior
					option = TUR_DEMOCRATIC_KEMALIST
				}
				has_game_rule = {
					rule = TUR_ai_behavior
					option = TUR_DEMOCRATIC_ALTERNATE
				}
				has_country_flag = TUR_AI_RANDOM_DEMOCRATIC
				has_country_flag = TUR_AI_RANDOM_DEMOCRATIC_ALTERNATE
			}
		}
		AND = {
			tag = LIT
			OR = {
				has_game_rule = {
					rule = LIT_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = LIT_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = LAT
			OR = {
				has_game_rule = {
					rule = LAT_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = LAT_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = EST
			OR = {
				has_game_rule = {
					rule = EST_ai_behavior
					option = DEMOCRATIC
				}
				has_country_flag = EST_AI_RANDOM_DEMOCRATIC
			}
		}
		AND = {
			tag = ITA
			OR = {
				has_game_rule = {
					rule = ITA_ai_behavior
					option = ITA_CHRISTIAN_DEMOCRACY
				}
				has_game_rule = {
					rule = ITA_ai_behavior
					option = ITA_DEMOCRATIC_PLAN
				}
				has_country_flag = ITA_AI_RANDOM_CHRISTIAN_DEMOCRACY
				has_country_flag = ITA_AI_RANDOM_DEMOCRATIC_PLAN
			}
		}
		AND = {
			tag = SWI
			OR = {
				has_game_rule = {
					rule = SWI_ai_behavior
					option = SWI_ALLIED_DEMOCRATIC
				}
				has_game_rule = {
					rule = SWI_ai_behavior
					option = SWI_EXPANSIONIST_DEMOCRATIC
				}
				has_country_flag = SWI_AI_RANDOM_ALLIED_DEMOCRATIC
				has_country_flag = SWI_AI_RANDOM_EXPANSIONIST_DEMOCRATIC
			}
		}
	}
}

AI_is_set_to_become_fascist = {
	OR = {
		AND = {
			tag = GER
			OR = {
				has_game_rule = {
					rule = GER_ai_behavior
					option = FASCIST
				}
				has_country_flag = GER_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = SOV
			OR = {
				has_game_rule = {
					rule = SOV_ai_behavior
					option = EXILES_FASCIST
				}
				has_country_flag = SOV_AI_RANDOM_EXILES_FASCIST
			}
		}
		AND = {
			tag = JAP
			OR = {
				has_game_rule = {
					rule = JAP_ai_behavior
					option = FASCIST
				}
				has_country_flag = JAP_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = ITA
			OR = {
				has_game_rule = {
					rule = ITA_ai_behavior
					option = FASCIST_HISTORICAL
				}
				has_game_rule = {
					rule = ITA_ai_behavior
					option = ALT_FASCIST_BALBO
				}
				has_game_rule = {
					rule = ITA_ai_behavior
					option = ALT_FASCIST_GRANDI
				}
				has_country_flag = ITA_AI_RANDOM_FASCIST_HISTORICAL
				has_country_flag = ITA_AI_RANDOM_FASCIST_BALBO
				has_country_flag = ITA_AI_RANDOM_FASCIST_GRANDI
			}
		}
		AND = {
			tag = FRA
			OR = {
				has_game_rule = {
					rule = FRA_ai_behavior
					option = FASCIST
				}
				has_country_flag = FRA_AI_FASCIST
			}
		}
		AND = {
			tag = POL
			OR = {
				has_game_rule = {
					rule = POL_ai_behavior
					option = FASCIST
				}
				has_game_rule = {
					rule = POL_ai_behavior
					option = FASCIST_INDEPENDENT
				}
				has_country_flag = POL_AI_RANDOM_FASCIST
				has_country_flag = POL_AI_RANDOM_FASCIST_INDEPENDENT
			}
		}
		AND = {
			tag = AST
			OR = {
				has_game_rule = {
					rule = AST_ai_behavior
					option = FASCIST
				}
				has_country_flag = AST_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = CAN
			OR = {
				has_game_rule = {
					rule = CAN_ai_behavior
					option = FASCIST
				}
				has_country_flag = CAN_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = SAF
			OR = {
				has_game_rule = {
					rule = SAF_ai_behavior
					option = FASCIST
				}
				has_country_flag = SAF_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = NZL
			OR = {
				has_game_rule = {
					rule = NZL_ai_behavior
					option = FASCIST
				}
				has_country_flag = NZL_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = RAJ
			OR = {
				has_game_rule = {
					rule = RAJ_ai_behavior
					option = FASCIST
				}
				has_country_flag = RAJ_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = HUN
			OR = {
				has_game_rule = {
					rule = HUN_ai_behavior
					option = FASCIST_ALTERNATE
				}
				has_game_rule = {
					rule = HUN_ai_behavior
					option = FASCIST_HISTORICAL
				}
				has_country_flag = HUN_AI_RANDOM_FASCIST_HISTORICAL
				has_country_flag = HUN_AI_RANDOM_FASCIST_ALTERNATE
			}
		}
		AND = {
			tag = ROM
			OR = {
				has_game_rule = {
					rule = ROM_ai_behavior
					option = FASCIST_HISTORICAL
				}
				has_country_flag = ROM_AI_RANDOM_FASCIST_HISTORICAL
			}
		}
		AND = {
			tag = YUG
			OR = {
				has_game_rule = {
					rule = YUG_ai_behavior
					option = FASCIST
				}
				has_country_flag = YUG_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = CZE
			OR = {
				has_game_rule = {
					rule = CZE_ai_behavior
					option = FASCIST
				}
				has_country_flag = CZE_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = MAN
			OR = {
				has_game_rule = {
					rule = MAN_ai_behavior
					option = OBEDIENCE
				}
				has_country_flag = MAN_AI_RANDOM_OBEDIENCE
			}
		}
		AND = {
			tag = ENG
			OR = {
				has_game_rule = {
					rule = ENG_ai_behavior
					option = FASCIST
				}
				has_country_flag = ENG_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = USA
			OR = {
				has_game_rule = {
					rule = USA_ai_behavior
					option = FASCIST
				}
				has_country_flag = USA_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = HOL
			OR = {
				has_game_rule = {
					rule = HOL_ai_behavior
					option = FASCIST
				}
				has_country_flag = HOL_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = MEX
			OR = {
				has_game_rule = {
					rule = MEX_ai_behavior
					option = FASCIST_DICTATORSHIP
				}
				has_game_rule = {
					rule = MEX_ai_behavior
					option = THEOCRATIC_ORDER
				}
				has_country_flag = MEX_AI_FASCIST_DICTATORSHIP
				has_country_flag = MEX_AI_THEOCRATIC_ORDER
			}
		}
		AND = {
			tag = SPR
			OR = {
				has_game_rule = {
					rule = SPR_ai_behavior
					option = NATIONALIST_HISTORICAL
				}
				has_game_rule = {
					rule = SPR_ai_behavior
					option = FALANGIST
				}
				has_country_flag = SPR_AI_RANDOM_NATIONALIST_HISTORICAL
				has_country_flag = SPR_AI_RANDOM_FALANGIST
			}
		}
		AND = {
			tag = POR
			OR = {
				has_game_rule = {
					rule = POR_ai_behavior
					option = FASCIST
				}
				has_game_rule = {
					rule = POR_ai_behavior
					option = FASCIST_FIFTH_EMPIRE
				}
				has_country_flag = POR_AI_RANDOM_FASCIST_AXIS
				has_country_flag = POR_AI_RANDOM_FASCIST_FIFTH_EMPIRE
			}
		}
		AND = {
			tag = GRE
			OR = {
				has_game_rule = {
					rule = GRE_ai_behavior
					option = FASCISM
				}
				has_game_rule = {
					rule = GRE_ai_behavior
					option = FASCISM_ALTERNATE
				}
				has_country_flag = GRE_AI_RANDOM_FASCISM
				has_country_flag = GRE_AI_RANDOM_FASCISM_ALTERNATE
			}
		}
		AND = {
			tag = BUL
			OR = {
				has_game_rule = {
					rule = BUL_ai_behavior
					option = FASCIST
				}
				has_country_flag = BUL_AI_RANDOM_FASCIST_AXIS
			}
		}
		AND = {
			tag = TUR
			OR = {
				has_game_rule = {
					rule = TUR_ai_behavior
					option = FASCISM_TUR_AI
				}
				has_game_rule = {
					rule = TUR_ai_behavior
					option = TUR_FASCISM_ALTERNATE
				}
				has_country_flag = TUR_AI_RANDOM_FASCISM
				has_country_flag = TUR_AI_RANDOM_FASCISM_ALTERNATE
			}
		}
		AND = {
			tag = LIT
			OR = {
				has_game_rule = {
					rule = LIT_ai_behavior
					option = FASCIST
				}
				has_country_flag = LIT_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = LAT
			OR = {
				has_game_rule = {
					rule = LAT_ai_behavior
					option = FASCIST
				}
				has_country_flag = LAT_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = EST
			OR = {
				has_game_rule = {
					rule = EST_ai_behavior
					option = FASCIST
				}
				has_country_flag = EST_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = SWI
			OR = {
				has_game_rule = {
					rule = SWI_ai_behavior
					option = SWI_FASCIST
				}
				has_country_flag = SWI_AI_RANDOM_FASCIST
			}
		}
		AND = {
			tag = ETH
			OR = {
				has_game_rule = {
					rule = ETH_ai_behavior
					option = Collaborationist
				}
				has_game_rule = {
					rule = ETH_ai_behavior
					option = Independent_Fascist
				}
				has_country_flag = ETH_AI_RANDOM_COLLABORATIONIST
				has_country_flag = ETH_AI_RANDOM_INDEPENDENT_FASCIST
			}
		}
	}
}

AI_is_set_to_become_neutral = {
	OR = {
		AND = {
			tag = GER
			OR = {
				has_game_rule = {
					rule = GER_ai_behavior
					option = KAISER
				}
				has_country_flag = GER_AI_RANDOM_KAISER
			}
		}
		AND = {
			tag = SOV
			OR = {
				has_game_rule = {
					rule = SOV_ai_behavior
					option = EXILES_TSARIST
				}
				has_country_flag = SOV_AI_RANDOM_EXILES_TSARIST
			}
		}
		AND = {
			tag = JAP
			OR = {
				has_game_rule = {
					rule = JAP_ai_behavior
					option = NEUTRALITY
				}
				has_country_flag = JAP_AI_RANDOM_NEUTRALITY
			}
		}
		AND = {
			tag = FRA
			OR = {
				has_game_rule = {
					rule = FRA_ai_behavior
					option = ORLEANIST
				}
				has_game_rule = {
					rule = FRA_ai_behavior
					option = LEGITIMIST
				}
				has_game_rule = {
					rule = FRA_ai_behavior
					option = BONAPARTIST
				}
				has_country_flag = FRA_AI_ORLEANIST
				has_country_flag = FRA_AI_LEGITIMIST
				has_country_flag = FRA_AI_BONAPARTIST
			}
		}
		AND = {
			tag = POL
			OR = {
				has_game_rule = {
					rule = POL_ai_behavior
					option = HISTORICAL
				}
				has_game_rule = {
					rule = POL_ai_behavior
					option = COMMONWEALTH
				}
				has_game_rule = {
					rule = POL_ai_behavior
					option = ROMANIA
				}
				has_game_rule = {
					rule = POL_ai_behavior
					option = HABSBURG
				}
				has_game_rule = {
					rule = POL_ai_behavior
					option = BERMONDT
				}
				has_country_flag = POL_AI_RANDOM_HISTORICAL
				has_country_flag = POL_AI_RANDOM_COMMONWEALTH
				has_country_flag = POL_AI_RANDOM_ROMANIA
				has_country_flag = POL_AI_RANDOM_HABSBURG
				has_country_flag = POL_AI_RANDOM_BERMONDT
			}
		}
		AND = {
			tag = YUG
			OR = {
				has_game_rule = {
					rule = YUG_ai_behavior
					option = HISTORICAL
				}
				has_country_flag = YUG_AI_RANDOM_HISTORICAL
			}
		}
		AND = {
			tag = CHI
			OR = {
				has_game_rule = {
					rule = CHI_ai_behavior
					option = HISTORICAL
				}
				has_game_rule = {
					rule = CHI_ai_behavior
					option = ALTERNATE
				}
				has_country_flag = CHI_AI_RANDOM_HISTORICAL
				has_country_flag = CHI_AI_RANDOM_ALTERNATE
			}
		}
		AND = {
			tag = ENG
			OR = {
				has_game_rule = {
					rule = ENG_ai_behavior
					option = NEUTRALITY
				}
				has_country_flag = ENG_AI_RANDOM_NEUTRALITY
			}
		}
		AND = {
			tag = HOL
			OR = {
				has_game_rule = {
					rule = HOL_ai_behavior
					option = NEUTRALITY
				}
				has_country_flag = HOL_AI_RANDOM_NEUTRALITY
			}
		}
		AND = {
			tag = SPR
			OR = {
				has_game_rule = {
					rule = SPR_ai_behavior
					option = CARLIST
				}
				has_country_flag = SPR_AI_RANDOM_CARLIST
			}
		}
		AND = {
			tag = POR
			OR = {
				has_game_rule = {
					rule = POR_ai_behavior
					option = HISTORICAL
				}
				has_game_rule = {
					rule = POR_ai_behavior
					option = NEUTRALITY_MONARCHIST
				}
				has_country_flag = POR_AI_RANDOM_NEUTRALITY_HISTORICAL
				has_country_flag = POR_AI_RANDOM_NEUTRALITY_MONARCHIST
			}
		}
		AND = {
			tag = GRE
			OR = {
				has_game_rule = {
					rule = GRE_ai_behavior
					option = HISTORICAL
				}
				has_game_rule = {
					rule = GRE_ai_behavior
					option = MONARCHIST
				}
				has_game_rule = {
					rule = GRE_ai_behavior
					option = MONARCHIST_ALTERNATE
				}
				has_country_flag = GRE_AI_RANDOM_NEUTRALITY_HISTORICAL
				has_country_flag = GRE_AI_RANDOM_MONARCHIST
				has_country_flag = GRE_AI_RANDOM_MONARCHIST_ALTERNATE
			}
		}
		AND = {
			tag = BUL
			OR = {
				has_game_rule = {
					rule = BUL_ai_behavior
					option = THE_RETURN_OF_FERDINAND
				}
				has_country_flag = BUL_AI_RANDOM_THE_RETURN_OF_FERDINAND
			}
		}
		AND = {
			tag = TUR
			OR = {
				has_game_rule = {
					rule = TUR_ai_behavior
					option = HISTORICAL
				}
				has_game_rule = {
					rule = TUR_ai_behavior
					option = ALTERNATE_KEMALIST
				}
				has_country_flag = TUR_AI_RANDOM_NEUTRALITY_HISTORICAL
				has_country_flag = TUR_AI_RANDOM_ALT_KEMALIST
			}
		}
		AND = {
			tag = LIT
			OR = {
				has_game_rule = {
					rule = LIT_ai_behavior
					option = MONARCHIST
				}
				has_country_flag = LIT_AI_RANDOM_MONARCHY
			}
		}
		AND = {
			tag = ITA
			OR = {
				has_game_rule = {
					rule = ITA_ai_behavior
					option = ITA_MONARCHIST_ROMAN_EMPIRE
				}
				has_country_flag = ITA_AI_RANDOM_MONARCHIST
			}
		}
		AND = {
			tag = SWI
			OR = {
				has_game_rule = {
					rule = SWI_ai_behavior
					option = HISTORICAL
				}
				has_game_rule = {
					rule = SWI_ai_behavior
					option = SWI_IMPERIAL
				}
				has_country_flag = SWI_AI_RANDOM_HISTORICAL
				has_country_flag = SWI_AI_RANDOM_IMPERIAL
			}
		}
		AND = {
			tag = ETH
			OR = {
				has_game_rule = {
					rule = ETH_ai_behavior
					option = HISTORICAL
				}
				has_game_rule = {
					rule = ETH_ai_behavior
					option = IMPERIAL
				}
				has_country_flag = ETH_AI_RANDOM_HISTORICAL
				has_country_flag = ETH_AI_RANDOM_IMPERIAL
			}
		}
	}
}

is_neutral_monarchy = {
	OR = {
		tag = SAU
		tag = PER
		tag = AFG
		tag = TIB
		tag = NEP
		tag = BHU
		tag = IRQ
		tag = ETH
		tag = ALB
		tag = GER
		tag = SOV
		tag = BUL
		tag = SPR
		tag = JAP
		tag = FRA
		tag = YUG
		tag = ENG
		tag = HOL
		AND = {
			tag = POL
			OR = {
				has_game_rule = {
					rule = POL_ai_behavior
					option = COMMONWEALTH
				}
				has_game_rule = {
					rule = POL_ai_behavior
					option = ROMANIA
				}
				has_game_rule = {
					rule = POL_ai_behavior
					option = HABSBURG
				}
				has_game_rule = {
					rule = POL_ai_behavior
					option = BERMONDT
				}
				has_country_flag = POL_AI_RANDOM_COMMONWEALTH
				has_country_flag = POL_AI_RANDOM_ROMANIA
				has_country_flag = POL_AI_RANDOM_HABSBURG
				has_country_flag = POL_AI_RANDOM_BERMONDT
			}
		}
		AND = {
			tag = POR
			OR = {
				has_game_rule = {
					rule = POR_ai_behavior
					option = NEUTRALITY_MONARCHIST
				}
				has_country_flag = POR_AI_RANDOM_NEUTRALITY_MONARCHIST
			}
		}
		AND = {
			tag = GRE
			OR = {
				has_game_rule = {
					rule = GRE_ai_behavior
					option = MONARCHIST
				}
				has_game_rule = {
					rule = GRE_ai_behavior
					option = MONARCHIST_ALTERNATE
				}
				has_country_flag = GRE_AI_RANDOM_MONARCHIST
				has_country_flag = GRE_AI_RANDOM_MONARCHIST_ALTERNATE
			}
		}
		AND = {
			tag = TUR
			OR = {
				has_game_rule = {
					rule = TUR_ai_behavior
					option = OTTOMAN
				}
				has_country_flag = TUR_AI_RANDOM_OTTOMAN
			}
		}
		AND = {
			tag = LIT
			OR = {
				has_game_rule = {
					rule = LIT_ai_behavior
					option = MONARCHIST
				}
				has_country_flag = LIT_AI_RANDOM_MONARCHY
			}
		}
		AND = {
			has_start_date > 1910.4.30
			NOT = { has_start_date > 1933.1.1 }
			OR = {
				tag = AUH
				tag = RUS
				tag = QIN
				tag = SIA
				tag = TUR
				tag = POR
				tag = DEN
			}
		}
	}
}

can_change_national_idea_group = {
	OR = {
		is_ai = no
		AND = {
			is_ai = yes
			NOT = { has_global_flag = eu4_like_ideas_ai_disabled }
			OR = {
				AND = {
					NOT = { has_global_flag = eu4_like_ideas_ai_only_majors }
					NOT = { has_global_flag = eu4_like_ideas_ai_only_minors }
					OR = {
						NOT = { has_global_flag = eu4_like_ideas_ai_idea_usage_delayed }
						AND = {
							has_global_flag = eu4_like_ideas_ai_idea_usage_delayed
							meta_trigger = {
								text = {
									date > [DATE]
								}
								DATE = "[?global.eu4_like_ideas_AI_idea_usage_delay.GetDateStringNoHour]"
							}
						}
					}
				}
				AND = {
					is_major = yes
					has_global_flag = eu4_like_ideas_ai_only_majors
					OR = {
						NOT = { has_global_flag = eu4_like_ideas_ai_idea_usage_delayed }
						AND = {
							has_global_flag = eu4_like_ideas_ai_idea_usage_delayed
							meta_trigger = {
								text = {
									date > [DATE]
								}
								DATE = "[?global.eu4_like_ideas_AI_idea_usage_delay.GetDateStringNoHour]"
							}
						}
					}
				}
				AND = {
					is_major = no
					has_global_flag = eu4_like_ideas_ai_only_minors
					OR = {
						NOT = { has_global_flag = eu4_like_ideas_ai_idea_usage_delayed }
						AND = {
							has_global_flag = eu4_like_ideas_ai_idea_usage_delayed
							meta_trigger = {
								text = {
									date > [DATE]
								}
								DATE = "[?global.eu4_like_ideas_AI_idea_usage_delay.GetDateStringNoHour]"
							}
						}
					}
				}
			}
		}
	}
	calculate_right_national_ideas_id = yes
	NOT = { check_variable = { national_ideas_id = national_ideas_id_other_context } }
}

calculate_right_national_ideas_id = {
	set_temp_variable = { national_ideas_id_other_context = 1000 }
	# Formables
	if = {
		limit = {
			OR = {
				original_tag = MAN
				has_cosmetic_tag = CHI_QING_EMPIRE
				has_cosmetic_tag = QIN_formable
				AND = {
					has_start_date > 1910.4.30
					NOT = { has_start_date > 1933.1.1 }
					tag = QIN
				}
			}
		}
		set_temp_variable = { national_ideas_id_other_context = 16 }
	}
	else_if = {
		limit = {
			has_cosmetic_tag = GRE_MACEDONIAN_EMPIRE
		}
		set_temp_variable = { national_ideas_id_other_context = 17 }
	}
	else_if = {
		limit = {
			OR = {
				has_cosmetic_tag = OTT_UNIFIED
				AND = {
					original_tag = TUR
					has_start_date > 1910.4.30
					NOT = { has_start_date > 1933.1.1 }
				}
			}
		}
		set_temp_variable = { national_ideas_id_other_context = 20 }
	}
	else_if = {
		limit = {
			OR = {
				has_cosmetic_tag = HUN_EMPIRE
				AND = {
					has_start_date > 1910.4.30
					NOT = { has_start_date > 1933.1.1 }
					original_tag = AUH
				}
			}
		}
		set_temp_variable = { national_ideas_id_other_context = 21 }
	}
	# Countries
	else_if = {
		limit = {
			original_tag = GER
		}
		if = {
			limit = {
				has_government = neutrality
			}
			set_temp_variable = { national_ideas_id_other_context = 13 }
		}
		else = {
			set_temp_variable = { national_ideas_id_other_context = 1 }
		}
	}
	else_if = {
		limit = {
			original_tag = USA
		}
		set_temp_variable = { national_ideas_id_other_context = 2 }
	}
	else_if = {
		limit = {
			original_tag = ENG
		}
		set_temp_variable = { national_ideas_id_other_context = 3 }
	}
	else_if = {
		limit = {
			original_tag = ITA
		}
		set_temp_variable = { national_ideas_id_other_context = 4 }
	}
	else_if = {
		limit = {
			original_tag = SOV
		}
		if = {
			limit = {
				has_government = neutrality
			}
			set_temp_variable = { national_ideas_id_other_context = 27 }
		}
		else = {
			set_temp_variable = { national_ideas_id_other_context = 5 }
		}
	}
	else_if = {
		limit = {
			original_tag = JAP
		}
		set_temp_variable = { national_ideas_id_other_context = 6 }
	}
	else_if = {
		limit = {
			original_tag = FRA
		}
		set_temp_variable = { national_ideas_id_other_context = 7 }
	}
	else_if = {
		limit = {
			original_tag = CAN
		}
		set_temp_variable = { national_ideas_id_other_context = 8 }
	}
	else_if = {
		limit = {
			original_tag = PRC
		}
		set_temp_variable = { national_ideas_id_other_context = 9 }
	}
	else_if = {
		limit = {
			original_tag = CHI
		}
		set_temp_variable = { national_ideas_id_other_context = 10 }
	}
	else_if = {
		limit = {
			OR = {
				original_tag = GXC
				original_tag = YUN
				original_tag = SHX
				original_tag = XSM
				original_tag = SIK
			}
		}
		set_temp_variable = { national_ideas_id_other_context = 11 }
	}
	else_if = {
		limit = {
			original_tag = POL
		}
		set_temp_variable = { national_ideas_id_other_context = 12 }
	}
	else_if = {
		limit = {
			original_tag = GRE
		}
		set_temp_variable = { national_ideas_id_other_context = 14 }
	}
	else_if = {
		limit = {
			original_tag = SPR
		}
		if = {
			limit = {
				OR = {
					tag = SPC
					has_government = communism
				}
			}
			set_temp_variable = { national_ideas_id_other_context = 26 }
		}
		else = {
			set_temp_variable = { national_ideas_id_other_context = 15 }
		}
	}
	else_if = {
		limit = {
			original_tag = ROM
		}
		set_temp_variable = { national_ideas_id_other_context = 18 }
	}
	else_if = {
		limit = {
			original_tag = TUR
		}
		set_temp_variable = { national_ideas_id_other_context = 19 }
	}
	else_if = {
		limit = {
			original_tag = POR
		}
		set_temp_variable = { national_ideas_id_other_context = 22 }
	}
	else_if = {
		limit = {
			original_tag = SWE
		}
		set_temp_variable = { national_ideas_id_other_context = 23 }
	}
	else_if = {
		limit = {
			original_tag = HOL
		}
		set_temp_variable = { national_ideas_id_other_context = 24 }
	}
	else_if = {
		limit = {
			original_tag = SAU
		}
		set_temp_variable = { national_ideas_id_other_context = 25 }
	}
	else_if = {
		limit = {
			original_tag = BEL
		}
		set_temp_variable = { national_ideas_id_other_context = 28 }
	}
	else_if = {
		limit = {
			original_tag = SWI
		}
		set_temp_variable = { national_ideas_id_other_context = 29 }
	}
	else_if = {
		limit = {
			original_tag = PER
		}
		set_temp_variable = { national_ideas_id_other_context = 30 }
	}
	else_if = {
		limit = {
			original_tag = HUN
		}
		set_temp_variable = { national_ideas_id_other_context = 31 }
	}
}

AI_might_want_to_spend_pp_on_something_else = {
	is_ai = yes
	OR = {
		AI_might_want_to_change_to_a_better_economy_law = yes
		AI_might_want_to_change_to_a_better_conscription_law = yes
		AND = {
			JAP_has_idea_JAP_intervene_in_china = yes
			any_enemy_country = {
				is_literally_china = yes
			}
		}
	}
}

AI_might_want_to_change_to_a_better_economy_law = {
	is_ai = yes
	set_temp_variable = { required_pp_temp = modifier@economy_cost_factor }
	add_to_temp_variable = { required_pp_temp = 1 }
	multiply_temp_variable = { required_pp_temp = 150 }
	add_to_temp_variable = { required_pp_temp = idea_cost_var }
	has_political_power < required_pp_temp
	OR = {
		AND = {
			NOT = { has_idea = low_economic_mobilisation }
			NOT = { has_idea = partial_economic_mobilisation }
			NOT = { has_idea = war_economy }
			NOT = { has_idea = tot_economic_mobilisation }
			# Trigger for Law:
			has_war_support > 0.15
			if = {
				limit = {
					original_tag = HUN
					has_dlc = "Death or Dishonor"
				}
				NOT = { has_idea = HUN_treaty_of_triannon }
			}
			if = {
				limit = {
					has_completed_focus = USA_limited_intervention
					has_defensive_war = no
				}
				has_war_support > 0.3
				congress_high_support_trigger = yes
			}
			# AI reasons:
			has_war_support < 0.25
			OR = {
				NOT = { tag = ENG }
				has_war = yes
				date > 1937.6.1
			}
		}
		AND = {
			NOT = { has_idea = partial_economic_mobilisation }
			NOT = { has_idea = war_economy }
			NOT = { has_idea = tot_economic_mobilisation }
			# Trigger for Law:
			has_war_support > 0.25
			if = {
				limit = {
					original_tag = HUN
					has_dlc = "Death or Dishonor"
				}
				OR = {
					has_completed_focus = HUN_secret_rearmament
					NOT = { has_idea = HUN_treaty_of_triannon }
				}
			}
			if = {
				limit = {
					has_completed_focus = USA_limited_intervention
					has_defensive_war = no
				}
				has_war_support > 0.5
				congress_high_support_trigger = yes
			}
			# AI reasons:
			## None
		}
		AND = {
			NOT = { has_idea = war_economy }
			NOT = { has_idea = tot_economic_mobilisation }
			# Trigger for Law:
			has_war_support > 0.5
			OR = {
				has_government = fascism
				has_government = communism
				AND = {
					has_war = yes
					any_enemy_country = {
						ic_ratio = {
							tag = ROOT
							ratio > 0.4
						}
					}
				}
			}
			# AI reasons:
			## None
		}
		AND = {
			NOT = { has_idea = tot_economic_mobilisation }
			# Trigger for Law:
			has_war = yes
			has_war_support > 0.8
			any_enemy_country = {
				ic_ratio = {
					tag = ROOT
					ratio > 0.5
				}
			}
			if = {
				limit = {
					original_tag = HUN
					has_dlc = "Death or Dishonor"
					NOT = {
						has_dlc = "Gotterdammerung"
					}
				}
				if = {
					limit = {
						has_dlc = "Arms Against Tyranny"
					}
					NOT = { has_idea = HUN_treaty_of_triannon_aat }
				}
				else = {
					NOT = { has_idea = HUN_treaty_of_triannon }
				}
			}
			else_if = {
				limit = {
					original_tag = HUN
					has_dlc = "Gotterdammerung"
				}
				if = {
					limit = {
						has_dlc = "Arms Against Tyranny"
					}
					custom_trigger_tooltip = {
						tooltip = wuw_HUN_not_has_trianon_for_laws_tt
						NOT = {
							OR = {
								has_idea = HUN_treaty_of_triannon_aat_wuw
								has_idea = HUN_treaty_of_triannon_aat_wuw_no_air_debuff
								has_idea = HUN_treaty_of_triannon_aat_wuw_no_army_exp_debuff
								has_idea = HUN_treaty_of_triannon_aat_wuw_no_air_or_army_debuff
							}
						}

					}
				}
				else = {
					custom_trigger_tooltip = {
						tooltip = wuw_HUN_not_has_trianon_for_laws_tt
						NOT = {
							OR = {
								has_idea = HUN_treaty_of_triannon_wuw
								has_idea = HUN_treaty_of_triannon_wuw_no_army_exp_debuff
								has_idea = HUN_treaty_of_triannon_wuw_no_air_debuff
								has_idea = HUN_treaty_of_triannon_wuw_no_air_or_army_debuff
							}
						}
					}
				}
			}
			if = {
				limit = {
					has_completed_focus = USA_limited_intervention
					has_defensive_war = no
				}
				has_war_support > 0.9
				congress_high_support_trigger = yes
			}
			if = {
				limit = {
					original_tag = TUR
					has_dlc = "Battle for the Bosporus"
				}
				NOT = {
					OR = {
						has_active_mission = TUR_etatism_crisis_1
						has_active_mission = TUR_etatism_crisis_2
						has_active_mission = TUR_etatism_crisis_3
					}
				}
			}
			# AI reasons:
			manpower_per_military_factory > 10000
			NOT = { has_idea = volunteer_only }
			NOT = { has_idea = limited_conscription }
			OR = {
				NOT = { tag = GER }
				has_doctrine = last_stand
				has_war = no
				date > 1944.01.01
			}
			OR = {
				NOT = { tag = SOV }
				has_war = no
				NOT = {
					OR = {
						has_manpower < 2000000
						NOT = {
							OR = {
								has_idea = all_adults_serve
								has_idea = service_by_requirement
							}
						}
					}
				}
			}
		}
	}
}

AI_might_want_to_change_to_a_better_conscription_law = {
	is_ai = yes
	set_temp_variable = { required_pp_temp = modifier@mobilization_laws_cost_factor }
	add_to_temp_variable = { required_pp_temp = 1 }
	multiply_temp_variable = { required_pp_temp = 150 }
	add_to_temp_variable = { required_pp_temp = idea_cost_var }
	has_political_power < required_pp_temp
	OR = {
		AND = {
			NOT = { has_idea = volunteer_only }
			NOT = { has_idea = limited_conscription }
			NOT = { has_idea = extensive_conscription }
			NOT = { has_idea = service_by_requirement }
			NOT = { has_idea = all_adults_serve }
			NOT = { has_idea = scraping_the_barrel }
			# Trigger for Law:
			if = {
				limit = {
					original_tag = HUN
					has_dlc = "Death or Dishonor"
				}
				NOT = { has_idea = HUN_treaty_of_triannon }
			}
			NOT = { has_idea = undisturbed_isolation }
			NOT = { has_idea = isolation }
			# AI reasons:
			has_idea = disarmed_nation
		}
		AND = {
			NOT = { has_idea = limited_conscription }
			NOT = { has_idea = extensive_conscription }
			NOT = { has_idea = service_by_requirement }
			NOT = { has_idea = all_adults_serve }
			NOT = { has_idea = scraping_the_barrel }
			# Trigger for Law:
			has_war_support > 0.1
			NOT = { has_idea = undisturbed_isolation }
			NOT = { has_idea = isolation }
			if = {
				limit = {
					original_tag = AST
					has_dlc = "Together for Victory"
				}
				has_completed_focus = AST_citizen_military_forces
			}
			if = {
				limit = {
					original_tag = CAN
					has_dlc = "Together for Victory"
				}
				has_completed_focus = CAN_commit_to_the_war
			}
			if = {
				limit = {
					original_tag = RAJ
					has_dlc = "Together for Victory"
				}
				is_subject = no
			}
			if = {
				limit = {
					original_tag = HUN
					has_dlc = "Death or Dishonor"
				}
				NOT = { has_idea = HUN_treaty_of_triannon }
			}
			if = {
				limit = {
					original_tag = ENG
					has_dlc = "Man the Guns"
					has_completed_focus = ENG_concessions_to_the_trade_unions
				}
				NOT = { has_country_flag = ENG_cannot_increase_conscription_law }
			}
			# AI reasons:
			OR = {
				manpower_per_military_factory < 1000
				AND = {
					tag = ENG
					has_idea_with_trait = military_theorist
				}
			}
		}
		AND = {
			NOT = { has_idea = extensive_conscription }
			NOT = { has_idea = service_by_requirement }
			NOT = { has_idea = all_adults_serve }
			NOT = { has_idea = scraping_the_barrel }
			# Trigger for Law:
			OR = {
				has_government = fascism
				has_government = communism
				AND = {
					has_war = yes
					enemies_strength_ratio > 0.5
					#any_enemy_country = {
					#	strength_ratio = {
					#		tag = ROOT
					#		ratio > 0.5
					#	}
					#}
				}
			}
			has_war_support > 0.2
			#Special rules AST in TFV
			if = {
				limit = {
					original_tag = AST
					has_dlc = "Together for Victory"
				}
				has_completed_focus = AST_citizen_military_forces
				has_completed_focus = AST_fight_work_or_perish
			}
			if = {
				limit = {
					original_tag = CAN
					has_dlc = "Together for Victory"
				}
				has_completed_focus = CAN_commit_to_the_war
				has_completed_focus = CAN_if_day
			}
			if = {
				limit = {
					original_tag = RAJ
					has_dlc = "Together for Victory"
				}
				is_subject = no
			}
			if = {
				limit = {
					original_tag = HUN
					has_dlc = "Death or Dishonor"
				}
				NOT = { has_idea = HUN_treaty_of_triannon }
			}
			if = {
				limit = {
					original_tag = ENG
					has_dlc = "Man the Guns"
					has_completed_focus = ENG_concessions_to_the_trade_unions
				}
				NOT = { has_country_flag = ENG_cannot_increase_conscription_law }
			}
			# AI reasons:
			OR = {
				manpower_per_military_factory < 800
				AND = {
					tag = CHI
					has_manpower < 200000
				}
			}
		}
		AND = {
			NOT = { has_idea = service_by_requirement }
			NOT = { has_idea = all_adults_serve }
			NOT = { has_idea = scraping_the_barrel }
			# Trigger for Law:
			OR = {
				has_government = fascism
				has_government = communism
				AND = {
					has_war = yes
					enemies_strength_ratio > 0.6
				}
			}
			OR = {
				has_war_support > 0.6
				surrender_progress > 0
			}
			if = {
				limit = {
					original_tag = AST
					has_dlc = "Together for Victory"
				}
				has_completed_focus = AST_citizen_military_forces
				has_completed_focus = AST_fight_work_or_perish
			}
			if = {
				limit = {
					original_tag = CAN
					has_dlc = "Together for Victory"
				}
				OR = {
					has_completed_focus = CAN_compromise_with_quebec
					has_completed_focus = CAN_forced_quebec_conscription
				}
			}
			if = {
				limit = {
					original_tag = RAJ
					has_dlc = "Together for Victory"
				}
				is_subject = no
			}
			if = {
				limit = {
					original_tag = HUN
					has_dlc = "Death or Dishonor"
				}
				NOT = { has_idea = HUN_treaty_of_triannon }
			}
			if = {
				limit = {
					original_tag = ENG
					has_dlc = "Man the Guns"
					has_completed_focus = ENG_concessions_to_the_trade_unions
				}
				NOT = { has_country_flag = ENG_cannot_increase_conscription_law }
			}
			# AI reasons:
			OR = {
				tag = CHI
				tag = SOV
				NOT = { manpower_per_military_factory >  3000 }
			}
			OR = {
				manpower_per_military_factory < 700
				AND = {
					tag = CHI
					has_manpower < 200000
				}
				AND = {
					original_tag = GER
					has_manpower < 2000000
				}
				AND = {
					original_tag = SOV
					check_variable = { manpower_k < 3000 }
				}
			}
		}
		AND = {
			NOT = { has_idea = all_adults_serve }
			NOT = { has_idea = scraping_the_barrel }
			# Trigger for Law:
			has_war = yes
			OR = {
				has_war_support > 0.7
				surrender_progress > 0
			}
			enemies_strength_ratio > 0.75
			if = {
				limit = {
					original_tag = AST
					has_dlc = "Together for Victory"
				}
				has_completed_focus = AST_citizen_military_forces
				has_completed_focus = AST_fight_work_or_perish
			}
			if = {
				limit = {
					original_tag = CAN
					has_dlc = "Together for Victory"
				}
				OR = {
					has_completed_focus = CAN_compromise_with_quebec
					has_completed_focus = CAN_forced_quebec_conscription
				}
			}
			if = {
				limit = {
					original_tag = RAJ
					has_dlc = "Together for Victory"
				}
				is_subject = no
			}
			if = {
				limit = {
					original_tag = HUN
					has_dlc = "Death or Dishonor"
				}
				NOT = { has_idea = HUN_treaty_of_triannon }
			}
			if = {
				limit = {
					original_tag = ENG
					has_dlc = "Man the Guns"
					has_completed_focus = ENG_concessions_to_the_trade_unions
				}
				NOT = { has_country_flag = ENG_cannot_increase_conscription_law }
			}
			# AI reasons:
			OR = {
				tag = CHI
				NOT = { manpower_per_military_factory > 5000 }
			}
			OR = {
				manpower_per_military_factory < 600
				AND = {
					tag = CHI
					has_manpower < 200000
				}
				AND = {
					original_tag = SOV
					date > 1943.1.1
					has_manpower < 2000000
				}
			}
		}
		AND = {
			NOT = { has_idea = scraping_the_barrel }
			# Trigger for Law:
			has_war = yes
			OR = {
				has_war_support > 0.85
				surrender_progress > 0.25
			}
			enemies_strength_ratio > 1
			if = {
				limit = {
					original_tag = AST
					has_dlc = "Together for Victory"
				}
				has_completed_focus = AST_citizen_military_forces
				has_completed_focus = AST_fight_work_or_perish
			}
			if = {
				limit = {
					original_tag = CAN
					has_dlc = "Together for Victory"
				}
				OR = {
					has_completed_focus = CAN_compromise_with_quebec
					has_completed_focus = CAN_forced_quebec_conscription
				}
			}
			if = {
				limit = {
					original_tag = RAJ
					has_dlc = "Together for Victory"
				}
				is_subject = no
			}
			if = {
				limit = {
					original_tag = HUN
					has_dlc = "Death or Dishonor"
				}
				NOT = { has_idea = HUN_treaty_of_triannon }
			}
			if = {
				limit = {
					original_tag = ENG
					has_dlc = "Man the Guns"
					has_completed_focus = ENG_concessions_to_the_trade_unions
				}
				NOT = { has_country_flag = ENG_cannot_increase_conscription_law }
			}
			# AI reasons:
			NOT = { manpower_per_military_factory > 5000 }
			manpower_per_military_factory < 500
		}
	}
}

AI_can_remove_any_idea_group = {
	is_ai = yes
	NOT = { has_global_flag = eu4_like_ideas_ai_disabled }
	NOT = { has_global_flag = eu4_like_ideas_rule_AI_ability_to_remove_idea_groups_disabled }
	OR = {
		AND = {
			NOT = { has_global_flag = eu4_like_ideas_ai_only_majors }
			NOT = { has_global_flag = eu4_like_ideas_ai_only_minors }
		}
		AND = {
			is_major = yes
			has_global_flag = eu4_like_ideas_ai_only_majors
		}
		AND = {
			is_major = no
			has_global_flag = eu4_like_ideas_ai_only_minors
		}
	}
	OR = {
		# Communist Ideas
		AND = {
			set_temp_variable = { idea_group_out_of_context = 4 }
			has_selected_idea_group = yes
			OR = {
				AND = {
					NOT = { has_government = communism }
					NOT = { AI_is_set_to_become_communist = yes }
					communism < 0.2
				}
				OR = {
					AI_is_set_to_become_democratic = yes
					democratic > 0.5
				}
				OR = {
					AI_is_set_to_become_fascist = yes
					fascism > 0.5
				}
				OR = {
					AI_is_set_to_become_neutral = yes
					AND = {
						is_neutral_monarchy = yes
						neutrality > 0.5
					}
				}
			}
		}
		# Democratic Ideas
		AND = {
			set_temp_variable = { idea_group_out_of_context = 5 }
			has_selected_idea_group = yes
			OR = {
				AND = {
					NOT = { has_government = democratic }
					NOT = { AI_is_set_to_become_democratic = yes }
					democratic < 0.2
				}
				OR = {
					AI_is_set_to_become_communist = yes
					communism > 0.5
				}
				OR = {
					AI_is_set_to_become_fascist = yes
					fascism > 0.5
				}
				OR = {
					AI_is_set_to_become_neutral = yes
					AND = {
						is_neutral_monarchy = yes
						neutrality > 0.5
					}
				}
			}
		}
		# Fascist Ideas
		AND = {
			set_temp_variable = { idea_group_out_of_context = 6 }
			has_selected_idea_group = yes
			OR = {
				AND = {
					NOT = { has_government = fascism }
					NOT = { AI_is_set_to_become_fascist = yes }
					fascism < 0.2
				}
				OR = {
					AI_is_set_to_become_communist = yes
					communism > 0.5
				}
				OR = {
					AI_is_set_to_become_democratic = yes
					democratic > 0.5
				}
				OR = {
					AI_is_set_to_become_neutral = yes
					AND = {
						is_neutral_monarchy = yes
						neutrality > 0.5
					}
				}
			}
		}
		# Monarchist Ideas
		AND = {
			set_temp_variable = { idea_group_out_of_context = 19 }
			has_selected_idea_group = yes
			OR = {
				AND = {
					NOT = { has_government = neutrality }
					NOT = { is_neutral_monarchy = yes }
					NOT = { AI_is_set_to_become_neutral = yes }
					neutrality < 0.2
				}
				OR = {
					AI_is_set_to_become_communist = yes
					communism > 0.5
				}
				OR = {
					AI_is_set_to_become_democratic = yes
					democratic > 0.5
				}
				OR = {
					AI_is_set_to_become_fascist = yes
					fascism > 0.5
				}
			}
		}
	}
}

can_remove_flags_for_available_dismissed_alerts = {
	OR = {
		AND = {
			NOT = { has_country_flag = disabled_eu4_like_ideas_alerts_1 }
			has_country_flag = temporarily_disabled_eu4_like_ideas_alerts_1
			NOT = { is_in_array = { eu4_like_ideas_alerts = 1 } }
			can_select_any_idea = yes
		}
		AND = {
			NOT = { has_country_flag = disabled_eu4_like_ideas_alerts_2 }
			has_country_flag = temporarily_disabled_eu4_like_ideas_alerts_2
			NOT = { is_in_array = { eu4_like_ideas_alerts = 2 } }
			can_select_any_idea_group = yes
		}
		AND = {
			NOT = { has_country_flag = disabled_eu4_like_ideas_alerts_3 }
			has_country_flag = temporarily_disabled_eu4_like_ideas_alerts_3
			NOT = { is_in_array = { eu4_like_ideas_alerts = 3 } }
			can_select_any_policy = yes
		}
	}
}

specific_idea_group_slot_is_unlocked = {
	OR = {
		has_global_flag = eu4_like_ideas_test_flag
		AND = {
			check_variable = { i = 0 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_1.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { i = 1 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_2.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 2 }
			check_variable = { i = 2 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_3.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 2 }
			check_variable = { i = 3 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_4.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 4 }
			check_variable = { i = 4 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_5.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 4 }
			check_variable = { i = 5 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_6.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 6 }
			check_variable = { i = 6 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_7.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 6 }
			check_variable = { i = 7 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_8.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 8 }
			check_variable = { i = 8 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_9.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 8 }
			check_variable = { i = 9 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_10.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 10 }
			check_variable = { i = 10 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_11.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 10 }
			check_variable = { i = 11 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_12.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 12 }
			check_variable = { i = 12 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_13.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 12 }
			check_variable = { i = 13 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_14.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 14 }
			check_variable = { i = 14 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_15.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 14 }
			check_variable = { i = 15 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_16.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 16 }
			check_variable = { i = 16 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_17.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 16 }
			check_variable = { i = 17 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_18.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 18 }
			check_variable = { i = 18 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_19.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 18 }
			check_variable = { i = 19 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_20.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 20 }
			check_variable = { i = 20 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_21.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 20 }
			check_variable = { i = 21 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_22.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 22 }
			check_variable = { i = 22 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_23.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 22 }
			check_variable = { i = 23 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_24.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 24 }
			check_variable = { i = 24 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_25.GetDateStringNoHour]"
			}
		}
		AND = {
			check_variable = { global.num_of_unlockable_idea_groups > 24 }
			check_variable = { i = 25 }
			meta_trigger = {
				text = {
					date > [DATE]
				}
				DATE = "[?global.unlock_date_for_idea_group_26.GetDateStringNoHour]"
			}
		}
	}
}

# usage:
## set_temp_variable = { idea_group_out_of_context = 1 }
## has_selected_idea_group = yes
has_selected_idea_group = {
	custom_trigger_tooltip = {
		tooltip = HAS_IDEA_GROUP_SELECTED
		is_in_array = { selected_idea_groups = idea_group_out_of_context }
	}
}

# usage:
## set_temp_variable = { idea_group_out_of_context = 1 }
## has_completed_idea_group = yes
has_completed_idea_group = {
	custom_trigger_tooltip = {
		tooltip = HAS_IDEA_GROUP_COMPLETED
		has_selected_idea_group = yes
		set_temp_variable = { required_num = global.required_ideas_for_policy_minus_1?6 }
		meta_trigger = {
			text = {
				check_variable = { completed_ideas_of_group_[GROUP] > required_num }
			}
			GROUP = "[?idea_group_out_of_context]"
		}
	}
}

calculate_total_num_of_ideas_trigger = {
	set_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_1 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_2 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_3 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_4 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_5 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_6 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_7 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_8 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_9 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_10 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_11 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_12 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_13 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_14 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_15 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_16 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_17 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_18 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_19 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_20 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_21 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_22 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_23 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_24 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_25 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_26 }
	add_to_temp_variable = { num_of_ideas_temp = completed_ideas_of_group_27 }
}