#textdomain wesnoth-anl

#define SHARE_COMMAND_COMMON
    [set_variable]
        name=finished_options
        value=yes
    [/set_variable]
    [set_variable]
        name=finished_suboptions
        value=yes
    [/set_variable]

    [set_variable]
        name=unit.status.worked_this_turn
        value=yes
    [/set_variable]
    [set_variable]
        name=unit.moves
        value=0
    [/set_variable]

    [redraw]
    [/redraw]
#enddef

#define DONATE_FUNDS_OPTION TARGET_SIDE
    [option]
        message= "<span color='green'>" + "$player_{TARGET_SIDE}.name" + "</span>" # wmllint: ignore no spellcheck
        [show_if]
            [variable]
                name=leader.gold
                greater_than_equal_to=20
            [/variable]

            [have_unit]
                side={TARGET_SIDE}
                canrecruit=yes
            [/have_unit]
        [/show_if]
        [command]
            [set_variable]
                name=df_player_name
                value=$player_{TARGET_SIDE}.name
            [/set_variable]
            [message]
                speaker=unit
                message= _ "I hereby donate 20 gold to the coffers of $df_player_name|."
            [/message]
            [clear_variable]
                name=df_player_name
            [/clear_variable]

            [gold]
                side={TARGET_SIDE}
                amount=20
            [/gold]
            [gold]
                side=$side_number
                amount=-20
            [/gold]

            [set_variable]
                name=leader.gold
                sub=20
            [/set_variable]

            {SHARE_COMMAND_COMMON}
        [/command]
    [/option]
#enddef

#define SHARE_FARMING_KNOWLEDGE_OPTION TARGET_SIDE
    [option]
        message= {MENU_IMG_TXT "items/flower4.png" $diplo_msg[{TARGET_SIDE}].farming}
        [show_if]
            [variable]
                name=player_$side_number|.farming.target
                greater_than=$player_{TARGET_SIDE}.farming.target
            [/variable]

            [have_unit]
                side={TARGET_SIDE}
                canrecruit=yes
            [/have_unit]
        [/show_if]
        [command]
            [set_variable]
                name=player_{TARGET_SIDE}.farming.progress
                add=1
            [/set_variable]

            {SHARE_COMMAND_COMMON}

            [set_variable]
                name=sf_player_name
                value=$player_{TARGET_SIDE}.name
            [/set_variable]
            [message]
                speaker=unit
                message= _ "$sf_player_name|, since our wisdom exceeds yours I have instructed my scholars to further your understanding of agriculture."
            [/message]

            [clear_variable]
                name=sf_player_name
            [/clear_variable]
        [/command]
    [/option]
#enddef

#define SHARE_MINING_KNOWLEDGE_OPTION TARGET_SIDE
    [option]
        message= {MENU_IMG_TXT "items/gold-coins-small.png" $diplo_msg[{TARGET_SIDE}].mining}
        [show_if]
            [variable]
                name=player_$side_number|.mining.target
                greater_than=$player_{TARGET_SIDE}.mining.target
            [/variable]

            [have_unit]
                side={TARGET_SIDE}
                canrecruit=yes
            [/have_unit]
        [/show_if]
        [command]
            [set_variable]
                name=player_{TARGET_SIDE}.mining.progress
                add=1
            [/set_variable]

            {SHARE_COMMAND_COMMON}

            [set_variable]
                name=sm_player_name
                value=$player_{TARGET_SIDE}.name
            [/set_variable]
            [message]
                speaker=unit
                message= _ "$sm_player_name|, since the wisdom of my people exceeds yours I have instructed my scholars to aid you in your efforts to learn the science of mining."
            [/message]

            [clear_variable]
                name=sm_player_name
            [/clear_variable]
        [/command]
    [/option]
#enddef

