#When adding effects directly in on_actions always consider if it would be best to do so through a scripted effect. on_actions with a lot of script in them are harder to get an overview of.

# ROOT = province, FROM = country
on_diplomatic_annex = {
	FROM = {
		update_goods_subjects_province = { GOODS = copper }
		update_goods_subjects_province = { GOODS = tin }
		update_goods_subjects_province = { GOODS = iron }
		update_goods_subjects_province = { GOODS = zinc }
		update_goods_subjects_province = { GOODS = lead }
		update_goods_subjects_province = { GOODS = glass }
		update_goods_subjects_province = { GOODS = tobacco }
		update_goods_subjects_province = { GOODS = cocoa }
	}
}

on_trade_good_changed = {
	on_trade_good_changed_government_effect_TGE = yes
	
	if = {
		limit = { 
			ROOT = { 
				AND = {
					has_province_modifier = copper_mine
					has_province_modifier = copper_mine_small
					has_province_modifier = tin_mine
					has_province_modifier = tin_mine_small
					has_province_modifier = zinc_mine
					has_province_modifier = zinc_mine_small
					has_province_modifier = iron_mine
					has_province_modifier = iron_mine_small
					has_province_modifier = lead_mine
					has_province_modifier = lead_mine_small
				}
			}
		}
		remove_province_modifier = copper_mine
		remove_province_modifier = copper_mine_small
		remove_province_modifier = tin_mine
		remove_province_modifier = tin_mine_small
		remove_province_modifier = zinc_mine
		remove_province_modifier = zinc_mine_small
		remove_province_modifier = iron_mine
		remove_province_modifier = iron_mine_small
		remove_province_modifier = lead_mine
		remove_province_modifier = lead_mine_small
		clr_province_flag = has_mine
	}
	
	if = {
		limit = {
			ROOT = { 
				trade_goods = indigo 
				continent = europe
			}
			NOT = { has_province_modifier = woad_type }
		}
		ROOT = {
			add_permanent_province_modifier = { 
				name = woad_type
				duration = -1  
				desc = woad_type_tooltip
			}
		}
	}
	if = {
		limit = { 
			ROOT = { 
				AND = {
					NOT = { trade_goods = indigo }
					OR = {
						has_province_modifier = woad_type
						has_province_modifier = woad_type_bad
					}
				}
			}
		}
		remove_province_modifier = woad_type
		remove_province_modifier = woad_type_bad
	}
	
	if = {
		limit = {
			ROOT = { trade_goods = metalworking }
			NOT = { has_global_flag = metalworking_start }
		}
		ROOT = { province_event = { id = prices_marcin.15 days = 1 } }
		set_global_flag = metalworking_start
	}
	if = {
		limit = {
			ROOT = {
				has_province_flag = has_cannon
			}
		}
		ROOT = {
			goods_save = yes
			change_trade_goods = cannon
		}
	}
	
	if = {
		limit = {
			ROOT = {
				has_province_flag = has_metalworking
			}
		}
		ROOT = {
			goods_save = yes
			change_trade_goods = metalworking
		}
	}
	
	if = {
		limit = {
			ROOT = {
				has_province_flag = has_steam_engine
			}
		}
		ROOT = {
			goods_save = yes
			change_trade_goods = steam_engine
		}
	}
	
	if = {
		limit = {
			ROOT = {
				has_province_flag = has_optics
			}
		}
		ROOT = {
			goods_save = yes
			change_trade_goods = optics
		}
	}
	
	if = {
		limit = {
			ROOT = {
				has_province_flag = has_munitions
			}
		}
		ROOT = {
			goods_save = yes
			change_trade_goods = munitions
		}
	}
	
	if = {
		limit = {
			ROOT = {
				has_province_flag = has_munitions
			}
		}
		ROOT = {
			goods_save = yes
			change_trade_goods = munitions
		}
	}
	
	if = {
		limit = {
			ROOT = {
				has_province_flag = has_chocolate
			}
		}
		ROOT = {
			goods_save = yes
			change_trade_goods = chocolate
		}
	}
	
	if = {
		limit = {
			ROOT = {
				has_province_flag = has_cigars
			}
		}
		ROOT = {
			goods_save = yes
			change_trade_goods = cigars
		}
	}
	
	
}

