namespace = integrated_byz_events
#Byz Resurgence copied event file from Byzantium Events by Nevik, used with permission.
#DISCLAIMER: By integrating these events I have taken certain liberties regarding what events to keep and whether to modify them or not. In general, I like railroading without forcing an outcome.
#When Paradox creates events, the philosophy is adding historical flavour without actually directly forcing a particular outcome. As such, you will find some events being entirely removed,
#some being heavily altered and some may be exactly the way they used to be. There will be a comment next to every event regarding as to why changes have happened or why something has been removed.

#The Palaiologan Renaissance
country_event = {
	id = integrated_byz_events.1
	title = integrated_byz_events.1.t
	desc = integrated_byz_events.1.d
	picture = ARTWORK_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = BYZ
		government = monarchy
		dynasty = "Palaiologos"
		NOT = { has_country_modifier = integrated_palaiologan_renaissance }
		NOT = { is_year = 1475 }
	}
	
	mean_time_to_happen = { 
		months = 12 #Adjusted from 50 days
	}
	#Adjusted options to require money to grant modifier, with an option to not finance it.
	option = { #Support the freethinkers!
		name = integrated_byz_events.1.a
		ai_chance = { factor = 10 } #Shouldn't happen.
		add_years_of_income = -2
		add_country_modifier = {
			name = integrated_palaiologan_renaissance
			duration = 18250
		}
	}
	option = { #Do not
		name = integrated_byz_events.1.b
		ai_chance = { factor = 90 }
		add_legitimacy = -5
	}
}

#Palaiologan Renaissance Part 2, added by Byzantine Resurgence
country_event = {
	id = integrated_byz_events.2
	title = integrated_byz_events.2.t
	desc = integrated_byz_events.2.d
	picture = ARTWORK_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = BYZ
		is_institution_enabled = renaissance
		owns = 151
		has_country_modifier = integrated_palaiologan_renaissance
	}
	
	mean_time_to_happen = { 
		days = 50
	}
	
	option = {
		name = integrated_byz_events.2.a
		151 = {
			add_institution_embracement = {
				which = renaissance
				value = 100
			}
		}
	}
}

#The event of events that allows for all of these events to fire.
# country_event = {
	# id = integrated_byz_events.3
	# title = integrated_byz_events.3.t
	# desc = integrated_byz_events.3.d
	# picture = ARTWORK_eventPicture
	
	# fire_only_once = yes
	
	# trigger = {
		# tag = BYZ
	# }
	
	# mean_time_to_happen = { 
		# days = 1
	# }
	
	# option = {
		# name = integrated_byz_events.3.a
		# ai_chance = { factor = 1 }
		# custom_tooltip = using_integrated_byz_events
		# set_global_flag = integrated_byz_events_used
		# set_country_flag = rebellious_demetrios_flag #To allow for Demetrios to rise (integrated_byz_events.16)
	# }
	
	# option = {
		# name = integrated_byz_events.3.b
		# ai_chance = { factor = 0 } #AI shall never pick unadapted events
		# set_global_flag = original_byz_events_used
		# custom_tooltip = using_original_byz_events
		# 151 = {
			# remove_province_modifier = integrated_theodosian_walls
		# }
	# }
# }

#Ioannes VIII Palaiologos, event removed due to it being too railroading.
#Konstantinos XI Palaiologos, see above.

#Ottoman tribute 1, removed. This event chain had a purpose in attempting to railroad the Ottomans to give about 6-7 years of time for Byzantium to gather allies and such, but it much like many things I once added does not follow vanilla principles.
#Ottoman tribute 2, removed.
#Ottoman Tribute 3, removed.
#Ottoman Tribute 4, removed.

