﻿#Effects relating to Casus Bellis.

#############################################################################################################################################################################################################
# modify_participants_fame_values 																																											#
# by Sean Hughes 																																															#
#																																																			#
# Description: Makes the correct adjustments to prestige or piety for each participant in a war. 																											#
#																																																			#
# Parameters:																																																#
#	WINNER: The character who won the war.																																									#
#	LOSER: The character who lost the war.																																									#
#	IS_RELIGIOUS_WAR: If yes we will modify Piety values instead of Prestige values.																														#
#	FAME_BASE: The base value for calculating how much Prestige or Piety is gained/lost by each character, as below:																						#
#	  WINNER_FAME_SCALE: The winner will receive Prestige/Piety equal to FAME_BASE multiplied by this scale.																								#
#	  LOSER_FAME_SCALE: The winner will receive Prestige/Piety equal to FAME_BASE multiplied by this scale. **NOTE: This value should always be negative, otherwise the loser will gain piety/prestige!**	#
#	  WINNER_ALLY_FAME_SCALE: Winner's allies will receive Prestige/Piety based on FAME_BASE, multiplied by this scale, then adjusted based on their War Contributuion.										#
#	  LOSER_ALLY_FAME_SCALE: As above, but for the loser's side. ** NOTE: In the current design this should always be the same as WINNER_ALLY_FAME_SCALE, but I'm splitting it out in order to future-proof	#
#		this effect in case the design changes or modders want to alter how it works. **																													#	
#																																																			#
#############################################################################################################################################################################################################

@maximum_prestige_winner = 1000
@maximum_piety_winner = 1000
@maximum_merit_winner = 1000
@minimum_prestige_loser = -1000
@minimum_piety_loser = -1000

@maximum_prestige_winner_ally = 1000
@maximum_piety_winner_ally = 1000
@maximum_merit_winner_ally = 1000
@maximum_prestige_loser_ally = 1000
@maximum_piety_loser_ally = 1000

modify_all_participants_fame_values = {

	# Give the winner the appropriate type & amount of 'fame' (prestige or piety).
	if = {
		# If the attacker is the winner, we only award fame *experience* instead of actual fame currency.
		limit = {
			$WINNER$ = scope:attacker
		}
		if = {
			# Piety level progress for winning offensive religious wars.
			limit = {
				$IS_RELIGIOUS_WAR$ = yes
			}
			scope:attacker = {
				add_piety_experience = {
					value = $FAME_BASE$
					multiply = $WINNER_FAME_SCALE$
					max = @maximum_piety_winner
				}
			}
		}
		else = {
			# Prestige level progress for winning all other offensive wars.
			scope:attacker = {
				add_prestige_experience = {
					value = $FAME_BASE$
					multiply = $WINNER_FAME_SCALE$
					max = @maximum_prestige_winner
				}
			}
		}		
	}
	else = {
		# If the defender is the winner, they get actual fame currency as a reward.
		if = {
			# Gain piety for winning defensive religious wars.
			limit = {
				$IS_RELIGIOUS_WAR$ = yes
			}
			scope:defender = {
				add_piety = {
					value = $FAME_BASE$
					multiply = $WINNER_FAME_SCALE$
					max = @maximum_piety_winner
				}
			}
		}
		else = {
			# Gain prestige for winning all other defensive wars.
			scope:defender = {
				add_prestige = {
					value = $FAME_BASE$
					multiply = $WINNER_FAME_SCALE$
					max = @maximum_prestige_winner
				}
			}
		}
	}
	if = {
		# Award Merit to the victorious attacker
		limit = {
			$WINNER$ = scope:attacker
		}
		scope:attacker = {
			if = {
				limit = {
					government_allows = merit
				}
				change_merit = {
					value = $FAME_BASE$
					multiply = $WINNER_FAME_SCALE$
					max = @maximum_merit_winner
				}
			}
		}
	}
	else = {
		# Award Merit to the victorious defender
		scope:defender = {
			if = {
				limit = {
					government_allows = merit
				}
				change_merit = {
					value = $FAME_BASE$
					multiply = $WINNER_FAME_SCALE$
					max = @maximum_merit_winner
				}
			}
		}
	}

	# Award the appropriate type & amount of 'fame' to the allies of both primary participants.
	modify_allies_of_participants_fame_values = {
		WINNER = $WINNER$
		IS_RELIGIOUS_WAR = $IS_RELIGIOUS_WAR$
		FAME_BASE = $FAME_BASE$
		WINNER_ALLY_FAME_SCALE = $WINNER_ALLY_FAME_SCALE$
		LOSER_ALLY_FAME_SCALE = $LOSER_ALLY_FAME_SCALE$
	}

	# Take the appropriate type & amount of 'fame' away from the loser of the war.
	if = {
		# Religious wars cost Piety for the loser.
		limit = {
			$IS_RELIGIOUS_WAR$ = yes
		}

		$LOSER$ = {
			add_piety = {
				value = $FAME_BASE$
				multiply = $LOSER_FAME_SCALE$
				min = @minimum_piety_loser
			}
		}
	}
	else = {
		# All other war types cost  Prestige from the loser.
		$LOSER$ = {
			add_prestige = {
				value = $FAME_BASE$
				multiply = $LOSER_FAME_SCALE$
				min = @minimum_prestige_loser
			}
		}
	}
}

