#textdomain wesnoth-ei

#define PLACE_ITEM ID NME IMAGE X Y REQUIREMENTS ITEM_NAME ITEM_DESC ITEM_USE INVALID_DESC EFFECTS EQUIP_WML
    [item]
        x,y={X},{Y}
        image={IMAGE}
    [/item]
    [event]
        name=moveto
        id=EVENT_{ID}
        first_time_only=no
        delayed_variable_substitution=no
        [filter]
            side=1
            x,y={X},{Y}

            [not]
                trait=undead
            [/not]
            # most of these items would feel strange on a WC or Soulless
        [/filter]
        [if]
            [have_unit]
                x,y={X},{Y}
                [and]
                    {REQUIREMENTS}
                [/and]
            [/have_unit]

            [then]
                [item_dialog]
                    name={ITEM_NAME}
                    image={IMAGE}
                    description={ITEM_DESC}
                    effect={ITEM_USE}
                    take_string=_"Take it."
                    leave_string=_"Leave it."
                [/item_dialog]
                [if]
                    {VARIABLE_CONDITIONAL item_picked equals yes}
                    [then]
                        [remove_event]
                            id=EVENT_{ID}
                        [/remove_event]
                        [remove_item]
                            x,y={X},{Y}
                            image={IMAGE}
                        [/remove_item]
                        [modify_unit]
                            [filter]
                                side=1
                                x,y={X},{Y}
                            [/filter]

                            # picking up an item consumes your moves and attack. Prevents baneblade cheese, and kinda feels right anyways.
                            moves=0
                            attacks_left=0 # so we can't pick up multiple items on 1 turn, or repeatedly suicide with the baneblade
                            [trait]
                                id=TRAIT_{ID}
                                name={NME}
                                description={ITEM_DESC}
                                {EFFECTS}
                            [/trait]
                        [/modify_unit]
                        {EQUIP_WML}
                    [/then]
                [/if]
            [/then]

            [else]
                [message]
                    speaker=unit
                    message={INVALID_DESC}
                [/message]
            [/else]
        [/if]
    [/event]
#enddef

#define GLOBAL__DROPPABLE ID IMAGE DESC DIE_DROP_ITEM CMD_DROP_ITEM
    [event]
        name=die
        first_time_only=no

        [filter]
            trait=TRAIT_{ID}
        [/filter]

        {DIE_DROP_ITEM}
    [/event]
    [event]
        name=prestart
        [clear_menu_item]
            id=DROP_ITEM_{ID}
        [/clear_menu_item]
        [set_menu_item]
            id=DROP_ITEM_{ID} # for some reason this breaks if I use the default ID
            description={DESC}
            image={IMAGE}~CROP(18,18,36,36)~SCALE(20,20)
            [filter_location]
                [filter]
                    side=1
                    trait=TRAIT_{ID}
                [/filter]
            [/filter_location]
            [command]
                [remove_trait]
                    trait_id=TRAIT_{ID}
                [/remove_trait]
                {CMD_DROP_ITEM}
            [/command]
        [/set_menu_item]
    [/event]
#enddef

#define NOTE_REUSEABLE
    _"<span size='small'><i>  This item is reusable if its wielder dies, and can be dropped by right clicking.</i></span>
<span size='small'><i>  Picking up an item consumes your moves and attack.</i></span>
<b></b>"
#enddef
#define NOTE_SINGLE_USE
    _"<span size='small'><i>This item can <b>NOT</b> be dropped, and can <b>NOT</b> be reused if its user dies.</i></span>
<span size='small'><i>  Picking up an item consumes your moves and attack.</i></span>
<b></b>"
#enddef

#-------------------
# CRYSTAL QUIVER
#-------------------
# anybody can wield this, but you only benefit from the "quiver" part if you have a bow/crosbow
#define ID_CRYSTAL_QUIVER
crystal_quiver #enddef

#define PLACE_ITEM_CRYSTAL_QUIVER X Y
    {PLACE_ITEM
    {ID_CRYSTAL_QUIVER}  _"quiver"  items/crystal-quiver.png  {X}  {Y}  ()
    _"Crystal Quiver"
    _"Arrows from this crystalline quiver glimmer with a pale magical light, <i><b>illuminating</b></i> the surrounding area and making your bow or crossbow attacks <i><b>arcane</b></i>."
    {NOTE_REUSEABLE}
    ""
    (
        [effect]
            apply_to=attack
            range=ranged
            [set_specials]
                mode=append
                {WEAPON_SPECIAL_ARCANE_EI}
            [/set_specials]
            name=bow,crossbow,composite bow
        [/effect]
        [effect]
            apply_to=new_ability
            [abilities]
                {ABILITY_ILLUMINATES HALO="halo/illuminates-aura.png"}
            [/abilities]
        [/effect]
        [effect]
            apply_to=overlay
            add=misc/crystal-quiver-icon.png
        [/effect]
    )
    ()
    }
