############################################################################################################
#	Expert AI mod - scripted law AI effects
############################################################################################################

EAI_LAW_priority_decisions = {

	########################
	### Manpower
	########################

	# women_in_the_workforce
	if = {
		limit = {

			### Available trigger

			EAI_LAW_get_women_in_the_workforce = yes

			###

			set_temp_variable = { _check_pp = 100 }
			EAI_PP_has_check_pp = yes
		}

		if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: women_in_the_workforce" } 

		EAI_PP_return_stored = yes
		activate_decision = women_in_the_workforce
		EAI_PP_store = yes
	}

	########################
	### Stability
	########################

	# improved_worker_conditions
	if = {
		limit = {

			### Priority

			NOT = { 
				EAI_LAW_get_women_in_the_workforce = yes
				EAI_LAW_upgrade_economy_law = yes
				EAI_LAW_upgrade_manpower_law = yes
				EAI_LAW_upgrade_trade_law = yes
			}

			EAI_needs_stability = yes

			### Available trigger

			has_stability < 1.0
			if = {
				limit = {
					tag = SPR
				}
				NOT = {
					has_idea = SPR_political_violence
				}
			}

			NOT = { has_country_flag = EAI_improved_worker_conditions_taken }

			###

			set_temp_variable = { _check_pp = 100 }
			EAI_PP_has_check_pp = yes
		}

		if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: improved_worker_conditions" } 

		EAI_PP_return_stored = yes
		activate_decision = improved_worker_conditions
		EAI_PP_store = yes
	}

	########################
	### War support
	########################

	if = { limit = { EAI_needs_war_support = yes }
	
		# AI has a critical need for war support so return enough PP to allow it to take those decisions
		set_temp_variable = { _pp_amount = 100 }
		EAI_PP_give_pp_amount = yes
		if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: War support" }
	}

	########################
	### Strategies
	########################

	# SOV
	if = { limit = { tag = SOV }

		### Purge decisions

			# SOV_forge_production_reports
			if = {
				limit = {
					set_temp_variable = { _pp_cost = 25 }

					SOV_paranoia_is_medium_level = yes

					NOT = { has_country_flag = EAI_SOV_forge_production_reports_ACTIVE }
					
					set_temp_variable = { _check_pp = _pp_cost }
					EAI_PP_has_check_pp = yes

					### Available trigger

					has_country_flag = SOV_paranoia_system_active_flag
				}

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: SOV_forge_production_reports" } 

				EAI_PP_return_stored = yes
				activate_decision = SOV_forge_production_reports
				EAI_PP_store = yes
			}

			# SOV_inspection_in_the_navy
			if = {
				limit = {
					set_temp_variable = { _pp_cost = 50 }

					SOV_paranoia_is_medium_level = yes

					has_country_flag = EAI_SOV_forge_production_reports_ACTIVE
					NOT = { has_country_flag = EAI_SOV_inspection_in_the_navy_ACTIVE }
					
					set_temp_variable = { _check_pp = _pp_cost }
					EAI_PP_has_check_pp = yes

					### Available trigger

					has_country_flag = SOV_paranoia_system_active_flag
					OR = {
						any_navy_leader = {
							SOV_character_can_be_purged = yes
						}
						NOT = { has_idea = SOV_anti_soviet_military_thinking_banned_navy }
						NOT = { has_idea = SOV_shipyard_staff_purged }
					}
					SOV_is_stalinist = yes
				}

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: SOV_inspection_in_the_navy" } 

				EAI_PP_return_stored = yes
				activate_decision = SOV_inspection_in_the_navy
				EAI_PP_store = yes
			}

		###

			# SOV_nikolay_voznesensky
			if = {
				limit = {
					set_temp_variable = { _pp_cost = 150 }

					set_temp_variable = { _check_pp = _pp_cost }
					EAI_PP_has_check_pp = yes

					focus_progress = { focus = SOV_the_stalin_constitution progress > 0 }

					has_idea = war_economy

					### Available trigger

					has_available_idea_with_traits = { idea = captain_of_industry limit = 1 }
					NOT = { has_idea_with_trait = captain_of_industry }
				}

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: SOV_nikolay_voznesensky" } 

				add_ideas = SOV_nikolay_voznesensky
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_priority_decisions" }
			}

			# mikhail_kalinin
			if = {
				limit = {
					set_temp_variable = { _pp_cost = 150 }

					set_temp_variable = { _check_pp = _pp_cost }
					EAI_PP_has_check_pp = yes

					has_idea = war_economy
					has_idea = free_trade
					has_idea = SOV_nikolay_voznesensky

					### Available trigger

					has_available_idea_with_traits = { idea = popular_figurehead limit = 1 }
					NOT = { has_idea = mikhail_kalinin }
				}

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: mikhail_kalinin" } 

				add_ideas = mikhail_kalinin
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_priority_decisions" }
			}

			# SOV_gosproyektstroy_1
			if = {
				limit = {
					set_temp_variable = { _pp_cost = 100 }

					set_temp_variable = { _check_pp = _pp_cost }
					EAI_PP_has_check_pp = yes

					NOT = { has_country_flag = SOV_gosproyektstroy_1_taken }

					### Available trigger

					has_completed_focus = SOV_foreign_experts
					NOT = { has_idea = SOV_gosproyektstroy_1 }
					NOT = { has_country_flag = SOV_gosproyektstroy_level_2_flag }
				}

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: SOV_gosproyektstroy_1" } 

				add_ideas = SOV_gosproyektstroy_1
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_priority_decisions" }

				set_country_flag = SOV_gosproyektstroy_1_taken
			}

			# SOV_gosproyektstroy_bring_foreign_experts
			if = {
				limit = {
					set_temp_variable = { _pp_cost = SOV_gosproyektstroy_decision_cost }

					set_temp_variable = { _check_pp = _pp_cost }
					EAI_PP_has_check_pp = yes

					### Available trigger

					has_idea = SOV_gosproyektstroy_1

					NOT = { has_country_flag = SOV_gosproyektstroy_upgrade_in_progress_flag }
					USA = {
						has_opinion = {
							target = ROOT
							value > 29
						}
						SOV_is_valid_subject = yes
						NOT = { has_war_with = ROOT }
					}
				}

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: SOV_gosproyektstroy_bring_foreign_experts" } 

				set_temp_variable = { _pp_amount = _pp_cost }
				EAI_PP_give_pp_amount = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: SOV_gosproyektstroy_bring_foreign_experts" }
			}

			# SOV_gosproyektstroy_focus_civ
			if = {
				limit = {
					set_temp_variable = { _pp_cost = SOV_gosproyektstroy_decision_cost }

					set_temp_variable = { _check_pp = _pp_cost }
					EAI_PP_has_check_pp = yes

					### Available trigger

					has_idea = SOV_gosproyektstroy_2_usa
					NOT = { has_country_flag = SOV_gosproyektstroy_upgrade_in_progress_flag }
				}

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: SOV_gosproyektstroy_focus_civ" } 

				EAI_PP_return_stored = yes
				activate_decision = SOV_gosproyektstroy_focus_civ
				EAI_PP_store = yes
			}

			# SOV_claims_in_baltic
			if = {
				limit = { 
					date > 1939.10.1

					is_subject = no

					OR = {
						AND = {
							focus_progress = { focus = SOV_claims_in_baltic progress > 0 } 
							NOT = { has_completed_focus = SOV_claims_in_baltic }
						}
						AND = {
							has_completed_focus = SOV_claims_in_baltic

							add_to_temp_array = { SOV_claims_in_baltic_targets = EST.id }
							add_to_temp_array = { SOV_claims_in_baltic_targets = LAT.id }
							add_to_temp_array = { SOV_claims_in_baltic_targets = LIT.id }
							any_of_scopes = { array = SOV_claims_in_baltic_targets
								country_exists = THIS
								NOT = { has_war_with = ROOT }
								NOT = { is_in_faction_with = ROOT }
								NOT = { has_country_flag = SOV_ultimatum_sent_flag }
							}
						}
					}
				}

				# if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: SOV_claims_in_baltic" } 

				set_variable = { EAI_PP_needs_pp = 150 }

				if = {
					limit = {
						set_temp_variable = { _pp_cost = 75 }

						date > 1940.3.1

						has_completed_focus = SOV_claims_in_baltic

						set_temp_variable = { _check_pp = _pp_cost }
						EAI_PP_has_check_pp = yes
					}

					if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | EAI_LAW_priority_decisions: SOV_claims_in_baltic 2" } 

					set_temp_variable = { _pp_amount = _pp_cost }
					EAI_PP_give_pp_amount = yes
					if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: SOV_claims_in_baltic" }
				}
			}

		###
	}

	# JAP
	if = { limit = { tag = JAP }

		if = { 
			limit = { 
				is_historical_focus_on = yes
				date < 1937.1.1
				NOT = { has_global_flag = JAP_test_the_soviets }
			}
		
			set_temp_variable = { _pp_amount = 50 }
			EAI_PP_give_pp_amount = yes
			if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: JAP_test_the_soviets" }
		}
	}

	# GER
	if = { limit = { tag = GER }

		if = { 
			limit = { 
				is_historical_focus_on = yes
				date < 1940.1.1

				set_temp_variable = { _pp_cost = 150 }

				set_temp_variable = { _check_pp = _pp_cost }
				EAI_PP_has_check_pp = yes

				###

				if = { limit = { date < 1938.1.1 }
					has_idea = war_economy
				}

				NOT = {
					has_idea = GER_philipp_holzmann
					has_idea = GER_philipp_holzmann_improved
					has_idea = GER_philipp_holzmann_improved_2
					has_idea = GER_philipp_holzmann_improved_2_no_aat
				}
			}

			# if = {
			# 	limit = {
			# 		original_tag = GER
			# 		NOT = {
			# 			has_completed_focus = GER_employ_philipp_holzmann
			# 			has_completed_focus = GER_revitalize_the_nation
			# 		}
			# 	}
			
			# 	add_ideas = GER_philipp_holzmann
			# 	EAI_PP_pay_pp_cost = yes
			# }
			if = {
				limit = {
					original_tag = GER
					OR = {
						AND = {
							has_completed_focus = GER_employ_philipp_holzmann
							NOT = { has_completed_focus = GER_plenipotentiary_of_armaments }
						}
						has_completed_focus = GER_revitalize_the_nation
					}
				}
			
				add_ideas = GER_philipp_holzmann_improved
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_priority_decisions" }
			}
			if = {
				limit = {
					original_tag = GER
					has_dlc = "Arms Against Tyranny"
					has_completed_focus = GER_plenipotentiary_of_armaments
				}
			
				add_ideas = GER_philipp_holzmann_improved_2
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_priority_decisions" }
			}
			if = {
				limit = {
					original_tag = GER
					NOT = { has_dlc = "Arms Against Tyranny" }
					has_completed_focus = GER_plenipotentiary_of_armaments
				}
			
				add_ideas = GER_philipp_holzmann_improved_2_no_aat
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_priority_decisions" }
			}
		}
	}
}

