#textdomain wesnoth-ei
[scenario]
    id=09_Castle_in_the_Ice
    name= _ "Castle in the Ice"
    map_file=09_Castle_in_the_Ice.map
    victory_when_enemies_defeated=no
    next_scenario=10_Dark_Sanctuary
    turns=unlimited

    #
    # -------WILDLANDS GOAL NOTES:
    # this is a long campaign, and I wanted to avoid it feeling tedious
    # so, the wildlands arc (placed at the campaign's middle) has a lot of unusual mechanics, to try and make these scenarios feel different from normal scenarios
    # S09 has "frostbite" and several events, S10 has a split army with many events, and S11 is heavily scripted.
    # the income changes hopefully put emphasis on gold rather than army, and being frugal rather than rushing for an early finish (there are no early finish bonuses)
    #

    #
    # -------WILDLANDS INCOME NOTES:
    # wildlands scenarios all have 100% carryover and 0 starting gold (except for S08 with some starting gold, and S12 with 40% carryover)
    # in S09, Dacyn warns you to conserve your gold, but even if you spend recklessly it's extremely difficult to make a subsequent scenario unwinnable:
    #     S08 (Xenophobia) requires you to end with at least 300 gold
    #     S09 (Castle In The Ice) needs few recruits and only has a single-tile castle. You'd have to try pretty hard to go broke.
    #             plus there are several gold pickups lying around
    #             this scenario has no time limit (i.e. no early finish bonus), but few villages and continual cold damage, to hopefully prevent abuse
    #     S10 (Dark Sanctuary) is a bit of a gold-eater, but even if you spend everything now, S12 is still winnable with 0 gold
    #             there's also gold just inside the gate (wyvern), ensuring that even if you spend everything immediately, you still have enough gold to resist the orcs
    #             this scenario has no time limit (i.e. no early finish bonus), but few villages and increasing enemy spawns, to hopefully prevent abuse
    #     S11 (Captured) has no need for recruiting
    #             this scenario has no time limit so you can farm infinite xp, but without any gold you won't be able to bring leveled recalls through S12
    #             so it's in the player's best interest to rush the exit as quickly as possible
    #     S12 (Evacuation) is beatable without any recruiting - just run straight for the bridge
    #             but S08-S11 gold conservation pays off here, letting you recruit a large army and potentially save all your leveled recalls
    #

    {WINTER_SCHEDULE}

    {SCENARIO_MUSIC       suspense.ogg}
    {EXTRA_SCENARIO_MUSIC nunc_dimittis.ogg}

    [story]
        [part]
            story=_ "As Gweddry and his band continued north, winter tightened its grip on the wildlands. The days began to shorten and the air swiftly grew chill, making the already challenging mountains even more perilous to traverse."
            music=silence.ogg
        [/part]
    [/story]
    {EI_TRACK {JOURNEY_09_NEW} }

    #---------------------
    # GWEDDRY
    #---------------------
    [side]
        side=1
        canrecruit=yes
        controller=human
        team_name=good
        user_team_name=_"Wesnothians"
        shroud=yes
        fog=yes
        gold=0 # see notes in S09_Castle_In_The_Ice
        {FLAG_VARIANT loyalist}
        # wmllint: recognize Gweddry
        {CHARACTER_STATS_GWEDDRY}
    [/side]
    {STARTING_VILLAGES 1 5}

    #---------------------
    # DRAKES
    #---------------------
    [side]
        color=orange
        side=2
        type=Hurricane Drake
        id=Kaslar Ro
        name= _ "Kaslar Ro"
        canrecruit=yes
        facing=se
        [modifications]
            {TRAIT_INTELLIGENT}
            {TRAIT_STRONG}
        [/modifications]
        recruit=Drake Fighter,Drake Burner,Drake Glider
        team_name=monsters
        user_team_name=_"Drakes"
        gold=0
        income=-2
        [ai]
            grouping=defensive
            [avoid]
                x= 0-19, 0-99,   34-99,39-99,42-99 # avoid fighting the icemonax
                y=17-99,22-99,     0-8, 0-10, 0-14
            [/avoid]
            leader_value=0
        [/ai]
    [/side]
    {SILENTLY_LIMIT_MOVES 2 (id=Kaslar Ro) 2} # specify Kaslar Ro because Mortic is also a leader
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Drake Burner"  2} # mostly gliders, for lore reasons
    {LIMIT_CONTEMPORANEOUS_RECRUITS 2 "Drake Fighter" 2}

    [side]
        color=orange
        side=3
        type=Sky Drake
        id=Kegra
        name= _ "Kegra"
        canrecruit=yes
        facing=sw
        [modifications]
            {TRAIT_RESILIENT}
            {TRAIT_STRONG}
        [/modifications]
        recruit=Drake Fighter,Drake Burner,Drake Glider
        team_name=monsters
        user_team_name=_"Drakes"
        gold=0
        income=-2
        [ai]
            grouping=defensive
            [avoid]
                x= 0-19, 0-99,   34-99,39-99,42-99 # avoid fighting the icemonax
                y=17-99,22-99,    0-8, 0-10, 0-14
            [/avoid]
            leader_value=0
        [/ai]
    [/side]
    {SILENTLY_LIMIT_LEADER_MOVES 3 2}
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 "Drake Burner"  2} # mostly gliders, for lore reasons
    {LIMIT_CONTEMPORANEOUS_RECRUITS 3 "Drake Fighter" 2}

    # drakes have no gold until they're first spotted...
    [event]
        name=prestart
        {VARIABLE drakes_no_income yes}
    [/event]
    [event]
        name=side 2 turn refresh, side 3 turn refresh
        first_time_only=no

        [filter_condition]
            {VARIABLE_CONDITIONAL drakes_no_income equals yes}
        [/filter_condition]

        [modify_side]
            side=2,3
            gold=0
        [/modify_side]
    [/event]

    # ...but income increases over time, so you're not punished as much for sending scouts north and "activating" the drakes early
