﻿mod_fixed_law = {
	groups= {
		overlord
	}
	requires_approval = no
	should_notify_third_parties = no
	
	selectable = {
		NOT = { is_country_type = decentralized }
		is_revolutionary = no
		is_ai = no
	}
	
	potential = {
		scope:target_country = {
			is_subject_of = root
		}
	}
	
	possible = {		
	}
	
	pact = {	
		cost = 25
		recipient_pays_maintenance = no
		
		second_modifier = {
			country_cannot_start_law_enactment_bool = yes
		}
		
		requirement_to_maintain = {
			trigger = {
				has_diplomatic_relevance = scope:target_country
			}
		}

	 	requirement_to_maintain = {
			trigger = {
				custom_tooltip = {
					text = "DIPLOMATIC_PACT_REQUIREMENT_AT_PEACE"
					NOT = { has_war_with = scope:target_country }
				}			
			}
		}			
	}
	
	ai = {
		max_influence_spending_fraction = 0.20
		
		evaluation_chance = {
			value = 0.0
			
			if = {
				limit = { country_rank >= rank_value:major_power }
				add = {
					value = country_rank
					multiply = 0.05
				}				
			}			
		}		
		
		# This is only used for determining the value of a bankroll in sways, so it follows different logic from normal action acceptance
		# The format here is as if scope:actor was asking if root wants a bankroll
		accept_score = {
			value = 0

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_BASE"
				value = 5
			}
			
			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_RANK"
	
				if = {
					limit = { scope:actor = { country_rank < root.country_rank } }
					value = -5
				}
				
				if = {
					limit = { scope:actor = { country_rank > root.country_rank } }
					value = 5
				}				
			}		
			
			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_GDP"
				value = "scope:actor.ai_gdp_comparison(root)"
				max = 20
				min = -20
			}
			
			if = {
				limit = { scaled_debt >= 0.05 }
				
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_DEBT"
					value = scaled_debt
					multiply = 30	
					min = 1
				}					
			}
			else_if = {
				limit = { scaled_gold_reserves >= 0.05 }
				
				subtract = {
					desc = "DIPLOMATIC_ACCEPTANCE_GOLD_RESERVES"				
					value = scaled_gold_reserves
					multiply = 20
					min = 1
				}						
			}
		}		
	
		# This is only used for determining the value of a bankroll in sways, so it follows different logic from normal action acceptance
		# The format here is as if scope:actor was asking for a bankroll from root
		junior_accept_score = {
			value = 0

			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_BASE"
				value = -10
			}			
			
			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_RANK"
	
				if = {
					limit = { scope:actor = { country_rank > root.country_rank } }
					value = -5
				}
				
				if = {
					limit = { scope:actor = { country_rank < root.country_rank } }
					value = 5
				}				
			}				

			subtract = {
				value = 10
				multiply = scope:actor.num_income_transfer_pacts
			}

			subtract = {
				value = 10
				multiply = num_income_transfer_pacts
			}				
			
			add = {
				desc = "DIPLOMATIC_ACCEPTANCE_GDP"
				value = "scope:actor.ai_gdp_comparison(root)"
				add = 2
				multiply = -10
				min = -100
				max = 0
			}
			
			if = {
				limit = { scaled_debt >= 0.05 }
				
				subtract = {
					desc = "DIPLOMATIC_ACCEPTANCE_DEBT"
					value = scaled_debt
					multiply = 100	
					min = 1
				}					
			}
			else_if = {
				limit = { scaled_gold_reserves >= 0.05 }
				
				add = {
					desc = "DIPLOMATIC_ACCEPTANCE_GOLD_RESERVES"				
					value = scaled_gold_reserves
					multiply = 25
					min = 1
				}						
			}
		}	
	
		propose_score = {
			value = 10

			if = {
				limit = {
					exists = c:CIR
					has_journal_entry = je_great_game_control
					country_has_primary_culture = cu:british
					scope:target_country = {
						c:CIR ?= this
					}
				}
				add = {
					value = 50
				}		
			}
		}
	
		will_propose = { 
			scaled_debt <= 0
			is_at_war = no
			weekly_net_fixed_income > 0	
			has_attitude = {
				who = scope:target_country
				attitude = protective
			}
			OR = {
				num_income_transfer_pacts < 1
				AND = {
					num_income_transfer_pacts < 2
					income >= 200000
				}
				AND = {
					num_income_transfer_pacts < 3
					income >= 400000
				}				
			}
			
			OR = {
				root = {
					owes_obligation_to = scope:target_country			
				}	
				NOT = { 
					scope:target_country = {
						owes_obligation_to = root			
					}						
				}
				AND = {
					is_at_war = no
					scope:target_country = { is_at_war = yes }
				}			
			}		
			# We want to have at least five times their income, and at least 50k income in general
			OR = {
				AND = {
					income >= 50000
					weekly_net_fixed_income >= 4000
					scope:target_country.income <= 10000
				}
				AND = {
					income >= 75000
					weekly_net_fixed_income >= 6000
					scope:target_country.income <= 15000
				}				
				AND = {
					income >= 100000
					weekly_net_fixed_income >= 8000
					scope:target_country.income <= 20000
				}
				AND = {
					income >= 125000
					weekly_net_fixed_income >= 10000
					scope:target_country.income <= 25000
				}
				AND = {
					income >= 150000
					weekly_net_fixed_income >= 12000
					scope:target_country.income <= 30000
				}	
				AND = {
					income >= 175000
					weekly_net_fixed_income >= 14000
					scope:target_country.income <= 35000
				}
				AND = {
					income >= 200000
					weekly_net_fixed_income >= 16000
					scope:target_country.income <= 40000
				}
				AND = {
					income >= 225000
					weekly_net_fixed_income >= 18000
					scope:target_country.income <= 45000
				}	
				AND = {
					income >= 250000
					weekly_net_fixed_income >= 20000
					scope:target_country.income <= 50000
				}					
			}			
		}
		
		will_break = { 
			NOT = {
				AND = {
					has_variable = forced_bankroll_time
					var:forced_bankroll_time ?= scope:target_country
				}
			}
			OR = {		
				scaled_debt > 0.25
				AND = {
					scaled_debt > 0
					OR = {
						weekly_net_fixed_income < 0	
						is_at_war = yes
					}				
				}				
				NOT = {
					has_attitude = {
						who = scope:target_country
						attitude = protective
					}				
				}
				num_income_transfer_pacts > 3
				AND = {
					num_income_transfer_pacts > 1
					OR = {
						weekly_net_fixed_income < -10000	
						income < 300000
					}			
				}
				AND = {
					num_income_transfer_pacts > 2
					OR = {
						weekly_net_fixed_income < -5000					
						income < 500000
					}
				}				
				NOR = {
					root = {
						owes_obligation_to = scope:target_country			
					}	
					NOT = { 
						scope:target_country = {
							owes_obligation_to = root			
						}						
					}
					AND = {
						is_at_war = no
						scope:target_country = { is_at_war = yes }
					}			
				}							
				# Threshold for breaking off a bankroll is higher than for starting it
				# We also don't look at weekly_net_fixed_income here since starting a bankroll changes it
				NOR = {
					AND = {
						income >= 40000
						scope:target_country.income <= 12500
					}				
					AND = {
						income >= 50000
						scope:target_country.income <= 15000
					}
					AND = {
						income >= 75000
						scope:target_country.income <= 20000
					}				
					AND = {
						income >= 100000
						scope:target_country.income <= 25000
					}
					AND = {
						income >= 125000
						scope:target_country.income <= 30000
					}
					AND = {
						income >= 150000
						scope:target_country.income <= 35000
					}	
					AND = {
						income >= 175000
						scope:target_country.income <= 40000
					}
					AND = {
						income >= 200000
						scope:target_country.income <= 45000
					}
					AND = {
						income >= 225000
						scope:target_country.income <= 50000
					}
					AND = {
						income >= 250000
						scope:target_country.income <= 55000
					}					
				}						
			}
		}			
	}
}