modify_all_participants_fame_values_crusading_claim = {

	# Give the winner the appropriate type & amount of 'fame' (prestige or piety).
	if = {
		# If the attacker is the winner, we only award fame *experience* instead of actual fame currency.
		limit = {
			$WINNER$ = scope:attacker
		}
		scope:attacker = {
			add_prestige_experience = {
				value = $FAME_BASE$
				multiply = $WINNER_FAME_SCALE$
			}
		}		
	}
	else = {
		# Gain prestige for winning all other defensive wars.
		scope:defender = {
			add_prestige = {
				value = $FAME_BASE$
				multiply = $WINNER_FAME_SCALE$
			}
		}
	}

	# Award the appropriate type & amount of 'fame' to the allies of both primary participants.
	modify_allies_of_participants_fame_values_crusading_claim = {
		WINNER = $WINNER$
		FAME_BASE = $FAME_BASE$
		WINNER_ALLY_FAME_SCALE = $WINNER_ALLY_FAME_SCALE$
		LOSER_ALLY_FAME_SCALE = $LOSER_ALLY_FAME_SCALE$
	}

	# All other war types cost  Prestige from the loser.
	$LOSER$ = {
		add_prestige = {
			value = $FAME_BASE$
			multiply = $LOSER_FAME_SCALE$
		}
	}
}

#############################################################################################################################################################################################################
# modify_allies_of_participants_fame_values																																									#
# by Sean Hughes 																																															#
#																																																			#
# Description: Makes the correct adjustments to prestige or piety but ONLY for the allies in a war (e.g., not the primary attacker/defender).																#
#	Used as part of 'modify_participants_fame_values' but can also be used on it's own where desired, such as in a white peace where you don't want to give the primary participants any prestige/piety.	#
#																																																			#
# Parameters:																																																#
#	WINNER: The character who won the war.																																									#
#	IS_RELIGIOUS_WAR: If yes we will modify Piety values instead of Prestige values.																														#
#	FAME_BASE: The base value for calculating how much Prestige or Piety is gained/lost by each character, as below:																						#
#	  WINNER_ALLY_FAME_SCALE: Winner's allies will receive Prestige/Piety based on FAME_BASE, multiplied by this scale, then adjusted based on their War Contributuion.										#
#	  LOSER_ALLY_FAME_SCALE: As above, but for the loser's side. ** NOTE: In the current design this should always be the same as WINNER_ALLY_FAME_SCALE, but I'm splitting it out in order to future-proof	#
#		this effect in case the design changes or modders want to alter how it works. **																													#	
#																																																			#
#############################################################################################################################################################################################################

