#textdomain wesnoth-sota

#define SIDE_1_ARDONNA_BASE
    side=1
    controller=human
    team_name=good
    user_team_name= _ "Ardonna"
    # This type of Dark Adept cannot eventually advance to a lich.
    type=Dark Adept SotA
    id=Ardonna
    profile=portraits/ardonna.png
    gender=female
    name= _ "Ardonna"
    canrecruit=yes
    [modifications]
        {TRAIT_QUICK}
        {TRAIT_RESILIENT}
    [/modifications]
    {FLAG_VARIANT undead}
#enddef

#define SIDE_1_ARDONNA
    {SIDE_1_ARDONNA_BASE}
    recruit=Vampire Bat
#enddef

#define SIDE_1_ARDONNA_EARLY
    {SIDE_1_ARDONNA_BASE}
    recruit=Vampire Bat SotA
#enddef

#define SIDE_1_RAS-TABAHN
    side=1
    controller=human
    team_name=good
    user_team_name= _ "Ras-Tabahn"
    # This type of Dark Sorcerer cannot advance to a lich.
    type=Dark Sorcerer SotA
    id=Ras-Tabahn
    name= _ "Ras-Tabahn"
    canrecruit=yes
    [modifications]
        {TRAIT_STRONG}
        {TRAIT_INTELLIGENT}
    [/modifications]
    recruit=Walking Corpse,Ghost,Skeleton,Skeleton Archer
    {FLAG_VARIANT undead}
#enddef

#define SIDE_1_BOTH
    side=1
    controller=human
    team_name=good
    user_team_name= _ "Ardryn-Na"
    # This type of Dark Adept cannot eventually advance to a lich.
    type=Dark Adept SotA
    id=Ardonna
    profile=portraits/ardonna.png
    gender=female
    name= _ "Ardryn-Na"
    canrecruit=yes
    [modifications]
        {TRAIT_QUICK}
        {TRAIT_RESILIENT}
    [/modifications]
    {FLAG_VARIANT undead}
    recruit=Walking Corpse,Ghost,Skeleton,Skeleton Archer
#enddef

#define RECALL_LOYAL_UNITS
    [recall]
        id=Bone Captain
        show=no
    [/recall]
    [recall]
        id=Carcyn
        show=no
    [/recall]
    # Only one Shynal will be recalled.
    [recall]
        id=Shynal
        show=no
    [/recall]
    [recall]
        id=Corpse Shynal
        show=no
    [/recall]
    [recall]
        id=Vendraxis
        show=no
    [/recall]
    [recall]
        id=Ras-Tabahn
        show=no
    [/recall]
#enddef

#define HOW_TO_LOSE_WITH_ARDONNA
    [objective]
        description= _ "Death of Ardonna"
        condition=lose
    [/objective]
    {TURNS_RUN_OUT}
#enddef

#define HOW_TO_LOSE_WITH_RAS-TABAHN
    [objective]
        description= _ "Death of Ras-Tabahn"
        condition=lose
    [/objective]
    {TURNS_RUN_OUT}
#enddef

#define HOW_TO_LOSE_WITH_BOTH
    [objective]
        description= _ "Death of Ardryn-Na"
        condition=lose
    [/objective]
    [objective]
        description= _ "Death of Ras-Tabahn"
        condition=lose
    [/objective]
    {TURNS_RUN_OUT}
#enddef

