
planet_megastructure_constuti = {
    situation_log_category = planetmegas
    complete_icon_frame = GFX_situation_outcome_frame_green
    complete_icon = GFX_situation_outcome_positive
    fail_icon_frame = GFX_situation_outcome_frame_red
    fail_icon = GFX_situation_outcome_meh
    picture = {
        trigger = { has_situation_flag = building_plnmg_reincarnation }
        picture = GFX_evt_planetmega_reincarnation
    }

    triggered_target_modifier = {
        potential = {
            has_situation_flag = can_use_building_capacity
            target = {
                or = {
                    not = { exists = owner }
                    is_plnmg_const_sit_byd_cap_need = no
                }
            }
        }
        planet_building_capacity_add = -1
    }

    #total_progress = 5040
    stages = {
        stage_1 = {
            icon = GFX_planet_mega_stage_1
            icon_background = GFX_situation_stage_frame_green
            custom_tooltip = stage_planet_mega_1_tooltip
            #section_weight= 10
            end = 505 #10%
        }
        stage_2 = {
            icon = GFX_planet_mega_stage_1
            icon_background = GFX_situation_stage_frame_green
            custom_tooltip = stage_planet_mega_1_tooltip
            on_first_enter = {
                set_variable = { which = situation_modifier_level value = 1 }
                #situation_event = { id = planetmega.1030 }
            }
            target_modifier = {
                planet_jobs_produces_mult = -0.1
                planet_buildings_produces_mult = -0.1
            }
            #section_weight= 10
            end = 1010 #20%
        }
        stage_3 = {
            icon = GFX_planet_mega_stage_1
            icon_background = GFX_situation_stage_frame_green
            custom_tooltip = stage_planet_mega_1_tooltip
            on_first_enter = {
                set_variable = { which = situation_modifier_level value = 2 }
                #situation_event = { id = planetmega.1030 }
            }
            target_modifier = {
                planet_jobs_produces_mult = -0.2
                planet_buildings_produces_mult = -0.2
            }
            #section_weight= 10
            end = 1510 #30%
        }
        stage_4 = {
            icon = GFX_planet_mega_stage_2
            icon_background = GFX_situation_stage_frame_green
            custom_tooltip = stage_planet_mega_2_tooltip
            on_first_enter = {
                set_variable = { which = situation_modifier_level value = 3 }
                #situation_event = { id = planetmega.1030 }
            }
            target_modifier = {
                planet_jobs_produces_mult = -0.3
                planet_buildings_produces_mult = -0.3
            }
            #section_weight= 10
            end = 2020 #40%
        }
        stage_5 = {
            icon = GFX_planet_mega_stage_2
            icon_background = GFX_situation_stage_frame_green
            custom_tooltip = stage_planet_mega_2_tooltip
            on_first_enter = {
                set_variable = { which = situation_modifier_level value = 4 }
                #situation_event = { id = planetmega.1030 }
            }
            target_modifier = {
                planet_jobs_produces_mult = -0.4
                planet_buildings_produces_mult = -0.4
            }
            #section_weight= 10
            end = 2520 #50%
        }
        stage_6 = {
            icon = GFX_planet_mega_stage_2
            icon_background = GFX_situation_stage_frame_green
            custom_tooltip = stage_planet_mega_2_tooltip
            on_first_enter = {
                set_variable = { which = situation_modifier_level value = 5 }
                #situation_event = { id = planetmega.1030 }
            }
            target_modifier = {
                planet_jobs_produces_mult = -0.5
                planet_buildings_produces_mult = -0.5
            }
            #section_weight= 10
            end = 3020 #60%
        }
        stage_7 = {
            icon = GFX_planet_mega_stage_2
            icon_background = GFX_situation_stage_frame_green
            custom_tooltip = stage_planet_mega_2_tooltip
            on_first_enter = {
                set_variable = { which = situation_modifier_level value = 6 }
                #situation_event = { id = planetmega.1030 }
            }
            target_modifier = {
                planet_jobs_produces_mult = -0.4
                planet_buildings_produces_mult = -0.4
            }
            #section_weight= 10
            end = 3530 #70%
        }
        stage_8 = {
            icon = GFX_planet_mega_stage_3
            icon_background = GFX_situation_stage_frame_green
            custom_tooltip = stage_planet_mega_3_tooltip
            on_first_enter = {
                set_variable = { which = situation_modifier_level value = 7 }
                #situation_event = { id = planetmega.1030 }
            }
            target_modifier = {
                planet_jobs_produces_mult = -0.3
                planet_buildings_produces_mult = -0.3
            }
            #section_weight= 10
            end = 4030 #80%
        }
        stage_9 = {
            icon = GFX_planet_mega_stage_3
            icon_background = GFX_situation_stage_frame_green
            custom_tooltip = stage_planet_mega_3_tooltip
            on_first_enter = {
                set_variable = { which = situation_modifier_level value = 5 }
                #situation_event = { id = planetmega.1030 }
            }
            target_modifier = {
                planet_jobs_produces_mult = -0.2
                planet_buildings_produces_mult = -0.2
            }
            #section_weight= 10
            end = 4540 #90%
        }
        stage_10 = {
            icon = GFX_planet_mega_stage_3
            icon_background = GFX_situation_stage_frame_green
            custom_tooltip = stage_planet_mega_3_tooltip
            on_first_enter = {
                set_variable = { which = situation_modifier_level value = 2.5 }
                #situation_event = { id = planetmega.1030 }
            }
            target_modifier = {
                planet_jobs_produces_mult = -0.1
                planet_buildings_produces_mult = -0.1
            }
            #section_weight= 10
            end = 5040 #42年
        }
    }

    category = positive

    on_start = {
        situation_event = { id = planetmega.1055 }
        #set_variable = { which = vic_game_year value = value:plnmg_getVicYearTime }
    }
    on_progress_complete = {
        custom_tooltip = planet_megastructure_construction_tooltip
        hidden_effect = { situation_event = { id = planetmega.1090 } }
    }
    on_fail = { situation_event = { id = planetmega.99 } }
    on_abort = { situation_event = { id = planetmega.99 } }
    on_monthly = {
        events = {
            planetmega.11
        }
    }

    approach = { #steady
        name = planetmega_approach_default
        icon = GFX_situation_tower_crane
        icon_background = GFX_situation_approach_bg_green
        default = yes
        on_select = {
            custom_tooltip = planet_megastructure_default_effect
            hidden_effect = {
                if = {
                    limit = { is_variable_set = special_plnmg_const_approach_index }
                    clear_variable = special_plnmg_const_approach_index
                }
            }
        }
        ai_weight = { base = 100 }
        resources = {
            category = situations
            upkeep = {
                energy = @plnmg_base_upkeep_t3
                alloys = @plnmg_base_upkeep_t2
                mult = value:sv_plnmg_sit_upkp_mult
            }
            inline_script = situations/plnmg_sit_approach_upkp
        }
    }

    approach = { #pause
        name = planetmega_approach_pause
        allow = {
            custom_tooltip = {
                fail_text = planetmega_constuti_nopause_desc
                owner = { has_country_flag = plnmg_player_delighted }
            }
        }
        on_select = {
            custom_tooltip = planet_megastructure_pause_effect
            hidden_effect = { set_variable = { which = special_plnmg_const_approach_index value = 1 } }
        }
        icon = GFX_situation_tower_crane
        icon_background = GFX_situation_approach_bg_yellow
        ai_weight = { base = 0 }
        resources = {
            category = situations
            upkeep = { energy = 3 }
        }
    }

    approach = {
        name = planetmega_approach_setting
        icon = GFX_situation_approach_engineering
        icon_background = GFX_situation_approach_bg_yellow
        ai_weight = { base = 0 }
        on_select = {
            hidden_effect = {
                if = {
                    limit = {
                        is_variable_set = special_plnmg_const_approach_index
                        check_variable = { which = special_plnmg_const_approach_index value = 1 }
                    }
                    set_situation_approach = planetmega_approach_pause
                }
                else = { set_situation_approach = planetmega_approach_default }
            }
            situation_event = { id = planetmega.250 }
        }
    }

    monthly_progress = {
        base = @progressBase_buildPlanetMega
        modifier = {
            add = value:plnmg_spacemega_build_speed_mult_uti
            desc = from_megastructure_build_speed_mult
        }
        modifier = {
            add = value:plnmg_mega_build_speed_mult_uti
            desc = from_ground_megastructure_build_speed_mult
        }
        # modifier = {
        # 	add = value:plnmg_plnt_build_speed_mult
        # 	desc = plnt_building_speed_desc
        # }
        modifier = {
            is_planetmega_speed_customized = yes
            add = value:planetmega_custom_speed_mult
            desc = planetmega_custom_speed_mult_desc
        }

        modifier = {
            mult = value:sv_plnmg_sit_speed_final_mult
            desc = string_current_approach
            current_situation_approach = planetmega_approach_default
        }
        modifier = {
            mult = 0
            desc = string_current_approach
            current_situation_approach = planetmega_approach_pause
        }
        modifier = {
            mult = 0
            desc = situation_locked_desc
            has_situation_flag = situation_locked
        }
    }

    abort_trigger = {
        OR = {
            NOT = { exists = target.owner }
            target.owner = { NOT = { is_same_value = root.owner } }
        }
    }
}