#Orban 1
country_event = {
	id = integrated_byz_events.8
	title = integrated_byz_events.8.t
	desc = integrated_byz_events.8.d
	picture = ADVISOR_eventPicture
	
	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = BYZ
		is_year = 1452
		NOT = { is_year = 1475 }
		NOT = { has_dlc = "Mandate of Heaven" } #Added this because I noticed it doubles with the age ability of the Ottomans.
	}
	
	fire_only_once = yes
	
	mean_time_to_happen = {
		days = 10
	}
	
	option = {
		name = integrated_byz_events.8.a
		trigger = { #Byz Resurgence added: So that Byzantium cannot cheese this event.
			treasury = 100
		}
		ai_chance = { factor = 50 } #Should happen if Byzantium can do it.
		
		#Byz Resurgence adjusted: I personally think this is the wrong way of representing the importance of Orban and it does not resemble anything in vanilla. I have adjusted this to instead become a siege ability modifier, as that's what Orban did for the Ottomans - Build cannons.
		#add_mil_power = 1500 
		add_country_modifier = {
			name = orbans_cannons
			duration = 9125 #25yr
		}
		add_treasury = -100
		define_advisor = {
			type = natural_scientist
			name = "Orban"
			location = 151
			skill = 3
		}
	}
	
	option = {
		name = integrated_byz_events.8.b
		ai_chance = {
			factor = 50
			modifier = {
				factor = 0
				treasury = 100
			}
		}
		TUR = {
			country_event = { id = integrated_byz_events.9 }
		}
	}
}

#Orban 2
country_event = {
	id = integrated_byz_events.9
	title = integrated_byz_events.9.t
	desc = integrated_byz_events.9.d
	picture = ADVISOR_eventPicture

	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = TUR
		is_year = 1452
		NOT = { is_year = 1475 }
	}
	
	fire_only_once = yes
	
	is_triggered_only = yes
	
	option = {
		name = integrated_byz_events.9.a
		ai_chance = { factor = 100 }
		#Byz Resurgence adjusted: Same as above
		#add_mil_power = 1500 
		add_country_modifier = {
			name = orbans_cannons
			duration = 9125 #25yr
		}
		add_treasury = -100
		define_advisor = {
			type = natural_scientist
			name = "Orban"
			location = 149
			skill = 3
		}
	}
	
	option = {
		name = integrated_byz_events.9.b
	}
}

#Giovanni Giustiniani, removed in favour of another event chain I have created.

#Theodosian Walls, repurposed: The modifier is already present in the history file of Constantinople. This event will now remove the modifier around reaching year 1500 or so. Also notice that the event does not require you to be Byzantium - Ottomans get this event as well.
province_event = {
	id = integrated_byz_events.11
	title = integrated_byz_events.11.t
	desc = integrated_byz_events.11.d
	picture = FORT_eventPicture

	trigger = {
		# has_global_flag = integrated_byz_events_used
		province_id = 151
        has_province_modifier = integrated_theodosian_walls #Adding for non-Leviathan users that get this province modifier.
		owner = {
			mil_tech = 7
		}
	}
	
	mean_time_to_happen = {
		years = 5 #Adjusted to years instead of days
	}
	
	fire_only_once = yes
	
	option = {
		name = integrated_byz_events.11.a
        remove_province_modifier = integrated_theodosian_walls
		add_permanent_province_modifier = {
			name = "ceremonial_theodosian_walls"
			duration = -1
		}
	}
}

#Countries Join War 1, removed due to it being unrealistic.
#Countries join war 2, removed, see above.
#Sultan Refuses Tribute, removed.
#Turks Run out of Europe, removed. While it was certainly cool as a way of defining a custom war goal, it is again too much railroading due to it being a scripted outcome and could be exploited.

#Demetrios I Palaiologos, repurposed into a pretender rebel event upon John VIII's death as happened historically.
country_event = {
	id = integrated_byz_events.16
	title = integrated_byz_events.16.t
	desc = integrated_byz_events.16.d
	picture = CIVIL_WAR_eventPicture
	
	is_triggered_only = yes
	
	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = BYZ
		NOT = { is_at_war = yes }
        NOT = { is_year = 1460 }
		owns = 151
		owns = 7137
	}

	mean_time_to_happen = {
		days = 1
	}
	
	option = {
		name = integrated_byz_events.16.a
		clr_country_flag = rebellious_demetrios_flag #Just to be sure
		7137 = { #Selymbria
			spawn_rebels = {
				type = pretender_rebels
				size = 3
				leader = "Demetrios Palaiologos"
			}
		}
	}
}

#Thomas I Palaiologos, removed. See above.
#Andreas I Palaiologos, removed. See above.
#Manuel III Palaiologos, removed. See above.
#Fall of Constantinople, removed for similar reasons as Turks Run out of Europe. Already presented in my own mod anyway.

#A Tale of Two Churches, removed and moved the patriarch authority gain to the history file of Byzantium since I alter it anyway.