#define HERO_DEATHS
    [event]
        name=last_breath
        [filter]
            id=Ardonna
        [/filter]
        [message]
            speaker=Ardonna
            message= _ "No, no, NO, <i><b>NO</b></i>!"
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Ardonna
        [/filter]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=last_breath
        [filter]
            id=Ras-Tabahn
        [/filter]
        [message]
            speaker=Ras-Tabahn
            message= _ "Urgh."
        [/message]
    [/event]

    [event]
        name=die
        [filter]
            id=Ras-Tabahn
            race=human
        [/filter]
        [message]
            speaker=Ardonna
            message= _ "But I don't know how to bring you back yet!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=die
        [filter]
            id=Ras-Tabahn
            race=undead
        [/filter]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=die
        [filter]
            id=Shynal
            race=human
        [/filter]
        [if]
            [have_unit]
                id=Carcyn
            [/have_unit]
            [then]
                [message]
                    speaker=Carcyn
                    message= _ "Shynal!"
                [/message]
                [message]
                    speaker=Carcyn
                    message= _ "Bring her back. Please!"
                [/message]
                [message]
                    speaker=Ardonna
                    message= _ "I'm not sure that's such a good..."
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "If you insist."
                [/message]
                {ADVANCE_UNIT (id=Shynal) (Walking Corpse Shynal)}
                [modify_unit]
                    [filter]
                        type=Walking Corpse Shynal
                    [/filter]
                    id=Corpse Shynal
                [/modify_unit]
                [message]
                    speaker=Corpse Shynal
                    message= _ "Car. Cyn."
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "She will not know you for long, so make the most of it."
                [/message]

                [event]
                    name=die
                    [filter]
                        id=Corpse Shynal
                    [/filter]
                    [message]
                        speaker=Carcyn
                        message= _ "Perhaps that was for the best."
                    [/message]
                [/event]
            [/then]
        [/if]
    [/event]

    [event]
        name=die
        [filter]
            id=Shynal
            type=Lich SotA, Ancient Lich SotA, Lich, Ancient Lich
        [/filter]
        [if]
            [have_unit]
                id=Carcyn
            [/have_unit]
            [then]
                [message]
                    speaker=Carcyn
                    message= _ "Shynal!"
                [/message]
                [message]
                    speaker=Carcyn
                    message= _ "Bring her back. Please!"
                [/message]
                [message]
                    speaker=Ras-Tabahn
                    message= _ "It's not possible. She was already back from the dead. She has been utterly destroyed this time."
                [/message]
            [/then]
        [/if]
    [/event]

    [event]
        name=last_breath
        [filter]
            id=Carcyn
        [/filter]
        [message]
            speaker=Shynal
            message= _ "Oh, my sweet Carcyn!"
        [/message]
    [/event]
    [event]
        name=die
        [filter]
            id=Carcyn
        [/filter]
        [if]
            [variable]
                name=side_number
                equals=1
            [/variable]
            [then]
                [message]
                    speaker=Shynal
                    message= _ "You were always so reckless."
                [/message]
            [/then]
            [else]
                [message]
                    speaker=Shynal
                    message= _ "I will miss you."
                [/message]
            [/else]
        [/if]
    [/event]
#enddef

# Ardonna is a normal unit, but uses mostly custom portraits. These events cause the
# portrait to change as necessary. The profile event is called automatically by the
# post_advance event or can be called manually. This macro is included in every scenario.
#define MANAGE_PROFILE
    [event]
        name=post_advance
        first_time_only=no
        [filter]
            id=Ardonna
        [/filter]

        [fire_event]
            name=ardonna_profile
        [/fire_event]
    [/event]

    [event]
        name=ardonna_profile
        first_time_only=no

        [store_unit]
            [filter]
                id=Ardonna
            [/filter]
            variable=Ardonna_stored
        [/store_unit]
        [switch]
            variable=Ardonna_stored.type
            [case]
                value=Necromancer SotA
                [set_variable]
                    name=Ardonna_stored.profile
                    value="portraits/humans/necromancer+female.png"
                [/set_variable]
            [/case]
            [case]
                value=Lich SotA, Ancient Lich SotA
                [set_variable]
                    name=Ardonna_stored.profile
                    value="portraits/ardonna-lich.png"
                [/set_variable]
            [/case]
            # Other values should not change it from "profile=portraits/ardonna.png"
        [/switch]
        [unstore_unit]
            variable=Ardonna_stored
        [/unstore_unit]
        [clear_variable]
            name=Ardonna_stored
        [/clear_variable]
    [/event]
