#textdomain wesnoth-anl
#define DONATE_FUNDS_OPTION TARGET_SIDE
    [option]
        message= "@$player_{TARGET_SIDE}.name"	# wmllint: ignore
        [show_if]
            {CONDITION leader.gold greater_than_equal_to 20}
            [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]
            {ADD_GOLD {TARGET_SIDE} 20}
            {ADD_GOLD $side_number -20}
            {VARIABLE_OP leader.gold add -20}
            {VARIABLE finished_options yes}
            {VARIABLE finished_suboptions yes}
            {VARIABLE unit.status.worked_this_turn yes}
            {VARIABLE unit.moves 0}
            {REDRAW}
        [/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]
            {CONDITION player_$side_number|.farming.target greater_than $player_{TARGET_SIDE}.farming.target}
            [have_unit]
                side={TARGET_SIDE}
                canrecruit=yes
            [/have_unit]
        [/show_if]
        [command]
            {VARIABLE_OP player_{TARGET_SIDE}.farming.progress add 1}
            {VARIABLE finished_options yes}
            {VARIABLE finished_suboptions yes}
            {VARIABLE unit.status.worked_this_turn yes}
            {VARIABLE unit.moves 0}
            {REDRAW}
            [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]
            {CONDITION player_$side_number|.mining.target greater_than $player_{TARGET_SIDE}.mining.target}
            [have_unit]
                side={TARGET_SIDE}
                canrecruit=yes
            [/have_unit]
        [/show_if]
        [command]
            {VARIABLE_OP player_{TARGET_SIDE}.mining.progress add 1}
            {VARIABLE finished_options yes}
            {VARIABLE finished_suboptions yes}
            {VARIABLE unit.status.worked_this_turn yes}
            {VARIABLE unit.moves 0}
            {REDRAW}
            [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]
            {CONDITION player_$side_number|.warfare.target greater_than $player_{TARGET_SIDE}.warfare.target}
            [have_unit]
                side={TARGET_SIDE}
                canrecruit=yes
            [/have_unit]
        [/show_if]
        [command]
            {VARIABLE_OP player_{TARGET_SIDE}.warfare.progress add 1}
            {VARIABLE finished_options yes}
            {VARIABLE finished_suboptions yes}
            {VARIABLE unit.status.worked_this_turn yes}
            {VARIABLE unit.moves 0}
            {REDRAW}
            [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="@" + _ "$player_name
Share knowledge of agriculture"
                        # wmllint: markcheck on
                    [/set_variable]
                    [set_variable]
                        name=diplo_msg[$side_i].mining
                        # wmllint: markcheck off
                        value="@" + _ "$player_name
Share knowledge of mining"
                        # wmllint: markcheck on
                    [/set_variable]
                    [set_variable]
                        name=diplo_msg[$side_i].warfare
                        # wmllint: markcheck off
                        value="@" + _ "$player_name
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]
            {VARIABLE_OP side format $unit.side}
            {VARIABLE finished_options no}
            [while]
                {CONDITION finished_options equals no}
                [do]
                    [message]
                        caption=_ "Diplomatic Options"
                        speaker=unit
                        #wmllint: display on
                        message= _ "What shall I do?"
                        #wmllint: display off

                        # Nothing

                        [option]
                            message= _ "Nothing"
                            [command]
                                {VARIABLE finished_options yes}
                            [/command]
                        [/option]

                        # Giving Money

                        [option]
                            message= {MENU_IMG_TXT "items/gold-coins-small.png" ("@"+_"Donate Funds
Give 20 gold to another player")}
                            [command]
                                {VARIABLE finished_suboptions no}
                                [while]
                                    {CONDITION finished_suboptions equals no}
                                    [do]
                                        [message]
                                            caption=_ "Diplomatic Options"
                                            speaker=unit
                                            image=items/gold-coins-small.png
                                            message= _ "Who will you donate funds to?"

                                            [option]
                                                message= _ "Back"
                                                [command]
                                                    {VARIABLE finished_suboptions yes}
                                                [/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" ("@"+_"Share Knowledge
Help an ally with their research")}
                            [command]
                                {VARIABLE finished_suboptions no}
                                [while]
                                    {CONDITION finished_suboptions equals no}
                                    [do]
                                        [message]
                                            caption=_ "Diplomatic Options"
                                            speaker=unit
                                            image=items/book4.png
                                            message= _ "Who will you share knowledge with?"

                                            [option]
                                                message= _ "Back"
                                                [command]
                                                    {VARIABLE finished_suboptions yes}
                                                [/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)" ("@"+_"Negotiate with the Dwarves
Lets you recruit a Dwarvish unit
Negotiation Progress: $player_$side_number|.leader_option_1.progress|/$player_$side_number|.leader_option_1.target")}
                            [show_if]
                                {CONDITION player_$side_number|.ally_1 equals no}
                                [or]
                                    {CONDITION player_$side_number|.ally_2 equals no}
                                [/or]
                                [or]
                                    {CONDITION player_$side_number|.ally_3 equals no}
                                [/or]
                                [or]
                                    {CONDITION player_$side_number|.ally_4 equals no}
                                [/or]
                            [/show_if]
                            [command]
                                {VARIABLE finished_options yes}
                                {VARIABLE unit.status.worked_this_turn yes}
                                {VARIABLE unit.moves 0}
                                {VARIABLE_OP player_$side_number|.leader_option_1.progress add 1}
                            [/command]
                        [/option]

                        # Elves

                        [option]
                            message= {MENU_IMG_TXT "units/elves-wood/marshal.png~TC(1,magenta)" ("@"+_"Negotiate with the Elves
Lets you recruit an Elvish unit
Negotiation Progress: $player_$side_number|.leader_option_2.progress|/$player_$side_number|.leader_option_2.target")}
                            [show_if]
                                {CONDITION player_$side_number|.ally_5 equals no}
                                [or]
                                    {CONDITION player_$side_number|.ally_6 equals no}
                                [/or]
                                [or]
                                    {CONDITION player_$side_number|.ally_7 equals no}
                                [/or]
                                [or]
                                    {CONDITION player_$side_number|.ally_8 equals no}
                                [/or]
                            [/show_if]
                            [command]
                                {VARIABLE finished_options yes}
                                {VARIABLE unit.status.worked_this_turn yes}
                                {VARIABLE unit.moves 0}
                                {VARIABLE_OP player_$side_number|.leader_option_2.progress add 1}
                            [/command]
                        [/option]
                    [/message]
                [/do]
            [/while]

            # Picking a Diplomactic recruit

            # Dwarves

            [if]
                {CONDITION player_$side_number|.leader_option_1.progress greater_than_equal_to $player_$side_number|.leader_option_1.target}
                [then]
                    [message]
                        speaker=narrator
                        caption=_ "Negotiation Complete"
                        image="portraits/dwarves/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]
                    {VARIABLE_OP player_$side_number|.leader_option_1.progress format 0}
                [/then]
            [/if]

            # Elves

            [if]
                {CONDITION player_$side_number|.leader_option_2.progress greater_than_equal_to $player_$side_number|.leader_option_2.target}
                [then]
                    [message]
                        speaker=narrator
                        caption=_ "Negotiation Complete"
                        image="portraits/elves/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" _"Elvish Shaman" ally_8}
#textdomain wesnoth-anl
                    [/message]
                    {VARIABLE_OP player_$side_number|.leader_option_2.progress format 0}
                [/then]
            [/if]

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