﻿@dlm_landmark_project_icon = "gfx/interface/icons/point_of_interest_types/poi_special_buildings_wonder.dds"
@dlm_landmark_project_illustration = "gfx/interface/illustrations/great_projects/dlm_landmark_project.dds"

dlm_landmark_construction = {
	icon = {
		reference = @dlm_landmark_project_icon
	}

	illustration = {
		reference = @dlm_landmark_project_illustration
	}

	name = {
		desc = great_project_type_dlm_landmark_construction
	}

	is_shown = {
		dlm_has_commissionable_landmark_county = yes
		NOT = { is_planning_great_project = dlm_landmark_construction }
	}

	province_filter = capital

	can_start_planning = {
		custom_tooltip = {
			text = dlm_landmark_project_use_major_decision_tt
			always = no
		}
	}

	can_cancel = {
		always = yes
	}

	is_location_valid = {
		always = yes
	}

	owner = province_owner

	is_valid = {
		scope:province = {
			custom_tooltip = {
				text = dlm_landmark_project_location_valid_tt
				has_variable = dlm_group
				has_variable = dlm_type
			}
		}
	}

	cost = { }

	construction_time = dlm_landmark_construction_days

	on_plan_build = {
		hidden_effect = {
			if = {
				limit = {
					scope:province = {
						NOT = { has_variable = dlm_group }
						NOT = { has_variable = dlm_type }
					}
				}
				save_scope_as = dlm_active_landmark_project
				scope:province = {
					county = {
						save_scope_as = dlm_target_county
						capital_barony = {
							save_scope_as = dlm_target_barony
						}
					}
				}
				scope:founder = {
					trigger_event = dlm_ducal_landmarks.000201
				}
			}
			every_contribution = {
				limit = {
					contribution_id = bootstrap_foundations
					contribution_is_funded = no
				}
				save_scope_as = dlm_bootstrap_contribution
			}
			if = {
				limit = { exists = scope:dlm_bootstrap_contribution }
				scope:founder = {
					fund_great_project_contribution = {
						contribution = scope:dlm_bootstrap_contribution
						check_can_contribute = no
					}
				}
			}
		}
	}

	on_start_build = {
		hidden_effect = {
			scope:province = {
				dlm_create_special_landmark_effect = { BUILDING = dlm_landmark_construction_early }
			}
			scope:founder ?= {
				scope:province.county = {
					save_scope_as = dlm_target_county
				}
				trigger_event = {
					id = dlm_ducal_landmarks.0031
					days = dlm_landmark_midpoint_patronage_days
				}
			}
		}
	}

	on_complete = {
		hidden_effect = {
			save_scope_as = dlm_active_landmark_project
			scope:founder ?= {
				remove_character_modifier = dlm_landmark_workforce_committed
				scope:province.county = {
					save_scope_as = dlm_target_county
				}
				dlm_complete_landmark_construction_effect = yes
				trigger_event = dlm_ducal_landmarks.0019
			}
		}
	}

	on_cancel = {
		hidden_effect = {
			scope:province = {
				if = {
					limit = { has_building = dlm_landmark_construction_early_01 }
					remove_building = dlm_landmark_construction_early_01
				}
				remove_variable = dlm_quality_contribution_bonus
				dlm_clear_landmark_state_effect = yes
			}
			scope:founder ?= {
				remove_character_modifier = dlm_landmark_workforce_committed
			}
		}
	}

	allowed_contributor_filter = {
		owner = yes
	}

	project_contributions = {
		bootstrap_foundations = {
			is_shown = {
				always = yes
			}

			show_in_planning_phase = yes

			contributor_is_valid = {
				scope:great_project.great_project_location = {
					NOT = { has_variable = dlm_optional_contribution_cutoff_reached }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}

			cost = { }

			contributor_cooldown = 0

			ai_will_do = {
				value = 0
			}
		}

		minor_patron_investment = {
			is_shown = {
				always = yes
			}

			show_in_planning_phase = yes

			is_required = no

			contributor_is_valid = {
				scope:great_project.great_project_location = {
					NOT = { has_variable = dlm_optional_contribution_cutoff_reached }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}

			cost = {
				treasury_or_gold = 100
			}

			contributor_cooldown = 0

			on_contribution_funded = {
				scope:great_project.great_project_location = {
					change_variable = { name = dlm_quality_contribution_bonus add = 25 }
				}
			}

			ai_will_do = {
				value = 1000
			}
		}

		major_patron_investment = {
			is_shown = {
				always = yes
			}

			show_in_planning_phase = yes

			is_required = no

			contributor_is_valid = {
				scope:great_project.great_project_location = {
					NOT = { has_variable = dlm_optional_contribution_cutoff_reached }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}

			cost = {
				treasury_or_gold = 250
			}

			contributor_cooldown = 0

			on_contribution_funded = {
				scope:great_project.great_project_location = {
					change_variable = { name = dlm_quality_contribution_bonus add = 80 }
				}
			}

			ai_will_do = {
				value = 1000
			}
		}

		mobilized_workforce = {
			is_shown = {
				always = yes
			}

			show_in_planning_phase = yes

			is_required = no

			contributor_is_valid = {
				scope:great_project.great_project_location = {
					NOT = { has_variable = dlm_optional_contribution_cutoff_reached }
				}
			}

			allowed_contributor_filter = {
				owner = yes
			}

			cost = { }

			contributor_cooldown = 0

			on_contribution_funded = {
				scope:great_project.great_project_location = {
					change_variable = { name = dlm_quality_contribution_bonus add = 25 }
				}
				add_character_modifier = {
					modifier = dlm_landmark_workforce_committed
				}
			}

			ai_will_do = {
				value = 1000
			}
		}
	}
}
