#Written by Hiddengearz

AB_calculate_penalty_increase = { #Calculate rate of AB penalty increase & apply it
	if = {
		limit = {
			has_country_flag = { flag = total_AB_wars value = 1 } #Has 1 AB wars
		}
		ab_penalty_increase = yes
		
	}
	if = {
		limit = {
			has_country_flag = { flag = total_AB_wars value = 2 } #Has 2 AB wars
		}
		ab_penalty_increase = yes
		ab_penalty_increase = yes
		
	}
	if = {
		limit = {
			has_country_flag = { flag = total_AB_wars value = 3 } #Has 3 AB wars
		}
		ab_penalty_increase = yes
		ab_penalty_increase = yes
		ab_penalty_increase = yes
		
	}
	if = {
		limit = {
			has_country_flag = { flag = total_AB_wars value = 4 } #Has 4 AB wars	
		}
		ab_penalty_increase = yes
		ab_penalty_increase = yes
		ab_penalty_increase = yes
		ab_penalty_increase = yes
		
	}
}

ab_penalty_increase = { #apply AB penlty - triggered in AB_calculate_penalty_increase
	if = {
		limit = {
			has_idea = ab_penalty_8
		}
		swap_ideas = { remove_idea = ab_penalty_8 add_idea = ab_penalty_9 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_7
		}
		swap_ideas = { remove_idea = ab_penalty_7 add_idea = ab_penalty_8 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_6
		}
		swap_ideas = { remove_idea = ab_penalty_6 add_idea = ab_penalty_7 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_5
		}
		swap_ideas = { remove_idea = ab_penalty_5 add_idea = ab_penalty_6 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_4
		}
		swap_ideas = { remove_idea = ab_penalty_4 add_idea = ab_penalty_5 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_3
		}
		swap_ideas = { remove_idea = ab_penalty_3 add_idea = ab_penalty_4 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_2
		}
		swap_ideas = { remove_idea = ab_penalty_2 add_idea = ab_penalty_3 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_1
		}
		swap_ideas = { remove_idea = ab_penalty_1 add_idea = ab_penalty_2 }
	}
	if = {
		limit = {
			not = {
				has_idea = ab_penalty_1 has_idea = ab_penalty_2 has_idea = ab_penalty_3 has_idea = ab_penalty_4 
				has_idea = ab_penalty_5 has_idea = ab_penalty_6 has_idea = ab_penalty_7 has_idea = ab_penalty_8 
				has_idea = ab_penalty_1 has_idea = ab_penalty_1 has_idea = ab_penalty_1 has_idea = ab_penalty_1 
				has_idea = ab_penalty_9 has_idea = ab_penalty_10 has_idea = ab_penalty_11 has_idea = ab_penalty_12
				has_idea = ab_penalty_13 has_idea = ab_penalty_14 has_idea = ab_penalty_15 has_idea = ab_penalty_16 
				has_idea = ab_penalty_17 has_idea = ab_penalty_18 has_idea = ab_penalty_19 has_idea = ab_penalty_20 
				has_idea = ab_penalty_21 has_idea = ab_penalty_22 has_idea = ab_penalty_23 has_idea = ab_penalty_24 
			}
			has_an_AB_war = yes
		}
		add_ideas = ab_penalty_1
	}
	
}

AB_calculate_penalty_decrease = { #Calculate rate of AB penalty decrease & apply it
	AB_Decrease_penalty = yes
	
}

AB_Decrease_penalty = { #lower AB penalty - triggered in AB_calculate_penalty_decrease
	
	if = {
		limit = {
			has_idea = ab_penalty_1
		}
		remove_ideas = ab_penalty_1
	}
	if = {
		limit = {
			has_idea = ab_penalty_2
		}
		swap_ideas = { remove_idea = ab_penalty_2 add_idea = ab_penalty_1 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_3
		}
		swap_ideas = { remove_idea = ab_penalty_3 add_idea = ab_penalty_2 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_4
		}
		swap_ideas = { remove_idea = ab_penalty_4 add_idea = ab_penalty_3 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_5
		}
		swap_ideas = { remove_idea = ab_penalty_5 add_idea = ab_penalty_4 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_6
		}
		swap_ideas = { remove_idea = ab_penalty_6 add_idea = ab_penalty_5 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_7
		}
		swap_ideas = { remove_idea = ab_penalty_7 add_idea = ab_penalty_6 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_8
		}
		swap_ideas = { remove_idea = ab_penalty_8 add_idea = ab_penalty_7 }
	}
	if = {
		limit = {
			has_idea = ab_penalty_9
		}
		swap_ideas = { remove_idea = ab_penalty_9 add_idea = ab_penalty_8 }
	}
	
}

#Is triggered for the first anti bully war. It will only trigger again when another anti bully war starts
#and there is no other active anti bully war at the time of the second anti bully war
AB_war_main = {
	
	if = { #If you have an AB war continue to increase penalty
		limit = {
			has_an_AB_war = yes
		}
		AB_calculate_penalty_increase = yes
		country_event = { id = anti_bully.3 days = 30 } #delay the next increase in AB penalty for x days
	}
	if = {
		limit = {
			has_an_AB_war = no
		}
		AB_calculate_penalty_decrease = yes
		country_event = { id = anti_bully.3 days = 30 }
	}
	
		
	
}

#Second function that runs for every AB war. Will decrease total_AB_wars flag when each AB war is over
#When total_AB_wars is 0 AB_war_main will begin to decrease AB war penalty
AB_war_second = { 
	
	if = {
		limit = {
			still_in_this_AB_war = no
		}
		modify_country_flag = { flag = total_AB_wars value = -1 }
		else = {
			country_event = { id = anti_bully.4 days = 30 } #check again in 30 days
		}
	}
	
}
