Recruited units gain object that adds a special to all their attacks

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
DopeKiwiWarrior
Posts: 30
Joined: January 27th, 2013, 4:04 pm
Location: Inside your mom, she ate me, send help before I dissolve.

Recruited units gain object that adds a special to all their attacks

Post by DopeKiwiWarrior »

Basically I have created an 'attackspeed' leadership aura called fervor. The unit who has it adds 33% to number of attacks of units around. It works around a dummy ability and a weapon special that checks for it. This part works.

However, I need every unit recruited in the game to be affectable by this ability. I found out I should do it through an object in a recruit event (and in prestart for leaders) but I couldn't figure it out so I have two questions:
  1. How to create an object that adds a weapon special to all of its bearer's attacks?
  2. How to give this object to every leader and every new recruited unit?
Creator of Moonday Era, go check it out! (And critique the hell out of it, because it needs it.)
User avatar
beetlenaut
Developer
Posts: 2825
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: Recruited units gain object that adds a special to all their attacks

Post by beetlenaut »

1. There is a [set_specials] tag in [effect] that does that.
2. For 1.12, You need to use two events. One event has name=recruit,recall and gives the object to $unit. It needs to go into every scenario, so make it a macro that you can include. It will take care of all recruited units and leaders too, after the first scenario. In the first scenario, you also need a start event that gives the object to every unit on the map in order to give one to the leaders initially. (During prestart, I'm pretty sure the leaders can't be affected yet, so that may be part of your problem.)
2. For 1.13, you can just use an [event] with name=unit_placed, and it will take care of everything.
Campaigns: Dead Water,
The Founding of Borstep,
Secrets of the Ancients,
and WML Guide
User avatar
DopeKiwiWarrior
Posts: 30
Joined: January 27th, 2013, 4:04 pm
Location: Inside your mom, she ate me, send help before I dissolve.

Re: Recruited units gain object that adds a special to all their attacks

Post by DopeKiwiWarrior »

beetlenaut wrote: February 26th, 2018, 5:04 am 1. There is a [set_specials] tag in [effect] that does that.
2. For 1.12, You need to use two events. One event has name=recruit,recall and gives the object to $unit. It needs to go into every scenario, so make it a macro that you can include. It will take care of all recruited units and leaders too, after the first scenario. In the first scenario, you also need a start event that gives the object to every unit on the map in order to give one to the leaders initially. (During prestart, I'm pretty sure the leaders can't be affected yet, so that may be part of your problem.)
2. For 1.13, you can just use an [event] with name=unit_placed, and it will take care of everything.
First of all, thanks.
But
  1. I know about it, but doesn't it affect only the first attack it finds? I want it to apply to every attack of that unit.
  2. I might have been unclear - I know all the tools, I just need to structure it so the object gets given to the right unit and does what I want. I should have posted the code but right now I can't. I'll try the start event.
Creator of Moonday Era, go check it out! (And critique the hell out of it, because it needs it.)
User avatar
James_The_Invisible
Posts: 534
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces
Contact:

Re: Recruited units gain object that adds a special to all their attacks

Post by James_The_Invisible »

doesn't it affect only the first attack it finds? I want it to apply to every attack of that unit.
It should affect all matching attacks. If you want it to be applied to all attacks, you do not have to use any filter.
User avatar
DopeKiwiWarrior
Posts: 30
Joined: January 27th, 2013, 4:04 pm
Location: Inside your mom, she ate me, send help before I dissolve.

Re: Recruited units gain object that adds a special to all their attacks

Post by DopeKiwiWarrior »

James_The_Invisible wrote: February 26th, 2018, 9:46 am
doesn't it affect only the first attack it finds? I want it to apply to every attack of that unit.
It should affect all matching attacks. If you want it to be applied to all attacks, you do not have to use any filter.
Alright, thanks. Would you be able to help with my second point?
Creator of Moonday Era, go check it out! (And critique the hell out of it, because it needs it.)
User avatar
James_The_Invisible
Posts: 534
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces
Contact:

Re: Recruited units gain object that adds a special to all their attacks

Post by James_The_Invisible »

About code structure? Should look like this:

Code: Select all

[event]
    name=...
    [object]
        silent=yes # not needed on Wesnoth 1.13 if you do not use description (and name?) attribute
        [filter]
            # somehow specify unit the object should be applied to. only first matching unit is actually given the object
        [/filter]
        [effect]
            apply_to=attack
            [set_specials]
                mode=append # omit this line if you want to replace existing weapon specials
                {WEAPON_SPECIAL_X} # does not need to be a macro
            [/set_specials]
        [/effect]
    [/object]
[/event]
If the object should be applied to multiple units, you need to store them via [store_unit] to a variable and then iterate over it:

Code: Select all

[store_unit]
    [filter]
        # some filter
    [/filter]
    variable=x
[/store_unit]
{FOREACH x i}
    [object]
        [filter]
            id=$x[$i].id
        [/filter]
        ...
    [/object]
{NEXT i}
{CLEAR_VARIABLE x}
User avatar
DopeKiwiWarrior
Posts: 30
Joined: January 27th, 2013, 4:04 pm
Location: Inside your mom, she ate me, send help before I dissolve.

Re: Recruited units gain object that adds a special to all their attacks

Post by DopeKiwiWarrior »

Code: Select all

#define ABILITY_FERVOR
[dummy]
	id=fervor aura
	name= _ "fervor aura"
	description= _ "lol"
[/dummy]
#enddef
#define WEAPON_SPECIAL_LATENT_FERVOR
    [attacks]
    	[filter_self]
		[filter_adjacent]
            		ability=fervor aura
        	[/filter_adjacent]
	[/filter_self]
        id=latent fervor
        name= _ "fervor"
        name_inactive = "fervor"
        description= _ "This unit is affected by fervor, it attacks 33% more times."
        multiply=1.34
    [/attacks]
#enddef
#define FERVOR_GIVER
[event]
	name=recruit
	first_time_only=no
	[if]
		[not]
			[have_unit]
				id=$unit.id
				ability=fervor aura
			[/have_unit]
		[/not]
		[then]
			[modify_unit]
				[filter]
					id=$unit.id
				[/filter]
				[object]
					silent=no
					[effect]
						[attack]
							[set_specials]
								mode=append
								[specials]
									{WEAPON_SPECIAL_LATENT_FERVOR}
								[/specials]
							[/set_specials]
						[/attack]
					[/effect]
					description="[censored] object"
				[/object]
			[/modify_unit]
		[/then]
	[/if]		
[/event]
[event]
	name=start
	[store_unit]
		[filter]
			canrecruit=yes
		[/filter]
        variable=leaders
    	[/store_unit]
	{FOREACH leaders i}
		[if]
			[not]
				[have_unit]
					id=$leaders[$i].id
					ability=fervor aura
				[/have_unit]
			[/not]
		[then]
			[modify_unit]
				[filter]
					id=$leaders[$i].id
				[/filter]
				[object]
					silent=yes
					[effect]
						[attack]
							[set_specials]
								mode=append
								[specials]
									{WEAPON_SPECIAL_LATENT_FERVOR}
								[/specials]
							[/set_specials]
						[/attack]
					[/effect]
				[/object]
			[/modify_unit]
		[/then]
	[/if]
	{NEXT i}
	[clear_variable]
		name=leaders
	[/clear_variable]
[/event]
#enddef
This doesn't work in three ways:
  1. The object is only given to the leaders
  2. The ability works always and doesn't filter for adjacent units
  3. The weapon special isn't shown, either active or inactive, on units that obtained it through the object
Why is that?
Creator of Moonday Era, go check it out! (And critique the hell out of it, because it needs it.)
User avatar
James_The_Invisible
Posts: 534
Joined: October 28th, 2012, 1:58 pm
Location: Somewhere in the Northlands, fighting dark forces
Contact:

Re: Recruited units gain object that adds a special to all their attacks

Post by James_The_Invisible »

About the third issue, you have got the [effect] part wrongly. There should not be nested [attack] tag, you have to use apply_to=attack.
I have never used [object] inside [modify_unit] so I have no idea whether there is a problem. Did you try to insert the object without the [modify_unit] (that is just [object] with [filter])?
User avatar
DopeKiwiWarrior
Posts: 30
Joined: January 27th, 2013, 4:04 pm
Location: Inside your mom, she ate me, send help before I dissolve.

Re: Recruited units gain object that adds a special to all their attacks

Post by DopeKiwiWarrior »

James_The_Invisible wrote: February 26th, 2018, 7:40 pm About the third issue, you have got the [effect] part wrongly. There should not be nested [attack] tag, you have to use apply_to=attack.
I have never used [object] inside [modify_unit] so I have no idea whether there is a problem. Did you try to insert the object without the [modify_unit] (that is just [object] with [filter])?
I got it wrong in nesting a [specials] tag in there too. Also I got it wrong that it only gets given to leaders when in reality they were just that more powerful than the regular units. After removing the unnecessary specials tag, it works. Thanks for the help.
Creator of Moonday Era, go check it out! (And critique the hell out of it, because it needs it.)
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Recruited units gain object that adds a special to all their attacks

Post by Celtic_Minstrel »

You shouldn't really be using [object] inside [modify_unit] unless you want the modification to disappear when the unit levels up. (Which is a perfectly valid use case, mind you.)
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Post Reply