namespace = heavenly

# Missionaries from treaty port build hospitals/schools
heavenly.1 = {
	type = country_event
	placement = scope:missionary_state

	title = heavenly.1.t
	desc = heavenly.1.d
	flavor = heavenly.1.f

	event_image = {
		video = "gfx/event_pictures/southamerica_christianity.bk2"
	}

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/southamerica/christianity"

	icon = "gfx/interface/icons/event_icons/event_scales.dds"

	duration = 3

	trigger = {
		NOT = {
			root.religion = {
				has_discrimination_trait = christian
			}
		}
		any_scope_state = {
			is_incorporated = yes
			any_scope_pop = {
				NOT = {
					religion = rel:protestant
				}
			}
			any_neighbouring_state = {
				is_treaty_port = yes
				owner = {
					religion = rel:protestant
				}
			}
		}
	}
	immediate = {
		random_scope_state = {
			limit = {
				is_incorporated = yes
				any_scope_pop = {
					NOT = {
						religion = rel:protestant
					}
				}
				any_neighbouring_state = {
					is_treaty_port = yes
					owner = {
						religion = rel:protestant
					}
				}
			}
			save_scope_as = missionary_state
			random_neighbouring_state = {
				limit = {
					is_treaty_port = yes
					owner = {
						religion = rel:protestant
					}
				}
				save_scope_as = treaty_port_scope
				owner = {
					save_scope_as = treaty_port_owner
				}
			}
		}
	}

	option = {
		name = heavenly.1.a
		default_option = yes
		scope:missionary_state = {
			add_modifier = {
				name = missionary_schools_hospitals
				months = normal_modifier_time
			}
			convert_population = {
				target = rel:protestant value = 0.05
			}
		}
	}
	option = {
		name = heavenly.1.b
		change_relations = {
			country = scope:treaty_port_owner
			value = -1
		}
		scope:missionary_state = {
			convert_population = {
				target = rel:protestant
				value = 0.01
			}
		}
	}
}

# The God Worshipping Society
heavenly.2 = {
	type = country_event
	placement = scope:cult_state

	title = heavenly.2.t
	desc = heavenly.2.d
	flavor = heavenly.2.f

	event_image = {
		video = "gfx/event_pictures/asia_union_leader.bk2"
	}

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/asia/union_leader"

	icon = "gfx/interface/icons/event_icons/event_newspaper.dds"

	duration = 3

	trigger = {
	}

	immediate = {
	random_subject_or_below = {
		random_scope_state = {
			limit = {
				has_modifier = god_worshippers
			}
			save_scope_as = cult_state
			set_variable = {
				name = cult_center
			}
		}
		}
	}
	option = {
		name = heavenly.2.a
		scope:cult_state = {
			# Already added when the Journal Entry activated, but we're going to remove it and add it again to make it visible to the player
			hidden_effect = {
				remove_modifier = god_worshippers
			}
			add_modifier = {
				name = god_worshippers
				months = short_modifier_time
			}
			convert_population = {
				target = rel:protestant value = 0.1
			}
		}
	}
}

# Cult Grows
# Repeatable
heavenly.3 = {
	type = country_event
	placement = scope:cult_growth_state

	title = heavenly.3.t
	desc = heavenly.3.d
	flavor = heavenly.3.f

	event_image = {
		video = "gfx/event_pictures/asia_union_leader.bk2"
	}

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/asia/union_leader"

	icon = "gfx/interface/icons/event_icons/event_newspaper.dds"

	duration = 3

	cooldown = { months = 3 }

	trigger = {
	any_subject_or_below = {
		any_scope_state = {
			has_variable = cult_center
			any_scope_pop = {
				has_pop_religion = protestant
			}
			any_neighbouring_state = {
				owner = ROOT
				NOT = {
					has_variable = cult_center
				}
				NOT = { is_capital = yes }
			}
		}
		}
	}
	immediate = {
	random_subject_or_below = {
		random_scope_state = {
			limit = {
				has_variable = cult_center
				any_scope_pop = {
					has_pop_religion = protestant
				}
				any_neighbouring_state = {
					owner = ROOT
					NOT = {
						has_variable = cult_center
					}
				}
			}
			save_scope_as = cult_center
			random_neighbouring_state = {
				limit = {
					owner = ROOT
					NOT = {
						has_variable = cult_center
					}
				}
				save_scope_as = cult_growth_state
				set_variable = {
					name = cult_center
				}
			}
		}
		}
	}
	option = {
		name = heavenly.3.a
		scope:cult_growth_state = {
			add_modifier = {
				name = god_worshippers
				months = short_modifier_time
			}
			convert_population = {
				target = rel:protestant value = 0.1
			}
		}
	}
}

