﻿# group = this is the law_group a law belongs to
# icon = graphical icon shown in-game
# modifier = {} modifier on country for having adopted this law

law_slavery_banned = {
	group = lawgroup_slavery

	progressiveness = 100

	icon = "gfx/interface/icons/law_icons/slavery_banned.dds"

	on_activate = {
		if = {
			limit = { has_variable = slavery_recently_enacted }
			remove_variable = slavery_recently_enacted
		}

		set_variable = {
			name = slavery_recently_abolished
			value = yes
			days = 1825
		}
		every_scope_state = {
			limit = {
				any_scope_pop = {
					is_pop_type = slaves
				}
			}
			set_variable = {
				name = former_slave_state
				value = yes
				days = 1825
			}
		}
		custom_tooltip = {
			text = liberate_slaves_tt
			liberate_slaves = yes
		}
	}

	ai_enact_weight_modifier = {
		value = 0
		# Brazilian AI is less likely to pursue slavery banned if there are no abolitionists in power.
		if = {
			limit = {
				c:BRZ ?= this
				has_law = law_type:law_slave_trade
				NOR = {
					any_interest_group = {
						is_in_government = yes
						leader = {
							has_ideology = ideology:ideology_abolitionist
						}
					}
					ruler ?= { has_ideology = ideology:ideology_abolitionist }
					heir ?= { has_ideology = ideology:ideology_abolitionist }
				}
				scope:law.type = law_type:law_slavery_banned
			}
			add = -100
		}
		#Petitions
		if = {
			limit = { ai_has_enact_weight_modifier_journal_entries = yes }
			add = 750
		}

		# This was funny while it lasted.
		if = {
			limit = {
				has_law = law_type:law_council_republic
			}
			add = 750
		}

		# Strong tendency towards abolitionism in the late game
		if = {
			limit = {
				has_technology_researched = human_rights
				NOT = { has_strategy = ai_strategy_reactionary_agenda }
				OR = {
					NOT = { has_strategy = ai_strategy_conservative_agenda }
					any_political_movement = {
						law_enactment_stance = {
							law = law_type:law_slavery_banned
							value > neutral
						}
						political_movement_support >= 0.10
					}
				}
			}
			add = 1000
		}
	}

	ai_impose_chance = {
		value = 0

		if = {
			limit = {
				has_law = law_type:law_slavery_banned
				NOT = { has_strategy = ai_strategy_reactionary_agenda }
				has_technology_researched = civilizing_mission
			}

			add = base_impose_law_weight
			if = {
				limit = {
					OR = {
						has_strategy = ai_strategy_progressive_agenda
						has_strategy = ai_strategy_egalitarian_agenda
					}
				}
				multiply = 5
			}
		}

		if = {
			limit = {
				scope:target_country = {
					c:BIC ?= this
					OR = {
						has_journal_entry = je_british_dictate_plantations
						has_journal_entry = je_british_dictate_military
						has_journal_entry = je_british_dictate_universities
					}
				}
			}
			multiply = 0
		}
	}
}

law_debt_slavery = {
	group = lawgroup_slavery

	progressiveness = 0

	icon = "gfx/interface/icons/law_icons/debt_slavery.dds"

	disallowing_laws = {
		law_multicultural
		law_affirmative_action
	}

	on_activate = {
		set_variable = {
			name = slavery_recently_enacted
			value = yes
			days = 1825
		}
		every_scope_state = {
			limit = {
				NOT = {
					any_scope_pop = {
						is_pop_type = slaves
					}
				}
			}
			set_variable = {
				name = former_free_state
				value = yes
				days = 1825
			}
		}
		ig:ig_landowners ?= {
			if = {
				limit = {
					NOT = { has_ideology = ideology:ideology_pro_slavery }
				}
				add_ideology = ideology_pro_slavery
			}
		}
	}

	modifier = {
		interest_group_ig_landowners_pol_str_mult = 0.25
	}

	# AI should never enact debt slavery
	ai_will_do = {
		always = no
	}

	ai_enact_weight_modifier = { #Petitions
		value = 0

		if = {
			limit = { ai_has_enact_weight_modifier_journal_entries = yes }
			add = 750
		}
	}
}

