#	Example:
# 
#	example_trigger = {
#		tag = GER
#		is_ai = no
#	}
#
#
#	In a script file:
#
#	trigger = {
#		exampel_trigger = yes
#	}
#

pd_ai_will_offer_peace = {
	# root is the sender and this is receiver
	
	# TODO
	always = no
}

pd_ai_will_accept = {
	# base
	set_temp_variable = { will_accept = -100 }
			
	# close to surrender 
	set_temp_variable = { sp = var:THIS.surrender_progress }
	multiply_temp_variable = { sp = 200 }
	round_temp_variable = sp
	subtract_from_temp_variable = { sp = 100 }
	clamp_temp_variable = {
		var = sp
		min = 0
		max = 100
	}
	add_to_temp_variable = { will_accept = sp }
	
	# war support
	set_temp_variable = { ws = var:THIS.has_war_support }
	multiply_temp_variable = { ws = -200 }
	round_temp_variable = ws
	add_to_temp_variable = { ws = 100 }
	add_to_temp_variable = { will_accept = ws }
	
	# stability 
	set_temp_variable = { s = var:THIS.has_stability }
	multiply_temp_variable = { s = -200 }
	round_temp_variable = s
	add_to_temp_variable = { s = 100 }
	add_to_temp_variable = { will_accept = s }
			
	# relative war score 
	set_temp_variable = { rvp = ROOT.vp@PREV }
	set_temp_variable = { tvp = THIS.vp@ROOT }
	subtract_from_temp_variable = { rvp = tvp }
	round_temp_variable = rvp
	add_to_temp_variable = { will_accept = rvp }
			
	# strength ratio
	set_temp_variable = { str = THIS.enemies_strength_ratio@ROOT }
	multiply_temp_variable = { str = 100 }
	round_temp_variable = str
	subtract_from_temp_variable = { str = 100 }
	clamp_temp_variable = {
		var = str
		max = 1000
	}
	add_to_temp_variable = { will_accept = str }
	
	# world tension (while threat < 0.2 -> 0, later -100 for each 0.1)
	set_temp_variable = { wt = global.threat }
	multiply_temp_variable = { wt = -1000 }
	round_temp_variable = wt
	add_to_temp_variable = { wt = 200 }
	clamp_temp_variable = {
		var = wt
		max = 0
	}
	add_to_temp_variable = { will_accept = wt }
	
	# peace deal cost
	subtract_from_temp_variable = { will_accept = ROOT.pd_total_cost }
	
	# wants to much!
	if = {
		limit = {
			check_variable = { ROOT.vp@PREV < ROOT.pd_total_cost }
		}
		subtract_from_temp_variable = { will_accept = 10000 }
	}
	
	# is major
	if = {
		limit = {
			is_major = yes
		}
		subtract_from_temp_variable = { will_accept = 200 }
	}
	
	# is in faction
	if = {
		limit = {
			is_in_faction = yes
		}
		subtract_from_temp_variable = { will_accept = 100 }
	}
	
	# Final check
	check_variable = { will_accept > 0 }
}