
namespace = CS

##NOTES:
## COURT SPLENDOR IS A VARIABLE TRACKED ON THE CAPITAL PROVINCE SCOPE AND WHICH GIVES A MODIFIER TO THE character_event
## If capital changes to a province without a court_splendor, assign the characters court splendor to the province (- a certain amount)
## Every 5 years, every province that is not a capital will suffer a large decrease
## If ruler dies, the next character will inherit the capital province and will be assigned that provinces court splendor
## 

## INITIALIZE COURT SPLENDOR - WORKING
character_event = {
	
	id = CS.10000
	hide_window = yes
	
	is_triggered_only = yes
	
	trigger = {
	is_save_game = no
	higher_real_tier_than = COUNT
	is_nomadic = no
	is_tribal = no
	}
	
	immediate = {
	if = {
		limit = {
			ai = no
		}
		log = "1: This event is running for [Root.GetTitledName]"
	}
	## Generates starting court splendor for every Duke, King, Emperor, and independent ruler
	## Variables to Use:
	## Tier level: Duke, King, Emperor. Important.
	## Demesne Size. Important. 
	## majesty tech
	## Yearly income. Very Important
	## Constantinople and Baghdad, special.
		capital_scope = {
			set_variable = { which = court_splendor value = 10 }
			if = {
				limit = {
					num_of_max_settlements = 7
					}
				change_variable = { which = court_splendor value = 16 }
				}
			else_if = {
				limit = {
					num_of_max_settlements = 6
					}
				change_variable = { which = court_splendor value = 12 }
				}
			else_if = {
				limit = {
					num_of_max_settlements = 5
					}
				change_variable = { which = court_splendor value = 8 }
				}
			else_if = {
				limit = {
					num_of_max_settlements = 4
					}
				change_variable = { which = court_splendor value = 3 }
				}
			else = {
			}
			if = {
				limit = {
				owner = {
					yearly_income = 800
					}
				}
				change_variable = { which = court_splendor value = 32 }	
			}
			else_if = {
				limit = {
				owner = {
					yearly_income = 700
				}
				}
				change_variable = { which = court_splendor value = 28 }
			}
			else_if = {
				limit = {
				owner = {
					yearly_income = 600
				}
				}
				change_variable = { which = court_splendor value = 24 }
			}
			else_if = {
				limit = {
				owner = {
					yearly_income = 500
				}
				}
				change_variable = { which = court_splendor value = 21 }
			}
			else_if = {
				limit = {
				owner = {
					yearly_income = 400
				}
				}
				change_variable = { which = court_splendor value = 18 }
				
			}
			else_if = {
				limit = {
				owner = {
					yearly_income = 300
				}
				}
				change_variable = { which = court_splendor value = 14 }
				
			}
			else_if = {
				limit = {
				owner = {
					yearly_income = 200
				}
				}
				change_variable = { which = court_splendor value = 10 }
				
			}
			else_if = {
				limit = {
				owner = {
					yearly_income = 100
				}
				}
				change_variable = { which = court_splendor value = 6 }
			}
			else_if = {
				limit = {
				owner = {
					yearly_income = 50
				}
				}
				change_variable = { which = court_splendor value = 4 }
			}
			else_if = {
				limit = {
				owner = {
					yearly_income = 25
				}
				}
				change_variable = { which = court_splendor value = 2 }
			}
			else = {
			}
			if = {
				limit = {
					TECH_MAJESTY = 7
				}
				multiply_variable = { which = court_splendor value = 1.5 }
			}
			else_if = {
				limit = {
					TECH_MAJESTY = 6
				}
				multiply_variable = { which = court_splendor value = 1.4 }
			}
			else_if = {
				limit = {
					TECH_MAJESTY = 5
				}
				multiply_variable = { which = court_splendor value = 1.3 }
			}
			else_if = {
				limit = {
					TECH_MAJESTY = 4
				}
				multiply_variable = { which = court_splendor value = 1.2 }
			}
			else_if = {
				limit = {
					TECH_MAJESTY = 3
				}
				multiply_variable = { which = court_splendor value = 1.1 }
			}
			else = {

			}
			if = {
				limit = {
					owner = { 
						tier = EMPEROR
					}
				}
				change_variable = { which = court_splendor value = 30 }
			}
			else_if = {
				limit = {
					owner = { 
						tier = KING
					}
				}
				change_variable = { which = court_splendor value = 18 }
			}
			else_if = {
				limit = {
					owner = { 
						tier = DUKE
					}
				}
				change_variable = { which = court_splendor value = 6 }
			}
			else = {
			}
			if = {
				limit = {
					OR = {
						province_id = 693
						province_id = 496
					AND = {
						province_id = 181
						NOT = { year = 1100}
					}
					}
				}
				change_variable = { which = court_splendor value = 10 }
			}

			if = {
				limit = {
					total_years_played = 5
				}
				multiply_variable = { which = court_splendor value = 0.6 }
			}
			
			### Now set the province flag.
			### Flag better than modifier I think...
			
			if = {
				limit = {
				check_variable = { which = court_splendor value = 125 }
				}
				set_province_flag = magnificent_court
				owner = {
					remove_court_modifier = yes
					set_variable = { which = court_splendor_character which = court_splendor} ### NOT SURE IF NECESSARY
					add_character_modifier = { name = magnificent_court duration = 140}
					add_character_modifier = { name = magnificent_court_maintenance duration = 140}
					if = {
					limit = {
					religion_group = muslim
					}
					add_character_modifier = { name = decadence7 duration = 140}
					}
				}
			}
			else_if = {
				limit = {
				check_variable = { which = court_splendor value = 100 }
				NOT = {
				check_variable = { which = court_splendor value = 125 }
				}
				}
				set_province_flag = grand_court
				owner = {
					remove_court_modifier = yes
					set_variable = { which = court_splendor_character which = court_splendor} ### NOT SURE IF NECESSARY
					add_character_modifier = { name = grand_court duration = 140}
					add_character_modifier = { name = grand_court_maintenance duration = 140}
					if = {
					limit = {
					religion_group = muslim
					}
					add_character_modifier = { name = decadence6 duration = 140}
					}
				}
			}
			else_if = {
				limit = {
				check_variable = { which = court_splendor value = 75 }
				NOT = {
				check_variable = { which = court_splendor value = 100 }
				}
				}
				set_province_flag = splendid_court
				owner = {
					remove_court_modifier = yes
					set_variable = { which = court_splendor_character which = court_splendor} ### NOT SURE IF NECESSARY
					add_character_modifier = { name = splendid_court duration = 140}
					add_character_modifier = { name = splendid_court_maintenance duration = 140}
					if = {
					limit = {
					religion_group = muslim
					}
					add_character_modifier = { name = decadence5 duration = 140}
					}
				}
			}
			else_if = {
				limit = {

				check_variable = { which = court_splendor value = 50 }
				NOT = {
				check_variable = { which = court_splendor value = 75 }
				}
				}
				set_province_flag = standard_court
				owner = {
					remove_court_modifier = yes
					set_variable = { which = court_splendor_character which = court_splendor} ### NOT SURE IF NECESSARY
					add_character_modifier = { name = standard_court duration = 140}
					add_character_modifier = { name = standard_court_maintenance duration = 140}
					if = {
					limit = {
					religion_group = muslim
					}
					add_character_modifier = { name = decadence4 duration = 140}
					}
				}
			}
			else_if = {
				limit = {
				check_variable = { which = court_splendor value = 30 }
				NOT = {
				check_variable = { which = court_splendor value = 49.9 }
				}
				}
				set_province_flag = acceptable_court
				owner = {
					remove_court_modifier = yes
					set_variable = { which = court_splendor_character which = court_splendor} ### NOT SURE IF NECESSARY
					add_character_modifier = { name = acceptable_court duration = 140}
					add_character_modifier = { name = acceptable_court_maintenance duration = 140}
					if = {
					limit = {
					religion_group = muslim
					}
					add_character_modifier = { name = decadence3 duration = 140}
					}
				}
			}
			else_if = {
				limit = {
				check_variable = { which = court_splendor value = 15 }
				NOT = {
				check_variable = { which = court_splendor value = 30 }
				}
				}
				set_province_flag = shabby_court
				owner = {
					remove_court_modifier = yes
					set_variable = { which = court_splendor which = court_splendor_character} ### NOT SURE IF NECESSARY
					add_character_modifier = { name = shabby_court duration = 140}
					add_character_modifier = { name = shabby_court_maintenance duration = 140}
					if = {
						limit = {
							religion_group = muslim
						}
						add_character_modifier = { name = decadence2 duration = 140}
					}
				}
			}
			else = {
			set_province_flag = abysmal_court
				owner = {
					remove_court_modifier = yes
					set_variable = { which = court_splendor which = court_splendor_character} ### NOT SURE IF NECESSARY
					add_character_modifier = { name = abysmal_court duration = 140}
					add_character_modifier = { name = abysmal_court_maintenance duration = 140}
					if = {
					limit = {
					religion_group = muslim
					}
					add_character_modifier = { name = decadence1 duration = 140}
					}
				}
			}
	
	
		}
		character_event = { id = CS.11000 days = 3}
	}
}

