Ambush Question

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Akkarin345
Posts: 429
Joined: January 19th, 2008, 6:16 pm
Location: England

Ambush Question

Post by Akkarin345 »

In my campaign i am hoping that when you move into a village a number of 'villagers' will appear to defend it, as you are invading their home. This is the same as Decent Into Darkness' 2nd scenario. I was wondering if this code would work and whether just pasting it into the scenario file would be ok; or whether it needs something else adding to it. ( I took this from an existing campaign and modified it to what i need)

Code: Select all

    # Generate a random number of guards between 0 and 2 around X,Y
#define RANDOM_GUARDS TYPE NAME_STRING SIDE X Y
    {VARIABLE_OP number_of_guards random 0..2}

    {REPEAT $number_of_guards (
        [store_locations]
            [filter_adjacent_location]
                x,y={X},{Y}
            [/filter_adjacent_location]

            [not]
                [filter]
                [/filter]
            [/not]

            variable=possible_guard_locations
        [/store_locations]

        {IF_VAR possible_guard_locations.length greater_than 0 (
            [then]
                {VARIABLE_OP random_location_index random 0..$possible_guard_locations.length}

                [move_unit_fake]
                    side={SIDE}
                    type={TYPE}
                    x={X},$possible_guard_locations[$random_location_index].x
                    y={Y},$possible_guard_locations[$random_location_index].y
                [/move_unit_fake]

                [unit]
                    name={NAME_STRING}  # wmllint: ignore
                    type={TYPE}
                    side={SIDE}
                    x,y=$possible_guard_locations[$random_location_index].x,$possible_guard_locations[$random_location_index].y
                    random_traits=yes
                [/unit]
            [/then]
        )}
    )}

    {CLEAR_VARIABLE number_of_guards}
    {CLEAR_VARIABLE possible_guard_locations}
    {CLEAR_VARIABLE random_location_index}
#enddef

    # In-scenario events
    [event]
        name=capture
        first_time_only=yes
        [filter]
            side=1
        [/filter]

        [message]
            speaker=Eydis
            message=_ "As i thought the villagers will die to protect their homes."
        [/message]
    [/event]

    [event]
        name=capture
        first_time_only=no
        [filter]
            side=1
        [/filter]

        {IF_VAR village_$x1|_$y1|_cleared not_equals yes (
            [then]
                {RANDOM_GUARDS (Marauder Scout, Marauder Axeman) (_ "Villager") 2 $x1 $y1}

                {VARIABLE village_$x1|_$y1|_cleared yes}
            [/then]

            [else]
                [allow_undo][/allow_undo]
            [/else]
        )}
    [/event]
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: Ambush Question

Post by A Guy »

You need to put the macro definition for {RANDOM_GUARDS} somewhere.
I'm just... a guy...
I'm back for now, I might get started on some work again.
User avatar
Akkarin345
Posts: 429
Joined: January 19th, 2008, 6:16 pm
Location: England

Re: Ambush Question

Post by Akkarin345 »

Erm i don't know much about WML but i intended that there would be a random number ( no more than 2) and it would be random about which of the two units would make up the villagers. Would it be easier to just have a set number and a set unit type?
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Ambush Question

Post by Max »

looks good - i can't see anything missing. although there's one problem:

Code: Select all

{RANDOM_GUARDS (Marauder Scout, Marauder Axeman) (_ "Villager") 2 $x1 $y1}
this macro expects you to pass a single unit type...
User avatar
Akkarin345
Posts: 429
Joined: January 19th, 2008, 6:16 pm
Location: England

Re: Ambush Question

Post by Akkarin345 »

Ahh ok, so if i took out the axeman then the code would work?
Also is there a way of getting the axeman and/or scout option?
Max
Posts: 1449
Joined: April 13th, 2008, 12:41 am

Re: Ambush Question

Post by Max »

just pass a single unit type and everything should be fine, the macro itself is quite smart and doesn't depend on anything else than the code snippets you've posted here.

i'm sure there is a way to pass a variable (containing a list) instead of a unit type, but my wml knowledge isn't that good.
User avatar
Akkarin345
Posts: 429
Joined: January 19th, 2008, 6:16 pm
Location: England

Re: Ambush Question

Post by Akkarin345 »

Ok thanks for the help. I wish i knew more WML as i have some big ideas for this campaign and they probobly are too complicated to code :lol2:.
User avatar
Akkarin345
Posts: 429
Joined: January 19th, 2008, 6:16 pm
Location: England

Re: Ambush Question

Post by Akkarin345 »

Sorry to double post, i however do have a new question. ( I think i might change this to the Chronicle of Vanimaro, my campaign, WML help thread lol)

When loading the campaign after adding the second scenario i got an error message which says these lines have something wrong in them :

21, 44 and 45 ( i suspect it would say theres more if there was enough space to )
I have included the top half of the file and marked the lines where something is meant to be wrong.

Code: Select all

#textdomain wesnoth-CoV
[scenario]
    id=1_1_First_Blood
    name= _ "First Blood"
    next_scenario=2_Revenge_of_the_Marauders
    victory_when_enemies_defeated=yes
    map_data="{@campaigns/Chronicles_of_Vanimaro/maps/1_1_First_Blood.map}"
    turns=24
    {SCENARIO_MUSIC "battle.ogg"}
    {DEFAULT_SCHEDULE}

    [story]
        [part]
            story=_ "The Sidhe and Issaelfr set out to raid the local Marauder village. They saw their new enemy as not fit of the land and felt they were above the Marauders. The first battle of the Marauders and the Elves would soon begin. A worried Marauder Lord preapred for battle. "
            delay=4000
            show_title=yes
        [/part]   
    [/story]     --------> line 21
    [event]
        name=prestart
        [objectives]
            side=1
            [objective]
                description= _ "Defeat Asgir"
                condition=win
            [/objective]
            [objective]
                description= _ "Death of Onnachadh"
                condition=lose
            [/objective]
            [objective]
                description= _ "Death of Eydis"
                condition=lose
            [/objective]
            [objective]
                description= _ "Turns run out"
                condition=lose
            [/objective]

# Side definitions
 ----------------------------------> line 44 if you do?
    [side]
        type="Wild Elf Raindancer"   ----> line 44 if you don't count the spaces
        id=Onnachadh
        name= _"Onnachadh"
        unrenamable=yes
        side=1
        canrecruit=yes
        controller=human
        recruit="Wild Elf Warrior,Wild Elf Raindancer,Wild Elf Wanderer,Wild Elf Fury"
        gold=100
        team_name=Sidhe   
        user_team_name=_"Sidhe"   
    [/side]
    [side]
        type="Frost Elf Archer"
        id=Eydis
        name= _"Eydis"
        unrenamable=yes
        side=2
        canrecruit=yes
        controller=ai
        recruit="Frost Elf Archer,Frost Elf Bladedancer"
        [ai]
            recruitment_pattern=bladedancer,archer, Bladedance, archer
        [/ai]
        gold=100
        team_name=Sidhe  
        user_team_name=_"Sidhe"   
    [/side]

Are you meant to count the gaps as a line?
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: Ambush Question

Post by A Guy »

You forgot to close the [event] tag.
I'm just... a guy...
I'm back for now, I might get started on some work again.
User avatar
Akkarin345
Posts: 429
Joined: January 19th, 2008, 6:16 pm
Location: England

Re: Ambush Question

Post by Akkarin345 »

Ahhh thanks.
Does Wesnoth count a blank line as a line or is that number lines of coding?
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: Ambush Question

Post by A Guy »

Blank lines are counted as well.
I'm just... a guy...
I'm back for now, I might get started on some work again.
Post Reply