How to find the -real- max_hitpoints?

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
User avatar
Ken_Oh
Moderator Emeritus
Posts: 2176
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

How to find the -real- max_hitpoints?

Post by Ken_Oh » October 16th, 2007, 12:47 pm

I can't find a unit's real max hitpoints as a value. It's a variable that should be there, but isn't.

Here's what a Strong and Resilient Spearman looks like:

Code: Select all

[unit]
	hitpoints="42"
	id="Spearman"

	max_hitpoints="36"
But here is a Quick and Intelligent one:

Code: Select all

[unit]
	hitpoints="34"
	id="Spearman"

	max_hitpoints="36"
This causes some problems when you're trying to alter units, as Bob the Mighty has found out: http://www.wesnoth.org/forum/viewtopic.php?t=17638

I'm running into similar problems now that I'm trying to code healing abilities. The problem is, unlike Bob's scenario, I want my healing to be able to interact with canrecruit=0 units, with traits and potential AMLAs.

I don't know a whole lot about programming, but it just seems really odd to have a value that you can see on the screen yet you can't find in the code.

Anyone have any idea how to get around this? Is that variable hidden somewhere?

User avatar
zookeeper
WML Wizard
Posts: 9740
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Post by zookeeper » October 16th, 2007, 1:06 pm

Well...you could store the units hitpoints= on recruit, scenario start or whenever you know it's in full health.

Also, you could store the units hitpoints=, use an [object] to heal it to full, check/store the hitpoints= then, and revert them back to the original value.

But yes, I'd agree that it'd be best if these things were directly available in some key. Same applies for experience=, AFAIK.

User avatar
Ken_Oh
Moderator Emeritus
Posts: 2176
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Post by Ken_Oh » October 16th, 2007, 1:12 pm

Experience is indeed the same. At least I don't see a need to alter them too much.

I'll try your second suggestion really quick.

EDIT: That works perfectly. Thanks!

Honestly, I was afraid you were going to say that I should figure for all of the modifications myself with a bunch of FOREACH loops to find the true hitpoints. I'm really glad you had a better idea. ;)

Clonkinator
Posts: 676
Joined: July 20th, 2006, 4:45 pm
Location: Germany

Post by Clonkinator » October 16th, 2007, 6:50 pm

The same applies to the movement points, and counting the upgrades to the original value doesn't even work for me... :(

User avatar
shadowm
Site Administrator
Posts: 6545
Joined: November 14th, 2006, 5:54 pm
Location: Chile
Contact:

Post by shadowm » October 16th, 2007, 7:32 pm

Clonkinator wrote:The same applies to the movement points, and counting the upgrades to the original value doesn't even work for me... :(
It must if you do it correctly. The game doesn't cheat on WML saves.
Author of the unofficial UtBS sequels Invasion from the Unknown and After the Storm.

User avatar
Bob_The_Mighty
Posts: 783
Joined: July 13th, 2006, 1:15 pm

Post by Bob_The_Mighty » October 16th, 2007, 9:12 pm

Ken Oh, could you post an example of WML that you got to work?
My current projects:
2p Campaign: The Altaz Mariners
3p Survival: Save The Village

User avatar
Ken_Oh
Moderator Emeritus
Posts: 2176
Joined: February 6th, 2006, 4:03 am
Location: Baltimore, Maryland, USA

Post by Ken_Oh » October 16th, 2007, 9:44 pm

Code: Select all

#define COMMAND_RPG_HEALS

[set_menu_item]
	id=white_magic_heals
	description="Heal Unit"
	[filter_location]
		[filter]
			[not]
				side=$side_number
				canrecruit=1
			[/not]
			[wml_filter]
				[not]
					healed="1"
				[/not]
			[/wml_filter]
		[/filter]
	[/filter_location]
	[show_if]	
		[have_unit]
		side=$side_number
		canrecruit=1
			[wml_filter]
				[not]
					heals_left="0"
				[/not]
			[/wml_filter]
			[filter_location]
				radius=1
				x=$x1
				y=$y1	
			[/filter_location]
		[/have_unit]
	[/show_if]		
	[command]	
		[store_unit]
			variable=target
			[filter]
				[not]
					side=$side_number
					canrecruit=1	
				[/not]
				x=$x1
				y=$y1
			[/filter]
			kill=no
		[/store_unit]		
		[store_unit]
			variable=acting_unit
			[filter]
				side=$side_number
				canrecruit=1					
			[/filter]
		[/store_unit]		
		[object]
	     	silent=yes
	       	[filter]
	       		 x,y=$x1,$y1
			[/filter]
			[effect]
				 apply_to=hitpoints
				 heal_full=yes
			[/effect]
		[/object]		
		[store_unit]
			variable=target_fake
			[filter]
				[not]
					side=$side_number
					canrecruit=1	
				[/not]
				x=$x1
				y=$y1
			[/filter]
		[/store_unit]		
		{VARIABLE_OP acting_unit.heals_left add -1}
		{VARIABLE heal_display_init_hp $target.hitpoints}
		{VARIABLE_OP target.hitpoints add $acting_unit.heal_value}
		{VARIABLE heal_display_hp $acting_unit.heal_value}
		[if]
			[variable]
				name=target.hitpoints
				greater_than_equal_to=$target_fake.hitpoints
			[/variable]
			[then]
				{VARIABLE target.hitpoints $target_fake.hitpoints}
				{VARIABLE heal_display_hp $target.hitpoints}
				{VARIABLE_OP heal_display_hp add -$heal_display_init_hp}
			[/then]	
		[/if]			
		{VARIABLE target.healed 1}
		[sound]
			name=heal.wav
		[/sound]
		[unstore_unit]
			variable=target
			text=$heal_display_hp
			{COLOR_HEAL}
		[/unstore_unit]
		
		[unstore_unit]
			variable=acting_unit
		[/unstore_unit]
	[/command]
[/set_menu_item]
Sorry, I'd break it down better but I gotta go.

EDIT: I guess there isn't too much to break down. Feel free to ask questions if you need.

Post Reply