###

EAI_LAW_upgrade = {

	EAI_LAW_upgrade_economy_law = yes

	if = { limit = { EAI_LAW_upgrade_special_prio = yes }

		EAI_LAW_upgrade_conscription_law = yes
		if = { limit = { NOT = { has_country_flag = EAI_trade_law_recently_changed } }

			EAI_LAW_upgrade_trade_law = yes
		}
	}
}

EAI_LAW_upgrade_economy_law = {
	
    if = { 
		limit = { 
			EAI_LAW_upgrade_economy_law = yes 

			OR = {
				AND = {
					has_war = yes

					NOT = { EAI_LAW_upgrade_manpower_law = yes }
				}
				AND = {
					has_war = no
				}
			}
		}

		set_temp_variable = { EAI_eco_law_cost = modifier@economy_cost_factor }
		add_to_temp_variable = { EAI_eco_law_cost = 1 }
		multiply_temp_variable = { EAI_eco_law_cost = 150 }

		if = { limit = { set_temp_variable = { _check_pp = EAI_eco_law_cost } EAI_PP_has_check_pp = yes }

			if = { limit = { EAI_LAW_get_low_economic_mobilisation = yes } 
            
				set_temp_variable = { _pp_cost = EAI_eco_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_economy_law" }
                add_ideas = low_economic_mobilisation

				### on_add

				if = {
					limit = {
						tag = USA
						has_completed_focus = USA_limited_intervention
						has_defensive_war = no
					}
					USA_congress_large_opposition = yes
				}

				###

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | ECONOMY LAW: low_economic_mobilisation (script)" } 
            }

			else_if = { limit = { EAI_LAW_get_partial_economic_mobilisation = yes } 
                
				set_temp_variable = { _pp_cost = EAI_eco_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_economy_law" }
                add_ideas = partial_economic_mobilisation

				### on_add

				if = {
					limit = {
						tag = USA
						has_completed_focus = USA_limited_intervention
						has_defensive_war = no
					}
					USA_congress_large_opposition = yes
				}

				###

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | ECONOMY LAW: partial_economic_mobilisation (script)" } 
            }

			else_if = { limit = { EAI_LAW_get_war_economy = yes } 

				set_temp_variable = { _pp_cost = EAI_eco_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_economy_law" }
                add_ideas = war_economy

				### on_add

				if = {
					limit = {
						tag = USA
						has_completed_focus = USA_limited_intervention
						has_defensive_war = no
					}
					USA_congress_large_opposition = yes
				}

				###

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | ECONOMY LAW: war_economy (script)" } 
            }

			else_if = { limit = { EAI_LAW_get_tot_economic_mobilisation = yes } 
            
				set_temp_variable = { _pp_cost = EAI_eco_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_economy_law" }
                add_ideas = tot_economic_mobilisation

				### on_add

				if = {
					limit = {
						tag = USA
						has_completed_focus = USA_limited_intervention
						has_defensive_war = no
					}
					USA_congress_large_opposition = yes
				}

				###

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | ECONOMY LAW: tot_economic_mobilisation (script)" } 
            }
		}
	}
}

EAI_LAW_upgrade_conscription_law = {

    if = { 
		limit = { 
			EAI_LAW_upgrade_manpower_law = yes 

			OR = {
                AND = {
			    	has_war = yes
			    }
			    AND = {
			    	has_war = no

			    	NOT = {
			    		EAI_LAW_upgrade_economy_law = yes

			    		EAI_LAW_upgrade_trade_law = yes
			    	}
			    }
            }
		}

		set_temp_variable = { EAI_man_law_cost = modifier@mobilization_laws_cost_factor }
		add_to_temp_variable = { EAI_man_law_cost = 1 }
		multiply_temp_variable = { EAI_man_law_cost = 150 }

		if = { limit = { set_temp_variable = { _check_pp = EAI_man_law_cost } EAI_PP_has_check_pp = yes }

			if = { limit = { EAI_LAW_get_volunteer_only = yes } 
            
				set_temp_variable = { _pp_cost = EAI_man_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_conscription_law" }
                add_ideas = volunteer_only

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSCRIPTION LAW: volunteer_only (script) current mp = [?manpower_k|0]k current army = [?deployed_army_manpower_k]k" } 
            }

			else_if = { limit = { EAI_LAW_get_limited_conscription = yes } 
                
				set_temp_variable = { _pp_cost = EAI_man_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_conscription_law" }
                add_ideas = limited_conscription

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSCRIPTION LAW: limited_conscription (script) current mp = [?manpower_k|0]k current army = [?deployed_army_manpower_k]k" } 
            }

			else_if = { limit = { EAI_LAW_get_extensive_conscription = yes } 
           
		   		set_temp_variable = { _pp_cost = EAI_man_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_conscription_law" }
                add_ideas = extensive_conscription

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSCRIPTION LAW: extensive_conscription (script) current mp = [?manpower_k|0]k current army = [?deployed_army_manpower_k]k" } 
            }

			else_if = { limit = { EAI_LAW_get_service_by_requirement = yes } 
            
				set_temp_variable = { _pp_cost = EAI_man_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_conscription_law" }
                add_ideas = service_by_requirement

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSCRIPTION LAW: service_by_requirement (script) current mp = [?manpower_k|0]k current army = [?deployed_army_manpower_k]k" } 
            }

            else_if = { limit = { EAI_LAW_get_all_adults_serve = yes } 
            
				set_temp_variable = { _pp_cost = EAI_man_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_conscription_law" }
                add_ideas = all_adults_serve

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSCRIPTION LAW: all_adults_serve (script) current mp = [?manpower_k|0]k current army = [?deployed_army_manpower_k]k" } 
            }

            else_if = { limit = { EAI_LAW_get_scraping_the_barrel = yes } 
            
				set_temp_variable = { _pp_cost = EAI_man_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_conscription_law" }
                add_ideas = scraping_the_barrel

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | CONSCRIPTION LAW: scraping_the_barrel (script) current mp = [?manpower_k|0]k current army = [?deployed_army_manpower_k]k" } 
            }
		}
	}
}

EAI_LAW_upgrade_trade_law = {
	
    if = { 
		limit = { 
			EAI_LAW_upgrade_trade_law = yes 

			OR = {
				AND = {
					has_war = yes
	
					NOT = { EAI_LAW_upgrade_manpower_law = yes }
				}
				AND = {
					has_war = no
				}
			}
		}

		set_temp_variable = { EAI_tra_law_cost = modifier@trade_laws_cost_factor }
		add_to_temp_variable = { EAI_tra_law_cost = 1 }
		multiply_temp_variable = { EAI_tra_law_cost = 150 }

		if = { limit = { set_temp_variable = { _check_pp = EAI_tra_law_cost } EAI_PP_has_check_pp = yes }

			if = { limit = { EAI_LAW_get_free_trade = yes } 
            
				set_temp_variable = { _pp_cost = EAI_tra_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_trade_law" }
                add_ideas = free_trade

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | TRADE LAW: free_trade (need: [?EAI_average_resource_need]) (script)" } 
            }

			else_if = { limit = { EAI_LAW_get_export_focus = yes } 
                
				set_temp_variable = { _pp_cost = EAI_tra_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_trade_law" }
                add_ideas = export_focus

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | TRADE LAW: export_focus (need: [?EAI_average_resource_need]) (script)" } 
            }

			else_if = { limit = { EAI_LAW_get_limited_exports = yes } 
           
		   		set_temp_variable = { _pp_cost = EAI_tra_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_trade_law" }
                add_ideas = limited_exports

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | TRADE LAW: limited_exports (need: [?EAI_average_resource_need]) (script)" } 
            }

			else_if = { limit = { EAI_LAW_get_closed_economy = yes } 
           
		   		set_temp_variable = { _pp_cost = EAI_tra_law_cost }
				EAI_PP_pay_pp_cost = yes
				if = { limit = { has_country_flag = EAI_pp_logging } log = "SOURCE: EAI_LAW_upgrade_trade_law" }
                add_ideas = closed_economy

				if = { limit = { has_country_flag = EAI_law_logging } log = "[GetYear] [GetMonth] | AI | [Root.GetName] | TRADE LAW: closed_economy (need: [?EAI_average_resource_need]) (script)" } 
            }

			set_country_flag = { flag = EAI_trade_law_recently_changed value = 1 days = 90 } # limits the AI from changing trade law due to minor fluctuations
		}
	}
}

###

EAI_LAW_manpower_shortage_days = {

	if = { 
		limit = { 
			EAI_reserve_manpower_less_than_5p = yes 
			NOT = { conscription_ratio < 1.0 } 
		}
	
		add_to_variable = { EAI_LAW_manpower_shortage_days = 1 }
	}
	else = { set_variable = { EAI_LAW_manpower_shortage_days = 0 } }
}

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

EAI_LAW_print_law_needs = {

	log = "===================== EAI_print_law_needs"

	if = { limit = { EAI_LAW_wants_civilian_economy = yes } log = "EAI_LAW_wants_civilian_economy = yes" } else = { log = "EAI_LAW_wants_civilian_economy = no" }
	if = { limit = { EAI_LAW_available_civilian_economy = yes } log = "EAI_LAW_available_civilian_economy = yes" } else = { log = "EAI_LAW_available_civilian_economy = no" }
	if = { limit = { has_idea = civilian_economy } log = "has_civilian_economy = yes" } else = { log = "has_civilian_economy = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_low_economic_mobilisation = yes } log = "EAI_LAW_wants_low_economic_mobilisation = yes" } else = { log = "EAI_LAW_wants_low_economic_mobilisation = no" }
	if = { limit = { EAI_LAW_available_low_economic_mobilisation = yes } log = "EAI_LAW_available_low_economic_mobilisation = yes" } else = { log = "EAI_LAW_available_low_economic_mobilisation = no" }
	if = { limit = { has_idea = low_economic_mobilisation } log = "has_low_economic_mobilisation = yes" } else = { log = "has_low_economic_mobilisation = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_partial_economic_mobilisation = yes } log = "EAI_LAW_wants_partial_economic_mobilisation = yes" } else = { log = "EAI_LAW_wants_partial_economic_mobilisation = no" }
	if = { limit = { EAI_LAW_available_partial_economic_mobilisation = yes } log = "EAI_LAW_available_partial_economic_mobilisation = yes" } else = { log = "EAI_LAW_available_partial_economic_mobilisation = no" }
	if = { limit = { has_idea = partial_economic_mobilisation } log = "has_partial_economic_mobilisation = yes" } else = { log = "has_partial_economic_mobilisation = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_war_economy = yes } log = "EAI_LAW_wants_war_economy = yes" } else = { log = "EAI_LAW_wants_war_economy = no" }
	if = { limit = { EAI_LAW_available_war_economy = yes } log = "EAI_LAW_available_war_economy = yes" } else = { log = "EAI_LAW_available_war_economy = no" }
	if = { limit = { has_idea = war_economy } log = "has_war_economy = yes" } else = { log = "has_war_economy = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_tot_economic_mobilisation = yes } log = "EAI_LAW_wants_tot_economic_mobilisation = yes" } else = { log = "EAI_LAW_wants_tot_economic_mobilisation = no" }
	if = { limit = { EAI_LAW_available_tot_economic_mobilisation = yes } log = "EAI_LAW_available_tot_economic_mobilisation = yes" } else = { log = "EAI_LAW_available_tot_economic_mobilisation = no" }
	if = { limit = { has_idea = tot_economic_mobilisation } log = "has_tot_economic_mobilisation = yes" } else = { log = "has_tot_economic_mobilisation = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_volunteer_only = yes } log = "EAI_LAW_wants_volunteer_only = yes" } else = { log = "EAI_LAW_wants_volunteer_only = no" }
	if = { limit = { EAI_LAW_available_volunteer_only = yes } log = "EAI_LAW_available_volunteer_only = yes" } else = { log = "EAI_LAW_available_volunteer_only = no" }
	if = { limit = { has_idea = volunteer_only } log = "has_volunteer_only = yes" } else = { log = "has_volunteer_only = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_limited_conscription = yes } log = "EAI_LAW_wants_limited_conscription = yes" } else = { log = "EAI_LAW_wants_limited_conscription = no" }
	if = { limit = { EAI_LAW_available_limited_conscription = yes } log = "EAI_LAW_available_limited_conscription = yes" } else = { log = "EAI_LAW_available_limited_conscription = no" }
	if = { limit = { has_idea = limited_conscription } log = "has_limited_conscription = yes" } else = { log = "has_limited_conscription = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_extensive_conscription = yes } log = "EAI_LAW_wants_extensive_conscription = yes" } else = { log = "EAI_LAW_wants_extensive_conscription = no" }
	if = { limit = { EAI_LAW_available_extensive_conscription = yes } log = "EAI_LAW_available_extensive_conscription = yes" } else = { log = "EAI_LAW_available_extensive_conscription = no" }
	if = { limit = { has_idea = extensive_conscription } log = "has_extensive_conscription = yes" } else = { log = "has_extensive_conscription = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_service_by_requirement = yes } log = "EAI_LAW_wants_service_by_requirement = yes" } else = { log = "EAI_LAW_wants_service_by_requirement = no" }
	if = { limit = { EAI_LAW_available_service_by_requirement = yes } log = "EAI_LAW_available_service_by_requirement = yes" } else = { log = "EAI_LAW_available_service_by_requirement = no" }
	if = { limit = { has_idea = service_by_requirement } log = "has_service_by_requirement = yes" } else = { log = "has_service_by_requirement = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_all_adults_serve = yes } log = "EAI_LAW_wants_all_adults_serve = yes" } else = { log = "EAI_LAW_wants_all_adults_serve = no" }
	if = { limit = { EAI_LAW_available_all_adults_serve = yes } log = "EAI_LAW_available_all_adults_serve = yes" } else = { log = "EAI_LAW_available_all_adults_serve = no" }
	if = { limit = { has_idea = all_adults_serve } log = "has_all_adults_serve = yes" } else = { log = "has_all_adults_serve = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_scraping_the_barrel = yes } log = "EAI_LAW_wants_scraping_the_barrel = yes" } else = { log = "EAI_LAW_wants_scraping_the_barrel = no" }
	if = { limit = { EAI_LAW_available_scraping_the_barrel = yes } log = "EAI_LAW_available_scraping_the_barrel = yes" } else = { log = "EAI_LAW_available_scraping_the_barrel = no" }
	if = { limit = { has_idea = scraping_the_barrel } log = "has_scraping_the_barrel = yes" } else = { log = "has_scraping_the_barrel = no" }
	log = "==="
	if = { limit = { EAI_LAW_wants_women_in_the_workforce = yes } log = "EAI_LAW_wants_women_in_the_workforce = yes" } else = { log = "EAI_LAW_wants_women_in_the_workforce = no" }
	if = { limit = { EAI_LAW_available_women_in_the_workforce = yes } log = "EAI_LAW_available_women_in_the_workforce = yes" } else = { log = "EAI_LAW_available_women_in_the_workforce = no" }
	if = { limit = { has_country_flag = EAI_women_in_the_workforce_taken } log = "has_women_in_the_workforce = yes" } else = { log = "has_women_in_the_workforce = no" }
	log = "==="
}