on_province_owner_change = {

	###cannon_foundry
	if = {
		limit = {
			AND = {
				ROOT = { has_building = cannon_foundry NOT = { has_building = off } }
				owner = { check_variable = { which = copper value = 0.4 } check_variable = { which = tin value = 0.3 } }	
			}
		}
		owner = {
			subtract_variable = { which = copper value = 0.4 }      
			subtract_variable = { which = tin value = 0.3 }        
			change_variable = { which = copper_used value = 0.4 }        
			change_variable = { which = tin_used value = 0.3 }         		
			change_variable = { which = cannon_foundry_amount value = 1 }         
		}
		FROM = {
			change_variable = { which = copper value = 0.4 }      
			change_variable = { which = tin value = 0.3 }        
			subtract_variable = { which = copper_used value = 0.4 }        
			subtract_variable = { which = tin_used value = 0.3 } 
			subtract_variable = { which = cannon_foundry_amount value = 1 }         			
		}
	}
	else_if = {
		limit = {
			AND = {
				ROOT = { has_building = cannon_foundry NOT = { has_building = off } }	
				owner = { NOT = { check_variable = { which = copper value = 0.4 } check_variable = { which = tin value = 0.3 } } }
			}
		}
		owner = {
			change_variable = { which = copper_used value = 0.4 }        
			change_variable = { which = tin_used value = 0.3 }
			change_variable = { which = cannon_foundry_amount value = 1 }
		}
		FROM = {
			subtract_variable = { which = copper_used value = 0.4 }        
			subtract_variable = { which = tin_used value = 0.3 }
			subtract_variable = { which = cannon_foundry_amount value = 1 } 
		}
	}
	if = {
		limit = { AND = { has_building = cannon_foundry has_building = off } }
		owner = {
			change_variable = {            
				which = cannon_foundry_amount
				value = 1
			}
		}
		FROM = {
			subtract_variable = {            
				which = cannon_foundry_amount
				value = 1
			}
		}
	}
	###metalworking_workshop
	if = {
		limit = {
			AND = {
				ROOT = { has_building = metalworking_workshop NOT = { has_building = off_2 } }
				owner = { check_variable = { which = iron value = 1.0 } }	
			}
		}
		owner = {
			subtract_variable = { which = iron value = 1.0 }             
			change_variable = { which = iron_used value = 1.0 }              		
			change_variable = { which = metalworking_workshop_amount value = 1 }         
		}
		FROM = {
			change_variable = { which = iron value = 1.0 }           
			subtract_variable = { which = iron_used value = 1.0 }        
			subtract_variable = { which = metalworking_workshop_amount value = 1 }         			
		}
	}
	else_if = {
		limit = {
			AND = {
				ROOT = { has_building = metalworking_workshop NOT = { has_building = off_2 } }	
				owner = { NOT = { check_variable = { which = iron value = 1.0 } } }
			}
		}
		owner = {
			change_variable = { which = iron_used value = 1.0 }        
			change_variable = { which = metalworking_workshop_amount value = 1 }
		}
		FROM = {
			subtract_variable = { which = iron_used value = 1.0 }        
			subtract_variable = { which = metalworking_workshop_amount value = 1 } 
		}
	}
	if = {
		limit = { AND = { has_building = metalworking_workshop has_building = off_2 } }
		owner = {
			change_variable = {            
				which = metalworking_workshop_amount
				value = 1
			}
		}
		FROM = {
			subtract_variable = {            
				which = metalworking_workshop_amount
				value = 1
			}
		}
	}
	###munition_factory
	if = {
		limit = {
			AND = {
				ROOT = { has_building = munition_factory NOT = { has_building = off_3 } }
				owner = { check_variable = { which = lead value = 1.0 } }	
			}
		}
		owner = {
			subtract_variable = { which = lead value = 1.0 }             
			change_variable = { which = lead_used value = 1.0 }              		
			change_variable = { which = munition_factory_amount value = 1 }         
		}
		FROM = {
			change_variable = { which = lead value = 1.0 }           
			subtract_variable = { which = lead_used value = 1.0 }        
			subtract_variable = { which = munition_factory_amount value = 1 }         			
		}
	}
	else_if = {
		limit = {
			AND = {
				ROOT = { has_building = munition_factory NOT = { has_building = off_3 } }	
				owner = { NOT = { check_variable = { which = lead value = 1.0 } } }
			}
		}
		owner = {
			change_variable = { which = lead_used value = 1.0 }        
			change_variable = { which = munition_factory_amount value = 1 }
		}
		FROM = {
			subtract_variable = { which = lead_used value = 1.0 }        
			subtract_variable = { which = munition_factory_amount value = 1 } 
		}
	}
	if = {
		limit = { AND = { has_building = munition_factory has_building = off_3 } }
		owner = {
			change_variable = {            
				which = munition_factory_amount
				value = 1
			}
		}
		FROM = {
			subtract_variable = {            
				which = munition_factory_amount
				value = 1
			}
		}
	}
	###spectacle_factory
	if = {
		limit = {
			AND = {
				ROOT = { has_building = spectacle_factory NOT = { has_building = off_5 } }
				owner = { check_variable = { which = glass value = 0.6 } }	
			}
		}
		owner = {
			subtract_variable = { which = glass value = 0.6 }             
			change_variable = { which = glass_used value = 0.6 }              		
			change_variable = { which = spectacle_factory_amount value = 1 }         
		}
		FROM = {
			change_variable = { which = glass value = 0.6 }           
			subtract_variable = { which = glass_used value = 0.6 }        
			subtract_variable = { which = spectacle_factory_amount value = 1 }         			
		}
	}
	else_if = {
		limit = {
			AND = {
				ROOT = { has_building = spectacle_factory NOT = { has_building = off_5 } }	
				owner = { NOT = { check_variable = { which = glass value = 0.6 } } }
			}
		}
		owner = {
			change_variable = { which = glass_used value = 0.6 }        
			change_variable = { which = spectacle_factory_amount value = 1 }
		}
		FROM = {
			subtract_variable = { which = glass_used value = 0.6 }        
			subtract_variable = { which = spectacle_factory_amount value = 1 } 
		}
	}
	if = {
		limit = { AND = { has_building = spectacle_factory has_building = off_5 } }
		owner = {
			change_variable = {            
				which = spectacle_factory_amount
				value = 1
			}
		}
		FROM = {
			subtract_variable = {            
				which = spectacle_factory_amount
				value = 1
			}
		}
	}
	###cigars_factory
	if = {
		limit = {
			AND = {
				ROOT = { has_building = cigars_factory NOT = { has_building = off_6 } }
				owner = { check_variable = { which = tobacco value = 0.6 } }	
			}
		}
		owner = {
			subtract_variable = { which = tobacco value = 0.6 }             
			change_variable = { which = tobacco_used value = 0.6 }              		
			change_variable = { which = cigars_factory_amount value = 1 }         
		}
		FROM = {
			change_variable = { which = tobacco value = 0.6 }           
			subtract_variable = { which = tobacco_used value = 0.6 }        
			subtract_variable = { which = cigars_factory_amount value = 1 }         			
		}
	}
	else_if = {
		limit = {
			AND = {
				ROOT = { has_building = cigars_factory NOT = { has_building = off_6 } }	
				owner = { NOT = { check_variable = { which = tobacco value = 0.6 } } }
			}
		}
		owner = {
			change_variable = { which = tobacco_used value = 0.6 }        
			change_variable = { which = cigars_factory_amount value = 1 }
		}
		FROM = {
			subtract_variable = { which = tobacco_used value = 0.6 }        
			subtract_variable = { which = cigars_factory_amount value = 1 } 
		}
	}
	if = {
		limit = { AND = { has_building = cigars_factory has_building = off_6 } }
		owner = {
			change_variable = {            
				which = cigars_factory_amount
				value = 1
			}
		}
		FROM = {
			subtract_variable = {            
				which = cigars_factory_amount
				value = 1
			}
		}
	}
	###chocolate_factory
	if = {
		limit = {
			AND = {
				ROOT = { has_building = chocolate_factory NOT = { has_building = off_7 } }
				owner = { check_variable = { which = cocoa value = 0.6 } }	
			}
		}
		owner = {
			subtract_variable = { which = cocoa value = 0.6 }             
			change_variable = { which = cocoa_used value = 0.6 }              		
			change_variable = { which = chocolate_factory_amount value = 1 }         
		}
		FROM = {
			change_variable = { which = cocoa value = 0.6 }           
			subtract_variable = { which = cocoa_used value = 0.6 }        
			subtract_variable = { which = chocolate_factory_amount value = 1 }         			
		}
	}
	else_if = {
		limit = {
			AND = {
				ROOT = { has_building = chocolate_factory NOT = { has_building = off_7 } }	
				owner = { NOT = { check_variable = { which = cocoa value = 0.6 } } }
			}
		}
		owner = {
			change_variable = { which = cocoa_used value = 0.6 }        
			change_variable = { which = chocolate_factory_amount value = 1 }
		}
		FROM = {
			subtract_variable = { which = cocoa_used value = 0.6 }        
			subtract_variable = { which = chocolate_factory_amount value = 1 } 
		}
	}
	if = {
		limit = { AND = { has_building = chocolate_factory has_building = off_7 } }
		owner = {
			change_variable = {            
				which = chocolate_factory_amount
				value = 1
			}
		}
		FROM = {
			subtract_variable = {            
				which = chocolate_factory_amount
				value = 1
			}
		}
	}
	###steam_engine_manu
	if = {
		limit = {
			AND = {
				ROOT = { has_building = steam_engine_manu NOT = { has_building = off_4 } }
				owner = { check_variable = { which = copper value = 0.4 } check_variable = { which = zinc value = 0.3 } }	
			}
		}
		owner = {
			subtract_variable = { which = copper value = 0.4 }      
			subtract_variable = { which = zinc value = 0.3 }        
			change_variable = { which = copper_used value = 0.4 }        
			change_variable = { which = zinc_used value = 0.3 }         		
			change_variable = { which = steam_engine_manu_amount value = 1 }         
		}
		FROM = {
			change_variable = { which = copper value = 0.4 }      
			change_variable = { which = zinc value = 0.3 }        
			subtract_variable = { which = copper_used value = 0.4 }        
			subtract_variable = { which = zinc_used value = 0.3 } 
			subtract_variable = { which = steam_engine_manu_amount value = 1 }         			
		}
	}
	else_if = {
		limit = {
			AND = {
				ROOT = { has_building = steam_engine_manu NOT = { has_building = off_4 } }	
				owner = { NOT = { check_variable = { which = copper value = 0.4 } check_variable = { which = zinc value = 0.3 } } }
			}
		}
		owner = {
			change_variable = { which = copper_used value = 0.4 }        
			change_variable = { which = zinc_used value = 0.3 }
			change_variable = { which = steam_engine_manu_amount value = 1 }
		}
		FROM = {
			subtract_variable = { which = copper_used value = 0.4 }        
			subtract_variable = { which = zinc_used value = 0.3 }
			subtract_variable = { which = steam_engine_manu_amount value = 1 } 
		}
	}
	if = {
		limit = { AND = { has_building = steam_engine_manu has_building = off_4 } }
		owner = {
			change_variable = {            
				which = steam_engine_manu_amount
				value = 1
			}
		}
		FROM = {
			subtract_variable = {            
				which = steam_engine_manu_amount
				value = 1
			}
		}
	}
	
	FROM = { 
		country_event = { id = New_TradeGood_Events.2 days = 3 }
	}
	owner = {
		country_event = { id = New_TradeGood_Events.2 days = 3 }
		country_event = { id = New_TradeGood_Events.50 days = 25 }
	}
	
}