#define SET_INCOME TURN_NUMBER AMOUNT2 AMOUNT3
    [event]
        name=turn {TURN_NUMBER}
        [modify_side]
            side=2
            income={AMOUNT2}
        [/modify_side]
        [modify_side]
            side=3
            income={AMOUNT3}
        [/modify_side]
    [/event]
#enddef
    {SET_INCOME  1  {ON_DIFFICULTY -1 -1 -1}  {ON_DIFFICULTY -1 -1 -1} }
    {SET_INCOME 10  {ON_DIFFICULTY  0  3  6}  {ON_DIFFICULTY -1  2  4} }
    {SET_INCOME 20  {ON_DIFFICULTY  0  4  8}  {ON_DIFFICULTY  0  3  6} }
    {SET_INCOME 30  {ON_DIFFICULTY  1  6 11}  {ON_DIFFICULTY  0  4  8} }
    {SET_INCOME 40  {ON_DIFFICULTY  1  7 13}  {ON_DIFFICULTY  1  6 11} }
    {SET_INCOME 50  {ON_DIFFICULTY  2  9 15}  {ON_DIFFICULTY  1  7 13} }

    #---------------------
    # MONSTERS
    #---------------------
    [side]
        no_leader=yes
        hidden=yes
        side=4
        team_name=monsters
        user_team_name=_"Beasts"
        [ai]
            aggression=0.9
            grouping=no
            leader_value=0
            [goal]
                [criteria]
                    side=1
                [/criteria]
                value=5
            [/goal]
            [avoid]
                [filter]
                    side=2,3
                [/filter]
                radius=3
            [/avoid]
        [/ai]
    [/side]
    [event]
        name=prestart
        {GENERIC_UNIT 4 (Yeti) 53 33}
        [+unit]
            max_moves=3
        [/unit]

        [micro_ai]
            side=4
            ai_type=zone_guardian
            action=add
            [filter]
                type=Yeti
            [/filter]
            [filter_location]
                x,y=53,33
                radius=0
            [/filter_location]
            [filter_location_enemy]
                x,y=53,33
                radius=4
            [/filter_location_enemy]
        [/micro_ai]

#ifndef EASY
        {GENERIC_UNIT 4 (Icemonax) 42 4}
        {GENERIC_UNIT 4 (Icemonax) 42 4}
        {GENERIC_UNIT 4 (Icemonax) 42 4}
#endif
#ifdef HARD
        {GENERIC_UNIT 4 (Great Icemonax) 42 4}
#endif
        [micro_ai]
            side=4
            ai_type=zone_guardian
            action=add
            [filter]
                type=Icemonax,Great Icemonax
            [/filter]
            [filter_location]
                x,y=42,4
                radius=3
            [/filter_location]
            [filter_location_enemy]
                x,y=42,4
                radius=8
            [/filter_location_enemy]
        [/micro_ai]

        {NAMED_UNIT 4 (Ghost) 29 31 "Pudror" (_"Pudror") ()} # these are the ghosts of rival orcs
        {NAMED_UNIT 4 (Wraith) 29 31 "Chief Bir-brish" (_"Chief Bir-brish") ()}
#ifndef EASY
        {NAMED_UNIT 4 (Ghost) 29 31 "Huno" (_"Huno") ()}
#endif
#ifdef HARD
        {NAMED_UNIT 4 (Ghost) 29 31 "Iprish" (_"Iprish") ()}
#endif
        [micro_ai]
            side=4
            ai_type=zone_guardian
            action=add
            [filter]
                type=Ghost,Wraith,Shadow
            [/filter]
            [filter_location]
                x,y=31,32
                radius=3
            [/filter_location]
            [filter_location_enemy]
                x,y=31,32
                radius=5
            [/filter_location_enemy]
        [/micro_ai]

        {GENERIC_UNIT 4 (Frost Stoat) 9 22}
#ifndef EASY
        {GENERIC_UNIT 4 (Frost Stoat) 9 22}
#endif
#ifdef HARD
        {GENERIC_UNIT 4 (Frost Stoat) 9 22}
#endif
        [micro_ai]
            side=4
            ai_type=zone_guardian
            action=add
            [filter]
                type=Frost Stoat
            [/filter]
            [filter_location]
                x,y=9,22
                radius=3
            [/filter_location]
            [filter_location_enemy]
                x,y=5,17
                radius=9
            [/filter_location_enemy]
        [/micro_ai]
    [/event]

    #---------------------
    # OGRES
    #---------------------
    [side]
        no_leader=yes
        side=5
        hidden=yes
        team_name=monsters
        user_team_name=_"Ogres"
        shroud=yes # so that shared vision works properly for them
        fog=yes
        [ai]
            aggression=0.9
            grouping=no
        [/ai]
        {GENERIC_UNIT 5 (Ogre) 42 30}
        {GENERIC_UNIT 5 (Young Ogre) 42 30}
        {GENERIC_UNIT 5 (Young Ogre) 42 30}
    [/side]
    [event]
        name=prestart
        [micro_ai]
            side=5
            ai_type=zone_guardian
            action=add
            ca_id=ogre_ai
            [filter]
                type=Young Ogre,Ogre,Great Ogre
            [/filter]
            [filter_location]
                x,y=42,30
                radius=3
            [/filter_location]
            [filter_location_enemy]
                x,y=42,30
                radius=6
            [/filter_location_enemy]
        [/micro_ai]
    [/event]

#define RECALL_IF_EMPTY FLT X Y
    [if]
        [not]
            [have_unit]
                x,y={X},{Y}
            [/have_unit]
        [/not]

        [then]
            [recall]
                side=1
                x,y={X},{Y}
                {FLT}
            [/recall]
        [/then]
    [/if]
#enddef
#define SPAWN_IF_EMPTY TYPE X Y
    [if]
        [not]
            [have_unit]
                x,y={X},{Y}
            [/have_unit]
        [/not]

        [then]
            {GENERIC_UNIT 1 ({TYPE}) {X} {Y}}
        [/then]
    [/if]