#enddef

# If one of the two kids is advanced to something other than a Dark Adept, they complain.
# The player is given the choice to reconsider. They say something about being very
# powerful which may clue the player in to the fact that they can become Ancient Liches,
# and that it would be a good idea to go that way. Maybe.
#define KIDS_ADVANCE
    [event]
        name=post_advance
        first_time_only=no
        [filter]
            id=Carcyn, Shynal
        [/filter]
        [if]
            [have_unit]
                id=$unit.id
                type=Footpad, Thug
            [/have_unit]
            [then]
                [fire_event]
                    name=argue_about_advancement
                    [primary_unit]
                        id=$unit.id
                    [/primary_unit]
                [/fire_event]
            [/then]
        [/if]

        [if]
            # Shynal uses a couple custom portraits. We manage them here.
            [variable]
                name=unit.id
                equals=Shynal
            [/variable]
            [then]
                [store_unit]
                    # Her type may have just changed, so we will store a fresh
                    # copy of the unit.
                    [filter]
                        id=$unit.id
                    [/filter]
                    variable=Shynal_stored
                [/store_unit]
                [switch]
                    variable=Shynal_stored.type
                    [case]
                        value=Dark Adept SotA, Dark Adept, Dark Sorcerer SotA, Dark Sorcerer
                        [set_variable]
                            name=Shynal_stored.profile
                            value="portraits/shynal-adept.png"
                        [/set_variable]
                    [/case]
                    [case]
                        value=Necromancer SotA, Necromancer
                        [set_variable]
                            name=Shynal_stored.profile
                            value="portraits/humans/necromancer+female.png"
                        [/set_variable]
                    [/case]
                    [case]
                        value=Lich
                        [set_variable]
                            name=Shynal_stored.profile
                            value="portraits/lich.png"
                        [/set_variable]
                    [/case]
                    [case]
                        value=Ancient Lich
                        [set_variable]
                            name=Shynal_stored.profile
                            value="portraits/brown-lich.png"
                        [/set_variable]
                    [/case]
                    # Other values should not change it from its original
                    # outlaw-themed value.
                [/switch]
                [unstore_unit]
                    variable=Shynal_stored
                [/unstore_unit]
                [clear_variable]
                    name=Shynal_stored
                [/clear_variable]
            [/then]
        [/if]
    [/event]

    # This event is split from above for readability.
    [event]
        name=argue_about_advancement
        first_time_only=no
        [if]
            # The dialog is different if one of the kids is already a Dark something.
            [have_unit]
                type=Dark Adept SotA, Dark Sorcerer SotA, Necromancer SotA, Dark Adept, Dark Sorcerer, Necromancer
                [and]
                    id=Shynal
                    [or]
                        id=Carcyn
                    [/or]
                [/and]
            [/have_unit]
            [then]
                [if]
                    [variable]
                        name=unit.id
                        equals=Carcyn
                    [/variable]
                    [then]
                        [message]
                            speaker=$unit.id
                            message= _ "Aww. I wanted to be a mage like Shynal."
                        [/message]
                    [/then]
                    [else]
                        [message]
                            speaker=$unit.id
                            message= _ "Aww. I wanted to be a mage like Carcyn."
                        [/message]
                    [/else]
                [/if]
                [message]
                    speaker=Ras-Tabahn
                    [option]
                        message= _ "Do not make me regret liberating you from jail. My decision is final."
                    [/option]
                    [option]
                        message= _ "I have reconsidered. Perhaps you will be very powerful one day."
                        [command]
                            {ADVANCE_UNIT (id=$unit.id) (Dark Adept SotA)}
                            [modify_unit]
                                [filter]
                                    id=$unit.id
                                [/filter]
                                experience=$unit.experience
                            [/modify_unit]
                            [message]
                                speaker=$unit.id
                                message= _ "Thanks!"
                            [/message]
                        [/command]
                    [/option]
                [/message]
            [/then]
            [else]
                [if]
                    [variable]
                        name=refused_to_make_DA
                        not_equals=yes
                    [/variable]
                    [then]
                        [message]
                            speaker=$unit.id
                            message= _ "Hey, I wanted to be a wizard like you and live forever when you figure it out! I know I could be super-powerful in the end."
                        [/message]

                        [message]
                            speaker=Ras-Tabahn
                            [option]
                                message= _ "Hold your tongue. You will do as I command."
                                [command]
                                    [set_variable]
                                        name=refused_to_make_DA
                                        value=yes
                                    [/set_variable]
                                [/command]
                            [/option]
                            [option]
                                message= _ "Very well. Having more adepts might be a good idea after all."
                                [command]
                                    {ADVANCE_UNIT (id=$unit.id) (Dark Adept SotA)}
                                    [modify_unit]
                                        [filter]
                                            id=$unit.id
                                        [/filter]
                                        experience=$unit.experience
                                    [/modify_unit]
                                [/command]
                            [/option]
                        [/message]
                    [/then]
                [/if]
            [/else]
        [/if]
    [/event]
