#historical events for hearts of iron 4 - initially created by CSRZ for 1.7.1 Hydra/Man the Guns

add_namespace = japsov

#Soviet Union dows Japan after the war in Europe is over
country_event = {
	id = japsov.1
	title = japsov.1.t
	desc = japsov.1.d

	picture = GFX_report_soviets_invade_manchuria

	fire_only_once = yes

	trigger = {
		tag = SOV
		has_government = communism
		is_subject = no
		NOT = { has_war_with = GER }
		OR = {
			GER = { NOT = { has_government = fascism } }
			NOT = { country_exists = GER }
			GER = { is_subject = yes }
		}
		JAP = { has_government = fascism }
		JAP = { is_subject = no }
		OR = {
			JAP = { has_war_with = USA }	
			JAP = { has_war_with = ENG }
			AND = {
				date > 1942.01.01
				JAP = { has_war_with = PRC }
			}	
		}
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = japsov.1.a
		ai_chance = { factor = 100 }
		declare_war_on = {
			target = JAP
			type = annex_everything
		}
		set_global_flag = soviet_japan_war_gets_hot
	}

	option = {
		name = japsov.1.b
	}
}

#Japan dows Soviet Union if the Soviet Union is on the verge of collapse
country_event = {
	id = japsov.2
	title = japsov.2.t
	desc = japsov.2.d

	picture = GFX_report_the_end_of_soviet_union

	fire_only_once = yes

	trigger = {
		tag = JAP
		#NOT = { JAP = { has_war_with = SOV } } #will fire even if Japanese player already is in war with the Soviet Union
		NOT = { JAP = { has_war_with = GER } }
		has_government = fascism
		SOV = { has_government = communism }
		is_subject = no
		SOV = { is_subject = no }
		SOV = { has_war_with = GER }
		SOV = { surrender_progress > 0.15 }
		OR = {
			SOV = {
				NOT = {
					controls_state = 219 # Moscow
					#controls_state = 214 # Arkhangelsk
					controls_state = 195 # Leningrad 
					controls_state = 217 # Stalingrad
				}
			}
			SOV = { surrender_progress > 0.75 }
		}
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = japsov.2.a
		ai_chance = { factor = 100 }
		declare_war_on = {
			target = SOV
			type = annex_everything
		}
		hidden_effect = {
			news_event = { id = japsov.3 hours = 6 }
			set_global_flag = japan_claims_vladivostok
		}
	}

	option = {
		name = japsov.2.b
	}
}

#The End of the Soviet Union
news_event = {
	id = japsov.3
	title = japsov.3.t
	desc = japsov.3.d
	picture = GFX_news_event_the_end_of_soviet_union	

	major = yes

	#fire_only_once = yes

	is_triggered_only = yes

	option = {
		name = japsov.3.a #the era of communism in Europe is over
		trigger = {
			OR = {
				has_government = communism
			}
		}
	}

	option = {
		name = japsov.3.b #what does it mean for us?
		trigger = {
			NOT = {
				has_government = communism
			}
		}
	}	
}

#Peace Treaty of Vladivostok - part I - very similar to Ribentrop-Molotov, but between Germany and Japan - will result in German-Japanese border on the lake Bajkal
country_event = {
	id = japsov.4
	title = japsov.4.t
	desc = japsov.4.d

	picture = GFX_report_the_end_of_soviet_union

	fire_only_once = yes

	trigger = {
		tag = JAP
		has_global_flag = japan_claims_vladivostok
		is_subject = no
		NOT = { country_exists = SOV }
		NOT = { has_war_with = GER }
		GER = { owns_state = 219 } # Moscow
	}

	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = japsov.4.a
		ai_chance = { factor = 100 }
		GER = { country_event = { id = japsov.5 } }
	}

	option = {
		name = japsov.4.b
	}
}

