######################################################
#	Expert AI mod - scripted law AI triggers
######################################################

EAI_PP_has_check_pp = {
	
	set_temp_variable = { total_pp = EAI_PP_stored_pp }
	add_to_temp_variable = { total_pp = political_power }
	NOT = { check_variable = { total_pp < _check_pp } }
}

EAI_PP_store_pp_prio = {

	OR = {
		AND = { EAI_PP_store_pp_strategies = yes }

		AND = {

			### Exceptions

				NOT = {

					AND = {
						tag = SPR
						is_historical_focus_on = yes
						has_civil_war = no
						date < 1937.1.1
					}

					AND = {
						date < 1938.1.1
						has_available_idea_with_traits = { idea = silent_workhorse limit = 1 }
						NOT = { has_idea_with_trait = silent_workhorse }
					}

					AND = {
						tag = JAP
						has_civil_war = no
						date < 1939.1.1
					}
					
					AND = {
						tag = BUL
						is_historical_focus_on = yes
						has_dlc = "Battle for the Bosporus"
						has_active_mission = BUL_ff_impending_coup_mission
						date < 1942.12.12
					}
				}

			### SOV strategies

				### Law cost reduction
				
				if = { limit = { has_focus_tree = soviet_focus has_completed_focus = SOV_the_centre has_country_flag = EAI_improved_worker_conditions_taken }

					OR = {
						has_completed_focus = SOV_secure_the_administration
						focus_progress = { focus = SOV_secure_the_administration progress > 0 }
					}
				}
				else = { always = yes }

				### SOV really needs to get these done

				if = {
					limit = {
						has_focus_tree = soviet_focus
						has_completed_focus = SOV_claims_in_baltic
						is_historical_focus_on = yes
						is_subject = no
						date > 1940.4.1
						date < 1941.1.1
						has_political_power < 100
					}

					NOT = {
						any_country =  {
							OR = { tag = EST tag = LAT tag = LIT }

							NOT = { has_war_with = ROOT }

							# SOV_basic_ultimatum_triggers
							country_exists = THIS
							NOT = { has_war_with = ROOT }
							NOT = { is_in_faction_with = ROOT } #CAN'T SEND ULTIMATUMS TO ALLIES OR SUBJECTS
							#OR = { #Can send Ultimatum to non-allies or puppets (but not to faction allies)
							#	NOT = { is_in_faction_with = ROOT }
							#	is_Subject_of = ROOT
							#}
							NOT = { has_country_flag = SOV_ultimatum_sent_flag }
						}
					}
				}

				###

			###
		}
	}
}

EAI_PP_store_pp_strategies = {

	OR = {

		# Store PP for attache
		AND = {
			OR = { tag = GER tag = ITA tag = ENG tag = FRA tag = SOV }
			NOT = { has_idea = EAI_attache_sent }
			date < 1937.1.1
		}

		AND = {
			tag = SOV 
			date < 1939.1.1
			has_war = no
		}

		# Get early eco upgrade if attache was sent
		AND = {
			OR = { tag = ENG tag = FRA } 
			has_idea = civilian_economy
			has_idea = EAI_attache_sent
		}
	}
}