# Monthly Technological Progress of pre-FTL civilizations.
@early_progress_rate	= 1		# 160 years to tech up.
@mid_progress_rate		= 2		# 80 years to tech up.
@late_progress_rate		= 4		# 40 years to tech up.
@low_awareness			= 0.5
@partial_awareness		= 1.0
@high_awareness			= 1.5
@full_awareness			= 2

# AI empires don't have pulse events, so we're using non-player facing situations to give them a monthly on-action

pre_ftl_tech_progress_situation = { # This situation's name-key is used in pre-FTL tech level UI code, do not change without code support!
	picture = GFX_evt_acquire_asset
	complete_icon_frame = GFX_situation_outcome_frame_blue
	complete_icon = GFX_situation_outcome_meh

	on_progress_complete = {
		# Tech up and start the situation again!
		custom_tooltip = situation_unknown_outcome_approach
		hidden_effect = { destroy_situation = this }
		owner = {
			country_event = { id = preftl.0 }
		}
	}

	on_abort = {
		#Effects when Situation is cancelled via abort_trigger trigger
		hidden_effect = { destroy_situation = this }
		owner = {
			country_event = { id = preftl.0 }
		} #Allows situation to be aborted to 'force' technological progress
	}

	abort_trigger = {
		owner = {
			is_primitive = no
		}
	}

	on_fail = {
		log_error = "pre_ftl_tech_progress_situation situation failed, this is not meant to happen"
		# Restart the situation
		# if we don't do this, the game crashes to desktop when you try to open the diplomacy screen
		custom_tooltip = situation_unknown_outcome_approach
		hidden_effect = { destroy_situation = this }
		owner = {
			start_situation = {
				type = pre_ftl_tech_progress_situation
			}
		}
	}

	on_monthly = {
		random_events = {
			95 = 0
			5 = preftl.50	# Random event gatekeeper
		}
		events = {
			preftl.5		# Technological progress & setback gatekeeper
			preftl.20		# Societal Enlightenment gatekeeper
			awareness.200	# Awareness Decay
		}
	}

	stages = {
		high_level = {
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_blue
			end = 1920
		}
	}

	monthly_progress = {
		# Total: 1920
		base = 0
		modifier = {
			add = @early_progress_rate
			desc = early_age
			owner = {
				OR = {
					has_country_flag = stone_age
					has_country_flag = bronze_age
					has_country_flag = iron_age
					has_country_flag = late_medieval_age
				}
			}
		}
		modifier = {
			add = @mid_progress_rate
			desc = mid_age
			owner = {
				OR = {
					has_country_flag = renaissance_age
					has_country_flag = steam_age
					has_country_flag = industrial_age
					has_country_flag = machine_age
				}
			}
		}
		modifier = {
			add = @late_progress_rate
			desc = late_age
			owner = {
				OR = {
					has_country_flag = atomic_age
					has_country_flag = early_space_age
				}
			}
		}
		modifier = {
			add = @low_awareness
			desc = awareness_low
			owner = {
				current_awareness_level = low
			}
		}
		modifier = {
			add = @partial_awareness
			desc = awareness_partial
			owner = {
				current_awareness_level = medium
			}
		}
		modifier = {
			add = @high_awareness
			desc = awareness_high
			owner = {
				current_awareness_level = high
			}
		}
		modifier = {
			add = @full_awareness
			desc = awareness_full
			owner = {
				current_awareness_level = full
			}
		}
		modifier = {
			mult = 1.5
			desc = acquired_tech
			owner = {
				has_country_flag = acquired_tech
			}
		}
		modifier = {
			mult = 2
			desc = technological_breakthrough
			has_situation_flag = technological_breakthrough
		}
		modifier = {
			mult = 1.25
			desc = technological_breakthrough
			has_situation_flag = belives_the_great_gestalt
		}
		modifier = {
			mult = 1.25
			desc = technological_breakthrough
			has_situation_flag = successful_asteroid_interception
		}
		modifier = {
			mult = 0.25
			desc = technological_setback
			has_situation_flag = technological_setback
		}
		modifier = {
			mult = 0.50
			desc = technological_setback
			mid_game_years_passed <= 0
		}
		modifier = {
			mult = 0
			desc = tech_frozen
			owner = { has_country_flag = tech_frozen }
		}
		modifier = {
			mult = 0
			desc = tech_frozen
			owner = {
				capital_scope = {
					is_planet_class = pc_habitat
				}
			}
		}
		modifier = {
			mult = 3
			desc = open_technological_enlightenment
			owner = {
				has_country_flag = open_technological_enlightenment_pact
				capital_scope = {
					has_observation_outpost = yes
					observation_outpost_owner = {
						if = {
							limit = {
								is_galactic_community_formed = yes
								is_galactic_community_member = yes
							}
							NOT = { is_active_resolution = resolution_pre_ftl_stances_equal_standing }
						}
						else = {
							always = yes
						}
					}
				}
			}
		}
		modifier = {
			mult = 4.5
			desc = open_technological_enlightenment
			owner = {
				has_country_flag = open_technological_enlightenment_pact
				capital_scope = {
					has_observation_outpost = yes
					observation_outpost_owner = {
						is_galactic_community_formed = yes
						is_galactic_community_member = yes
						is_active_resolution = resolution_pre_ftl_stances_equal_standing
					}
				}
			}
		}
		modifier = {
			mult = 1.5
			desc = good_trade
			owner = {
				capital_scope = {
					has_modifier = fruitful_coop_planet_mod
				}
			}
		}
		modifier = {
			mult = 1.25
			desc = payback_student
			owner = {
				has_country_flag = open_technological_enlightenment_pact
				capital_scope = {
					has_observation_outpost = yes
					observation_outpost_owner = {
						has_modifier = payback_student
					}
				}
			}
		}
	}
	approach = {
		name = approach_revolt_do_nothing
		icon = GFX_situation_approach_this_is_fine
		icon_background = GFX_situation_approach_bg_yellow
		default = yes
		on_select = {
			custom_tooltip = deficit_approach_do_nothing_tooltip
		}
	}
}

