# The Great Work (ap_great_work).
# Started by apb_greatwork.1, one day after the perk is taken. Targets the country.
# One-way bar from 0 to 100 in four stages. There is no fail state: nothing
# lowers progress, and the worst that happens is that work stops for a while.
# A wing is chosen each time stage 2, 3 or 4 is entered (so at the end of
# stages 1-3). Reaching 100 fires apb_greatwork.30, which rewards the capital
# and ends the situation.

apb_situation_great_work = {
	picture = GFX_evt_metropolis
	situation_log_category = developments

	potential = {
		has_ascension_perk = ap_great_work
	}

	complete_icon = GFX_situation_outcome_positive
	complete_icon_frame = GFX_situation_outcome_frame_green

	# Same ending pattern as apb_situation_core_overdrive: the ending only fires a
	# situation_event; that event applies the reward (immediate) and ends the
	# situation (after). The flag makes sure the ending is handed over only once.
	on_progress_complete = {
		custom_tooltip = apb_gw_complete_tt
		hidden_effect = {
			if = {
				limit = { NOT = { has_situation_flag = apb_gw_ending } }
				set_situation_flag = apb_gw_ending
				situation_event = { id = apb_greatwork.30 }
			}
		}
	}

	stages = {
		apb_gw_stage_foundations = {
			end = 25
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_blue
			custom_tooltip = apb_gw_stage_wing_tt
		}
		apb_gw_stage_frame = {
			end = 50
			icon = GFX_situation_stage_2
			icon_background = GFX_situation_stage_frame_blue
			on_first_enter = {
				owner = { apb_gw_offer_wing = yes }
			}
			custom_tooltip = apb_gw_stage_wing_tt
		}
		apb_gw_stage_halls = {
			end = 75
			icon = GFX_situation_stage_3
			icon_background = GFX_situation_stage_frame_blue
			on_first_enter = {
				owner = { apb_gw_offer_wing = yes }
			}
			custom_tooltip = apb_gw_stage_wing_tt
		}
		apb_gw_stage_crown = {
			end = 100
			icon = GFX_situation_stage_4
			icon_background = GFX_situation_stage_frame_green
			on_first_enter = {
				owner = { apb_gw_offer_wing = yes }
			}
			custom_tooltip = apb_gw_complete_tt
		}
	}

	monthly_progress = {
		base = 0
		modifier = {
			desc = apb_gw_steady_progress
			current_situation_approach = apb_gw_steady
			add = 0.3
		}
		modifier = {
			desc = apb_gw_treasury_progress
			current_situation_approach = apb_gw_treasury
			add = 1
		}
		modifier = {
			desc = apb_gw_faithful_progress
			current_situation_approach = apb_gw_faithful
			add = 0.6
		}
		# Must stay last: a strike or sabotage stops all work for a while.
		modifier = {
			desc = apb_gw_halted_progress
			owner = { has_country_flag = apb_gw_work_halted }
			factor = 0
		}
	}

	# Steady hands: free and slow. The default, and the fallback when a paid
	# approach can no longer be afforded (its allow fails).
	approach = {
		name = apb_gw_steady
		icon = GFX_situation_approach_balance_sheet
		icon_background = GFX_situation_approach_bg_green
		default = yes
		on_select = {
			custom_tooltip = apb_gw_steady_tt
			hidden_effect = {
				owner = { apb_gw_faithful_off = yes }
			}
		}
		ai_weight = {
			base = 2
		}
	}

	# Open the treasury: fast, paid in minerals and alloys.
	approach = {
		name = apb_gw_treasury
		icon = GFX_situation_approach_minerals
		icon_background = GFX_situation_approach_bg_yellow
		allow = {
			owner = {
				has_resource = { type = minerals amount >= 120 }
				has_resource = { type = alloys amount >= 40 }
			}
		}
		on_select = {
			custom_tooltip = apb_gw_treasury_tt
			hidden_effect = {
				owner = { apb_gw_faithful_off = yes }
			}
		}
		resources = {
			category = situations
			upkeep = {
				minerals = 60
				alloys = 20
			}
		}
		ai_weight = {
			base = 0
			modifier = {
				add = 5
				owner = {
					resource_income_compare = {
						resource = minerals
						value >= 250
					}
					resource_income_compare = {
						resource = alloys
						value >= 40
					}
				}
			}
		}
	}

	# Call the faithful: medium pace, paid in unity, +5 stability on the capital.
	# The stability is a planet modifier on the capital, kept in step by on_select
	# here and by the monthly event apb_greatwork.2 (the situation targets the
	# country, so target_modifier cannot be used).
	approach = {
		name = apb_gw_faithful
		icon = GFX_situation_approach_unity
		icon_background = GFX_situation_approach_bg_yellow
		allow = {
			owner = {
				has_resource = { type = unity amount >= 80 }
			}
		}
		on_select = {
			custom_tooltip = apb_gw_faithful_tt
			hidden_effect = {
				owner = { apb_gw_faithful_on = yes }
			}
		}
		resources = {
			category = situations
			upkeep = {
				unity = 40
			}
		}
		ai_weight = {
			base = 0
		}
	}

	on_monthly = {
		events = {
			apb_greatwork.2
		}
		random_events = {
			150 = 0
			4 = apb_greatwork.20
			4 = apb_greatwork.21
			4 = apb_greatwork.22
			4 = apb_greatwork.23
		}
	}
}
