#category = short_term medium_term or long_term
# ROOT is faction leader, FROM is faction member who opens UI and views goals, completed/cancel/complete_effect do not have FROM scopes


######################################################################

###  ##   ##  ### ###  ##  #  #      ## ###  ###  ##  ### ### ###  ##  
#   #  # #  #  #   #  #  # ## #     #   #  # #   #  #  #  #    #  #  # 
##  #### #     #   #  #  # # ##      #  ###  ##  #     #  ##   #  #    
#   #  # #  #  #   #  #  # #  #       # #    #   #  #  #  #    #  #  # 
#   #  #  ##   #  ###  ##  #  #     ##  #    ###  ##  ### #   ###  ##  

######################################################################



faction_goal_unlock_research = {
	name = faction_goal_unlock_research_name
	description = faction_goal_unlock_research_desc
	category = short_term
	group = FOCUS_FILTER_INTERNAL_AFFAIRS
	available = {
		FROM = { num_faction_members > 0 }
	}
	visible = {
		FROM = { has_faction_research_unlocked = no }
	}
	select_effect = {
		set_temp_variable = { total_techs = 0 }
		every_collection_element = {
			input = {
				input = game:scope
				operators =  {
					faction_members
				}
			}
			add_to_temp_variable = { total_techs = num_researched_technologies }
		}
		
		multiply_temp_variable = {
			var = total_techs
			value = 1.20
		}
		scope:faction = {
			set_variable = { unlock_military_techs_researched_target = total_techs }
		}
	}
	completed = {
		scope:faction = {
			hidden_trigger = {
				tooltip_evaluation = eval
				set_temp_variable = { unlock_military_techs_researched_compare = 0 }			
				all_collection_elements = {
					collection = {
						input = game:scope
						operators =  { faction_members }
					}
					add_to_temp_variable = { unlock_military_techs_researched_compare = num_researched_technologies }
				}
				set_temp_variable = { unlock_military_techs_researched_compare_temp_target = unlock_military_techs_researched_compare }
				multiply_temp_variable = { unlock_military_techs_researched_compare_temp_target = 1.20 }
			}
			if = {
				limit = {
					has_variable = unlock_military_techs_researched_target
				}
				check_variable = {
					var = unlock_military_techs_researched_compare
					value = unlock_military_techs_researched_target
					compare = greater_than
					tooltip = "GOAL_T_TRIGGER_A"
				}
			}
			else = {
				check_variable = {
					var = unlock_military_techs_researched_compare
					value = unlock_military_techs_researched_compare_temp_target
					compare = greater_than
					tooltip = "GOAL_T_TRIGGER_A"
				}
			}
		}
	}
	complete_effect = {
		set_faction_research_unlocked = yes
		add_faction_initiative = 1
	}
	ai_will_do = {
		base = 1000 # They should always do this if they can
	}
}

faction_goal_unlock_military = {
	name = faction_goal_unlock_military_name
	description = faction_goal_unlock_military_desc
	category = short_term
	group = FOCUS_FILTER_INTERNAL_AFFAIRS
	available = {
		FROM = { num_faction_members > 0 }
	}
	visible = {
		FROM = { has_faction_military_unlocked = no }
	}
	select_effect = {
		set_temp_variable = { total_divs = 0 }
		every_collection_element = {
			input = {
				input = game:scope
				operators =  {
					faction_members
				}
			}
			add_to_temp_variable = { total_divs = num_armies }
		}
		
		multiply_temp_variable = {
			var = total_divs
			value = 1.20
		}
		scope:faction = {
			set_variable = { unlock_target = total_divs }
		}
	}
	completed = {
		scope:faction = {
			hidden_trigger = {
				tooltip_evaluation = eval
				set_temp_variable = { unlock_compare = 0 }			
				all_collection_elements = {
					collection = {
						input = game:scope
						operators =  { faction_members }
					}
					add_to_temp_variable = { unlock_compare = num_armies }
					set_temp_variable = { unlock_military_techs_researched_compare_temp_target = unlock_compare }
					multiply_temp_variable = { unlock_military_techs_researched_compare_temp_target = 1.20 }
				}
			}
			if = {
				limit = {
					has_variable = unlock_target
				}
				check_variable = {
					var = unlock_compare
					value = unlock_target
					compare = greater_than
					tooltip = "GOAL_T_TRIGGER_B"
				}
			}
			else = {
				check_variable = {
					var = unlock_compare
					value = unlock_military_techs_researched_compare_temp_target
					compare = greater_than
					tooltip = "GOAL_T_TRIGGER_B"
				}
			}
		}
	}
	complete_effect = {
		set_faction_military_unlocked = yes
		add_faction_initiative = 1
	}
	ai_will_do = {
		base = 1000 # They should always do this if they can
	}
}


 ###  ##  ###   ##  #  # 
   # #  # #  # #  # ## # 
   # #### ###  #### # ## 
