#textdomain wesnoth-dw

# 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_NUMBER FILTER VAR_NAME
    [set_variable]
        name=distance
        value=0
    [/set_variable]

    [set_variable]
        name=location_found
        value=no
    [/set_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_NUMBER.
    [while]
        [variable]
            name=location_found
            equals=no
        [/variable]
        [and]
            [variable]
                name=distance
                less_than_equal_to={MAX_DISTANCE_NUMBER}
            [/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=distance
    [/clear_variable]

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

#define SIDE_1
    side=1
    controller=human
    team_name=good guys
    user_team_name= _ "Merman Forces"

    type=Merman Child King
    id=Kai Krellis
    name= _ "Kai Krellis"
    canrecruit=yes
    unrenamable=yes

    recruit=Merman Citizen, Merman Fighter, Merman Hunter, Mermaid Initiate
#enddef

#define RECALL_LOYAL_UNITS
    [recall]
        id=Cylanna
    [/recall]
    [recall]
        id=Gwabbo
    [/recall]
    [recall]
        id=Teeloa
    [/recall]
    [recall]
        id=Keshan
    [/recall]
    [recall]
        id=Inky
    [/recall]
    [recall]
        id=Tyegea
    [/recall]
    [recall]
        id=Friendly Bat
    [/recall]
    [recall]
        id=Undead Bat
    [/recall]
    [recall]
        id=Fearsome Bat
    [/recall]
#enddef

#define HOW_TO_LOSE
    [objective]
        description= _ "Death of Kai Krellis"
        condition=lose
    [/objective]
    [objective]
        description= _ "Death of Cylanna"
        condition=lose
    [/objective]

    {TURNS_RUN_OUT}
#enddef

#define HERO_DEATHS
    [event]
        name=die
        [filter]
            id=Cylanna
        [/filter]
        [message]
            speaker=Kai Krellis
            message= _ "Cylanna! I need you!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]

    [event]
        name=die
        [filter]
            id=Kai Krellis
        [/filter]
        [message]
            speaker=Cylanna
            message= _ "We are lost without our king!"
        [/message]
        [endlevel]
            result=defeat
        [/endlevel]
    [/event]
#enddef
