#textdomain wesnoth-did
[scenario]
    id=Forever_and_Ever_Amen
    next_scenario=Forever_and_Ever_Amen

    name=_ "Forever and Ever, Amen"
    map_data="{campaigns/Descent_Into_Darkness/maps/Forever_and_ever_amen.map}"
    turns=-1

    victory_when_enemies_defeated=yes

    {STORY_FOREVER_AND_EVER_AMEN}

    {UNDERGROUND}

    [side]
        side=1
        controller=human
        type=Lich
        description=Mal Keshar
        user_description=_ "Malin Keshar"
        unrenamable=yes
        canrecruit=yes
        recruit=Walking Corpse,Vampire Bat,Ghost,Ghoul,Skeleton Archer,Skeleton,Dark Adept
        gold=200
        save_id=Malin Keshar
        profile=portraits/malinlich.png
    [/side]

    {STARTING_VILLAGES 1 6}

    [side]
        # Foolish Hero
        side=2
        controller=ai
        # place leader, grant gold and recruits later
        no_leader=yes
        gold=0
        recruit=
        [ai]
            villages_per_scout=10
            village_value=0.5
        [/ai]
        fog=no
        shroud=no
        #After I have greatly reduced the number of villages in this scenario
        #it might be a good idea to give our foolish hero some income
        {INCOME 5 7 9}
    [/side]

    [event]
        name=prestart

        # {SCATTER_IMAGE (terrain=Uu) 3 scenery/rubble.png}

        [objectives]
            side=1
            [objective]
                condition=win
                description=_ "Defeat the foolish hero"
            [/objective]
            [objective]
                condition=lose
                description=_ "Destruction of Mal Keshar"
            [/objective]
        [/objectives]
        
        [if]
            [variable]
                name=timesForever
                greater_than=0
            [/variable]
            
            [then]
                # after the first repetition, we'll let the campaign really end
                # when Malin dies
                [event]
                    name=die

                    [filter]
                        description="Mal Keshar"
                    [/filter]
                    
                    [role]
                        side=2
                        [not]
                            canrecruit=yes
                        [/not]
                        role=second
                    [/role]
                    [music]
                        name=elvish-theme.ogg
                        immediate=yes
                        append=no
                    [/music]
                    {DIALOGUE_FAEA_END}
                    [endlevel]
                        result=continue_no_save
                        next_scenario=null
                    [/endlevel]
                [/event]
                
                {VARIABLE previous_randomHero $randomHero}
            [/then]
            
            [else]
                # Normal defeat condition on the first repeat
                {MAL_DEATH}
                
                {VARIABLE previous_randomHero -1}
            [/else]
        [/if]
        
        # let's pick a random hero type...
        {VARIABLE_OP randomHero random (0..4)}
        
        # and make sure it's not the same as last time
        [while]
            [variable]
                name=randomHero
                equals=$previous_randomHero
            [/variable]
            
            [do]
                {VARIABLE_OP randomHero random (0..4)}
            [/do]
        [/while]
        
        [if]
            [variable]
                name=randomHero
                numerical_equals=0
            [/variable]
            [then]
                [unit]
                    side=2
                    type=Royal Guard
                    description=Foolish Hero
                    user_description=_ "Foolish Hero"
                    x,y=20,3
                    canrecruit=yes
                [/unit]
                {ALLOW_RECRUIT (Spearman,Swordsman,Pikeman,Bowman,Longbowman,Heavy Infantryman,Shock Trooper,Mage,Red Mage,White Mage,Horseman,Knight,Lancer)}

                [music]
                    name=loyalists.ogg
                    immediate=yes
                    append=no
                [/music]
                [music]
                    name=the_city_falls.ogg
                    append=yes
                [/music]
            [/then]
        [/if]
        [if]
            [variable]
                name=randomHero
                numerical_equals=1
            [/variable]
            [then]
                [unit]
                    side=2
                    type=Assassin
                    description=Foolish Hero
                    user_description=_ "Foolish Hero"
                    x,y=20,3
                    canrecruit=yes
                [/unit]
                {ALLOW_RECRUIT (Thug,Bandit,Footpad,Outlaw,Poacher,Trapper,Thief,Rogue)}

                [music]
                    name=battle.ogg
                    append=no
                [/music]
            [/then]
        [/if]
        [if]
            [variable]
                name=randomHero
                numerical_equals=2
            [/variable]
            [then]
                [unit]
                    side=2
                    type=Elvish Marshal
                    description=Foolish Hero
                    user_description=_ "Foolish Hero"
                    x,y=20,3
                    canrecruit=yes
                [/unit]
                {ALLOW_RECRUIT (Elvish Fighter,Elvish Hero,Elvish Captain,Elvish Archer,Elvish Ranger,Elvish Marksman,Elvish Shaman,Elvish Sorceress,Elvish Druid,Elvish Scout,Elvish Rider,Wose)}

                [music]
                    name=knolls.ogg
                    immediate=yes
                    append=no
                [/music]
                [music]
                    name=the_city_falls.ogg
                    append=yes
                [/music]
            [/then]
        [/if]
        [if]
            [variable]
                name=randomHero
                numerical_equals=3
            [/variable]
            [then]
                [unit]
                    side=2
                    type=Dwarvish Lord
                    description=Foolish Hero
                    user_description=_ "Foolish Hero"
                    x,y=20,3
                    canrecruit=yes
                [/unit]
                {ALLOW_RECRUIT (Dwarvish Fighter,Dwarvish Steelclad,Dwarvish Thunderer,Dwarvish Thunderguard,Dwarvish Stalwart,Dwarvish Guardsman,Dwarvish Ulfserker,Dwarvish Berserker,Gryphon Rider,Gryphon Master)}

                [music]
                    name=battle.ogg
                    immediate=yes
                    append=no
                [/music]
                [music]
                    name=underground.ogg
                    append=yes
                [/music]
            [/then]
        [/if]
        [if]
            [variable]
                name=randomHero
                numerical_equals=4
            [/variable]
            [then]
                [unit]
                    side=2
                    type=Orcish Warlord
                    description=Foolish Hero
                    user_description=_ "Foolish Hero"
                    x,y=20,3
                    canrecruit=yes
                [/unit]
                {ALLOW_RECRUIT (Orcish Warrior,Orcish Slayer,Orcish Crossbowman,Troll,Troll Rocklobber)}

                [music]
                    name=northerners.ogg
                    immediate=yes
                    append=no
                [/music]
                [music]
                    name=battle.ogg
                    append=yes
                [/music]
            [/then]
        [/if]

        # Give the foolish hero gold = 100*timesForever + 100
        {VARIABLE_OP heroGold format $timesForever}
        {VARIABLE_OP heroGold multiply 100}
        {VARIABLE_OP heroGold add 100}
        [gold]
            side=2
            amount=$heroGold
        [/gold]
        {CLEAR_VARIABLE heroGold}

        # play only sad music after a few repetitions
        [if]
            [variable]
                name=timesForever
                greater_than=4
            [/variable]
            [then]
                [music]
                    name=the_king_is_dead.ogg
                    immediate=yes
                    append=no
                [/music]
                [music]
                    name=elvish-theme.ogg
                    append=yes
                [/music]
                [music]
                    name=nunc_dimittis.ogg
                    append=yes
                [/music]
            [/then]
        [/if]
    [/event]

    [event]
        name=start
        [if]
            [variable]
                name=randomHero
                numerical_equals=0
            [/variable]
            [then]
                {DIALOGUE_FAEA_START0}
            [/then]
        [/if]
        [if]
            [variable]
                name=randomHero
                numerical_equals=1
            [/variable]
            [then]
                {DIALOGUE_FAEA_START1}
            [/then]
        [/if]
        [if]
            [variable]
                name=randomHero
                numerical_equals=2
            [/variable]
            [then]
                {DIALOGUE_FAEA_START2}
            [/then]
        [/if]
        [if]
            [variable]
                name=randomHero
                numerical_equals=3
            [/variable]
            [then]
                {DIALOGUE_FAEA_START3}
            [/then]
        [/if]
        [if]
            [variable]
                name=randomHero
                numerical_equals=4
            [/variable]
            [then]
                {DIALOGUE_FAEA_START4}
            [/then]
        [/if]

        # Some more harassment once the scanario's been played a few times
        [if]
            [variable]
                name=timesForever
                numerical_equals=7
            [/variable]
            [then]
                {DIALOGUE_FAEA_SASS1}
            [/then]
        [/if]
    [/event]

    # In-scenario events defined within the prestart event

    [event]
        name=victory
        {VARIABLE_OP timesForever add 1}
    [/event]

    {@campaigns/Descent_Into_Darkness/utils/global-events.cfg}
[/scenario]