##Investment Event - working from before, whatever

long_character_event = {
	id = CS.10100
	
	is_triggered_only = yes
	
	desc = {
       trigger = { has_character_modifier = magnificent_court }
       text = EVT_DESC10100A
       picture = GFX_magnificent_court
     }
     desc = {
       trigger = { has_character_modifier = grand_court }
       text = EVT_DESC10100B
       picture = GFX_grand_court
     }
     desc = {
       trigger = { has_character_modifier = splendid_court }
       text = EVT_DESC10100C
       picture = GFX_splendid_court
     }
     desc = {
       trigger = { has_character_modifier = standard_court }
       text = EVT_DESC10100D
       picture = GFX_standard_court
     }
     desc = {
       trigger = { has_character_modifier = acceptable_court }
       text = EVT_DESC10100E
       picture = GFX_acceptable_court
     }
     desc = {
       trigger = { has_character_modifier = shabby_court }
       text = EVT_DESC10100F
       picture = GFX_shabby_court
     }
     desc = {
       trigger = { has_character_modifier = abysmal_court }
       text = EVT_DESC10100G
       picture = GFX_abysmal_court
     }
	
	option = {
		name = EVTOPTA_CS10100
		trigger = {
			OR = {
			has_character_modifier = magnificent_court
			}
			treasury = 1000 
		}
		treasury = -1000
		hidden_tooltip = {
		add_character_modifier = { name = recent_investment duration = 60 }
			if = {
				limit = {
					has_character_modifier = magnificent_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 4 }
				}
			}
		}
	}
	option = {
		name = EVTOPTB_CS10100
		trigger = {
			OR = {
			has_character_modifier = magnificent_court
			has_character_modifier = grand_court
			has_character_modifier = splendid_court
			}
			treasury = 500 
		}
		treasury = -500
		hidden_tooltip = {
		add_character_modifier = { name = recent_investment duration = 60 }
			if = {
				limit = {
					has_character_modifier = magnificent_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 2 }
				}
			}
			if = {
				limit = {
					has_character_modifier = grand_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 3.33 }
				}
			}
			if = {
				limit = {
					has_character_modifier = splendid_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 6.67 }
				}
			}
		}
	}
	option = {
		name = EVTOPTC_CS10100
		trigger = {
			OR = {
			has_character_modifier = magnificent_court
			has_character_modifier = grand_court
			has_character_modifier = splendid_court
			has_character_modifier = standard_court
			}
			treasury = 200 
		}
		treasury = -200
		hidden_tooltip = {
		add_character_modifier = { name = recent_investment duration = 60 }
			if = {
				limit = {
					has_character_modifier = magnificent_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 0.8 }
				}
			}
			if = {
				limit = {
					has_character_modifier = grand_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 1.33 }
				}
			}
			if = {
				limit = {
					has_character_modifier = splendid_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 2.67 }
				}
			}
			if = {
				limit = {
					has_character_modifier = standard_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 5 }
				}
			}
		}
	}
	option = {
		name = EVTOPTD_CS10100
		trigger = {
			OR = {
			has_character_modifier = grand_court
			has_character_modifier = splendid_court
			has_character_modifier = standard_court
			has_character_modifier = acceptable_court}
			treasury = 100 
		}
		treasury = -100
		hidden_tooltip = {
		add_character_modifier = { name = recent_investment duration = 60 }
			if = {
				limit = {
					has_character_modifier = grand_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 0.67 }
				}
			}
			if = {
				limit = {
					has_character_modifier = splendid_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 1.33 }
				}
			}
			if = {
				limit = {
					has_character_modifier = standard_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 2.5 }
				}
			}
			if = {
				limit = {
					has_character_modifier = acceptable_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 5 }
				}
			}
		}
	}
	option = {
		name = EVTOPTE_CS10100
		trigger = {
			OR = {
			has_character_modifier = standard_court
			has_character_modifier = acceptable_court
			has_character_modifier = shabby_court
			has_character_modifier = abysmal_court }
			wealth = 50 
		}
		treasury = -50
		hidden_tooltip = {
		add_character_modifier = { name = recent_investment duration = 60 }
			if = {
				limit = {
					has_character_modifier = standard_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 1.25 }
				}
			}
			if = {
				limit = {
					has_character_modifier = acceptable_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 2.5 }
				}
			}
			if = {
				limit = {
					has_character_modifier = shabby_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 5 }
				}
			}
			if = {
				limit = {
					has_character_modifier = abysmal_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 10 }
				}
			}
		}
	}
	option = {
		name = EVTOPTF_CS10100
		trigger = {
			OR = {
			has_character_modifier = acceptable_court
			has_character_modifier = shabby_court
			has_character_modifier = abysmal_court }
			wealth = 20 
		}
		treasury = -20
		hidden_tooltip = {
		add_character_modifier = { name = recent_investment duration = 60 }
			if = {
				limit = {
					has_character_modifier = acceptable_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 1 }
				}
			}
			if = {
				limit = {
					has_character_modifier = shabby_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 2 }
				}
			}
			if = {
				limit = {
					has_character_modifier = abysmal_court
				}
				capital_scope = {
				change_variable = 	{ which = court_splendor value = 4 }
				}
			}
		}
	}
	option = {
		name = EVTOPTG_CS10100
	}
}