#enddef

#define GLOBAL__DROPPABLE_CRYSTAL_QUIVER
    {GLOBAL__DROPPABLE
    {ID_CRYSTAL_QUIVER}
    items/crystal-quiver.png
    _"Drop Crystal Quiver"
    ({PLACE_ITEM_CRYSTAL_QUIVER $unit.x $unit.y})
    ({PLACE_ITEM_CRYSTAL_QUIVER $x1 $y1})
    }
#enddef

#-------------------
# HOLY AMULETS
#-------------------
#define ID_HOLY_AMULET_1
holy_amulet_1 #enddef

#define ID_HOLY_AMULET_2
holy_amulet_2 #enddef

#define ID_HOLY_AMULET_3
holy_amulet_3 #enddef

#define PLACE_ITEM_HOLY_AMULET ID X Y
    {PLACE_ITEM
    {ID}  _"amulet"  items/ankh-necklace.png  {X}  {Y}  ()
    _"Holy Amulet"
    _"Engraved with a consecrated symbol, this amulet will bless both your <i><b>melee</b></i> and <i><b>ranged</b></i> attacks with <i><b>arcane</b></i> damage."
    {NOTE_REUSEABLE}
    ""
    (
        [effect]
            apply_to=new_ability
            [abilities]
                {ABILITY_ARCANE_EI}
            [/abilities]
        [/effect]
    )
    ()
    }
#enddef

#define GLOBAL__DROPPABLE_HOLY_AMULET ID
    {GLOBAL__DROPPABLE
    {ID}
    items/ankh-necklace.png
    _"Drop Holy Amulet"
    ({PLACE_ITEM_HOLY_AMULET {ID} $unit.x $unit.y})
    ({PLACE_ITEM_HOLY_AMULET {ID} $x1 $y1})
    }
#enddef

#-------------------
# SHIELD OF THE SENTINEL
#-------------------
#define ID_SENTINEL
sentinel #enddef

#define PLACE_ITEM_SHIELD_OF_THE_SENTINEL X Y
    {PLACE_ITEM
    {ID_SENTINEL}  _"sentinel"  items/shield-of-the-sentinel.png  {X}  {Y}  ()
    _"Shield of the Sentinel"
    _"Deep within this shield’s towering bulk, enchanted machinery whirrs faintly. Whenever an adjacent ally is hit by an attack, <i><b>this shield’s bearer is hit instead</b></i>."
    {NOTE_REUSEABLE}
    ""
    (
        [effect]
            apply_to=overlay
            add=misc/sentinel-icon.png
        [/effect]
    )
    (
        [remove_item]
            x,y={X},{Y}
            image=items/shield-of-the-sentinel-stand.png
        [/remove_item]
    )
    }
#enddef

#define GLOBAL__DROPPABLE_SHIELD_OF_THE_SENTINEL
    {GLOBAL__DROPPABLE
    {ID_SENTINEL}
    items/shield-of-the-sentinel.png
    _"Drop Shield of the Sentinel"
    ({PLACE_ITEM_SHIELD_OF_THE_SENTINEL $unit.x $unit.y})
    ({PLACE_ITEM_SHIELD_OF_THE_SENTINEL $x1 $y1})
    }
#enddef

