﻿INJECT:trade_privilege = {
	ai = {

		treaty_categories = {
			trade
		}

		evaluation_chance = {
			value = 0.1

			if = {
				limit = {
					c:RUS ?= this
					has_variable = ai_russia_client_bloc_pending
				}
				add = 0.15
			}
		}

		proposal_weight = {
			value = 1

			if = {
				limit = {
					c:RUS ?= this
					ai_russia_article_partner_is_pending_client = yes
					scope:other_country = {
						is_subject = yes
					}
				}
				add = 5
			}
		}

		article_ai_usage = {
			request
		}

		inherent_accept_score = {
			value = 0

			if = {
				limit = {
					scope:source_country ?= this
				}

				# We are doing this to be able to reuse loc across treaties and diplomatic actions
				scope:source_country = {
					save_temporary_scope_as = target
				}
				scope:target_country = {
					save_temporary_scope_as = actor
				}

				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_BASE_ADDITIONAL"
					value = -25
				}

				if = {
					limit = {
						has_law_or_variant = law_type:law_isolationism
					}
					add = {
						desc = "law_isolationism"
						add = -100
					}
				}

				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_GDP"
					value = "scope:target_country.ai_gdp_comparison(root)"
					multiply = 2
					min = -10
					max = 10
				}

				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_MUTUAL_TRADE_VALUE"
					value = "mutual_trade_value_with_country(scope:target_country)"
					multiply = 50000
					divide = { # We modulate this value by GDP, clamped to a range to ensure it remains relevant for very small/very large economies
						value = gdp
						max = scope:target_country.gdp # We use whichever GDP is smaller
						min = 1000000
					}
					min = 1
					max = 10
				}

				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_ATTITUDE"
					if = {
						limit = {
							OR = {
								has_attitude = {
									who = scope:target_country
									attitude = antagonistic
								}
								has_attitude = {
									who = scope:target_country
									attitude = domineering
								}
								has_attitude = {
									who = scope:target_country
									attitude = belligerent
								}
								has_attitude = {
									who = scope:target_country
									attitude = rebellious
								}
							}
						}
						value = -1000
					}
				}

				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_INCOMPATIBLE_ECONOMIC_SYSTEMS"
					if = {
						limit = {
							OR = {
								AND = {
									scope:target_country = { has_radical_leftist_economy = no }
									scope:target_country = { has_radical_leftist_economy = yes }
								}
								AND = {
									scope:target_country = { has_radical_leftist_economy = yes }
									scope:target_country = { has_radical_leftist_economy = no }
								}
							}
						}
						value = -50
					}
				}
				
				if = {
					limit = {
						c:JAP ?= scope:source_country
						scope:source_country ?= {
							has_journal_entry = je_meiji_imperial_marriage
						}
					}
					add = {
						# KAI: Added -10000 to withdraw from treaty during their binding period
						# Added -1000 to cancel out Dejima Trade's +1000 score from being a historical treaty
						desc = "je_meiji_imperial_marriage"
						value = -11500
					}
				}
			}
			else = {
				scope:source_country = {
					save_temporary_scope_as = actor
				}
				scope:target_country = {
					save_temporary_scope_as = target
				}

				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_BASE_ADDITIONAL"
					value = -5
				}

				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_GDP"
					value = "scope:source_country.ai_gdp_comparison(root)"
					multiply = 4
					min = -10
					max = 10
				}

				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_MUTUAL_TRADE_VALUE"
					value = "mutual_trade_value_with_country(scope:source_country)"
					multiply = 100000
					divide = { # We modulate this value by GDP, clamped to a range to ensure it remains relevant for very small/very large economies
						value = gdp
						max = scope:source_country.gdp # We use whichever GDP is smaller
						min = 1000000
					}
					min = 1
					max = 25
				}

				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_ATTITUDE"
					if = {
						limit = {
							OR = {
								has_attitude = {
									who = scope:source_country
									attitude = antagonistic
								}
								has_attitude = {
									who = scope:source_country
									attitude = domineering
								}
								has_attitude = {
									who = scope:source_country
									attitude = belligerent
								}
								has_attitude = {
									who = scope:source_country
									attitude = rebellious
								}
							}
						}
						value = -1000
					}
				}

				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_INCOMPATIBLE_ECONOMIC_SYSTEMS"
					if = {
						limit = {
							OR = {
								AND = {
									scope:source_country = { has_radical_leftist_economy = no }
									scope:target_country = { has_radical_leftist_economy = yes }
								}
								AND = {
									scope:source_country = { has_radical_leftist_economy = yes }
									scope:target_country = { has_radical_leftist_economy = no }
								}
							}
						}
						value = -50
					}
				}

				add = {
					desc = "je_hawaiian_interest"
					if = {
						limit = {
							has_journal_entry = je_hawaiian_interest
							c:HAW ?= {
								this = scope:source_country
							}
						}
						value = 20
					}
				}
			}
		}

		contextual_accept_score = {
			value = 0

			if = {
				limit = {
					scope:treaty ?= {
						NOT = {
							any_scope_article_option = {
								NOT = { has_type = trade_privilege }
								NOT = { is_desired_by = root }
							}
						}
						any_scope_article_option = {
							has_type = trade_privilege
						}
					}
				}
				if = {
					limit = {
						scope:target_country = {
							has_variable = pro_lobby_proposal_trade_privilege
							var:pro_lobby_opportunity_target ?= scope:source_country
						}
					}
					add = {
						desc = "LOBBY_OPPORTUNITY_BONUS"
						value = 50
					}
				}

				if = {
					limit = {
						scope:target_country = {
							has_variable = anti_lobby_proposal_trade_privilege
							var:anti_lobby_opportunity_target ?= scope:source_country
						}
					}
					add = {
						desc = "LOBBY_OPPORTUNITY_BONUS"
						value = 25
					}
				}
			}
			else = {
				if = {
					limit = {
						scope:target_country = {
							has_variable = pro_lobby_proposal_trade_privilege
							var:pro_lobby_opportunity_target ?= scope:source_country
						}
					}
					add = {
						desc = "LOBBY_OPPORTUNITY_BONUS"
						value = 10
					}
				}

				if = {
					limit = {
						scope:target_country = {
							has_variable = anti_lobby_proposal_trade_privilege
							var:anti_lobby_opportunity_target ?= scope:source_country
						}
					}
					add = {
						desc = "LOBBY_OPPORTUNITY_BONUS"
						value = 5
					}
				}
			}
		}
	}
}