##################################
# Mercenary Enclave Reward Patron
##################################
# Scale profit with enclave size.
# Scope it on the enclave then when resolving fire an event aiming at the patron

@dividend_base_rate = 1 # 20 years to completion with no other modifiers.
@dividend_hire_rate = 1 # Adds an extra month of progress if the fleet is hired.
@dividend_non_patron_hire_rate = 2 # Adds two extra months of progress if the fleet is hired by a non-patron.
@dividend_rank_rate = 0.4 # Adds 0.4 months of progress at per Rank.
@dividend_resolution_1_rate = 0.5 # Adds an extra half a month of progress with every GalCom resolution.
@dividend_resolution_2_rate = 1.0
@dividend_resolution_3_rate = 1.5
@dividend_resolution_4_rate = 2.0
@dividend_resolution_5_rate = 2.5
@dividend_financial_trouble_rate = -5 # Subtracts five months of progress during financial troubles.
@dividend_lord_of_war_rate = 2.5 # Adds an extra two and a half months of progress if the Patron has Lord of War.

# Values above are set so that a Rank 5 Merc Enclave will pay out every 2 years assuming GalCom Resolution up to Level 3 are passed, their patron has the Lord of War AP and their fleet is constantly hired by a non-patron.

mercenary_dividends = {
	picture = GFX_evt_acquire_asset
	complete_icon_frame = GFX_situation_outcome_frame_blue
	complete_icon = GFX_situation_outcome_meh
	on_progress_complete = {
		#Figure out Patron and give resources
		custom_tooltip = situation_unknown_outcome_approach #not really necessary except to silence the error log
		owner = { country_event = { id = enclave.275 } }
	}
	on_fail = {
		log_error = "mercenary_dividends situation failed, this is not meant to happen"
		destroy_situation = this
	}
	on_monthly = {
		random_events = {
			5 = 0
			# Cut, potentially revisit later
			#1 = Mercenaries poaching military
			#1 = Joint research project
			#1 = Joint officer drills
			#1 = Competing Mercenaries
			#1 = Small scale reward
			#1 = A once per game rare event chain?
		}
	}
	stages = {
		high_level = {
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_blue
			end = 240
		}
	}
	monthly_progress = {
		#total: 240 Can use scripted variable above to fine tune progress
		base = @dividend_base_rate
		modifier = {
			add = @dividend_hire_rate
			desc = fleet_hired
			any_playable_country = {
				any_controlled_fleet = {
					owner = { is_same_value = root.owner }
				}
			}
		}

		modifier = {
			add = @dividend_non_patron_hire_rate
			desc = fleet_hired
			exists = owner
			owner = {
				AND = {
					any_owned_fleet = {
						NOT = {
							controller = { is_same_value = root.owner }
						}
					}
					any_owned_fleet = {
						is_ship_size = enclave_mercenary_station
						solar_system = {
							exists = owner
							space_owner = {
								NOT = {
									any_controlled_fleet = {
										owner = { is_same_value = root.owner }
									}
								}
							}
						}
					}
				}
			}
		}

		modifier = {
			add = @dividend_rank_rate
			desc = enclave_rank
			owner = { has_modifier = mercenary_fleet_size_upgrade_1 }
		}
		modifier = {
			add = @dividend_rank_rate
			desc = enclave_rank
			owner = { has_modifier = mercenary_fleet_size_upgrade_2 }
		}
		modifier = {
			add = @dividend_rank_rate
			desc = enclave_rank
			owner = { has_modifier = mercenary_fleet_size_upgrade_3 }
		}
		modifier = {
			add = @dividend_rank_rate
			desc = enclave_rank
			owner = { has_modifier = mercenary_fleet_size_upgrade_4 }
		}
		modifier = {
			add = @dividend_rank_rate
			desc = enclave_rank
			owner = { has_modifier = mercenary_fleet_size_upgrade_5 }
		}
		modifier = {
			add = @dividend_financial_trouble_rate
			desc = enclave_rank
			owner = { has_modifier = merc_financial_troubles }
			situation_progress > 3 #We don't want total situation progress to ever go below 0
		}

		modifier = {
			add = @dividend_resolution_1_rate
			desc = RESOLUTIONS
			is_active_resolution = resolution_defenseprivatization_defense_contracts
		}
		modifier = {
			add = @dividend_resolution_2_rate
			desc = RESOLUTIONS
			is_active_resolution = resolution_defenseprivatization_private_support_troops
		}
		modifier = {
			add = @dividend_resolution_3_rate
			desc = RESOLUTIONS
			is_active_resolution = resolution_defenseprivatization_condottieri
		}
		modifier = {
			add = @dividend_resolution_4_rate
			desc = RESOLUTIONS
			is_active_resolution = resolution_defenseprivatization_security_business
		}
		modifier = {
			add = @dividend_resolution_5_rate
			desc = RESOLUTIONS
			is_active_resolution = resolution_defenseprivatization_corporate_warlords
		}

		modifier = {
			add = @dividend_lord_of_war_rate
			desc = lord_of_war
			owner = {
				any_owned_fleet = {
					is_ship_size = enclave_mercenary_station
					solar_system = {
						exists = space_owner
						space_owner = {
							has_ascension_perk = ap_lord_of_war
						}
					}
				}
			}
		}
	}
	approach = { #Actually, the player will never see this Situations. Just adding one in in case one is required
		name = approach_revolt_do_nothing
		icon = GFX_situation_approach_this_is_fine
		icon_background = GFX_situation_approach_bg_yellow
		default = yes
		on_select = {
			custom_tooltip = deficit_approach_do_nothing_tooltip
		}
	}
}