#-------------------
# SENTINEL DAMAGE BLOCKING
#-------------------
# first, we need to make the attacker deal 0 damage
#define SENTINEL_BLOCK_DAMAGE FILT ATTACKER DEFENDER WEAPON
    first_time_only=no
    [{FILT}]
        [filter_adjacent]
            trait=TRAIT_sentinel
            is_enemy=no
        [/filter_adjacent]
    [/{FILT}]

    # record all the relevant damage details and specials
    # not bothering with ghostplague; sentinel is already complex enough
    {VARIABLE sentinel_enemyside ${ATTACKER}.side}
    {VARIABLE sentinel_damage ${WEAPON}.damage}
    {VARIABLE sentinel_poisons        no}
    {VARIABLE sentinel_slows          no}
    {VARIABLE sentinel_drains         no}
    {VARIABLE sentinel_greaterdrains  no}
    {VARIABLE sentinel_plagues        no}
    [if]
        [have_unit]
            id=${ATTACKER}.id
            [has_attack]
                range=${WEAPON}.range
                name=${WEAPON}.name
                type=${WEAPON}.type
                damage=${WEAPON}.damage
                special_id=poison
            [/has_attack]
        [/have_unit]

        [then]
            {VARIABLE sentinel_poisons       yes}
        [/then]
    [/if]
    [if]
        [have_unit]
            id=${ATTACKER}.id
            [has_attack]
                range=${WEAPON}.range
                name=${WEAPON}.name
                type=${WEAPON}.type
                damage=${WEAPON}.damage
                special_id=slow
            [/has_attack]
        [/have_unit]

        [then]
            {VARIABLE sentinel_slows         yes}
        [/then]
    [/if]
    [if]
        [have_unit]
            id=${ATTACKER}.id
            [has_attack]
                range=${WEAPON}.range
                name=${WEAPON}.name
                type=${WEAPON}.type
                damage=${WEAPON}.damage
                special_id=drains
            [/has_attack]
        [/have_unit]

        [then]
            {VARIABLE sentinel_drains        yes}
        [/then]
    [/if]
    [if]
        [have_unit]
            id=${ATTACKER}.id
            [has_attack]
                range=${WEAPON}.range
                name=${WEAPON}.name
                type=${WEAPON}.type
                damage=${WEAPON}.damage
                special_id=greater drains
            [/has_attack]
        [/have_unit]

        [then]
            {VARIABLE sentinel_greaterdrains yes}
        [/then]
    [/if]
    [if]
        [have_unit]
            id=${ATTACKER}.id
            [has_attack]
                range=${WEAPON}.range
                name=${WEAPON}.name
                type=${WEAPON}.type
                damage=${WEAPON}.damage
                special_id=plague
            [/has_attack]
        [/have_unit]

        [then]
            {VARIABLE sentinel_plagues       yes}
        [/then]
    [/if]

    # does the survivor trait apply?
    # if the sentinel has survivor AND the attacker is undead
    [if]
        [have_unit]
            trait=TRAIT_sentinel

            [and]
                trait=survivor
            [/and]

            [filter_adjacent]
                id=${DEFENDER}.id
                is_enemy=no
            [/filter_adjacent]
        [/have_unit]

        [and]
            [have_unit]
                id=${ATTACKER}.id
                trait=undead

                [or]
                    type_adv_tree=Dark Adept,Vampire Bat
                [/or]
            [/have_unit]
        [/and]
        [then]
            {VARIABLE_OP sentinel_damage sub 1}
        [/then]
    [/if]

    # implement charge, AFTER survivor
    [if]
        [have_unit]
            id=$unit.id
            [has_attack]
                range=$weapon.range
                name=$weapon.name
                type=$weapon.type
                damage=$weapon.damage
                special_id=charge
            [/has_attack]
        [/have_unit]

        [then]
            {VARIABLE_OP sentinel_damage multiply 2}
        [/then]
        # for Charge, only care about the primary unit, not the unit being sentinel-ed
    [/if]

    # block all damage
    [modify_unit]
        [filter]
            id=${ATTACKER}.id
        [/filter]

        [object]
            id=sentinel_damage_blocker # after combat, remove this object
            [effect]
                apply_to=attack
                remove_specials=poison,slow
                [set_specials]
                    mode=append
                    [damage]
                        apply_to=self
                        value=0
                        overwrite_specials=one_side # not overwriting causes issues with the survivor trait
                    [/damage]
                [/set_specials]
            [/effect]
        [/object]
    [/modify_unit]
#enddef

#-------------------
# SENTINEL INFLICT DAMAGE
#-------------------
# if the attacker hits, inflict the original damage on the sentinel
#define SENTINEL_INFLICT_DAMAGE FILT ATTACKER DEFENDER WEAPON
    first_time_only=no
    [{FILT}]
        [filter_adjacent]
            trait=TRAIT_sentinel
            is_enemy=no
        [/filter_adjacent]
    [/{FILT}]

    # harm unit
    [harm_unit]
        [filter]
            trait=TRAIT_sentinel
            [filter_adjacent]
                id=${DEFENDER}.id
                is_enemy=no
            [/filter_adjacent]
        [/filter]
        [filter_second]
            id=${ATTACKER}.id
        [/filter_second]

        amount=$sentinel_damage
        damage_type=${WEAPON}.type
        alignment=${ATTACKER}.alignment
        poisoned=$sentinel_poisons
        slowed=$sentinel_slows
        animate=yes
        delay=0
        fire_event=yes
        #         variable=sentinel_damage_dealt # this throws an error if the unit dies. Instead, base drain_amount on $sentinel_damage, regardless of resistances
    [/harm_unit]

    # implement drain
    [if]
        {VARIABLE_CONDITIONAL sentinel_drains equals yes}
        [then]
            {VARIABLE_OP drain_amount divide 2}
            [heal_unit]
                [filter]
                    id=${ATTACKER}.id
                [/filter]

                amount=$drain_amount
            [/heal_unit]
        [/then]
    [/if]
    [if]
        {VARIABLE_CONDITIONAL sentinel_greaterdrains equals yes}
        [then]
            {VARIABLE_OP drain_amount divide 1}
            [heal_unit]
                [filter]
                    id=${ATTACKER}.id
                [/filter]

                amount=$drain_amount
            [/heal_unit]
        [/then]
    [/if]
#enddef

