﻿@msg_completion_effect_generic = "event:/DLC/EP4/SFX/Stingers/China/tgp_mx_sting_finishing_great_project_generic"
@msg_completion_effect_military = "event:/DLC/EP4/SFX/Stingers/China/tgp_mx_sting_finishing_great_project_military"

@great_project_mandala_icon = "gfx/interface/icons/great_projects/mandala_capital.dds"
@great_project_china_icon = "gfx/interface/icons/great_projects/city_china.dds"
@great_project_great_canals_icon = "gfx/interface/icons/great_projects/grand_canals.dds"
@icon_great_project_great_wall = "gfx/interface/icons/great_projects/great_wall.dds"

@default_illustration = "gfx/interface/illustrations/great_projects/asia_great_project_default.dds"
@mandala_capital_illustration = "gfx/interface/illustrations/decisions/tgp_projects_mandala_capital.dds"
@castle_china_illustration = "gfx/interface/illustrations/holding_types/tgp_castle_china.dds"
@great_wall_illustration = "gfx/interface/illustrations/decisions/tgp_great_wall.dds"
@grand_canals_illustration = "gfx/interface/illustrations/event_scenes/tgp_chinese_city.dds"
@courtyard_asia_illustration = "gfx/interface/illustrations/event_scenes/tgp_courtyard_asia.dds"

