# operation_type_name = {			# Key of the site, used for name lookup etc.
#	picture = <sprite key>			# GFX_* sprite key for the operation image
#	desc = <triggered event desc>	# Description generator for the operation, with scope this=spy network
#	stages = <int>					# Should match number of defined stages below.
#	potential = <trigger>			# Trigger checking if a scope with this=spy network is potential to use (this will add/remove this operation without giving the player a reason).
#	allow = <trigger>				# Trigger checking if a scope with this=spy network is allowed to use (this will toggle enable/disabled mode on buttons etc).
#	stage = {						# Stage definition, order dependent.
#		difficulty = <value>			# base difficulty for this stage
#		icon = <string>			# icon gfx type.
#		event = <string>			# event to fire when finished the state.
#	}
#	stage = {...}					# Second stage, the total number of 'stage' entries should match value of 'stages'
#	on_roll_failed = <effect>		# Effect to fire when a roll fails, with scope this=spy operation.
#	on_create = <effect>			# Effect to fire upon operation creation, with scope this=spy operation.
#}

@diff_t0 = 1
@diff_t1 = 2
@diff_t2 = 3
@diff_t3 = 4
@diff_t4 = 5
@diff_t5 = 6
@diff_t6 = 7
@diff_t7 = 8
@diff_t8 = 9
@diff_t9 = 10

operation_plnmg_gather_information = {
    target = none
    categories = { op_cat_subterfuge }
    picture = GFX_evt_spymaster
    desc = operation_plnmg_gather_information_desc
    stages = 1

    resources = {
        category = operations
        cost = { influence = 10 }
        upkeep = { energy = 10 }
    }

    spy_power_cost = 3
    potential = {
        target = { is_primitive = no }
        owner = {
            is_ai = no
            has_technology = tech_planetmega_transfer
        }
    }
    allow = {
        custom_tooltip = {
            is_running_espionage_operation = no
            fail_text = operation_one_at_a_time
        }
        custom_tooltip = {
            fail_text = plnmg_eg_must_unlock_espionage
            owner = {
                any_owned_colony = {
                    has_deposit = d_plnmg_extra_galaxy
                    has_carrier_flag = unlock_eg_espionage
                }
            }
        }
    }
    stage = {
        difficulty = @diff_t0
        icon = GFX_espionage_chapter_icon_document
        event = operation.7000
    }

    on_roll_failed = {
        standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_low_stakes }
    }
    on_create = {
        target = {
            set_timed_country_flag = {
                flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
                years = 30
            }
        }
    }
}

operation_plnmg_foment_rebellion = {
    target = none
    categories = { op_cat_manipulation op_cat_government }
    picture = GFX_evt_conclave
    desc = operation_plnmg_foment_rebellion_desc
    stages = 3
    spy_power_cost = 30

    resources = {
        category = operations
        cost = {
            influence = 100
        }
        upkeep = {
            energy = 20
        }
    }

    potential = {
        #has_nemesis = yes
        owner = {
            is_ai = no
            has_technology = tech_planetmega_transfer
        }
        target = { is_primitive = no }
    }
    allow = {
        custom_tooltip = {
            fail_text = operation_foment_rebellion_recent
            #owner = { not = { has_country_flag = recent_foment_rebellion@fromfrom.target } }
            target = { not = { any_owned_colony = { is_plnmg_rebellion_fomented = yes } } }
        }
        custom_tooltip = {
            is_running_espionage_operation = no
            fail_text = operation_one_at_a_time
        }
        custom_tooltip = {
            fail_text = plnmg_eg_must_unlock_espionage
            owner = {
                any_owned_colony = {
                    has_deposit = d_plnmg_extra_galaxy
                    has_carrier_flag = unlock_eg_espionage
                }
            }
        }
    }

    stage = {
        difficulty = @diff_t7
        icon = GFX_espionage_chapter_icon_surveillance
        event = planetmega_exp.100
    }
    stage = {
        difficulty = @diff_t8
        icon = GFX_espionage_chapter_icon_target
        event = planetmega_exp.101
    }
    stage = {
        difficulty = @diff_t9
        icon = GFX_espionage_chapter_icon_success
        event = planetmega_exp.102
    }
    on_roll_failed = {
        standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_deepcover }
    }
    on_create = {
        target = {
            set_timed_country_flag = {
                flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
                years = 30
            }
        }
    }
}

