namespace = opium_wars

# Start event for obsessed country
opium_wars.1 = {
	type = country_event
	placement = ROOT

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

	duration = 3

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

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/opium_smoker"

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

	trigger = {
		NOT = { has_variable = opium_wars_start_var }
		any_primary_culture = {
			has_cultural_obsession = opium
		}
		is_country_type = unrecognized
		total_population > 5000000
		NOT = {
			any_country = {
				has_variable = opium_wars_target
			}
		}
		is_subject = no
		NOT = { has_law = law_type:law_free_trade }
		any_market = {
			owner = ROOT
			any_trade_route = {
				goods = g:opium
				importer.owner = ROOT
				NOT = { actor_market.owner = root }
				actor_market.owner = {
					country_rank >= rank_value:major_power
					# Exclude countries that already have a treaty port e.g. Portugal at game start
					NOT = {
						any_scope_state = {
							market = {
								owner = ROOT
							}
						}
					}
				}
			}
		}
		NOT = {
			has_modifier = opium_wars_addiction_modifier
		}
	}

	immediate = {
		set_variable = opium_wars_start_var
		random_primary_culture = {
			limit = {
				has_cultural_obsession = opium
			}
			save_scope_as = addicted_culture
		}
		random_market = {
			limit = {
				owner = ROOT
				any_trade_route = {
					goods = g:opium
					importer.owner = ROOT
					NOT = { actor_market.owner = root }
					actor_market.owner = {
						country_rank >= rank_value:major_power
						NOT = {
							any_scope_state = {
								market = {
									owner = ROOT
								}
							}
						}
					}
				}
			}
			random_trade_route = {
				limit = {
					goods = g:opium
					importer.owner = ROOT
					NOT = { actor_market.owner = root }
					actor_market.owner = {
						country_rank >= rank_value:major_power
					}
				}
				actor_market.owner = {
					save_scope_as = opium_importer
				}
			}
		}
	}

	option = {
		name = opium_wars.1.a
		default_option = yes
		set_variable = opium_wars_target
		set_variable = {
			name = opium_wars_completion_tracker
			value = 0
		}
		add_journal_entry = {
			type = je_opium_obsession
		}
		# send events to all applicable powers
			# can't just use the scope because we want to catch multiple countries if we can
		random_market = {
			limit = {
				owner = ROOT
				any_trade_route = {
					goods = g:opium
					importer.owner = ROOT
					NOT = { actor_market.owner = root }
					actor_market.owner = {
						country_rank >= rank_value:major_power
					}
				}
			}
			every_trade_route = {
				limit = {
					goods = g:opium
					importer.owner = ROOT
					NOT = { actor_market.owner = root }
					actor_market.owner = {
						country_rank >= rank_value:major_power
					}
				}
				actor_market.owner = {
					trigger_event = {
						id = opium_wars.2
					}
				}
			}
		}
		add_modifier = {
			name = opium_wars_addiction_modifier
			months = normal_modifier_time
		}
		ai_chance = {
			base = 100
		}
	}
	option = {
		name = opium_wars.1.b
		add_modifier = {
			name = opium_wars_addiction_modifier
			months = normal_modifier_time
		}
		ai_chance = {
			base = 10
		}
	}
}

# Start event for opium importer
opium_wars.2 = {
	type = country_event
	placement = ROOT

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

	duration = 3

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

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/opium_smoker"

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

	trigger = {
		# triggered by event
	}

	immediate = {
		save_scope_as = opium_wars_aggressor_country
		random_country = {
			limit = {
				has_variable = opium_wars_target
			}
			save_scope_as = opium_wars_target_country
			random_primary_culture = {
				limit = {
					has_cultural_obsession = opium
				}
				save_scope_as = opium_addicted_culture
			}
		}
	}

	option = { # go opium wars
		name = opium_wars.2.a
		default_option = yes
		set_variable = opium_wars_aggressor
		change_relations = {
			country = scope:opium_wars_target_country
			value = -30
		}
		add_journal_entry = {
			type = je_opium_wars
			target = scope:opium_wars_target_country
		}
		hidden_effect = {
			every_country = {
				limit = {
					NOT = { this = root }
					OR = {
						this = scope:opium_wars_target_country
						has_overlapping_interests = scope:opium_wars_target_country
						has_overlapping_interests = root
					}			
				}
				post_notification = opium_wars_british_response_angry
			}		
		
			scope:opium_wars_target_country = {
			
				set_secret_goal = {
					country = root
					secret_goal = antagonize			
				}		

		
		}
		if = {
limit = {

is_player = no

}
		
				create_diplomatic_play = {
			name = id_mod_yapianzhanzheng
			target_country = scope:opium_wars_target_country
			type = dp_take_treaty_port
		}
		}
		else = {
		ROOT = {
		
					
			set_secret_goal = {
				country = scope:opium_wars_target_country
				secret_goal = conquer
			}	
		
		}
		
		}
				
			
			
	
			}

		
		ai_chance = {
			base = 95
		}
	}
	option = { # not interested
		name = opium_wars.2.b
		change_relations = {
			country = scope:opium_wars_target_country
			value = 20
		}
		hidden_effect = {	
			every_country = {
				limit = {
					NOT = { this = root }
					OR = {
						this = scope:opium_wars_target_country
						has_overlapping_interests = scope:opium_wars_target_country
						has_overlapping_interests = root
					}			
				}
				post_notification = opium_wars_british_response_passive
			}	
		
			set_mutual_secret_goal = {
				country = scope:opium_wars_target_country
				secret_goal = befriend
			}		
		}		
		ai_chance = {
			base = 5
		}
	}
}

