How to consume attack?

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.
Post Reply
Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

How to consume attack?

Post by Enderlook » January 23rd, 2018, 2:56 pm

I'm making an ability to heal units, this "healer" must to be adjacent to the wound target, open right click and chose "Heal Unit" from the menu. Then it will display a little menu where you have to choose which healer will heal the target (this happen because a wound unit could have several healer adjacent). After click the healer the unit get heal and the choosen healer loose its attack for this turn. My problem is: How can I do the last part?

This is the healer function:

Code: Select all

#define HEALER_WORK number
	[heal_unit]
		amount=$healers[{number}].abilities.dummyhealer.value
		animate=yes
	[/heal_unit]
#enddef
And this is the list of "healers" that are adjacent to the wounded unit:

Code: Select all

[store_unit]
							[filter]
								side=$side_number
								ability=healer
								[filter_adjacent]
									x,y=$x1,$y1
								[/filter_adjacent]
							[/filter]
							variable=healers
						[/store_unit]
Am I having third main problems here.
1) How to get the coordinates of the healer. $healers[{number}].x and $healers[{number}].y?
2) How to modify the unit in order to consume its attack? I found that heal can restore attacks, but it doesn't work with negative numbers...
3) How can I check if the healer unit has its attacks? I don't want the healer be able to heal even if he already use it attack.

User avatar
beetlenaut
Developer
Posts: 2205
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: How to consume attack?

Post by beetlenaut » January 23rd, 2018, 3:13 pm

There is a unit variable called "attacks_left". You can check it or modify it.
http://wiki.wesnoth.org/SingleUnitWML
Campaigns: Dead Water
The Founding of Borstep
Secrets of the Ancients

User avatar
WhiteWolf
Forum Regular
Posts: 370
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to consume attack?

Post by WhiteWolf » January 23rd, 2018, 3:16 pm

Enderlook wrote:After click the healer the unit get heal and the choosen healer loose its attack for this turn. My problem is: How can I do the last part?
Each unit has an attacks_left attribute, set it to 0:

Code: Select all

[modify_unit]
    [filter]
        # the healer
    [/filter]
   attacks_left=0
[/modify_unit]
To solve the rest of your issues, I recommend a bit of change in the approach:
[set_menu_item] has a [filter] tag. When applied, the menu item is only shown if there is a unit matching the filter where the cursor is. This filter could be to have a healer there, AND that he still has his attack (inside an [and] in the filter, unit.attacks_left must be greater than 0). Then 1) is solved: the healer is the unit with x,y=$x1,$y1.
Then you'd need to store the units adjacent to $x1,$y1 (with 1 radius), and the player selects which wounded unit to heal. When done, use the code above to set the healer's attacks to zero. (so that he won't pass the filter another time in this turn, and can't heal again until next turn).

Checking whether a unit can still attack or not is only possible when an enemy unit is standing next to it I guess... but if you stick with this solution, it's trivial: if the menu item is present, he can still attack, if not, then the unit already used its attack, or has already healed.
For development and testing, these values can be checked manually in the inspection window, using :debug, then :inspect commands.
Author of the Underness Series, consisting of V 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 published!

User avatar
beetlenaut
Developer
Posts: 2205
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: How to consume attack?

Post by beetlenaut » January 23rd, 2018, 3:23 pm

WhiteWolf wrote:Checking whether a unit can still attack or not is only possible when an enemy unit is standing next to it I guess.
No, the orb turns red if you set attacks_left to 0.
Campaigns: Dead Water
The Founding of Borstep
Secrets of the Ancients

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to consume attack?

Post by Enderlook » January 23rd, 2018, 3:33 pm

WhiteWolf wrote:
Enderlook wrote:After click the healer the unit get heal and the choosen healer loose its attack for this turn. My problem is: How can I do the last part?
Each unit has an attacks_left attribute, set it to 0:

Code: Select all

[modify_unit]
    [filter]
        # the healer
    [/filter]
   attacks_left=0
[/modify_unit]
To solve the rest of your issues, I recommend a bit of change in the approach:
[set_menu_item] has a [filter] tag. When applied, the menu item is only shown if there is a unit matching the filter where the cursor is. This filter could be to have a healer there, AND that he still has his attack (inside an [and] in the filter, unit.attacks_left must be greater than 0). Then 1) is solved: the healer is the unit with x,y=$x1,$y1.
Then you'd need to store the units adjacent to $x1,$y1 (with 1 radius), and the player selects which wounded unit to heal. When done, use the code above to set the healer's attacks to zero. (so that he won't pass the filter another time in this turn, and can't heal again until next turn).

Checking whether a unit can still attack or not is only possible when an enemy unit is standing next to it I guess... but if you stick with this solution, it's trivial: if the menu item is present, he can still attack, if not, then the unit already used its attack, or has already healed.
For development and testing, these values can be checked manually in the inspection window, using :debug, then :inspect commands.
I'm sorry, but I didn't understand why you want to reverse my code. Actually, I do right click in the wounded target and then select the medic. But you want to right click in the healer and then select the wounded. I also though about that option, but isn't there the same problem? Instead of not know the location of the healer I won't know the location of the wounded target (actually it's x1, y1, but you want to use that variables to store the healer).
beetlenaut wrote:There is a unit variable called "attacks_left". You can check it or modify it.
http://wiki.wesnoth.org/SingleUnitWML
Thanks!

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to consume attack?

Post by Enderlook » January 23rd, 2018, 3:48 pm

1) Impresive! Seems that "x,y=$healers[{number}].x,$healers[{number}].y" actually works!
2)