#Peace Treaty of Vladivostok - part II
country_event = {
	id = japsov.5
	title = japsov.5.t
	desc = japsov.5.d

	picture = GFX_report_the_end_of_soviet_union

	fire_only_once = yes

	is_triggered_only = yes

	mean_time_to_happen = {
		days = 1
	}

	option = {
		name = japsov.5.a
		ai_chance = { factor = 100 }
		if = {
			limit = {
				644 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 644
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 644 }
		}
		if = {
			limit = {
				637 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 637
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 637 }
		}
		if = {
			limit = {
				562 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 562
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 562 }
		}
		if = {
			limit = {
				574 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 574
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 574 }
		}
		if = {
			limit = {
				563 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 563
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 563 }
		}
		if = {
			limit = {
				564 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 564
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 564 }
		}
		if = {
			limit = {
				565 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 565
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 565 }
		}
		if = {
			limit = {
				560 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 560
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 560 }
		}
		if = {
			limit = {
				561 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 561
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 561 }
		}
		if = {
			limit = {
				655 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 655
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 655 }
		}
		if = {
			limit = {
				657 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 657
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 657 }
		}
		if = {
			limit = {
				408 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 408
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 408 }
		}
		if = {
			limit = {
				409 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 409
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 409 }
		}
		if = {
			limit = {
				330 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 330
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 330 }
		}

		if = {
			limit = {
				817 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 817
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 817 }
		}
		if = {
			limit = {
				818 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 818
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 818 }
		}
		if = {
			limit = {
				819 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 819
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 819 }
		}
		if = {
			limit = {
				820 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 820
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 820 }
		}



		if = {
			limit = {
				329 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 329
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 329 }
		}
		if = {
			limit = {
				822 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 822
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 822 }
		}
		if = {
			limit = {
				874 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 874
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 874 }
		}
		if = {
			limit = {
				875 = {
					OR = {
						is_controlled_by = GER
						any_other_country = {
							controls_state = 875
							is_in_faction_with = GER
							GER = { is_faction_leader = yes }
						}
					}
				}
			}
			JAP = { transfer_state = 875 }
		}

	}

	option = {
		name = japsov.5.b
	}
}

#Mengjiang becomes Mongol Empire - part I
country_event = {
	id = japsov.6
	title = japsov.6.t
	desc = japsov.6.d
	picture = GFX_report_soviets_invade_manchuria

	fire_only_once = yes

	trigger = {
		tag = JAP
		owns_state = 330
		country_exists = MEN
		OR = {
			MEN = { is_subject_of = JAP }
			MEN = { is_in_faction_with = JAP }
		}
	}

	mean_time_to_happen = {
		days = 2
	}

	option = {
		name = japsov.6.a
		ai_chance = { factor = 100 }
		MEN = { transfer_state = 330 }
		MEN = { transfer_state = 817 }
		MEN = { transfer_state = 818 }
		MEN = { transfer_state = 819 }
		MEN = { transfer_state = 820 }
	}

	option = {
		name = japsov.6.b
	}
}

#Mengjiang becomes Mongol Empire - part II
country_event = {
	id = japsov.7
	title = japsov.7.t
	desc = japsov.7.d
	picture = GFX_report_soviets_invade_manchuria

	fire_only_once = yes

	trigger = {
		tag = JAP
		owns_state = 329
		country_exists = MEN
		OR = {
			MEN = { is_subject_of = JAP }
			MEN = { is_in_faction_with = JAP }
		}
	}

	mean_time_to_happen = {
		days = 2
	}

	option = {
		name = japsov.7.a
		ai_chance = { factor = 100 }
		MEN = { transfer_state = 329 }	
	}

	option = {
		name = japsov.7.b
	}
}

#Mengjiang becomes Mongol Empire - part III
country_event = {
	id = japsov.8
	title = japsov.8.t
	desc = japsov.8.d
	picture = GFX_report_soviets_invade_manchuria

	fire_only_once = yes

	trigger = {
		tag = MEN
		owns_state = 330
	}

	mean_time_to_happen = {
		days = 2
	}

	option = {
		name = japsov.8.a
		ai_chance = { factor = 100 }
		set_capital = { state = 330 }
		330 = { add_core_of = MEN }
		329 = { add_core_of = MEN }
		817 = { add_core_of = MEN }
		818 = { add_core_of = MEN }
		819 = { add_core_of = MEN }
		820 = { add_core_of = MEN }
	}

	option = {
		name = japsov.8.b
	}
}

#Soviet Union releases Korea and China
country_event = {
	id = japsov.9
	title = japsov.9.t
	desc = japsov.9.d
	picture = GFX_report_soviets_invade_manchuria

	#fire_only_once = yes #will fire until there is no viable states to release or option b is taken

	trigger = {
		tag = SOV
		OR = { 
			owns_state = 525 #Korea
			owns_state = 527 #Korea
			owns_state = 609 #East Hebei
			owns_state = 745 #Manchuria
			owns_state = 610
			owns_state = 716
			owns_state = 715
			owns_state = 328
			owns_state = 717
			owns_state = 714
			owns_state = 761
			owns_state = 611 #Mengjiang
			owns_state = 612
		}
		NOT = { has_country_flag = interested_in_annexing_korea_and_china }		
	}

	mean_time_to_happen = {
		days = 2
	}

	option = {
		name = japsov.9.a
		ai_chance = { factor = 100 }
		release_puppet = KOR
		release = PRC
	}

	option = {
		name = japsov.9.b
		set_country_flag = interested_in_annexing_korea_and_china
	}
}

