﻿da_knowledge_sharing = {
	groups= {
		power_bloc_leader
		overlord
	}
	requires_approval = no
	should_notify_third_parties = yes
	show_effect_in_tooltip = yes

	texture = "gfx/interface/icons/diplomatic_action_icons/knowledge_sharing.dds"
	confirmation_sound = "event:/SFX/UI/MapInteraction/SubjectInteractions/diplomatic_action_subjects_10_knowledge_sharing_benign"
	selectable = {
		has_dlc_feature = subject_and_bloc_actions
	}

	possible = {
		scope:target_country = {
			NOT = { is_diplomatic_play_enemy_of = root }
		}
	}

	accept_effect = {
		add_overlord_lobby_appeasement_from_diplomacy = {
			FIRST = scope:target_country
			SECOND = root
			PRO_AMOUNT = 2
			ANTI_AMOUNT = -2
			FACTOR = appeasement_knowledge_sharing_started
		}

		if = {
			limit = {
				scope:target_country = {
					is_subject_of = root
				}
			}
			custom_tooltip = {
				text = "DIPLOMATIC_PACT_REDUCED_LIBERTY_DESIRE"
			}
		}
	}

	pact = {
		cost = 50
		maintenance_paid_by = first_country
		forced_duration = 12

		first_modifier = {
			country_tech_spread_mult = -0.10
		}

		second_modifier = {
			country_tech_spread_mult = 0.25
			country_liberty_desire_add = -0.05
		}

		actor_can_break = {
			always = yes
		}

		requirement_to_maintain = {
			trigger = {
				scope:target_country = {
					OR = {
						is_subject_of = root
						power_bloc.power_bloc_leader ?= root
					}
				}
			}
		}

		requirement_to_maintain = {
			trigger = {
				custom_tooltip = {
					text = "DIPLOMATIC_PACT_REQUIREMENT_MORE_TECHS_RESEARCHED"
					techs_researched > scope:target_country.techs_researched
				}
			}
		}

		manual_break_effect = {
			scope:target_country = {
				if = {
					limit = { is_subject_of = root }
					add_liberty_desire = 10
				}
			}

			add_overlord_lobby_appeasement_from_diplomacy = {
				FIRST = scope:target_country
				SECOND = root
				PRO_AMOUNT = -2
				ANTI_AMOUNT = 2
				FACTOR = appeasement_knowledge_sharing_ended
			}
		}
	}

	ai = {
		max_influence_spending_fraction = 0.1

		evaluation_chance = {
			value = 0.25
		}

		propose_score = {
			value = 1 # Low propose score, AI should replace this with other pacts if needed

			add = {
				value = scope:target_country.country_rank
				multiply = 1
			}
		}

		will_propose = {
			modifier:country_tech_spread_mult > -0.25 # don't compromise tech spread more than -25%
			has_attitude = {
				who = scope:target_country
				attitude = protective
			}
			NOT = { is_country_type = unrecognized }
			OR = {
				scope:target_country = { liberty_desire >= 25 }
				NOT = {
					any_subject_or_below = {
						root = {
							has_diplomatic_pact = {
								type = da_knowledge_sharing
								who = prev
							}
						}
					}
				}
			}
			# KAI: Only worth doing if target country has high enough population
			scope:target_country = {
				is_direct_subject_of = root
				this.total_population >= {
					value = root.total_population
					multiply = 0.4
				}
			}
		}

		will_break = {
			OR = {
				has_attitude = {
					who = scope:target_country
					attitude = domineering
				}
				is_country_type = unrecognized
				modifier:country_tech_spread_mult <= -0.5
			}
		}

		accept_score = {
			value = 0

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_BASE"
				value = -100
			}

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_TECH_SPREAD_VALUE"
				value = modifier:country_tech_spread_mult
				add = 0.25
				multiply = 200
			}

			if = {
				limit = {
					"scope:actor.ai_ideological_opinion(root)" > 0
				}
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_IDEOLOGICAL_OPINION"
					value = "scope:actor.ai_ideological_opinion(root)"
					multiply = 0.5
					max = 25
				}
			}
			else_if = {
				limit = {
					"scope:actor.ai_ideological_opinion(root)" < 0
				}
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_IDEOLOGICAL_OPINION_NEGATIVE"
					value = "scope:actor.ai_ideological_opinion(root)"
					multiply = 0.5
					min = -25
				}
			}

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_ATTITUDE"
				if = {
					limit = {
						has_attitude = {
							who = scope:actor
							attitude = protective
						}
					}
					value = 50
				}
				else_if = {
					limit = {
						has_attitude = {
							who = scope:actor
							attitude = domineering
						}
					}
					value = -50
				}
			}

			if = {
				limit = {
					scope:actor = { is_subject_of = root }
				}
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_ACTOR_LIBERTY_DESIRE"
					value = "scope:actor.liberty_desire"
					subtract = 50
				}
			}

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_RELATIONS"
				if = {
					limit = {
						"relations(scope:actor)" >= relations_threshold:friendly
					}
					value = 100
				}
				else_if = {
					limit = {
						"relations(scope:actor)" >= relations_threshold:amicable
					}
					value = 50
				}
				else_if = {
					limit = {
						"relations(scope:actor)" >=  relations_threshold:cordial
					}
					value = 25
				}
				else_if = {
					limit = {
						"relations(scope:actor)" > relations_threshold:poor
					}
					value = -50
				}
				else = {
					value = -75
				}
			}

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_INFAMY"
				if = {
					limit = {
						"scope:actor.infamy" >= infamy_threshold:infamous
						"scope:actor.infamy" < infamy_threshold:notorious
					}
					value = -10
				}
				if = {
					limit = {
						"scope:actor.infamy" >= infamy_threshold:notorious
						"scope:actor.infamy" < infamy_threshold:pariah
					}
					value = -25
				}
				if = {
					limit = {
						"scope:actor.infamy" >= infamy_threshold:pariah
					}
					value = -50
				}
			}
		}
	}
}

