Defense and abilities

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.
User avatar
Picka79
Posts: 24
Joined: February 11th, 2014, 5:59 pm
Location: France

Defense and abilities

Post by Picka79 »

Hello!
I'm trying to create an ability who heals and increases by 10% the defense of adjacents mounted units (allies). I usually look at the abilities from the game to help me but there isn't any abilities which changes the defense.
I tried this, but it doesn't work :

Code: Select all

    [defense]
        id=test4
        value=-10
        [filter_base_value]
            greater_than=20
        [/filter_base_value]
        affect_allies=yes
        affect_enemies=no
        affect_self=no
        [affect_adjacent]
            adjacent=n,ne,se,s,sw,nw
            [filter]
                movement_type=mounted
            [/filter]
        [/affect_adjacent]
    [/defense]
Can you help me?

Sorry about my bad bad bad english :roll:
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Defense and abilities

Post by zookeeper »

There is no simple way (as in, doable with ability tags alone) to do a defense-altering ability. In fact, I believe it's practically impossible in a way which would be reflected everywhere it needs to be in the interface; the best I can think of is giving every potential attacker's every attack an invisible weapon special which decreases their chance to hit. However, the improved defense would only show up in the damage calculations dialog, meaning that when moving your cavalry, the hexes next to the support unit would not display the improved defense value.
User avatar
Picka79
Posts: 24
Joined: February 11th, 2014, 5:59 pm
Location: France

Re: Defense and abilities

Post by Picka79 »

Thank's for your answer.

I am going to find another idea, because it is a little bit hard for me! ^_^



Hum, I have another question! I want that my unit give 1 exp point to adjacent units (when the units heal) but i don't know how to do that! :hmm:
User avatar
trewe
Translator
Posts: 122
Joined: December 24th, 2012, 5:37 pm
Location: Portugal
Contact:

Re: Defense and abilities

Post by trewe »

The simplest way would be to give every possible unit which could benefit from it an object which increases the defenses when an allied unit with that ability is adjacent.

e.g.

Code: Select all

    [event]
        name=turn refresh,recruit,recall,post advance
        first_time_only=no
        id=increase_defense_event

        [filter_condition] # do not fire this event without a reason
            [have_unit]
                [filter_wml]
                    movement_type=mounted
                [/filter_wml]
                [not]
                    [filter_wml]
                        [modifications]
                            [object]
                                custom_object_id=increases_defenses
                            [/object]
                        [/modifications]
                    [/filter_wml]
                [/not]
            [/have_unit]
        [/filter_condition]

        [store_unit]
            [filter] # any mounted units still without the object
                [filter_wml]
                    movement_type=mounted
                [/filter_wml]
                [not]
                    [filter_wml]
                        [modifications]
                            [object]
                                custom_object_id=increases_defenses
                            [/object]
                        [/modifications]
                    [/filter_wml]
                [/not]
            [/filter]
            variable=possible_targets
        [/store_unit]

        {FOREACH possible_targets i_temp}
            [object]
                silent=yes
                custom_object_id=increases_defenses # prevent the object being given more than once

                [filter]
                    id=$possible_targets[$i_temp].id
                [/filter]

                [effect] # apply this effect if an allied unit with said ability is adjacent
                    [filter]
                        [filter_adjacent]
                            ability=increase_defense
                            is_enemy=no
                        [/filter_adjacent]
                    [/filter]

                    apply_to=defense
                    replace=no
                    [defense] # all defenses which should be modified
                        shallow_water=-10
                        reef=-10
                        swamp_water=-10
                        flat=-10
                        sand=-10
                        forest=-10
                        hills=-10
                        #mountains=-10
                        village=-10
                        castle=-10
                        cave=-10
                        frozen=-10
                        fungus=-10
                    [/defense]
                [/effect]
            [/object]
        {NEXT i_temp}

        {CLEAR_VARIABLE possible_targets}
    [/event]
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Defense and abilities

Post by zookeeper »

trewe wrote:The simplest way would be to give every possible unit which could benefit from it an object which increases the defenses when an allied unit with that ability is adjacent.
Well, your code also makes the effect permanent. As opposed to abilities, an [effect] [filter] only selects whether or not to apply the effect at all, not when it should be "active".
User avatar
Dugi
Posts: 4961
Joined: July 22nd, 2010, 10:29 am
Location: Carpathian Mountains
Contact:

Re: Defense and abilities

Post by Dugi »

A working alternative would be to make no change to the terrain defence at all, but to add it a weapon special that decreases the opponent's chance to hit if the user is adjacent to a unit with that ability, something like this:

Code: Select all

[chance_to_hit]
  id=defended
  apply_to=opponent
  sub=10
  [filter_self]
     [filter_adjacent]
        ability=defend
        is_enemy=no
     [/filter_adjacent]
  [/filter_self]