#Knights to the Byzantines
country_event = {
	id = integrated_byz_events.22
	title = integrated_byz_events.22.t
	desc = integrated_byz_events.22.d
	picture = POPE_PREACHING_eventPicture
	
	fire_only_once = yes
	
	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = BYZ
		religion = catholic
		PAP = {
			has_opinion = {
				who = BYZ
				value = 100
			}
		}
	}
	
	mean_time_to_happen = {
		months = 12
	}
	
	option = {
		name = integrated_byz_events.22.a
		create_march = KNI
	}
}

#Reconstruction of Great Palace of Constantinople, removed due to it already having representation in my mod.
#Renovation of Hagia Sophia, removed because minarets are parts of Mosques.

#Allies Send Supplies, repurposed to trigger randomly while in defensive war with TUR.
country_event = {
    id = integrated_byz_events.25
	title = integrated_byz_events.25.t
	desc = integrated_byz_events.25.d
	picture = SHIP_SAILING_eventPicture

	#is_triggered_only = yes
	immediate = { #For localisation
		random_country = {
			limit = {
				NOT = { tag = BYZ }
				exists = yes
				OR = {
					tag = VEN
					tag = PAP
					tag = GEN
					tag = CYP
					AND = {
						NOT = { 
							has_country_flag = refused_to_help_byz 
							has_country_flag = helped_byz_war
							tag = TUR
							war_with = TUR
							truce_with = TUR
							is_rival = BYZ
						}
						OR = {
							has_opinion = {
								who = BYZ
								value = 80
							}
							NOT = {
								has_opinion = {
									who = TUR
									value = -50
								}
							}
						}
						is_at_war = no
						is_subject = no
						OR = {
							religion = orthodox
							religion = catholic
							religion = protestant
							religion = reformed
						}
					}
				}
			}
			save_event_target_as = SupplySender
		}
	}
	
	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = BYZ
		#Byz Resurgence altered: It would make sense if you can only get this event if Constantinople is not blockaded.
		151 = {
			is_blockaded = no
		}
		NOT = { has_country_modifier = integrated_ally_supplies } #Cannot have the modifier this event grants.
		defensive_war_with = TUR
		NOT = { army_size = TUR	} #Added to make sure it doesn't proc in a stupid war.
		151 = { #Does not proc if Byzantium owns all provinces around Constantinople.
			NOT = {
				any_neighbor_province = {
					NOT = { owned_by = ROOT }
				}
			}
		}
	}
	
	mean_time_to_happen = {
		months = 64
	}
	
	option = {
		name = integrated_byz_events.25.a
        add_country_modifier = {
			name = integrated_ally_supplies
			duration = 365
		}
        add_treasury = 50
	}
}

#Byzantine Silk, removed due to already being represented in my mod.

#Loukas Notaras
country_event = {
    id = integrated_byz_events.27
	title = integrated_byz_events.27.t
	desc = integrated_byz_events.27.d
	picture = ADVISOR_eventPicture
    
    fire_only_once = yes
    
    trigger = {
		# has_global_flag = integrated_byz_events_used
        tag = BYZ
		NOT = { is_year = 1475 }
    }
    
    mean_time_to_happen = {
        months = 90
    }
    
    option = {
        name = integrated_byz_events.27.a
        define_admiral = {
            name = "Loukas Notaras"
            shock = 2
            fire = 3
            manuever = 1
        }
		#I don't particularly like when you have the same name for an advisor and a general.
        # define_advisor = {
            # type = statesman
            # name = "Loukas Notaras"
            # location = 151
            # skill = 1
            # discount = yes
        # }
    }
}