#Mengjiang dissapears forever into the void - meant to block other countries from releasing it (anti-border gore measure)
#country_event = {
#	id = japsov.10
#	title = japsov.10.t
#	desc = japsov.10.d
#	picture = GFX_report_soviets_invade_manchuria
#
#	fire_only_once = yes
#
#	trigger = {
#		tag = JAP
#		NOT = { country_exists = MEN }		
#	}
#
#	mean_time_to_happen = {
#		days = 2
#	}
#
#	option = {
#		name = japsov.10.a
#		ai_chance = { factor = 100 }
#		every_state = {
#			if = {
#				limit = { is_core_of = MEN }
#				remove_core_of = MEN
#			}
#		}
#	}
#}

#Mongolia becomes the Soviet puppet
country_event = {
	id = japsov.11
	title = japsov.11.t
	desc = japsov.11.d
	picture = GFX_report_soviets_invade_manchuria

	fire_only_once = yes
	
	trigger = {
		tag = SOV
		country_exists = MON
		NOT = { country_exists = TAN }
		MON = { is_in_faction_with = SOV }
	}

	mean_time_to_happen = {
		days = 2
	}

	option = {
		name = japsov.11.a
		ai_chance = { factor = 100 }
		MON = {
			country_event = { id = japsov.12 }
		}
	}

	option = {
		name = japsov.11.b
	}
}

country_event = {
	id = japsov.12
	title = japsov.12.t
	desc = japsov.12.d
	picture = GFX_report_soviets_invade_manchuria
	
	is_triggered_only = yes
	
	option = { # Accept
		name = japsov.12.a
		ai_chance = { factor = 100 }
		SOV = {
			country_event = { id = japsov.14 }
		}
		#custom_effect_tooltip = GAME_OVER_TT #It's not game over only a puppeting.
	}
	option = { # Refuse
		name = japsov.12.b
		SOV = {
			country_event = { id = japsov.13 }
		}
	}
}

# Mongolia declines the offer
country_event = {
	id = japsov.13
	title = japsov.13.t
	desc = japsov.13.d
	picture = GFX_report_soviets_invade_manchuria
	
	is_triggered_only = yes
	
	option = {
		name = japsov.13.a
	}
}

# Mongolia accepts the offer
country_event = {
	id = japsov.14
	title = japsov.14.t
	desc = japsov.14.d
	picture = GFX_report_soviets_invade_manchuria
	
	is_triggered_only = yes
	
	option = {
		name = japsov.14.a
		puppet = MON
	}
}

# South Sakhalin and Kuriles fix - OUTDATED - better version for La Resistance below
#country_event = {
#	id = japsov.16
#	
#	trigger = {
#		tag = SOV
#		country_exists = SOV
#	}
#
#	mean_time_to_happen = { days = 2 }
#
#	hidden = yes
#
#	fire_only_once = yes
#
#	immediate = {
#		537 = {
#			add_core_of = SOV
#		}
#	}
#}

#country_event = {
#	id = japsov.17
#	
#	trigger = {
#		tag = SOV
#		country_exists = SOV
#		SOV = { has_war_with = JAP }
#	}
#
#	mean_time_to_happen = { days = 2 }
#
#	hidden = yes
#
#	fire_only_once = yes
#
#	immediate = {
#		555 = {
#			add_claim_by = SOV
#		}
#	}
#}

#If Soviet AI controls North Sakhalin it will automatically gain South Sakhalin after peace conference to reduce border gore in Asia

country_event = {
	id = japsov.18
	
	trigger = {
		tag = SOV
		country_exists = SOV
		SOV = { owns_state = 655 }
		NOT = { SOV = { owns_state = 537 } }
		NOT = { SOV = { has_war_with = JAP } } #It wouldn't make sense
		OR = {
			AND = {
				JAP = { surrender_progress > 0.25 }
				JAP = { owns_state = 537 }
			}
			NOT = { country_exists = JAP }
			JAP = { is_subject = yes }
		}
	}

	mean_time_to_happen = { days = 2 }

	fire_only_once = yes

	option = { # Rush Japan
		name = japsov.18.a
		ai_chance = { factor = 100 }
		537 = {
			add_core_of = SOV
			remove_core_of = JAP
		}
		SOV = { transfer_state = 537 }
		SOV = { transfer_state = 555 } #Soviets will occupy Kuriles
		JAP = {
			country_event = { id = japsov.19 }
		}
	}
	option = { # Don't
		name = japsov.18.b
	}
}


# Soviets invade Sakhalin and Kuriles
country_event = {
	id = japsov.19
	title = japsov.19.t
	desc = japsov.19.d
	picture = GFX_report_soviets_invade_manchuria
	
	is_triggered_only = yes
	
	option = {
		name = japsov.19.a
		537 = {
			remove_core_of = JAP
		}
	}
}