#enddef

#define JOURNEY_PART STAGE
    [part]
        [background_layer]
            image=maps/background.jpg
            scale_vertically=yes
            scale_horizontally=no
            keep_aspect_ratio=yes
        [/background_layer]
        [background_layer]
            image=maps/titlescreen.png
            scale_vertically=yes
            scale_horizontally=no
            keep_aspect_ratio=yes
            base_layer=yes
        [/background_layer]
        show_title=yes
        {JOURNEY_STAGE{STAGE}}
    [/part]
#enddef

#define FREEZE_UNIT ID
    [object]
        id=freeze_unit
        take_only_once=no
        silent=yes
        duration=scenario  # So this object will not be in the save files forever.
        [filter]
            id={ID}
        [/filter]
        [effect]
            apply_to=movement_costs
            replace=yes
            [movement_costs]
                shallow_water={UNREACHABLE}
                reef={UNREACHABLE}
                swamp_water={UNREACHABLE}
                flat={UNREACHABLE}
                sand={UNREACHABLE}
                forest={UNREACHABLE}
                hills={UNREACHABLE}
                mountains={UNREACHABLE}
                village={UNREACHABLE}
                castle={UNREACHABLE}
                cave={UNREACHABLE}
                frozen={UNREACHABLE}
                unwalkable={UNREACHABLE}
                fungus={UNREACHABLE}
            [/movement_costs]
        [/effect]
    [/object]
#enddef

#define THAW_UNIT ID
    [remove_object]
        id={ID}
        object_id=freeze_unit
    [/remove_object]
#enddef

# Finds the nearest hex to (X,Y) within MAX_DISTANCE that matches the FILTER, and stores
# the location in VARIABLE with x, y, and terrain. If there is more than one location
# found, VARIABLE will be an array.
#define NEAREST_HEX X Y MAX_DISTANCE FILTER VAR_NAME
    [set_variable]
        name=distance
        value=0
    [/set_variable]
    [set_variable]
        name=location_found
        value=no
    [/set_variable]
    [clear_variable]
        name={VAR_NAME}
    [/clear_variable]

    # Store any matching locations within a radius of "distance". If nothing got stored,
    # add one to "distance" and try again. Do this until a location is found, or
    # "distance" goes over the MAX_DISTANCE:
    [while]
        [variable]
            name={VAR_NAME}.length
            less_than=1
        [/variable]
        [and]
            [variable]
                name=distance
                less_than_equal_to={MAX_DISTANCE}
            [/variable]
        [/and]

        [do]
            [store_locations]
                {FILTER}
                [and]
                    x={X}
                    y={Y}
                    radius=$distance
                [/and]
                variable={VAR_NAME}
            [/store_locations]

            [if]
                [variable]
                    name={VAR_NAME}.length
                    greater_than=0
                [/variable]
                [then]
                    [set_variable]
                        name=location_found
                        value=yes
                    [/set_variable]
                [/then]
            [/if]

            [set_variable]
                name=distance
                add=1
            [/set_variable]
        [/do]
    [/while]

    [clear_variable]
        name=location_found, distance
    [/clear_variable]