mindwardens_dividends = {
	picture = GFX_evt_acquire_asset
	complete_icon_frame = GFX_situation_outcome_frame_blue
	complete_icon = GFX_situation_outcome_meh
	on_progress_complete = {
		# Figure out Patron and give resources
		custom_tooltip = situation_unknown_outcome_approach # Silence the error log
		owner = { country_event = { id = shroud.6840 } }
	}
	on_fail = {
		log_error = "mindwardens_dividends situation failed, this is not meant to happen."
		destroy_situation = this
	}
	stages = {
		high_level = {
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_blue
			end = 240
		}
	}
	monthly_progress = {
		base = @dividend_base_rate

		modifier = {
			add = @dividend_hire_rate
			desc = fleet_hired
			any_playable_country = {
				any_controlled_fleet = {
					owner = { is_same_value = root.owner }
				}
			}
		}
		modifier = {
			add = @dividend_non_patron_hire_rate
			desc = fleet_hired
			exists = owner
			any_playable_country = {
				any_controlled_fleet = {
					owner = { is_same_value = root.owner }
				}
				root.owner = {
					NOT = { has_country_flag = created_by@prev }
				}
			}
		}

		modifier = {
			add = @dividend_rank_rate
			desc = enclave_rank
			owner = { has_country_flag = mindwardens_upgrade_1 }
		}
		modifier = {
			add = @dividend_rank_rate
			desc = enclave_rank
			owner = { has_country_flag = mindwardens_upgrade_2 }
		}
		modifier = {
			add = @dividend_rank_rate
			desc = enclave_rank
			owner = { has_country_flag = mindwardens_upgrade_3 }
		}
		modifier = {
			add = @dividend_rank_rate
			desc = enclave_rank
			owner = { has_country_flag = mindwardens_upgrade_4 }
		}
		modifier = {
			add = @dividend_rank_rate
			desc = enclave_rank
			owner = { has_country_flag = mindwardens_upgrade_5 }
		}

		modifier = {
			add = @dividend_non_patron_hire_rate
			desc = shroud.4205.c
			owner = { has_country_flag = aura_intel_bought }
		}
		modifier = {
			add = @dividend_hire_rate
			desc = shroud.4205.b
			owner = {
				OR = {
					has_country_flag = zro_bought_patron
					has_country_flag = zro_bought
				}
			}
		}
		modifier = {
			add = @dividend_non_patron_hire_rate
			desc = shroud.4205.b
			owner = { has_country_flag = zro_bought }
		}
		modifier = {
			add = @dividend_hire_rate
			desc = shroud.4205.d
			owner = {
				OR = {
					has_country_flag = raid_target_asked_patron
					has_country_flag = raid_target_asked
				}
			}
		}
		modifier = {
			add = @dividend_non_patron_hire_rate
			desc = shroud.4205.d
			owner = { has_country_flag = raid_target_asked }
		}
		modifier = {
			add = @dividend_hire_rate
			desc = shroud.4205.e
			owner = {
				OR = {
					has_country_flag = police_recruited_patron
					has_country_flag = police_recruited
				}
			}
		}
		modifier = {
			add = @dividend_non_patron_hire_rate
			desc = shroud.4205.e
			owner = { has_country_flag = police_recruited }
		}
		modifier = {
			add = @dividend_hire_rate
			desc = shroud.4205.ef
			owner = {
				OR = {
					has_country_flag = logistics_assistance_patron
					has_country_flag = logistics_assistance
				}
			}
		}
		modifier = {
			add = @dividend_non_patron_hire_rate
			desc = shroud.4205.ef
			owner = { has_country_flag = logistics_assistance }
		}
		modifier = {
			add = @dividend_hire_rate
			desc = shroud.4205.f
			owner = {
				OR = {
					has_country_flag = army_recruited_patron
					has_country_flag = army_recruited
				}
			}
		}
		modifier = {
			add = @dividend_non_patron_hire_rate
			desc = shroud.4205.f
			owner = { has_country_flag = army_recruited }
		}
		modifier = {
			add = @dividend_hire_rate
			desc = shroud.4205.g
			owner = {
				OR = {
					has_country_flag = commander_given_patron
					has_country_flag = commander_given
				}
			}
		}
		modifier = {
			add = @dividend_non_patron_hire_rate
			desc = shroud.4205.g
			owner = { has_country_flag = commander_given }
		}
		modifier = {
			add = @dividend_hire_rate
			desc = shroud.4205.h
			owner = {
				OR = {
					has_country_flag = reckoning_intel_given_patron
					has_country_flag = reckoning_intel_given
				}
			}
		}
		modifier = {
			add = @dividend_non_patron_hire_rate
			desc = shroud.4205.h
			owner = { has_country_flag = reckoning_intel_given }
		}
	}
}

