dabber's questions: object on unit

The place to post your WML questions and answers.

Moderators: Forum Moderators, Developers

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.
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: check unit status

Post by dabber »

I cannot seem to check whether a unit is undead or not. What am I doing wrong? Truncated code below: (AoE drain attack)
Spoiler:
I can correctly check other information in the units variable, such as hitpoints and resistances, but I cannot seem to check not_living.
User avatar
Ravana
Forum Moderator
Posts: 2451
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: dabber's questions: check not living

Post by Ravana »

I believe you do not want the first $ for name=.
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: check not living

Post by dabber »

Well I feel dumb. That fixed it.
I write C code for a living, so I'm used to pointer dereference, but the $ in WML constantly gets me.
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: all terrain

Post by dabber »

Is there an easy way to make all terrain types unwalkable, and then make one terrain type cost 1 move? I don't want to have to individually list each type I want to set unwalkable. The goal is to let the unit move across only one type of terrain.
It seems like all I ask in this thread is dumb questions. :)
User avatar
Ravana
Forum Moderator
Posts: 2451
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: dabber's questions: all terrain

Post by Ravana »

Not really. Ideas might be
- switching movetype
- unwalkable overlay
but they all have limitations and side effects.

You can also iterate over movement_costs keys, but that would be more work than hardcoding existing terrain types.
User avatar
Pentarctagon
Project Manager
Posts: 4494
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: dabber's questions: all terrain

Post by Pentarctagon »

Would [terrain_defaults] help with this?
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: all terrain

Post by dabber »

If I create two last breath events for a unit, but one of the events kills the unit via [kill], will the second last breath always fire?
My second event doesn't seem to be firing and I'm trying to find a cause. I see both events in the save file looking correct.
User avatar
Adamant14
Posts: 906
Joined: April 24th, 2010, 1:14 pm

Re: dabber's questions: all terrain

Post by Adamant14 »

dabber wrote:
April 8th, 2019, 4:31 pm
If I create two last breath events for a unit, but one of the events kills the unit via [kill], will the second last breath always fire?
My second event doesn't seem to be firing and I'm trying to find a cause. I see both events in the save file looking correct.
If you kill the unit via [kill] tag in your first last breath event, then the unit does no longer exist, and the second last breath will never fire.

https://wiki.wesnoth.org/Eventwml#last_breath

https://wiki.wesnoth.org/Eventwml#die
Author of Antar, Son of Rheor ( SP Campaign) | Development Thread + Feedback Thread + Replays of ASoR
User avatar
Ravana
Forum Moderator
Posts: 2451
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: dabber's questions: last breath

Post by Ravana »

I believe you are not given any guarantee in which order the events would fire.
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: all terrain

Post by dabber »

Adamant14 wrote:
April 9th, 2019, 5:27 pm
dabber wrote:
April 8th, 2019, 4:31 pm
If I create two last breath events for a unit, but one of the events kills the unit via [kill], will the second last breath always fire?
My second event doesn't seem to be firing and I'm trying to find a cause. I see both events in the save file looking correct.
If you kill the unit via [kill] tag in your first last breath event, then the unit does no longer exist, and the second last breath will never fire.

https://wiki.wesnoth.org/Eventwml#last_breath

https://wiki.wesnoth.org/Eventwml#die
I read that exact link, but I didn't think the wording was decisive, which is why I posted the question. Yet now that I think about it again, it can only be this way. Mentally I think of the event as tied to the unit, but structurally that's incorrect. Only the filter ties it to the unit, and the filter will fail after [kill]. I need to restructure.
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: last breath

Post by dabber »

I want to upgrade the damage and hitpoints of every enemy unit. I did this on recruit successfully, but I cannot make creating a unit directly do it. What am I missing?
I tried doing it with an object, basically replacing [advancement] below with [object] and a location filter, but that didn't work either.

Code: Select all

#define GENERIC_UNIT_HARDER_WORKER SIDE TYPE X Y HPS DMG
    # Creates a generic unit of TYPE belonging to SIDE at X,Y, which has a
    # random name, gender and traits (just like a recruited unit).
    [unit]
        side={SIDE}
        type={TYPE}
        x={X}
        y={Y}
        generate_name=yes
        random_traits=yes
        random_gender=yes
        upkeep=full
        [modify_unit]
            [advancement]
                [effect]
                    apply_to=hitpoints
                    increase_total={HPS}
                    increase={HPS}
                [/effect]
                [effect]
                    apply_to=attack
                    increase_damage={DMG}
                [/effect]
            [/advancement]
        [/modify_unit]
    [/unit]
#enddef