#-------------------
# SENTINEL RESET BLOCKER
#-------------------
# once the attack is over, reset
#define SENTINEL_RESET
    [remove_object]
        object_id=sentinel_damage_blocker
    [/remove_object]
    {CLEAR_VARIABLE sentinel_damage,sentinel_damage_dealt,sentinel_enemyside,sentinel_no_recursion}
    {CLEAR_VARIABLE sentinel_poisons,sentinel_slows,sentinel_drains,sentinel_greaterdrains,sentinel_plagues}
#enddef

#-------------------
# SENTINEL _MAIN
#-------------------
#define GLOBAL__IMPLMENTATION_SHIELD_OF_THE_SENTINEL
    [event]
        name=pre attack
        {SENTINEL_BLOCK_DAMAGE   filter_second  unit         second_unit  weapon}
    [/event]
    [event]
        name=pre attack
        {SENTINEL_BLOCK_DAMAGE   filter         second_unit  unit         second_weapon}
    [/event]

    [event]
        name=attacker hits
        {SENTINEL_INFLICT_DAMAGE filter_second  unit         second_unit  weapon}
    [/event]
    [event]
        name=defender hits
        {SENTINEL_INFLICT_DAMAGE filter         second_unit  unit         second_weapon}
    [/event]

    [event]
        name=attack end
        first_time_only=no
        {SENTINEL_RESET}
    [/event]
    [event]
        name=die
        first_time_only=no

        [filter]
            trait=TRAIT_sentinel
            [not]
                id=$sentinel_no_recursion
            [/not]
        [/filter]

        [if]
            {VARIABLE_CONDITIONAL sentinel_plagues equals yes}
            [then]
                [event] # wait until the attack finishes, so the unit dies off by itself
                    name=attack end
                    delayed_variable_substitution=no
                    {NAMED_UNIT $sentinel_enemyside (Walking Corpse) $unit.x $unit.y "wc_$unit.id" $unit.name ()}
                    [+unit]
                        animate=yes
                    [/unit]
                [/event]
            [/then]
        [/if]
        {SENTINEL_RESET} # especially important if we're using a berserk attack
    [/event]
#enddef

#-------------------
# YETI BURGER
#-------------------
# this is an extrordinarily strong item, especially when comboed with the Sentinel Shield
# but also very difficult to get, and means you're spending gold you need for S12_Evacuation.
# IMO it's not worth the cost to obtain, but item-collectors may enjoy it

#define ID_YETIBURGER
yeti_steak #enddef

#define PLACE_ITEM_YETIBURGER X Y
    {PLACE_ITEM
    {ID_YETIBURGER}  _"yetiburger"  items/yeti-meat.png  {X}  {Y}  ()
    _"Yetiburger"
    _"Eating this funny tasting meat <i><b>doubles your hitpoints</b></i> and grants <i><b>immunity to cold</b></i>."
    {NOTE_SINGLE_USE}
    ""
    (
        [effect]
            apply_to=hitpoints
            increase=+100%
            increase_total=+100%
        [/effect]
        [effect]
            apply_to=resistance
            replace=yes
            [resistance]
                cold=0
            [/resistance]
        [/effect]
    )
    ()
    }
#enddef

#-------------------
# ANT AMBROSIA
#-------------------
#define PLACE_ITEM_ANTAMBROSIA ID X Y
    {PLACE_ITEM
    {ID}  _"ant ambrosia"  items/ant-ambrosia.png  {X}  {Y}  ()
    _"Ant Ambrosia"
    _"This goopy honey-like substance makes you feel very sleepy... perhaps eating too much would be unwise.

<i><b><span color='#FF0000'>-1</span> damage, <span color='#FF0000'>-1</span> movement, <span color='#00FF00'>+10</span> hitpoints</b></i>."
    {NOTE_SINGLE_USE}
    ""
    (
        [effect]
            apply_to=movement
            increase=-1
        [/effect]
        [effect]
            apply_to=attack
            increase_damage=-1
        [/effect]
        [effect]
            apply_to=hitpoints
            increase=10
            increase_total=10
        [/effect]
    )
    ()
    }
#enddef

#-------------------
# BANEBLADE
#-------------------
#define ID_BANEBLADE
baneblade #enddef

#define PLACE_ITEM_BANEBLADE X Y
    {PLACE_ITEM
    {ID_BANEBLADE}  _"baneblade"  items/sword-wraith.png  {X}  {Y}  ()
    _"Baneblade"
    _"This incorporeal sword resembles those wielded by undead wraiths. Any mortal brave enough to wield it becomes <i><b>chaotic</b></i> and lashes out at their foes with reckless abandon.
<i><b>6x4 arcane</b></i> damage, <i><b>drains</b></i>, <i><b>berserk</b></i>."
    {NOTE_REUSEABLE}
    ""
    (
        [effect]
            apply_to=attack
            range=melee
            defense_weight=0 # force the baneblade to be used on defense, even if it's a fatal choice
        [/effect]
        [effect]
            apply_to=new_attack
            name=sword
            description=_"baneblade"
            icon="attacks/baneblade.png"
            type=arcane
            range=melee
            damage=6
            number=4
            [specials]
                {WEAPON_SPECIAL_BERSERK}
                {WEAPON_SPECIAL_DRAIN}
            [/specials]
        [/effect]
        [effect] # for some reason items ignore strong, so manually do that here
            [filter]
                trait=strong,survivor
            [/filter]

            apply_to=attack
            special_type=berserk
            increase_damage=1
        [/effect]
        [effect]
            apply_to=alignment
            set=chaotic
        [/effect]
        [effect]
            apply_to=overlay
            add=misc/soulsword-icon.png
        [/effect]
    )
    ()
    }
