on_actions = {
	on_startup = {
		effect = {
			random_country = {
				set_global_flag = monuments_mod_active
				# Game Rule: Cost
				if = {
					limit = {
						has_game_rule = {
							rule = monuments_game_rule_costs
							option = reduced_by_50
						}
					}
					set_global_flag = monuments_game_rule_costs_reduced_by_50
				}
				else_if = {
					limit = {
						has_game_rule = {
							rule = monuments_game_rule_costs
							option = increased_by_50
						}
					}
					set_global_flag = monuments_game_rule_costs_increased_by_50
				}
				else_if = {
					limit = {
						has_game_rule = {
							rule = monuments_game_rule_costs
							option = increased_by_100
						}
					}
					set_global_flag = monuments_game_rule_costs_increased_by_100
				}
				# Game Rule: Bonus Target
				if = {
					limit = {
						has_game_rule = {
							rule = monuments_game_rule_bonus_target
							option = controller
						}
					}
					set_global_flag = monuments_game_rule_bonus_target_controller
				}
				# Game Rule: Country Restriction
				if = {
					limit = {
						has_game_rule = {
							rule = monuments_game_rule_country_restriction
							option = no
						}
					}
					set_global_flag = monuments_game_rule_no_country_restriction
				}
				# Game Rule: AI PP Cost Enabled/Disabled
				if = {
					limit = {
						has_game_rule = {
							rule = monuments_game_rule_costs_ai
							option = disabled
						}
					}
					set_variable = { global.ai_monuments_pp_threshold = 0 }
					set_global_flag = monuments_game_rule_no_pp_cost_ai
				}
				else = {
					# Game Rule: AI PP Threshold
					if = {
						limit = {
							has_game_rule = {
								rule = monuments_game_rule_ai_monuments_pp_threshold
								option = MONUMENTS_GAME_RULE_AI_MONUMENTS_PP_THRESHOLD_100
							}
						}
						set_variable = { global.ai_monuments_pp_threshold = 100 }
					}
					else_if = {
						limit = {
							has_game_rule = {
								rule = monuments_game_rule_ai_monuments_pp_threshold
								option = MONUMENTS_GAME_RULE_AI_MONUMENTS_PP_THRESHOLD_200
							}
						}
						set_variable = { global.ai_monuments_pp_threshold = 200 }
					}
					else_if = {
						limit = {
							has_game_rule = {
								rule = monuments_game_rule_ai_monuments_pp_threshold
								option = MONUMENTS_GAME_RULE_AI_MONUMENTS_PP_THRESHOLD_300
							}
						}
						set_variable = { global.ai_monuments_pp_threshold = 300 }
					}
					else_if = {
						limit = {
							has_game_rule = {
								rule = monuments_game_rule_ai_monuments_pp_threshold
								option = MONUMENTS_GAME_RULE_AI_MONUMENTS_PP_THRESHOLD_400
							}
						}
						set_variable = { global.ai_monuments_pp_threshold = 400 }
					}
					else_if = {
						limit = {
							has_game_rule = {
								rule = monuments_game_rule_ai_monuments_pp_threshold
								option = MONUMENTS_GAME_RULE_AI_MONUMENTS_PP_THRESHOLD_500
							}
						}
						set_variable = { global.ai_monuments_pp_threshold = 500 }
					}
					else = {
						set_variable = { global.ai_monuments_pp_threshold = 300 }
					}
				}
				# Game Rule: Landmark Monuments
				if = {
					limit = {
						has_dlc = "Gotterdammerung"
						has_game_rule = {
							rule = monuments_game_rule_landmark_monuments
							option = disabled
						}
					}
					set_global_flag = monuments_game_rule_disabled_landmark_monuments
				}
				# Set up Monuments
				set_up_monuments_at_start_effect = yes
			}
		}
	}

	on_weekly = {
		random_events = {
			1000 = 0
			30 = monuments_events.2
			75 = monuments_events.5
			75 = monuments_events.6
			75 = monuments_events.7
			75 = monuments_events.8
			75 = monuments_events.9
		}
		effect = {
			# Political Power Gain from Subjects
			if = {
				limit = {
					num_subjects > 0
					NOT = { check_variable = { modifier@political_power_gain_from_subjects = 0 } }
				}
				set_variable = { political_power_gain_from_subjects_var = num_subjects }
				multiply_variable = { political_power_gain_from_subjects_var = modifier@political_power_gain_from_subjects }
				if = {
					limit = {
						NOT = { has_dynamic_modifier = { modifier = political_power_gain_from_subjects_dynamic_modifier } }
					}
					add_dynamic_modifier = { modifier = political_power_gain_from_subjects_dynamic_modifier }
				}
			}
			else_if = {
				limit = {
					has_dynamic_modifier = { modifier = political_power_gain_from_subjects_dynamic_modifier }
				}
				clear_variable = political_power_gain_from_subjects_var
				remove_dynamic_modifier = { modifier = political_power_gain_from_subjects_dynamic_modifier }
			}

			# Communism Drift in Neighbors and Subjects
			if = {
				limit = {
					is_a_soviet_union_monument_country = yes
				}
				weekly_communism_drift_effect_from_monument = yes
			}
		}
	}

	on_monthly = {
		random_events = {
			1000 = 0
			20 = monuments_events.3
			50 = monuments_events.4
			1 = monuments_events.12 # very rare, if you get this you are lucky
		}
		effect = {
			every_state = {
				limit = {
					OR = {
						is_owned_by = ROOT
						AND = {
							scope_for_monument_bonus_receiver_is_controller = yes
							is_controlled_by = ROOT
						}
					}
					state_has_any_monument = yes
				}
				for_each_loop = {
					array = state_monuments_array
					set_temp_variable = { monument_id = v }
					set_monument_effects = yes
				}
			}
		}
	}

# mood mechanic removed in vanilla
#	on_monthly_GER = {
#		effect = {
#			set_temp_variable = { SS_anger_change = modifier@monthly_ss_mood_change }
#			if = {
#				limit = {
#					NOT = { check_variable = { SS_anger_change = 0 } }
#					has_variable = SS_anger
#					check_variable = { SS_anger < 100 }
#					check_variable = { SS_anger > -100 }
#					monument_character_trigger_has_character_heinrich_himmler = yes
#				}
#				add_to_variable = { SS_anger = SS_anger_change }
#			}
#		}
#	}

	# ROOT is winner, FROM gets annexed
	on_annex = {
		effect = {
			every_state = {
				limit = {
					OR = {
						is_owned_by = ROOT
						AND = {
							scope_for_monument_bonus_receiver_is_controller = yes
							is_controlled_by = ROOT
						}
					}
					state_has_any_monument = yes
				}
				for_each_loop = {
					array = state_monuments_array
					set_temp_variable = { monument_id = v }
					set_monument_effects = yes
				}
				if = {
					limit = {
						has_monument_construction = yes
						NOT = { check_variable = { ROOT.monument_construction_state_1 = THIS.id } }
						NOT = { check_variable = { ROOT.monument_construction_state_2 = THIS.id } }
						NOT = { check_variable = { ROOT.monument_construction_state_3 = THIS.id } }
						NOT = { check_variable = { ROOT.monument_construction_state_4 = THIS.id } }
						NOT = { check_variable = { ROOT.monument_construction_state_5 = THIS.id } }
					}
					cancel_monument_construction = yes
				}
			}
			FROM = {
				every_state = {
					limit = {
						OR = {
							is_owned_by = PREV
							AND = {
								scope_for_monument_bonus_receiver_is_controller = yes
								is_controlled_by = PREV
							}
						}
						state_has_any_monument = yes
					}
					for_each_loop = {
						array = state_monuments_array
						set_temp_variable = { monument_id = v }
						set_monument_effects = yes
					}
					if = {
						limit = {
							has_monument_construction = yes
							NOT = { check_variable = { ROOT.monument_construction_state_1 = THIS.id } }
							NOT = { check_variable = { ROOT.monument_construction_state_2 = THIS.id } }
							NOT = { check_variable = { ROOT.monument_construction_state_3 = THIS.id } }
							NOT = { check_variable = { ROOT.monument_construction_state_4 = THIS.id } }
							NOT = { check_variable = { ROOT.monument_construction_state_5 = THIS.id } }
						}
						cancel_monument_construction = yes
					}
				}
			}
		}
	}

	# ROOT is new controller, FROM is old controller, FROM.FROM is state ID
	on_state_control_changed = {
		effect = {
			FROM.FROM = {
				if = {
					limit = {
						state_has_any_monument = yes
					}
					for_each_loop = {
						array = state_monuments_array
						set_temp_variable = { monument_id = v }
						set_monument_effects = yes
					}
					if = {
						limit = {
							scope_for_monument_bonus_receiver_is_controller = yes
							ROOT = {
								NOT = { original_tag = FROM }
								has_war_with = FROM
							}
						}
						for_each_loop = {
							array = state_monuments_array
							set_temp_variable = { monument_id = v }
							if = {
								limit = {
									monument_can_downgrade = yes
								}
								if = {
									limit = {
										can_use_monument_bonuses_ignore_disabled_monument_condition = yes
									}
									downgrade_monument = yes
								}
								else = {
									set_temp_variable = { level = 0 }
									set_monument_level = yes
								}
								if = {
									limit = {
										has_monument_construction = yes
									}
									set_temp_variable = { show_popup = 1 }
									cancel_monument_construction = yes
								}
							}
							if = {
								limit = {
									set_temp_variable = { level = 1 }
									has_less_monument_level = yes
								}
								ROOT = {
									PREV = {
										meta_effect = {
											text = {
												if = {
													limit = {
														has_state_flag = deactivated_monument_[ID]_@PREV
													}
													clr_state_flag = deactivated_monument_[ID]_@PREV
												}
											}
											ID = "[?monument_id]"
										}
									}
								}
								FROM = {
									PREV = {
										meta_effect = {
											text = {
												if = {
													limit = {
														has_state_flag = deactivated_monument_[ID]_@PREV
													}
													clr_state_flag = deactivated_monument_[ID]_@PREV
												}
											}
											ID = "[?monument_id]"
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	# ROOT is winner, FROM is loser
	on_peaceconference_ended = {
		effect = {
			every_state = {
				limit = {
					OR = {
						is_owned_by = ROOT
						AND = {
							scope_for_monument_bonus_receiver_is_controller = yes
							is_controlled_by = ROOT
						}
					}
					state_has_any_monument = yes
				}
				for_each_loop = {
					array = state_monuments_array
					set_temp_variable = { monument_id = v }
					set_monument_effects = yes
				}
				if = {
					limit = {
						NOT = { scope_for_monument_bonus_receiver_is_controller = yes }
						pc_is_state_claimed_by = ROOT
						ROOT = {
							NOT = { original_tag = FROM }
							NOT = { has_country_flag = monuments_are_getting_downgraded_after_war }
						}
					}
					for_each_loop = {
						array = state_monuments_array
						set_temp_variable = { monument_id = v }
						if = {
							limit = {
								monument_can_downgrade = yes
							}
							if = {
								limit = {
									can_use_monument_bonuses_ignore_disabled_monument_condition = yes
								}
								downgrade_monument = yes
							}
							else = {
								set_temp_variable = { level = 0 }
								set_monument_level = yes
							}
							if = {
								limit = {
									has_monument_construction = yes
								}
								set_temp_variable = { show_popup = 1 }
								cancel_monument_construction = yes
							}
						}
						if = {
							limit = {
								set_temp_variable = { level = 1 }
								has_less_monument_level = yes
							}
							ROOT = {
								PREV = {
									meta_effect = {
										text = {
											if = {
												limit = {
													has_state_flag = deactivated_monument_[ID]_@PREV
												}
												clr_state_flag = deactivated_monument_[ID]_@PREV
											}
										}
										ID = "[?monument_id]"
									}
								}
							}
							FROM = {
								PREV = {
									meta_effect = {
										text = {
											if = {
												limit = {
													has_state_flag = deactivated_monument_[ID]_@PREV
												}
												clr_state_flag = deactivated_monument_[ID]_@PREV
											}
										}
										ID = "[?monument_id]"
									}
								}
							}
						}
					}
				}
				if = {
					limit = {
						has_monument_construction = yes
						NOT = { check_variable = { ROOT.monument_construction_state_1 = THIS.id } }
						NOT = { check_variable = { ROOT.monument_construction_state_2 = THIS.id } }
						NOT = { check_variable = { ROOT.monument_construction_state_3 = THIS.id } }
						NOT = { check_variable = { ROOT.monument_construction_state_4 = THIS.id } }
						NOT = { check_variable = { ROOT.monument_construction_state_5 = THIS.id } }
					}
					cancel_monument_construction = yes
				}
			}
			if = {
				limit = {
					NOT = { has_country_flag = monuments_are_getting_downgraded_after_war }
				}
				set_country_flag = monuments_are_getting_downgraded_after_war
			}
			else_if = {
				limit = {
					NOT = { has_country_flag = monuments_got_downgraded_after_war }
				}
				set_country_flag = monuments_got_downgraded_after_war
				country_event = { id = monuments_events.0 hours = 1 }
			}
			FROM = {
				every_state = {
					limit = {
						OR = {
							is_owned_by = PREV
							AND = {
								scope_for_monument_bonus_receiver_is_controller = yes
								is_controlled_by = PREV
							}
						}
						state_has_any_monument = yes
					}
					for_each_loop = {
						array = state_monuments_array
						set_temp_variable = { monument_id = v }
						set_monument_effects = yes
					}
				}
			}

			if = {
				limit = {
					has_global_flag = jap_has_declared_war_on_usa
					NOT = { has_global_flag = usa_has_won_def_war_against_jap }
					original_tag = USA
					FROM = {
						original_tag = JAP
					}
				}
				set_global_flag = usa_has_won_def_war_against_jap
			}
		}
	}

	# ROOT is the nuking country, FROM is the nuked state
	on_nuke_drop = {
		effect = {
			FROM = {
				if = {
					limit = {
						state_has_any_monument = yes
						set_scope_for_monument_bonus_receiver = yes
					}
					for_each_loop = {
						array = state_monuments_array
						set_temp_variable = { monument_id = v }
						if = {
							limit = {
								monument_can_downgrade = yes
							}
							downgrade_monument = yes
						}
						if = {
							limit = {
								has_monument_construction = yes
							}
							set_temp_variable = { show_popup = 1 }
							cancel_monument_construction = yes
						}
						if = {
							limit = {
								set_temp_variable = { level = 1 }
								has_less_monument_level = yes
							}
							ROOT = {
								PREV = {
									meta_effect = {
										text = {
											if = {
												limit = {
													has_state_flag = deactivated_monument_[ID]_@PREV
												}
												clr_state_flag = deactivated_monument_[ID]_@PREV
											}
										}
										ID = "[?monument_id]"
									}
								}
							}
							FROM = {
								PREV = {
									meta_effect = {
										text = {
											if = {
												limit = {
													has_state_flag = deactivated_monument_[ID]_@PREV
												}
												clr_state_flag = deactivated_monument_[ID]_@PREV
											}
										}
										ID = "[?monument_id]"
									}
								}
							}
						}
					}
				}
			}
		}
	}

	on_ruling_party_change = {
		effect = {
			every_state = {
				limit = {
					OR = {
						is_owned_by = ROOT
						AND = {
							scope_for_monument_bonus_receiver_is_controller = yes
							is_controlled_by = ROOT
						}
					}
					state_has_any_monument = yes
				}
				for_each_loop = {
					array = state_monuments_array
					set_temp_variable = { monument_id = v }
					set_monument_effects = yes
				}
			}
		}
	}

	# ROOT is the nation being liberated, FROM the leader of the liberators
	on_liberate = {
		effect = {
			every_state = {
				limit = {
					OR = {
						is_owned_by = ROOT
						AND = {
							scope_for_monument_bonus_receiver_is_controller = yes
							is_controlled_by = ROOT
						}
					}
					state_has_any_monument = yes
				}
				for_each_loop = {
					array = state_monuments_array
					set_temp_variable = { monument_id = v }
					set_monument_effects = yes
				}
			}
		}
	}

	# ROOT is the released nation, FROM the releaser
	on_release_as_free = {
		effect = {
			every_state = {
				limit = {
					OR = {
						is_owned_by = ROOT
						AND = {
							scope_for_monument_bonus_receiver_is_controller = yes
							is_controlled_by = ROOT
						}
					}
					state_has_any_monument = yes
				}
				for_each_loop = {
					array = state_monuments_array
					set_temp_variable = { monument_id = v }
					set_monument_effects = yes
				}
			}
		}
	}

	# ROOT is the released nation, FROM the releaser
	on_release_as_puppet = {
		effect = {
			every_state = {
				limit = {
					OR = {
						is_owned_by = ROOT
						AND = {
							scope_for_monument_bonus_receiver_is_controller = yes
							is_controlled_by = ROOT
						}
					}
					state_has_any_monument = yes
				}
				for_each_loop = {
					array = state_monuments_array
					set_temp_variable = { monument_id = v }
					set_monument_effects = yes
				}
			}
		}
	}

	# ROOT is the attacker, FROM is the defender
	on_war_relation_added = {
		effect = {
			if = {
				limit = {
					NOT = { has_global_flag = jap_has_declared_war_on_usa }
					original_tag = JAP
					FROM = {
						original_tag = USA
					}
				}
				set_global_flag = jap_has_declared_war_on_usa
			}
		}
	}
}