#enddef
    [event]
        name=prestart

        {PLACE_IMAGE scenery/village-human-burned1.png 21 26}

        {PLACE_IMAGE scenery/village-human-burned1.png 23 31}
        {PLACE_IMAGE scenery/village-human-burned2.png 26 28}
        {PLACE_IMAGE scenery/village-human-burned3.png 25 33}
        {PLACE_IMAGE scenery/village-human-burned4.png 30 29}
        {PLACE_IMAGE items/bones.png 24 30}
        {PLACE_IMAGE "items/bones.png~FL(horiz)" 31 29}

        {PLACE_IMAGE scenery/castle-ruins.png 28 28}
        {PLACE_IMAGE scenery/castle-ruins2.png 26 32}

        {PLACE_IMAGE scenery/castle-ruins3.png 27 30}
        {PLACE_IMAGE "scenery/temple-cracked2.png~FL(horiz)" 28 31}
        {PLACE_IMAGE items/orcish-flag.png 27 31}
        # I imagine this area to be a rival orcish clan's village, which the whitefangs destroyed (and I guess they came back as ghosts?)

        {PLACE_IMAGE items/bones.png 52 33}
        {PLACE_IMAGE "items/bones.png~FL(horiz)" 52 32}
        {PLACE_IMAGE items/bones.png 54 33}
        {PLACE_IMAGE "items/bones.png~FL(horiz)" 53 33}
        {PLACE_IMAGE items/burial.png 53 33}

        {RECALL_XY Dacyn 5 31}
        {RECALL_XY Owaec 3 31}

        # originally all these RECALL_IF_EMPTYs were because I didn't give Gweddry a keep to recruit from,
        # leaving them here in case I change my mind later
        {RECALL_XY Addogin 2 32}
        {RECALL_XY Terraent 2 32}
        #         {RECALL_IF_EMPTY (type=Paladin,Grand Knight,Cavalier) 2 32}
        #         {RECALL_IF_EMPTY (type=Knight,Lancer,Dragoon) 2 32}
        #         {RECALL_IF_EMPTY (type=Horseman,Cavalryman) 2 32}
        #         {SPAWN_IF_EMPTY (Horseman) 2 32}

        {RECALL_XY (Hahid al-Ali) 7 32} # using these coordinates to position an elixir
        #         {RECALL_IF_EMPTY (type=Mage of Light) 7 32}
        #         {RECALL_IF_EMPTY (type=White Mage) 7 32}
        #         {RECALL_IF_EMPTY (type=Great Mage) 7 32}
        #         {RECALL_IF_EMPTY (type=Arch Mage,Silver Mage) 7 32}
        #         {RECALL_IF_EMPTY (type=Red Mage) 7 32}
        #         {RECALL_IF_EMPTY (type=Mage) 7 32}
        #         {SPAWN_IF_EMPTY (Mage) 7 32}

        {RECALL_XY Dolburras 5 30}
        #         {RECALL_IF_EMPTY (type=Iron Mauler,Halberdier,Royal Guard,Master at Arms,Master Bowman) 5 30}
        #         {RECALL_IF_EMPTY (type=Shock Trooper,Pikeman,Swordsman,Javelineer,Duelist,Longbowman) 5 30}
        #         {RECALL_IF_EMPTY (type=Heavy Infantryman,Spearman,Fencer,Bowman) 5 30}
        #         {SPAWN_IF_EMPTY (Heavy Infantryman) 5 30}

        {RECALL_XY Grug 4 32}
        #         {RECALL_IF_EMPTY (type=Great Ogre) 4 32}
        #         {RECALL_IF_EMPTY (type=Ogre) 4 32}
        #         {RECALL_IF_EMPTY (type=Young Ogre) 4 32}
        #         {RECALL_IF_EMPTY (type=Iron Mauler,Halberdier,Royal Guard,Master at Arms,Master Bowman) 4 32}
        #         {RECALL_IF_EMPTY (type=Shock Trooper,Pikeman,Swordsman,Javelineer,Duelist,Longbowman) 4 32}
        #         {RECALL_IF_EMPTY (type=Heavy Infantryman,Spearman,Fencer,Bowman) 4 32}
        #         {SPAWN_IF_EMPTY (Spearman) 4 32}

        [objectives]
            side=1
            [objective]
                description= _ "Move any unit to the abandoned castle."
                condition=win
            [/objective]
            [objective]
                {BONUS_OBJECTIVE_CAPTION}
                description= _ "Move Grug next to an enemy ogre."
                condition=win
                [show_if]
                    [variable]
                        name=grug_event_active
                        equals=yes
                    [/variable]
                [/show_if]
            [/objective]
            [objective]
                description= _ "Death of Gweddry, Dacyn, or Owaec"
                condition=lose
            [/objective]
            [gold_carryover]
                bonus=no
                carryover_percentage=100
            [/gold_carryover]
            [note]
                description= _ "It is winter, daytime is shorter"
            [/note]
            [note]
                #po: The amount is likely between 2 and 10 per turn.
                #po: With the current balancing it’s the same for every difficulty, starting at 2/turn and rising by 1 every 10 turns.
                description= _ "Living units take $|frostbite_amount cold damage every turn. Damage increases every 10 turns."
                [show_if]
                    [variable]
                        name=frostbite_amount
                        greater_than=0
                    [/variable]
                [/show_if]
            [/note]
        [/objectives]
    [/event]

    [event]
        name=start
        [message]
            speaker=Owaec
            message= _ "This winter cold chills my very bones! I long for the rolling plains of my homeland. I wonder how the horse lords fare against the grim undead; surely Wesnoth is near victory?"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Doubtful, but <i>our</i> victory is close. Across this river lies the abandoned sanctuary, and within lies an artifact that can destroy Mal-Ravanal once and for all. That is the object of our quest."
        [/message]
        [message]
            speaker=Dacyn
            message= _ "This area was deserted whence last I came, but I have heard rumors that a flight of drakes has taken up residence."
        [/message]
        [if]
            [have_unit]
                id=Terraent
            [/have_unit]

            [then]
                [message]
                    speaker=Terraent
                    message= _ "And listen! I hear the bone-chilling howls of wolves echoing among the peaks."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Gweddry
                    message= _ "And listen! I hear the bone-chilling howls of wolves echoing among the peaks."
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Owaec
            message= _ "Wolves and drakes, bah! I fear no mindless beasts!"
        [/message]
        [message]
            speaker=Dacyn
            message= _ "Unlike yourself, drakes are very much intelligent. Their inner flame guards against our mages’ fire and their flight will serve them better than our feet amidst these snow-covered mountains."
        [/message]
        [if]
            [have_unit]
                id=Dolburras
            [/have_unit]

            [then]
                [message]
                    speaker=Dolburras
                    #po: "Yes, and don't understimate wild beasts! I've known wolves to take a dwarf's arm clean off."
                    message= _ "Aye, and dinnae underestimate wild beasts! I’ve known wolves ta take a dwarf’s arm clean off."
                [/message]
                [message]
                    speaker=Gweddry
                    message= _ "Still, we must press onwards to the icy castle."
                [/message]
            [/then]

            [else]
                [message]
                    speaker=Gweddry
                    message= _ "And wild beasts are not to be underestimated either! Still, we must press onwards to the icy castle."
                [/message]
            [/else]
        [/if]

        # show a path leading to the objective
        {SCROLL_TO 15 26}
        [remove_shroud]
            side=1
            x,y=18,26
            radius=1
        [/remove_shroud]
        [delay]
            time=750
        [/delay]

        {SCROLL_TO 20 21}
        [remove_shroud]
            side=1
            x,y=20,21
            radius=1
        [/remove_shroud]
        [delay]
            time=750
        [/delay]

        {SCROLL_TO 21 17}
        [remove_shroud]
            side=1
            x,y=21,17
            radius=1
        [/remove_shroud]
        [delay]
            time=750
        [/delay]

        {SCROLL_TO 26 12}
        [remove_shroud]
            side=1
            x,y=26,12
            radius=1
        [/remove_shroud]
        [delay]
            time=750
        [/delay]

        {SCROLL_TO 33 12}
        [remove_shroud]
            side=1
            x,y=33,12
            radius=1
        [/remove_shroud]
        [delay]
            time=750
        [/delay]

        {SCROLL_TO 42 4}
        [remove_shroud]
            side=1
            x,y=42,4
            radius=4
        [/remove_shroud]
        {HIGHLIGHT_IMAGE 42 4 items/gohere.png ()}

        # reveal a few things so the player has some idea of where to explore
        [remove_shroud]
            side=1
            x,y=53,33
            radius=1 # yeti
        [/remove_shroud]
        [remove_shroud]
            side=1
            radius=1
            x=39,44,  6 # villages
            y=29,28, 21
        [/remove_shroud]
        [remove_shroud]
            side=1
            x,y=27,32
            radius=1 # ruined orcish village
        [/remove_shroud]
        [remove_shroud]
            side=1
            x,y=9,16
            radius=1 # shipwreck
        [/remove_shroud]

        # hahid tries to sell an elixir
        [message]
            speaker=Hahid al-Ali
            message= _ "Fire and ice, eh? I have just the thing — behold the wondrous elixir of elements! Whoever drinks from this bubbling yellow vial will gain immunity to even the hottest flame!"
        [/message]
        [message]
            speaker=Hahid al-Ali
            message= _ "But wait, there’s more! The elixir of elements also bestows immunity to cold; perfect for enduring the frigid winter weather."
        [/message]
        [event]
            name=buy_elixir
            [gold]
                side=1
                amount=-10
            [/gold]
            [sound]
                name=gold.ogg
            [/sound]
            [message]
                speaker=Hahid al-Ali
                message= _ "Pleasure doing business with you!"
            [/message]
            {ELIXIR_OF_ELEMENTS 6 31}
        [/event]
        [event]
            name=ignore_elixir
            [message]
                speaker=Hahid al-Ali
                message= _ "Suit yourself; more for me!"
            [/message]
            {GIVE_ELEMENTS 7 32 ()}
        [/event]
        [message]
            speaker=Hahid al-Ali
            message= _ "Act fast, this offer is for a limited time only! <i>(elixirs only last for 1 scenario)</i>"
            [option]
                label= _ "Buy the elixir (10 gold)."
                [command]
                    [do_command]
                        [fire_event]
                            raise=buy_elixir
                        [/fire_event]
                    [/do_command]
                [/command]
            [/option]
            [option]
                label= _ "Leave the elixir for Hahid."
                [command]
                    [do_command]
                        [fire_event]
                            raise=ignore_elixir
                        [/fire_event]
                    [/do_command]
                [/command]
            [/option]
        [/message]
    [/event]

    # frostbite damage
