on_actions = {

	on_startup = {
		effect = {
			set_global_flag = mod_ragnarok_1937
			
			GER = { country_event = ragnarok.41 } # Mod start message
		}
	}

	# ROOT = country that joined a war
	on_war = { 
		effect = {
			if = {
				limit = {
					NOT = { has_idea = weak_forts }
				}
				add_ideas = weak_forts
			}
		}
	}
	
	## ROOT is subject, FROM is previous overlord
	#on_subject_free = {

	# ROOT is free nation, FROM is releaser
	on_release_as_free = {
		effect = {
			if = {
				limit = {
					ROOT = {					
						NOT = { has_idea = weak_forts }
					}
				}
				ROOT = { add_ideas = weak_forts }
			}
		}

		effect = {
			if = {
				limit = {
					OR = {
						has_global_flag = ragnarok_party
						has_global_flag = ragnarok_early_war
					}
					ROOT = {
						NOT = { tag = GER }
						is_ai = yes # Exclude other player-controlled nations that might be working with Germany					
					}
					USA = {
						exists = yes
						has_war_with = GER
						NOT = { has_war_with = ROOT }
					}
				}

				# Leave faction if not in the Allies already
				if = {
					limit = {
						ROOT = {
							is_in_faction = yes
							NOT = { is_in_faction_with = USA }
						}
					}

					ROOT = { leave_faction = yes }
				}

				# Join Allies
				if = {
					limit = {
						ROOT = {
							is_in_faction = no
						}
					}

					random_country = {
						limit = {
							is_faction_leader = yes
							has_war_with = GER
						}
						
						add_to_faction = ROOT
					}
				}

				# Join the war against Germany
				if = {
					limit = {
						ROOT = {
							NOT = { has_war_with = GER }
						}
					}
					
					if = {
						limit = {
							FRA = {
								exists = yes
								has_war_with = GER
							}
						}
						
						ROOT = {
							add_to_war = { targeted_alliance = FRA enemy = GER hostility_reason = ally }
						}
					}
					else = {
						ROOT = {
							add_to_war = { targeted_alliance = USA enemy = GER hostility_reason = ally }
						}
					}
				}
				
				if = {
					limit = {
						has_global_flag = ragnarok_applied_stable_government
						ROOT = {
							has_war_with = GER
						}
					}

					ROOT = {
						apply_AI_bonuses = yes
					}
				}
				
				if = {
					limit = {
						ROOT = {
							is_european_country = yes
							has_war_with = GER
						}
					}
					
					ROOT = {
						complete_industrial_focuses = yes
					}
				}
			}
		}
	}
	
}