planetmega_ultimate_research = {
    situation_log_category = planetmegas
    complete_icon_frame = GFX_situation_outcome_frame_green
    complete_icon = GFX_situation_outcome_positive
    fail_icon_frame = GFX_situation_outcome_frame_red
    fail_icon = GFX_situation_outcome_meh
    picture = GFX_evt_physics_research

    #total_progress = 101
    stages = {
        stage_1 = {
            icon = GFX_situation_stage_1
            icon_background = GFX_situation_stage_frame_green
            #section_weight= 10
            end = 101
        }
    }

    category = positive

    on_progress_complete = {
        owner = {
            if = {
                limit = { hidden_trigger = { has_country_flag = planetmega_ultimate_enabled } }
                country_event = { id = planetmega.1020 }
            }
            else = { country_event = { id = planetmega.1021 } }
        }
        hidden_effect = { situation_event = { id = situation.1180 days = 1 } }
    }
    on_fail = {
        owner = { start_situation = { type = planetmega_ultimate_research } }
        hidden_effect = { destroy_situation = this }
    }

    abort_trigger = { is_ironman = yes }
    on_abort = { situation_event = { id = planetmega.1015 } }

    on_monthly = {
        random_events = {
            99 = 0
            1 = planetmega.1015
        }
    }

    approach = {
        name = planetmega_approach_default
        icon = GFX_situation_tower_crane
        icon_background = GFX_situation_approach_bg_green
        default = yes
        ai_weight = { base = 10 }
        modifier = { country_physics_research_produces_mult = -0.5 }
    }

    approach = {
        name = planetmega_approach_encourage
        icon = GFX_situation_tower_crane
        icon_background = GFX_situation_approach_bg_yellow
        ai_weight = {
            base = 0
            modifier = {
                owner = { has_ascension_perk = ap_cosmogenesis }
                weight = 20
            }
        }
        modifier = { country_physics_research_produces_mult = -1 }
        triggered_modifier = {
            potential = { owner = { has_ascension_perk = ap_cosmogenesis } }
            country_physics_research_produces_mult = 0.1
        }
    }

    monthly_progress = {
        base = 1
        modifier = {
            add = 1
            desc = string_current_approach
            current_situation_approach = planetmega_approach_encourage
        }
        modifier = {
            factor = 1.25
            desc = ap_cosmogenesis
            owner = { has_ascension_perk = ap_cosmogenesis }
        }
    }
}
