#textdomain wesnoth-anl

#define TARGET_RESEARCH_COMMAND TARGET_ID TARGET_NAME
    [set_variable]
        name=player_$side_number|.research.current_target
        value={TARGET_ID}
    [/set_variable]
    [set_variable]
        name=player_$side_number|.research.target_language_name
        value={TARGET_NAME}
    [/set_variable]

    [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]
#enddef

#define RESEARCH_OPTIONS TYPES

    # Picking new recruit

    [set_menu_item]
        id=anl_choose_new_recruit
        description=_ "Choose New Recruit"
        [show_if]
            [variable]
                name=player_$side_number|.warfare.troop_available
                greater_than_equal_to=1
            [/variable]

            [have_unit]
                side=$side_number
                x,y=$x1,$y1
                type={TYPES}
                canrecruit=no
                [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]
# wmlindent: start ignoring
    [command]
        [message]
        speaker=unit
        caption=_ "Study Complete"
# wmllint: display on
        message= _ "Which type of unit would you like to be able to recruit?"
# wmllint: display off
#textdomain wesnoth-units
            {PICK_RECRUIT_OPTION ("units/human-loyalists/spearman.png~TC($side_number|,magenta)") "Spearman" _"Spearman" troop_1}
            {PICK_RECRUIT_OPTION ("units/human-loyalists/bowman.png~TC($side_number|,magenta)") "Bowman" _"Bowman" troop_2}
            {PICK_RECRUIT_OPTION ("units/human-loyalists/fencer.png~TC($side_number|,magenta)") "Fencer" _"Fencer" troop_3}
            {PICK_RECRUIT_OPTION ("units/human-loyalists/heavyinfantry.png~TC($side_number|,magenta)") "Heavy Infantryman" _"Heavy Infantryman" troop_4}
            {PICK_RECRUIT_OPTION ("units/human-loyalists/sergeant.png~TC($side_number|,magenta)") "Sergeant" _"Sergeant" troop_5}
            {PICK_RECRUIT_OPTION ("units/human-loyalists/cavalryman/cavalryman.png~TC($side_number|,magenta)") "Cavalryman" _"Cavalryman" troop_6}
            {PICK_RECRUIT_OPTION ("units/human-loyalists/horseman/horseman.png~TC($side_number|,magenta)") "Horseman" _"Horseman" troop_7}
#textdomain wesnoth-anl
        [/message]

        [set_variable]
            name=player_$side_number|.warfare.troop_available
            sub=1
        [/set_variable]
    [/command]
# wmlindent: stop ignoring
    [/set_menu_item]

    # Changing Research Target

    [set_menu_item]
        id=anl_oversee_research
        description=_ "Oversee Research"
        [show_if]
            [have_unit]
                side=$side_number
                x,y=$x1,$y1
                type={TYPES}
                canrecruit=no
                [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_unit]
                [filter]
                    x=$x1
                    y=$y1
                [/filter]
                kill=no
                variable=unit
            [/store_unit]

            [set_variable]
                name=finished_options
                value=no
            [/set_variable]
            [set_variable]
                name=cancelled
                value=no
            [/set_variable]

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

                [do]
                    # wmlindent:  start ignoring
                    [message]
                        speaker=unit
                        caption=_ "Research"
                        # wmllint: display on
                        message= _ "We are currently studying $player_$side_number|.research.target_language_name|. To which end would you have our scholars devote their minds?