#define SET_FROSTBITE_AMOUNT TURN_NUMBER AMOUNT
    [event]
        name=turn {TURN_NUMBER}
        {VARIABLE frostbite_amount {AMOUNT}}
    [/event]
#enddef
    {SET_FROSTBITE_AMOUNT  {ON_DIFFICULTY  1   1   1}    2}
    {SET_FROSTBITE_AMOUNT  {ON_DIFFICULTY 10  10  10}    3}
    {SET_FROSTBITE_AMOUNT  {ON_DIFFICULTY 20  20  20}    4}
    {SET_FROSTBITE_AMOUNT  {ON_DIFFICULTY 30  30  30}    5}
    {SET_FROSTBITE_AMOUNT  {ON_DIFFICULTY 40  40  40}    6}
    {SET_FROSTBITE_AMOUNT  {ON_DIFFICULTY 50  50  50}    7}
    {SET_FROSTBITE_AMOUNT  {ON_DIFFICULTY 60  60  60}    8}
    {SET_FROSTBITE_AMOUNT  {ON_DIFFICULTY 70  70  70}    9}
    {SET_FROSTBITE_AMOUNT  {ON_DIFFICULTY 80  80  80}   10}
    {SET_FROSTBITE_AMOUNT  {ON_DIFFICULTY 90  90  90}   11}
    {SET_FROSTBITE_AMOUNT {ON_DIFFICULTY 100 100 100}   12}
    {SET_FROSTBITE_AMOUNT {ON_DIFFICULTY 110 110 110}   13} # good luck surviving long enough for these numbers to matter
    {SET_FROSTBITE_AMOUNT {ON_DIFFICULTY 120 120 120}   14}
    {SET_FROSTBITE_AMOUNT {ON_DIFFICULTY 130 130 130}   15}
    {SET_FROSTBITE_AMOUNT {ON_DIFFICULTY 140 140 140}   16}
    {SET_FROSTBITE_AMOUNT {ON_DIFFICULTY 150 150 150}   17}
    [event]
        name=side 5 turn end
        first_time_only=no
        [store_unit]
            [filter]
                side=1
                x,y=0-99,0-99 # not on your recall list

                [not]
                    trait=undead
                [/not]
            [/filter]
            kill=no
            variable=frostbite_units
        [/store_unit]

        [sound]
            name=wind.ogg
        [/sound]

        [delay]
            time=200
        [/delay]

        [foreach]
            array=frostbite_units
            variable=unit
            [do]
                {MODIFY_UNIT (id=$unit.id) status.slowed yes}
                [delay]
                    time=100
                [/delay]

                [if]
                    # elixir of elements and yetiburger grant immunity to frostbite
                    # (there's only 2 immunity items and you have 3 heroes, so this isn't abusable to farm infinite gold)
                    [have_unit]
                        id=$unit.id
                        trait=TRAIT_{ID_YETIBURGER},TRAIT_elements
                    [/have_unit]

                    [then]
                        [floating_text]
                            x,y=$unit.x,$unit.y
                            #po: other units are taking damage from the cold, but this unit is immune (through the elixir or yetiburger)
                            text= _ "<span color='#00FF00' size='small'>resist</span>"
                        [/floating_text]
                    [/then]

                    [else]
                        [if]
                            # if the unit is about to die, deal the damage after turn refresh, so we have a chance to heal first
                            [have_unit]
                                id=$unit.id
                                formula=(self.hitpoints<=$frostbite_amount)
                            [/have_unit]
                            [then]
                                [event]
                                    name=turn refresh
                                    delayed_variable_substitution=no
                                    [harm_unit]
                                        [filter]
                                            id=$unit.id
                                        [/filter]
                                        amount=$frostbite_amount
                                        animate=yes
                                        kill=yes
                                        fire_event=yes
                                    [/harm_unit]
                                [/event]
                            [/then]

                            # otherwise deal the damage immediately, and don't animate
                            [else]
                                [harm_unit]
                                    [filter]
                                        id=$unit.id
                                    [/filter]
                                    amount=$frostbite_amount
                                    animate=no
                                    kill=yes
                                    fire_event=yes
                                [/harm_unit]
                            [/else]
                        [/if]
                    [/else]
                [/if]
                {MODIFY_UNIT (id=$unit.id) status.slowed no}
                [fire_event]
                    name=explain_frostbite
                    [primary_unit]
                        id=$unit.id
                    [/primary_unit]
                [/fire_event]
            [/do]
        [/foreach]
        [delay]
            time=200
        [/delay]
    [/event]
    [event]
        name=explain_frostbite
        [message]
            speaker=unit
            message= _ "<i>Brrrr</i>, I can’t feel my fingers or toes! We’ll die of cold if we’re trapped out here for too long."
        [/message]
        [message]
            speaker=Addogin
            message= _ "What am I even doin’ here? All I wanted was to make an honest living smashin’ in skulls, then retire somewhere warm..."
        [/message]
        [show_objectives]
        [/show_objectives]
    [/event]
    [event]
        name=turn 20
        [message]
            speaker=Gweddry
            message= _ "The cold keeps getting worse! We have to reach that abandoned castle before we all freeze!"
        [/message]
    [/event]

    # warn the player to be frugal with their gold over the next few scenarios, in anticipation of S12 Evacuation
    # this also fires when the drakes recruit/recall, in case the player just decides not to recruit anything
    [event]
        name=recruit,recall
        [message]
            speaker=Dacyn
            message= _ "Gweddry, you should try to conserve our gold over the next few conflicts. We will be hard-pressed to find many villages in these lands and will surely need more for later."
        [/message]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "(This and the next 3 scenarios have 100% carryover, but few villages and 0 starting gold.)"
        [/message]
        [message]
            speaker=narrator
            image=wesnoth-icon.png
            message= _ "(You’ll want as much gold as you can possibly get when you try to leave the wildlands!)"
        [/message]
    [/event]

    # reveal the ruined keep
    [event]
        name=moveto
        [filter]
            side=1
            [filter_location]
                x=20,25
                y=22,28
                radius=9
            [/filter_location]
        [/filter]
        [remove_shroud]
            side=1
            x,y=24,28
            radius=2
        [/remove_shroud]
        {SCROLL_TO 24 28}
        [if]
            {VARIABLE_CONDITIONAL unit.id equals Dacyn}
            [then]
                [message]
                    speaker=Gweddry
                    #po: The speaker is normally whichever unit just moved. However, if that's Dacyn then Gweddry says it to avoid Dacyn talking to himself.
                    message= _ "Look, a ruined castle off in the distance! Is that the one we’re looking for?"
                [/message]
            [/then]

            [else]
                [message]
                    speaker=unit
                    message= _ "Look, a ruined castle off in the distance! Is that the one we’re looking for?"
                [/message]
            [/else]
        [/if]
        [message]
            speaker=Dacyn
            message= _ "No. The ruin we’re journeying towards lies across the river."
        [/message]
    [/event]

    #---------------------
    # WOLF EVENTS
    #---------------------