#The Mandala Capital Great Project!
mandala_capital_01 = {
	icon = {
		reference = @great_project_mandala_icon
	}
	illustration = {
		reference = @mandala_capital_illustration
	}

	name = {
		desc = great_project_type_mandala_capital_01
	}

	is_important = yes
	is_shown = {
		government_has_flag = government_is_mandala
		capital_province = { 
			NOT = { has_building_with_flag = mandala_capital_building }
		}
		NOT = { is_planning_great_project = mandala_capital_01 }
	}

	is_valid = {
		scope:province.barony.holder = {
			government_has_flag = government_is_mandala
		}
	}

	can_start_planning = {
		capital_province = { has_great_building = no }
		government_has_flag = government_is_mandala
		NOT = { is_planning_great_project = mandala_capital_01 }
		piety_level >= medium_piety_level
		number_of_tributaries >= 1
		legitimacy_level >= 1
		is_independent_ruler = yes
		trigger_if = {
			limit = {
				is_tributary = yes
			}
			suzerain = {
				NOT = { has_government = mandala_government }
			}
		}
		custom_tooltip = {
			text = great_project_mandala_capital_pick_aspect_tt
			has_mandala_aspect_trigger = yes
		}
		#There can only be 2 active (i.e. non-Ruined) Mandala Capitals per De Jure Kingdom
		custom_tooltip = {
			text = not_already_full_on_mandala_capitals
			less_than_max_amount_of_mandala_capitals_trigger = yes
		}
	}

	cost = {
		piety = major_piety_value
	}
	owner = province_owner

	construction_time = great_project_mandala_construction_time

	contributor_cooldown = standard_contributor_cooldown_value

	on_plan_build = {
		scope:owner = {
			#Memory
			create_character_memory = {
				type = started_planning_mandala_capital_memory
				participants = { founder = scope:owner }
			}
			scope:new_memory ?= {
				set_variable = {
					name = mandala_capital_planned_location
					value = scope:province
				}
				if = {
					limit = { exists = var:mandala_capital_planned_location }
					#To prevent 'unused except in loc' errors :catto:
				}
			}
		}
	}

	on_complete = {
		scope:owner = {
			scope:province = {
				if = {
					limit = { 
						NOT = { has_holding_type = temple_citadel_holding }
					}
					set_holding_type = temple_citadel_holding
				}
				set_great_building = mandala_capital_01
				add_to_global_variable_list = { # Add to list so it can be found by the PoI
					name = mandala_poi_list
					target = this
				}
			}
			#Owner rewards
			show_as_tooltip = { mandala_owner_reward_01_effect = yes }
			#Memory
			create_character_memory = {
				type = completed_first_mandala_capital_memory
				participants = { founder = scope:founder }
			}
			scope:new_memory ?= {
				set_variable = {
					name = mandala_capital_location
					value = scope:province
				}
				if = {
					limit = { exists = var:mandala_capital_location }
					#To prevent 'unused except in loc' errors :catto:
				}
			}
		}
		#Tally the rewards
		scope:great_project ?= {
			#Rite of Worthiness
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = rite_of_worthiness }
			#Slabs of Sandstone
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = slabs_of_sandstone }
			#Laterite Blocks
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = laterite_blocks }
			#Timber
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = timber }
			#Work Force
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = work_force }
			#Woodcarvings
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = woodcarvings }
			#Sanctified Domes
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = sanctified_domes }
			#Ornate Reliefs
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = ornate_reliefs }
			#Family Shrine
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = family_shrine }
		}
		#Dole out some rewards!
		gather_contributors_in_list_effect = yes
		every_in_list = {
			list = contributors_to_reward
			if = {
				limit = { this = scope:owner }
				trigger_event = tgp_east_asia_mandala_capital_events.1000
			}
			else = {
				if = {
					limit = { 
						scope:owner = { is_ai = yes }
					}
					show_as_tooltip = { 
						mandala_contributor_opinion_reward_effect = { OVERLORD = scope:owner }
					}
				}
				trigger_event = tgp_east_asia_mandala_capital_events.1010
			}
		}
	}

	on_cancel = {
		scope:owner = {
			add_prestige = minor_prestige_loss
		}
		every_contribution = {
			limit = {
				contribution_is_funded = yes
			}
			contributor = {
				if = {
					limit = {
						this != scope:owner
						this != scope:founder
					}
					add_to_list = contributors_to_disappoint	
				}
			}
		}
		every_in_list = {
			list = contributors_to_disappoint
			add_opinion = {
				modifier = wasted_our_efforts
				target = scope:owner
				opinion = -30
			}
		}
	}

	on_start_build = { 
		scope:owner = {
			add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		}
		scope:great_project = {
			every_contribution = {
				limit = {
					contribution_is_funded = yes
				}
				contributor = {
					add_prestige = minor_prestige_value 
				}	
			}
		}
	}

	invite_interaction = request_great_project_contribution_interaction

	allowed_contributor_filter = {
		owner = yes
		tributaries = yes
		vassals = yes
	}

	project_contributions = {
		rite_of_worthiness = {

			allowed_contributor_filter = {
				owner = yes
			}

			contributor_is_valid = { 
				#Only 2 Capital Temple Complexes per De Jure Kingdom
				trigger_if = {
					limit = {
						capital_county.kingdom = {
							any_in_de_jure_hierarchy = {
								count >= mandala_capitals_per_dejure_kingdom
								tier = tier_barony
								title_province = {
									NOT = { scope:great_project.great_project_location.county = root.capital_county } #We don't count our own great project since it needs to be upgradeable.
									OR = {
										AND = {
											has_building_with_flag = mandala_capital_building
											has_ruined_great_building = no
										}
										any_great_project_in_province = {
											OR = {
												great_project_type = mandala_capital_01
												great_project_type = mandala_capital_02
												great_project_type = mandala_capital_03
												great_project_type = mandala_capital_04
												great_project_type = mandala_capital_05
											}
											OR = {
												great_project_construction_phase_is = in_progress
												great_project_construction_phase_is = completed
											}	
										}
									}
								}
							}
						}
					}
					custom_tooltip = {
						text = not_already_full_on_mandala_capitals
						always = no
					}	
				}
				trigger_else = {
					#Aspect of Creation
					trigger_if = {
						limit = {
							scope:owner.house = { has_house_aspiration_parameter = aspect_of_creation }
						}
						creation_first_tier_trigger = yes
					}
					#Aspect of Serenity
					trigger_else_if = {
						limit = {
							scope:owner.house = { has_house_aspiration_parameter = aspect_of_serenity }
						}
						serenity_first_tier_trigger = { MANDALA = scope:owner }
					}
					#Aspect of Destruction
					trigger_else_if = {
						limit = {
							scope:owner.house = { has_house_aspiration_parameter = aspect_of_destruction }
						}
						destruction_first_tier_trigger = yes
					}
					#Aspect of Trickery
					trigger_else_if = {
						limit = {
							scope:owner.house = { has_house_aspiration_parameter = aspect_of_trickery }
						}
						trickery_first_tier_trigger = yes
					}
					#No Aspect, no dice
					trigger_else = {
						custom_tooltip = {
							text = rite_of_worthiness_per_aspect
							always = no
						}
					}
				}
			}

			cost = {}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_minor_rite_reward_effect = yes }
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 3
				duchy = 3
				kingdom = 3
				empire = 3
				hegemony = 3
			}

			ai_will_do = {
				value = 1000
			}
		}

		slabs_of_sandstone = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = {
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_gold_cost
					}
					else = { 
						value = {
							add = mandala_contribution_mid_gold_cost
							divide = 2
						}
					}
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_slabs_of_sandstone_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		laterite_blocks = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = {
				gold = mandala_contribution_low_gold_cost
				piety = {
					if = {
						limit = { is_ai = yes }
						value = 0
					}
					else = { value = mandala_contribution_mid_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_laterite_blocks_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		timber = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = {
				gold = mandala_contribution_low_gold_cost
				piety = {
					if = {
						limit = { is_ai = yes }
						value = 0
					}
					else = { value = mandala_contribution_low_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_timber_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		work_force = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = {
				piety = {
					if = {
						limit = { is_ai = yes }
						value = 0
					}
					else = { value = mandala_contribution_high_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_work_force_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		woodcarvings = {
			is_required = no

			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				piety = {
					if = {
						limit = { is_ai = yes }
						value = 0
					}
					else = { value = mandala_contribution_mid_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_woodcarvings_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		sanctified_domes = {
			is_required = no

			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = {
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_gold_cost
					}
					else = { 
						value = {
							add = mandala_contribution_mid_gold_cost
							divide = 2
						}
					}
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = 0
					}
					else = { value = mandala_contribution_mid_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_sanctified_domes_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		ornate_reliefs = {
			is_required = no

			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = {
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_gold_cost
					}
					else = { value = mandala_contribution_mid_gold_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_ornate_reliefs_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		family_shrine = {
			is_required = no

			is_shown = {
				trigger_if = {
					limit = {
						NOT = { exists = scope:owner }
					}
					always = yes
				}
				trigger_else = {
					exists = scope:owner.primary_heir
					scope:owner.dynasty ?= { has_dynasty_perk = tgp_sea_legacy_3 }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = {
				custom_tooltip = {
					text = tgp_sea_legacy_3_name
					dynasty = { has_dynasty_perk = tgp_sea_legacy_3 }
				}
			}

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_gold_cost
					}
					else = { value = mandala_contribution_mid_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = 0
					}
					else = { value = mandala_contribution_mid_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_family_shrine_reward_effect = yes }
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
			}
		}
	}

	ai_target_quick_trigger = {
		adult = yes
		government_type = { mandala_government }
		rank = county
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 1
		duchy = 1
		kingdom = 1
		empire = 1
		hegemony = 1
	}
	ai_will_do = {
		value = 1000
	}

	completion_sound_effect = @msg_completion_effect_generic
}

mandala_capital_02 = {
	icon = {
		reference = @great_project_mandala_icon
	}
	illustration = {
		reference = @mandala_capital_illustration
	}

	name = {
		desc = great_project_type_mandala_capital_02
	}
	
	owner = province_owner

	is_important = yes
	is_shown = {
		government_has_flag = government_is_mandala
		capital_province = { 
			has_building_with_flag = first_tier_mandala_capital_building
			NOT = { has_building_with_flag = second_tier_mandala_capital_building }
		}
		NOT = { is_planning_great_project = mandala_capital_02 }
	}

	is_valid = {
		scope:province.barony.holder = {
			government_has_flag = government_is_mandala
		}
	}

	can_start_planning = {
		capital_province = { has_ruined_great_building = no }
		government_has_flag = government_is_mandala
		NOR = {
			is_planning_great_project = mandala_capital_02
			piety_level < high_piety_level
		}
		custom_tooltip = {
			text = mandala_capital_tier_2_amount_of_subjects
			num_mandala_subject_value >= mandala_capital_tier_2_subject_threshold_value
		}
		legitimacy_level >= 2
		is_independent_ruler = yes
		trigger_if = {
			limit = { is_tributary = yes }
			suzerain = {
				NOT = { has_government = mandala_government }
			}
		}
		#There can only be 2 active (i.e. non-Ruined) Mandala Capitals per De Jure Kingdom
		custom_tooltip = {
			text = not_already_full_on_mandala_capitals
			less_than_max_amount_of_mandala_capitals_trigger = yes
		}
	}

	cost = {
		piety = massive_piety_value
	}

	construction_time = great_project_mandala_construction_time

	contributor_cooldown = standard_contributor_cooldown_value

	on_plan_build = {
		scope:owner = {
			#Memory
			create_character_memory = {
				type = started_planning_mandala_capital_memory
				participants = { founder = scope:owner }
			}
			scope:new_memory ?= {
				set_variable = {
					name = mandala_capital_planned_location
					value = scope:province
				}
				set_variable = {
					name = second_tier_mandala_capital
					value = flag:yes
				}
				if = {
					limit = { 
						exists = var:mandala_capital_planned_location
						exists = var:second_tier_mandala_capital
					}
					#To prevent 'unused except in loc' errors :catto:
				}
			}
		}
	}

	on_complete = {
		scope:owner = {
			scope:province = {
				hidden_effect = { remove_building = mandala_capital_01 }
				set_great_building = mandala_capital_02
			}
			#Owner rewards
			show_as_tooltip = { mandala_owner_reward_01_effect = yes }
			#Memory
			create_character_memory = {
				type = upgraded_mandala_capital_memory
				participants = { founder = scope:founder }
			}
			scope:new_memory ?= {
				set_variable = {
					name = mandala_capital_location
					value = scope:province
				}
				set_variable = {
					name = second_tier_mandala_capital
					value = flag:yes
				}
				if = {
					limit = { 
						exists = var:mandala_capital_location
						exists = var:second_tier_mandala_capital
					}
					#To prevent 'unused except in loc' errors :catto:
				}
			}
		}
		#Tally the rewards
		scope:great_project ?= {
			#Rite of Worthiness
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = rite_of_worthiness }
			#Brick
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = brick }
			#Tiles
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = tiles }
			#Shallow Pools
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = shallow_pools }
			#Work Force
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = work_force }
			#Decorative Tiles
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = decorative_tiles }
			#Decorated Domes
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = decorated_domes }
			#Family Statues
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = family_statues }
		}
		#Dole out some rewards!
		gather_contributors_in_list_effect = yes
		every_in_list = {
			list = contributors_to_reward
			if = {
				limit = { this = scope:owner }
				trigger_event = tgp_east_asia_mandala_capital_events.1000
			}
			else = {
				if = {
					limit = { 
						scope:owner = { is_ai = yes }
					}
					show_as_tooltip = { 
						mandala_contributor_opinion_reward_effect = { OVERLORD = scope:owner }
					}
				}
				trigger_event = tgp_east_asia_mandala_capital_events.1010
			}
		}
	}

	on_cancel = {
		scope:owner = {
			add_prestige = minor_prestige_loss
		}
		every_contribution = {
			limit = {
				contribution_is_funded = yes
			}
			contributor = {
				if = {
					limit = {
						this != scope:owner
						this != scope:founder
					}
					add_to_list = contributors_to_disappoint	
				}
			}
		}
		every_in_list = {
			list = contributors_to_disappoint
			add_opinion = {
				modifier = wasted_our_efforts
				target = scope:owner
				opinion = -30
			}
		}
	}

	on_start_build = {
		scope:owner = {
			add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		}
		scope:great_project = {
			every_contribution = {
				limit = {
					contribution_is_funded = yes
				}
				contributor = {
					add_prestige = minor_prestige_value 
				}	
			}
		}
	}

	allowed_contributor_filter = {
		owner = yes
		tributaries = yes
		vassals = yes
	}

	project_contributions = {
		rite_of_worthiness = {
			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = { 
				#Aspect of Creation
				trigger_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_creation }
					}
					creation_second_tier_trigger = yes
				}
				#Aspect of Serenity
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_serenity }
					}
					serenity_second_tier_trigger = { MANDALA = scope:owner }
				}
				#Aspect of Destruction
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_destruction }
					}
					destruction_second_tier_trigger = yes
				}
				#Aspect of Trickery
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_trickery }
					}
					trickery_second_tier_trigger = yes
				}
				#No Aspect, no dice
				trigger_else = {
					custom_tooltip = {
						text = rite_of_worthiness_per_aspect
						always = no
					}
				}
			}

			cost = { }

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_minor_rite_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 3
				duchy = 3
				kingdom = 3
				empire = 3
				hegemony = 3
			}
			ai_will_do = {
				value = 1000
			}
		}

		brick = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_gold_cost
					}
					else = { value = mandala_contribution_mid_gold_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_brick_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		tiles = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_gold_cost
					}
					else = { value = mandala_contribution_mid_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_piety_cost
					}
					else = { value = mandala_contribution_mid_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_tiles_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		shallow_pools = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_gold_cost
					}
					else = { value = mandala_contribution_mid_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_piety_cost
					}
					else = { value = mandala_contribution_mid_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_shallow_pools_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		work_force = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = {
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_high_piety_cost }
				} 
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_work_force_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		decorative_tiles = {
			is_required = no

			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_gold_cost
					}
					else = { value = mandala_contribution_mid_gold_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_decorative_tiles_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		decorated_domes = {
			is_required = no

			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_gold_cost
					}
					else_if = {
						limit = {
							this = scope:owner
							dynasty = { has_dynasty_modifier = mandala_sanctified_domes_dynasty_modifier }
						}
						value = {
							add = mandala_contribution_mid_gold_cost
							divide = 2
						}
					}
					else = { value = mandala_contribution_mid_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else_if = {
						limit = {
							this = scope:owner
							dynasty = { has_dynasty_modifier = mandala_sanctified_domes_dynasty_modifier }
						}
						value = {
							add = mandala_contribution_high_piety_cost
							subtract = mandala_contribution_mid_piety_cost
						}
					}
					else = { value = mandala_contribution_high_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_decorated_domes_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		family_statues = {
			is_required = no

			is_shown = {
				trigger_if = {
					limit = {
						NOT = { exists = scope:owner }
					}
					always = yes
				}
				trigger_else = {
					exists = scope:owner.primary_heir
					scope:owner.dynasty ?= { has_dynasty_perk = tgp_sea_legacy_3 }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = {
				custom_tooltip = {
					text = tgp_sea_legacy_3_name
					dynasty = { has_dynasty_perk = tgp_sea_legacy_3 }
				}
			}

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_high_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_family_statues_reward_effect = yes }
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
			}
		}
	}

	ai_target_quick_trigger = {
		adult = yes
		government_type = { mandala_government }
		rank = county
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 1
		duchy = 1
		kingdom = 1
		empire = 1
		hegemony = 1
	}
	ai_will_do = {
		value = 1000
	}

	completion_sound_effect = @msg_completion_effect_generic
}

mandala_capital_03 = {
	icon = {
		reference = @great_project_mandala_icon
	}
	illustration = {
		reference = @mandala_capital_illustration
	}

	name = {
		desc = great_project_type_mandala_capital_03
	}

	owner = province_owner

	is_important = yes
	is_shown = {
		government_has_flag = government_is_mandala
		capital_province = { 
			has_building_with_flag = second_tier_mandala_capital_building
			NOT = { has_building_with_flag = third_tier_mandala_capital_building }
		}
		NOT = { is_planning_great_project = mandala_capital_03 }
	}

	is_valid = {
		scope:province.barony.holder = {
			government_has_flag = government_is_mandala
		}
	}

	can_start_planning = {
		capital_province = { has_ruined_great_building = no }
		government_has_flag = government_is_mandala
		NOR = {
			is_planning_great_project = mandala_capital_03
			piety_level < high_piety_level
		}
		custom_tooltip = {
			text = mandala_capital_tier_3_amount_of_subjects
			num_mandala_subject_value >= mandala_capital_tier_3_subject_threshold_value
		}
		legitimacy_level >= 4
		is_independent_ruler = yes
		trigger_if = {
			limit = {
				is_tributary = yes
			}
			suzerain = {
				NOT = { has_government = mandala_government }
			}
		}
		#There can only be 2 active (i.e. non-Ruined) Mandala Capitals per De Jure Kingdom
		custom_tooltip = {
			text = not_already_full_on_mandala_capitals
			less_than_max_amount_of_mandala_capitals_trigger = yes
		}
	}

	cost = {
		piety = {
			value = massive_piety_value
			multiply = 1.5
		}
	}

	construction_time = great_project_mandala_increased_construction_time

	contributor_cooldown = standard_contributor_cooldown_value

	on_plan_build = {
		scope:owner = {
			#Memory
			create_character_memory = {
				type = started_planning_mandala_capital_memory
				participants = { founder = scope:owner }
			}
			scope:new_memory ?= {
				set_variable = {
					name = mandala_capital_planned_location
					value = scope:province
				}
				set_variable = {
					name = third_tier_mandala_capital
					value = flag:yes
				}
				if = {
					limit = { 
						exists = var:mandala_capital_planned_location
						exists = var:third_tier_mandala_capital
					}
					#To prevent 'unused except in loc' errors :catto:
				}
			}
		}
	}

	on_complete = {
		scope:owner = {
			scope:province = {
				hidden_effect = { remove_building = mandala_capital_02 }
				set_great_building = mandala_capital_03
			}
			#Owner rewards
			show_as_tooltip = { mandala_owner_reward_01_effect = yes }
			#Memory
			create_character_memory = {
				type = upgraded_mandala_capital_memory
				participants = { founder = scope:founder }
			}
			scope:new_memory ?= {
				set_variable = {
					name = mandala_capital_location
					value = scope:province
				}
				set_variable = {
					name = third_tier_mandala_capital
					value = flag:yes
				}
				if = {
					limit = { 
						exists = var:mandala_capital_location
						exists = var:third_tier_mandala_capital
					}
					#To prevent 'unused except in loc' errors :catto:
				}
			}
		}
		#Tally the rewards
		scope:great_project ?= {
			#Rite of Worthiness
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = rite_of_worthiness }
			#Volcanic Stone
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = volcanic_stone }
			#Corbel Gateways
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = corbel_gateways }
			#Divine Statues
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = divine_statues }
			#Work Force
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = work_force }
			#Creation Aspect
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = creation_aspect }
			#Serenity Aspect
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = serenity_aspect }
			#Destruction Aspect
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = destruction_aspect }
			#Trickery Aspect
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = trickery_aspect }
			#Gilded Domes
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = gilded_domes }
			#Family Temple Compound
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = family_temple_compound }
		}
		#Dole out some rewards!
		gather_contributors_in_list_effect = yes
		every_in_list = {
			list = contributors_to_reward
			if = {
				limit = { this = scope:owner }
				trigger_event = tgp_east_asia_mandala_capital_events.1000
			}
			else = {
				if = {
					limit = { 
						scope:owner = { is_ai = yes }
					}
					show_as_tooltip = { 
						mandala_contributor_opinion_reward_effect = { OVERLORD = scope:owner }
					}
				}
				trigger_event = tgp_east_asia_mandala_capital_events.1010
			}
		}
	}

	on_cancel = {
		scope:owner = {
			add_prestige = minor_prestige_loss
		}
		every_contribution = {
			limit = {
				contribution_is_funded = yes
			}
			contributor = {
				if = {
					limit = {
						this != scope:owner
						this != scope:founder
					}
					add_to_list = contributors_to_disappoint	
				}
			}
		}
		every_in_list = {
			list = contributors_to_disappoint
			add_opinion = {
				modifier = wasted_our_efforts
				target = scope:owner
				opinion = -30
			}
		}
	}

	on_start_build = {
		scope:owner = {
			add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		}
		scope:great_project = {
			every_contribution = {
				limit = {
					contribution_is_funded = yes
				}
				contributor = {
					add_prestige = minor_prestige_value 
				}	
			}
		}
	}

	allowed_contributor_filter = {
		owner = yes
		tributaries = yes
		vassals = yes
	}

	invite_interaction = request_great_project_contribution_interaction

	project_contributions = {
		rite_of_worthiness = {
			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = { 
				#Aspect of Creation
				trigger_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_creation }
					}
					creation_third_tier_trigger = yes
				}
				#Aspect of Serenity
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_serenity }
					}
					serenity_third_tier_trigger = { MANDALA = scope:owner }
				}
				#Aspect of Destruction
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_destruction }
					}
					destruction_third_tier_trigger = yes
				}
				#Aspect of Trickery
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_trickery }
					}
					trickery_third_tier_trigger = yes
				}
				#No Aspect, no dice
				trigger_else = {
					custom_tooltip = {
						text = rite_of_worthiness_per_aspect
						always = no
					}
				}
			}

			cost = { }

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_medium_rite_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 3
				duchy = 3
				kingdom = 3
				empire = 3
				hegemony = 3
			}
			ai_will_do = {
				value = 1000
			}
		}

		volcanic_stone = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_volcanic_stone_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		corbel_gateways = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_high_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_corbel_gateways_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		divine_statues = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_high_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_divine_statues_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		work_force = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = {
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_huge_piety_cost }
				} 
			}
			
			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_work_force_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		creation_aspect = {
			is_required = no

			is_shown = {
				trigger_if = {
					limit = {
						NOT = { exists = scope:owner }
					}
					always = yes
				}
				trigger_else = {
					scope:owner.house ?= { has_house_aspiration_parameter = aspect_of_creation }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = { 
				piety_level >= max_piety_level
				custom_tooltip = {
					text = great_project_mandala_capital_has_creation_aspect_tt
					house = { has_house_aspiration_parameter = aspect_of_creation }
				}
			}

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_huge_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_creation_aspect_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		serenity_aspect = {
			is_required = no

			is_shown = {
				trigger_if = {
					limit = {
						NOT = { exists = scope:owner }
					}
					always = yes
				}
				trigger_else = {
					scope:owner.house ?= { has_house_aspiration_parameter = aspect_of_serenity }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = {
				piety_level >= max_piety_level
				custom_tooltip = {
					text = great_project_mandala_capital_has_serenity_aspect_tt
					house = { has_house_aspiration_parameter = aspect_of_serenity }
				}
			}

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_huge_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_serenity_aspect_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		destruction_aspect = {
			is_required = no

			is_shown = {
				trigger_if = {
					limit = {
						NOT = { exists = scope:owner }
					}
					always = yes
				}
				trigger_else = {
					scope:owner.house ?= { has_house_aspiration_parameter = aspect_of_destruction }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = {
				piety_level >= max_piety_level
				custom_tooltip = {
					text = great_project_mandala_capital_has_destruction_aspect_tt
					house = { has_house_aspiration_parameter = aspect_of_destruction }
				}
			}

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_huge_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_destruction_aspect_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		trickery_aspect = {
			is_required = no

			is_shown = {
				trigger_if = {
					limit = {
						NOT = { exists = scope:owner }
					}
					always = yes
				}
				trigger_else = {
					scope:owner.house ?= { has_house_aspiration_parameter = aspect_of_trickery }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = {
				piety_level >= max_piety_level
				custom_tooltip = {
					text = great_project_mandala_capital_has_trickery_aspect_tt
					house = { has_house_aspiration_parameter = aspect_of_trickery }
				}
			}

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_huge_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_trickery_aspect_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		gilded_domes = {
			is_required = no

			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_gilded_domes_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		family_temple_compound = {
			is_required = no

			is_shown = {
				trigger_if = {
					limit = {
						NOT = { exists = scope:owner }
					}
					always = yes
				}
				trigger_else = {
					exists = scope:owner.primary_heir
					scope:owner.dynasty ?= { has_dynasty_perk = tgp_sea_legacy_3 }
				}
			}

			contributor_is_valid = {
				custom_tooltip = {
					text = you_are_owner_of_the_project
					this = scope:owner
				}
				custom_tooltip = {
					text = tgp_sea_legacy_3_name
					dynasty = { has_dynasty_perk = tgp_sea_legacy_3 }
				}
			}

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_huge_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_family_statues_reward_effect = yes }
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
			}
		}

	}

	ai_target_quick_trigger = {
		adult = yes
		government_type = { mandala_government }
		rank = county
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 1
		duchy = 1
		kingdom = 1
		empire = 1
		hegemony = 1
	}
	ai_will_do = {
		value = 1000
	}

	completion_sound_effect = @msg_completion_effect_generic
}

mandala_capital_04 = {
	icon = {
		reference = @great_project_mandala_icon
	}
	illustration = {
		reference = @mandala_capital_illustration
	}

	name = {
		desc = great_project_type_mandala_capital_04
	}

	owner = province_owner

	is_important = yes
	is_shown = {
		government_has_flag = government_is_mandala
		capital_province = { 
			has_building_with_flag = third_tier_mandala_capital_building
			NOT = { has_building_with_flag = fourth_tier_mandala_capital_building }
		}
		NOT = { is_planning_great_project = mandala_capital_04 }
	}

	is_valid = {
		scope:province.barony.holder = {
			government_has_flag = government_is_mandala
		}
	}

	can_start_planning = {
		capital_province = { has_ruined_great_building = no }
		government_has_flag = government_is_mandala
		NOR = {
			is_planning_great_project = mandala_capital_04
			piety_level < very_high_piety_level
		}
		custom_tooltip = {
			text = mandala_capital_tier_4_amount_of_subjects
			num_mandala_subject_value >= mandala_capital_tier_4_subject_threshold_value
		}
		legitimacy_level >= 5
		is_independent_ruler = yes
		trigger_if = {
			limit = {
				is_tributary = yes
			}
			suzerain = {
				NOT = { has_government = mandala_government }
			}
		}
		#There can only be 2 active (i.e. non-Ruined) Mandala Capitals per De Jure Kingdom
		custom_tooltip = {
			text = not_already_full_on_mandala_capitals
			less_than_max_amount_of_mandala_capitals_trigger = yes
		}
	}

	cost = {
		piety = {
			value = massive_piety_value
			multiply = 2
		}
	}

	construction_time = great_project_mandala_increased_construction_time

	contributor_cooldown = standard_contributor_cooldown_value

	on_plan_build = {
		scope:owner = {
			#Memory
			create_character_memory = {
				type = started_planning_mandala_capital_memory
				participants = { founder = scope:owner }
			}
			scope:new_memory ?= {
				set_variable = {
					name = mandala_capital_planned_location
					value = scope:province
				}
				set_variable = {
					name = fourth_tier_mandala_capital
					value = flag:yes
				}
				if = {
					limit = { 
						exists = var:mandala_capital_planned_location
						exists = var:fourth_tier_mandala_capital
					}
					#To prevent 'unused except in loc' errors :catto:
				}
			}
		}
	}

	on_complete = { 
		scope:owner = {
			scope:province = {
				hidden_effect = { remove_building = mandala_capital_03 }
				set_great_building = mandala_capital_04
			} 
			#Owner rewards
			show_as_tooltip = { mandala_owner_reward_01_effect = yes }
			#Memory
			create_character_memory = {
				type = upgraded_mandala_capital_memory
				participants = { founder = scope:founder }
			}
			scope:new_memory ?= {
				set_variable = {
					name = mandala_capital_location
					value = scope:province
				}
				set_variable = {
					name = fourth_tier_mandala_capital
					value = flag:yes
				}
				if = {
					limit = { 
						exists = var:mandala_capital_location
						exists = var:fourth_tier_mandala_capital
					}
					#To prevent 'unused except in loc' errors :catto:
				}
			}
		}
		#Tally the rewards
		scope:great_project ?= {
			#Rite of Worthiness
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = rite_of_worthiness }
			#Slabs of Granite
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = slabs_of_granite }
			#Zaungdans
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = zaungdans }
			#Gilded Shrines
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = gilded_shrines }
			#Work Force
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = work_force }
			#Bell Stupas
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = bell_stupas }
			#Bejeweled Domes
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = bejeweled_domes }
			#Family Temple Complex
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = family_temple_complex }
		}
		#Dole out some rewards!
		gather_contributors_in_list_effect = yes
		every_in_list = {
			list = contributors_to_reward
			if = {
				limit = { this = scope:owner }
				trigger_event = tgp_east_asia_mandala_capital_events.1000
			}
			else = {
				if = {
					limit = { 
						scope:owner = { is_ai = yes }
					}
					show_as_tooltip = { 
						mandala_contributor_opinion_reward_effect = { OVERLORD = scope:owner }
					}
				}
				trigger_event = tgp_east_asia_mandala_capital_events.1010
			}
		}
	}

	on_cancel = {
		scope:owner = {
			add_prestige = minor_prestige_loss
		}
		every_contribution = {
			limit = {
				contribution_is_funded = yes
			}
			contributor = {
				if = {
					limit = {
						this != scope:owner
						this != scope:founder
					}
					add_to_list = contributors_to_disappoint	
				}
			}
		}
		every_in_list = {
			list = contributors_to_disappoint
			add_opinion = {
				modifier = wasted_our_efforts
				target = scope:owner
				opinion = -30
			}
		}
	}

	on_start_build = {
		scope:owner = {
			add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		}
		scope:great_project = {
			every_contribution = {
				limit = {
					contribution_is_funded = yes
				}
				contributor = {
					add_prestige = minor_prestige_value 
				}	
			}
		}
	}

	allowed_contributor_filter = {
		owner = yes
		tributaries = yes
		vassals = yes
	}

	project_contributions = {
		rite_of_worthiness = {
			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = { 
				#Aspect of Creation
				trigger_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_creation }
					}
					creation_fourth_tier_trigger = yes
				}
				#Aspect of Serenity
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_serenity }
					}
					serenity_fourth_tier_trigger = { MANDALA = scope:owner }
				}
				#Aspect of Destruction
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_destruction }
					}
					destruction_fourth_tier_trigger = yes
				}
				#Aspect of Trickery
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_trickery }
					}
					trickery_fourth_tier_trigger = yes
				}
				#No Aspect, no dice
				trigger_else = {
					custom_tooltip = {
						text = rite_of_worthiness_per_aspect
						always = no
					}
				}
			}

			cost = { }

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { contributed_rites_of_worthiness_02_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 3
				duchy = 3
				kingdom = 3
				empire = 3
				hegemony = 3
			}
			ai_will_do = {
				value = 1000
			}
		}

		slabs_of_granite = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_huge_gold_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			on_complete = {
				show_as_tooltip = { mandala_contributor_slabs_of_granite_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		zaungdans = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_huge_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_huge_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			on_complete = {
				show_as_tooltip = { mandala_contributor_zaungdans_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		gilded_shrines = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_huge_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_piety_cost
					}
					else = { value = mandala_contribution_huge_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			on_complete = {
				show_as_tooltip = { mandala_contributor_gilded_shrines_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		work_force = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				piety = {
					if = {
						limit = { is_ai = yes }
						value = 0
					}
					else = { value = mandala_contribution_huge_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_work_force_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		bell_stupas = {
			is_required = no

			is_shown = {
				trigger_if = {
					limit = {
						NOT = { exists = scope:owner }
					}
					always = yes
				}
				trigger_else = {
					scope:founder.faith = { religion_tag = buddhism_religion }
				}
			}

			contributor_is_valid = {
				root.faith = { religion_tag = buddhism_religion }
			}

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_huge_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = 0
					}
					else = { value = mandala_contribution_huge_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_bell_stupas_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		bejeweled_domes = {
			is_required = no

			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = mandala_contribution_mega_gold_cost
				piety = {
					if = {
						limit = { is_ai = yes }
						value = 0
					}
					else = { value = mandala_contribution_mid_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_bejeweled_domes_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		family_temple_complex = {
			is_required = no

			is_shown = {
				trigger_if = {
					limit = {
						NOT = { exists = scope:owner }
					}
					always = yes
				}
				trigger_else = {
					exists = scope:owner.primary_heir
					scope:owner.dynasty ?= { has_dynasty_perk = tgp_sea_legacy_3 }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = {
				custom_tooltip = {
					text = tgp_sea_legacy_3_name
					dynasty = { has_dynasty_perk = tgp_sea_legacy_3 }
				}
			}

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_mid_gold_cost
					}
					else = { value = mandala_contribution_high_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = 0
					}
					else = { value = mandala_contribution_high_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_family_temple_complex_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
			}
		}
	}

	ai_target_quick_trigger = {
		adult = yes
		government_type = { mandala_government }
		rank = county
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 1
		duchy = 1
		kingdom = 1
		empire = 1
		hegemony = 1
	}
	ai_will_do = {
		value = 1000
	}

	completion_sound_effect = @msg_completion_effect_generic
}

mandala_capital_05 = {
	icon = {
		reference = @great_project_mandala_icon
	}
	illustration = {
		reference = @mandala_capital_illustration
	}

	name = {
		desc = great_project_type_mandala_capital_05
	}

	owner = province_owner

	is_important = yes
	is_shown = {
		government_has_flag = government_is_mandala
		capital_province = { 
			has_building_with_flag = fourth_tier_mandala_capital_building
			NOT = { has_building_with_flag = final_tier_mandala_capital_building }
		}
		NOT = { is_planning_great_project = mandala_capital_05 }
	}

	is_valid = {
		scope:province.barony.holder = {
			government_has_flag = government_is_mandala
		}
	}

	can_start_planning = {
		capital_province = { has_ruined_great_building = no }
		government_has_flag = government_is_mandala
		NOR = {
			is_planning_great_project = mandala_capital_05
			piety_level < very_high_piety_level
		}
		custom_tooltip = {
			text = mandala_capital_tier_5_amount_of_subjects
			num_mandala_subject_value >= mandala_capital_tier_5_subject_threshold_value
		}
		legitimacy_level >= 7
		is_independent_ruler = yes
		trigger_if = {
			limit = {
				is_tributary = yes
			}
			suzerain = {
				NOT = { has_government = mandala_government }
			}
		}
		#There can only be 2 active (i.e. non-Ruined) Mandala Capitals per De Jure Kingdom
		custom_tooltip = {
			text = not_already_full_on_mandala_capitals
			less_than_max_amount_of_mandala_capitals_trigger = yes
		}
	}

	cost = {
		piety = {
			value = massive_piety_value
			multiply = 3
		}
	}

	construction_time = great_project_mandala_massive_construction_time

	contributor_cooldown = standard_contributor_cooldown_value 

	on_plan_build = {
		scope:owner = {
			create_artifact = {
				name = mandala_capital_05_unconfirmed_talisman
				description = mandala_capital_05_unconfirmed_talisman_desc
				type = miscellaneous
				visuals = small_box
				decaying = no
				modifier = artifact_monthly_piety_gain_mult_1_modifier
				save_scope_as = newly_created_talisman
			}
			hidden_effect_new_object = {
				scope:newly_created_talisman = {
					set_variable = {
						name = mandala_capital_05_unconfirmed_talisman
						value = yes
					}
					set_variable = {
						name = mandala_temple_location
						value = scope:owner.capital_province
					}
					if = {
						limit = { has_variable = mandala_temple_location }
						#To prevent 'unused except in loc' errors :catto:
					}
					set_artifact_name = mandala_capital_05_unconfirmed_talisman
					set_artifact_description = mandala_capital_05_unconfirmed_talisman_desc
				}
			}
			#Memory
			create_character_memory = {
				type = started_planning_mandala_capital_memory
				participants = { founder = scope:owner }
			}
			scope:new_memory ?= {
				set_variable = {
					name = mandala_capital_planned_location
					value = scope:province
				}
				set_variable = {
					name = final_tier_mandala_capital
					value = flag:yes
				}
				if = {
					limit = { 
						exists = var:mandala_capital_planned_location
						exists = var:final_tier_mandala_capital
					}
					#To prevent 'unused except in loc' errors :catto:
				}
			}
		}
	}

	on_complete = { 
		scope:owner = {
			capital_province = {
				hidden_effect = { remove_building = mandala_capital_04 }
				set_great_building = mandala_capital_05
			} 
			#Owner rewards
			show_as_tooltip = { mandala_owner_reward_01_effect = yes }
			#Memory
			create_character_memory = {
				type = upgraded_mandala_capital_memory
				participants = { founder = scope:founder }
			}
			scope:new_memory ?= {
				set_variable = {
					name = mandala_capital_location
					value = scope:province
				}
				set_variable = {
					name = final_tier_mandala_capital
					value = flag:yes
				}
				if = {
					limit = { 
						exists = var:mandala_capital_location
						exists = var:final_tier_mandala_capital
					}
					#To prevent 'unused except in loc' errors :catto:
				}
			}
		}
		#Tally the rewards
		scope:great_project ?= {
			#Rite of Worthiness
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = rite_of_worthiness }
			#Marble Foundation
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = marble_foundation }
			#Divine Barays
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = divine_barays }
			#Work Force
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = work_force }
			#Bejeweled Reliefs
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = bejeweled_reliefs }
			#Bunga Mas Forest
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = bunga_mas_forest }
			#Dynastic Temple Complex
			determine_if_contributed_and_save_scope_effect = { CONTRIBUTION = dynastic_temple_complex }
		}
		#Dole out some rewards!
		gather_contributors_in_list_effect = yes
		every_in_list = {
			list = contributors_to_reward
			if = {
				limit = { this = scope:owner }
				trigger_event = tgp_east_asia_mandala_capital_events.1000
			}
			else = {
				if = {
					limit = { 
						scope:owner = { is_ai = yes }
					}
					show_as_tooltip = { 
						mandala_contributor_opinion_reward_effect = { OVERLORD = scope:owner }
					}
				}
				trigger_event = tgp_east_asia_mandala_capital_events.1010
			}
		}
	}

	on_cancel = {
		scope:owner = {
			add_prestige = minor_prestige_loss
			if = {
				limit = {
					any_character_artifact = { has_variable = mandala_capital_05_unconfirmed_talisman }
				}
				random_character_artifact = {
					limit = { has_variable = mandala_capital_05_unconfirmed_talisman }
					destroy_artifact = this
				}
			}
		}
		every_contribution = {
			limit = {
				contribution_is_funded = yes
			}
			contributor = {
				if = {
					limit = {
						this != scope:owner
						this != scope:founder
					}
					add_to_list = contributors_to_disappoint	
				}
			}
		}
		every_in_list = {
			list = contributors_to_disappoint
			add_opinion = {
				modifier = wasted_our_efforts
				target = scope:owner
				opinion = -30
			}
		}
	}

	on_start_build = { 
		scope:owner = {
			add_legitimacy_effect = { LEGITIMACY = minor_legitimacy_gain }
		}
		scope:great_project = {
			every_contribution = {
				limit = {
					contribution_is_funded = yes
				}
				contributor = {
					add_prestige = minor_prestige_value 
				}	
			}
		}
	}

	allowed_contributor_filter = {
		owner = yes
		tributaries = yes
		vassals = yes
	}

	project_contributions = {
		rite_of_worthiness = {
			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = { 
				#Aspect of Creation
				trigger_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_creation }
					}
					creation_fifth_tier_trigger = yes
				}
				#Aspect of Serenity
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_serenity }
					}
					serenity_fifth_tier_trigger = { MANDALA = scope:owner }
				}
				#Aspect of Destruction
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_destruction }
					}
					destruction_fifth_tier_trigger = yes
				}
				#Aspect of Trickery
				trigger_else_if = {
					limit = {
						scope:owner.house = { has_house_aspiration_parameter = aspect_of_trickery }
					}
					trickery_fifth_tier_trigger = yes
				}
				#No Aspect, no dice
				trigger_else = {
					custom_tooltip = {
						text = rite_of_worthiness_per_aspect
						always = no
					}
				}
			}

			cost = { }

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_medium_rite_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 3
				duchy = 3
				kingdom = 3
				empire = 3
				hegemony = 3
			}
			ai_will_do = {
				value = 1000
			}
		}

		marble_foundation = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_high_gold_cost
					}
					else = { value = mandala_contribution_mega_gold_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_marble_foundation_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		divine_barays = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_high_gold_cost
					}
					else = { value = mandala_contribution_mega_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_high_piety_cost
					}
					else = { value = mandala_contribution_mega_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_divine_barays_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		work_force = {
			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_high_piety_cost
					}
					else = { value = mandala_contribution_mega_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_work_force_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		bejeweled_reliefs = {
			is_required = no

			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_high_gold_cost
					}
					else = { value = mandala_contribution_mega_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_low_piety_cost
					}
					else = { value = mandala_contribution_mid_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_bejeweled_reliefs_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		bunga_mas_forest = {
			is_required = no

			contributor_is_valid = { highest_held_title_tier > tier_barony }

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_high_gold_cost
					}
					else = { 
						value = mandala_contribution_mega_gold_cost
						multiply = 1.5
						#Rounds up to the closest number divisible by 5
						divide = 5
						ceiling = yes
						multiply = 5
					}
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_high_piety_cost
					}
					else = { value = mandala_contribution_mega_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_bunga_mas_forest_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
				if = {
					limit = {
						is_tributary = yes
						overlord = { has_realm_law_flag = tributaries_more_likely_to_contribute_to_GPs }
					}
					multiply = 2
				}
			}
		}

		dynastic_temple_complex = {
			is_required = no

			is_shown = {
				trigger_if = {
					limit = {
						NOT = { exists = scope:owner }
					}
					always = yes
				}
				trigger_else = {
					exists = scope:owner.primary_heir
					scope:owner.dynasty ?= { has_dynasty_perk = tgp_sea_legacy_3 }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}
			contributor_is_valid = {
				custom_tooltip = {
					text = tgp_sea_legacy_3_name
					dynasty = { has_dynasty_perk = tgp_sea_legacy_3 }
				}
			}

			cost = { 
				gold = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_high_gold_cost
					}
					else = { value = mandala_contribution_mega_gold_cost }
				}
				piety = {
					if = {
						limit = { is_ai = yes }
						value = mandala_contribution_high_piety_cost
					}
					else = { value = mandala_contribution_mega_piety_cost }
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value

			on_complete = {
				show_as_tooltip = { mandala_contributor_family_temple_complex_reward_effect = yes }
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 12
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = 50
			}
		}
	}

	ai_target_quick_trigger = {
		adult = yes
		government_type = { mandala_government }
		rank = county
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 1
		duchy = 1
		kingdom = 1
		empire = 1
		hegemony = 1
	}
	ai_will_do = {
		value = 1000
	}

	completion_sound_effect = @msg_completion_effect_generic
}