#enddef

# Conditional clause that means both Carcyn and Shynal are still alive.
#define BOTH_KIDS_LIVE
    [and]
        [have_unit]
            id=Shynal
        [/have_unit]
        [have_unit]
            id=Carcyn
        [/have_unit]
    [/and]
#enddef

# Conditional clause that means both Carcyn and Shynal are dead.
#define NO_KIDS_LIVE
    [and]
        [not]
            [have_unit]
                id=Shynal
            [/have_unit]
        [/not]
        [not]
            [have_unit]
                id=Carcyn
            [/have_unit]
        [/not]
    [/and]
#enddef

# Conditional clause that means only Carcyn *or* Shynal is still alive.
#define ONE_KID_LIVES
    [and]
        [have_unit]
            id=Shynal
        [/have_unit]
        [not]
            [have_unit]
                id=Carcyn
            [/have_unit]
        [/not]
    [/and]
    [or]
        [and]
            [have_unit]
                id=Carcyn
            [/have_unit]
            [not]
                [have_unit]
                    id=Shynal
                [/have_unit]
            [/not]
        [/and]
    [/or]
#enddef

# Returns the nearest unoccupied castle hex to the side's starting location. If there
# isn't one, the starting location is returned.
#define FIND_CASTLE_HEX SIDE VARIABLE
    [store_starting_location]
        side={SIDE}
        variable=side{SIDE}_keep_location
    [/store_starting_location]
    {NEAREST_HEX ($side{SIDE}_keep_location.x) ($side{SIDE}_keep_location.y) 6 (
        terrain=C*
        [not]
            [filter]
            [/filter]
        [/not]
    ) {VARIABLE}}
    [if]
        [variable]
            name={VARIABLE}.length
            less_than=1
        [/variable]
        [then]
            [set_variables]
                name={VARIABLE}
                to_variable=side{SIDE}_keep_location
            [/set_variables]
        [/then]
    [/if]
    [clear_variable]
        name=side{SIDE}_keep_location
    [/clear_variable]
#enddef

