Changing unit type of a Leader?

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.
quantumfleet
Posts: 38
Joined: June 17th, 2011, 1:26 am

Changing unit type of a Leader?

Post by quantumfleet »

Specifically, I want to create an event that changes the leader of a side from one unit to another; ie Elvish Captain -> Elvish Marksman. Is it possible to do this to a canrecruit=yes unit without ending the level prematurely and keeping the unit's name?

EDIT: check page 2
Last edited by quantumfleet on August 22nd, 2011, 10:51 pm, edited 1 time in total.
Currently working on various ideas using 1.9.8.9
monochromatic
Posts: 1549
Joined: June 18th, 2009, 1:45 am

Re: Changing unit type of a Leader?

Post by monochromatic »

1.8 -
{MODIFY_UNIT (id=MyName) type (Elvish Marksman)}

1.9 -
[modify_unit]
[filter]
id=MyName
[/filter]
type=Elvish Marksman
[/modify_unit]

This is just one way. You could use ADVANCE_UNIT or TRANSFORM_UNIT as well.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Changing unit type of a Leader?

Post by zookeeper »

monochromatic wrote:1.8 -
{MODIFY_UNIT (id=MyName) type (Elvish Marksman)}
No no no no. It don't work.
monochromatic wrote:1.9 -
[modify_unit]
[filter]
id=MyName
[/filter]
type=Elvish Marksman
[/modify_unit]
I don't know if that works or not, but I wouldn't count on it.
monochromatic wrote:This is just one way. You could use ADVANCE_UNIT or TRANSFORM_UNIT as well.
Yes, those are the proper ways to do it.
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Changing unit type of a Leader?

Post by Anonymissimus »

zookeeper wrote:
monochromatic wrote:1.9 -
[modify_unit]
[filter]
id=MyName
[/filter]
type=Elvish Marksman
[/modify_unit]
I don't know if that works or not, but I wouldn't count on it.
It does and is the default way (as opposed to ADVANCE_UNIT and TRANSFORM_UNIT).
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
monochromatic
Posts: 1549
Joined: June 18th, 2009, 1:45 am

Re: Changing unit type of a Leader?

Post by monochromatic »

zookeeper wrote:
monochromatic wrote:1.8 -
{MODIFY_UNIT (id=MyName) type (Elvish Marksman)}
No no no no. It don't work.
Darn! I haven't worked with 1.8 WML for so long. :?
quantumfleet
Posts: 38
Joined: June 17th, 2011, 1:26 am

Re: Changing unit type of a Leader?

Post by quantumfleet »

Thanks for the replies. I still have one question: how would I apply this to the leader in a MP scenario? I'm not sure what the id is stored as. Basically, what I'm trying to do is allow each player the opportunity to change their leader's unit type after certain conditions are met, but I'm not sure on how to do this.

