# -*- ck2.events -*-

namespace = dsf_forts_building
province_event = {
    id = dsf_forts_building.1

	is_triggered_only = yes
    hide_window = yes

    immediate = {
        FROM = {
            if = {
                limit = { has_fort = no }

                # Remove all fort modifiers from province
                remove_province_modifier = dsf_building_battle_camp
                remove_province_modifier = dsf_building_fortress_camp
                remove_province_modifier = dsf_building_military_outpost
                remove_province_modifier = dsf_building_wooden_bastion
                remove_province_modifier = dsf_building_stone_bastion
				remove_province_modifier = dsf_building_siege_camp
            }
            else = {
                if = {
                    limit = { fort_has_building = dsf_stone_bastion }

					remove_province_modifier = dsf_building_battle_camp
					remove_province_modifier = dsf_building_fortress_camp
					remove_province_modifier = dsf_building_military_outpost
                    remove_province_modifier = dsf_building_wooden_bastion

                    add_province_modifier = {
                        name = dsf_building_stone_bastion
                        duration = -1
                    }
                }
                else_if = {
                    limit = { fort_has_building = dsf_wooden_bastion }

					remove_province_modifier = dsf_building_battle_camp
					remove_province_modifier = dsf_building_fortress_camp
					remove_province_modifier = dsf_building_military_outpost

                    add_province_modifier = {
                        name = dsf_building_wooden_bastion
                        duration = -1
                    }
                }
				else_if = {
                    limit = { fort_has_building = dsf_military_outpost }

					remove_province_modifier = dsf_building_battle_camp
					remove_province_modifier = dsf_building_fortress_camp

                    add_province_modifier = {
                        name = dsf_building_military_outpost
                        duration = -1
                    }
                }
				else_if = {
                    limit = { fort_has_building = dsf_fortress_camp }

					remove_province_modifier = dsf_building_battle_camp

                    add_province_modifier = {
                        name = dsf_building_fortress_camp
                        duration = -1
                    }
                }
				else_if = {
                    limit = { fort_has_building = dsf_battle_camp }

                    add_province_modifier = {
                        name = dsf_building_battle_camp
                        duration = -1
                    }
                }
				else_if = {
                    limit = { fort_has_building = dsf_siege_camp }

                    add_province_modifier = {
                        name = dsf_building_siege_camp
                        duration = -1
                    }
                }
            }
        }

        repeat_event = {
            id = dsf_forts_building.1
            days = 30
        }
    }
}

province_event = {
    id = dsf_forts_building.2

	is_triggered_only = yes
    hide_window = yes

	immediate = {
		province_event = { id = dsf_forts_building.1 }
	}
}

province_event = {
    id = dsf_forts_building.3
    
    hide_window = yes
    is_triggered_only = yes # on_war_ended_defeat
    
    immediate = {
        ROOT = {
            any_fort = {
                if = {
                    limit = { 
                        owner = {
                            OR = {
                                character = FROM
                                is_vassal_or_below_of = FROM
                            }
                        }
                    }
                    
                    destroy_fort = THIS
                }
            }
        }
        
        FROM = {
            any_fort = {
                if = {
                    limit = { 
                        owner = {
                            OR = {
                                character = ROOT
                                is_vassal_or_below_of = ROOT
                            }
                        }
                    }
                    
                    destroy_fort = THIS
                }
            }
        }
    }
}