# operation_plnmg_crisis_beacon = {
#     target = none
#     categories = { op_cat_provocation op_cat_technology }
#     picture = GFX_evt_unidentified_monster
#     desc = operation_crisis_beacon_desc
#     stages = 3
#
#     resources = {
#         category = operations
#         cost = {
#             influence = 320
#         }
#         upkeep = {
#             energy = 16
#         }
#     }
#
#     spy_power_cost = 80
#
#     potential = {
#         has_nemesis = yes
#         owner = {
#             is_ai = no
#             any_owned_colony = {
#                 has_deposit = d_plnmg_extra_galaxy
#                 has_carrier_flag = unlock_eg_espionage
#             }
#         }
#         target = { is_primitive = no }
#         OR = {
#             has_crisis = yes #Contingency, Extradimensionals or Prethoryn
#             has_global_flag = marauder_crisis_ongoing #Khan
#             has_global_flag = gray_goo_crisis_active #Gray Tempest
#         }
#         NOR = {
#             crisis_happened_and_defeated = yes #Contingency, Extradimensionals or Prethoryn
#             AND = { #If the Khan is defeated, Crisis Beacon should be hidden until a new crisis happens
#                 has_global_flag = great_khan_dead
#                 has_crisis = no
#             }
#             AND = { #If the Gray Tempest is defeated, Crisis Beacon should be hidden until a new crisis happens
#                 has_global_flag = graygoo_defeated
#                 has_crisis = no
#             }
#         }
#     }
#
#     allow = {
#         if = {
#             limit = {
#                 owner = { has_country_flag = crisis_beacon_timer }
#             }
#             custom_tooltip = {
#                 NOT = {
#                     any_country = { has_country_flag = crisis_beacon_from@root.owner }
#                 }
#                 fail_text = operation_crisis_beacon_too_recent_timer
#             }
#         }
#         else = {
#             custom_tooltip = {
#                 NOT = {
#                     any_country = { has_country_flag = crisis_beacon_from@root.owner }
#                 }
#                 fail_text = operation_crisis_beacon_too_recent
#             }
#         }
#         custom_tooltip = {
#             is_running_espionage_operation = no
#             fail_text = operation_one_at_a_time
#         }
#     }
#
#     stage = {
#         difficulty = @diff_t8
#         icon = GFX_espionage_chapter_icon_target
#         event = operation.4000
#     }
#     stage = {
#         difficulty = @diff_t8
#         icon = GFX_espionage_chapter_icon_motion
#         event = operation.4001
#     }
#     stage = {
#         difficulty = @diff_t8
#         icon = GFX_espionage_chapter_icon_success
#         event = operation.4002
#     }
#     on_roll_failed = {
#         standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_deepcover }
#     }
#     on_create = {}
# }

