﻿activity_cagm_grand_apiary = {
	header_background = "gfx/interface/illustrations/activity_header_backgrounds/activity_cagm_grand_apiary.dds"

	activity_group_type = activities
	sort_order = 301

	is_shown = { OR = { is_landed = yes is_landless_adventurer = yes } }
	can_start_showing_failures_only = {
		NOT = { is_activity_type_on_cooldown = activity_cagm_grand_apiary }
		is_available_adult = yes
		is_imprisoned = no
		NOT = { is_incapable = yes }
	}
	is_valid = {
		scope:host = {
			is_alive = yes is_adult = yes is_imprisoned = no
			NOT = { is_incapable = yes }
			OR = { is_landed = yes is_landless_adventurer = yes }
		}
	}
	on_invalidated = {
		invalidation_imprisoned_effect = yes
		invalidation_incapable_effect = yes
		invalidation_unlanded_effect = yes
	}
	on_host_death = { invalidation_host_death_effect = yes }

	is_single_location = yes
	province_filter = domicile_realm
	ai_province_filter = domicile_domain
	max_route_deviation_mult = 1.5
	max_province_icons = 8
	allow_zero_guest_invites = yes
	open_invite = no
	is_location_valid = { has_holding = yes }
	province_description = { desc = activity_cagm_grand_apiary_province_desc }
	province_score = {
		value = 10
		if = { limit = { county.holder = scope:host } add = 20 }
		if = { limit = { OR = { terrain = farmlands terrain = plains terrain = forest terrain = taiga terrain = floodplains terrain = oasis terrain = jungle } } add = 10 }
		if = { limit = { has_building_or_higher = orchards_01 } add = 12 }
		if = { limit = { has_building_or_higher = pastures_01 } add = 8 }
		if = { limit = { has_building_or_higher = logging_camps_01 } add = 8 }
	}

	conclusion_description = {
		first_valid = {
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_exceptional has_variable = cagm_apiary_story_method_gentle } } desc = cagm_apiary_conclusion_exceptional_gentle }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_exceptional has_variable = cagm_apiary_story_method_keeper } } desc = cagm_apiary_conclusion_exceptional_keeper }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_exceptional has_variable = cagm_apiary_story_method_force } } desc = cagm_apiary_conclusion_exceptional_force }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_success has_variable = cagm_apiary_story_method_gentle } } desc = cagm_apiary_conclusion_success_gentle }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_success has_variable = cagm_apiary_story_method_keeper } } desc = cagm_apiary_conclusion_success_keeper }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_success has_variable = cagm_apiary_story_method_force } } desc = cagm_apiary_conclusion_success_force }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_failure has_variable = cagm_apiary_story_method_gentle } } desc = cagm_apiary_conclusion_failure_gentle }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_failure has_variable = cagm_apiary_story_method_keeper } } desc = cagm_apiary_conclusion_failure_keeper }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_failure has_variable = cagm_apiary_story_method_force } } desc = cagm_apiary_conclusion_failure_force }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_exceptional } } desc = cagm_apiary_conclusion_exceptional }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_success } } desc = cagm_apiary_conclusion_success }
			triggered_desc = { trigger = { scope:activity = { has_variable = cagm_apiary_result_failure } } desc = cagm_apiary_conclusion_failure }
			desc = activity_cagm_grand_apiary_conclusion_desc
		}
	}

	cost = { gold = { value = cagm_standard_activity_gold_cost desc = cagm_standard_activity_base_cost } }
	ui_predicted_cost = { gold = { value = cagm_standard_activity_gold_cost } }
	cooldown = { years = 2 }
	options = {
		cagm_apiary_purpose = {
			cagm_apiary_establish = { default = yes ai_will_do = { value = 30 } }
			cagm_apiary_harvest = {
				is_valid = { NOT = { faith.religion = religion:jainism_religion } }
				ai_will_do = { value = 25 if = { limit = { has_trait = greedy } add = 20 } }
			}
			cagm_apiary_wax = {
				is_valid = { NOT = { faith.religion = religion:jainism_religion } }
				ai_will_do = { value = 20 if = { limit = { learning >= 12 } add = 20 } }
			}
			cagm_apiary_seek_great_swarm = {
				is_valid = {
					custom_tooltip = {
						text = cagm_apiary_great_swarm_rumor_required_tt
						has_character_flag = cagm_apiary_great_swarm_rumor
					}
				}
				ai_will_do = { value = 15 if = { limit = { has_trait = ambitious } add = 25 } }
			}
			cagm_apiary_shelter = {
				is_valid = {
					custom_tooltip = {
						text = cagm_apiary_shelter_available_tt
						OR = {
							faith.religion = religion:jainism_religion
							has_trait = compassionate
						}
					}
				}
				ai_will_do = {
					value = 10
					if = { limit = { faith.religion = religion:jainism_religion } add = 90 }
					if = { limit = { has_trait = compassionate } add = 40 }
				}
			}
		}
		cagm_apiary_preparations = {
			cagm_apiary_preparations_local = { default = yes ai_will_do = { value = 50 } }
			cagm_apiary_preparations_sound = {
				is_valid = { can_make_expensive_purchase_trigger = { PRICE = root.cagm_modest_option_gold_cost } }
				cost = { gold = { value = cagm_modest_option_gold_cost desc = cagm_apiary_preparations_sound } }
				ai_will_do = { value = 35 }
			}
			cagm_apiary_preparations_grand = {
				is_valid = { can_make_expensive_purchase_trigger = { PRICE = root.cagm_grand_option_gold_cost } }
				cost = { gold = { value = cagm_grand_option_gold_cost desc = cagm_apiary_preparations_grand } }
				ai_will_do = { value = 15 }
			}
		}
		cagm_apiary_role = {
			cagm_apiary_role_patron = { default = yes ai_will_do = { value = 70 } }
			cagm_apiary_role_work = { ai_will_do = { value = 30 if = { limit = { has_trait = brave } add = 25 } if = { limit = { has_trait = craven } multiply = 0 } } }
		}
	}

	special_option_category = cagm_apiary_purpose
	on_start = {
		set_variable = { name = cagm_apiary_event_adjustment value = 0 }
		set_variable = { name = cagm_apiary_success value = cagm_apiary_success_value }
	}
	phases = {
		cagm_apiary_phase = {
			order = 1 is_predefined = yes location_source = pickable
			on_phase_active = {
				if = {
					limit = { this = scope:host }
					scope:activity = {
						save_scope_as = activity
						activity_location = { save_scope_as = location }
						set_variable = { name = cagm_apiary_success value = cagm_apiary_success_value }
						progress_activity_phase_after = { days = 35 }
					}
					save_scope_as = root_scope
					trigger_event = cagm_apiary.0001
					trigger_event = { id = cagm_apiary.0010 days = 7 }
					trigger_event = { id = cagm_apiary.0020 days = 14 }
					trigger_event = { id = cagm_apiary.0050 days = 17 }
					trigger_event = { id = cagm_apiary.0030 days = 21 }
					trigger_event = { id = cagm_apiary.0099 days = 29 }
				}
			}
		}
	}

	map_entity = "building_western_hunt_01_entity"
	background = {
		texture = "gfx/interface/illustrations/event_scenes/ep2_hunt_generic.dds"
		environment = "environment_generic_hunt"
		ambience = "event:/SFX/Events/Backgrounds/fields_farms_day"
	}
	activity_window_widgets = { cagm_apiary_success_widget = "activity_plugin_widgets_summary" }
	max_guest_arrival_delay_time = { months = 1 }
	max_guests = 8
	can_be_activity_guest = {
		is_adult = yes is_alive = yes is_imprisoned = no
		in_diplomatic_range = scope:host
		NOT = { is_at_war_with = scope:host }
	}
	guest_invite_rules = {
		rules = { 1 = activity_invite_rule_vassals }
		defaults = { 1 = activity_invite_rule_courtiers 2 = activity_invite_rule_friends }
	}
	host_intents = { intents = { reduce_stress_intent befriend_attendee_intent } default = reduce_stress_intent }
	guest_intents = { intents = { reduce_stress_intent befriend_attendee_intent } default = reduce_stress_intent }
	guest_join_chance = { base = 60 base_activity_modifier = yes activity_guest_shared_ai_accept_modifier = yes }
	ai_check_interval = 70
	ai_will_do = {
		value = 9
		if = { limit = { stewardship >= 12 } add = 8 }
		if = { limit = { OR = { has_trait = lifestyle_gardener has_trait = lifestyle_herbalist has_trait = cagm_apiarist } } add = 8 }
		if = { limit = { short_term_gold < cagm_standard_activity_gold_cost } multiply = 0 }
	}
	window_characters = {
		host = { camera = camera_body effect = { scope:host = { add_to_list = characters } } scripted_animation = { animation = personality_rational } }
		guest = { camera = camera_body_right effect = { every_attending_character = { limit = { this != scope:host } add_to_list = characters } } scripted_animation = { animation = admiration } }
	}
}