## Decay - COMPLETE, PARTIALLY TESTED. NEED TO TEST IF CHAR AND PROVICNE DONT HAVE MODIFIER (initialization case
character_event = {

	id = CS.11000
	hide_window = yes
	
	is_triggered_only = yes

	trigger = {
		higher_real_tier_than = COUNT
		NOT = { has_character_modifier = decay_event_active}
		}
	
	immediate = {
		add_character_modifier = { name = decay_event_active duration = 90 }
		if = {
		limit = {
			FROM = { ai = no }
		}
		log = "2: This event is running for [Root.GetTitledName]"
		}
		if = {
			limit = {
				NOT = { has_character_flag = decay_active}
			}
			set_character_flag = decay_active
		}
		capital_scope = {
		## First check if for some reason the capital does not have any flag
			if = {
				limit = {
					NOT = {
							check_variable = { which = court_splendor value = 0.1}
							}
				}
				owner = {
					if = {
						limit = {
							has_character_modifier = magnificent_court
							}
					capital_scope = {
						set_variable = { which = court_splendor value = 100} ## Lower because changing capital should reduce splendor
						##remove_character_modifier = magnificent_court
						##remove_character_modifier = magnificent_court_maintenance
						##add_character_modifier = { name = grand_court duration = -1}
						}
					}
					else_if = {
						limit = {
							has_character_modifier = grand_court
							}
					capital_scope = {
						set_variable = { which = court_splendor value = 75} ## Lower because changing capital should reduce splendor
						}
					}
					else_if = {
						limit = {
							has_character_modifier = splendid_court
							}
					capital_scope = {
						set_variable = { which = court_splendor value = 55} ## Lower because changing capital should reduce splendor
						}
					}
					else_if = {
						limit = {
							has_character_modifier = standard_court
							}
					capital_scope = {
						set_variable = { which = court_splendor value = 35} ## Lower because changing capital should reduce splendor
						}
					}
					else_if = {
						limit = {
							has_character_modifier = acceptable_court
							}
					capital_scope = {
						set_variable = { which = court_splendor value = 20} ## Lower because changing capital should reduce splendor
						}
					}
					else_if = {
						limit = {
							has_character_modifier = shabby_court
							}
					capital_scope = {
						set_variable = { which = court_splendor value = 7} ## Lower because changing capital should reduce splendor
						}
					}
					else = {
						character_event = {
						id = CS.10000
						}
					}
				}
			}
	## Magnificent court
			if = {
				limit = {
				check_variable = { which = court_splendor value = 125 }
				}
				owner = {
					if = {
						limit = {
							NOT = {
							OR = {
								has_character_modifier = magnificent_court
								has_character_modifier = magnificent_court_maintenance
								}
								}
							}
						remove_court_modifier = yes
						add_character_modifier = { name = magnificent_court duration = 140}
						add_character_modifier = { name = magnificent_court_maintenance duration = 140}
					}
					if = {
							limit = {
							religion_group = muslim
							NOT = {
							has_character_modifier = decadence7
							}
							}
							remove_character_modifier = decadence1
							remove_character_modifier = decadence2
							remove_character_modifier = decadence3
							remove_character_modifier = decadence4
							remove_character_modifier = decadence5
							remove_character_modifier = decadence6
							add_character_modifier = { name = decadence7 duration = 140}
						}
				}
					
								
				if = {
					limit = {
						owner = {
							has_character_modifier = magnificent_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.2}
				}
				else_if = {
				limit = {
						owner = {
							has_character_modifier = grand_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.3}
				}
				else_if = {
				limit = {
						owner = {
							has_character_modifier = splendid_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.5}
				}
				else = {
					subtract_variable = { which = court_splendor value = 0.75}
				}
				if = {
					limit = {
						NOT = {check_variable = { which = court_splendor value = 125 }}
					}
					set_province_flag = grand_court
					owner = {
						if = {
							limit = {
								has_character_modifier = magnificent_court_maintenance
								}
							remove_character_modifier = magnificent_court_maintenance
							add_character_modifier = { name = grand_court_maintenance duration = 140}
						}
						remove_character_modifier = magnificent_court
						add_character_modifier = { name = grand_court duration = 140}
					}
				}
					
			}
			
			## GRAND COURT
			if = {
				limit = {
				check_variable = { which = court_splendor value = 100 }
				NOT = {
				check_variable = { which = court_splendor value = 125 }
				}
				}
				owner = {
					if = {
						limit = {
							NOT = {
							OR = {
								has_character_modifier = grand_court
								has_character_modifier = grand_court_maintenance
								}
								}
							}
						remove_court_modifier = yes
						add_character_modifier = { name = grand_court duration = 140}
						add_character_modifier = { name = grand_court_maintenance duration = 140}
				
					}
					if = {
							limit = {
							religion_group = muslim
							NOT = {
							has_character_modifier = decadence6
							}
							}
							remove_character_modifier = decadence1
							remove_character_modifier = decadence2
							remove_character_modifier = decadence3
							remove_character_modifier = decadence4
							remove_character_modifier = decadence5
							remove_character_modifier = decadence7
							add_character_modifier = { name = decadence6 duration = 140}
						}
				}
				if = {
					limit = {
						owner = {
							has_character_modifier = grand_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.2}
				}
				else_if = {
				limit = {
						owner = {
							has_character_modifier = splendid_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.3}
				}
				else_if = {
				limit = {
						owner = {
							has_character_modifier = standard_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.5}
				}
				else = {
					subtract_variable = { which = court_splendor value = 0.75}
				}
				if = {
					limit = {
						NOT = {check_variable = { which = court_splendor value = 100 }}
					}
					set_province_flag = splendid_court
					owner = {
						if = {
							limit = {
								has_character_modifier = grand_court_maintenance
								}
							remove_character_modifier = grand_court_maintenance
							add_character_modifier = { name = splendid_court_maintenance duration = 140}
						}
						remove_character_modifier = grand_court
						add_character_modifier = { name = splendid_court duration = 140}
					}
				}	
			}
			
			## SPLENDID COURT
			if = {
				limit = {
				check_variable = { which = court_splendor value = 75 }
				NOT = {
				check_variable = { which = court_splendor value = 100 }
				}
				}
				owner = {
					if = {
						limit = {
							NOT = {
							OR = {
								has_character_modifier = splendid_court
								has_character_modifier = splendid_court_maintenance
								}
								}
							}
						remove_court_modifier = yes
						add_character_modifier = { name = splendid_court duration = 140}
						add_character_modifier = { name = splendid_court_maintenance duration = 140}
					
					}
					if = {
							limit = {
							religion_group = muslim
							NOT = {
							has_character_modifier = decadence5
							}
							}
							remove_character_modifier = decadence1
							remove_character_modifier = decadence2
							remove_character_modifier = decadence3
							remove_character_modifier = decadence4
							remove_character_modifier = decadence7
							remove_character_modifier = decadence6
							add_character_modifier = { name = decadence5 duration = 140}
						}
				}
				if = {
					limit = {
						owner = {
							has_character_modifier = splendid_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.2}
				}
				else_if = {
				limit = {
						owner = {
							has_character_modifier = standard_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.3}
				}
				else_if = {
				limit = {
						owner = {
							has_character_modifier = acceptable_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.5}
				}
				else = {
					subtract_variable = { which = court_splendor value = 0.75}
				}
				
				if = {
					limit = {
						NOT = {check_variable = { which = court_splendor value = 75 }}
					}
					set_province_flag = standard_court
					owner = {
						if = {
							limit = {
								has_character_modifier = splendid_court_maintenance
								}
							remove_character_modifier = splendid_court_maintenance
							add_character_modifier = { name = standard_court_maintenance duration = 140}
						}
						remove_character_modifier = splendid_court
						add_character_modifier = { name = standard_court duration = 140}
					}
				}
					
			}
			
			### STANDARD COURT
			if = {
				limit = {
				check_variable = { which = court_splendor value = 50 }
				NOT = {
				check_variable = { which = court_splendor value = 75 }
				}
				}
				owner = {
					if = {
						limit = {
							NOT = {
							OR = {
								has_character_modifier = standard_court
								has_character_modifier = standard_court_maintenance
								}
								}
							}
						remove_court_modifier = yes
						add_character_modifier = { name = standard_court duration = 140}
						add_character_modifier = { name = standard_court_maintenance duration = 140}
						
					}
					if = {
							limit = {
							religion_group = muslim
							NOT = {
							has_character_modifier = decadence4
							}
							}
							remove_character_modifier = decadence1
							remove_character_modifier = decadence2
							remove_character_modifier = decadence3
							remove_character_modifier = decadence7
							remove_character_modifier = decadence5
							remove_character_modifier = decadence6
							add_character_modifier = { name = decadence4 duration = 140}
						}
				}
				if = {
					limit = {
						owner = {
							has_character_modifier = standard_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.2}
				}
				else_if = {
				limit = {
						owner = {
							has_character_modifier = acceptable_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.3}
				}
				else_if = {
				limit = {
						owner = {
							has_character_modifier = shabby_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.5}
				}
				else = {
					subtract_variable = { which = court_splendor value = 0.75}
				}
				
				if = {
					limit = {
						NOT = {check_variable = { which = court_splendor value = 50 }}
					}
					set_province_flag = acceptable_court
					owner = {
						if = {
							limit = {
								has_character_modifier = standard_court_maintenance
								}
							remove_character_modifier = standard_court_maintenance
							add_character_modifier = { name = acceptable_court_maintenance duration = 140}
						}
						remove_character_modifier = standard_court
						add_character_modifier = { name = acceptable_court duration = 140}
					}
				}
					
			}
			
			## ACCEPTABLE COURT
			if = {
				limit = {
				check_variable = { which = court_splendor value = 30 }
				NOT = {
				check_variable = { which = court_splendor value = 50 }
				}
				}
				owner = {
					if = {
						limit = {
							NOT = {
							OR = {
								has_character_modifier = acceptable_court
								has_character_modifier = acceptable_court_maintenance
								}
								}
							}
						remove_court_modifier = yes
						add_character_modifier = { name = acceptable_court duration = 140}
						add_character_modifier = { name = acceptable_court_maintenance duration = 140}
						
					}
					if = {
							limit = {
							religion_group = muslim
							NOT = {
							has_character_modifier = decadence7
							}
							}
							remove_character_modifier = decadence1
							remove_character_modifier = decadence2
							remove_character_modifier = decadence7
							remove_character_modifier = decadence4
							remove_character_modifier = decadence5
							remove_character_modifier = decadence6
							add_character_modifier = { name = decadence3 duration = 140}
						}
				}
				if = {
					limit = {
						owner = {
							has_character_modifier = acceptable_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.2}
				}
				else_if = {
				limit = {
						owner = {
							has_character_modifier = shabby_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.3}
				}
				else = {
					subtract_variable = { which = court_splendor value = 0.5}
					}
				
				if = {
					limit = {
						NOT = {check_variable = { which = court_splendor value = 30 }}
					}
					set_province_flag = shabby_court
					owner = {
						if = {
							limit = {
								has_character_modifier = acceptable_court_maintenance
								}
							remove_character_modifier = acceptable_court_maintenance
							add_character_modifier = { name = shabby_court_maintenance duration = 140}
						}
						remove_character_modifier = acceptable_court
						add_character_modifier = { name = shabby_court duration = 140}
					}
				}
					
			}
			
			### Shabby court
			if = {
				limit = {
				check_variable = { which = court_splendor value = 15 }
				NOT = {
				check_variable = { which = court_splendor value = 30 }
				}
				}
				owner = {
					if = {
						limit = {
							NOT = {
							OR = {
								has_character_modifier = shabby_court
								has_character_modifier = shabby_court_maintenance
								}
								}
							}
						remove_court_modifier = yes
						add_character_modifier = { name = shabby_court duration = 140}
						add_character_modifier = { name = shabby_court_maintenance duration = 140}
					}
					if = {
							limit = {
							religion_group = muslim
							NOT = {
							has_character_modifier = decadence2
							}
							}
							remove_character_modifier = decadence1
							remove_character_modifier = decadence7
							remove_character_modifier = decadence3
							remove_character_modifier = decadence4
							remove_character_modifier = decadence5
							remove_character_modifier = decadence6
							add_character_modifier = { name = decadence2 duration = 140}
						}
				}
				if = {
				limit = {
						owner = {
							has_character_modifier = shabby_court_maintenance
						}
					}
					subtract_variable = { which = court_splendor value = 0.2}
				}
				else = {
					subtract_variable = { which = court_splendor value = 0.3}
					}
				
				if = {
					limit = {
						NOT = {check_variable = { which = court_splendor value = 15 }}
					}
					set_province_flag = abysmal_court
					owner = {
						if = {
							limit = {
								has_character_modifier = shabby_court_maintenance
								}
							remove_character_modifier = shabby_court_maintenance
							add_character_modifier = { name = abysmal_court_maintenance duration = 140}
						}
						remove_character_modifier = shabby_court
						add_character_modifier = { name = abysmal_court duration = 140}
					}
				}
					
			}
			
			### Abysmal Court Failsafe
			if = {
				limit = {
				check_variable = { which = court_splendor value = 0 }
				NOT = {
				check_variable = { which = court_splendor value = 15 }
				}
				}
				owner = {
					if = {
						limit = {
							NOT = {
							OR = {
								has_character_modifier = abysmal_court
								has_character_modifier = abysmal_court_maintenance
								}
								}
							}
						remove_court_modifier = yes
						add_character_modifier = { name = abysmal_court duration = 140}
						add_character_modifier = { name = abysmal_court_maintenance duration = 140}
					}
					if = {
							limit = {
							religion_group = muslim
							NOT = {
							has_character_modifier = decadence1
							}
							}
							remove_character_modifier = decadence2
							remove_character_modifier = decadence7
							remove_character_modifier = decadence3
							remove_character_modifier = decadence4
							remove_character_modifier = decadence5
							remove_character_modifier = decadence6
							add_character_modifier = { name = decadence1 duration = 140}
						}
				}
				
				if = {
					limit = {
						NOT = {check_variable = { which = court_splendor value = 1 }}
					}
					set_variable = { which = court_splendor value = 1 }
				}
			}
			ROOT = {
				set_variable = { which = court_splendor which = PREV}
			}
		}

		## Just since I need courtsplendor to be character...

		## AI EVENTS
		character_event = {
			id = CS.13000
		}

		## AUTONOMY
		character_event = {
			id = CS.12000
		}
			
			
			## CHAIN EVENTS
			
		character_event = {
			id = CS.11000
			days = 91
		}	
	}
}

## AUTONOMY
character_event = {
	id = CS.12000
	hide_window = yes
	is_triggered_only = yes

	trigger = {
		higher_real_tier_than = COUNT
		independent = yes
		is_nomadic = no
		is_tribal = no
	}
	immediate = {
		set_variable = { which = autonomy value = 0}
		set_variable = { which = autonomy1 value = 0 }
		set_variable = { which = levies_provided value = 0}

		determine_min_levy = yes

		determine_max_levy = yes
		
		set_variable = { which = vassal_levies value = 0}
		set_variable = { which = income_temp value = 0 }
		set_variable = { which = vassal_levies1 value = 0}
		set_variable = { which = vassal_levies2 value = 0}
		any_vassal = {

			character_event = {
				id = CS.12100
				days = 1
			}
			character_event = {
				id = CS.12105
				days = 4
			}
			character_event = {
				id = CS.12210
				days = 7
			}
		}
		character_event = {
				id = CS.12200
				days = 11
		}
	}
	
}

character_event = {
	id = CS.12100
	hide_window = yes

	is_triggered_only = yes

	trigger = {
		higher_real_tier_than = COUNT
	}

	immediate = {
		FROM = {
			set_variable = { which = court_splendor_temp which = court_splendor }
		set_variable = { which = minmax_levy which = min_levy }
		divide_variable = { which = minmax_levy which = max_levy}
		}

		set_variable = { which = income_liege_temp value = 0}
		set_variable = { which = levies_liege_temp value = 0}
		set_variable = { which = levies_temp value = 0}
		set_variable = { which = income_temp value = 0}
		export_to_variable = { which = income_liege_temp value = yearly_income who = FROM}
		export_to_variable = { which = levies_liege_temp value = realm_levies who = FROM}


		export_to_variable = { which = levies_temp value = realm_levies}
		 ## NEED TO CHECK IF THE WAR MODIFIER IS ON OR NOT

		export_to_variable = { which = income_temp value = yearly_income}

		set_variable = { which = debug_income which = income_temp }
		set_variable = { which = court_splendor_temp which = court_splendor}
		set_variable = { which = autonomy value = 2 }

		divide_variable = { which = court_splendor_temp which = FROM }
		multiply_variable = { which = court_splendor_temp value = 1.8 } ## Lets say 0.3
		divide_variable = { which = income_temp which = income_liege_temp} ## Lets say 0.2
		multiply_variable = { which = income_temp value = 1.2 }
		divide_variable = { which = levies_temp which = levies_liege_temp} ## lets say 0.2
		multiply_variable = { which = levies_temp value = 1.33 }
		set_variable = { which = debug_rel_income which = income_temp }
		change_variable = { which = autonomy which = court_splendor_temp }
		change_variable = { which = autonomy which = income_temp }
		change_variable = { which = autonomy which = levies_temp }
		## High of ~6.4 Then distance modifier pushes it up more

		## DISTANCE
		FROM = {
			capital_scope = {
				ROOT = {
					capital_scope = {
						if = {
							limit = {
								distance = { who = PREVPREV value = 900 }
							}
							ROOT = { 
								set_variable = { which = distance_modifier value = 2.5}
							}
						}
						else_if = {
							limit = {
								distance = { who = PREVPREV value = 750 }
							}
							ROOT = { 
								set_variable = { which = distance_modifier value = 2.2 }
							}
						}
						else_if = {
							limit = {
								distance = { who = PREVPREV value = 600 }
							}
							ROOT = { 
								set_variable = { which = distance_modifier value = 1.82 }
							}
						}
						else_if = {
							limit = {
								distance = { who = PREVPREV value = 500 }
							}
							ROOT = { 
								set_variable = { which = distance_modifier value = 1.67 }
							}
						}
						else_if = {
							limit = {
								distance = { who = PREVPREV value = 400 }
							}
							ROOT = { 
								set_variable = { which = distance_modifier value = 1.51 }
							}
						}
						else_if = {
							limit = {
								distance = { who = PREVPREV value = 300 }
							}
							ROOT = { 
								set_variable = { which = distance_modifier value = 1.37 }
							}
						}
						else_if = {
							limit = {
								distance = { who = PREVPREV value = 200 }
							}
							ROOT = { 
								set_variable = { which = distance_modifier value = 1.25 }
							}
						}
						else = {
							ROOT = {
								set_variable = { which = distance_modifier value = 1 }
							}
						}
					}
				}
			}
		}

		multiply_variable = { which = autonomy which = distance_modifier }

		set_variable = { which = autonomy1 which = autonomy}

		## Calculate Effect of centralization

		## CONCLAVE SPLITS CENTRALIZATION INTO 2, SO LETS DO BOTH
		if = {
			limit = {
				FROM = { has_law = crown_authority_4 }
			}
			multiply_variable = { which = autonomy value = 0.5 }
			if = {
				limit = {
					check_variable = { which = autonomy1 value = 5 }
				}
				opinion = { modifier = too_much_authority_4 who = FROM days = 90 }
			}
		}
		else_if = {
			limit = {
				FROM = { has_law = crown_authority_3 }
			}
			multiply_variable = { which = autonomy value = 0.67 }
			if = {
				limit = {
					check_variable = { which = autonomy1 value = 2 }
				}
				opinion = { modifier = too_much_authority_3 who = FROM days = 90 }
			}
		}
		else_if = {
			limit = {
				FROM = { has_law = crown_authority_2 }
			}
			multiply_variable = { which = autonomy value = 0.78 }
			if = {
				limit = {
					check_variable = { which = autonomy1 value = 2 }
				}
				opinion = { modifier = too_much_authority_2 who = FROM days = 90 }
			}
		}
		else_if = {
			limit = {
				FROM = { has_law = crown_authority_1 }
			}
			multiply_variable = { which = autonomy value = 0.9 }
			if = {
				limit = {
					check_variable = { which = autonomy1 value = 2 }
				}
				opinion = { modifier = too_much_authority_1 who = FROM days = 90 }
			}
		}
		else = {

		}


		if = {
			limit = {
				FROM = { has_law = administration_2 }
			}
			multiply_variable = { which = autonomy value = 0.62 }
		}
		else_if = {
			limit = {
				FROM = { has_law = administration_1 }
			}
			multiply_variable = { which = autonomy value = 0.8 }
		}
		else = {

		}


		calculate_autonomy_modifier = yes

		## TAX ADJUSTMENT
		## total income - income temp * tax policy 

		set_variable = { which = tax_adjustment value = 0 }

		if = {
			limit = {
				FROM = { has_law = feudal_slider_4 }
			}
			change_variable = { which = tax_adjustment value = 0.12 }
		}
		else_if = {
			limit = {
				FROM = { has_law = feudal_slider_3 }
			}
			change_variable = { which = tax_adjustment value = 0.09}
		}
		else_if = {
			limit = {
				FROM = { has_law = feudal_slider_2 }
			}
			change_variable = { which = tax_adjustment value = 0.06 }
		}
		else_if = {
			limit = {
				FROM = { has_law = feudal_slider_1 }
			}
			change_variable = { which = tax_adjustment value = 0.03 }
		}
		else = {

		}

		if = {
			limit = {
				FROM = { has_law = feudal_obligations_4 }
			}
			change_variable = { which = tax_adjustment value = 0.18 }
		}
		else_if = {
			limit = {
				FROM = { has_law = feudal_obligations_3 }
			}
			change_variable = { which = tax_adjustment value = 0.135}
		}
		else_if = {
			limit = {
				FROM = { has_law = feudal_obligations_2 }
			}
			change_variable = { which = tax_adjustment value = 0.09 }
		}
		else_if = {
			limit = {
				FROM = { has_law = feudal_obligations_1 }
			}
			change_variable = { which = tax_adjustment value = 0.045 }
		}
		else = {

		}


		if = {
			limit = {
				FROM = { has_law = iqta_slider_4 }
			}
			set_character_flag = whatsgoingon1
			change_variable = { which = tax_adjustment value = 0.14 }
		}
		else_if = {
			limit = {
				FROM = { has_law = iqta_slider_3 }
			}
			set_character_flag = whatsgoingon2
			change_variable = { which = tax_adjustment value = 0.11}
		}
		else_if = {
			limit = {
				FROM = { has_law = iqta_slider_2 }
			}
			set_character_flag = whatsgoingon3
			change_variable = { which = tax_adjustment value = 0.07 }
		}
		else_if = {
			limit = {
				FROM = { has_law = iqta_slider_1 }
			}
			set_character_flag = whatsgoingon4
			change_variable = { which = tax_adjustment value = 0.035 }
		}
		else = {

		}

		if = {
			limit = {
				FROM = { has_law = iqta_obligations_4 }
			}
			set_character_flag = whatsgoingon5
			change_variable = { which = tax_adjustment value = 0.210 }
		}
		else_if = {
			limit = {
				FROM = { has_law = iqta_obligations_3 }
			}
			set_character_flag = whatsgoingon6
			change_variable = { which = tax_adjustment value = 0.157}
		}
		else_if = {
			limit = {
				FROM = { has_law = iqta_obligations_2 }
			}
			set_character_flag = whatsgoingon7
			change_variable = { which = tax_adjustment value = 0.105 }
		}
		else_if = {
			limit = {
				FROM = { has_law = iqta_obligations_1 }
			}
			set_character_flag = whatsgoingon8
			change_variable = { which = tax_adjustment value = 0.053 }
		}
		else = {

		}

		multiply_variable = { which = income_temp which = tax_adjustment} ## 8. 0.04
		multiply_variable = { which = income_temp which = autonomy_modifier} ## 6. # 0.03

		## This should be enough

		if = {
			limit = {
				FROM = { ai = no }
			}
			log = "3: [Root.GetTitledName] has [Root.income_temp.GetValue]"
		}

		

		FROM = {
			change_variable = { which = income_temp which = ROOT }
		}

		if = {
			limit = {
				FROM = { ai = no }
			}
			log = "4: [From.GetTitledName] is currently [From.income_temp.GetValue]"
		}

		

		## Say 500 is Liege tax
		## 200 is vassal income
		## income_temp = 0.4
		## Tax adjustment is 10%
		## Income_temp = 0.04
		## So normally, 492 is the total liege tax, and 8 comes from this vassal
		## Okay. Now with Autonomy modifier of say 25%
		## Income_temp = 0.01
		## Now, instead of 500, liege tax is.. 494 (only 2 comes from the vassal)
		## What is the adjustment? 494/500 = 98.8% 
		## 1.2% is the adjustment
		## 40% * (change in amount paid)
		## 40% * (income_temp-income_tempnew)
		## 40% * 0.03 = 0.012 which is the adjustment

		add_autonomy_to_disp = yes


		## Now do the calculations...

		## I have total vassal levies already
		## So... 


		
	}
}

character_event = {
	id = CS.12105

	hide_window = yes

	is_triggered_only = yes

	trigger = {
		higher_real_tier_than = BARON
	}

	immediate = {
		set_variable = { which = min_levy which = FROM}
		set_variable = { which = max_levy which = FROM}

		export_to_variable = { which = realm_levies1 value = realm_levies}
		
		determine_opinion_modifier = yes

		set_variable = { which = levies_provided which = opinion_temp}
		multiply_variable = { which = levies_provided which = max_levy}

		set_variable = { which = levies_provided1 which = levies_provided}
		divide_variable = { which = levies_provided1 which = min_levy }

		if = {
			limit = {
				check_variable = { which = levies_provided1 value = 1} ## Then levyadjustment is bigger
			}

		}
		else = {
		 	set_variable = { which = levies_provided which = min_levy} ## okay...
		}

		multiply_variable = { which = levies_provided which = realm_levies1 }
		## AND NOW BECAUSE THE GAME IS RETARDED

		FROM = {
			change_variable = { which = levies_provided which = ROOT}
			
		}

	}

}

character_event = {
	id = CS.12210

	hide_window = yes

	is_triggered_only = yes

	trigger = {
		higher_real_tier_than = COUNT
		is_nomadic = no
		is_tribal = no
	}

	immediate = {

		FROM = {
			set_variable = { which = vassal_levies which = levies_provided}
		}

		set_variable = { which = vassal_levies which = FROM }
		if = {
			limit = {
				check_variable = { which = autonomy value = 4}
			}
			set_variable = { which = vassal_levies1 which = vassal_levies}
			multiply_variable = { which = levies_provided value = 0.5 }
			subtract_variable = { which = vassal_levies1 which = levies_provided}
			set_variable = { which = debugsubtractcommand which = vassal_levies1}
			divide_variable = { which = vassal_levies1 which = vassal_levies}
			subtract_variable = { which = vassal_levies1 value = 1}
			multiply_variable = { which = vassal_levies1 value = -1} ## This is the amount to adjust max levy by
			set_variable = { which = vassal_levies2 which = vassal_levies1}
			multiply_variable = { which = vassal_levies2 which = minmax_levy} ## amount min levy to be adjusted by

			FROM = {
			change_variable = { which = vassal_levies1 which = ROOT}
			change_variable = { which = vassal_levies2 which = ROOT}
			}
		}
	}
}


character_event = {
	id = CS.12200

	hide_window = yes

	is_triggered_only = yes

	immediate = {
		set_variable = { which = my_income value = 0}
		if = {
			limit = {
				ai = no
			}
			log = "5: [Root.GetTitledName] is currently [Root.income_temp.GetValue]"
		}
		export_to_variable = { which = my_income value = monthly_income }
		multiply_variable = { which = income_temp which = my_income }
		if = {
			limit = {
				ai = no
			}
			log = "6: [Root.GetTitledName] is currently [Root.income_temp.GetValue]"
		}
		assign_income_modifier = yes
		if = {
			limit = {
				OR = {
					NOT = { has_character_flag = called_levies}
					war = no
				}
			}
			change_laws_minmaxlevy = yes
		}
	}	
}

## AI ACCEPTS REQUEST
character_event = {
	id = CS.15200

	hide_window = yes
	is_triggered_only = yes

	immediate = {
		top_liege = {
			letter_event = { id = CS.15500 days = 1 random = 2} 
			subtract_variable = { which = vassal_levies1 which = ROOT}
			change_laws_minmaxlevy = yes
		}
	}
}


## CHARACTER RECEIVES REQUEST - FINISH LATER

## AI REJECTS REQUEST
character_event = {
	id = CS.15300

	hide_window = yes
	is_triggered_only = yes

	immediate = {
		set_character_flag = gotthisfar
		liege = {
			letter_event = { id = CS.15501 days = 1 random = 2} 
		}
	}
}

letter_event = {
	id = CS.15500
	desc = EVTDESC_CS15500
	is_triggered_only = yes

	immediate = {
		opinion = { modifier = aided_in_war who = FROM years = 3 }
		if = {
			limit = {
				reverse_has_opinion_modifier = { who = FROM modifier = called_into_war years = 5}
			}
			reverse_opinion = { modifier = called_into_war_again who = FROM years = 5 }
		}
		else = {
			reverse_opinion = { modifier = called_into_war who = FROM years = 5 }
		}
	}

	option = {
		name = EVTOPTACS15500
	}
}

letter_event = {
	id = CS.15501
	desc = EVTDESC_CS15501
	is_triggered_only = yes


	option = { ## INSULT THEM
		name = EVTOPTACS15501
		opinion = { modifier = refused_call_1 who = FROM years = 5 }
		reverse_opinion = { modifier = insulted_me_CS who = FROM years = 5}
	}

	option = { ## LET IT GO
		name = EVTOPTBCS15501
		opinion = { modifier = refused_call_2 who = FROM years = 5 }
	}
}

## End war maintenance

character_event = {
	id = CS.15100

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		independent = yes
		war = no
		has_character_flag = called_levies
	}
	immediate = {
		clr_character_flag = called_levies
		any_vassal = {
			clr_character_flag = accepted_request
		}
	}
}

## When capital sieged, decrease court splendor

character_event = {
	id = CS.18000

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		check_variable = { which = court_splendor value = 10}
		FROM = { is_capital = yes} ## Does this fucking thing even work
	}
	## 
	immediate = {
		capital_scope = {
			random_list = {
				10 = {
					change_variable = { which = court_splendor value = -20}
				}
				10 = {
					change_variable = { which = court_splendor value = -10}
				}
				10 = {
					change_variable = { which = court_splendor value = -30}
				}
				10 = {
					multiply_variable = { which = court_splendor value = 0.75}
				}
			}
		}
	}
}

## New Ruler Inherits Title with cap province

character_event = {
	id = CS.19000

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		higher_real_tier_than = COUNT
		NOT = { has_character_flag = decay_active}
	}

	immediate = {
		if = {
			limit = {
				capital_scope = {
					check_variable = { which = court_splendor value = 0.1}
				}
			}
			character_event = { id = CS.11000 days = 1}
		}
		else = {
			character_event = { id = CS.10000 days = 1}
		}
	}
}

## Catch if ruler has no modifier (generated or something)

character_event = {
	id = CS.21000

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		higher_real_tier_than = COUNT
		is_nomadic = no
		is_tribal = no
		NOT = { has_character_flag = maintenance_event }
	}

	immediate = {
		set_character_flag = maintenance_event
		if = {
			limit = {
				war = no
				has_character_flag = accepted_request
			}
			clr_character_flag = accepted_request
		}
		if = {
			limit = {
				war = no
				has_character_flag = called_levies
			}
			clr_character_flag = called_levies
		}
		if = {
			limit = {
				NOT = { has_character_flag = decay_active}
			}
			if = {
					limit = {
						ai = no
					}
					log = "7: This event is running for [Root.GetTitledName]"
				}
			if = {
				limit = {
					capital_scope = {
					check_variable = { which = court_splendor value = 0.1}
					}
				}
				character_event = { id = CS.11000 days = 1}
			}
			else = {
				character_event = { id = CS.10000 days = 1}
			}
		}

		character_event = { id = CS.21050 days = 30}
	}
}

character_event = {
	id = CS.21050

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		higher_real_tier_than = COUNT
		NOT = { month = 10 }
		is_nomadic = no
		is_tribal = no
	}

	immediate = {
		if = {
			limit = {
				war = no
				has_character_flag = accepted_request
			}
			clr_character_flag = accepted_request
		}
		if = {
			limit = {
				war = no
				has_character_flag = called_levies
			}
			clr_character_flag = called_levies
		}
		if = {
			limit = {
				NOT = { has_character_flag = decay_active}
			}
			if = {
					limit = {
						ai = no
					}
					log = "8: This event is running for [Root.GetTitledName]"
				}
			if = {
				limit = {
					capital_scope = {
					check_variable = { which = court_splendor value = 0.1}
					}
				}
				
				character_event = { id = CS.11000 days = 1}
			}
			else = {
				character_event = { id = CS.10000 days = 1}
			}
		}

		character_event = { id = CS.21050 days = 30}
	}
}


character_event = { ## Merchants Pre-Event
	id = CS.30000

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		higher_real_tier_than = COUNT
		is_nomadic = no
		is_tribal = no
	}

	immediate = {
		random = {
			chance = 4
			modifier = {
				factor = 0
				OR = {
					has_character_modifier = abysmal_court
					has_character_modifier = shabby_court
					has_character_modifier = acceptable_court
					has_character_modifier = standard_court
				}
			}
			modifier = {
				factor = 1.6
				has_character_modifier = grand_court
			}
			modifier = {
				factor = 2.2
				has_character_modifier = magnificent_court
			}
			character_event = { id = 31000 days = 10 random = 120 }
		}
	}
}

character_event = { ## Merchants Pre-Event
	id = CS.31000

	is_triggered_only = yes

	desc = { ## Artifact Merchants
       trigger = { has_character_flag = artifact_merchants }
       text = EVT_DESCCS31000A
       picture = GFX_magnificent_court
     }  
     desc = { ## Weapon and Armor Merchants
       trigger = { has_character_flag = wanda_merchants }
       text = EVT_DESCCS31000B
       picture = GFX_magnificent_court
     }
     desc = { ## Books Merchants
       trigger = { has_character_flag = books_merchants }
       text = EVT_DESCCS31000C
       picture = GFX_magnificent_court
     }

     immediate = {
     	random_list = {
     		20 = {
     			set_character_flag = artifact_merchants
     		}
     		20 = {
     			set_character_flag = wanda_merchants
     		}
     		5 = {
     			modifier = {
     				factor = 2
     				learning = 15
     			}
     			modifier = {
     				factor = 4
     				trait = erudite
     			}
     			set_character_flag = books_merchants
     		}
     	}

     }

     option = { ## Lets see their wares
     	name = EVTOPTA_CS31000
		hidden_tooltip = {
			character_event = {
				id = CS.32000
			}
		}
     }
     option = { ## Send them away
     	name = EVTOPTB_CS31000
     	trigger = {
     		NOT = { has_character_flag = books_merchants }
     	}
		hidden_tooltip = {
			clr_character_flag = wanda_merchants
			clr_character_flag = artifact_merchants
		}
     }

    option = { ## What do I need with books?
    	name = EVTOPTC_CS31000
     	trigger = {
     		has_character_flag = books_merchants
     	}
		hidden_tooltip = {
			clr_character_flag = artifact_merchants
		}
    }
}

character_event = { ## Merchants Pre-Event
	id = CS.32000

	is_triggered_only = yes

	desc = { ## Artifact Merchants
       trigger = { has_character_flag = chinese_merchants }
       text = EVT_DESCCS32000A
       picture = GFX_magnificent_court
    }
    desc = { ## Artifact Merchants
       trigger = { has_character_flag = centralasia_merchants }
       text = EVT_DESCCS32000B
       picture = GFX_magnificent_court
    }
    desc = { ## Artifact Merchants
       trigger = { has_character_flag = arabian_merchants }
       text = EVT_DESCCS32000C
       picture = GFX_magnificent_court
    }
    desc = { ## Weapon and Armor Merchants
       trigger = { has_character_flag = indian_merchants }
       text = EVT_DESCCS32000D
       picture = GFX_magnificent_court
    }
    desc = { ## Books Merchants
       trigger = { has_character_flag = european_merchants }
       text = EVT_DESCCS32000E
       picture = GFX_magnificent_court
    }
     desc = { ## Books Merchants
       trigger = { has_character_flag = wanda_merchants }
       text = EVT_DESCCS32000E
       picture = GFX_magnificent_court
    }
    desc = { ## Weapon and Armor Merchants
       trigger = { has_character_flag = books_merchants }
       text = EVT_DESCCS32000F
       picture = GFX_magnificent_court
    }

    immediate = {
    	if = {
    		limit = {
    			has_character_flag = artifact_merchants
    		}
    		random_list = {
    			5 = {
    				set_character_flag = chinese_merchants
    			}
    			5 = {
    				modifier = {
    					factor = 0
    					region = steppes
    				}
    				set_character_flag = centralasia_merchants
    			}
    			5 = {
    				modifier = {
    					factor = 0
    					region = near_east
    				}
    				set_character_flag = arabian_merchants
    			}
    			5 = {
    				modifier = {
    					factor = 0
    					region = india
    				}
    				set_character_flag = indian_merchants
    			}
    			5 = {
    				modifier = {
    					factor = 0
    					region = europe
    				}
    				set_character_flag = european_merchants
    			}
    			clr_character_flag = artifact_merchants
    		}
    	}

    	if = {
    		limit = {
    			has_character_flag = chinese_merchants
    		}
    		## Roll for wares
    		random_list = {
    			10 = {
    				set_character_flag = china_roll_1
    			}
    			10 = {
    				set_character_flag = china_roll_2
    			}
    			10 = {
    				set_character_flag = china_roll_3
    			}
    			10 = {
    				set_character_flag = china_roll_4
    			}
    		}
    		## Roll for weapon
    		random_list = {
    			3 = {
    				set_character_flag = Jian
    			}
    			10 = {
    				set_character_flag = SSpear
    			}
    			8 = {
    				set_character_flag = Ji
    			}
    		}
    		## Roll for books
    		random_list = {
    			1 = {
    				set_character_flag = classic_of_poetry
    			}
    			5 = {
    				set_character_flag = chinese_book_health
    			}
    			5 = {
    				set_character_flag = chinese_book_law
    			}
    			5 = {
    				set_character_flag = chinese_book_economy
    			}
    			5 = {
    				set_character_flag = chinese_book_history
    			}
    		}
    	}
    	if = {
    		limit = { has_character_flag = centralasia_merchants
    		}
    		random_list = {
    			1 = { 
    				set_character_flag = tier4ca
    			}
    			1 = { 
    				set_character_flag = tier3ca
    			}
    			1 = { 
    				set_character_flag = tier2ca
    			}
    		}
    	}

    }
    ## CHINESE MERCHANTS

    option = { ## WEAPON JIAN
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_1
    		}

    		has_character_flag = Jian
    		treasury = 1000
    	}
    	treasury = -4000
    	add_artifact = jian_sword
    	custom_tooltip = { text = blahblah}
    }
    option = { ## Other Weapon
    	name = {
        	text = EVTOPTB_MNM_40000_MACE
        	trigger = { 
        		OR = {
	    		has_character_flag = china_roll_1
	    		}
        		has_character_flag = SSpear
        	}
        }
        name = {
        	text = EVTOPTB_MNM_40000_MACE
        	trigger = { 
        		OR = {
	    		has_character_flag = china_roll_1
	    		}
        		has_character_flag = Ji
        	}
        }
    	
    	if = {
    		limit = {
    			has_character_flag = SSpear
    		}
    		treasury = -2000
    		add_artifact = chinese_serpent_spear
    	}
    	if = {
    		limit = {
    			has_character_flag = Ji
    		}
    		treasury = -2500
    		add_artifact = chinese_ji
    	}
    	custom_tooltip = { text = blahblah}
    }
    option = { ## These robes are quite magnificent
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_4
    		}
    		treasury = 1000
    	}
    	treasury = -2000
    	add_artifact = chinese_ceremonial_robes
    	custom_tooltip = { text = blahblah}
    }
    option = { ## I think I'll settle for this small figurine
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_1
    		has_character_flag = china_roll_3
    		}
    		treasury = 250
    	}
    	treasury = -500
    	add_artifact = chinese_ceremonial_robes
    	custom_tooltip = { text = blahblah}
    }
    option = { ## That amulet sure is pricy! But...
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_2
    		}
    		treasury = 1000
    	}
    	treasury = -4000
    	add_artifact = chinese_dragon_amulet
    	custom_tooltip = { text = blahblah}
    }
    option = { ## That thing is a clock? How does it work?
    	name = 
    	trigger = {
    		has_character_flag = china_roll_3
    		treasury = 800
    	}
    	treasury = -2500
    	add_artifact = water_clock
    	custom_tooltip = { text = blahblah}
    }
    option = { ## That parchment! What an interesting way of writing!
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_3
    		has_character_flag = china_roll_4
    		}
    		treasury = 200
    	}
    	treasury = -600
    	add_artifact = chinese_calligraphy
    	custom_tooltip = { text = blahblah}
    }
    option = { ## Thats a very unique painting!
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_4
    		}
    		treasury = 200
    	}
    	treasury = -700
    	add_artifact = chinese_artwork
    	custom_tooltip = { text = blahblah}
    }
    option = { ## This book looks interesting
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_1
    		has_character_flag = china_roll_2
    		}
    		has_character_flag = classic_of_poetry
    		treasury = 500
    	}
    	treasury = -2000
    	add_artifact = water_clock
    	custom_tooltip = { text = blahblah}
    }
    option = { ## This book looks interesting
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_1
    		has_character_flag = china_roll_2
    		}
    		has_character_flag = chinese_book_health
    		treasury = 400
    	}
    	treasury = -1000
    	add_artifact = water_clock
    	custom_tooltip = { text = blahblah}
    }
    option = { ## This book looks interesting
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_1
    		has_character_flag = china_roll_2
    		}
    		has_character_flag = chinese_book_law
    		treasury = 400
    	}
    	treasury = -1000
    	add_artifact = water_clock
    	custom_tooltip = { text = blahblah}
    }
    option = { ## This book looks interesting
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_1
    		has_character_flag = china_roll_2
    		}
    		has_character_flag = chinese_book_economy
    		treasury = 400
    	}
    	treasury = -1000
    	add_artifact = water_clock
    	custom_tooltip = { text = blahblah}
    }
    option = { ## This book looks interesting
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = china_roll_1
    		has_character_flag = china_roll_2
    		}
    		has_character_flag = chinese_book_history
    		treasury = 200
    	}
    	treasury = -500
    	add_artifact = water_clock
    	custom_tooltip = { text = blahblah}
    }
     option = { ## I think I'll settle for this sculpture
    	name = 
    	trigger = {
    		has_character_flag = china_roll_2
    		treasury = 250
    	}
    	treasury = -600
    	add_artifact = chinese_sculpture
    	custom_tooltip = { text = blahblah}
    }

    ######## CENTRAL ASIA
    option = { ## Tier 4 Bow
    	name = 
    	trigger = {
    		has_character_flag = tier4ca
    		treasury = 400
    	}
    	treasury = -3200
    	random_list = {
    		10 = {
    			add_artifact = bow_tier_4_silent_wind
    		}
    		10 = {
    			add_artifact = bow_tier_4_lightning
    		}
    		10 = {
    			add_artifact = bow_tier_4_eagle
    		}
    	}
    	custom_tooltip = { text = blahblah}
    }
    option = { ## Tier 3 Bow
    	name = 
    	trigger = {
    		has_character_flag = tier43ca
    		treasury = 200
    	}
    	treasury = -1600
    	random_list = {
    		10 = {
    			add_artifact = bow_tier_3_silent_wind
    		}
    		10 = {
    			add_artifact = bow_tier_3_lightning
    		}
    		10 = {
    			add_artifact = bow_tier_3_eagle
    		}
    	}
    	custom_tooltip = { text = blahblah}
    }
    option = { ## Tier 2 Bow
    	name = 
    	trigger = {
    		has_character_flag = tier2ca
    		treasury = 100
    	}
    	treasury = -800
    	add_artifact = bow_tier_2_new
    	custom_tooltip = { text = blahblah}
    }
    option = { ## Circlet 3
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = tier4ca
    		has_character_flag = tier3ca
    		}
    		treasury = 200
    	}
    	treasury = -1600
    	add_artifact = circlet_of_the_heavens
    	custom_tooltip = { text = blahblah}
    }
     option = { ## Circlet 2
    	name = 
    	trigger = {
    		has_character_flag = tier2ca
    		treasury = 100
    	}
    	treasury = -900
    	add_artifact = circlet_of_the_sun
    	custom_tooltip = { text = blahblah}
    }
    option = { ## Fur 3
    	name = 
    	trigger = {
    		OR = {
    		has_character_flag = tier4ca
    		has_character_flag = tier3ca
    		}
    		treasury = 200
    	}
    	treasury = -1500
    	add_artifact = cloak_fur_tier_3 
    	custom_tooltip = { text = blahblah}
    }
     option = { ## Fur 2
    	name = 
    	trigger = {
    		has_character_flag = tier2ca
    		treasury = 100
    	}
    	treasury = -800
    	add_artifact = cloak_fur_tier_2
    	custom_tooltip = { text = blahblah}
    }
}