#define SHARE_WARFARE_KNOWLEDGE_OPTION TARGET_SIDE
    [option]
        message= {MENU_IMG_TXT "wesnoth-icon.png" $diplo_msg[{TARGET_SIDE}].warfare}
        [show_if]
            [variable]
                name=player_$side_number|.warfare.target
                greater_than=$player_{TARGET_SIDE}.warfare.target
            [/variable]

            [and]
                [variable]
                    name=player_{TARGET_SIDE}.troops
                    less_than=7
                [/variable]
            [/and]

            [have_unit]
                side={TARGET_SIDE}
                canrecruit=yes
            [/have_unit]
        [/show_if]
        [command]
            [set_variable]
                name=player_{TARGET_SIDE}.warfare.progress
                add=1
            [/set_variable]

            {SHARE_COMMAND_COMMON}

            [set_variable]
                name=sw_player_name
                value=$player_{TARGET_SIDE}.name
            [/set_variable]
            [message]
                speaker=unit
                message= _ "You know worryingly little about the arts of war, $sw_player_name|. I feel an obligation to instruct you in this vital matter."
            [/message]

            [clear_variable]
                name=sw_player_name
            [/clear_variable]
        [/command]
    [/option]
#enddef

#define LEADER_OPTIONS
    [set_menu_item]
        id=anl_diplomacy
        description=_ "Diplomacy"
        [show_if]
            [have_unit]
                side=$side_number
                x,y=$x1,$y1
                canrecruit=yes
                [not]
                    [filter_wml]
                        [status]
                            worked_this_turn=yes
                        [/status]
                    [/filter_wml]
                [/not]
            [/have_unit]
        [/show_if]
        [filter_location]
            terrain="Gg^Ve,Gg^Vea"
        [/filter_location]
        [command]
            [store_side]
                side=$side_number
                variable=leader
            [/store_side]

            [store_unit]
                [filter]
                    x=$x1
                    y=$y1
                [/filter]
                variable=unit
            [/store_unit]
            # build the translated messages for diplomatic options
            [set_variable]
                name=side_i
                value=0
            [/set_variable]
            [while]
                [variable]
                    name=side_i
                    less_than=4
                [/variable]
                [do]
                    [set_variable]
                        name=side_i
                        add=1
                    [/set_variable]
                    [set_variable]
                        name=player_name
                        to_variable="player_$side_i|.name"
                    [/set_variable]
                    [set_variable]
                        name=diplo_msg[$side_i].farming
                        # wmllint: markcheck off
                        value=_ "<span color='green'>$player_name</span>
Share knowledge of agriculture"
                        # wmllint: markcheck on
                    [/set_variable]
                    [set_variable]
                        name=diplo_msg[$side_i].mining
                        # wmllint: markcheck off
                        value=_ "<span color='green'>$player_name</span>
Share knowledge of mining"
                        # wmllint: markcheck on
                    [/set_variable]
                    [set_variable]
                        name=diplo_msg[$side_i].warfare
                        # wmllint: markcheck off
                        value=_ "<span color='green'>$player_name</span>