#  # #  # #    #  # #  # 
 ##  #  # #    #  # #  # 


faction_goal_coastal_security = {
	name = coastal_security_goal_name
	description = coastal_security_goal_desc
	category = short_term
	group = FOCUS_FILTER_NAVY_XP
	allowed = {
	}
	visible = {
		FROM = {
			original_tag = JAP
		}
	}
	completed = {
		has_naval_control = 90
		has_naval_control = 79
		has_naval_control = 77
		has_naval_control = 76
		has_naval_control = 75
		has_naval_control = 73
	}
	complete_effect = {
		add_faction_initiative = 1
		add_faction_power_projection = 500
		every_collection_element = {
			input = {
				input = game:scope
				operators =  { 
					faction_members 
				}	
				name = ALL_FACTION_MEMBERS
			}
			navy_experience = 50
		}
	}
	ai_will_do = {
		base = 1
		modifier = {
			add = 4 # Mid game prio
			date > 1940.1.1
		}
	}
}



##########################################################

 ##  ### #  # ### ###  ###  ##       ##   ##   ##  #    ## 
#    #   ## # #   #  #  #  #  #     #    #  # #  # #   #   
# ## ##  # ## ##  ###   #  #        # ## #  # #### #    #  
#  # #   #  # #   #  #  #  #  #     #  # #  # #  # #     # 
 ##  ### #  # ### #  # ###  ##       ##   ##  #  # ### ##  

##########################################################

faction_goal_spy_master = {
	name = spy_master_goal_name
	description = spy_master_goal_desc
	group = FOCUS_FILTER_POLITICAL_CHARACTER
	category = short_term
	allowed = {
		has_dlc = "La Resistance"
	}
	visible = {
		FROM = {
			is_spymaster = no
			any_allied_country = {
				is_spymaster = no
			}
		}
	}
	completed = {
		OR = {
			is_spymaster = yes
			any_allied_country = {
				is_spymaster = yes
			}
		}
	}
	complete_effect = {
		add_faction_power_projection = 50
		custom_effect_tooltip = generic_skip_one_line_tt
		custom_effect_tooltip = THE_SPY_MASTER
		add_faction_initiative = 1
		custom_effect_tooltip = generic_skip_one_line_tt
		every_faction_member = { 
			limit = {
				has_intelligence_agency = no
			}
			create_intelligence_agency = yes
		}
		every_faction_member = { 
			limit = {
				has_intelligence_agency = yes
				NOT = { has_done_agency_upgrade  = upgrade_form_department }
			}
			upgrade_intelligence_agency = upgrade_form_department
		}
		every_faction_member = {
			limit = {
				has_intelligence_agency = yes
				has_done_agency_upgrade  = upgrade_form_department
				NOT = { has_done_agency_upgrade = upgrade_crypto_strength }
			}
			upgrade_intelligence_agency = upgrade_crypto_strength
		}
		every_faction_member = { 
			limit = {
				has_intelligence_agency = yes
				has_done_agency_upgrade = upgrade_crypto_strength
				has_tech = mechanical_computing
				NOT = { has_done_agency_upgrade = upgrade_crypto_strength_2 }
			}
			add_faction_initiative = 1
			upgrade_intelligence_agency = upgrade_crypto_strength_2
		}
		every_faction_member = { 
			limit = {
				has_intelligence_agency = yes
				NOT = { agency_upgrade_number > 30 }
				OR = {
					has_done_agency_upgrade = upgrade_crypto_strength_2
					NOT = { has_tech = mechanical_computing }
				}
			}
			add_faction_initiative = 1
			gain_random_agency_upgrade = yes
		}
		every_faction_member = { # Fallback in case someone completed everything
			visible_when_empty = yes
			limit = {
				has_intelligence_agency = yes
				agency_upgrade_number > 30
			}
			add_faction_initiative = 1
			add_political_power = 100
		}
	}
	ai_will_do = {
		base = 1
		modifier = {  
			add = 2
			has_intelligence_agency = yes
		}
	}
}