#Prince Orhan 1
country_event = {
    id = integrated_byz_events.28
	title = integrated_byz_events.28.t
	desc = integrated_byz_events.28.d
	picture = CIVIL_WAR_eventPicture
    
    fire_only_once = yes
    
    trigger = {
		# has_global_flag = integrated_byz_events_used
        tag = BYZ
        is_year = 1451
		NOT = { is_year = 1475 }
        TUR = {
            owns = 149
        }
        NOT = { war_with = TUR }
    }
    
    mean_time_to_happen = {
        days = 10
    }
    
    option = {
        name = integrated_byz_events.28.a #Release him!
        ai_chance = { factor = 20 }
        TUR = {
            country_event = { id = integrated_byz_events.29 }
            add_claim = 151
		}
        if = {
            limit = {
                TUR = {
                    owns = 149
                }
            }
            149 = {
                spawn_rebels = {
                    type = pretender_rebels
                    size = 2
                    leader = "Orhan Osmanoglu"
                    friend = BYZ
					religion = sunni
					culture = turkish
                }
            }
        }
        if = {
            limit = {
                TUR = {
                    NOT = { owns = 149 }
                }
            }
            TUR = {
                random_owned_province = {
                    limit = {
                        is_capital = no
                    }
                    spawn_rebels = {
                        type = pretender_rebels
                        size = 2
                        leader = "Orhan Osmanoglu"
                        friend = BYZ
						religion = sunni
						culture = turkish
                    }
                }
            }
        }
        clr_country_flag = subject_of_ottomans
		set_country_flag = defied_the_sultan
    }
    option = {
        name = integrated_byz_events.28.b #Threaten to release
        ai_chance = { factor = 60 }
        TUR = {
			country_event = { id = integrated_byz_events.30 }
		}
		clr_country_flag = subject_of_ottomans
		set_country_flag = defied_the_sultan
        add_prestige = 10
    }
    option = {
        name = integrated_byz_events.28.c #take him in as an advisor
        ai_chance = { factor = 20 }
        define_advisor = {
            type = recruitmaster
            name = "Sehzade Orhan elebi"
            location = 151
            skill = 1
        }
    }
}

#Prince Orhan 2
country_event = {
	id = integrated_byz_events.29
	title = integrated_byz_events.29.t
	desc = integrated_byz_events.29.d
	picture = CIVIL_WAR_eventPicture
	
	is_triggered_only = yes
	
	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = TUR
	}
	
	option = {
		name = integrated_byz_events.29.a
		#Byz Resurgence altered: These declarations of war are detrimental. If anything, a CB should be granted.
		#declare_war = BYZ
		add_casus_belli = { 
			target = BYZ
			type = cb_insult
			months = 12
		}
	}
}

#Prince Orhan 3
country_event = {
	id = integrated_byz_events.30
	title = integrated_byz_events.30.t
	desc = integrated_byz_events.30.d
	picture = BAD_WITH_MONARCH_eventPicture
	
	is_triggered_only = yes
	
	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = TUR
	}
	
	option = {
		name = integrated_byz_events.30.a
        ai_chance = { factor = 80 }
        add_claim = 151
        BYZ = {
            country_event = { id = integrated_byz_events.33 }
        }
	}
    
    option = {
        name = integrated_byz_events.30.b
        ai_chance = { factor = 20 }
        add_prestige = -50
        add_treasury = -500
        BYZ = {
            country_event = { id = integrated_byz_events.31 }
        }
    }
}

#Prince Orhan 4
country_event = {
	id = integrated_byz_events.31
	title = integrated_byz_events.31.t
	desc = integrated_byz_events.31.d
	picture = GOOD_WITH_MONARCH_eventPicture

	is_triggered_only = yes
	
	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = BYZ
	}
	
	option = {
		name = integrated_byz_events.31.a
        add_prestige = 50
        add_treasury = 500
	}
}

#Prince Orhan 5, removed since it's one of those ways the Ottomans can be forced into declaring war on Byzantium despite whatever allies Byzantium has picked up.

#Prince Orhan 6
country_event = {
	id = integrated_byz_events.33
	title = integrated_byz_events.33.t
	desc = integrated_byz_events.33.d
	picture = BAD_WITH_MONARCH_eventPicture

	is_triggered_only = yes
	
	trigger = {
		# has_global_flag = integrated_byz_events_used
		tag = BYZ
	}
	
	option = {
		name = integrated_byz_events.33.a
        define_advisor = {
            type = recruitmaster
            name = "Sehzade Orhan elebi"
            location = 151
            skill = 1
        }
	}
}

#Moved Succession Crisis to a different file to distinguish it to a succession_crisis.txt

#Control over Black Sea Trade
country_event = {
    id = integrated_byz_events.37
    title = integrated_byz_events.37.t
    desc = integrated_byz_events.37.d
    picture = SHIP_SAILING_eventPicture
    
    trigger = {
		# has_global_flag = integrated_byz_events_used
        tag = BYZ
        owns = 151
        owns = 149
        owns = 316
        owns = 317
        owns = 2296
		#Added BT tag
        owns = 5157 #Iznik
        owns = 5130 #Karasi
        owns = 5156 #Biga
        NOT = { has_country_flag = controls_black_sea_trade }
    }
    
    fire_only_once = yes
    
    option = {
        name = integrated_byz_events.37.a
        capital_scope = {
            add_trade_modifier = {
                who = BYZ
                duration = -1
                power = 50
                key = control_of_black_sea_trade
            }
        }
        reverse_add_opinion = {
            who = VEN
			modifier = byz_controls_black_sea
        }
        reverse_add_opinion = {
            who = GEN
			modifier = byz_controls_black_sea
        }
        add_dip_power = 100
        add_historical_rival = VEN
        VEN = {
            add_historical_rival = BYZ
        }
        set_country_flag = controls_black_sea_trade
    }
    
}