#enddef

#define GLOBAL__DROPPABLE_BANEBLADE
    {GLOBAL__DROPPABLE
    {ID_BANEBLADE}
    items/sword-wraith.png
    _"Drop Baneblade"
    ({PLACE_ITEM_BANEBLADE $unit.x $unit.y})
    ({PLACE_ITEM_BANEBLADE $x1 $y1})
    }
#enddef

#-------------------
# POTION OF BARKSKIN
#-------------------
#define ID_BARKSKIN
potion_of_barkskin #enddef

#define PLACE_ITEM_BARKSKIN X Y
    {PLACE_ITEM
    {ID_BARKSKIN}  _"barkskin"  items/potion-red.png  {X}  {Y}  ()
    _"Potion of Barkskin"
    _"This potion bubbles as though over an open flame, yet is cool to the touch. Its drinker gains the <i><b>steadfast</b></i> ability and can <i><b>heal 2 hitpoints each turn</b></i>, like dwarves with the ‘healthy’ trait."
    {NOTE_SINGLE_USE}
    ""
    (
        [effect]
            apply_to=new_ability
            [abilities]
                {ABILITY_STEADFAST}
            [/abilities]
        [/effect]
        [effect]
            apply_to="healthy"
        [/effect]
        [effect]
            apply_to=overlay
            add=misc/potion-of-vitality-icon.png
        [/effect]
    )
    ()
    }
#enddef

#-------------------
# RING OF INVISIBILITY
#-------------------
#define ID_INVISIBILITY
ring_of_invisibility #enddef

#define PLACE_ITEM_INVISIBILITY X Y
    {PLACE_ITEM
    {ID_INVISIBILITY}  _"ring"  items/ring-gold.png  {X}  {Y}  ()
    _"Ring of Invisibility"
    _"This plain gold ring looks unremarkable, but its wearer gains <i><b>skirmisher</b></i> and <i><b>nightstalk</b></i>, becoming invisible in the dark."
    {NOTE_REUSEABLE}
    ""
    (
        [effect]
            apply_to=new_ability
            [abilities]
                {ABILITY_NIGHTSTALK}
                {ABILITY_SKIRMISHER}
            [/abilities]
        [/effect]
        [effect]
            apply_to=overlay
            add=misc/ring-of-invisibility-icon.png
        [/effect]
    )
    ()
    }
#enddef

#define GLOBAL__DROPPABLE_INVISIBILITY
    {GLOBAL__DROPPABLE
    {ID_INVISIBILITY}
    items/ring-gold.png
    _"Drop Ring of Invisibility"
    ({PLACE_ITEM_INVISIBILITY $unit.x $unit.y})
    ({PLACE_ITEM_INVISIBILITY $x1 $y1})
    }
#enddef

#-------------------
# PLAGUE STAFF
#-------------------
#define ID_PLAGUE_STAFF
plague_staff #enddef

#define PLACE_ITEM_PLAGUE_STAFF X Y
    {PLACE_ITEM
    {ID_PLAGUE_STAFF}  _"staff"  items/plague-staff.png  {X}  {Y}
    (
        [not]
            type_adv_tree=White Mage,Paladin

            [not]
                id=Dacyn
            [/not]
        [/not]

        [not]
            id=Owaec,Gweddry,Dacyn,Hahid al-Ali,Terraent
        [/not]
        # messes with existing recruiting, and messes with the S18 cutscene
        # if Dacyn gets this, it also breaks his scripted advancements (and his S17a recruitment)
    )
    _"Plague Staff"
    _"Looted from a dead necromancer, the wielder of this dark staff becomes <i><b>chaotic</b></i>, and can <i><b>recruit and recall</b></i> Walking Corpses and Soulless.
<i><b>6x3 impact</b></i> damage, <i>plague</i>."
    {NOTE_REUSEABLE}
    _"I will not wield such a dark magical artifact, though I shall not begrudge its use by my companions."
    # this message makes no sense for Dacyn (his entire quest is to get a dark magical artifact), but I couldn't think of something good and generic that works for everyone.
    (
        [effect]
            apply_to=new_attack
            name=staff
            description= _ "plague staff"
            icon="attacks/staff-plague.png"
            type=impact
            range=melee
            damage=6
            number=3
            [specials]
                {WEAPON_SPECIAL_PLAGUE}
            [/specials]
        [/effect]
        [effect] # for some reason items ignore strong, so manually do that here
            [filter]
                trait=strong,survivor
            [/filter]

            apply_to=attack
            special_type=plague
            increase_damage=1
        [/effect]
        [effect]
            apply_to=alignment
            set=chaotic
        [/effect]

        [effect]
            apply_to=overlay
            remove=misc/leader-gold.png
        [/effect]

        [effect]
            apply_to=overlay
            add=misc/leader-expendable.png
        [/effect]

        [effect]
            apply_to=overlay
            add=misc/plague-staff-icon.png
        [/effect]
    )
    (
        [modify_unit]
            [filter]
                x,y={X},{Y}
            [/filter]

            canrecruit=yes
            [filter_recall]
                trait=undead
            [/filter_recall]
        [/modify_unit]
        [set_extra_recruit]
            x,y={X},{Y}
            extra_recruit=Walking Corpse,Soulless
        [/set_extra_recruit]
        [fire_event]
            name=plague_staff_picked_up
        [/fire_event]
    )
    }