modify_allies_of_participants_fame_values = {
	# Give the allies of both primary participants the appropriate type & amount of 'fame'.

	if = {
		# Religious wars award Piety to participants.
		limit = {
			$IS_RELIGIOUS_WAR$ = yes
		}
		if = {
			# Award Piety to the victorious attacker's allies.
			limit = {
				$WINNER$ = scope:attacker
			}
			add_from_contribution_attackers = {
				piety = {
					value = $FAME_BASE$
					multiply = $WINNER_ALLY_FAME_SCALE$
					max = @maximum_piety_winner_ally
				}
				opinion = {
					modifier = contributed_in_war
				}
			}
			# Award Piety to the defeated defender's allies.
			add_from_contribution_defenders = {
				piety = {
					value = $FAME_BASE$
					multiply = $LOSER_ALLY_FAME_SCALE$
					max = @maximum_prestige_loser_ally
				}
				opinion = {
					modifier = contributed_in_war
				}
			}
		}
		else = {
			# Award Piety to the victorious defender's allies.
			add_from_contribution_defenders = {
				piety = {
					value = $FAME_BASE$
					multiply = $WINNER_ALLY_FAME_SCALE$
					max = @maximum_piety_winner_ally
				}
				opinion = {
					modifier = contributed_in_war
				}
			}
			# Award Piety to the defeated attacker's allies.
			add_from_contribution_attackers = {
				piety = {
					value = $FAME_BASE$
					multiply = $LOSER_ALLY_FAME_SCALE$
					max = @maximum_prestige_loser_ally
				}
				opinion = {
					modifier = contributed_in_war
				}
			}
		}
	}
	else = {
		# All other war types award Prestige to participants.
		if = {
			# Award Prestige to the victorious attacker's allies.
			limit = {
				$WINNER$ = scope:attacker
			}
			add_from_contribution_attackers = {
				prestige = {
					value = $FAME_BASE$
					multiply = $WINNER_ALLY_FAME_SCALE$
					max = @maximum_prestige_winner_ally
				}
				opinion = {
					modifier = contributed_in_war
				}
			}
			# Award Prestige to the defeated defender's allies.
			add_from_contribution_defenders = {
				prestige = {
					value = $FAME_BASE$
					multiply = $LOSER_ALLY_FAME_SCALE$
					max = @maximum_prestige_loser_ally
				}
				opinion = {
					modifier = contributed_in_war
				}
			}
		}
		else = {
			# Award Prestige to the victorious defender's allies.
			add_from_contribution_defenders = {
				prestige = {
					value = $FAME_BASE$
					multiply = $WINNER_ALLY_FAME_SCALE$
					max = @maximum_prestige_winner_ally
				}
				opinion = {
					modifier = contributed_in_war
				}
			}
			# Award Prestige to the defeated attacker's allies.
			add_from_contribution_attackers = {
				prestige = {
					value = $FAME_BASE$
					multiply = $LOSER_ALLY_FAME_SCALE$
					max = @maximum_prestige_loser_ally
				}
				opinion = {
					modifier = contributed_in_war
				}
			}
		}
	}
	# Award Merit to each participant of the winning side
	if = {
		# Award Merit to the victorious attacker's allies.
		limit = {
			$WINNER$ = scope:attacker
		}
		add_from_contribution_attackers = {
			merit = {
				value = $FAME_BASE$
				multiply = $WINNER_ALLY_FAME_SCALE$
				max = @maximum_merit_winner_ally
			}
		}
	}
	else = {
		# Award Merit to the victorious defender's allies.
		add_from_contribution_defenders = {
			merit = {
				value = $FAME_BASE$
				multiply = $LOSER_ALLY_FAME_SCALE$
				max = @maximum_merit_winner_ally
			}
		}
	}
}