Code: Select all

	[modify_unit]
		[filter]
			x,y=$healers[{number}].x,$healers[{number}].y
		[/filter]
		attacks_left=0
	[/modify_unit]

User avatar
beetlenaut
Developer
Posts: 2205
Joined: December 8th, 2007, 3:21 am
Location: Washington State
Contact:

Re: How to consume attack?

Post by beetlenaut » January 23rd, 2018, 3:50 pm

I think it makes more sense to click on the healer first since it's the one doing the action.
Campaigns: Dead Water
The Founding of Borstep
Secrets of the Ancients

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to consume attack?

Post by Enderlook » January 23rd, 2018, 3:52 pm

Ok. I'll take that in consideration. Thanks for your opinion, but the opinion of my brother is stronger... and he isn't agree :D .

User avatar
WhiteWolf
Forum Regular
Posts: 370
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to consume attack?

Post by WhiteWolf » January 23rd, 2018, 3:55 pm

beetlenaut wrote:No, the orb turns red if you set attacks_left to 0.
Doesn't that depend on settings? Also, it stays green in 1.12.
Enderlook wrote: I'm sorry, but I didn't understand why you want to reverse my code. Actually, I do right click in the wounded target and then select the medic. But you want to right click in the healer and then select the wounded. I also though about that option, but isn't there the same problem? Instead of not know the location of the healer I won't know the location of the wounded target (actually it's x1, y1, but you want to use that variables to store the healer).
I misunderstood :) Stick with your code: the coordinates of a healer are indeed $healers[number].x and y. The fun part is of course to determine the number, since its range changes, depending on how many healers are nearby. There could be more ways to this, here's what I'd do, but there's probably easier ways.
Spoiler:
Author of the Underness Series, consisting of V 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 published!

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to consume attack?

Post by Enderlook » January 23rd, 2018, 4:01 pm

WhiteWolf wrote:
beetlenaut wrote:No, the orb turns red if you set attacks_left to 0.
Doesn't that depend on settings? Also, it stays green in 1.12.
I use 1.12.6, when a unit attack, the orb turns black.


I use something similar to your second code and it's work:
WhiteWolf wrote: Another way would be to have a [message] with six options, each option containing a [show_if] regarding:

Code: Select all

# say this is the 3rd option:
[show_if]
    [have_unit]
        ability=healer
        x,y=$healers[3].x,$healers[3].y
   [/have_unit]
[/show_if]
But I'm not quite sure about this one. If there aren't 3 healers, this means you are indexing out of the healers array. It's supposed to be something zero-like, I think, so have_unit should yield false, and it should work, but I'm not 100% sure.[/spoiler]
I use this code [option] six times, from 0 to 6. And it works even if there is only 1 adjacent, or 3, or etc.

Code: Select all

[option]
								message={HEALER_PRINT 0}
								[show_if]
									[variable]
										name=healers[0].hitpoints
										greater_than=0
									[/variable]
									[and]
										[variable]
											name=healers[0].attacks_left
											greater_than=0
										[/variable]
									[/and]
								[/show_if]
								[command]
									{HEALER_WORK 0}
								[/command]
							[/option]

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to consume attack?

Post by Enderlook » January 23rd, 2018, 4:02 pm

I notice now that I have two little graphical bugs:

Code: Select all

#define HEALER_WORK number
	[heal_unit]
		amount=$healers[{number}].abilities.dummyhealer.value
		animate=yes
	[/heal_unit]
	[modify_unit]
		[filter]
			x,y=$healers[{number}].x,$healers[{number}].y
		[/filter]
		attacks_left=0
	[/modify_unit]
#enddef
That heal the target and consume the attack of the unit. But it doesn't turn the orb into black. What can I do?

Also, when I use [message] it always appear the portrait of the king, not the portrait of the unit in that hex.

User avatar
WhiteWolf
Forum Regular
Posts: 370
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to consume attack?

Post by WhiteWolf » January 23rd, 2018, 4:20 pm

Because in 1.12, orb only turns black when moves=0. Of course, when a unit attacks, its moves also become 0 :) But, when you modify attacks_left to 0 by hand, moves don't become 0, so orb doesn't turn black.

Who is the speaker in the [message]? Can you please attach that code? :)
Author of the Underness Series, consisting of V 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 published!

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to consume attack?

Post by Enderlook » January 23rd, 2018, 4:42 pm

WhiteWolf wrote:Because in 1.12, orb only turns black when moves=0. Of course, when a unit attacks, its moves also become 0 :) But, when you modify attacks_left to 0 by hand, moves don't become 0, so orb doesn't turn black.

Who is the speaker in the [message]? Can you please attach that code? :)
Ok, I will reduce its moves also.

Code: Select all

[message]
							message= _ "Which unit will you use to heal me?"							
							[option]
								message= _ "None"
							[/option]
[message]
That is fine or I have to post a bigger chunk of code? I know that x1, y1 is the wound unit (the unit I want to speak). Also I store that unit as "target", but I never used that stored unit...

User avatar
WhiteWolf
Forum Regular
Posts: 370
Joined: September 22nd, 2009, 7:48 pm
Location: Hungary

Re: How to consume attack?

Post by WhiteWolf » January 23rd, 2018, 4:53 pm

Add speaker=unit to the [message] :)
Author of the Underness Series, consisting of V 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 published!

Enderlook
Posts: 38
Joined: January 22nd, 2018, 12:23 am

Re: How to consume attack?

Post by Enderlook » January 23rd, 2018, 5:52 pm

Thanks!

Post Reply