#enddef

#define GLOBAL__DROPPABLE_PLAGUE_STAFF
    {GLOBAL__DROPPABLE
    {ID_PLAGUE_STAFF}
    items/plague-staff.png
    _"Drop Plague Staff"
    ({PLACE_ITEM_PLAGUE_STAFF $unit.x $unit.y})
    ({PLACE_ITEM_PLAGUE_STAFF $x1 $y1}
    [modify_unit]
        [filter]
            x,y=$x1,$y1
        [/filter]

        canrecruit=no
    [/modify_unit]
    [set_extra_recruit]
        x,y=$x1,$y1
        extra_recruit=
    [/set_extra_recruit]
    [fire_event]
        name=plague_staff_dropped
    [/fire_event])
    }
#enddef

#define GLOBAL__PLAGUE_STAFF_RECRUIT_VARIATIONS
    # falcon has flight, spider has HP, wolf is general-purpose, sand_scorpion has impact resist
    {RECRUIT_UNIT_VARIATIONS 1 "Walking Corpse" falcon,spider,wolf,sand_scorpion}
    {RECRUIT_UNIT_VARIATIONS 1 "Soulless"       falcon,spider,wolf,sand_scorpion}
    [event]
        name=recruit

        [filter]
            side=1
            trait=undead
        [/filter]

        [filter_condition]
            [variable]
                name=owaec_done_complaining_plague
                not_equals=yes
            [/variable]
        [/filter_condition]
        {VARIABLE owaec_done_complaining_plague yes}
        [message]
            speaker=Dacyn
            #po: If the player accepts the plague staff, the unit that picks it up can recruit walking corpses of animals (but not humans),
            #po: randomly getting a falcon, spider, wolf or sand scorpion corpse. Here “crown” means “top of head”, or “top of cephalothorax”.
            #po: Dacyn says this the first time a corpse is recruited, and this event could happen in almost any scenario from S07b onwards.
            #po: Even before picking up the amulet, he’s showing a level of interest that might get a student expelled from the Academy on Alduin
            message=_"Fascinating. The necromantic magic concentrates in the subject’s crown, replacing its bestial soul. Unnatural, yet effective."
        [/message]
        [message]
            speaker=Owaec
            #po: First time a corpse is recruited by the wielder of the plague staff.
            message=_"A disgusting abomination! I lament living in such times..."
        [/message]
    [/event]
#enddef
#define REFRESH_PLAGUE_STAFF_UPKEEP
    [if]
        [have_unit]
            trait=TRAIT_{ID_PLAGUE_STAFF}
            [not]
                trait=loyal,loyal_dummy
            [/not]
        [/have_unit]

        [then]
            {STORE_UNIT_VAR (trait=TRAIT_{ID_PLAGUE_STAFF}) level staff_level}
            {MODIFY_UNIT (id=Dacyn) upkeep $staff_level}
            {CLEAR_VARIABLE staff_level}
        [/then]

        [else]
            {MODIFY_UNIT (id=Dacyn) upkeep 0}
        [/else]
    [/if]
#enddef
#define GLOBAL__PLAGUE_STAFF_USE_UPKEEP
    # normally, canrecruit=yes means the plague staff wielder has no upkeep
    # unfortunately, this unbalances the northlands scenarios, since an additional loyal unit is worth several hundred gold.
    # I don't want to just reduce the player's gold each turn, since that won't show up in the upkeep UI
    # instead, this is an awful solution where I modify Dacyn's upkeep (normally 0) to pretend to be the plague staff holder
    [event]
        name=new turn,plague_staff_picked_up,plague_staff_dropped
        first_time_only=no
        {REFRESH_PLAGUE_STAFF_UPKEEP}
        [allow_undo]
        [/allow_undo]
        [on_undo]
            {REFRESH_PLAGUE_STAFF_UPKEEP}
        [/on_undo]
    [/event]
    [event]
        name=recall,post advance,die
        first_time_only=no

        [filter]
            trait=TRAIT_{ID_PLAGUE_STAFF}
        [/filter]

        {REFRESH_PLAGUE_STAFF_UPKEEP}
        [allow_undo]
        [/allow_undo]
        [on_undo]
            {REFRESH_PLAGUE_STAFF_UPKEEP}
        [/on_undo]
    [/event]