modify_allies_of_participants_fame_both_values = {
	# Give the allies of both primary participants the appropriate type & amount of 'fame'.

	if = {
		# Award Piety to the victorious attacker's allies.
		limit = {
			$WINNER$ = scope:attacker
		}
		add_from_contribution_attackers = {
			prestige = {
				value = $PRESTIGE_FAME_BASE$
				multiply = $WINNER_ALLY_FAME_SCALE$
				max = @maximum_prestige_winner_ally
			}
			piety = {
				value = $PIETY_FAME_BASE$
				multiply = $WINNER_ALLY_FAME_SCALE$
				max = @maximum_piety_winner_ally
			}
			opinion = {
				modifier = contributed_in_war
			}
		}
		# Award Piety to the defeated defender's allies.
		add_from_contribution_defenders = {
			prestige = {
				value = $PRESTIGE_FAME_BASE$
				multiply = $LOSER_ALLY_FAME_SCALE$
				max = @maximum_prestige_loser_ally
			}
			piety = {
				value = $PIETY_FAME_BASE$
				multiply = $LOSER_ALLY_FAME_SCALE$
				max = @maximum_piety_loser_ally
			}
			opinion = {
				modifier = contributed_in_war
			}
		}
	}
	else = {
		# Award Piety to the victorious defender's allies.
		add_from_contribution_defenders = {
			prestige = {
				value = $PRESTIGE_FAME_BASE$
				multiply = $WINNER_ALLY_FAME_SCALE$
				max = @maximum_prestige_winner_ally
			}
			piety = {
				value = $PIETY_FAME_BASE$
				multiply = $WINNER_ALLY_FAME_SCALE$
				max = @maximum_piety_winner_ally
			}
			opinion = {
				modifier = contributed_in_war
			}
		}
		# Award Piety to the defeated attacker's allies.
		add_from_contribution_attackers = {
			prestige = {
				value = $PRESTIGE_FAME_BASE$
				multiply = $LOSER_ALLY_FAME_SCALE$
				max = @maximum_prestige_loser_ally
			}
			piety = {
				value = $PIETY_FAME_BASE$
				multiply = $LOSER_ALLY_FAME_SCALE$
				max = @maximum_piety_loser_ally
			}
			opinion = {
				modifier = contributed_in_war
			}
		}	
	}

}

modify_allies_of_participants_fame_values_crusading_claim = {
	# Give the allies of both primary participants the appropriate type & amount of 'fame'.

	if = {
		# Award Prestige to the victorious attacker's allies.
		limit = {
			$WINNER$ = scope:attacker
		}
		add_from_contribution_attackers = {
			prestige = {
				value = $FAME_BASE$
				multiply = $WINNER_ALLY_FAME_SCALE$
			}
			opinion = {
				modifier = contributed_in_war
			}
		}
		# Award Prestige to the defeated defender's allies.
		add_from_contribution_defenders = {
			prestige = {
				value = $FAME_BASE$
				multiply = $LOSER_ALLY_FAME_SCALE$
			}
			opinion = {
				modifier = contributed_in_war
			}
		}
	}
	else = {
		# Award Prestige to the victorious defender's allies.
		add_from_contribution_defenders = {
			prestige = {
				value = $FAME_BASE$
				multiply = $WINNER_ALLY_FAME_SCALE$
			}
			opinion = {
				modifier = contributed_in_war
			}
		}
		# Award Prestige to the defeated attacker's allies.
		add_from_contribution_attackers = {
			prestige = {
				value = $FAME_BASE$
				multiply = $LOSER_ALLY_FAME_SCALE$
				multiply = -1
			}
			opinion = {
				modifier = contributed_in_war
			}
		}
	}
}

add_hook_from_temp_de_jure_liege_to_attacker = {
	# Assumes scope of title to be conquered.
	# Assumes scope:attacker to be set for the character initiating the war.
	# Assumes scope:temp_de_jure_liege to be set for the de jure liege that
	# might gain a title from the war.
	# Outcome: De jure liege of the contested title will owe a favor towards
	# the attacker of the war if the de jure liege is in the vassal tree of the attacker.
	if = {
		limit = {
			exists = scope:temp_de_jure_liege
			scope:temp_de_jure_liege != scope:attacker
			scope:temp_de_jure_liege = { target_is_liege_or_above = scope:attacker }
			scope:temp_de_jure_liege = {
				is_ai = yes
			}
			scope:attacker = {
				can_add_hook = {
					type = favor_hook
					target = scope:temp_de_jure_liege
				}
			}
		}
		scope:attacker = {
			add_hook = {
				type = favor_hook
				target = scope:temp_de_jure_liege
			}
		}
	}
}