#define SPAWN_ON_TURN TURN TYPE COUNT SPAWNX SPAWNY
    [event]
        name=side 1 turn {TURN}
        {REPEAT {COUNT} (
            {GENERIC_UNIT 4 ({TYPE}) {SPAWNX} {SPAWNY}}
        )}
    [/event]
#enddef

    {SPAWN_ON_TURN  1 (Wolf)       {ON_DIFFICULTY 0 2 3} 1 12}

    {SPAWN_ON_TURN  9 (Great Wolf) {ON_DIFFICULTY 0 1 1} 53 27}
    {SPAWN_ON_TURN  9 (Wolf)       {ON_DIFFICULTY 0 1 2} 53 27}
    {SPAWN_ON_TURN 18 (Wolf)       {ON_DIFFICULTY 0 1 2} 1 12}

    {SPAWN_ON_TURN 24 (Great Wolf) {ON_DIFFICULTY 0 1 1} 53 27}
    {SPAWN_ON_TURN 24 (Wolf)       {ON_DIFFICULTY 0 1 2} 53 27}

    {SPAWN_ON_TURN 32 (Wolf)       {ON_DIFFICULTY 0 2 3} 1 12}

    {SPAWN_ON_TURN 40 (Great Wolf) {ON_DIFFICULTY 0 1 1} 53 27}
    {SPAWN_ON_TURN 40 (Wolf)       {ON_DIFFICULTY 0 1 2} 53 27}

    {SPAWN_ON_TURN 48 (Great Wolf) {ON_DIFFICULTY 0 0 1} 53 27}
    {SPAWN_ON_TURN 48 (Wolf)       {ON_DIFFICULTY 0 1 2} 53 27}
    {SPAWN_ON_TURN 48 (Wolf)       {ON_DIFFICULTY 0 2 2} 1 12}

    {SPAWN_ON_TURN 56 (Great Wolf) {ON_DIFFICULTY 0 1 1} 53 27}
    {SPAWN_ON_TURN 56 (Wolf)       {ON_DIFFICULTY 0 1 2} 53 27}

    {SPAWN_ON_TURN 64 (Wolf)       {ON_DIFFICULTY 0 2 3} 1 12}

    {SPAWN_ON_TURN 72 (Great Wolf) {ON_DIFFICULTY 0 1 1} 53 27}
    {SPAWN_ON_TURN 72 (Wolf)       {ON_DIFFICULTY 0 1 2} 53 27}

    #---------------------
    # DRAKE EVENTS
    #---------------------
    [event]
        name=prestart
        {NAMED_UNIT 3 (Orcish Warlord)   33 11 "Tapok"  (_"Tapok")  ()}
        [+unit]
            max_moves=0
        [/unit]
        {FACING sw}
        {NAMED_UNIT 3 (Orcish Grunt)     34 11 "Ogho"   (_"Ogho")   ()}
        [+unit]
            max_moves=0
        [/unit]
        {FACING sw}
        {NAMED_NOTRAIT_UNIT 2 (Drake Flameheart) 30 12 "Mortic" (_"Mortic")}
        [+unit]
            max_moves=0
        [/unit]
        {FACING ne}
        [+unit]
            [modifications]
                {TRAIT_RESILIENT}
            [/modifications]
        [/unit]

        [+unit]
            [modifications]
                {TRAIT_STRONG}
            [/modifications]
        [/unit]

        [modify_unit]
            [filter]
                id=Mortic
            [/filter]

            [object]
                [effect]
                    apply_to=overlay
                    add=misc/leader-crown.png
                [/effect]
                # not canrecruit=yes, otherwise he'll run away from battle and go towards a keep
            [/object]
        [/modify_unit]
    [/event]
    [event]
        name=sighted
        [filter]
            side=2,3 # spotting any drake (most likely Mortic) triggers this exchange
        [/filter]
        [filter_second]
            side=1
        [/filter_second]

        # reveal the area
        [remove_shroud]
            side=1
            x,y=31-33,12
            radius=2
        [/remove_shroud]
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x,y=31-33,12
            radius=2
        [/lift_fog]

        [message]
            speaker=Tapok
            #po: male Orcish Warlord talking to Mortic, a random-gender Drake Flameheart.
            #po: "they" being two other male drakes
            message= _ "Well? Are they ready?"
        [/message]
        {NAMED_UNIT 2 (Drake Glider)     31 12 "Ga'all" (_"Ga’all") ()} {ANIMATE} {FACING sw}
        {NAMED_UNIT 2 (Drake Warrior)    31 13 "Verash" (_"Verash") ()} {ANIMATE} {FACING nw}
        [message]
            speaker=Mortic
            #po: random-gender Drake to two male drakes
            #po: using the Morogor dialect from WoF (unless I messed it up)
            message= _ "Ga’all, your Hunt has failed.