[/chance_to_hit]
User avatar
Picka79
Posts: 24
Joined: February 11th, 2014, 5:59 pm
Location: France

Re: Defense and abilities

Post by Picka79 »

:mrgreen: Thank's Dugi!
Your method works perfectly!
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Defense and abilities

Post by zookeeper »

Yeah, it works as long as they also have a ranged attack to give that special to. Otherwise, ranged attacks will hit them normally.
User avatar
Picka79
Posts: 24
Joined: February 11th, 2014, 5:59 pm
Location: France

Re: Defense and abilities

Post by Picka79 »

I have a second question!

I'm trying to create an ability, "student", which give 1 exp at the beginning of the turn if an adjacent unit has the ability "teacher".

Code: Select all

#define ABILITY_STUDENT
    [dummy]
        id=student
    [/dummy]

    [abilities]
    [/abilities]

    [event]
        name=turn_refresh
        first_time_only=no
        [modify_unit]
            [filter]
                side=$side_number
                ability=student
                [filter_adjacent]
                    ability=teacher
                    side=$side_number
                [/filter_adjacent]
            [/filter]
            experience="$($this_unit.experience + 1)"
        [/modify_unit]
    [/event]
#enddef
Of course, that does not work. :cry: Can you help me?
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Defense and abilities

Post by 8680 »

Picka79 wrote:I'm trying to create an ability, "student", which give 1 exp at the beginning of the turn if an adjacent unit has the ability "teacher".

Code: Select all

#define ABILITY_STUDENT
    [dummy]
        id=student
    [/dummy]

    [abilities]
    [/abilities]

    [event]
        name=turn_refresh
        first_time_only=no
        [modify_unit]
            [filter]
                side=$side_number
                ability=student
                [filter_adjacent]
                    ability=teacher
                    side=$side_number
                [/filter_adjacent]
            [/filter]
            experience="$($this_unit.experience + 1)"
        [/modify_unit]
    [/event]
#enddef
When your current ABILITY_STUDENT macro is included in an [abilities] tag, like this:

Code: Select all

[abilities]
    {ABILITY_ABC}
    {ABILITY_STUDENT}
    {ABILITY_XYZ}
[/abilities]
It will expand to look like this:

Code: Select all

[abilities]
    {ABILITY_ABC}
    [dummy]
        id=student
    [/dummy]
    [abilities]
    [/abilities]
    [event]
        ...
    [/event]
    {ABILITY_XYZ}
[/abilities]
Whereas it should be written to expand to look like this:

Code: Select all

[abilities]
    {ABILITY_ABC}
    [dummy]
        id=student
    [/dummy]
[/abilities]
[event]
    ...
[/event]
[+abilities]
    {ABILITY_XYZ}
[/abilities]
So, the macro definition should look like this:

Code: Select all

#define ABILITY_STUDENT
    [dummy]
        id=student
    [/dummy]
[/abilities]
[event]
    ...
[/event]
[+abilities]
#enddef
User avatar
Picka79
Posts: 24
Joined: February 11th, 2014, 5:59 pm
Location: France

Re: Defense and abilities

Post by Picka79 »

I tried your code but my unit won nothing :|
I doubtless made an error in [event].

My current code :

Code: Select all

#define ABILITY_STUDENT
    [dummy]
        id=student
    [/dummy]

    [/abilities]

    [event]
        name=turn_refresh
        first_time_only=no
        [modify_unit]
            [filter]
                side=$side_number
                ability=student
                [filter_adjacent]
                    ability=teacher
                    side=$side_number
                [/filter_adjacent]
            [/filter]
            experience="$($this_unit.experience + 1)"
        [/modify_unit]
    [/event]

[+abilities]

#enddef
User avatar
iceiceice
Posts: 1056
Joined: August 23rd, 2013, 2:10 am

Re: Defense and abilities

Post by iceiceice »

name=turn_refresh -> name = turn refresh
User avatar
Picka79
Posts: 24
Joined: February 11th, 2014, 5:59 pm
Location: France

Re: Defense and abilities

Post by Picka79 »

It always doesn't work! :cry:
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Defense and abilities

Post by 8680 »

You may need to escape the variable and formula substitutions in experience="$($this_unit.experience + 1)" by adding vertical lines after the dollar signs (so it becomes experience="$|($|this_unit.experience + 1)").

This would be so that the variable and the formula will not be substituted by [event], but rather passed on to [modify_unit] — the variable $this_unit does not exist until [modify_unit] is running, so if it’s substituted before that, the formula would be + 1.
iceiceice wrote:name=turn_refresh -> name = turn refresh
Low lines and spaces are interchangeable in [event]name.
User avatar
iceiceice
Posts: 1056
Joined: August 23rd, 2013, 2:10 am

Re: Defense and abilities

Post by iceiceice »

Ah, didn't know that, I always just copy the wiki verbatim when possible.
Post Reply