Feasibility of Coding new abilities(double attack,trample,.)

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
Silux
Posts: 119
Joined: January 28th, 2013, 8:48 pm
Location: Somewhere over the rainbow

Feasibility of Coding new abilities(double attack,trample,.)

Post by Silux »

I like a lot BoW and i worked out new units and maps to play with my friends.

i managed to make new abilities by editing the existing ones, but i didn't managed to make new ones.
Example;

Code: Select all

#define ABILITY_DARK_AURA
    # Canned definition of the Illuminates ability to be included in an
    # [abilities] clause.
    [dark_aura]
        id=dark_aura
        value=-25
        max_value=0
        cumulative=yes
        name= _ "dark aura"
        female_name= _ "female^dark_aura"
        description= _ "Dark Aura:
This unit obscures the sun in the surrounding area, making chaotic units fight better, and legal units fight worse.
Any units adjacent to this unit will fight as if it were dusk when it is day, and as if it were night when it is dusk."
        affect_self=yes
    [/dark_aura]
#enddef
Then i'd like to code some new abilities that affect the number of attack turns like;
having the unit able to attack two units per turn
or getting being able to move for the remaining moves if had killed a unit in attack

Thanks in advance for reading!:D
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Feasibility of Coding new abilities(double attack,trampl

Post by 8680 »

Abilities with unrecognized tag names don’t do anything — [dark_aura] should be changed back to [illuminates].
Silux wrote:being able to move for the remaining moves if had killed a unit in attack
This can be done by setting movement_used=0 in the [attack] tags of the [unit_type]s you want to be able to do this (if you only want the units to be able to move after using some of their attacks but not others, only set movement_used in those attack’s tags).

This could be implemented as a weapon special thus:

Code: Select all

#define WEAPON_SPECIAL_SPRING_ATTACK
## We are in the [attack] tag’s [specials] subtag (aka [attack][specials]).
## Close the [specials] tag.
[/specials]
## Now we are in the [attack] tag.
## Set movement_used.
movement_used=0
## Reopen [specials].
[+specials]
## Now we are back in [attack][specials].
#enddef
## For more information on reopening (“amending”) tags, see
## <http://wiki.Wesnoth.org/SyntaxWML>.
However, non-skirmisher units lose all movement when moving next to a non-level-0 enemy (into the enemy’s Zone of Control), so movement_used=0 could only be used by skirmishers or against level 0 enemies.
Silux wrote:having the unit able to attack two units per turn
This can be done by setting attacks=2 in the [unit_type] tag. The number can be changed, though there’s no point in setting it over 6. Also, attacking not only eats all a unit’s moves, but uses them as fuel — units with no moves left cannot attack, unless their attacks are made to not use movement, as above.
Silux
Posts: 119
Joined: January 28th, 2013, 8:48 pm
Location: Somewhere over the rainbow

Re: Feasibility of Coding new abilities(double attack,trampl

Post by Silux »

Thanks!:D

I understood the code.

I got the point of how attack and moves work.
Now i can make a sort of berseker that refresh it's moves on attack^^
Zone of Control isn't a problem if the unit gains moves every time it attacks.
It would behave like the Ulfseker with the choice of stopping the assault.

I agree that more than 6 attacks are unnecessary(only six neighbours at time).
Anyway it would be cool to have some sort of Supermario berseker that stomps enemy heads all the way until the leader.

I'll try to get it work tomorrow:)
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Feasibility of Coding new abilities(double attack,trampl

Post by 8680 »

This should restore a unit’s moves after it attacks:

Code: Select all

#define ABILITY_MOVE_AFTER_ATTACK
[dummy]
    id="MoveAfterAttack"
    name="..."
    description="..."
[/dummy]
[/abilities]
[event]
    id="ABILITY_MOVE_AFTER_ATTACK-attack_end-1"
    name=attack_end
    first_time_only=no
    [filter]
        ability="MoveAfterAttack"
    [/filter]
    [modify_unit]
        [filter]
            id=$unit.id
        [/filter]
        moves=$unit.max_moves
    [/modify_unit]
[/event]
[event]
    id="ABILITY_MOVE_AFTER_ATTACK-attack_end-2"
    name=attack_end
    first_time_only=no
    [filter_second]
        ability="MoveAfterAttack"
    [/filter_second]
    [modify_unit]
        [filter]
            id=$second_unit.id
        [/filter]
        moves=$second_unit.max_moves
    [/modify_unit]
[/event]
[+abilities]
#enddef
I forgot in my previous example (spring attack) that it would need a [dummy] tag to be displayed in the sidebar, as above (inserted before the [/specials]).

Also, I’ve moved this to the proper subforum, WML Workshop (Coder’s Corner is for C++).
Last edited by 8680 on January 29th, 2013, 6:30 pm, edited 1 time in total.
Reason: Added first_time_only=no. For the, what, seventh time?
Silux
Posts: 119
Joined: January 28th, 2013, 8:48 pm
Location: Somewhere over the rainbow

Re: Feasibility of Coding new abilities(double attack,trampl

Post by Silux »

The latest code works partially, as the first unit having the ability which attacks gets to move a second time, while successive units behave as default.

I managed to get a dark version of illuminate by setting value at -25 instead of +25.It doesn't provide any bonus at dusk, but only negates the disadvantage in the day:D
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Feasibility of Coding new abilities(double attack,trampl

Post by 8680 »

Silux wrote:The latest code works partially, as the first unit having the ability which attacks gets to move a second time, while successive units behave as default.
Add first_time_only=no to the events. I think I have forgotten this at least thrice as many times as not.
Silux wrote:I managed to get a dark version of illuminate by setting value at -25 instead of +25.It doesn't provide any bonus at dusk, but only negates the disadvantage in the day:D
Many add-ons have a “de-illuminates” or “darkens” ability; download some and see how they do it. I’m fairly sure Era of Magic (EoMa) and Invasion from the Unknown (IftU) have such an ability. I think IftU is more complex, so you may want to start with EoMa; on the other hand, I think EoMa takes more space (it has more images), so you may want to start with IftU.
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: Feasibility of Coding new abilities(double attack,trampl

Post by JaMiT »

Silux wrote:I managed to get a dark version of illuminate by setting value at -25 instead of +25.It doesn't provide any bonus at dusk, but only negates the disadvantage in the day:D
What you are encountering is that min_value= defaults to 0. If you want your ability to reduce the lawful bonus below zero (which gives a bonus to chaotic units), change "max_value=25" (from the default illuminates) to "min_value=-25". (Have you looked at the the documentation for defining abilities?)
Silux
Posts: 119
Joined: January 28th, 2013, 8:48 pm
Location: Somewhere over the rainbow

Re: Feasibility of Coding new abilities(double attack,trampl

Post by Silux »

ok now i have both of them working as intented!

I looked on the documentation before posting, but i missed how to add new keys to the abilities.

Looking at how custom campaigns are made is really interesting!

I found out that moving after attacking is more useful as i thought.Its best use is "hit and run" attacks, possibly conquering a village on retreat.


New questions:
How i can make a unit to be able to move and attack the turn which is recruited?
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: Feasibility of Coding new abilities(double attack,trampl

Post by JaMiT »

Silux wrote:How i can make a unit to be able to move and attack the turn which is recruited?
Modify it in its recruit event.
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Feasibility of Coding new abilities(double attack,trampl

Post by 8680 »

JaMiT wrote:Modify it in its recruit event.
Like so:

Code: Select all

[event]
    name=recruit
    first_time_only=no
    [filter]
        ## A StandardUnitFilter for which units you want this to apply to.
        ## See <http://wiki.wesnoth.org/StandardUnitFilter>.
    [/filter]
    [modify_unit]
        [filter]
            id=$unit.id
        [/filter]
        moves=$unit.max_moves
        attacks_left=$unit.max_attacks
    [/modify_unit]
[/event]
Silux
Posts: 119
Joined: January 28th, 2013, 8:48 pm
Location: Somewhere over the rainbow

Re: Feasibility of Coding new abilities(double attack,trampl

Post by Silux »

where this event has to be placed?
i tried to put it in the scenario and on the unit, but it had no effect.

example:

Code: Select all

    [event]
        name=recruit
        first_time_only=no
        [filter]
            ## A StandardUnitFilter for which units you want this to apply to.
            ## See <http://wiki.wesnoth.org/StandardUnitFilter>.
        [/filter]
        [modify_unit]
            [filter]
                id=Troll Whelp
            [/filter]
            moves=$unit.max_moves
            attacks_left=$unit.max_attacks
        [/modify_unit]
    [/event]
User avatar
8680
Moderator Emeritus
Posts: 742
Joined: March 20th, 2011, 11:45 pm
Location: The past

Re: Feasibility of Coding new abilities(double attack,trampl

Post by 8680 »

If you want it to apply to all recruited Troll Whelps, try this:

Code: Select all

[event]
    name=recruit
    first_time_only=no
    [filter]
        type="Troll Whelp"
    [/filter]
    [modify_unit]
        [filter]
            id=$unit.id
        [/filter]
        moves=$unit.max_moves
        attacks_left=$unit.max_attacks
    [/modify_unit]
[/event]
Silux wrote:i tried to put it in the scenario and on the unit, but it had no effect.
Either should work. If you want it to apply in all scenarios, put it in the unit type. If you want it to apply only in specific scenarios, put it in those scenarios.
Silux
Posts: 119
Joined: January 28th, 2013, 8:48 pm
Location: Somewhere over the rainbow

Re: Feasibility of Coding new abilities(double attack,trampl

Post by Silux »

Code: Select all

[event]
    name=recruit
    first_time_only=no
    [filter]
        ## A StandardUnitFilter for which units you want this to apply to.
        ## See <http://wiki.wesnoth.org/StandardUnitFilter>.
    [/filter]
    [modify_unit]
        [filter]
            id=$unit.id
        [/filter]
        moves=$unit.max_moves
        attacks_left=$unit.max_attacks
    [/modify_unit]
    [/event]
#It seemed not to have any effect because i had put them in the wrong file path.
Tried that on the cfg of the orc assassin and the results were scary.As soon as someone recruited an orc assassin all units, even those recruited from other sides, got to be able to move the turn when recruited.
Battle with orcs were much more interesting, faster and brutal than usual:)

So it's possible to make units to affect the behavior of other units, maybe just only units of a certain race.
That's quite illuminating for me!

so:

Code: Select all

[event]
    name=recruit
    first_time_only=no
    [filter]
        type="General"
    [/filter]
    [modify_unit]
        [filter]
            id=$unit.id
        [/filter]
        apply_to=attack
        range=melee
        increase_damage=20%
        
        range=ranged
        increase_damage=20%
    [/modify_unit]
    [/event]
        [event]
    name=die
    first_time_only=no
    [filter]
        type="General"
    [/filter]
    [modify_unit]
        [filter]
            id=$unit.id
            
        [/filter]
        apply_to=attack
        range=melee
        increase_damage=-20%
        
        range=ranged
        increase_damage=-20%
    [/modify_unit]
    [/event]
 
It sould boost the attack of "General" units for each General in the battle.
JaMiT
Inactive Developer
Posts: 511
Joined: January 22nd, 2012, 12:38 am

Re: Feasibility of Coding new abilities(double attack,trampl

Post by JaMiT »

Silux wrote:As soon as someone recruited an orc assassin all units, even those recruited from other sides, got to be able to move the turn when recruited.
Now that you know what happened, do you know why it happened? Just in case: This event had no effect until someone recruited an orc assassin because you put the event in the unit type definition. (Events defined in a unit type do not exist until a unit of that type exists.) The event affected all units because the event's filter was empty (meaning it fired for all recruit events).

Silux wrote:

Code: Select all

    [modify_unit]
        [filter]
            id=$unit.id
        [/filter]
        apply_to=attack
        range=melee
        increase_damage=20%
        
        range=ranged
        increase_damage=20%
    [/modify_unit]
You cannot repeat attribute keys within a tag. One of the "range=" lines will overwrite the other. Then again, why specify range= if you intend to modify all ranges by the same amount? (Or do you have custom ranges that are intentionally not modified?) Generally speaking, if a restriction is not specified in WML, the default tends to be "everything".

Also, there is no reason to expect keys for the [effect] tag to work directly inside [modify_unit].

Silux wrote:It sould boost the attack of "General" units for each General in the battle.
No, (even assuming [modify_unit] could work the way you wrote it) it would boost the attack of each "General", not a boost times the number of Generals. (You told [modify_unit] that it should only apply to the unit that triggered the event -- i.e. filtered on the unit's unique ID matching the ID of the unit that triggered the event by being recruited or killed. Which ends up being rather pointless in the "killed" case, as the only unit being modified is about to be deleted, never to return.)
Silux
Posts: 119
Joined: January 28th, 2013, 8:48 pm
Location: Somewhere over the rainbow

Re: Feasibility of Coding new abilities(double attack,trampl

Post by Silux »

Code: Select all

[filter]
           side=1
[/filter]       
[modify_unit]
            [filter]
                id=$unit.id
            [/filter]
            apply_to=attack
            increase_damage=20%
[/modify_unit]
Ok!
So this once fired if the side is 1, will boost the attack of the unit by 20%
Post Reply