Share knowledge of warfare"
                        # wmllint: markcheck on
                    [/set_variable]
                    [clear_variable]
                        name=player_name
                    [/clear_variable]
                [/do]
            [/while]
            [clear_variable]
                name=side_i
            [/clear_variable]

            [set_variable]
                name=side
                value=$unit.side
            [/set_variable]
            [set_variable]
                name=finished_options
                value=no
            [/set_variable]

            [while]
                [variable]
                    name=finished_options
                    equals=no
                [/variable]

                [do]
                    [message]
                        caption= _ "Diplomatic Options"
                        speaker=unit
                        # wmllint: display on
                        message= _ "What shall I do?"
                        # wmllint: display off

                        # Nothing

                        [option]
                            message= _ "Nothing"
                            [command]
                                [set_variable]
                                    name=finished_options
                                    value=yes
                                [/set_variable]
                            [/command]
                        [/option]

                        # Giving Money

                        [option]
                            message= {MENU_IMG_TXT "items/gold-coins-small.png" ( _ "<span color='green'>Donate Funds</span>
Give 20 gold to another player")}
                            [command]
                                [set_variable]
                                    name=finished_suboptions
                                    value=no
                                [/set_variable]

                                [while]
                                    [variable]
                                        name=finished_suboptions
                                        equals=no
                                    [/variable]

                                    [do]
                                        [message]
                                            caption=_ "Diplomatic Options"
                                            speaker=unit
                                            image=items/gold-coins-small.png
                                            message= _ "Who will you donate funds to?"

                                            [option]
                                                message= _ "Back"
                                                [command]
                                                    [set_variable]
                                                        name=finished_suboptions
                                                        value=yes
                                                    [/set_variable]
                                                [/command]
                                            [/option]

                                            {DONATE_FUNDS_OPTION 1}
                                            {DONATE_FUNDS_OPTION 2}
                                            {DONATE_FUNDS_OPTION 3}
                                            {DONATE_FUNDS_OPTION 4}
                                        [/message]
                                    [/do]
                                [/while]
                            [/command]
                        [/option]

                        # Sharing Knowledge

                        [option]
                            message= {MENU_IMG_TXT "items/book4.png" ( _ "<span color='green'>Share Knowledge</span>
Help an ally with their research")}
                            [command]
                                [set_variable]
                                    name=finished_suboptions
                                    value=no
                                [/set_variable]

                                [while]
                                    [variable]
                                        name=finished_suboptions
                                        equals=no
                                    [/variable]

                                    [do]
                                        [message]
                                            caption= _ "Diplomatic Options"
                                            speaker=unit
                                            image=items/book4.png
                                            message= _ "Who will you share knowledge with?"

                                            [option]
                                                message= _ "Back"
                                                [command]
                                                    [set_variable]
                                                        name=finished_suboptions
                                                        value=yes
                                                    [/set_variable]
                                                [/command]
                                            [/option]

                                            {SHARE_FARMING_KNOWLEDGE_OPTION 1}
                                            {SHARE_MINING_KNOWLEDGE_OPTION 1}
                                            {SHARE_WARFARE_KNOWLEDGE_OPTION 1}

                                            {SHARE_FARMING_KNOWLEDGE_OPTION 2}
                                            {SHARE_MINING_KNOWLEDGE_OPTION 2}
                                            {SHARE_WARFARE_KNOWLEDGE_OPTION 2}

                                            {SHARE_FARMING_KNOWLEDGE_OPTION 3}
                                            {SHARE_MINING_KNOWLEDGE_OPTION 3}
                                            {SHARE_WARFARE_KNOWLEDGE_OPTION 3}

                                            {SHARE_FARMING_KNOWLEDGE_OPTION 4}
                                            {SHARE_MINING_KNOWLEDGE_OPTION 4}
                                            {SHARE_WARFARE_KNOWLEDGE_OPTION 4}
                                        [/message]
                                    [/do]
                                [/while]
                            [/command]
                        [/option]

                        # Negotiations

                        # Dwarves

                        [option]
                            message= {MENU_IMG_TXT "units/dwarves/lord.png~TC(1,magenta)" ( _ "<span color='green'>Negotiate with the Dwarves</span>
Lets you recruit a Dwarvish unit
Negotiation Progress: $player_$side_number|.leader_option_1.progress|/$player_$side_number|.leader_option_1.target")}
                            [show_if]
                                [variable]
                                    name=player_$side_number|.ally_1
                                    equals=no
                                [/variable]

                                [or]
                                    [variable]
                                        name=player_$side_number|.ally_2
                                        equals=no
                                    [/variable]
                                [/or]

                                [or]
                                    [variable]
                                        name=player_$side_number|.ally_3
                                        equals=no
                                    [/variable]
                                [/or]

                                [or]
                                    [variable]
                                        name=player_$side_number|.ally_4
                                        equals=no
                                    [/variable]
                                [/or]
                            [/show_if]
                            [command]
                                [set_variable]
                                    name=finished_options
                                    value=yes
                                [/set_variable]

                                [set_variable]
                                    name=unit.status.worked_this_turn
                                    value=yes
                                [/set_variable]
                                [set_variable]
                                    name=unit.moves
                                    value=0
                                [/set_variable]

                                [set_variable]
                                    name=player_$side_number|.leader_option_1.progress
                                    add=1
                                [/set_variable]
                            [/command]
                        [/option]

                        # Elves

                        [option]
                            message= {MENU_IMG_TXT "units/elves-wood/marshal.png~TC(1,magenta)" ( _ "<span color='green'>Negotiate with the Elves</span>
Lets you recruit an Elvish unit
Negotiation Progress: $player_$side_number|.leader_option_2.progress|/$player_$side_number|.leader_option_2.target")}
                            [show_if]
                                [variable]
                                    name=player_$side_number|.ally_5
                                    equals=no
                                [/variable]

                                [or]
                                    [variable]
                                        name=player_$side_number|.ally_6
                                        equals=no
                                    [/variable]
                                [/or]

                                [or]
                                    [variable]
                                        name=player_$side_number|.ally_7
                                        equals=no
                                    [/variable]
                                [/or]

                                [or]
                                    [variable]
                                        name=player_$side_number|.ally_8
                                        equals=no
                                    [/variable]
                                [/or]
                            [/show_if]
                            [command]
                                [set_variable]
                                    name=finished_options
                                    value=yes
                                [/set_variable]

                                [set_variable]
                                    name=unit.status.worked_this_turn
                                    value=yes
                                [/set_variable]
                                [set_variable]
                                    name=unit.moves
                                    value=0
                                [/set_variable]

                                [set_variable]
                                    name=player_$side_number|.leader_option_2.progress
                                    add=1
                                [/set_variable]
                            [/command]
                        [/option]
                    [/message]
                [/do]
            [/while]

            # Picking a Diplomactic recruit

            # Dwarves

            [if]
                [variable]
                    name=player_$side_number|.leader_option_1.progress
                    greater_than_equal_to=$player_$side_number|.leader_option_1.target
                [/variable]

                [then]
                    [message]
                        speaker=narrator
                        caption=_ "Negotiation Complete"
                        image=portraits/dwarves/transparent/lord.png
                        # wmllint: display on
                        message= _ "Our talks are complete — the Dwarves will gladly fight by your side. Which of our brethren do you want to recruit?"
                        # wmllint: display off

                        #textdomain wesnoth-units
                        {PICK_RECRUIT_OPTION ("units/dwarves/fighter.png~TC($side_number|,magenta)") "Dwarvish Fighter" _"Dwarvish Fighter" ally_1}
                        {PICK_RECRUIT_OPTION ("units/dwarves/guard.png~TC($side_number|,magenta)") "Dwarvish Guardsman" _"Dwarvish Guardsman" ally_2}
                        {PICK_RECRUIT_OPTION ("units/dwarves/thunderer.png~TC($side_number|,magenta)") "Dwarvish Thunderer" _"Dwarvish Thunderer" ally_3}
                        {PICK_RECRUIT_OPTION ("units/dwarves/ulfserker.png~TC($side_number|,magenta)") "Dwarvish Ulfserker" _"Dwarvish Ulfserker" ally_4}
                        #textdomain wesnoth-anl
                    [/message]

                    [set_variable]
                        name=player_$side_number|.leader_option_1.progress
                        value=0
                    [/set_variable]
                [/then]
            [/if]

            # Elves

            [if]
                [variable]
                    name=player_$side_number|.leader_option_2.progress
                    greater_than_equal_to=$player_$side_number|.leader_option_2.target
                [/variable]

                [then]
                    [message]
                        speaker=narrator
                        caption=_ "Negotiation Complete"
                        image=portraits/elves/transparent/high-lord.png
                        # wmllint: display on
                        message= _ "Our talks are complete — the Elves shall aid you in this battle. Which our of kin do you wish to recruit?"
                        # wmllint: display off

                        #textdomain wesnoth-units
                        {PICK_RECRUIT_OPTION ("units/elves-wood/archer.png~TC($side_number|,magenta)") "Elvish Archer" _"Elvish Archer" ally_5}
                        {PICK_RECRUIT_OPTION ("units/elves-wood/fighter.png~TC($side_number|,magenta)") "Elvish Fighter" _"Elvish Fighter" ally_6}
                        {PICK_RECRUIT_OPTION ("units/elves-wood/scout.png~TC($side_number|,magenta)") "Elvish Scout" _"Elvish Scout" ally_7}
                        {PICK_RECRUIT_OPTION ("units/elves-wood/shaman.png~TC($side_number|,magenta)") "Elvish Shaman" _"female^Elvish Shaman" ally_8}
                        #textdomain wesnoth-anl
                    [/message]

                    [set_variable]
                        name=player_$side_number|.leader_option_2.progress
                        value=0
                    [/set_variable]
                [/then]
            [/if]

            [unstore_unit]
                variable=unit
            [/unstore_unit]
        [/command]
    [/set_menu_item]
#enddef