faction_goal_ensure_military_r_d = {
	name = ensure_military_r_d_goal_name
	description = ensure_military_r_d_goal_desc
	category = short_term
	group = FOCUS_FILTER_RESEARCH
	visible = {
		OR = {
			collection_size = {
				input = {
					input = game:all_states
					operators = {
						limit = {
							is_controlled_by_ROOT_or_ally = yes 
							land_facility > 0
						}
					}
					name = COLLECTION_FACTION_LAND_FACILITY
				}
				value < 1
			}
			collection_size = {
				input = {
					input = game:all_states
					operators = {
						limit = {
							is_controlled_by_ROOT_or_ally = yes 
							naval_facility > 0
						}
					}
					name = COLLECTION_FACTION_NAVAL_FACILITY
				}
				value < 1
			}
			collection_size = {
				input = {
					input = game:all_states
					operators = {
						limit = {
							is_controlled_by_ROOT_or_ally = yes 
							air_facility > 0
						}
					}
					name = COLLECTION_FACTION_AIR_FACILITY
				}
				value < 1
			}
		}
	}
	completed = {
		collection_size = {
			input = {
				input = game:all_states
				operators = {
					limit = {
						is_controlled_by_ROOT_or_ally = yes 
						land_facility > 0
					}
				}
				name = COLLECTION_FACTION_LAND_FACILITY
			}
			value > 0
		}
		collection_size = {
			input = {
				input = game:all_states
				operators = {
					limit = {
						is_controlled_by_ROOT_or_ally = yes 
						naval_facility > 0
					}
				}
				name = COLLECTION_FACTION_NAVAL_FACILITY
			}
			value > 0
		}
		collection_size = {
			input = {
				input = game:all_states
				operators = {
					limit = {
						is_controlled_by_ROOT_or_ally = yes 
						air_facility > 0
					}
				}
				name = COLLECTION_FACTION_AIR_FACILITY
			}
			value > 0
		}
	}
	complete_effect = {
		add_faction_power_projection = 100
		custom_effect_tooltip = generic_skip_one_line_tt
		custom_effect_tooltip = ALL_FACTION_MEMBERS
		every_collection_element = {
			input = {
				input = game:all_states
				operators = {
					limit = {
						is_controlled_by_ROOT_or_ally = yes
						OR = {
							air_facility > 0
							land_facility > 0
							naval_facility > 0
						}
					}
				}
				name = OWNS_LISTED_STATE
			}
			custom_effect_tooltip = OWNS_LISTED_STATE
			OWNER = { add_faction_influence_ratio = 0.05 }
		}
		every_faction_member = {
			if = {
				limit = {
					any_scientist = {
						has_scientist_level = {
							level > 0
							specialization = specialization_land
						}
						is_active_scientist = yes
					}
				}
				every_scientist = {
					visible_when_empty = yes
					limit = {
						has_scientist_level = {
							level > 0
							specialization = specialization_land
						}
						is_active_scientist = yes
					}
					add_scientist_xp = {
						experience = constant:sp_scientist_xp_gain.very_high
						specialization = specialization_land
					}
				}
			}
			if = {
				limit = {
					any_scientist = {
						has_scientist_level = {
							level > 0
							specialization = specialization_naval
						}
						is_active_scientist = yes
					}
				}
				every_scientist = {
					visible_when_empty = yes
					limit = {
						has_scientist_level = {
							level > 0
							specialization = specialization_naval
						}
						is_active_scientist = yes
					}
					add_scientist_xp = {
						experience = constant:sp_scientist_xp_gain.very_high
						specialization = specialization_naval
					}
				}
			}
			if = {
				limit = {
					any_scientist = {
						has_scientist_level = {
							level > 0
							specialization = specialization_air
						}
						is_active_scientist = yes
					}
				}
				every_scientist = {
					visible_when_empty = yes
					limit = {
						has_scientist_level = {
							level > 0
							specialization = specialization_air
						}
						is_active_scientist = yes
					}
					add_scientist_xp = {
						experience = constant:sp_scientist_xp_gain.very_high
						specialization = specialization_air
					}
				}
			}
		}
	}
	ai_will_do = {
		base = 1
	}
}


