
#scripted_diplomatic_actions = {
#
#	action_key = { # will be used in most localizations
#	
#		# root is the initiator of action and this is the target country
#		allowed = { #if action is valid
#			always = yes
#		}
#		visible = { #if action is visible on gui
#			always = yes
#		}
#		selectable = { #if action is selectable on gui
#			always = yes
#		}
#
#		requires_acceptance = yes # if true the action will require acceptance of target country
#		cost = 10 # pp cost, can be zero
#		command_power = 10 # cp cost, can be zero
#
#		cost_string = loc_key # if you have a custom cost, use this loc to display it
#		show_acceptance_on_action_button = yes # set to no if acceptance shouldn't be displayed on the action button
#
#		icon = 1 # icon frame to use in notification
#
#       #for effects/triggers/variables, root is the sender and this is receiver
#
#		# runs when the action is sent
#		on_sent_effect = {
#		}
#
#		# runs when the action is properly sent and accepted
#		complete_effect = {
#		}
#
#		# runs when the action is properly sent and rejected
#		reject_effect = {
#		}
#
#		# SEND POPUP CUSTOMIZATION
#		# use diplomatic_action as context in scripted gui
#		# send_scripted_gui = send_scripted_gui_name # if specified, the diplomatic action will use this scripted gui before sending the request. the player (or ai) can make changes on that gui and store stuff as variable to customize action
#		reset_send_effect = { # if action has a send scripted gui, this effect will be used for clearing the state of gui (will run when player opens the scripted gui by sending the action or when ai proposes action
#			# clear action
#			if = {
#				limit = { 
#					root = {
#						is_ai = yes
#					}
#				}
#				# initialize for ai
#			}
#		}
#		can_be_sent = { # send button will be disabled if no
#			always = yes
#		}
#		send_description = loc_key_send # if there is no scripted gui, this desc will be used in send yes/no pop up
#
#
#		# RECEIVE POPUP CUSTOMIZATION
#		# use diplomatic_action as context in scripted gui
#		# receive_scripted_gui = receive_scripted_gui_name #if specified the receiver of the action will get this scripted gui instead of yes-no popup when they receive the propose
#		reset_receive_effect = {
#			# clear action
#			if = {
#				limit = { 
#					is_ai = yes
#				}
#				# change stuff for ai
#			}
#		}
#		can_be_accepted = { # accept button will be disabled if no
#			always = yes
#		}
#		receive_description = loc_key_receive # if there is no scripted gui, this desc will be used in send yes/no pop up
#
#		
#		# PLAYER FEEDBACK ON ACCEPT/REJECT
#		accept_title = loc_key_accept #can be overridden to customize accepted/rejected pop ups for the sender
#		accept_description = loc_key_accept_desc
#		reject_title = loc_key_reject
#		reject_description = loc_key_reject_desc
#	
#		
#		# AI
#		# a list of ai_will_do entries that will be used to decide if AI should accept or reject a request
#		ai_acceptance = {
#			condition = { # name is used for loc
#				base = 100
#			}
#		}
#
#		# ai_will_do to decide if AI should send this action or not
#		ai_desire = {
#			base = -1
#			modifier = {
#				ROOT = {
#					tag = ENG
#				}
#				tag = GER
#				add = 1000
#			}
#		}
#	}
#}

scripted_diplomatic_actions = {

	offer_peace_deal = {
	
		# root is the initiator of action and this is the target country
		allowed = {
			always = yes
		}
		visible = {
			has_war_with = ROOT
		}
		selectable = { 
			ROOT = { 
				NOT = { civilwar_target = PREV }
			}
            
			OR = {
				AND = {
					is_in_faction = yes
					is_major = yes
				}
				is_in_faction = no
			}
			is_puppet = no
		}

		requires_acceptance = yes
		show_acceptance_on_action_button = yes # set to no if acceptance shouldn't be displayed on the action button
		cost = 0

		icon = 1

		on_sent_effect = {
			ROOT = { set_country_flag = pd_waiting_response }
		}

		complete_effect = {
			clear_vp = yes
			execute_peace_deal = yes
			ROOT = { 
				clr_country_flag = pd_waiting_response
				clr_country_flag = pd_ai_want_peace
				clear_variable = pd_ai_want_peace_with 
			}
		}
		
		reject_effect = {
			ROOT = { 
				clr_country_flag = pd_waiting_response
				clr_country_flag = pd_ai_want_peace
				clear_variable = pd_ai_want_peace_with 
			}
		}
		
		send_scripted_gui = pd_offer_peace_deal
		reset_send_effect = {
			ROOT = { clr_country_flag = pd_root_gives }
			reset_peace_deal_proposal = yes
		}
		
		can_be_sent = { # send button will be disabled if no
			OR = {
				check_variable = { ROOT.vp@PREV > ROOT.pd_total_cost }
				check_variable = { ROOT.vp@PREV = ROOT.pd_total_cost }
			}
			ROOT = {
				NOT = { 
					has_country_flag = pd_waiting_response 
					
					# Can't give away all states!
					all_of = {
						array = ROOT.owned_states

						OR = {
							is_in_array = {
								array = pd_take_array
								value = v
							}
							is_in_array = {
								array = pd_puppet_array
								value = v
							}
							is_in_array = {
								array = pd_liberate_array
								value = v
							}
						}
					}
				}
			}
		}
		
		receive_scripted_gui = pd_offer_peace_deal_receive

		ai_desire = {
			base = -100
			modifier = {
				add = 200
				ROOT = { has_country_flag = pd_ai_want_peace }
				check_variable = { ROOT.pd_ai_want_peace_with = THIS }
			}
		}
		
		ai_acceptance = {
			pd_base_reluctance = {
				base = -100
			}
			
			pd_close_to_surrender = {
				base = 0
				modifier = {
					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 = var:sp
				}
			}
			
			pd_war_support = {
				base = 0
				modifier = {
					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 = var:ws
				}
			}
			
			pd_stability = {
				base = 0
				modifier = {
					set_temp_variable = { s = var:THIS.has_stability }
					multiply_temp_variable = { s = -200 }
					round_temp_variable = s
					add_to_temp_variable = { s = 100 }
					add = var:s
				}
			}
			
			pd_relative_war_score = {
				base = 0
				modifier = {
					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 = var:rvp
				}
			}
			
			pd_strength_ratio = {
				base = 0
				modifier = {
					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 = var:str
				}
			}
			
			pd_proposal_cost = {
				base = 0
				modifier = {
					set_temp_variable = { tc = ROOT.pd_total_cost }
					multiply_temp_variable = { tc = -1 }
					add = tc
				}
			}
			
			pd_geopolitical_situation = {
				base = 0
				modifier = {
					add = -100
					is_major = yes
				}
				modifier = {
					add = -200
					is_in_faction = yes
				}
				modifier = {
					# 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 = var:wt
				}
			}
		}
	}
}
