// EffectsGroups for System Defense Mines
// arg1 total damage
// arg2 priority
// arg3 scope of systems effected: SOURCE, EMPIRE
//
// This macro handles multiple entries, where only the earliest applicable effects a target.
//   arg2/priority: the value should be unique from any other uses of EG_SYSTEM_MINES
//   arg3/scope: applies to either the source system only, or to all systems with an empire owned planet.
// Initial priority order of entries (earliest first):
//   SYS_DEF_MINES_3
//   SYS_DEF_MINES_2
//   FORTRESS_SPECIAL
//   SYS_DEF_MINES_1

EG_SYSTEM_MINES
'''        // Empire owned planet, damage enemy ship; sitreps issued below
        EffectsGroup
            scope = And [
                Ship
                [[SYSTEM_MINES_SCOPE_@3@]]
                Or [
                    OwnedBy affiliation = EnemyOf empire = Source.Owner
                    Unowned
                ]
                Structure low = @1@ + 0.0001
            ]
            activation = Not Unowned
            stackinggroup = "DEF_MINES_DAMAGE_STACK"
            priority = @2@
            effects = [
                SetStructure value = Value - @1@
            ]
        // Unowned planet, damage non-friendly ship; sitreps issued below
        EffectsGroup
            scope = And [
                Ship
                [[SYSTEM_MINES_SCOPE_@3@]]
                Or [
                    Not Unowned
                    And [
                        Unowned
                        Not HasTag name = "UNOWNED_FRIENDLY"
                    ]
                ]
                Structure low = @1@ + 0.0001
            ]
            activation = Unowned
            stackinggroup = "DEF_MINES_DAMAGE_STACK"
            priority = @2@
            effects = [
                SetStructure value = Value - @1@
            ]

        // Empire owned planet, destroy enemy ship; sitreps issued below
        EffectsGroup
            scope = And [
                Ship
                [[SYSTEM_MINES_SCOPE_@3@]]
                Or [
                    OwnedBy affiliation = EnemyOf empire = Source.Owner
                    Unowned
                ]
                Structure high = @1@
            ]
            activation = Not Unowned
            stackinggroup = "DEF_MINES_DAMAGE_STACK"
            priority = @2@
            effects = [
                Destroy
            ]
        // Unowned planet, destroy non-friendly ship; sitreps issued below
        EffectsGroup
            scope = And [
                Ship
                [[SYSTEM_MINES_SCOPE_@3@]]
                Or [
                    Not Unowned
                    And [
                        Unowned
                        Not HasTag name = "UNOWNED_FRIENDLY"
                    ]
                ]
                Structure high = @1@
            ]
            activation = Unowned
            stackinggroup = "DEF_MINES_DAMAGE_STACK"
            priority = @2@
            effects = [
                Destroy
            ]

        // Sitreps

        // Planet owner sitrep - visible enemy fleet damaged
        EffectsGroup
            scope = And [
                Fleet
                [[SYSTEM_MINES_SCOPE_@3@]]
                OwnedBy affiliation = EnemyOf empire = Source.Owner
                VisibleToEmpire empire = Source.Owner
            ]
            activation = Not Unowned
            stackinggroup = "DEF_MINES_SITREP_PLANET_VISIBLE_ENEMY_STACK"
            priority = @2@
            effects = [
                GenerateSitRepMessage
                    message = "EFFECT_MINES"
                    label = "EFFECT_MINES_LABEL"
                    icon = "icons/sitrep/combat_damage.png"
                    parameters = [
                        tag = "empire" data = Target.Owner
                        tag = "fleet" data = Target.ID
                        tag = "rawtext" data = @1@
                        tag = "system" data = Target.SystemID
                    ]
                    empire = Source.Owner
            ]
        // Planet owner sitrep - visible unowned ship damaged
        EffectsGroup
            scope = And [
                Ship
                [[SYSTEM_MINES_SCOPE_@3@]]
                Unowned
                VisibleToEmpire empire = Source.Owner
                Structure low = @1@ + 0.0001
            ]
            activation = Not Unowned
            stackinggroup = "DEF_MINES_SITREP_PLANET_VISIBLE_UNOWNED_STACK"
            priority = @2@
            effects = [
                GenerateSitRepMessage
                    message = "EFFECT_MINES_SINGLE_SHIP"
                    label = "EFFECT_MINES_LABEL"
                    icon = "icons/sitrep/combat_damage.png"
                    parameters = [
                        tag = "ship" data = Target.ID
                        tag = "shipdesign" data = Target.DesignID
                        tag = "rawtext" data = @1@
                        tag = "system" data = Target.SystemID
                    ]
                    empire = Source.Owner
            ]
        // Planet owner sitrep - visible unowned ship destroyed
        EffectsGroup
            scope = And [
                Ship
                [[SYSTEM_MINES_SCOPE_@3@]]
                Unowned
                VisibleToEmpire empire = Source.Owner
                Structure high = @1@
            ]
            activation = Not Unowned
            stackinggroup = "DEF_MINES_SITREP_PLANET_VISIBLE_UNOWNED_STACK"
            priority = @2@
            effects = [
                GenerateSitRepMessage
                    message = "EFFECT_MINES_UNOWNED_DESTROYED"
                    label = "EFFECT_MINES_SHIP_DESTROYED_LABEL"
                    icon = "icons/sitrep/combat_damage.png"
                    parameters = [
                        tag = "ship" data = Target.ID
                        tag = "shipdesign" data = Target.DesignID
                        tag = "system" data = Target.SystemID
                    ]
                    empire = Source.Owner
            ]
        // Planet owner sitrep - visible enemy ship destroyed
        EffectsGroup
            scope = And [
                Ship
                [[SYSTEM_MINES_SCOPE_@3@]]
                OwnedBy affiliation = EnemyOf empire = Source.Owner
                Structure high = @1@
                VisibleToEmpire empire = Source.Owner
            ]
            activation = Not Unowned
            stackinggroup = "DEF_MINES_SITREP_PLANET_VISIBLE_ENEMY_STACK"
            priority = @2@
            effects = [
                GenerateSitRepMessage
                    message = "EFFECT_MINES_SHIP_DESTROYED"
                    label = "EFFECT_MINES_SHIP_DESTROYED_LABEL"
                    icon = "icons/sitrep/combat_destroyed.png"
                    parameters = [
                        tag = "empire" data = Target.Owner
                        tag = "ship" data = Target.ID
                        tag = "system" data = Target.SystemID
                    ]
                    empire = Source.Owner
            ]
        // Planet owner sitrep - non-visible ship damaged or destroyed
        EffectsGroup
            scope = And [
                Ship
                [[SYSTEM_MINES_SCOPE_@3@]]
                Or [
                    OwnedBy affiliation = EnemyOf empire = Source.Owner
                    Unowned
                ]
                Not VisibleToEmpire empire = Source.Owner
            ]
            activation = Not Unowned
            stackinggroup = "DEF_MINES_SITREP_PLANET_INVISIBLE_STACK"
            priority = @2@
            effects = [
                GenerateSitRepMessage
                    message = "EFFECT_MINES_UNKNOWN"
                    label = "EFFECT_MINES_UNKNOWN_LABEL"
                    icon = "icons/sitrep/combat_damage.png"
                    parameters = [
                        tag = "system" data = Target.SystemID
                    ]
                    empire = Source.Owner
            ]
        // Fleet owner sitrep - damaged fleet
        EffectsGroup
            scope = And [
                Fleet
                [[SYSTEM_MINES_SCOPE_@3@]]
                Not Unowned
                OwnedBy affiliation = EnemyOf empire = Source.Owner
            ]
            stackinggroup = "DEF_MINES_SITREP_FLEET_STACK"
            priority = @2@
            effects = [
                GenerateSitRepMessage
                    message = "EFFECT_MINES"
                    label = "EFFECT_MINES_LABEL"
                    icon = "icons/sitrep/combat_damage.png"
                    parameters = [
                        tag = "empire" data = Target.Owner
                        tag = "fleet" data = Target.ID
                        tag = "rawtext" data = @1@
                        tag = "system" data = Target.SystemID
                    ]
                    empire = Target.Owner
            ]
        // Ship owner sitrep - destroyed ship
        EffectsGroup
            scope = And [
                Ship
                [[SYSTEM_MINES_SCOPE_@3@]]
                Not Unowned
                OwnedBy affiliation = EnemyOf empire = Source.Owner
                Structure high = @1@
            ]
            stackinggroup = "DEF_MINES_SITREP_SHIP_STACK"
            priority = @2@
            effects = [
                GenerateSitRepMessage
                    message = "EFFECT_MINES_SHIP_DESTROYED"
                    label = "EFFECT_MINES_SHIP_DESTROYED_LABEL"
                    icon = "icons/sitrep/combat_destroyed.png"
                    parameters = [
                        tag = "empire" data = Target.Owner
                        tag = "ship" data = Target.ID
                        tag = "system" data = Target.SystemID
                    ]
                    empire = Target.Owner
            ]
'''

SYSTEM_MINES_SCOPE_SOURCE
'''InSystem id = Source.SystemID'''

SYSTEM_MINES_SCOPE_EMPIRE
'''ContainedBy And [
                    System 
                    Contains And [
                        Planet
                        OwnedBy empire = Source.Owner
                    ]
                ]'''