#Gregorios Gemistos Plethon
country_event = {
    id = integrated_byz_events.40
	title = integrated_byz_events.40.t
	desc = integrated_byz_events.40.d
	picture = ADVISOR_eventPicture
    
    fire_only_once = yes
    
    trigger = {
		# has_global_flag = integrated_byz_events_used
        tag = BYZ
		NOT = { is_year = 1475 }
    }
    
    mean_time_to_happen = {
        months = 6
    }
    
    option = {
        name = integrated_byz_events.40.a
        define_advisor = {
            type = philosopher
            name = "Gregorios Gemistos Plethon"
            location = 151
            skill = 2
            discount = yes
        }
    }
}

#The Hexamilion Wall, re-added as BT updated Greece.
country_event = {
    id = integrated_byz_events.46
    title = integrated_byz_events.46.t
    desc = integrated_byz_events.46.d
    picture = FORT_eventPicture
    
    trigger = {
		# has_global_flag = integrated_byz_events_used
        tag = BYZ
        owns = 4701
    }
    
    fire_only_once = yes
    
    mean_time_to_happen = {
		months = 12
    }
    
    option = {
        name = integrated_byz_events.46.a
		#Removed the moving of forts as it does not make sense in the BT map.
        4701 = { #Corinth is now 4701.
            add_permanent_province_modifier = {
                name = integrated_hexamilion_wall
                duration = -1
            }
        }
        add_treasury = -25
    }
    
    option = {
        name = integrated_byz_events.46.b
        add_army_tradition = 10
    }
    
}

#Helena Palaiologina, Queen Consort of Cyprus
country_event = {
    id = integrated_byz_events.47
    title = integrated_byz_events.47.t
    desc = integrated_byz_events.47.d
    picture = ROYAL_COUPLE_FUTURE_eventPicture
    
    trigger = {
		# has_global_flag = integrated_byz_events_used
        tag = CYP
        NOT = { is_year = 1458 }
    }
    
    fire_only_once = yes
    
    mean_time_to_happen = {
        days = 20
    }
    
    option = {
        name = integrated_byz_events.47.a
        define_consort = {
            name = "Helena"
            country_of_origin = BYZ
            dynasty = "Palaiologos"
            adm = 5
            dip = 4 
            mil = 1
            female = yes
        }
        set_consort_culture = greek
        set_consort_religion = orthodox
    }
    
}

#Georgian Byzantine Marriage Alliance
country_event = {
    id = integrated_byz_events.48
    title = integrated_byz_events.48.t
    desc = integrated_byz_events.48.d
    picture = ROYAL_COUPLE_FUTURE_eventPicture
    
    trigger = {
		# has_global_flag = integrated_byz_events_used
        tag  = BYZ
        is_year = 1453
		NOT = { is_year = 1475 }
        has_consort = no
        is_at_war = no
        has_ruler = "Konstantinos XI"
        dynasty = "Palaiologos"
		has_dlc = "Rights of Man" #Added trigger in case it bugs up and thinks you can get a consort somehow.
        GEO = {
            num_of_cities = 5
            is_subject = no
            is_female = no
            is_at_war = no
            NOT = { 
                war_with = TUR
                truce_with = TUR
            }
        }
    }
    
    fire_only_once = yes
    
    mean_time_to_happen = {
        months = 2
    }
    
    option = {
        name = integrated_byz_events.48.a
        create_alliance = GEO
        create_marriage = GEO
        define_consort = {
            country_of_origin = GEO
            dynasty = "Bagrationi"
            adm = 1
            dip = 1
            mil = 1
            female = yes
        }
        define_heir = { #Between 2-6 in all stats. Yeowch.
            claim = 95
            dynasty = ROOT
            adm = 2
            dip = 2
            mil = 2
            age = 0
			max_random_adm = 4
			max_random_dip = 4
			max_random_mil = 4
			
        }
    }
    
    option = {
        name = integrated_byz_events.48.b
        add_country_modifier = {
			name = integrated_searching_for_better_allies
			duration = 3600
		}
    }
}