#textdomain wesnoth-anl

#define RESEARCH_OPTIONS TYPES

    # Picking new recruit

    [set_menu_item]
        id=anl_choose_new_recruit
        description=_ "Choose New Recruit"
        [show_if]
            {CONDITION player_$side_number|.warfare.troop_available greater_than_equal_to 1}
            [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.png~TC($side_number|,magenta)") "Cavalryman" _"Cavalryman" troop_6}
            {PICK_RECRUIT_OPTION ("units/human-loyalists/horseman.png~TC($side_number|,magenta)") "Horseman" _"Horseman" troop_7}
#textdomain wesnoth-anl
        [/message]
        {VARIABLE_OP player_$side_number|.warfare.troop_available add -1}
    [/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]

            {VARIABLE finished_options no}
            {VARIABLE cancelled no}

            [while]
                {CONDITION finished_options equals no}
                [do]
                    # wmlindent:  start ignoring
                    [message]
                        speaker=unit
                        caption=_ "Research"
                        #wmllint: display on
                        message= _ "We are currently studying $player_$side_number|.research.current_target|. 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]
                                {VARIABLE finished_options yes}
                                {VARIABLE cancelled yes}
                            [/command]
                        [/option]
                        # wmlindent: stop ignoring
                        # Farming

                        # FIXME: After 1.8, pangoize so first line is green
                        [option]
                            message= {MENU_IMG_TXT "items/flower4.png" (_"Agriculture
Farmers produce +1 gold
Study Progress: $player_$side_number|.farming.progress|/$player_$side_number|.farming.target")}
                            [command]
                                {VARIABLE player_$side_number|.research.current_target _"agriculture"}
                                {VARIABLE finished_options yes}
                                {VARIABLE unit.status.worked_this_turn yes}
                                {VARIABLE unit.moves 0}
                            [/command]
                        [/option]

                        # Mining

                        # FIXME: After 1.8, pangoize so first line is green
                        [option]
                            message= {MENU_IMG_TXT "items/gold-coins-small.png" (_"Mining
Miners produce +1 gold
Study Progress: $player_$side_number|.mining.progress|/$player_$side_number|.mining.target")}
                            [command]
                                {VARIABLE player_$side_number|.research.current_target _"mining"}
                                {VARIABLE finished_options yes}
                                {VARIABLE unit.status.worked_this_turn yes}
                                {VARIABLE unit.moves 0}
                            [/command]
                        [/option]

                        #Warfare

                        # FIXME: After 1.8, pangoize so first line is green
                        [option]
                            message= {MENU_IMG_TXT "wesnoth-icon.png" (_"Warfare
Allows you to recruit a new type of unit
Study Progress: $player_$side_number|.warfare.progress|/$player_$side_number|.warfare.target")}
                            [show_if]
                                {CONDITION player_$side_number|.troop_1 equals no}
                                [or]
                                    {CONDITION player_$side_number|.troop_2 equals no}
                                [/or]
                                [or]
                                    {CONDITION player_$side_number|.troop_3 equals no}
                                [/or]
                                [or]
                                    {CONDITION player_$side_number|.troop_4 equals no}
                                [/or]
                                [or]
                                    {CONDITION player_$side_number|.troop_5 equals no}
                                [/or]
                                [or]
                                    {CONDITION player_$side_number|.troop_6 equals no}
                                [/or]
                                [or]
                                    {CONDITION player_$side_number|.troop_7 equals no}
                                [/or]
                            [/show_if]

                            [command]
                                {VARIABLE player_$side_number|.research.current_target _"warfare"}
                                {VARIABLE finished_options yes}
                                {VARIABLE unit.status.worked_this_turn yes}
                                {VARIABLE unit.moves 0}
                            [/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]
        {CONDITION player_$side_number|.farming.progress greater_than_equal_to $player_$side_number|.farming.target}
        [then]
            {VARIABLE_OP player_$side_number|.farming.gold add 1}
            [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]
            {VARIABLE_OP player_$side_number|.farming.progress add -$player_$side_number|.farming.target}
            {VARIABLE_OP player_$side_number|.farming.target add 1}
        [/then]
    [/if]
#enddef

#define MINING_RESEARCH_COMPLETE
    [if]
        {CONDITION player_$side_number|.mining.progress greater_than_equal_to $player_$side_number|.mining.target}
        [then]
            {VARIABLE_OP player_$side_number|.mining.gold add 1}
            [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]
            {VARIABLE_OP player_$side_number|.mining.progress add -$player_$side_number|.mining.target}
            {VARIABLE_OP player_$side_number|.mining.target add 1}
        [/then]
    [/if]
#enddef

#define WARFARE_RESEARCH_COMPLETE
    [if]
        {CONDITION player_$side_number|.warfare.progress greater_than_equal_to $player_$side_number|.warfare.target}
        [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]
            {VARIABLE_OP player_$side_number|.warfare.troop_available add 1}
            {VARIABLE_OP player_$side_number|.warfare.progress add -$player_$side_number|.warfare.target}
            {VARIABLE_OP player_$side_number|.warfare.target add 1}
        [/then]
    [/if]
#enddef
