# Written by HansNery
add_namespace = md4
add_namespace = generic

# ROOT Receives Offer to Sign Free Trade Agreement
country_event = {
	id = md4.1
	title = md4.1.t
	desc = md4.1.d
	picture = GFX_negotiations
	is_triggered_only = yes

	option = { #Agree
		name = md4.1.a
		log = "[GetDateText]: [This.GetName]: md4.1.a executed"
		ai_chance = {
			base = 100
		}
		FROM = {
			add_opinion_modifier = {
				target = ROOT
				modifier = free_trade_agreement
			}
			country_event = { id = md4.2 hours = 6 }
		}
		add_opinion_modifier = {
			target = FROM
			modifier = free_trade_agreement
		}
		set_temp_variable = { receiver_nation = ROOT.id }
		set_temp_variable = { sender_nation = FROM.id }
		set_improved_trade_agreement = yes
		hidden_effect = {
			set_country_flag = fta_applicant@ROOT
			FROM = { set_country_flag = fta_inviter@ROOT }
		}
	}

	option = { #Refuse
		name = md4.1.b
		log = "[GetDateText]: [This.GetName]: md4.1.b executed"
		ai_chance = { base = 0 }
		FROM = {
			country_event = { id = md4.3 hours = 6 }
			add_opinion_modifier = {
				target = ROOT
				modifier = insult
			}
		}
	}

}

# ROOT signed Free Trade Agreement
country_event = {
	id = md4.2
	title = md4.2.t
	desc = md4.2.d
	picture = GFX_negotiations
	is_triggered_only = yes

	option = {
		name = md4.2.a
	}

}

# ROOT refused to sign Free Trade Agreement
country_event = {
	id = md4.3
	title = md4.3.t
	desc = md4.3.d
	picture = GFX_negotiations
	is_triggered_only = yes

	option = {
		name = md4.3.a
	}

}

# ROOT Receives Offer to Sign Military Cooperation Treaty
country_event = {
	id = md4.4
	title = md4.4.t
	desc = md4.4.d
	picture = GFX_handshake_black
	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			save_event_target_as = mct_applicant
			FROM = {
				save_event_target_as = mct_inviter
			}
		}
	}

	option = { #Agree
		name = md4.4.a
		log = "[GetDateText]: [This.GetName]: md4.4.a executed"
		ai_chance = {
			base = 100
		}
		FROM = {
			add_relation_modifier = {
				target = ROOT
				modifier = military_cooperation
			}
			country_event = { id = md4.5 hours = 6 }
		}
		add_political_power = -100
		army_experience = 25
		add_command_power = 15
		add_tech_bonus = {
			name = md4.4.t
			uses = 1
			bonus = 0.25
			category = CAT_special_forces_equipment
		} hidden_effect = { rq_eb_06e563e4ce = yes }
		add_doctrine_cost_reduction = {
			name = md4.4.t
			category = land_doctrine
			uses = 1
			cost_reduction = 0.25
		}
		hidden_effect = {
			set_country_flag = mct_applicant@ROOT
			FROM = { set_country_flag = mct_inviter@ROOT }
			news_event = { id = news.2 hours = 12 }
		}
	}

	option = { #Refuse
		name = md4.4.b
		log = "[GetDateText]: [This.GetName]: md4.4.b executed"
		ai_chance = { base = 0 }
		FROM = {
			country_event = { id = md4.6 hours = 6 }
			add_opinion_modifier = {
				target = ROOT
				modifier = insult
			}
		}
	}

}

# ROOT signed Military Cooperation Treaty
country_event = {
	id = md4.5
	title = md4.5.t
	desc = md4.5.d
	picture = GFX_handshake_black
	is_triggered_only = yes

	option = {
		name = md4.5.a
		log = "[GetDateText]: [This.GetName]: md4.5.a executed"
		add_political_power = -100
		army_experience = 25
		add_command_power = 15
		add_tech_bonus = {
			name = md4.5.t
			uses = 1
			bonus = 0.25
			category = CAT_special_forces_equipment
		} hidden_effect = { rq_eb_06e563e4ce = yes }
		add_doctrine_cost_reduction = {
			name = md4.5.t
			category = land_doctrine
			uses = 1
			cost_reduction = 0.25
		}
	}

}