#define GENERIC_UNIT_HARDER SIDE TYPE X Y
#ifdef HARD
    {GENERIC_UNIT_HARDER_WORKER {SIDE} {TYPE} {X} {Y} 50 100}
#else
    {GENERIC_UNIT {TYPE} {X} {Y}}
#endif
#enddef
User avatar
WhiteWolf
Forum Moderator
Posts: 637
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: dabber's questions: last breath

Post by WhiteWolf »

dabber wrote:
September 15th, 2020, 6:34 pm
I want to upgrade the damage and hitpoints of every enemy unit. I did this on recruit successfully, but I cannot make creating a unit directly do it.
I'm pretty sure that the direct action [modify_unit] cannot be placed inside [unit] just like that. Same goes for objects. Also, if you want to modify the hitpoints and attacks of a unit right at the creation, then the advancement tag is not the correct way - that only adds a new advancement to the unit which can be selected from the available options, when the unit advances.
The way I'd do it:

Code: Select all

#define STRENGTHEN_ENEMIES FILTER HP DMG
[object]
	[filter]
		{FILTER}
	[/filter]
	[effect]
		apply_to=hitpoints
		increase_total={HP}
		heal_full=yes
	[/effect]
	[effect]
		apply_to=attack
		increase_damage={DMG}
	[/effect]
[/object]
#enddef
And then your unit macro would be:

Code: Select all

#define GENERIC_UNIT_HARDER SIDE TYPE X Y
    {GENERIC_UNIT {SIDE} {TYPE} {X} {Y}}
#ifdef HARD
    {STRENGTHEN_ENEMIES x,y={X},{Y} 50 100}
#endif
#enddef
Keep in mind though that this will only work in a context where [object] is recognized, for example I'm not sure how it would behave if you put it directly into a [side] tag and that sort of thing.
Author of the Underness Series, consisting of 5 parts: The Desolation of Karlag, The Blind Sentinel, The Stone of the North, The Invasion Of The Western Cavalry, Fingerbone of Destiny
Standalone works: The Ravagers - now for 1.14, with new bugs!
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: last breath

Post by dabber »

WhiteWolf wrote:
September 15th, 2020, 7:16 pm
I'm pretty sure that the direct action [modify_unit] cannot be placed inside [unit] just like that.
That showed me my error. I meant to write [modifications] and instead I wrote [modify_unit]

Version that seems to do what I want below.
Now I have to mess with another part - getting the percentage increase out of a variable.

Code: Select all

#define GENERIC_UNIT_HARDER_WORKER SIDE TYPE X Y HPS DMG
    # Creates a generic unit of TYPE belonging to SIDE at X,Y, which has a
    # random name, gender and traits (just like a recruited unit).
    [unit]
        side={SIDE}
        type={TYPE}
        x={X}
        y={Y}
        generate_name=yes
        random_traits=yes
        random_gender=yes
        upkeep=full
        [modifications]
            [object]
                silent=yes
                [filter]
                    x,y={X},{Y}
                [/filter]
                [effect]
                    apply_to=hitpoints
                    increase_total={HPS}
                    increase={HPS}
                [/effect]
                [effect]
                    apply_to=attack
                    increase_damage={DMG}
                [/effect]
            [/object]
        [/modifications]
    [/unit]
#enddef
Pilauli
Posts: 40
Joined: August 18th, 2020, 12:56 pm

Re: dabber's questions: object on unit

Post by Pilauli »

The "Slow" trait might be a useful reference.

Code: Select all

#define TRAIT_SLOW
    # Units with trait Slow have -1 movement and 5% more hitpoints.
    [trait]
        id=slow
        male_name= _ "slow"
        female_name= _ "female^slow"
        help_text= _ "<italic>text='Slow'</italic> units have 1 less movement point but 5% more hitpoints." + _ "

Thick-bodied and clumsy, slow individuals of goblins and other species take a movement penalty but are compensated for it with a slight increase in endurance."
        [effect]
            apply_to=movement
            increase=-1
        [/effect]
        [effect]
            apply_to=hitpoints
            increase_total=5%
        [/effect]
    [/trait]
#enddef
It looks like just a percent sign after the number. The wiki indicates that the same thing works for damage increases:
https://wiki.wesnoth.org/EffectWML wrote: increase_damage: increases the attack's damage. This can be positive or negative, so you can use it to decrease damage as well. If it ends in a percent('%'), the change in damage will be a percentage ratio of the attack's original damage.
dabber
Posts: 395
Joined: April 2nd, 2014, 6:41 pm

Re: dabber's questions: object on unit

Post by dabber »

I had a really bad couple of days with reading my own code. Percentage increase wasn't working because I put the letter "n" in the variable name when I meant "h", and couldn't seem to see that I mistyped it.
Post Reply