#Decisions for East Asia
### Visit a Silk Road Market ###
visit_silk_road_market_decision = {
	picture = {
		reference = "gfx/interface/illustrations/decisions/tgp_silk_road.dds"
	}
	desc = visit_silk_road_market_decision_desc
	selection_tooltip = visit_silk_road_market_decision_tooltip

	cooldown = { years = 10 }

	ai_check_interval_by_tier = {
		barony = 0
		county = 0
		duchy = 240
		kingdom = 36
		empire = 36
		hegemony = 36
	}

	is_shown = {
		OR = {
			is_ai = no
			any_character_situation = { situation_type = silk_road_situation }
		}
		has_tgp_dlc_trigger = yes
		is_playable_character = yes

		#There is no point in showing this decision if you cannot benefit from going at all:
		OR = {
			silk_road_valid_market_to_visit_trigger = { SUB_REGION = china }
			silk_road_valid_market_to_visit_trigger = { SUB_REGION = tibet }
			silk_road_valid_market_to_visit_trigger = { SUB_REGION = india }
			silk_road_valid_market_to_visit_trigger = { SUB_REGION = central_asia }
			silk_road_valid_market_to_visit_trigger = { SUB_REGION = transcaspia }
			silk_road_valid_market_to_visit_trigger = { SUB_REGION = occident }
		}
	}

	is_valid = {
		is_adult = yes
		gold >= major_gold_value
	}	

	is_valid_showing_failures_only = {
		is_available_adult = yes
		is_playable_character = yes
		is_incapable = no
	}

	widget = {
		gui = "decision_view_widget_option_list_generic"
		controller = decision_option_list_controller
		decision_to_second_step_button = "THE_SILK_ROAD_AWAITS"
		show_from_start = yes

		# there are six potential silk road markets
		item = { # Chang'an
			value = c_jingzhao
			is_shown = { always = yes }
			is_valid = {
				custom_tooltip = {
					text = no_building_at_silk_road_market_desc
					title:c_jingzhao = { # Chang'an
						any_county_province = { has_building_with_flag = silk_road_node }
					}
				}
				custom_tooltip = {
					text = no_available_innovation_at_silk_road_market_desc
					silk_road_valid_market_to_visit_trigger = { SUB_REGION = china }
				}
			}
			localization = visit_silk_road_market_decision_changan
			icon = "gfx/interface/icons/travel/icon_travel_silk_road_marketplace.dds"
			ai_chance = {
				value = 1
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_jingzhao.title_province
								value <= squared_distance_small
							}
						}
					}
					multiply = 10
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_jingzhao.title_province
								value <= squared_distance_large
							}
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_jingzhao.title_province
								value > squared_distance_huge
							}
						}
					}
					multiply = 0.1
				}
			}
		}
		item = { # Lhasa
			value = c_lhasa
			is_shown = { always = yes }
			is_valid = {
				custom_tooltip = {
					text = no_building_at_silk_road_market_desc
					title:c_lhasa = {
						any_county_province = { has_building_with_flag = silk_road_node }
					}
	            }
				custom_tooltip = {
					text = no_available_innovation_at_silk_road_market_desc
					silk_road_valid_market_to_visit_trigger = { SUB_REGION = tibet }
	            }
			}
			localization = visit_silk_road_market_decision_lhasa
			icon = "gfx/interface/icons/travel/icon_travel_silk_road_marketplace.dds"
			ai_chance = {
				value = 1
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_lhasa.title_province
								value <= squared_distance_small
							}
						}
					}
					multiply = 10
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_lhasa.title_province
								value <= squared_distance_large
							}
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_lhasa.title_province
								value > squared_distance_huge
							}
						}
					}
					multiply = 0.1
				}
			}
		}
		item = { # Lahur
			value = c_lahur
			is_shown = { always = yes }
			is_valid = {
				custom_tooltip = {
					text = no_building_at_silk_road_market_desc
					title:c_lahur = {
						any_county_province = { has_building_with_flag = silk_road_node }
					}
	            }
				custom_tooltip = {
					text = no_available_innovation_at_silk_road_market_desc
					silk_road_valid_market_to_visit_trigger = { SUB_REGION = india }
	            }
			}
			localization = visit_silk_road_market_decision_lahur
			icon = "gfx/interface/icons/travel/icon_travel_silk_road_marketplace.dds"
			ai_chance = {
				value = 1
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_lahur.title_province
								value <= squared_distance_small
							}
						}
					}
					multiply = 10
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_lahur.title_province
								value <= squared_distance_large
							}
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_lahur.title_province
								value > squared_distance_huge
							}
						}
					}
					multiply = 0.1
				}
			}
		}
		item = { # Dunhuang
			value = c_shazhou
			is_shown = { always = yes }
			is_valid = {
				custom_tooltip = {
					text = no_building_at_silk_road_market_desc
					title:c_shazhou = { # Dunhuang
						any_county_province = { has_building_with_flag = silk_road_node }
					}
	            }
				custom_tooltip = {
					text = no_available_innovation_at_silk_road_market_desc
					silk_road_valid_market_to_visit_trigger = { SUB_REGION = central_asia }
	            }
			}
			localization = visit_silk_road_market_decision_dunhuang
			icon = "gfx/interface/icons/travel/icon_travel_silk_road_marketplace.dds"
			ai_chance = {
				value = 1
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_shazhou.title_province # Dunhuang
								value <= squared_distance_small
							}
						}
					}
					multiply = 10
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_shazhou.title_province # Dunhuang
								value <= squared_distance_large
							}
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_shazhou.title_province # Dunhuang
								value > squared_distance_huge
							}
						}
					}
					multiply = 0.1
				}
			}
		}
		item = { # Khiva
			value = c_khiva
			is_shown = { always = yes }
			is_valid = {
				custom_tooltip = {
					text = no_building_at_silk_road_market_desc
					title:c_khiva = {
						any_county_province = { has_building_with_flag = silk_road_node }
					}
	            }
				custom_tooltip = {
					text = no_available_innovation_at_silk_road_market_desc
					silk_road_valid_market_to_visit_trigger = { SUB_REGION = transcaspia }
	            }
			}
			localization = visit_silk_road_market_decision_khiva
			icon = "gfx/interface/icons/travel/icon_travel_silk_road_marketplace.dds"
			ai_chance = {
				value = 1
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_khiva.title_province
								value <= squared_distance_small
							}
						}
					}
					multiply = 10
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_khiva.title_province
								value <= squared_distance_large
							}
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_khiva.title_province
								value > squared_distance_huge
							}
						}
					}
					multiply = 0.1
				}
			}
		}
		item = { # Dvin
			value = c_dvin
			is_shown = { always = yes }
			is_valid = {
				custom_tooltip = {
					text = no_building_at_silk_road_market_desc
					title:c_dvin = {
						any_county_province = { has_building_with_flag = silk_road_node }
					}
	            }
				custom_tooltip = {
					text = no_available_innovation_at_silk_road_market_desc
					silk_road_valid_market_to_visit_trigger = { SUB_REGION = occident }
	            }
			}
			localization = visit_silk_road_market_decision_dvin
			icon = "gfx/interface/icons/travel/icon_travel_silk_road_marketplace.dds"
			ai_chance = {
				value = 1
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_dvin.title_province
								value <= squared_distance_small
							}
						}
					}
					multiply = 10
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_dvin.title_province
								value <= squared_distance_large
							}
						}
					}
					multiply = 2
				}
				if = {
					limit = {
						root.location = {
							squared_distance = {
								target = title:c_dvin.title_province
								value > squared_distance_huge
							}
						}
					}
					multiply = 0.1
				}
			}
		}
	}

	effect = {
		remove_short_term_gold = major_gold_value
		switch = {
			trigger = yes
			scope:c_dvin = { # Dvin
				title:c_dvin = { tgp_silk_road_decision_scope_effect = yes }
			}
			scope:c_jingzhao = { # Chang'an
				title:c_jingzhao = { tgp_silk_road_decision_scope_effect = yes }
			}
			scope:c_lahur = { # Lahur
				title:c_lahur = { tgp_silk_road_decision_scope_effect = yes }
			}
			scope:c_shazhou = { # Dunhuang
				title:c_shazhou = { tgp_silk_road_decision_scope_effect = yes }
			}
			scope:c_lhasa = { # Lhasa
				title:c_lhasa = { tgp_silk_road_decision_scope_effect = yes }
			}
			scope:c_khiva = { # Khiva
				title:c_khiva = { tgp_silk_road_decision_scope_effect = yes }
			}
		}
		if = {
			limit = { exists = scope:destination_province }
			# EVENTS
			if = {
				limit = { scope:destination_province = root.location }
				trigger_event = { id = tgp_silk_road_events.0010 }
			}
			else = {
				custom_tooltip = travel_silk_road_market_desc
				start_travel_plan = {
					destination = scope:destination_province
					on_arrival_event = tgp_silk_road_events.0010
					travel_with_domicile = no
					return_trip = yes
					on_travel_planner_cancel_on_action = silk_road_market_visit_travel_planner_cancel_on_action # here comes the refund!
					players_use_planner = yes
					#on_arrival_destinations = last
				}
			}
			if = {
				limit = { exists = scope:innovation_temp }
				custom_tooltip = potential_innovation_at_silk_road_market_desc
			}
			custom_tooltip = travel_silk_road_market_innovation_warning_tt
			if = {
				limit = {
					root.location = {
						squared_distance = {
							target = scope:destination_province
							value >= squared_distance_huge
						}
					}
				}
				custom_tooltip = travel_silk_road_market_long_tt
			}
		}
	}
	
	ai_potential = {
		is_at_war = no
		short_term_gold >= major_gold_value
		ai_greed > low_positive_ai_value
		ai_should_focus_on_building_in_their_capital = yes
	}

	ai_will_do = {
		base = 20

		modifier = {
			add = 10
			root.culture.culture_head = root
		}
		modifier = {
			factor = 0.1

			any_character_situation = {
				situation:silk_road_situation = this
				any_participant_group = {
					participant_group_type = silk_road_nomad
					participant_group_has_character = ROOT
				}
			}
		}
		modifier = {
			factor = 0.2
			any_character_situation = {
				situation:silk_road_situation = this
				any_participant_group = {
					participant_group_type = silk_road_periphery
					participant_group_has_character = ROOT
				}
			}
		}
		modifier = {
			factor = 0.5
			any_character_situation = {
				situation:silk_road_situation = this
				any_participant_group = {
					participant_group_type = silk_road_realm
					participant_group_has_character = ROOT
				}
			}
		}

		modifier = {
			factor = 0

			NOR = {
				silk_road_valid_market_to_visit_trigger = { SUB_REGION = china }
				silk_road_valid_market_to_visit_trigger = { SUB_REGION = tibet }
				silk_road_valid_market_to_visit_trigger = { SUB_REGION = india }
				silk_road_valid_market_to_visit_trigger = { SUB_REGION = central_asia }
				silk_road_valid_market_to_visit_trigger = { SUB_REGION = transcaspia }
				silk_road_valid_market_to_visit_trigger = { SUB_REGION = occident }
			}
		}
	}
}