Verash, your claws grow aged.
To our Flight, your only usefulness remains...
As tribute to the orcs."
        [/message]
        [message]
            speaker=Verash
            #po: "Aspirant" is a drake military rank
            message= _ "Aspirant Mortic,
As you command."
        [/message]
        [message]
            speaker=Ogho
            message= _ "C’mon wyrms, get moving!"
        [/message]
        {MOVE_UNIT id=Ogho   30 1}
        {MOVE_UNIT id=Verash 30 1}
        {MOVE_UNIT id=Ga'all 30 1}
        [message]
            speaker=Tapok
            message= _ "Heh heh, quality tribute, as always. Be grateful for our generosity. Chief only asked for two this time!"
        [/message]
        {MOVE_UNIT id=Tapok 30 1}
        {KILL id=Ogho,Verash,Ga'all,Tapok}
        {MODIFY_UNIT id=Mortic max_moves 5}

        [delay]
            time=700
        [/delay]

        {MODIFY_UNIT id=Mortic facing sw}
        [delay]
            time=300
        [/delay]

        {FIND_NEARBY (
            race=drake
            canrecruit=yes
            [or]
                id=Mortic
            [/or]
        )
        $unit.x $unit.y 99} # probably mortic
        [message]
            speaker=$found_unit.id
            #po: speaker is a drake, probably Mortic
            message= _ "An unknown creature approaches.
Paler than an Orc.
Taller than a Dwarf.
Tell me of your kin."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "We are men, of Wesnoth! We come in peace, seeking magic to help in our war against an undead horde."
        [/message]
        [message]
            speaker=$found_unit.id
            message= _ "Dra-Nak warned us.
You men of Wes-Noth speak of peace.
Yet you brandish your spears at our flight.
We have already paid the orcs, dearly.
No further tribute can be paid."
        [/message]
        [message]
            speaker=Gweddry
            message= _ "No, wait, we just want to-"
        [/message]
        [message]
            speaker=$found_unit.id
            message= _ "Our Hunt must continue."
        [/message]

        [modify_side]
            side=2
            gold={ON_DIFFICULTY 10 30 50}
        [/modify_side]
        [modify_side]
            side=3
            gold={ON_DIFFICULTY 10 30 50}
        [/modify_side]
        {CAPTURE_VILLAGES 3 32 13 0} # cap the village near Mortic, so he doesn't waste his first turn taking it
        {CLEAR_VARIABLE drakes_no_income}

        {SCROLL_TO 12 6}
        [remove_shroud]
            side=1
            x,y=12,6
            radius=1
        [/remove_shroud]
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x,y=12,6
            radius=1
        [/lift_fog]
        [delay]
            time=750
        [/delay]

        {SCROLL_TO 44 19}
        [remove_shroud]
            side=1
            x,y=44,19
            radius=1
        [/remove_shroud]
        [lift_fog]
            [filter_side]
                side=1
            [/filter_side]
            x,y=44,19
            radius=1
        [/lift_fog]
        [delay]
            time=750
        [/delay]
    [/event]
    [event]
        name=last breath
        [filter]
            id=Mortic
        [/filter]

        [message]
            speaker=Mortic
            #po: letting us know that they're just a small and relatively weak Drake Flight but it sets us up to meet some strong ones later
            #po: "aspirant" is a drake military rank
            message= _ "I am Aspirant.
Yet in these northlands, even prey bares its fangs,
And threatens to vanquish us.
We have struggled against mightier flights,
And tarnished our honor.
Yet our flame still persists.
I shall not fall here."
        [/message]
        {MOVE_UNIT id=Mortic 45 1}
        {KILL id=Mortic}
    [/event]

    #---------------------
    # OGRE EVENTS
    #---------------------
#define GRUG_OGRE_MESSAGE
    [fire_event]
        name=grug_ogre_message
    [/fire_event]
#enddef
    [event]
        name=grug_ogre_message
        [event]
            name=side 1 turn,side 1 turn end,grug_ogre_now
            [if]
                [have_unit]
                    id=Grug
                [/have_unit]

                [then]
                    [message]
                        speaker=Grug
                        #po: Grug to Gweddry
                        message= _ "Grug make ogre friendly! Talk ogre Grug make friend."
                    [/message]
                    [message]
                        speaker=Gweddry
                        message= _ "I think he’s saying he wants to talk with the wild ogres?"
                    [/message]
                    {VARIABLE grug_event_active yes}
                [/then]
            [/if]
        [/event]
    [/event]
#define OGRE_RECALL_COST
    [modify_unit]
        [filter]
            type=Young Ogre,Ogre,Great Ogre,Ancient Ogre
        [/filter]

        [object]
            duration=forever
            [effect]
                apply_to=recall_cost
                set=10
            [/effect]
        [/object]
    [/modify_unit]
#enddef

    # Humans will anger the ogres
    [event]
        name=sighted
        [filter]
            side=5
            [or]
                side=1
                race=human
            [/or]
        [/filter]
        [filter_second]
            side=5
            [or]
                side=1
                race=human
            [/or]
        [/filter_second]
        [filter_condition]
            {VARIABLE_CONDITIONAL ogres_peaceful not_equals yes}
        [/filter_condition]

        {FIND_NEARBY side=5 $unit.x $unit.y 99}
        [message]
            speaker=$found_unit.id
            #po: speaker is a hostile ogre
            message= _ "Guuuh... human?"
        [/message]
        {FIND_NEARBY side=1 $unit.x $unit.y 99}
        [message]
            speaker=$found_unit.id
            message= _ "Err, hello?"
        [/message]
        {FIND_NEARBY side=5 $unit.x $unit.y 99}
        [message]
            speaker=$found_unit.id
            message= _ "Human! Human human human!"
        [/message]
        [message]
            speaker=Gweddry
            message= _ "They don’t look very friendly..."
        [/message]

        {GRUG_OGRE_MESSAGE}
    [/event]

    #
    # Ogres can make peace with the ogres
    #
    [event]
        name=moveto
        [filter_condition] # works for either side's moves, unlike filter
            [have_unit]
                side=1
                race=ogre
                [not]
                    id=Grug
                [/not]
                [filter_adjacent]
                    side=5
                [/filter_adjacent]
            [/have_unit]
        [/filter_condition]

        {FIND_NEARBY side=1 $unit.x $unit.y 99}
        [message]
            speaker=$found_unit.id
            #po: player's ogre (but not Grug, who gets different lines) to hostile ogre
            message= _ "Guuuh... who you?"
        [/message]
        {FIND_NEARBY side=5 $unit.x $unit.y 99}
        [message]
            image_pos=right
            speaker=$found_unit.id
            #po: hostile ogre to player's ogre
            message= _ "Uhhhh... who <i><b>you</b></i>?"
        [/message]
        {FIND_NEARBY side=1 $unit.x $unit.y 99}
        [message]
            speaker=$found_unit.id
            message= _ "Me... friend? New friend?"
        [/message]
        {FIND_NEARBY side=5 $unit.x $unit.y 99}
        [message]
            image_pos=right
            speaker=$found_unit.id
            message= _ "New friend! Me no fight friend."
        [/message]

        {VARIABLE ogres_peaceful yes}
        [modify_side]
            side=5
            team_name=good
        [/modify_side]

        {GRUG_OGRE_MESSAGE}
    [/event]

    #
    # Grug can recruit the ogres
    #
    [event]
        name=moveto
        [filter_condition] # works for either side's moves, unlike filter
            [have_unit]
                side=1
                race=ogre
                id=Grug
                [filter_adjacent]
                    side=5
                [/filter_adjacent]
            [/have_unit]
        [/filter_condition]

        {FIND_NEARBY id=Grug 39 29 99}
        {FIND_NEARBY side=5 $found_unit.x $found_unit.y 99}

        {GRUG_OGRE_MESSAGE}
        [fire_event]
            name=grug_ogre_now
        [/fire_event]

        [message]
            image_pos=right
            x,y=$found_unit.x,$found_unit.y
            #po: hostile ogre to Grug
            message= _ "Guuuh... who you?"
        [/message]
        [message]
            speaker=Grug
            message= _ "Grug me! Me friend human."
        [/message]
        [message]
            image_pos=right
            x,y=$found_unit.x,$found_unit.y
            message= _ "Uhhhh... friend... human?"
        [/message]
        [message]
            speaker=Grug
            message= _ "You too friend human! Help human fight good."
        [/message]
        [message]
            image_pos=right
            x,y=$unit.x,$unit.y
            message= _ "OK, me help human fight! Human good!"
        [/message]

        {CLEAR_VARIABLE grug_event_active}
        {VARIABLE ogres_peaceful yes}
        [set_achievement]
            content_for=eastern_invasion
            id=ei_S09
        [/set_achievement]

        [modify_side]
            side=5
            team_name=good
        [/modify_side]
        [if]
            {VARIABLE_CONDITIONAL side_number equals 1}
            [then]
                {MODIFY_UNIT side=5 side 1}
                {OGRE_RECALL_COST}
            [/then]

            [else]
                [event]
                    name=side 1 turn
                    {MODIFY_UNIT side=5 side 1} # the micro_ai gets angry if I take its units away in the middle of its turn, so wait
                    {OGRE_RECALL_COST} # micro AI also doens't like this happening sooner, for some reason
                [/event]
            [/else]
        [/if]
    [/event]

    #---------------------
    # SHIPWRECK EVENT
    #---------------------
    {PLACE_IMAGE scenery/wreck-3.png 8 15}
    {PLACE_IMAGE items/gold-coins-small.png 9 16}
    {SET_LABEL 9 16 _"25 gold"}
    [event]
        name=moveto
        [filter]
            side=1
            x,y=9,16
        [/filter]
        {VARIABLE gold 25}
        [message]
            speaker=unit
            #po: circa 25 gold pieces
            message= _ "This shipwreck was carrying chests of gold! Most of them are buried under the ice, but I can still reach $gold pieces."
            sound=gold.ogg
        [/message]
        [gold]
            side=1
            amount=$gold
        [/gold]
        {REMOVE_IMAGE $unit.x $unit.y}
    [/event]

    #---------------------
    # DESTROYED VILLAGE EVENT
    #---------------------
    {PLACE_IMAGE items/gold-coins-small.png 27 32}
    [event]
        name=moveto
        [filter]
            side=1
            x,y=27,32
        [/filter]
        {VARIABLE gold 30}
        [message]
            speaker=unit
            #po: circa 30 gold pieces
            message= _ "This ruined town still has some valuables! I count enough to be worth $gold gold pieces."
            sound=gold.ogg
        [/message]
        [gold]
            side=1
            amount=$gold
        [/gold]
        {REMOVE_IMAGE $unit.x $unit.y}
    [/event]

    #---------------------
    # MORTIC GOLD EVENT
    #---------------------
    {PLACE_IMAGE items/gold-coins-small.png 30 12}
    [event]
        name=moveto
        [filter]
            side=1
            x,y=30,12
        [/filter]
        {VARIABLE gold 15}
        [message]
            speaker=unit
            #po: circa 15 gold pieces
            message= _ "This drake only had $gold gold pieces in his camp. Not much of a dragon hoard..."
            sound=gold.ogg
        [/message]
        [gold]
            side=1
            amount=$gold
        [/gold]
        {REMOVE_IMAGE $unit.x $unit.y}
    [/event]

    #---------------------
    # YETI EVENT
    #---------------------
    [event]
        name=sighted
        [filter]
            type=Yeti
        [/filter]
        [message]
            type=Yeti
            message= _ "GROARRR!!!"
        [/message]
    [/event]
    [event]
        name=last breath
        [filter]
            type=Yeti
        [/filter]
        {PLACE_ITEM_YETIBURGER $unit.x $unit.y}
        [message]
            speaker=Gweddry
            message= _ "I’ve never tried Yeti meat. I wonder what it tastes like?"
        [/message]
    [/event]
    [event]
        name=victory
        {CLEAR_VARIABLE frostbite_animate,frostbite_amount,frostbite_units,unit}
        {CLEAR_VARIABLE elixir_drinker}
    [/event]

    #---------------------
    # VICTORY EVENT
    #---------------------
    [event]
        name=moveto
        [filter]
            side=1
            x,y=42,4
            [not]
                trait=undead
            [/not]
        [/filter]
        [message]
            speaker=Dacyn
            #po: the player has moved a unit (any unit) to the castle
            message= _ "This is the place! Let us enter."
        [/message]

        {CLEAR_VARIABLE ogres_peaceful}
        {CLEAR_VARIABLE grug_event_active}
        [endlevel]
            result=victory
            bonus=no
            {NEW_GOLD_CARRYOVER 100}
        [/endlevel]
    [/event]

    {FOREIGN_DEFEAT}

    {HERODEATH_GWEDDRY}
    {HERODEATH_DACYN}
    {HERODEATH_OWAEC}
    {HERODEATH_ADDOGIN}
    {HERODEATH_HAHID}
    {HERODEATH_TERRAENT}
    {HERODEATH_GRUG}
    {HERODEATH_DOLBURRAS}
[/scenario]

#undef SPAWN_ON_TURN
#undef RECALL_IF_EMPTY