# Obssessed country succeeds
opium_wars.3 = {
	type = country_event
	placement = ROOT

	title = opium_wars.3.t
	desc = {
		first_valid = {
			triggered_desc = {
				desc = opium_wars.3.d
				trigger = {
					any_country = {
						has_variable = opium_wars_aggressor
					}
				}
			}
			triggered_desc = {
				desc = opium_wars.3.d2
				trigger = {
					always = yes
				}
			}
		}
	}
	flavor = opium_wars.3.f

	duration = 3

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

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/opium_smoker"

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

	trigger = {
		# triggered by JE complete
	}

	immediate = {
		random_primary_culture = {
			limit = {
				has_cultural_obsession = opium
			}
			save_scope_as = addicted_culture
		}
		if = {
			limit = {
				any_country = {
					has_variable = opium_wars_aggressor
				}
			}
			random_country = {
				limit = {
					has_variable = opium_wars_aggressor
				}
				save_scope_as = opium_wars_aggressor_country
			}
		}
		if = {
			limit = { has_journal_entry = je_warlord_china }
			post_notification = warlord_china_explosion_point_remove
			change_variable = {
				name = china_warlord_explosion
				subtract = 1
			}
		}
	}

	option = {
		name = opium_wars.3.a
		default_option = yes
		every_primary_culture = {
			remove_cultural_obsession = opium
		}
		add_modifier = {
			name = china_authority
			months = normal_modifier_time
		}
		remove_modifier = opium_wars_addiction_modifier
	}

	option = {
		name = opium_wars.3.b
		every_primary_culture = {
			remove_cultural_obsession = opium
		}
		add_modifier = {
			name = china_welfare
			months = normal_modifier_time
		}
		remove_modifier = opium_wars_addiction_modifier
	}
}

# Obsessed country fails
opium_wars.4 = {
	type = country_event
	placement = ROOT

	title = opium_wars.4.t
	desc = {
		first_valid = {
			triggered_desc = {
				desc = opium_wars.4.d
				trigger = {
					has_law = law_type:law_free_trade
				}
			}
			triggered_desc = {
				desc = opium_wars.4.d2
				trigger = {
					any_country = {
						has_variable = opium_wars_aggressor
						any_scope_state = {
							market = {
								owner = ROOT
							}
						}
					}
				}
			}
			triggered_desc = {
				desc = opium_wars.4.d3
				trigger = {
					always = yes
				}
			}
		}
	}
	flavor = opium_wars.4.f

	duration = 3

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

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/opium_smoker"

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

	trigger = {
		# triggered by JE complete
	}

	immediate = {
		if = {
			limit = {
				any_country = {
					has_variable = opium_wars_aggressor
					any_scope_state = {
						market = {
							owner = ROOT
						}
					}
				}
			}
			random_country = {
				limit = {
					has_variable = opium_wars_aggressor
					any_scope_state = {
						market = {
							owner = ROOT
						}
					}
				}
				save_scope_as = opium_wars_treaty_port_winner
				random_scope_state = {
					limit = {
						market = {
							owner = ROOT
						}
					}
					save_scope_as = treaty_port_state
				}
			}
		}
		if = {
			limit = { has_journal_entry = je_warlord_china }
			set_variable = lost_opium_wars
			post_notification = warlord_china_explosion_point_add
			change_variable = {
				name = china_warlord_explosion
				add = 1
			}
		}
	}

	option = {
		name = opium_wars.4.a
		default_option = yes
		add_modifier = {
			name = opium_wars_lost
			months = very_long_modifier_time
		}
		add_radicals = {
			value = very_large_radicals
		}
	}
}

# Importer country succeeds
opium_wars.5 = {
	type = country_event
	placement = ROOT

	title = opium_wars.5.t
	desc = {
		first_valid = {
			triggered_desc = {
				desc = opium_wars.5.d
				trigger = {
					scope:opium_wars_target_country = {
						has_law = law_type:law_free_trade
					}
				}
			}
			triggered_desc = {
				desc = opium_wars.5.d2
				trigger = {
					any_scope_state = {
						market = {
							owner = scope:opium_wars_target_country
						}
					}
				}
			}
		}
	}

	flavor = opium_wars.5.f

	duration = 3

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

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/opium_smoker"

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

	trigger = {
		# triggered by JE complete
	}

	immediate = {
		random_country = {
			limit = {
				has_variable = opium_wars_target
			}
			save_scope_as = opium_wars_target_country
		}
		if = {
			limit = {
				any_scope_state = {
					market = {
						owner = scope:opium_wars_target_country
					}
				}
			}
			random_scope_state = {
				limit = {
					market = {
						owner = scope:opium_wars_target_country
					}
				}
				save_scope_as = treaty_port_state
			}
		}
	}

	option = {
		name = opium_wars.5.a
		default_option = yes
		add_modifier = {
			name = opium_wars_navy_modifier
			months = normal_modifier_time
		}
	}

	option = {
		name = opium_wars.5.b
		add_modifier = {
			name = opium_wars_export_modifier
			months = normal_modifier_time
		}
	}
}