# Heavenly Kingdom spawn
heavenly.4 = {
	type = country_event
	placement = ROOT

	title = heavenly.4.t
	desc = heavenly.4.d
	flavor = heavenly.4.f

	event_image = {
		video = "gfx/event_pictures/asia_union_leader.bk2"
	}

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/asia/union_leader"

	icon = "gfx/interface/icons/event_icons/event_fire.dds"

	duration = 3

	trigger = {

	}
	immediate = {
		every_state = {
			limit = {
				has_modifier = god_worshippers
			}
			remove_modifier = god_worshippers
		}
				if = {
		limit = {
		c:GNG = {
		is_player = no
		}
		
		}
		c:GNG = {
				random_scope_state = {
			save_scope_as = heavenly_kingdom_spawn
		}

		}
		
		}
	#	else_if = {
	#			c:GNG = {
	#	is_player = yes
	#	}
		
		
		
	#	}
		
		
		else_if = {
		limit = {
		any_country = {
		is_player = no
										OR = {
				has_diplomatic_pact = { who = c:MCH type = id_buzhengshi }
				has_diplomatic_pact = { who = c:MCH type = id_zongdu } 
				has_diplomatic_pact = { who = c:MCH type = id_dujun }
				has_diplomatic_pact = { who = c:MCH type = vassal }
				}
		
		
		}
		any_subject_or_below = {
		exists = this
		}
		
		}
		
		random_subject_or_below = {
		limit = {
		is_player = no
								OR = {
				has_diplomatic_pact = { who = c:MCH type = id_buzhengshi }
				has_diplomatic_pact = { who = c:MCH type = id_zongdu } 
				has_diplomatic_pact = { who = c:MCH type = id_dujun }
				has_diplomatic_pact = { who = c:MCH type = vassal }
				}
		
		}
		random_scope_state = {
			save_scope_as = heavenly_kingdom_spawn
		}
		}
		
		}

		else= {
				random_scope_state = {
			save_scope_as = heavenly_kingdom_spawn
		}
		}

		create_country = {
			tag = TPG
			origin = this
			state = scope:heavenly_kingdom_spawn
			on_created = {
				if = {
					limit = {
						NOT = {
							has_ruling_interest_group = ig_devout
						}
					}
					ig:ig_devout = {
						add_ruling_interest_group = yes
					}
				}
				if = {
					limit = {
						NOT = {
							has_law = law_type:law_theocracy
						}
					}
					activate_law = law_type:law_theocracy
				}
				if = {
					limit = {
						NOT = {
							has_law = law_type:law_state_religion
						}
					}
					activate_law = law_type:law_state_religion
				}
				if = {
					limit = {
						NOT = {
							has_law = law_type:law_peasant_levies
						}
					}
					activate_law = law_type:law_peasant_levies
				}
				add_modifier = {
					name = uprising_conscription
					months = normal_modifier_time
				}
			}
		}
				c:TPG = {
			save_scope_as = heavenly_kingdom_scope
			}
		if = {
		limit = {
		NOT = {
		any_country = {
		is_player = yes
										OR = {
				has_diplomatic_pact = { who = c:MCH type = id_buzhengshi }
				has_diplomatic_pact = { who = c:MCH type = id_zongdu } 
				has_diplomatic_pact = { who = c:MCH type = id_dujun }
				}
		}
		
		}

		
		}
		c:TPG = {
					if = {
			limit = {
				c:GNG = {
					is_player = no
				}
			}
			annex = c:GNG
									c:TPG = {
			set_capital =  STATE_GUANGXI
			}
		}
							if = {
			limit = {
				c:YUE = {
					is_player = no
				}
			}
			annex = c:YUE
						c:TPG = {
			set_capital =  STATE_GUANGDONG
			}
		}
													if = {
			limit = {
				c:HNA = {
					is_player = no
				}
			}
			annex = c:HNA
						c:TPG = {
			set_capital =  STATE_EASTERN_HUBEI
			}
		}
									if = {
			limit = {
				c:AHU = {
					is_player = no
				}
			}
			annex = c:AHU
			
			c:TPG = {
			set_capital =  STATE_NANJING
			}
		}

					every_scope_state = {
				set_state_type = incorporated
			}
		}
		}
		if = {
			limit = { has_journal_entry = je_warlord_china }
			post_notification = warlord_china_explosion_point_add
			change_variable = {
				name = china_warlord_explosion
				add = 1
			}
		}
	}

	option = {
		name = heavenly.4.a
		default_option = yes
		ai_chance = { base = 1 }
		add_journal_entry = {
			type = je_taiping
		}
		if = {
			limit = {
				any_scope_state = {
					has_variable = cult_center
				}
			}
			every_scope_state = {
				limit = {
					has_variable = cult_center
				}
				set_state_owner = c:TPG
				set_state_type = incorporated
			}
			every_scope_state = {
				limit = {
					is_capital = no
					NOT = { has_variable = cult_center }
					any_neighbouring_state = {
						has_variable = cult_center
					}
					turmoil > 0.1
				}
				set_state_owner = c:TPG
				set_state_type = incorporated
			}
		}
		create_diplomatic_play = {
			name = taiping_rebellion
			target_country = scope:heavenly_kingdom_scope
			type = dp_taiping_rebellion
		}
	}
	option = {
		name = heavenly.4.b
		ai_chance = { base = 0 }
		if = {
			limit = {
				any_scope_state = {
					has_variable = cult_center
				}
			}
			every_scope_state = {
				limit = {
					has_variable = cult_center
				}
				set_state_owner = c:TPG
				set_state_type = incorporated
			}
			every_scope_state = {
				limit = {
					is_capital = no
					NOT = { has_variable = cult_center }
					any_neighbouring_state = {
						has_variable = cult_center
					}
					turmoil > 0.1
				}
				set_state_owner = c:TPG
				set_state_type = incorporated
			}
		}
		create_diplomatic_play = {
			name = taiping_rebellion
			target_country = scope:heavenly_kingdom_scope
			type = dp_taiping_rebellion
		}
		play_as = scope:heavenly_kingdom_scope
	}
}