##################################
# Fallen Empires
##################################

fallen_empires_situation = {
	picture = GFX_evt_fallen_empire
	complete_icon_frame = GFX_situation_outcome_frame_blue
	complete_icon = GFX_situation_outcome_meh
	on_progress_complete = {
	}
	on_fail = {
		log_error = "fallen_empires_situation situation failed, this is not meant to happen"
		destroy_situation = this
	}
	on_monthly = {
		random_events = {
			50 = fallen_empires.1 # Fallen Empire gets some fleet back (previously: MTTH 1 month)
			50 = fallen_empires.3 # Fallen Empire sends a warning (previously: MTTH 1 month)
			15 = fallen_empires.10 # Fallen Empire establishes communications (previously: MTTH 3 month)
			50 = fallen_empires.11 # Fallen Empire gets a construction ship if it's lost all construction ships (previously: MTTH 1 month)
		}
	}
	stages = {
		high_level = {
			icon = GFX_situation_stage_1
			icon_background = GFX_situation_stage_frame_blue
			end = 100
		}
	}
	monthly_progress = {
		base = 0
	}
	approach = { # The player will never see this Situation. Just adding one in in case one is required
		name = approach_revolt_do_nothing
		icon = GFX_situation_approach_this_is_fine
		icon_background = GFX_situation_approach_bg_yellow
		default = yes
		on_select = {
			custom_tooltip = deficit_approach_do_nothing_tooltip
		}
	}

	abort_trigger = {
		OR = {
			NOT = { exists = root.owner }
			root.owner = {
				NOR = {
					is_country_type = fallen_empire
					is_country_type = awakened_fallen_empire
				}
			}
		}
	}
}