# This event turns a necromancer into a lich. It can be activated by an event or from
# a right-click menu option. It needs $unit to be set or it won't do anything.
#define TURN_INTO_A_LICH
    [event]
        name=lichify
        first_time_only=no

        # This is just to get a more descriptive name for the "unit" variable.
        [set_variables]
            name=stored_necromancer
            mode=replace
            to_variable=unit
        [/set_variables]

        # The necromancer may have AMLAd and had its experience reset to 0. Now, as a
        # lich, there is a fourth level available for the unit, and all that experience
        # should be applied towards the level-up instead of simply being lost. We will
        # "unwind" each AMLA and calculate how much it cost, so we can give back those
        # experience points.
        [set_variable]
            name=num_amlas
            # This gives us the number of AMLAs that the unit has had:
            value=$stored_necromancer.modifications.advancement.length
        [/set_variable]
        [set_variable]
            # The experience that will be used for the new lich will be at least
            # the necromancer's current actual experience.
            name=experience_gained_after_max_level
            value=$stored_necromancer.experience
        [/set_variable]
        [set_variable]
            # Each AMLA took 20% more experience, so we will need to reduce this
            # value as we unwind them. The variable starts out storing the amount
            # needed for the *next* AMLA, so we will need to reduce it one step as
            # the first operation.
            name=experience_for_one_amla
            value=$stored_necromancer.max_experience
        [/set_variable]

        [while]
            [variable]
                name=num_amlas
                greater_than=0
            [/variable]
            [do]
                [set_variable]
                    # Each AMLA increased the experience needed by 20%, which
                    # is the same as multiplying by 1.2. We reverse that here.
                    name=experience_for_one_amla
                    divide=1.2
                [/set_variable]
                [set_variable]
                    # Round it off in case it's a float:
                    name=experience_for_one_amla
                    round=0
                [/set_variable]
                [set_variable]
                    # Add the experience that was needed for the previous AMLA
                    # to the amount that will be given to the lich:
                    name=experience_gained_after_max_level
                    add=$experience_for_one_amla
                [/set_variable]
                [set_variable]
                    name=num_amlas
                    sub=1
                [/set_variable]
            [/do]
        [/while]

        # It's nice if Ardonna looks different as an ancient lich, and since there is
        # another sprite available, we will use it. She needs a different type though:
        [if]
            [variable]
                name=stored_necromancer.id
                equals=Ardonna
            [/variable]
            [then]
                [set_variable]
                    name=lich_type
                    value=Lich SotA
                [/set_variable]
            [/then]
            [else]
                [set_variable]
                    name=lich_type
                    value=Lich
                [/set_variable]
            [/else]
        [/if]

        # We are going to create a new unit instead of transforming the old one.
        # Using the old unit would leave its AMLAs in effect, changing the hitpoints
        # and experience needed to level up.
        [unit]
            side=1
            type=$lich_type
            x=$stored_necromancer.x
            y=$stored_necromancer.y
            id=$stored_necromancer.id
            name=$stored_necromancer.name
            facing=$stored_necromancer.facing
            moves=$stored_necromancer.moves
            overlays=$stored_necromancer.overlays
            hitpoints=$stored_necromancer.hitpoints
            canrecruit=$stored_necromancer.canrecruit
            attacks_left=$stored_necromancer.attacks_left
            experience=$experience_gained_after_max_level

            # Copy the original traits into the new unit:
            [modifications]
                [insert_tag]
                    name=trait
                    variable=stored_necromancer.modifications.trait[0]
                [/insert_tag]
                [insert_tag]
                    name=trait
                    variable=stored_necromancer.modifications.trait[1]
                [/insert_tag]
            [/modifications]

            to_variable=new_lich  # Don't create the unit yet. Just store it.
        [/unit]

        # Hitpoints are transferred to the new unit so that turning into a lich doesn't
        # heal it. However, this could result in the lich having more HP than its
        # maximum. If that is the case, we will reset it to the maximum.
        [if]
            [variable]
                name=new_lich.hitpoints
                greater_than=$new_lich.max_hitpoints
            [/variable]
            [then]
                [set_variable]
                    name=new_lich.hitpoints
                    value=$new_lich.max_hitpoints
                [/set_variable]
            [/then]
        [/if]

        # Liches have one more movement point than necromancers. We will give that point
        # to them as long as they have not attacked yet and were not just recruited on
        # this turn. Checking attacks_left takes both possibilities into account.
        [if]
            [variable]
                name=new_lich.attacks_left
                not_equals=0
            [/variable]
            [then]
                [set_variable]
                    name=new_lich.moves
                    add=1
                [/set_variable]
            [/then]
        [/if]

        # The leaders are changed in a scripted event at the end of a scenario, so
        # they need to be handled differently than normal units:
        [if]
            [variable]
                name=stored_necromancer.id
                not_equals=Ardonna
            [/variable]
            [variable]
                name=stored_necromancer.id
                not_equals=Ras-Tabahn
            [/variable]
            [then]
                [unstore_unit]
                    # The unit will be automatically advanced to Ancient Lich at
                    # this point if its experience is sufficient. Theoretically,
                    # it could even AMLA.
                    variable=new_lich
                    text= _ "Lich"  # This text goes by quickly, so it must be short.
                    red,green,blue=220,0,220  # dark-magic purple
                    animate=yes
                [/unstore_unit]
            [/then]
            [else]
                # It's unlikely, but one of the leaders could be at a lower
                # level, and therefore have fewer hitpoints than the same unit
                # as a lich. We will set the hitpoints to the maximum in case
                # that has happened.
                [set_variable]
                    name=new_lich.hitpoints
                    value=$new_lich.max_hitpoints
                [/set_variable]

                # The leaders are changed to liches in between scenarios, so if
                # we are working with one of them, the new unit needs to get
                # sent to the recall list.
                [set_variable]
                    name=new_lich.x
                    value=recall
                [/set_variable]
                [set_variable]
                    name=new_lich.y
                    value=recall
                [/set_variable]
                [unstore_unit]
                    variable=new_lich
                [/unstore_unit]
            [/else]
        [/if]

        [clear_variable]
            name=stored_necromancer, new_lich, lich_type, num_amlas, experience_for_one_amla, experience_gained_after_max_level
        [/clear_variable]
    [/event]