And as an aside, I've been debugging what I've coded so far, and for some reason the "side_for" key inside [message] tags don't seem to work. I code in "side_for=2" and load it in a local game, but the message always displays for side 1, with side 1's leader portrait included when an option is granted (using [option tags). Am I using the key wrong?
Currently working on various ideas using 1.9.8.9
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Changing unit type of a Leader?

Post by Anonymissimus »

quantumfleet wrote:And as an aside, I've been debugging what I've coded so far, and for some reason the "side_for" key inside [message] tags don't seem to work. I code in "side_for=2" and load it in a local game, but the message always displays for side 1, with side 1's leader portrait included when an option is granted (using [option tags). Am I using the key wrong?
Yes. The engine synchronization architecture works by only allowing the currently active side to act. Thus messages with options or text input are only shown to that side, ignoring side_for=. Note that if you had looked after your stderr you would have seen a message about this.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Changing unit type of a Leader?

Post by zookeeper »

side_for= only has any real effect in networked multiplayer: it doesn't really display the message for side 2, it displays it for the client which controls side 2. If you use side_for=2 and play a hotseat game, then it always displays the message regardless of who's turn it is, because the same client controls all the sides including side 2.
quantumfleet
Posts: 38
Joined: June 17th, 2011, 1:26 am

Re: Changing unit type of a Leader?

Post by quantumfleet »

Anonymissimus wrote:
quantumfleet wrote:And as an aside, I've been debugging what I've coded so far, and for some reason the "side_for" key inside [message] tags don't seem to work. I code in "side_for=2" and load it in a local game, but the message always displays for side 1, with side 1's leader portrait included when an option is granted (using [option tags). Am I using the key wrong?
Yes. The engine synchronization architecture works by only allowing the currently active side to act. Thus messages with options or text input are only shown to that side, ignoring side_for=. Note that if you had looked after your stderr you would have seen a message about this.
Interesting.

If an event is coded like this:

Code: Select all

[event]
name=side 2 turn 1
{. . . }
[/event]
Then is player 1 technically the active player?
And equally importantly, in a multiplayer match, what is the ID of each side's leader?
Currently working on various ideas using 1.9.8.9
Anonymissimus
Inactive Developer
Posts: 2461
Joined: August 15th, 2008, 8:46 pm
Location: Germany

Re: Changing unit type of a Leader?

Post by Anonymissimus »

quantumfleet wrote: If an event is coded like this:

Code: Select all

[event]
name=side 2 turn 1
{. . . }
[/event]
Then is player 1 technically the active player?
No. At the point this event fires, side=2 has just become the active one. If you display in this event a message with input and side_for=1 it will display to only side=2 instead (IIRC).
The active side is always the side $side_number.
projects (BfW 1.12):
A Simple Campaign: campaign draft for wml startersPlan Your Advancements: mp mod
The Earth's Gut: sp campaignSettlers of Wesnoth: mp scenarioWesnoth Lua Pack: lua tags and utils
updated to 1.8 and handed over: A Gryphon's Tale: sp campaign
quantumfleet
Posts: 38
Joined: June 17th, 2011, 1:26 am

Re: Changing unit type of a Leader?

Post by quantumfleet »

At this point, I would like to ask again: How can I change the unit type of the leader unit in a multiplayer scenario? What is the id of the leader unit stored as?
Currently working on various ideas using 1.9.8.9
User avatar
Alarantalara
Art Contributor
Posts: 789
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Changing unit type of a Leader?

Post by Alarantalara »

You don't actually need an id for the filter.
The following will match a leader for a side perfectly well for all of the tags and macros mentioned. Just use it in place of id.

Code: Select all

side=(desired side)
canrecruit=yes
If you really want the id, then you can use the above in store_unit and retrieve the id from there, but it adds an extra step.
quantumfleet
Posts: 38
Joined: June 17th, 2011, 1:26 am

Re: Changing unit type of a Leader?

Post by quantumfleet »

Thank you!

EDIT:
Using the {ADVANCE_UNIT} macro doesn't appear to change the moves of a unit -- EG Wraith -> Bone Shooter results in a unit with 7 moves left out of five. I had planned to fix this with the following code:

Code: Select all

{ADVANCE_UNIT side=1,canrecruit=yes "Bone Shooter"}
[store_unit]
			kill=no
				[filter]
					side=1
					canrecruit=yes
				[/filter]
			[/store_unit]
			[set_variable]
				name=moves
				value=5
			[/set_variable]
			[unstore_unit]
				[filter]
					side=1
					canrecruit=yes
				[/filter]
			[/unstore_unit]
But the game's saying it "found invalid closing tag event for tag store_unit". Help???
Currently working on various ideas using 1.9.8.9
User avatar
Alarantalara
Art Contributor
Posts: 789
Joined: April 23rd, 2010, 8:17 pm
Location: Canada

Re: Changing unit type of a Leader?

Post by Alarantalara »

If you're using 1.9, you can do it all in one tag:

Code: Select all

[modify_unit]
    [filter]
       side=1
      canrecruit=yes
    [/filter]
    type=Bone Shooter
    moves=5
[/modify_unit]
If you're using 1.8, then what you have can work, but you're missing the variable key in store_unit and unstore_unit.
You may find is simpler to use the MODIFY_UNIT macro instead. You'll also need to correct the variable name in your set_variable tag.
quantumfleet
Posts: 38
Joined: June 17th, 2011, 1:26 am

Re: Changing unit type of a Leader?

Post by quantumfleet »

Thanks for mentioning that macro, it worked like a charm.

On an unrelated note, I just found out that I added a second [store_unit] tag near the top of the document by mistake. :doh:
Last edited by quantumfleet on August 22nd, 2011, 1:01 am, edited 1 time in total.
Currently working on various ideas using 1.9.8.9
Post Reply