operation_plnmg_steal_subjects = {
    target = none
    categories = { op_cat_sabotage op_cat_government }
    picture = GFX_evt_alien_segregation
    desc = operation_plnmg_steal_subjects_desc
    stages = 3
    spy_power_cost = 20

    resources = {
        category = operations
        cost = {
            influence = 100
        }
        upkeep = {
            energy = 15
        }
    }

    potential = {
        target = { is_primitive = no }
        owner = {
            is_ai = no
            is_machine_empire = no
            is_individual_machine = no
            has_technology = tech_planetmega_transfer
            or = {
                has_ascension_perk = ap_plnmg_organic_raid
                has_ascension_perk = ap_nihilistic_acquisition
            }
            # OR = {
            #     AND = {
            #         has_policy_flag = slavery_allowed
            #         is_gestalt = no
            #     }
            #     AND = {
            #         owner_main_species = { is_species_class = NECROID }
            #         is_pacifist = no
            #     }
            #     has_ascension_perk = ap_become_the_crisis
            #     has_ascension_perk = ap_cosmogenesis
            #     has_ascension_perk = ap_nihilistic_acquisition
            #     has_civic = civic_machine_assimilator
            # }
        }
    }
    allow = {
        custom_tooltip = {
            fail_text = at_least_5pops
            target = {
                any_owned_pop_group = {
                    pop_group_size >= 500
                    or = {
                        is_robotic_species = no
                        root.owner = { has_technology = tech_planetmega_junik }
                    }
                }
            }
        }
        custom_tooltip = {
            is_running_espionage_operation = no
            fail_text = operation_one_at_a_time
        }
        custom_tooltip = {
            fail_text = plnmg_eg_must_unlock_espionage
            owner = {
                any_owned_colony = {
                    has_deposit = d_plnmg_extra_galaxy
                    has_carrier_flag = unlock_eg_espionage
                }
            }
        }
        custom_tooltip = {
            fail_text = must_have_plnmg_farm2
            owner = {
                if = {
                    limit = { is_gestalt = no }
                    any_owned_colony = { has_deposit = d_plnmg_advanced_agriculture_edifice }
                }
                else_if = {
                    limit = { is_hive_empire = yes }
                    any_owned_colony = { has_deposit = d_plnmg_gene_farm_hive }
                }
            }
        }
    }
    stage = {
        difficulty = @diff_t6
        icon = GFX_espionage_chapter_icon_surveillance
        event = planetmega_exp.110
    }
    stage = {
        difficulty = @diff_t7
        icon = GFX_espionage_chapter_icon_target
        event = planetmega_exp.111
    }
    stage = {
        difficulty = @diff_t8
        icon = GFX_espionage_chapter_icon_motion
        event = planetmega_exp.112
    }
    on_roll_failed = {
        standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_generic }
    }
    on_create = {
        target = {
            set_timed_country_flag = {
                flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
                years = 30
            }
        }
    }
}

operation_planetmega_financial_targeted = {
    target = none
    categories = { op_cat_infiltration op_cat_economy }
    picture = GFX_evt_financial_instruments
    desc = operation_planetmega_financial_targeted_desc
    stages = 2
    resources = {
        category = operations
        cost = {
            trade = 150
            energy = 100
            influence = 25
        }
        upkeep = {
            trade = 25
            energy = 10
        }
    }

    spy_power_cost = 5
    potential = {
        target = {
            is_country_type = default
            is_gestalt = no
        }
        owner = {
            is_ai = no
            has_technology = tech_planetmega_financial
        }
    }
    allow = {
        custom_tooltip = {
            is_running_espionage_operation = no
            fail_text = operation_one_at_a_time
        }
        has_espionage_asset_economy = yes
        # custom_tooltip = {
        #     owner = { not = { has_country_flag = pmfintech_targeting } }
        #     fail_text = already_pmfintech_targeted
        # }
    }
    stage = {
        difficulty = @diff_t3
        icon = GFX_espionage_chapter_icon_target
        event = planetmega_effect.121
    }
    stage = {
        difficulty = @diff_t5
        icon = GFX_espionage_chapter_icon_success
        event = planetmega_effect.122
    }

    on_roll_failed = {
        standard_espionage_operation_on_roll_failed = { RANDOM_EVENTS = operation_random_events_low_stakes }
    }
    on_create = {
        #owner = { set_country_flag = pmfintech_targeting }
        target = {
            set_timed_country_flag = {
                flag = espionage_operation_targeted_by@root.owner #Used in random Spy Network events
                years = 30
            }
        }
    }
}