# ROOT refused to sign Military Cooperation Treaty
country_event = {
	id = md4.6
	title = md4.6.t
	desc = md4.6.d
	picture = GFX_handshake_black
	is_triggered_only = yes

	option = {
		name = md4.6.a
	}

}

## Useful Vanilla Events ######################################

#####################################################################
#####################################################################

# Generic invitaton to join major Alliance
country_event = {
	id = generic.5
	title = generic.5.t
	desc = { # FROM and ROOT are different ideologies
		text = generic.5.d.e
		trigger = {
			NOT = {
				has_government = FROM
			}
		}
	}
	picture = GFX_politics_speak
	is_triggered_only = yes

	immediate = {
		hidden_effect = {
			save_event_target_as = alliance_applicant
			FROM = {
				save_event_target_as = alliance_inviter
			}
		}
	}

	option = { #Agree / Both Democratic
		name = generic.5.a
		log = "[GetDateText]: [This.GetName]: generic.5.a executed"
		trigger = {
			FROM = {
				has_government = democratic
			}
			has_government = democratic
		}
		ai_chance = {
			base = 100
		}
		FROM = {
			add_to_faction = ROOT
			country_event = { id = generic.6 hours = 6 }
		}
		hidden_effect = {
			set_country_flag = alliance_applicant@ROOT
			FROM = { set_country_flag = alliance_inviter@ROOT }
		}
	}

	option = { #Agree / Both Fascist
		name = generic.5.b
		log = "[GetDateText]: [This.GetName]: generic.5.b executed"
		trigger = {
			FROM = {
				has_government = fascism
			}
			has_government = fascism
		}
		ai_chance = {
			base = 100
		}
		FROM = {
			add_to_faction = ROOT
			country_event = { id = generic.6 hours = 6 }
		}
		hidden_effect = {
			set_country_flag = alliance_applicant@ROOT
			FROM = { set_country_flag = alliance_inviter@ROOT }
		}
	}

	option = { #Agree / Both Communist
		name = generic.5.c
		log = "[GetDateText]: [This.GetName]: generic.5.c executed"
		trigger = {
			FROM = {
				has_government = communism
			}
			has_government = communism
		}
		ai_chance = {
			base = 100
		}
		FROM = {
			add_to_faction = ROOT
			country_event = { id = generic.6 hours = 6 }
		}
		hidden_effect = {
			set_country_flag = alliance_applicant@ROOT
			FROM = { set_country_flag = alliance_inviter@ROOT }
		}
	}

	option = { #Agree / Both different
		name = generic.5.e
		log = "[GetDateText]: [This.GetName]: generic.5.e executed"
		trigger = {
			NOT = {
				has_government = FROM
			}
		}
		ai_chance = {
			base = 100
		}
		FROM = {
			add_to_faction = ROOT
			country_event = { id = generic.6 hours = 6 }
		}
		hidden_effect = {
			set_country_flag = alliance_applicant@ROOT
			FROM = { set_country_flag = alliance_inviter@ROOT }
		}
	}

	option = { #Reject
		name = generic.5.f
		log = "[GetDateText]: [This.GetName]: generic.5.f executed"
		ai_chance = { base = 0 }
		FROM = {
			country_event = { id = generic.7 hours = 6 }
		}
	}

}

# Generic accepted invitation to join major Alliance
country_event = {
	id = generic.6
	title = generic.6.t
	desc = generic.6.d
	picture = GFX_message_signing
	is_triggered_only = yes

	option = {
		name = generic.6.a
		trigger = {
			FROM = {
				has_government = democratic
			}
			has_government = democratic
		}
	}

	option = {
		name = generic.6.b
		trigger = {
			FROM = {
				has_government = fascism
			}
			has_government = fascism
		}
	}

	option = {
		name = generic.6.c
		trigger = {
			FROM = {
				has_government = communism
			}
			has_government = communism
		}
	}

	option = {
		name = generic.6.e
		trigger = {
			NOT = {
				has_government = FROM
			}
		}
	}

}