law_slave_trade = {
	group = lawgroup_slavery

	progressiveness = 0

	icon = "gfx/interface/icons/law_icons/slave_trade.dds"

	disallowing_laws = {
		law_cultural_exclusion
		law_multicultural
		law_affirmative_action
	}

	on_activate = {
		set_variable = {
			name = slavery_recently_enacted
			value = yes
			days = 1825
		}
		every_scope_state = {
			limit = {
				NOT = {
					any_scope_pop = {
						is_pop_type = slaves
					}
				}
			}
			set_variable = {
				name = former_free_state
				value = yes
				days = 1825
			}
		}
		if = {
			limit = { has_variable = slavery_recently_abolished }
			custom_tooltip = {
				text = enslave_discriminated_farm_workers_tt
				every_scope_state = {
					limit = { has_variable = former_slave_state }
					enslave_discriminated_farm_workers = yes
				}
			}
			remove_variable = slavery_recently_abolished
			every_scope_state = {
				remove_variable = former_slave_state
			}
		}

		ig:ig_landowners ?= {
			if = {
				limit = {
					NOT = { has_ideology = ideology:ideology_pro_slavery }
				}
				add_ideology = ideology_pro_slavery
			}
		}
	}

	modifier = {
		interest_group_ig_landowners_pol_str_mult = 0.5
	}

	ai_will_do = {
		exists = ruler
		ruler = {
			has_ideology = ideology:ideology_slaver
		}
	}

	ai_enact_weight_modifier = { #Petitions
		value = 0

		if = {
			limit = { ai_has_enact_weight_modifier_journal_entries = yes }
			add = 750
		}
	}
}

law_legacy_slavery = {
	group = lawgroup_slavery

	progressiveness = 50

	icon = "gfx/interface/icons/law_icons/legacy_slavery.dds"

	# no need to add disallowing_laws here since it can only be enacted from Slave Trade

	unlocking_laws = {
		law_slave_trade
	}

	on_activate = {
		if = {
			limit = { has_variable = slavery_recently_abolished }
			custom_tooltip = {
				text = enslave_discriminated_farm_workers_tt
				every_scope_state = {
					limit = { has_variable = former_slave_state }
					enslave_discriminated_farm_workers = yes
				}
			}
			remove_variable = slavery_recently_abolished
			every_scope_state = {
				remove_variable = former_slave_state
			}
		}

		ig:ig_landowners ?= {
			if = {
				limit = {
					NOT = { has_ideology = ideology:ideology_pro_slavery }
				}
				add_ideology = ideology_pro_slavery
			}
		}
	}

	modifier = {
		interest_group_ig_landowners_pol_str_mult = 0.25
	}

	ai_enact_weight_modifier = {
		value = 0
		#Brazilian AI is more likely to pursue legacy slavery if there are no abolitionists in power.
		if = {
			limit = {
				c:BRZ ?= this
				has_law = law_type:law_slave_trade
				NOR = {
					any_interest_group = {
						is_in_government = yes
						leader = {
							has_ideology = ideology:ideology_abolitionist
						}
					}
					ruler = { has_ideology = ideology:ideology_abolitionist }
					heir = { has_ideology = ideology:ideology_abolitionist }
				}
				scope:law = law_type:law_legacy_slavery
			}
			add = 50
		}
		# Brazilian AI is more likely to pursue legacy slavery if the Aberdeen Act is being enforced
		if = {
			limit = {
				c:BRZ ?= this
				has_law = law_type:law_slave_trade
				has_modifier = aberdeen_act_enforced_brz
				scope:law = law_type:law_legacy_slavery
			}
			add = 50
		}
		#Petitions
		if = {
			limit = { ai_has_enact_weight_modifier_journal_entries = yes }
			add = 750
		}
	}
}