### 5 year maintenance event

character_event = {
	id = CS.50000

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		NOT = { higher_real_tier_than = COUNT}
		independent = no
	}
	remove_character_modifier = magnificent_court
	remove_character_modifier = grand_court
	remove_character_modifier = splendid_court
	remove_character_modifier = standard_court
	remove_character_modifier = acceptable_court
	remove_character_modifier = shabby_court
	remove_character_modifier = magnificent_court_maintenance
	remove_character_modifier = grand_court_maintenance
	remove_character_modifier = splendid_court_maintenance
	remove_character_modifier = standard_court_maintenance
	remove_character_modifier = acceptable_court_maintenance
	remove_character_modifier = shabby_court_maintenance
	remove_character_modifier = full_autonomy
	remove_character_modifier = high_autonomy
	remove_character_modifier = medium_autonomy
	remove_character_modifier = low_autonomy
	remove_character_modifier = decadence4
	remove_character_modifier = decadence3
	remove_character_modifier = decadence2
	remove_character_modifier = decadence1
}

### maintenance event to remove province court splendor

province_event = {
	id = CS.51000

	hide_window = yes
	is_triggered_only = yes

	trigger = {
		is_capital = no ## Idk if this stupid crap even works
	}

	if = {
		limit = {
			check_variable = { which = court_splendor value = 10}
		}
		change_variable = { which = court_splendor value = -10}
	}
}