# Generic rejected invitation to join major Alliance
country_event = {
	id = generic.7
	title = generic.7.t
	desc = generic.7.d
	picture = GFX_politics_speak
	is_triggered_only = yes

	option = {
		name = generic.7.a
		trigger = {
			FROM = {
				has_government = democratic
			}
			has_government = democratic
		}
	}

	option = {
		name = generic.7.b
		trigger = {
			FROM = {
				has_government = fascism
			}
			has_government = fascism
		}
	}

	option = {
		name = generic.7.c
		trigger = {
			FROM = {
				has_government = communism
			}
			has_government = communism
		}
	}

	option = {
		name = generic.7.e
		trigger = {
			NOT = {
				has_government = FROM
			}
		}
	}

}

#####################################################################
#####################################################################

# Generic country demands us to submit
country_event = {
	id = md4.14
	title = md4.14.t
	desc = md4.14.d
	picture = GFX_political_deal
	is_triggered_only = yes

	option = {
		name = md4.14.a
		log = "[GetDateText]: [This.GetName]: md4.14.a executed"
		ai_chance = {
			base = 60
			modifier = {
				factor = 1.5
				strength_ratio = {
					tag = FROM
					ratio < 0.5
				}
			}
			modifier = {
				factor = 0.17
				strength_ratio = {
					tag = FROM
					ratio > 1.5
				}
			}
			modifier = {
				factor = 0
				strength_ratio = {
					tag = FROM
					ratio > 2
				}
			}
			modifier = {
				add = 1000
				has_country_flag = always_say_yes
			}
		}
		FROM = { country_event = { id = md4.15 hours = 6 } }
		clr_country_flag = always_say_yes
	}

	option = {
		name = md4.14.b
		log = "[GetDateText]: [This.GetName]: md4.14.b executed"
		ai_chance = {
			base = 40
			modifier = {
				factor = 0.25
				strength_ratio = {
					tag = FROM
					ratio < 0.5
				}
			}
			modifier = {
				factor = 2.25
				strength_ratio = {
					tag = FROM
					ratio > 1.5
				}
			}
			modifier = {
				factor = 100
				strength_ratio = {
					tag = FROM
					ratio > 2
				}
			}
			modifier = {
				add = 0
				has_country_flag = always_say_yes
			}
		}
		FROM = { country_event = { id = md4.16 hours = 6 } }
		clr_country_flag = always_say_yes
	}

}

# Generic country accepts submission
country_event = {
	id = md4.15
	title = md4.15.t
	desc = md4.15.d
	picture = GFX_political_deal
	is_triggered_only = yes

	option = {
		name = md4.15.a
		log = "[GetDateText]: [This.GetName]: md4.15.a executed"
		puppet = FROM
	}

}

# Generic country rejects submission
country_event = {
	id = md4.16
	title = md4.16.t
	desc = md4.16.d
	picture = GFX_political_deal
	is_triggered_only = yes

	option = {
		name = md4.16.a
		log = "[GetDateText]: [This.GetName]: md4.16.a executed"
		set_temp_variable = { wargoal_on = FROM }
		add_threat_from_wargoal_effect = yes
		create_wargoal = {
			target = FROM
			type = puppet_wargoal_focus
		}
	}

}

# Generic country accepts alliance (use only if country inviting is already in faction, otherwise define a custom faction name, eg. see Syria)
country_event = {
	id = md4.17
	title = md4.17.t
	desc = md4.17.d
	picture = GFX_political_deal
	is_triggered_only = yes

	option = {
		name = md4.17.a
		log = "[GetDateText]: [This.GetName]: md4.17.a executed"
		ai_chance = { base = 100 }
		if = {
			limit = {
				is_in_faction = yes
				is_faction_leader = yes
			}
			ROOT = { add_to_faction = FROM }
		}
		if = {
			limit = {
				is_in_faction = yes
				is_faction_leader = no
			}
			random_country = {
				limit = {
					is_in_faction_with = ROOT
					is_faction_leader = yes
				}
				add_to_faction = FROM
			}
		}
		if = {
			limit = {
				is_in_faction = no
			}
			if = {
				limit = {
					OR = {
						original_tag = SYR
						original_tag = FSA
						original_tag = NUS
					}
				}
				create_faction_from_template = faction_template_peninsula_sword
			}
			ROOT = { add_to_faction = FROM }
		}
		FROM = {
			add_ai_strategy = {
				type = befriend
				id = ROOT
				value = 200
			}
			add_ai_strategy = {
				type = alliance
				id = ROOT
				value = 200
			}
		}
		add_ai_strategy = {
			type = befriend
			id = FROM
			value = 200
		}
		add_ai_strategy = {
			type = alliance
			id = FROM
			value = 200
		}
	}

}