Our farms produce $player_$side_number|.farming.gold|g
Our mines produce $player_$side_number|.mining.gold|g
"
                        # wmllint: display off

                        [option]
                            message= _ "Continue as before"
                            [command]
                                [set_variable]
                                    name=finished_options
                                    value=yes
                                [/set_variable]

                                [set_variable]
                                    name=cancelled
                                    value=yes
                                [/set_variable]
                            [/command]
                        [/option]
                        # wmlindent: stop ignoring
                        # Farming

                        [option]
                            message= {MENU_IMG_TXT "items/flower4.png" ( _ "<span color='green'>Agriculture</span>
Farmers produce +1 gold
Study Progress: $player_$side_number|.farming.progress|/$player_$side_number|.farming.target")}
                            [command]
                                {TARGET_RESEARCH_COMMAND agriculture ( _ "agriculture")}
                            [/command]
                        [/option]

                        # Mining

                        [option]
                            message= {MENU_IMG_TXT "items/gold-coins-small.png" ( _ "<span color='green'>Mining</span>
Miners produce +1 gold
Study Progress: $player_$side_number|.mining.progress|/$player_$side_number|.mining.target")}
                            [command]
                                {TARGET_RESEARCH_COMMAND mining ( _ "mining")}
                            [/command]
                        [/option]

                        #Warfare

                        [option]
                            message= {MENU_IMG_TXT "wesnoth-icon.png" ( _ "<span color='green'>Warfare</span>
Allows you to recruit a new type of unit
Study Progress: $player_$side_number|.warfare.progress|/$player_$side_number|.warfare.target")}
                            [show_if]
                                [variable]
                                    name=player_$side_number|.troops
                                    less_than=7
                                [/variable]
                            [/show_if]

                            [command]
                                {TARGET_RESEARCH_COMMAND warfare ( _ "warfare")}
                            [/command]
                        [/option]
                    [/message]
                [/do]
            [/while]

            [if]
                [variable]
                    name=cancelled
                    not_equals=yes
                [/variable]

                [then]
                    [unstore_unit]
                        variable=unit
                        find_vacant=no
                    [/unstore_unit]
                [/then]

                [else]
                    #[allow_undo]
                    #[/allow_undo]
                [/else]
            [/if]
        [/command]
    [/set_menu_item]
#enddef

# Research Complete Messages
# (These are shown at the start of a player's turn - they are triggered by an event included in the auto-studying macro)

#define FARMING_RESEARCH_COMPLETE
    [if]
        [variable]
            name=player_$side_number|.farming.progress
            greater_than_equal_to=$player_$side_number|.farming.target
        [/variable]

        [then]
            [set_variable]
                name=player_$side_number|.farming.gold
                add=1
            [/set_variable]

            [message]
                speaker=narrator
                caption= _ "Study Complete"
                image=items/flower4.png
                message= _ "$player_$side_number|.name|’s farms now produce $player_$side_number|.farming.gold gold."
            [/message]

            [set_variable]
                name=player_$side_number|.farming.progress
                sub=$player_$side_number|.farming.target
            [/set_variable]
            [set_variable]
                name=player_$side_number|.farming.target
                add=1
            [/set_variable]
        [/then]
    [/if]
#enddef

#define MINING_RESEARCH_COMPLETE
    [if]
        [variable]
            name=player_$side_number|.mining.progress
            greater_than_equal_to=$player_$side_number|.mining.target
        [/variable]

        [then]
            [set_variable]
                name=player_$side_number|.mining.gold
                add=1
            [/set_variable]

            [message]
                speaker=narrator
                caption= _ "Study Complete"
                image=items/gold-coins-small.png
                message= _ "$player_$side_number|.name|’s mines now produce $player_$side_number|.mining.gold gold."
            [/message]

            [set_variable]
                name=player_$side_number|.mining.progress
                sub=$player_$side_number|.mining.target
            [/set_variable]
            [set_variable]
                name=player_$side_number|.mining.target
                add=1
            [/set_variable]
        [/then]
    [/if]
#enddef

#define WARFARE_RESEARCH_COMPLETE
    [if]
        [variable]
            name=player_$side_number|.warfare.progress
            greater_than_equal_to=$player_$side_number|.warfare.target
        [/variable]

        [then]
            [message]
                speaker=narrator
                caption= _ "Study Complete"
                image=wesnoth-icon.png
                message= _ "$player_$side_number|.name|, we have finished researching warfare. Right-click on a mage in a university to select a unit to recruit."
            [/message]

            [set_variable]
                name=player_$side_number|.warfare.troop_available
                add=1
            [/set_variable]
            [set_variable]
                name=player_$side_number|.warfare.progress
                sub=$player_$side_number|.warfare.target
            [/set_variable]
            [set_variable]
                name=player_$side_number|.warfare.target
                add=1
            [/set_variable]
        [/then]
    [/if]
#enddef