# Smugglers caught - triggered by embargo
opium_wars.6 = {
	type = country_event
	placement = ROOT

	title = opium_wars.6.t
	desc = opium_wars.6.d
	flavor = opium_wars.6.f

	duration = 3

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

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/opium_smoker"

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

	trigger = {
		is_banning_goods = opium
		any_country = {
			has_variable = opium_wars_aggressor
		}
		NOR = {
			has_modifier = executed_opium_smugglers
			has_modifier = returned_opium_smugglers
		}
	}

	immediate = {
		random_country = {
			limit = {
				has_variable = opium_wars_aggressor
			}
			save_scope_as = smuggler_country
		}
	}

	option = { # execute the smuggler
		name = opium_wars.6.a
		default_option = yes
		change_relations = {
			country = scope:smuggler_country
			value = -20
		}
		add_modifier = {
			name = executed_opium_smugglers
			months = short_modifier_time
		}
	}

	option = { # negotiate return
		name = opium_wars.6.b
		add_modifier = {
			name = returned_opium_smugglers
			months = short_modifier_time
		}
		change_relations = {
			country = scope:smuggler_country
			value = -10
		}
	}
}

# Addiction recovery
opium_wars.7 = {
	type = country_event
	placement = scope:recovry_state

	title = opium_wars.7.t
	desc = opium_wars.7.d
	flavor = opium_wars.7.f

	duration = 3

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

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/opium_smoker"

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

	trigger = {
		is_banning_goods = opium
		has_modifier = opium_wars_addiction_modifier
		any_scope_state = {
			NOR = {
				has_modifier = opium_health_focus
				has_modifier = opium_loyalty_focus
			}
			any_scope_pop = {
				culture = {
					has_cultural_obsession = opium
				}
			}
		}
	}

	immediate = {
		random_scope_state = {
			limit = {
				NOR = {
					has_modifier = opium_health_focus
					has_modifier = opium_loyalty_focus
				}
				any_scope_pop = {
					culture = {
						has_cultural_obsession = opium
					}
				}
			}
			save_scope_as = recovry_state
			random_scope_pop = {
				limit = {
					culture = {
						has_cultural_obsession = opium
					}
				}
				save_scope_as = recovery_pop
			}
		}
	}

	option = {
		name = opium_wars.7.a
		default_option = yes
		scope:recovry_state = {
			add_modifier = {
				name = opium_health_focus
				months = short_modifier_time
			}
		}
	}

	option = {
		name = opium_wars.7.b
		scope:recovry_state = {
			add_loyalists = {
				value = 0.3
			}
			add_modifier = {
				name = opium_loyalty_focus
				months = short_modifier_time
			}
		}
	}
}

# Addiction Ravages State
opium_wars.8 = {
	type = country_event
	placement = scope:opium_addiction_state

	title = opium_wars.8.t
	desc = opium_wars.8.d
	flavor = opium_wars.8.f

	duration = 3

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

	on_created_soundeffect = "event:/SFX/UI/Alerts/event_appear"
	on_opened_soundeffect = "event:/SFX/Events/europenorthamerica/opium_smoker"

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

	trigger = {
		any_scope_state = {
			NOR = {
				has_modifier = opium_addiction_state_mod
				has_modifier = lesser_opium_addiction_state_mod
			}
			any_scope_pop = {
				culture = {
					has_cultural_obsession = opium
				}
			}
		}
		NOT = { is_banning_goods = opium }
	}

	immediate = {
		random_scope_state = {
			limit = {
				any_scope_pop = {
					culture = {
						has_cultural_obsession = opium
					}
				}
			}
			save_scope_as = opium_addiction_state
			random_scope_pop = {
				limit = {
					culture = {
						has_cultural_obsession = opium
					}
				}
				culture = { save_scope_as = opium_addiction_pop }
			}
		}
	}

	option = {
		name = opium_wars.8.a
		default_option = yes
		trigger = {
			NOT = {
				institution_investment_level = {
					institution = institution_health_system
					value >= 2
				}
			}
		}
		scope:opium_addiction_state = {
			add_modifier = {
				name = opium_addiction_state_mod
				months = short_modifier_time
			}
		}
	}
	option = {
		name = opium_wars.8.b
		trigger = {
			institution_investment_level = {
				institution = institution_health_system
				value >= 2
			}
		}
		scope:opium_addiction_state = {
			add_modifier = {
				name = lesser_opium_addiction_state_mod
				months = short_modifier_time
			}
		}
	}
}
