Difference between revisions of "WML Abilities"

From The Battle for Wesnoth Wiki
m (Charm {{DevFeature}})
Line 97: Line 97:
 
                 {MODIFY_UNIT x,y=$x2,$y2 side $charmer_side}
 
                 {MODIFY_UNIT x,y=$x2,$y2 side $charmer_side}
 
                 {MODIFY_UNIT x,y=$x2,$y2 moves 1}
 
                 {MODIFY_UNIT x,y=$x2,$y2 moves 1}
 +
                {MODIFY_UNIT x,y=$x2,$y2 attacks_left 1}
 
   
 
   
 
                 {VARIABLE_OP varname format "side_$charmed_side|_units_charmed"}
 
                 {VARIABLE_OP varname format "side_$charmed_side|_units_charmed"}

Revision as of 13:12, 1 July 2006

Remember that you must include the WML ability code in every scenario where you intend them to work. Template:DevFeature Or include them in the unit file inside the [unit] tag.

Knockback Template:DevFeature

When a unit is hit with a knockback attack, it is immediately pushed one hex away from the attacker, at which point the combat ends. Exception: units in villages can't be knocked out of them.

Examples that give knockback for every Drake Glider on their slam attack, and for the Shock Trooper named Jane:

{KNOCKBACK (type=Drake Glider) slam}
{KNOCKBACK description=Jane mace}

Note that this uses the macros OPPOSITE_SIDE, IF, IF_HAVE_UNIT and STORE_UNIT_VAR from the WML Utilities page.

#define KNOCKBACK FILTER WEAPON
    [event]
        name=attacker_hits
        first_time_only=no

        [filter]
            {FILTER}
        [/filter]

        [special_filter]
            weapon={WEAPON}
        [/special_filter]

        [sound]
            name=ghoul-hit.wav
        [/sound]

        {OPPOSITE_SIDE $x2 $y2 $x1 $y1 target_hex}

        [store_locations]
            x,y=$x2,$y2
            terrain=AaBbDeLptUVvYZ
            variable=defender_in_village
        [/store_locations]

        {IF_HAVE_UNIT x,y=$target_hex.x,$target_hex.y (
            [else]
                {IF defender_in_village.length not_equals 1 (
                    [then]
                        {STORE_UNIT_VAR x,y=$x2,$y2 side side_of_defender}

                        [teleport]
                            [filter]
                                x,y=$x2,$y2
                            [/filter]

                            x,y=$target_hex.x,$target_hex.y
                        [/teleport]

                        [capture_village]
                            side=$side_of_defender
                            x,y=$target_hex.x,$target_hex.y
                        [/capture_village]

                        {CLEAR_VARIABLE side_of_defender}
                    [/then]
                )}
            [/else]
        )}

        {CLEAR_VARIABLE target_hex}
        {CLEAR_VARIABLE defender_in_village}
    [/event]
#enddef

Charm Template:DevFeature

When a unit is hit with a charm attack, it instantly jumps to the attacker's side, and returns to it's original side at the beginning of that side's turn. A charmed unit has 1 movement point and can attack.

Example that makes all Troll Whelps have charm on their attack:

{CHARM (type=Troll Whelp) fist}

Note that this uses the macros IF, STORE_UNIT_VAR and MODIFY_UNIT from the WML Utilities page.

#define CHARM FILTER WEAPON
    [event]
        name=attacker_hits
        first_time_only=no

        [filter]
            {FILTER}
        [/filter]

        [special_filter]
            weapon={WEAPON}
        [/special_filter]

        {STORE_UNIT_VAR x,y=$x1,$y1 side charmer_side}
        {STORE_UNIT_VAR x,y=$x2,$y2 side charmed_side}

        {IF charmer_side not_equals $charmed_side (
            [then]
                {MODIFY_UNIT x,y=$x2,$y2 variables.real_side $charmed_side}
                {MODIFY_UNIT x,y=$x2,$y2 side $charmer_side}
                {MODIFY_UNIT x,y=$x2,$y2 moves 1}
                {MODIFY_UNIT x,y=$x2,$y2 attacks_left 1}

                {VARIABLE_OP varname format "side_$charmed_side|_units_charmed"}
                {VARIABLE $varname yes}

                {CLEAR_VARIABLE varname}
            [/then]
        )}

        {CLEAR_VARIABLE charmer_side}
        {CLEAR_VARIABLE charmed_side}
    [/event]

    [event]
        name=side turn
        first_time_only=no

        {VARIABLE_OP this_side_charmed to_variable "side_$side_number|_units_charmed"}

        {IF this_side_charmed equals yes (
            [then]
                [store_unit]
                    [filter]
                        [not]
                            side=$side_number
                        [/not]
                    [/filter]

                    variable=possibly_charmed
                    kill=no
                [/store_unit]

                {FOREACH possibly_charmed i}
                    {VARIABLE_OP real_side format "0$possibly_charmed[$i].variables.real_side"}

                    {IF real_side not_equals "0" (
                        [then]
                            {IF side_number equals $possibly_charmed[$i].variables.real_side (
                                [then]
                                    {CLEAR_VARIABLE possibly_charmed[$i].variables.real_side}
                                    {VARIABLE possibly_charmed[$i].side $side_number}

                                    [unstore_unit]
                                        variable=possibly_charmed[$i]
                                        find_vacant=no
                                    [/unstore_unit]
                                [/then]
                            )}
                        [/then]
                    )}
                {NEXT i}

                {CLEAR_VARIABLE possibly_charmed}
            [/then]
        )}
    [/event]
#enddef

Bloodlust

Bloodlust is a very simple ability. If a unit that has bloodlust kills an enemy unit when attacking, it may attack again, provided that there are more enemy units adjacent to it. Uses the MODIFY_UNIT macro from the WML Utilities page.

This would give the bloodlust ability to all Dwarvish Ulfserkers (making them insanely powerful):

{BLOODLUST (type=Dwarvish Ulfserker)}
#define BLOODLUST FILTER
    [event]
        name=die
        first_time_only=no

        [filter_second]
            {FILTER}
        [/filter_second]

        {MODIFY_UNIT x,y=$x2,$y2 moves 0}
    [/event]
#enddef