# Aftermath event
heavenly.5 = {
	type = country_event
	placement = ROOT

	title = heavenly.5.t
	desc = heavenly.5.d
	flavor = heavenly.5.f

	event_image = {
		video = "gfx/event_pictures/asia_union_leader.bk2"
	}

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/asia/union_leader"

	icon = "gfx/interface/icons/event_icons/event_newspaper.dds"

	duration = 3

	trigger = {
		# triggered by journal entry
	}

	option = { # mass re-conversions
		name = heavenly.5.a
		default_option = yes
		every_scope_state = {
			limit = {
				any_scope_pop = {
					religion = rel:protestant
				}
			}
			convert_population = {
				target = rel:mahayana value = 0.1
			}
		}
		every_country = {
			limit = {
				country_rank >= rank_value:great_power
				religion = {
					has_discrimination_trait = christian
				}
			}
			create_incident = {
				country = root
				value = 25
			}
		}
	}
	option = { # mercy and pardons
		name = heavenly.5.b
		add_loyalists = {
			value = 0.2
			religion = rel:protestant
		}
		every_country = {
			limit = {
				country_rank >= rank_value:great_power
				religion = {
					has_discrimination_trait = christian
				}
			}
			create_incident = {
				country = root
				value = 25
			}
		}
	}
}