### Industry

faction_goal_military_infrastructure = {
	name = military_infrastructure_goal_name
	description = military_infrastructure_goal_desc
	category = short_term
	group = FOCUS_FILTER_CONSOLIDATION
	visible = {
		collection_size = {
			input = {
				input = game:all_states
				operators = {
					limit = {
						is_core_of = controller
						is_controlled_by_ROOT_or_ally = yes 
						any_neighbor_state = {
							controller = {
								NOT = { is_in_faction_with = ROOT }
							}
						}
						infrastructure < 4
					}
				}
				name = COLLECTION_FACTION_BORDER_STATES_FULL_INFRASTRUCTURE
			}
			value > 0
		}
	}
	completed = {
		collection_size = {
			input = {
				input = game:all_states
				operators = {
					limit = {
						is_controlled_by_ROOT_or_ally = yes 
						any_neighbor_state = {
							controller = {
								NOT = { is_in_faction_with = ROOT }
							}
						}
						infrastructure < 4
					}
				}
				name = COLLECTION_FACTION_BORDER_STATES_FULL_INFRASTRUCTURE
			}
			value < 10
		}
	}
	complete_effect = {
		add_faction_power_projection = 100
		custom_effect_tooltip = generic_skip_one_line_tt
		custom_effect_tooltip = ALL_FACTION_MEMBERS
		every_faction_member = {
			army_experience = 50
			navy_experience = 50
			air_experience = 50
		}
	}
	ai_will_do = {
		base = 0
		modifier = {  
			add = 1
			has_war = no
		}
	}
}

faction_goal_a_great_fortress = {
	name = a_great_fortress_goal_name
	description = a_great_fortress_goal_desc
	category = short_term
	group = FOCUS_FILTER_CONSOLIDATION
	visible = {
	}
	available = {
		collection_size = {
			input = {
				input = collection:faction_owned_core_states
				operators = {
					limit = {
						NOT = { is_fully_controlled_by = OWNER }
					}
				}
				name = FACTION_CORE_STATES_NOT_FULLY_CONTROLLED
			}
			value < 1
		}
	}
	completed = {
		OR = {
			ROOT = {
				has_tech = coastal_fort_tech_2
				has_tech = land_fort_tech_2
			}
			any_allied_country = {
				has_tech = coastal_fort_tech_2
				has_tech = land_fort_tech_2
			}
			count_in_collection = {
				collection = {
					input = game:scope
					operators = { faction_members }
					name = FACTION_NAME
				}
				buildings = { bunker coastal_bunker}
				size > 29
			}
		}
	}
	complete_effect = {
		add_faction_power_projection = 100
		custom_effect_tooltip = generic_skip_one_line_tt
		custom_effect_tooltip = ALL_FACTION_MEMBERS
		every_faction_member = {
			limit = {
				NOT = { has_idea = deterrence }
			}
			add_timed_idea = {
				idea = deterrence
				days = 360
			}
		}
	}
	ai_will_do = {
		base = 0
		modifier = {
			add = 1
			has_tech = basic_fortification_tech
		}
	}
}