#enddef

# OFFSET changes depending on which map the ship is on. It only affects 'y' because the
# x-position of the ship is the same on both maps.
#define HIDE_SAILS_MENU_ITEM OFFSET
    [set_menu_item]
        id=hide-sails
        description= _ "Hide Sails and Rigging"

        [show_if]
            [variable]
                name=sails_hidden
                boolean_equals=no
            [/variable]
        [/show_if]

        [command]
            [terrain]
                x=5
                y="$(11+{OFFSET})"
                terrain=^
                layer=overlay
            [/terrain]
            [terrain]
                x=14
                y="$(9+{OFFSET})"
                terrain=^
                layer=overlay
            [/terrain]
            [terrain]
                x=7
                y="$(9+{OFFSET})"
                terrain=^Zrlp
                layer=overlay
            [/terrain]
            [set_variable]
                name=sails_hidden
                value=yes
            [/set_variable]
        [/command]
    [/set_menu_item]
#enddef

#define SHOW_SAILS_MENU_ITEM OFFSET
    [set_menu_item]
        id=show-sails
        description= _ "Show Sails and Rigging"

        [show_if]
            [variable]
                name=sails_hidden
                boolean_equals=yes
            [/variable]
        [/show_if]

        [command]
            [terrain]
                x=5
                y="$(11+{OFFSET})"
                terrain=^Zrig
                layer=overlay
            [/terrain]
            [terrain]
                x=14
                y="$(9+{OFFSET})"
                terrain=^Zpie
                layer=overlay
            [/terrain]
            [terrain]
                x=7
                y="$(9+{OFFSET})"
                terrain=^
                layer=overlay
            [/terrain]
            [set_variable]
                name=sails_hidden
                value=no
            [/set_variable]
        [/command]
    [/set_menu_item]
#enddef

# this is inserted in some scenarios to clear SotA Bats from older saves
# it needs to be in all scenarios which use SIDE_1_ARDONNA, otherwise the player
# may be able to recruit normal and SotA bats, or be able to recruit bats when
# he plays someone who should not be able to do so
#define SIDE_1_ARDONNA:TRANSFROM_BATS_TO_NORMAL_EVENT
    # SotA bats were necessary for the ship where they were drawn behind the
    # rigging, but not in later scenarios.
    [event]
        name=prestart

        # First, we'll make sure newly recruited ones will be correct
        [disallow_recruit]
            side=1
            type=Vampire Bat SotA
        [/disallow_recruit]
        [allow_recruit]
            side=1
            type=Vampire Bat
        [/allow_recruit]

        # Now the type of all bats on the recall list is changed
        [lua]
            code = <<
                for i, u in ipairs(wesnoth.get_recall_units { type = 'Vampire Bat SotA, Blood Bat SotA, Dread Bat SotA' }) do
                    if u.type == 'Vampire Bat SotA' then
                        u:transform('Vampire Bat')
                    elseif u.type == 'Blood Bat SotA' then
                        u:transform('Blood Bat')
                    elseif u.type == 'Dread Bat SotA' then
                        u:transform('Dread Bat')
                    end
                end
            >>
        [/lua]
    [/event]
#enddef