# Generic country rejects alliance
country_event = {
	id = md4.18
	title = md4.18.t
	desc = md4.18.d
	picture = GFX_treaty_rejected
	is_triggered_only = yes

	option = {
		name = md4.18.a
		log = "[GetDateText]: [This.GetName]: md4.18.a executed"
		ai_chance = { base = 100 }
		add_opinion_modifier = {
			target = ROOT
			modifier = insult
		}
	}

}

# Generic country cedes territory
country_event = {
	id = md4.19
	title = md4.19.t
	desc = md4.19.d
	picture = GFX_political_deal
	is_triggered_only = yes

	option = {
		name = md4.19.a
		log = "[GetDateText]: [This.GetName]: md4.19.a executed"
		ai_chance = { base = 100 }
		FROM = {
			every_state = {
				limit = { has_state_flag = SET_STATE_FOR_TRANSFER }
				if = {
					limit = { owner = { has_country_flag = STATE_TRANSFER_ADD_CORES } }
					add_core_of = ROOT
				}
				clr_state_flag = SET_STATE_FOR_TRANSFER
				ROOT = { transfer_state = PREV }
			}
			FROM = { clr_country_flag = STATE_TRANSFER_ADD_CORES }
		}
	}

}

# Generic country refuses to cede territory
country_event = {
	id = md4.20
	title = md4.20.t
	desc = md4.20.d
	picture = GFX_treaty_rejected
	is_triggered_only = yes

	option = {
		name = md4.20.a
		log = "[GetDateText]: [This.GetName]: md4.20.a executed"
		ai_chance = { base = 100 }
		FROM = {
			every_state = {
				limit = { has_state_flag = SET_STATE_FOR_TRANSFER }
				add_claim_by = ROOT
				if = {
					limit = { owner = { has_country_flag = STATE_TRANSFER_ADD_CORES } }
					add_core_of = ROOT
				}
				clr_state_flag = SET_STATE_FOR_TRANSFER
			}
			FROM = { clr_country_flag = STATE_TRANSFER_ADD_CORES }
		}
		set_temp_variable = { wargoal_on = FROM }
		set_temp_variable = { wargoal_type = 2 }
		add_threat_from_wargoal_effect = yes
		create_wargoal = {
			target = FROM
			type = annex_everything
		}
	}

}

# EAEU Integration Proposal

country_event = {
	id = md4.21
	title = md4.21.t
	desc = md4.21.d
	picture = GFX_eastern_europe
	is_triggered_only = yes

	option = { #Agree
		name = md4.21.a
		log = "[GetDateText]: [This.GetName]: md4.21.a executed"
		ai_chance = {
			base = 100
		}
		FROM = {
			add_opinion_modifier = {
				target = ROOT
				modifier = free_trade_agreement
			}
			country_event = { id = md4.22 hours = 6 }
		}
		add_opinion_modifier = {
			target = FROM
			modifier = free_trade_agreement
		}
		FROM = {
			add_ideas = EUR_idea_eacu_cooperation
		}
		set_temp_variable = { receiver_nation = ROOT.id }
		set_temp_variable = { sender_nation = FROM.id }
		set_improved_trade_agreement = yes
	}

	option = { #Refuse
		name = md4.21.b
		log = "[GetDateText]: [This.GetName]: md4.21.b executed"
		ai_chance = { base = 0 }
		FROM = {
			country_event = { id = md4.23 hours = 6 }
			add_opinion_modifier = {
				target = ROOT
				modifier = insult
			}
		}
	}

}

# ROOT signed EAEU Integration
country_event = {
	id = md4.22
	title = md4.22.t
	desc = md4.22.d
	picture = GFX_eastern_europe
	is_triggered_only = yes

	option = {
		name = md4.22.a
	}

}

# ROOT refused to sign EAEU Integration
country_event = {
	id = md4.23
	title = md4.23.t
	desc = md4.23.d
	picture = GFX_eastern_europe
	is_triggered_only = yes

	option = {
		name = md4.23.a
	}

}