#enddef

#define HERB_OVERLAY_ONESCENARIO
    [object]
        name= _ "Gwza-Alswdan"
        duration=scenario
        [effect]
            apply_to=status
            remove=poisoned
        [/effect]
        [effect]
            apply_to=overlay
            add=misc/herb-icon.png
        [/effect]
    [/object]
#enddef

#################################################################################################################################################
#
#define PLACE_ELIXIR ID IMAGE X Y ITEM_NAME ITEM_DESC MODIFY
    [item]
        x,y={X},{Y}
        image={IMAGE}
    [/item]
    [event]
        name=moveto
        id=EVENT_{ID}
        first_time_only=no
        delayed_variable_substitution=no
        [filter]
            side=1
            x,y={X},{Y}

            [not]
                trait=undead
            [/not]
            # most of these items would feel strange on a WC or Soulless
        [/filter]
        [item_dialog]
            name={ITEM_NAME}
            image={IMAGE}
            description={ITEM_DESC}
            effect=_"<span size='small'><i>  (Elixirs only last for 1 scenario.)</i></span>
<span size='small'><i>  Picking up an item consumes your moves and attack.</i></span>
<b></b>"
            take_string=_"Take it."
            leave_string=_"Leave it."
        [/item_dialog]
        [if]
            {VARIABLE_CONDITIONAL item_picked equals yes}
            [then]
                [remove_event]
                    id=EVENT_{ID}
                [/remove_event]
                [remove_item]
                    x,y={X},{Y}
                    image={IMAGE}
                [/remove_item]
                {MODIFY}
            [/then]
        [/if]
    [/event]
#enddef

#define ELIXIR_OF_WATER_BREATHING X Y
    {HIGHLIGHT_IMAGE {X} {Y} items/potion-blue.png ()}
    {PLACE_ELIXIR waterbreathing  items/potion-blue.png  {X}  {Y}
    _"Elixir of Water Breathing"
    _"This shimmering blue vial grants its drinker normal movement and defense in swamp and shallow water."
    {GIVE_WATER_BREATHING {X} {Y} (moves,attacks_left=0,0)}
    }
#enddef
#define GIVE_WATER_BREATHING X Y MODIFICATIONS
    [sound]
        name=potion.ogg
    [/sound]

    [delay]
        time=1500
    [/delay]

    {MODIFY_UNIT (x,y={X},{Y}) status.poisoned yes}
    [delay]
        time=300
    [/delay]
    {MODIFY_UNIT (x,y={X},{Y}) status.poisoned no}
    [floating_text]
        x,y={X},{Y}
        text= _ "<span color='#00FFFF' size='x-small'>water breathing</span>"
    [/floating_text]

    [modify_unit]
        [filter]
            side=1
            x,y={X},{Y}
        [/filter]

        {MODIFICATIONS}
        [trait]
            id=TRAIT_waterbreathing
            name=_ "waterbreathing"
            description=_"An elixir of waterbreathing has given this unit normal movement and defense in swamp and shallow water."
            [effect]
                apply_to=movement_costs
                replace=yes
                [movement_costs]
                    shallow_water=1
                    reef=1
                    swamp_water=1
                [/movement_costs]
            [/effect]
            [effect]
                apply_to=defense
                replace=yes
                [defense]
                    shallow_water=60
                    reef=50
                    swamp_water=60
                [/defense]
            [/effect]
        [/trait]
    [/modify_unit]

    [event] # auto-remove the elixir when the scenario completes
        name=victory
        [remove_trait]
            trait_id=TRAIT_waterbreathing
        [/remove_trait]
    [/event]
#enddef

#define ELIXIR_OF_ELEMENTS X Y
    {HIGHLIGHT_IMAGE {X} {Y} items/potion-yellow.png ()}
    {PLACE_ELIXIR "elements"  items/potion-yellow.png  {X}  {Y}
    _"Elixir of Elements"
    _"This bubbling yellow vial grants immunity to both fire and cold. It also makes you sweat profusely."
    {GIVE_ELEMENTS {X} {Y} (moves,attacks_left=0,0)}
    }
