decisions = {

	sin_realms = {
		is_high_prio = yes
		potential = {
			ai = no
			lower_real_tier_than = KING
			has_character_modifier = sin_realms_mod
		}
		allow = {
		}
		effect = {
			primary_title = {
				create_title = {
					tier = KING
					landless = no
					temporary = no
					culture = ROOT
					holder = ROOT
					custom_created = yes
					base_title = THIS
					copy_title_laws = yes
				}
				new_title = {
					set_title_flag = sin_realms
				}
			}
			
			set_defacto_liege = THIS
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 0
		}
	}

	sin_realms_convert = {
		is_high_prio = yes
		potential = {
			ai = no
			has_character_modifier = sin_realms_mod
		}
		allow = {
			OR = {
				any_realm_province = {
					NAND = {
						culture = ROOT
						religion = ROOT
					}
				}
				any_realm_lord = {
					NAND = {
						culture = ROOT
						religion = ROOT
					}
					NOR = {
						trait = slave
						trait = dragon
						culture = dragon
						religion = dragon_rel
						culture_group = winter_group
						culture_group = old_races
						culture_group = unoccupied_group
					}
				}
			}
		}
		effect = {
			any_realm_province = {
				culture = ROOT
				religion = ROOT
			}
			any_realm_lord = {
				IF = {
					limit = {
						NOR = {
							trait = slave
							trait = dragon
							culture = dragon
							religion = dragon
							culture_group = winter_group
							culture_group = old_races
							culture_group = unoccupied_group
						}
					}
					culture = ROOT
					religion = ROOT
				}
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 0
		}
	}

	sin_realms_feudal = {
		is_high_prio = yes
		potential = {
			ai = no
			has_character_modifier = sin_realms_mod
		}
		allow = {
			is_feudal = no
		}
		effect = {
			set_government_type = feudal_government
			any_realm_province = {
				capital_holding = {
					IF = {
						limit = { holding_type = tribal }
						convert_to = CASTLE
					}
					IF = {
						limit = {
							c_roma = { has_holder = yes }
						}
						add_building = ca_wall_q_1
						add_building = ca_wall_1
						add_building = ca_keep_1
						add_building = ca_militia_barracks_1
						add_building = ca_barracks_1
						add_building = ca_stable_1
						add_building = ca_town_1
						IF = {
							limit = { PREV = { port = yes } }
							add_building = ca_shipyard_1
						}
					}
				}
			}
			any_demesne_title = {
				IF = {
					limit = {
						OR = {
							holding_type = city
							holding_type = tribal
						}
					}
					convert_to = CASTLE
				}
				IF = {
					limit = {
						c_roma = { has_holder = yes }
						holding_type = castle
					}
					add_building = ca_wall_q_1
					add_building = ca_wall_1
					add_building = ca_keep_1
					add_building = ca_militia_barracks_1
					add_building = ca_barracks_1
					add_building = ca_stable_1
					add_building = ca_town_1
					IF = {
						limit = { location = { port = yes } }
						add_building = ca_shipyard_1
					}
				}
			}
			any_realm_lord = {
				IF = {
					limit = { is_tribal = yes }
					set_government_type = feudal_government 
				}
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 0
		}
	}

	sin_realms_republic = {
		is_high_prio = yes
		potential = {
			ai = no
			has_character_modifier = sin_realms_mod
			capital_scope = {
				port = yes
			}
		}
		allow = {
			is_republic = no
		}
		effect = {
			create_family_palace = yes
			set_government_type = merchant_republic_government
			any_realm_province = {
				capital_holding = {
					IF = {
						limit = { holding_type = tribal }
						convert_to = CITY
					}
					IF = {
						limit = {
							c_roma = { has_holder = yes }
							holding_type = city
						}
						add_building = ct_wall_q_1
						add_building = ct_wall_1
						add_building = ct_training_grounds_1
						add_building = ct_barracks_1
						add_building = ct_guard_1
						add_building = ct_marketplace_1
						IF = {
							limit = { PREV = { port = yes } }
							add_building = ct_port_1
							add_building = ct_shipyard_1
						}
					}
				}
			}
			any_demesne_title = {
				IF = {
					limit = {
						OR = {
							holding_type = castle
							holding_type = tribal
						}
					}
					convert_to = CITY
				}
				IF = {
					limit = {
						c_roma = { has_holder = yes }
						holding_type = city
					}
					add_building = ct_wall_q_1
					add_building = ct_wall_1
					add_building = ct_training_grounds_1
					add_building = ct_barracks_1
					add_building = ct_guard_1
					add_building = ct_marketplace_1
					IF = {
						limit = { location = { port = yes } }
						add_building = ct_port_1
						add_building = ct_shipyard_1
					}
				}
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 0
		}
	}

	sin_realms_tribal = {
		is_high_prio = yes
		potential = {
			ai = no
			has_character_modifier = sin_realms_mod
			c_roma = { has_holder = yes }
		}
		allow = {
			is_tribal = no
		}
		effect = {
			set_government_type = tribal_government
			any_realm_province = {
				capital_holding = {
					IF = {
						limit = {
							OR = {
								holding_type = castle
								holding_type = city
							}
						}
						convert_to = TRIBAL
					}
				}
			}
			any_realm_lord = {
				IF = {
					limit = {
						government = feudal_government
					}
					set_government_type = tribal_government
				}
				any_demesne_title = {
					IF = {
						limit = {
							OR = {
								holding_type = castle
								holding_type = city
							}
						}
						destroy_settlement = THIS
					}
				}
			}
			capital_holding = {
				convert_to = TRIBAL
			}
		}
		revoke_allowed = {
			always = no
		}
		ai_will_do = {
			factor = 0
		}
	}

}
targetted_decisions = {

	sin_realms_dip = {
		filter = all
		ai_target_filter = self

		from_potential = {
			ai = no
			primary_title = {
				has_title_flag = sin_realms
			}
			has_character_modifier = sin_realms_mod
		}
		potential = {
			ai = yes
			war = no
			lower_real_tier_than = KING
			any_realm_province = {
				OR = {
					any_neighbor_province = {
						holder_scope = {
							OR = {
								any_liege = { character = FROM }
								character = FROM
							}
						}
					}
					any_neighbor_province = {
						is_land = no
						any_neighbor_province = {
							holder_scope = {
								OR = {
									any_liege = { character = FROM }
									character = FROM
								}
							}
						}
					}
				}
			}
			NOT = {
				any_liege = { character = FROM }
			}
		}
		allow = {
		}
		effect = {
			set_defacto_liege = FROM
		}
		ai_will_do = {
			factor = 0
		}
	}

	sin_realms_dip2 = {
		filter = all
		ai_target_filter = self

		from_potential = {
			ai = no
			primary_title = {
				has_title_flag = sin_realms
			}
			has_character_modifier = sin_realms_mod
		}
		potential = {
			ai = yes
			war = no
			real_tier = KING
			any_realm_province = {
				OR = {
					any_neighbor_province = {
						holder_scope = {
							OR = {
								any_liege = { character = FROM }
								character = FROM
							}
						}
					}
					any_neighbor_province = {
						is_land = no
						any_neighbor_province = {
							holder_scope = {
								OR = {
									any_liege = { character = FROM }
									character = FROM
								}
							}
						}
					}
				}
			}
		}
		allow = {
		}
		effect = {
			any_vassal = {
				set_defacto_liege = FROM
			}
			any_demesne_title = {
				IF = {
					limit = { tier = KING }
					destroy_landed_title = THIS
				}
			}
			set_defacto_liege = FROM
		}
		ai_will_do = {
			factor = 0
		}
	}

}
title_decisions = {

	sin_realms_dip3 = {
		filter = realm_owned
		ai_target_filter = owned

		from_potential = {
			ai = no
			primary_title = {
				has_title_flag = sin_realms
			}
			has_character_modifier = sin_realms_mod
		}
		potential = {
			is_landless_type_title = no
			holder_scope = {
				NOR = {
					character = FROM
					ai = no
				}
			}
		}
		allow = {
		}
		effect = {
			grant_title_no_opinion = FROM
		}
		ai_will_do = {
			factor = 0
		}
	}

}