da_request_knowledge_sharing = {
	groups= {
		subject
	}
	requires_approval = yes
	should_notify_third_parties = yes
	show_effect_in_tooltip = yes
	uses_random_approval = yes

	texture = "gfx/interface/icons/diplomatic_action_icons/knowledge_sharing.dds"
	confirmation_sound = "event:/SFX/UI/MapInteraction/SubjectInteractions/diplomatic_action_subjects_10_knowledge_sharing_benign"

	possible = {
		NOT = { is_diplomatic_play_enemy_of = scope:target_country }
		custom_tooltip = {
			text = "KNOWLEDGE_SHARING_ON_COOLDOWN"
			NOT = {
				scope:target_country = {
					any_diplomatic_catalyst = {
						is_diplomatic_catalyst_type = catalyst_knowledge_sharing_requested
						target = root
					}
				}
			}
		}
	}

	accept_effect = {
		add_overlord_lobby_appeasement_from_diplomacy = {
			FIRST = root
			SECOND = scope:target_country
			PRO_AMOUNT = 2
			ANTI_AMOUNT = -2
			FACTOR = appeasement_knowledge_sharing_started
		}

		if = {
			limit = {
				scope:target_country = {
					is_subject_of = root
				}
			}
			custom_tooltip = {
				text = "DIPLOMATIC_PACT_REDUCED_LIBERTY_DESIRE"
			}
		}
	}

	decline_effect = {
		scope:target_country = { change_relations = { country = root value = -20 } }
		if = {
			limit = {
				is_subject_of = scope:target_country
			}
			add_liberty_desire = 10
		}
		hidden_effect = {
			scope:target_country = {
				create_diplomatic_catalyst = {
					type = catalyst_knowledge_sharing_requested
					target = root
				}
			}
		}
	}

	reverse_pact = da_knowledge_sharing

	ai = {
		evaluation_chance = {
			value = 0.25
		}

		propose_score = {
			value = {
				add = scope:target_country.techs_researched
				subtract = techs_researched
			}
		}

		will_propose = {
			techs_researched < scope:target_country.techs_researched
		}

		will_break = {
			OR = {
				government_legitimacy < 50
				"ai_ideological_opinion(scope:target_country)" <= -25
				has_attitude = {
					who = scope:target_country
					attitude = domineering
				}
			}
		}

		will_propose_even_if_not_accepted = {
			techs_researched < {
				add = scope:target_country.techs_researched
				multiply = 0.2
			}
		}
	}
}