########################
# CHINESE GREAT PROJECTS
########################

# Construct Great Barracks - Adds a unique duchy building
construct_great_barracks = {
	icon = {
		reference = @great_project_china_icon
	}
	illustration = {
		reference = @castle_china_illustration
	}

	name = {
		desc = great_project_type_construct_great_barracks
	}
	
	is_shown = {
		has_tgp_dlc_trigger = yes
		government_has_flag = government_is_celestial
		OR = {
			AND = {
				is_independent_ruler = yes
				highest_held_title_tier >= tier_empire
			}
			has_title = title:e_minister_of_war
			has_title = title:e_minister_grand_marshal
			has_title = title:e_minister_of_works
		}
		NOT = { is_planning_great_project = construct_great_barracks }
	}

	province_filter = top_realm

	is_location_valid = {
		scope:province = {
			custom_tooltip = {
				text = great_project_type_construct_great_barracks_military_governor_duchy_capital
				barony.county.holder ?= {
					vassal_contract_has_flag = celestial_military_appointment # is held by a military governor
				}
				this = barony.holder.capital_barony.title_province # is their capital
				duchy = {
					title_capital_county.title_province = scope:province # is also the duchy capital
				}
			}
			custom_tooltip = {
				text = great_project_type_construct_great_barracks_does_not_already_have_barracks
				NOT = {
					has_building = celestial_great_barracks_01 # you can overwrite duchy buildings, but there's no point in doing it to the same one
				}
			}
			trigger_if = {
				limit = {
					barony.county.holder = {
						is_ai = no
						this != root
					}
				}
				custom_tooltip = {
					text = great_project_type_construct_great_barracks_do_not_override_player_building
					NOT = {
						has_building_with_flag = duchy_building
					}
				}
			}
		}
	}

	can_start_planning = {
		# You/your liege/the minister have not already planned this project
		NOT = {
			top_liege = {
				custom_tooltip = {
					text = only_single_great_project_type_allowed
					is_planning_great_project = construct_great_barracks
				}
			}
		}
		culture ?= { has_innovation = innovation_barracks }
	}

	cost = {
		treasury_or_gold = great_project_base_starting_cost
	}

	construction_time = {
		value = great_project_base_construction_time
		multiply = common_great_project_construction_time_multiplier_value
	}

	allowed_contributor_filter = {
		owner = yes
		vassals = yes
	}

	contributor_cooldown = standard_contributor_cooldown_value
	
	on_start_build = {}
	
	on_complete = {
		if = {
			limit = {
				NOT = {
					scope:province ?= {
						has_building_with_flag = duchy_building
					}
				}
			}
			custom_tooltip = {
				text = great_project_type_construct_great_barracks_province_gains_great_barracks
				scope:province ?= {
					add_building = celestial_great_barracks_01
				}
			}
		}
		else = {
			custom_tooltip = {
				text = project_great_barracks_replace_tt
				scope:province ?= {
					replace_building_effect = celestial_great_barracks_01
				}
			}
		}
		great_project_notify_completion = { CHARACTER = scope:owner }
		scope:founder ?= {
			if = {
				limit = {
					tgp_is_any_minister = yes
					is_alive = yes # this is actually necessary, because they remain the scope character and accessible even after death
				}
				change_influence = minister_influence_gain_value
			}
		}
	}
	
	on_cancel = {}

	project_contributions = {
		base_materials = {
			contributor_is_valid = {
				custom_tooltip = {
					text = great_project_contribution_must_be_province_owner_or_above
					OR = {
						this = scope:great_project.great_project_location.province_owner
						is_liege_or_above_of = scope:great_project.great_project_location.province_owner
						has_title = title:e_minister_of_war
						has_title = title:e_minister_grand_marshal
						has_title = title:e_minister_of_works
					}
				}
			}

			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 4
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				great_project_reward_contribution_completion_notification_effect = {
					LEVEL = minor
					NON_OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
					OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		fort_material = {
			contributor_is_valid = {
				custom_tooltip = {
					text = great_project_contribution_must_be_province_owner_or_above
					OR = {
						this = scope:great_project.great_project_location.province_owner
						is_liege_or_above_of = scope:great_project.great_project_location.province_owner
						has_title = title:e_minister_of_war
						has_title = title:e_minister_grand_marshal
						has_title = title:e_minister_of_works
					}
				}
			}

			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 4
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				great_project_reward_contribution_completion_notification_effect = {
					LEVEL = minor
					NON_OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
					OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		work_force = {
			contributor_is_valid = {
				custom_tooltip = {
					text = great_project_contribution_must_be_province_owner_or_above
					OR = {
						this = scope:great_project.great_project_location.province_owner
						is_liege_or_above_of = scope:great_project.great_project_location.province_owner
						has_title = title:e_minister_of_war
						has_title = title:e_minister_grand_marshal
						has_title = title:e_minister_of_works
					}
				}
			}

			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 2
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				great_project_reward_contribution_completion_notification_effect = {
					LEVEL = minor
					NON_OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
					OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		soldiers = {
			contributor_is_valid = {
				custom_tooltip = {
					text = great_project_contribution_must_be_province_owner_or_above
					OR = {
						this = scope:great_project.great_project_location.province_owner
						is_liege_or_above_of = scope:great_project.great_project_location.province_owner
						has_title = title:e_minister_of_war
						has_title = title:e_minister_grand_marshal
						has_title = title:e_minister_of_works
					}
				}
			}

			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 2
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				great_project_reward_contribution_completion_notification_effect = {
					LEVEL = minor
					NON_OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
					OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
	}

	ai_target_quick_trigger = {
		adult = yes
		rank = empire
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 6
		hegemony = 6
	}
	ai_will_do = {
		value = 30
		if = {
			limit = {
				treasury >= 20000
			}
			add = 70
		}
		if = {
			limit = {
				situation:dynastic_cycle ?= {
					OR = {
						situation_current_phase = situation_dynastic_cycle_phase_stability_expansion
						situation_current_phase = situation_dynastic_cycle_phase_instability_conquest
					}
				}
			}
			add = 30
		}
		if = {
			limit = {
				is_at_war = yes
			}
			multiply = 0
		}
	}

	completion_sound_effect = @msg_completion_effect_generic
}

# Strengthen Capital - Improves the capital in various ways, and slows down the drift for the dynastic cycle
strengthen_capital = {
	icon = {
		reference = @great_project_china_icon
	}
	illustration = {
		reference = @courtyard_asia_illustration
	}

	name = {
		desc = great_project_type_strengthen_capital
	}
	
	is_shown = {
		has_tgp_dlc_trigger = yes
		OR = {
			has_title = title:h_china
			has_title = title:e_minister_of_works
		}
		NOR = {
			is_planning_great_project = strengthen_capital
			custom_tooltip = {
				text = only_single_great_project_type_allowed
				any_great_project = {
					great_project_type = strengthen_capital
				}
			}
		}
		NOT = {
			any_sub_realm_county = {
				has_county_modifier = tgp_strengthen_capital_modifier
			}
		}
		trigger_if = {
			limit = {
				exists = situation:dynastic_cycle.var:gp_strengthen_capital_cooldown
			}
			house != situation:dynastic_cycle.var:gp_strengthen_capital_cooldown
		}
	}

	can_start_planning = {
		OR = {
			is_independent_ruler = yes
			has_title = title:e_minister_of_works
		}
	}
	
	is_valid = {
		scope:province.county.holder.top_liege ?= scope:owner
	}

	cost = {
		treasury_or_gold = {
			value = great_project_base_starting_cost
			multiply = 2
		}
	}

	construction_time = {
		value = great_project_base_construction_time
		multiply = common_great_project_construction_time_multiplier_value
	}

	allowed_contributor_filter = {
		owner = yes
		vassals = yes
	}

	contributor_cooldown = standard_contributor_cooldown_value
	
	on_start_build = {}
	
	on_complete = {
		scope:province.county = {
			add_county_modifier = {
				modifier = tgp_strengthen_capital_modifier
				years = 20
			}
		}
		show_as_tooltip = {
			scope:founder.top_liege ?= { # because the real owner doesn't exist in the effect preview
				send_interface_toast = {
					type = event_generic_neutral_text
					title = great_project_completed_msg_t
					left_icon = scope:owner
					right_icon = scope:province.county
					desc = great_project_completed_msg_desc

					add_character_modifier = {
						modifier = tgp_strengthen_capital_character_modifier
						years = 20
					}
					
					if = {
						limit = { is_valid_for_legitimacy_change = yes }
						add_legitimacy = {
							value = medium_legitimacy_gain
							if = {
								limit = {
									any_character_situation = {
										situation_type = dynastic_cycle
										has_situation_top_phase_parameter = dynastic_cycle_great_projects_increased_legitimacy
									}
								}
								multiply = 2
							}
						}
					}
				}
			}		
		}
		hidden_effect = {
			scope:owner ?= {
				send_interface_toast = {
					type = event_generic_neutral_text
					title = great_project_completed_msg_t
					left_icon = scope:owner
					right_icon = scope:province.county
					desc = great_project_completed_msg_desc

					add_character_modifier = {
						modifier = tgp_strengthen_capital_character_modifier
						years = 20
					}
					
					if = {
						limit = { is_valid_for_legitimacy_change = yes }
						add_legitimacy = {
							value = medium_legitimacy_gain
							if = {
								limit = {
									any_character_situation = {
										situation_type = dynastic_cycle
										has_situation_top_phase_parameter = dynastic_cycle_great_projects_increased_legitimacy
									}
								}
								multiply = 2
							}
						}
					}
				}
			}
		}
		scope:founder ?= {
			if = {
				limit = {
					tgp_is_any_minister = yes
					is_alive = yes # this is actually necessary, because they remain the scope character and accessible even after death
				}
				change_influence = minister_influence_gain_value
			}
		}
		# The ruling house can only do this once, so let's set a cooldown
		situation:dynastic_cycle ?= {
			set_variable = {
				name = gp_strengthen_capital_cooldown
				value = scope:owner.house
			}
		}
	}
	
	on_cancel = {}

	# Top liege pays with the treasury, while vassals may pitch in with gold
	project_contributions = {
		materials = {
			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 2
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				great_project_reward_contribution_completion_notification_effect = {
					LEVEL = minor
					NON_OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
					OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		workforce = {
			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 2
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				great_project_reward_contribution_completion_notification_effect = {
					LEVEL = minor
					NON_OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
					OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		architects = {
			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 1.5
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no

			on_complete = {
				great_project_reward_contribution_completion_notification_effect = {
					LEVEL = major
					NON_OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
					OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
				}
				scope:province.county = {
					add_county_modifier = {
						modifier = tgp_strengthen_capital_architects_modifier
						years = 20
					}
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		engineers = {
			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 1.5
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no

			on_complete = {
				great_project_reward_contribution_completion_notification_effect = {
					LEVEL = major
					NON_OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
					OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
				}
				scope:province.county = {
					add_county_modifier = {
						modifier = tgp_strengthen_capital_engineers_modifier
						years = 20
					}
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		sculptors = {
			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 1.5
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no

			on_complete = {
				great_project_reward_contribution_completion_notification_effect = {
					LEVEL = major
					NON_OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
					OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
				}
				scope:province.county.holder = {
					add_character_modifier = {
						modifier = tgp_strengthen_capital_sculptors_modifier
						years = 20
					}
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		forbidden_city = {
			is_shown = {
				scope:owner = {
					capital_barony.title_province ?= {
						NOT = { has_building = forbidden_city_01 }
					}
				}
			}

			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 3
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no

			on_complete = {
				great_project_reward_contribution_completion_notification_effect = {
					LEVEL = major
					NON_OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
					OWNER_REWARD_EFFECT = great_project_reward_contribution_completion_null
				}
				scope:province = {
					set_great_building = forbidden_city_01
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
	}

	ai_target_quick_trigger = {
		adult = yes
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 0
		hegemony = 6
	}
	ai_will_do = {
		value = 500
		if = {
			limit = {
				is_at_war = yes
			}
			multiply = 0
		}
	}

	completion_sound_effect = @msg_completion_effect_generic
}

# The Great Wall projects
great_wall = { # This is a project to upgrade pre-existing wall sections within your realm
	icon = {
		reference = @icon_great_project_great_wall
	}
	illustration = {
		reference = @great_wall_illustration
	}

	name = {
		desc = great_project_type_great_wall
	}
	
	is_shown = {
		# You are the hegemon or a relevant minister
		OR = {
			has_title = title:h_china
			has_title = title:e_minister_of_works
			AND = {
				is_diarch_of_target = top_liege
				top_liege = {
					has_diarchy_type = grand_secretariat
				}
			}
		}
		NOT = { is_planning_great_project = great_wall } # Only expand it once at a time
		top_liege = {
			any_realm_county = { # You need to have a valid section to upgrade
				any_county_province = {
					has_holding = yes		#Unop: some wall segment exist in a province without any holding, creating a fake Great Project
					OR = {
						has_building = the_great_wall_01
						has_building = the_great_wall_02
						has_building = the_great_wall_03
					}
				}
			}
		}
	}

	can_start_planning = {
		NOR = {
			is_planning_great_project = great_wall
			custom_tooltip = {
				text = only_single_great_project_type_allowed
				any_great_project = {
					great_project_type = great_wall
				}
			}
		}
	}

	is_valid = {
		scope:owner = {
			any_realm_county = { # You need to still have a valid section to upgrade
				any_county_province = {
					OR = {
						has_building = the_great_wall_01
						has_building = the_great_wall_02
						has_building = the_great_wall_03
					}
				}
			}
		}
	}

	# Initial cost is very low, most of the cost is spent on contributions
	cost = {
		treasury_or_gold = {
			value = great_project_base_starting_cost
			multiply = 0.3
		}
	}

	construction_time = {
		value = great_project_base_construction_time
		multiply = common_great_project_construction_time_multiplier_value
	}

	contributor_cooldown = standard_contributor_cooldown_value

	allowed_contributor_filter = {
		owner = yes
		vassals = yes
		tributaries = yes
	}

	on_complete = {
		# We do not build the wall here, the upgrades are done as contributions instead
		custom_tooltip = {
			text = great_project_type_great_wall_province_gains_great_wall
		}
		scope:founder ?= {
			if = {
				limit = {
					tgp_is_any_minister = yes
					is_alive = yes # this is actually necessary, because they remain the scope character and accessible even after death
				}
				change_influence = minister_influence_gain_value
			}
		}
	}

	on_cancel = {
	}

	on_plan_build = {
	}

	on_start_build = {
		situation:dynastic_cycle = {
			if = {
				limit = {
					situation_top_has_catalyst = catalyst_great_wall
				}
				trigger_situation_catalyst = {
					catalyst = catalyst_great_wall
					character = scope:founder
				}
			}
		}
	}

	on_invalidated = {
	}

	project_contributions = {
		# The top liege needs to appoint a master builder, this is the only required contribution
		master_builder = {
			contributor_is_valid = {
				OR = {
					custom_tooltip = {
						text = you_are_owner_of_the_project
						this = scope:owner
					}
					has_title = title:e_minister_of_works
				}
			}

			context_allows_contributions = {
				custom_tooltip = {
					text = great_project_contribution_master_builder_must_have_funded_province
					exists = scope:great_project.var:any_funded_provinces
				}
			}

			cost = {
				treasury_or_gold = {
					value = great_project_base_contribution_cost
					multiply = 2
				}
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = { }

			ai_check_interval_by_tier = { # wait for a longer time than usual between checks to allow contributions to finish
				barony = 0
				county = 24
				duchy = 24
				kingdom = 12
				empire = 12
				hegemony = 12
			}
			ai_will_do = {
				value = 1000
				if = {
					limit = {
						is_at_war = yes
					}
					multiply = 0
				}
			}
		}
		# Below is a list of possible upgrades, one for each barony that starts the game with the great wall
		# This allows the player to upgrade however many sections they want/can afford, whenever they want
		# Vassals and tributaries can all contribute to these
		walls_01 = { # b_wulan
			is_shown = {
				title:b_wulan.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_wulan.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_02 = { # b_fengan
			is_shown = {
				title:b_fengan.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_fengan.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_03 = { # b_mingsha
			is_shown = {
				title:b_mingsha.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_mingsha.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_04 = { # b_yaode
			is_shown = {
				title:b_yaode.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_yaode.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_05 = { # b_huile
			is_shown = {
				title:b_huile.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_huile.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_06 = { # b_baojing
			is_shown = {
				title:b_baojing.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_baojing.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_07 = { # b_huaiyuan
			is_shown = {
				title:b_huaiyuan.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_huaiyuan.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_08 = { # b_shengwei
			is_shown = {
				title:b_shengwei.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_shengwei.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_09 = { # b_hequ
			is_shown = {
				title:b_hequ.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_hequ.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_10 = { # b_helan
			is_shown = {
				title:b_helan.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_helan.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_11 = { # b_dengkou
			is_shown = {
				title:b_dengkou.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_dengkou.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_12 = { # b_wuluhai
			is_shown = {
				title:b_wuluhai.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_wuluhai.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_13 = { # b_yongfeng
			is_shown = {
				title:b_yongfeng.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_yongfeng.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_14 = { # b_jiuyuan
			is_shown = {
				title:b_jiuyuan.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_jiuyuan.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_15 = { # b_tiande
			is_shown = {
				title:b_tiande.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_tiande.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_16 = { # b_jincheng
			is_shown = {
				title:b_jincheng.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_jincheng.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_17 = { # b_huichuan
			is_shown = {
				title:b_huichuan.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_huichuan.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_18 = { # b_huairong_2
			is_shown = {
				title:b_huairong_2.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_huairong_2.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_19 = { # b_pinggao
			is_shown = {
				title:b_pinggao.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_pinggao.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_20 = { # b_huaide
			is_shown = {
				title:b_huaide.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_huaide.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_21 = { # b_fangqu
			is_shown = {
				title:b_fangqu.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_fangqu.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_22 = { # b_huaian_2
			is_shown = {
				title:b_huaian_2.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_huaian_2.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_23 = { # b_luoyuan
			is_shown = {
				title:b_luoyuan.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_luoyuan.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_24 = { # b_hengshan_3
			is_shown = {
				title:b_hengshan_3.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_hengshan_3.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_25 = { # b_wuyan
			is_shown = {
				title:b_wuyan.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_wuyan.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_26 = { # b_ningshuo
			is_shown = {
				title:b_ningshuo.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_ningshuo.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_27 = { # b_longquan
			is_shown = {
				title:b_longquan.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_longquan.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_28 = { # b_rulin
			is_shown = {
				title:b_rulin.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_rulin.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_29 = { # b_kaiguang
			is_shown = {
				title:b_kaiguang.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_kaiguang.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_30 = { # b_linzhou_yincheng
			is_shown = {
				title:b_linzhou_yincheng.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_linzhou_yincheng.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_31 = { # b_xiazhou_dejing_east
			is_shown = {
				title:b_xiazhou_dejing_east.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_xiazhou_dejing_east.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_32 = { # b_xuande
			is_shown = {
				title:b_xuande.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_xuande.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_33 = { # b_baishui
			is_shown = {
				title:b_baishui.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_baishui.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_34 = { # b_rouxuan
			is_shown = {
				title:b_rouxuan.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_rouxuan.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		walls_35 = { # b_cirlxj_yangcheng
			is_shown = {
				title:b_cirlxj_yangcheng.title_province = {
					NOT = { has_building_or_higher = the_great_wall_04 }
					province_owner ?= { top_liege = root.top_liege }
				}
			}
			on_complete = {
				title:b_cirlxj_yangcheng.title_province = { set_great_building = the_great_wall_04 }
				contributor_great_wall_reward_effect = yes
			}
			
			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}
			
			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = no
			
			on_contribution_funded = {
				scope:great_project = {
					set_variable = any_funded_provinces
				}
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}

			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
	}

	ai_target_quick_trigger = {
		adult = yes
		rank = empire
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 6
		hegemony = 6
	}
	ai_will_do = {
		value = 500
		if = {
			limit = {
				is_at_war = yes
			}
			multiply = 0
		}
	}

	completion_sound_effect = @msg_completion_effect_military
}

great_wall_extend_to_shanhai_pass = {
	icon = {
		reference = @icon_great_project_great_wall
	}
	illustration = {
		reference = @great_wall_illustration
	}

	name = {
		desc = great_project_type_great_wall_extend_to_shanhai_pass
	}

	is_shown = {
		# The wall has not already been built
		NOT = { has_global_variable = great_wall_extend_to_shanhai_pass_complete }
		# You are the hegemon or a relevant minister
		OR = {
			has_title = title:h_china
			has_title = title:e_minister_of_works
			AND = {
				is_diarch_of_target = top_liege
				top_liege = {
					has_diarchy_type = grand_secretariat
				}
			}
		}
		# Project becomes visible once you own at least one of the relevant counties
		top_liege = {
			any_realm_county = {
				OR = {
					this = title:c_guizhou_2
					this = title:c_tanzhou_2
					this = title:c_jizhou_1
					this = title:c_pinzhou
				}
			}
		}
		# And you are not already planning this project
		NOT = { is_planning_great_project = great_wall_extend_to_shanhai_pass }
	}

	can_start_planning = {
		NOR = {
			is_planning_great_project = great_wall_extend_to_shanhai_pass
			custom_tooltip = {
				text = only_single_great_project_type_allowed
				any_great_project = {
					great_project_type = great_wall_extend_to_shanhai_pass
				}
			}
		}
		# All baronies have a holding and the relevant area is completely controlled
		title:b_jinshan_2.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_yanle.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_zunhua.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_yuyang.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_shicheng_2.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_anxi_2.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_lulong.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
	}

	is_valid = {
		title:b_jinshan_2.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_yanle.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_zunhua.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_yuyang.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_shicheng_2.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_anxi_2.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_lulong.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
	}

	cost = {
		treasury_or_gold = great_wall_treasury_cost_value
	}

	construction_time = {
		value = 3650
		multiply = common_great_project_construction_time_multiplier_value
	}

	contributor_cooldown = 0

	allowed_contributor_filter = {
		owner = yes
		vassals = yes
		tributaries = yes
	}

	on_complete = {
		# Add the great wall to all relevant holdings
		custom_tooltip = {
			text = add_great_wall_in_shanhai_desc
			
			title:b_jinshan_2.title_province = { add_great_building = the_great_wall_04 }
			title:b_yanle.title_province = { add_great_building = the_great_wall_04 }
			title:b_zunhua.title_province = { add_great_building = the_great_wall_04 }
			title:b_yuyang.title_province = { add_great_building = the_great_wall_04 }
			title:b_shicheng_2.title_province = { add_great_building = the_great_wall_04 }
			if = {
				limit = {
					title:b_anxi_2.title_province = {
						has_great_building = no
					}
				}
				title:b_anxi_2.title_province = { add_great_building = the_great_wall_04 }
			}
			title:b_lulong.title_province = { add_great_building = the_great_wall_shanhai_pass }
		}
		# Mark this section as complete
		set_global_variable = {
			name = great_wall_extend_to_shanhai_pass_complete
			value = yes
		}
		scope:founder ?= {
			if = {
				limit = {
					tgp_is_any_minister = yes
					is_alive = yes # this is actually necessary, because they remain the scope character and accessible even after death
				}
				change_influence = minister_influence_gain_value
			}
		}
	}

	on_cancel = {
	}

	on_plan_build = {
	}

	on_start_build = {
		situation:dynastic_cycle = {
			if = {
				limit = {
					situation_top_has_catalyst = catalyst_great_wall
				}
				trigger_situation_catalyst = {
					catalyst = catalyst_great_wall
					character = scope:founder
				}
			}
		}
	}

	on_invalidated = {
	}

	project_contributions = {
		materials = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		land_clearance = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		engineers = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		logistics = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		personnel_construction = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		personnel_dig = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		architects = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_at_war = yes
					}
					multiply = 0
				}
			}
		}
		fort_material = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = 100
				if = {
					limit = {
						is_at_war = yes
					}
					multiply = 0
				}
			}
		}
	}

	ai_target_quick_trigger = {
		adult = yes
		rank = empire
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 6
		hegemony = 6
	}
	ai_will_do = {
		value = 500
		if = {
			limit = {
				is_at_war = yes
			}
			multiply = 0
		}
	}

	completion_sound_effect = @msg_completion_effect_military
}

great_wall_extend_to_liaodong = {
	icon = {
		reference = @icon_great_project_great_wall
	}
	illustration = {
		reference = @great_wall_illustration
	}

	name = {
		desc = great_project_type_great_wall_extend_to_liaodong
	}


	is_shown = {
		# The wall has not already been built
		NOT = { has_global_variable = great_wall_extend_to_liaodong_complete }
		# You are the hegemon or a relevant minister
		OR = {
			has_title = title:h_china
			has_title = title:e_minister_of_works
			AND = {
				is_diarch_of_target = top_liege
				top_liege = {
					has_diarchy_type = grand_secretariat
				}
			}
		}
		# Project becomes visible once you own at least one of the relevant counties
		top_liege = {
			any_realm_county = {
				OR = {
					this = title:c_pinzhou
					this = title:c_lnj_liaoxi
					this = title:c_lnj_liaoxibei
					this = title:c_LIAO_chaoyang
					this = title:c_woye
					this = title:c_LIAO_liaozhou
					this = title:c_LIAO_wuzhou
					this = title:c_LIAO_yinzhou
					this = title:c_LIAO_guidezhou
					this = title:c_LIAO_diezhou
					this = title:c_uiju
				}
			}
		}
		# And you are not already planning this project
		NOT = { is_planning_great_project = great_wall_extend_to_liaodong }
	}

	can_start_planning = {
		NOR = {
			is_planning_great_project = great_wall_extend_to_liaodong
			custom_tooltip = {
				text = only_single_great_project_type_allowed
				any_great_project = {
					great_project_type = great_wall_extend_to_liaodong
				}
			}
		}
		# All baronies have a holding and the relevant area is completely controlled
		title:b_anxi_2.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_cirlzj_longtan.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_cirlzj_yuhejing.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Liping.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Chaoyang.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Wuanzhou.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Chengzhou.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Suizhou.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Weizhou2.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Yuanzhou.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Shuangzhou.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Qizhou.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Fuzhou2.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_FIC_Liao_Huangcaocun.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Guidezhou.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Fengcheng.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Liao_Dandong.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Goryeo_Bukgye_Uiju.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
		title:b_Goryeo_Bukgye_Cheolju.title_province = {
			save_temporary_scope_as = great_wall_extend_province
			custom_tooltip = {
				text = great_wall_extend_to_top_liege_of_province
				has_holding = yes
				province_owner ?= { top_liege = root.top_liege }
			}
		}
	}

	is_valid = {
		title:b_anxi_2.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_cirlzj_longtan.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_cirlzj_yuhejing.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Liping.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Chaoyang.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Wuanzhou.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Chengzhou.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Suizhou.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Weizhou2.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Yuanzhou.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Shuangzhou.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Qizhou.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Fuzhou2.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_FIC_Liao_Huangcaocun.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Guidezhou.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Fengcheng.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Liao_Dandong.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Goryeo_Bukgye_Uiju.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
		title:b_Goryeo_Bukgye_Cheolju.title_province = {
			province_owner ?= { top_liege = scope:owner.top_liege }
		}
	}

	cost = {
		treasury_or_gold = great_wall_treasury_cost_value
	}

	construction_time = {
		value = 3650
		multiply = common_great_project_construction_time_multiplier_value
	}

	contributor_cooldown = 0

	allowed_contributor_filter = {
		owner = yes
		vassals = yes
		tributaries = yes
	}

	on_complete = {
		# Add the great wall to all relevant holdings
		custom_tooltip = {
			text = add_great_wall_in_liaodong_desc
			title:b_anxi_2.title_province = {
				if = {
					limit = { has_great_building = no }
					add_great_building = the_great_wall_04
				}
			}
			title:b_cirlzj_longtan.title_province = { add_great_building = the_great_wall_04 }
			title:b_cirlzj_yuhejing.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Liping.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Chaoyang.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Wuanzhou.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Chengzhou.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Suizhou.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Weizhou2.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Yuanzhou.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Shuangzhou.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Qizhou.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Fuzhou2.title_province = { add_great_building = the_great_wall_04 }
			title:b_FIC_Liao_Huangcaocun.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Guidezhou.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Fengcheng.title_province = { add_great_building = the_great_wall_04 }
			title:b_Liao_Dandong.title_province = { add_great_building = the_great_wall_04 }
			title:b_Goryeo_Bukgye_Uiju.title_province = { add_great_building = the_great_wall_liaodong }
			title:b_Goryeo_Bukgye_Cheolju.title_province = { add_great_building = the_great_wall_04 }
		}
		# Mark this section as complete
		set_global_variable = {
			name = great_wall_extend_to_liaodong_complete
			value = yes
		}
		scope:founder ?= {
			if = {
				limit = {
					tgp_is_any_minister = yes
					is_alive = yes # this is actually necessary, because they remain the scope character and accessible even after death
				}
				change_influence = minister_influence_gain_value
			}
		}
	}

	on_cancel = {
	}

	on_plan_build = {
	}

	on_start_build = {
		situation:dynastic_cycle = {
			if = {
				limit = {
					situation_top_has_catalyst = catalyst_great_wall
				}
				trigger_situation_catalyst = {
					catalyst = catalyst_great_wall
					character = scope:founder
				}
			}
		}
	}

	on_invalidated = {
	}

	project_contributions = {
		materials = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		workforce = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		logistics = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		engineers = {
			contributor_is_valid = {
				OR = {
					top_liege = scope:owner
					is_tributary_of = scope:owner
				}
			}

			cost = {
				treasury_or_gold = great_wall_treasury_cost_value
			}

			contributor_cooldown = 0
			
			is_required = yes

			on_complete = {
				contributor_great_wall_reward_effect = yes
			}
			ai_check_interval_by_tier = {							
				barony = 0
				county = 12
				duchy = 9
				kingdom = 6
				empire = 6
				hegemony = 6
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
	}

	ai_target_quick_trigger = {
		adult = yes
		rank = empire
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 6
		hegemony = 6
	}
	ai_will_do = {
		value = 500
		if = {
			limit = {
				is_at_war = yes
			}
			multiply = 0
		}
	}

	completion_sound_effect = @msg_completion_effect_military
}

# Expand the Great Canal
grand_canals = {
	icon = {
		reference = @great_project_great_canals_icon
	}
	illustration = {
		reference = @grand_canals_illustration
	}

	name = {
		desc = great_project_type_grand_canals
	}


	is_shown = {
		has_tgp_dlc_trigger = yes
		# You are the hegemon or a relevant minister
		OR = {
			has_title = title:h_china
			has_title = title:e_minister_of_works
			AND = {
				is_diarch_of_target = top_liege
				top_liege = {
					has_diarchy_type = grand_secretariat
				}
			}
		}
		# All canals have yet to be built
		any_county_in_region = {
			region = dlc_tgp_grand_canal_region
			holder.top_liege = root.top_liege
			NOT = { has_county_modifier = tgp_grand_canal_modifier }
		}
	}

	can_start_planning = {
		NOR = {
			is_planning_great_project = grand_canals
			custom_tooltip = {
				text = only_single_great_project_type_allowed
				any_great_project = {
					great_project_type = grand_canals
				}
			}
		}
	}
	
	is_valid = {
	}
	
	is_location_valid = {
		scope:province = {
			county = {
				NOT = { has_county_modifier = tgp_grand_canal_modifier }
			}
			trigger_if = {
				limit = {
					geographical_region = dlc_tgp_grand_canal_1_region
				}
				root.top_liege = { completely_controls_region = dlc_tgp_grand_canal_1_region }
			}
			trigger_if = {
				limit = {
					geographical_region = dlc_tgp_grand_canal_2_region
				}
				root.top_liege = { completely_controls_region = dlc_tgp_grand_canal_2_region }
			}
			trigger_if = {
				limit = {
					geographical_region = dlc_tgp_grand_canal_3_region
				}
				root.top_liege = { completely_controls_region = dlc_tgp_grand_canal_3_region }
			}
			trigger_if = {
				limit = {
					geographical_region = dlc_tgp_grand_canal_4_region
				}
				root.top_liege = { completely_controls_region = dlc_tgp_grand_canal_4_region }
			}
		}
	}
	
	province_filter = geographical_region
	province_filter_target = dlc_tgp_grand_canal_region
	
	cost = {
		treasury_or_gold = {
			value = great_project_base_starting_cost
			multiply = 1.5
		}
	}

	construction_time = {
		value = great_project_base_construction_time
		multiply = common_great_project_construction_time_multiplier_value
	}

	contributor_cooldown = standard_contributor_cooldown_value

	allowed_contributor_filter = {
		owner = yes
		vassals = yes
		tributaries = yes
	}

	on_complete = {
		if = {
			limit = {
				NOT = { exists = scope:province }
			}
			custom_tooltip = grand_canals_effect_desc
		}
		scope:province ?= {
			switch = {
				trigger = geographical_region
				dlc_tgp_grand_canal_1_region = {
					every_county_in_region = {
						region = dlc_tgp_grand_canal_1_region
						add_county_modifier = tgp_grand_canal_modifier
					}
				}
				dlc_tgp_grand_canal_2_region = {
					every_county_in_region = {
						region = dlc_tgp_grand_canal_2_region
						add_county_modifier = tgp_grand_canal_modifier
					}
				}
				dlc_tgp_grand_canal_3_region = {
					every_county_in_region = {
						region = dlc_tgp_grand_canal_3_region
						add_county_modifier = tgp_grand_canal_modifier
					}
				}
				dlc_tgp_grand_canal_4_region = {
					every_county_in_region = {
						region = dlc_tgp_grand_canal_4_region
						add_county_modifier = tgp_grand_canal_modifier
					}
				}
			}
		}
		tgp_silk_road_canal_built_effect = yes
		scope:founder ?= {
			if = {
				limit = {
					tgp_is_any_minister = yes
					is_alive = yes # this is actually necessary, because they remain the scope character and accessible even after death
				}
				change_influence = minister_influence_gain_value
			}
		}
	}

	project_contributions = {
		materials = {
			contributor_is_valid = {
				OR = {
					custom_tooltip = {
						text = you_are_owner_of_the_project
						this = scope:owner
					}
					is_governor = yes
				}
			}


			cost = {
				treasury_or_gold = great_project_base_contribution_cost
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				if = {
					limit = {
						is_alive = yes
					}
					send_interface_toast = {
						type = event_toast_effect_good
						title = great_project_contribution_msg_t
						left_icon = root
						right_icon = scope:great_project.great_project_location.county
						
						if = {
							limit = {
								government_allows = merit
							}
							change_merit = {
								value = monumental_merit_gain
								if = {
									limit = {
										OR = {
											has_title = title:e_minister_of_personnel
											has_title = title:e_minister_of_works
										}
									}
									multiply = 2
								}
							}
						}
						else = {
							add_prestige = major_prestige_gain
						}
						if = {
							limit = {
								government_allows = administrative
							}
							change_influence = {
								value = monumental_influence_gain
								if = {
									limit = {
										OR = {
											has_title = title:e_minister_chancellor
											has_title = title:e_minister_censor
										}
									}
									multiply = 2
								}
							}
						}
						else = {
							add_prestige = major_prestige_gain
						}
						if = {
							limit = {
								has_trait = governor
							}
							increase_governance_effect = { VALUE = 15 }
						}
					}
				}
			}

			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
			
			ai_check_interval_by_tier = {
				barony = 0
				county = 18
				duchy = 12
				kingdom = 6
				empire = 3
				hegemony = 3
			}
		}

		logistics = {
			contributor_is_valid = {
				OR = {
					custom_tooltip = {
						text = you_are_owner_of_the_project
						this = scope:owner
					}
					is_governor = yes
				}
			}

			cost = {
				treasury_or_gold = great_project_base_contribution_cost
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				if = {
					limit = {
						is_alive = yes
					}
					send_interface_toast = {
						type = event_toast_effect_good
						title = great_project_contribution_msg_t
						left_icon = root
						right_icon = scope:great_project.great_project_location.county
						
						if = {
							limit = {
								government_allows = merit
							}
							change_merit = {
								value = monumental_merit_gain
								if = {
									limit = {
										OR = {
											has_title = title:e_minister_of_personnel
											has_title = title:e_minister_of_works
										}
									}
									multiply = 2
								}
							}
						}
						else = {
							add_prestige = major_prestige_gain
						}
						if = {
							limit = {
								government_allows = administrative
							}
							change_influence = {
								value = monumental_influence_gain
								if = {
									limit = {
										OR = {
											has_title = title:e_minister_chancellor
											has_title = title:e_minister_censor
										}
									}
									multiply = 2
								}
							}
						}
						else = {
							add_prestige = major_prestige_gain
						}
						if = {
							limit = {
								has_trait = logistician
							}
							add_trait_xp = {
								trait = logistician
								value = 15
							}
						}
						add_stewardship_lifestyle_xp = major_lifestyle_xp
					}
				}
			}
			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
		}
		personnel_construction = {
			contributor_is_valid = {
				OR = {
					custom_tooltip = {
						text = you_are_owner_of_the_project
						this = scope:owner
					}
					is_governor = yes
				}
			}

			cost = {
				treasury_or_gold = great_project_base_contribution_cost
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				if = {
					limit = {
						is_alive = yes
					}
					send_interface_toast = {
						type = event_toast_effect_good
						title = great_project_contribution_msg_t
						left_icon = root
						right_icon = scope:great_project.great_project_location.county
						
						if = {
							limit = {
								government_allows = merit
							}
							change_merit = {
								value = monumental_merit_gain
								if = {
									limit = {
										OR = {
											has_title = title:e_minister_chancellor
											has_title = title:e_minister_of_personnel
										}
									}
									multiply = 2
								}
							}
						}
						else = {
							add_prestige = major_prestige_gain
						}
						if = {
							limit = {
								has_trait = lifestyle_reveler
							}
							add_trait_xp = {
								trait = lifestyle_reveler
								value = 10
							}
						}
						add_diplomacy_lifestyle_xp = major_lifestyle_xp
					}
				}
			}

			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
			
			ai_check_interval_by_tier = {
				barony = 0
				county = 18
				duchy = 12
				kingdom = 6
				empire = 3
				hegemony = 3
			}
		}

		personnel_dig = {
			contributor_is_valid = {
				OR = {
					custom_tooltip = {
						text = you_are_owner_of_the_project
						this = scope:owner
					}
					is_governor = yes
				}
			}

			cost = {
				treasury_or_gold = great_project_base_contribution_cost
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				if = {
					limit = {
						is_alive = yes
					}
					send_interface_toast = {
						type = event_toast_effect_good
						title = great_project_contribution_msg_t
						left_icon = root
						right_icon = scope:great_project.great_project_location.county
						
						if = {
							limit = {
								government_allows = merit
							}
							change_merit = {
								value = monumental_merit_gain
								if = {
									limit = {
										OR = {
											has_title = title:e_minister_chancellor
											has_title = title:e_minister_of_personnel
										}
									}
									multiply = 2
								}
							}
						}
						else = {
							add_prestige = major_prestige_gain
						}
						if = {
							limit = {
								has_trait = lifestyle_reveler
							}
							add_trait_xp = {
								trait = lifestyle_reveler
								value = 10
							}
						}
						add_stewardship_lifestyle_xp = major_lifestyle_xp
					}
				}
			}

			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
			
			ai_check_interval_by_tier = {
				barony = 0
				county = 18
				duchy = 12
				kingdom = 6
				empire = 3
				hegemony = 3
			}
		}

		engineers = {
			contributor_is_valid = {
				OR = {
					custom_tooltip = {
						text = you_are_owner_of_the_project
						this = scope:owner
					}
					is_governor = yes
				}
			}

			cost = {
				treasury_or_gold = great_project_base_contribution_cost
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				if = {
					limit = {
						is_alive = yes
					}
					send_interface_toast = {
						type = event_toast_effect_good
						title = great_project_contribution_msg_t
						left_icon = root
						right_icon = scope:great_project.great_project_location.county
						
						if = {
							limit = {
								government_allows = merit
							}
							change_merit = {
								value = monumental_merit_gain
								if = {
									limit = {
										OR = {
											has_title = title:e_minister_of_personnel
											has_title = title:e_minister_of_works
										}
									}
									multiply = 2
								}
							}
						}
						else = {
							add_prestige = major_prestige_gain
						}
						if = {
							limit = {
								has_trait = military_engineer
							}
							add_trait_xp = {
								trait = military_engineer
								value = 15
							}
						}
						add_learning_lifestyle_xp = major_lifestyle_xp
					}
				}
			}

			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
			
			ai_check_interval_by_tier = {
				barony = 0
				county = 18
				duchy = 12
				kingdom = 6
				empire = 3
				hegemony = 3
			}
		}

		dredging_boats = {
			contributor_is_valid = {
				OR = {
					custom_tooltip = {
						text = you_are_owner_of_the_project
						this = scope:owner
					}
					is_governor = yes
				}
				any_sub_realm_county = {
					is_coastal_county = yes
				}
			}

			cost = {
				treasury_or_gold = great_project_base_contribution_cost
			}

			contributor_cooldown = individual_contribution_cooldown_value
			
			is_required = yes

			on_complete = {
				if = {
					limit = {
						is_alive = yes
					}
					send_interface_toast = {
						type = event_toast_effect_good
						title = great_project_contribution_msg_t
						left_icon = root
						right_icon = scope:great_project.great_project_location.county
						
						if = {
							limit = {
								government_allows = merit
							}
							change_merit = {
								value = monumental_merit_gain
								if = {
									limit = {
										OR = {
											has_title = title:e_minister_of_personnel
											has_title = title:e_minister_of_works
										}
									}
									multiply = 2
								}
							}
						}
						else = {
							add_prestige = major_prestige_gain
						}
						if = {
							limit = {
								has_trait = governor
							}
							increase_governance_effect = { VALUE = 15 }
						}
						if = {
							limit = {
								has_trait = forder
							}
							add_trait_xp = {
								trait = forder
								value = 15
							}
						}
					}
				}
			}

			on_contribution_funded = {
				great_project_notify_contribution = yes
				great_project_contribution_catalyst_effect = yes
			}
			
			ai_will_do = {
				value = chinese_great_projects_contribution_ai_will_do_base_value
			}
			
			ai_check_interval_by_tier = {
				barony = 0
				county = 18
				duchy = 12
				kingdom = 6
				empire = 3
				hegemony = 3
			}
		}
	}

	ai_target_quick_trigger = {
		adult = yes
		rank = empire
	}
	ai_check_interval_by_tier = {							
		barony = 0
		county = 0
		duchy = 0
		kingdom = 0
		empire = 6
		hegemony = 6
	}
	ai_will_do = {
		value = 500
		if = {
			limit = {
				is_at_war = yes
			}
			multiply = 0
		}
	}

	completion_sound_effect = @msg_completion_effect_generic
}