#enddef
#define GIVE_ELEMENTS X Y MODIFICATIONS
    [sound]
        name=potion.ogg
    [/sound]

    [delay]
        time=1500
    [/delay]

    {MODIFY_UNIT (x,y={X},{Y}) status.poisoned yes}
    [delay]
        time=300
    [/delay]
    {MODIFY_UNIT (x,y={X},{Y}) status.poisoned no}
    [floating_text]
        x,y={X},{Y}
        text= _ "<span color='#E8B923' size='x-small'>elemental resist</span>"
    [/floating_text]

    {STORE_UNIT_VAR x,y={X},{Y} id elixir_drinker} # used for frostbite immunity

    [modify_unit]
        [filter]
            side=1
            x,y={X},{Y}
        [/filter]

        {MODIFICATIONS}
        [trait]
            id=TRAIT_elements
            name= _ "elements"
            description=_"An elixir of elements has given this unit immunity to both fire and cold."
            [effect]
                apply_to=resistance
                replace=yes
                [resistance]
                    cold=0
                    fire=0
                [/resistance]
            [/effect]
        [/trait]
    [/modify_unit]

    [event] # auto-remove the elixir when the scenario completes
        name=victory
        [remove_trait]
            trait_id=TRAIT_elements
        [/remove_trait]
    [/event]
#enddef

#define DISPLAY_HASTE
    # hahid is the only one drinks the elixir of haste, but still show a pretty popup
    [item_dialog_musttake]
        name= _ "Elixir of Haste"
        image=items/potion-green.png
        description=_"This saccharine green liquid grants +1 movement and +10% defense on all terrain. You may have difficulty standing still."
        effect=_"<span size='small'><i>  (Elixirs only last for 1 scenario.)</i></span>
<span size='small'><i>  Picking up an item consumes your moves and attack.</i></span>
<b></b>"
        take_string=_"Take it."
    [/item_dialog_musttake]
#enddef
#define GIVE_HASTE X Y MODIFICATIONS
    [sound]
        name=potion.ogg
    [/sound]

    [delay]
        time=1500
    [/delay]

    {MODIFY_UNIT (x,y={X},{Y}) status.poisoned yes}
    [delay]
        time=300
    [/delay]
    {MODIFY_UNIT (x,y={X},{Y}) status.poisoned no}
    [floating_text]
        x,y={X},{Y}
        text= _ "<span color='#0BDA51' size='x-small'>haste</span>"
    [/floating_text]

    [modify_unit]
        [filter]
            side=1
            x,y={X},{Y}
        [/filter]

        {MODIFICATIONS}
        [trait]
            id=TRAIT_haste
            name=_"haste"
            description=_"An elixir of haste has given this unit +1 movement and +10% defense on all terrain."
            [effect]
                apply_to=movement
                increase=1
            [/effect]
            [effect]
                apply_to=defense
                [defense]
                    deep_water=-10
                    shallow_water=-10
                    reef=-10
                    swamp_water=-10
                    flat=-10
                    sand=-10
                    forest=-10
                    hills=-10
                    mountains=-10
                    village=-10
                    castle=-10
                    cave=-10
                    frozen=-10
                    fungus=-10
                [/defense]
            [/effect]
        [/trait]
    [/modify_unit]

    [event] # auto-remove the elixir when the scenario completes
        name=victory
        [remove_trait]
            trait_id=TRAIT_haste
        [/remove_trait]
    [/event]
#enddef

#define ELIXIR_OF_FURY X Y
    {HIGHLIGHT_IMAGE {X} {Y} items/potion-red.png ()}
    {PLACE_ELIXIR "elements"  items/potion-red.png  {X}  {Y}
    _"Elixir of Fury"
    _"The red liquid in this vial sloshes violently, as though trying to escape. Drinking it grants <b><i>unlimited melee attacks</i></b> and the <b><i>berserk</i></b> melee special."
    {GIVE_FURY {X} {Y} (moves,attacks_left=0,0)}
    }
#enddef
#define GIVE_FURY X Y MODIFICATIONS
    [sound]
        name=potion.ogg
    [/sound]

    [delay]
        time=1500
    [/delay]

    {MODIFY_UNIT (x,y={X},{Y}) status.poisoned yes}
    [delay]
        time=300
    [/delay]
    {MODIFY_UNIT (x,y={X},{Y}) status.poisoned no}
    [floating_text]
        x,y={X},{Y}
        text= _ "<span color='#FF0000' size='x-small'>berserker fury</span>"
    [/floating_text]

    [modify_unit]
        [filter]
            side=1
            x,y={X},{Y}
        [/filter]

        {MODIFICATIONS}
        [trait]
            id=TRAIT_fury
            name=_"fury"
            description=_"An elixir of fury has given this unit <b><i>unlimited melee attacks</i></b> and the <b><i>berserk</i></b> melee special."
            [effect]
                apply_to=attack
                range=melee
                set_attacks_used=0
                [set_specials]
                    mode=append
                    {WEAPON_SPECIAL_BERSERK}
                [/set_specials]
            [/effect]
        [/trait]
    [/modify_unit]

    [event] # auto-remove the elixir when the scenario completes
        name=victory
        [remove_trait]
            trait_id=TRAIT_fury
        [/remove_trait]
    [/event]
#enddef