on_dip_development = {	
	if = {
		limit = {
			OR = {
				trade_goods = copper
				trade_goods = tin
				trade_goods = iron
				trade_goods = zinc
				trade_goods = lead
				trade_goods = glass
				trade_goods = cocoa
				trade_goods = tobacco
			}
		}
		if = {
			limit = { 
				NOT = { has_province_modifier = import_from_subjects_modifier } 
			}
			owner = {
				country_event = { 
					id = New_TradeGood_Events.2
					days = 1
				}
			}
		}
		else_if = {
			limit = {
				has_province_modifier = import_from_subjects_modifier
			}
			owner = {
				country_event = { 
					id = New_TradeGood_Events.2
					days = 4
				}
				overlord = { 
					country_event = { 
						id = New_TradeGood_Events.2
						days = 4
					}
				}
			}
			if = {
				limit = { trade_goods = copper  }
				update_goods_subjects = { GOODS = copper }
			}
			else_if = {
				limit = { trade_goods = tin  }
				update_goods_subjects = { GOODS = tin }
			}
			else_if = {
				limit = { trade_goods = iron  }
				update_goods_subjects = { GOODS = iron }
			}
			else_if = {
				limit = { trade_goods = lead }
				update_goods_subjects = { GOODS = lead }
			}
			else_if = {
				limit = { trade_goods = zinc  }
				update_goods_subjects = { GOODS = zinc }
			}
			else_if = {
				limit = { trade_goods = glass  }
				update_goods_subjects = { GOODS = glass }
			}
			else_if = {
				limit = { trade_goods = cocoa  }
				update_goods_subjects = { GOODS = cocoa }
			}
			else_if = {
				limit = { trade_goods = tobacco  }
				update_goods_subjects = { GOODS = tobacco }
			}
		}
	}
}

on_abandon_colony = {
	if = {
		limit = {
			ROOT = {
				has_province_flag = cigars_tax
			}
		}
		add_base_tax = -2
		clr_province_flag = cigars_tax
	}
}

on_colony_established = {
	if = {
		limit = {
			NOT = { has_province_flag = cigars_tax }
			FROM = {
				trading_bonus = {
					trade_goods = cigars
					value = yes
				}
				check_variable = {
					which = tobacco_total 
					which = tobacco_used
				}
			}	
		}
		set_province_flag = cigars_tax
		add_base_tax = 2
	}
}



