1st Scenario, Leader Selection and general questions

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
JustNatan
Posts: 36
Joined: September 17th, 2020, 6:07 pm

1st Scenario, Leader Selection and general questions

Post by JustNatan »

Hey,
I am currently writing my first campaign from scratch. I have tinkered around with existing ones before (a little) and now I feel like I should start writing my own. I wanna create a campaign close to TDE (The Dark Eye).

One thing which is really important for me is a free selection of your starting character. I have seen similar stuff in the "A_Magicians_Tale" campaign, where you could pick companions, but I do not really understand how it's done there.

What I have is 9 class types standing on a map. I would like to have everyone say something and then a selection. Atm the game is automatically over, because you've been defeated instantly. Also I have to create a leader (I think so) even though I don't want one.

I have no idea how I can set the leader dynamically for the following scenarios, but I think it should be possible using a global variable. I am not that used to wml yet, but I am studying IT so general programming skills are there.

I also failed to find a guide explaining:
{NAMED_UNIT 2 "Dune Apothecary" 2 2 (Saajd) ("Saajd ibn Jahlif") ()} those phrases in curly brackets. I mean I can understand all of them, but I would like to know the official syntax and how many of them exist. They look very useful to safe space.

In A_magicians_tale/scenarios/01_The_Yellow_Wolf_Tavern.cfg there are things like:
{01_THE_YELLOW_WOLF_TAVERN_INTRODUCTION}
So I think that this is something like a method call or a macro, but it doesn't have a macro folder. How does the code compiling work here?

Last but not least: I know that there are a couple of syntax highlighter. I installed the WML extension in VS Code (linux), but it doesn't activate for cfg files automatically. How can I activate it manually? (maybe someone has the same issue and fixed it)

Thank you very much! I know that these questions are very inconsistent, but I think that some of my misunderstandings are interlinked with other misunderstandings :)

Natan
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: 1st Scenario, Leader Selection and general questions

Post by Pentarctagon »

Moved to the WML Workshop, since the questions are really more related to WML than the contents of the actual campaign.

To answer some of your questions though, see here for more detailed information, but just generally something like {NAMED_UNIT ... } means there's a macro definition somewhere that looks like:

Code: Select all

#define NAMED_UNIT ARG1 ARG2 ...
...macro code goes here...
#enddef
Putting these macro definitions in a "macros" or "utils" folder is the norm, but they can technically be put in any folder/file.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
lhybrideur
Posts: 369
Joined: July 9th, 2019, 1:46 pm

Re: 1st Scenario, Leader Selection and general questions

Post by lhybrideur »

Concerning leader selection, you can have a team for scenario one with a peasant leader that will speak to team 2 units from which you will choose your leader for the campaign. Define then the selected unit as the leader of team 2 and continue the campaign as team 2.
This should work AFAIR because leaders define teams.
JustNatan
Posts: 36
Joined: September 17th, 2020, 6:07 pm

Re: 1st Scenario, Leader Selection and general questions

Post by JustNatan »

Thank you both!

@Ilhybrideur
I'm not really sure what you mean.
I am very new to WML so I have a few questions:
1. The choosing would be via [option] right?
1.2 I thought about spawning every unit in a throne room and the player can move the chosen unit to a "pedestal" and thereby it get's selected. But I failed to find a way how I can read the unit type in connection with moveto.
2. Why shouldn't I just advance my unit? using something like

Code: Select all

[modify_unit]
            [filter]
            	id=hero1
            [/filter]
            type=Elvish Marksman #the fitting type
[/modify_unit]
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: 1st Scenario, Leader Selection and general questions

Post by Pilauli »

To change your unit's type, I believe you'll want to use [transform_unit]. I don't see any reason that wouldn't work. You could probably create a generic unit for a leader and then have them wonder aloud about which of their heroes they should emulate.

(I don't see any reason why the hero shouldn't technically be the leader. S/he would have the crown icon over the health bar, but if you don't put anything on the recruit list, then s/he won't be able to recruit anything.)

---

Moveto automatically stores the unit, including a bunch of facts about them, so that you can do something like this (untested code, might have syntax error):

Code: Select all

[event]
	name=moveto
	[filter]
		x,y=5,8
	[/filter]
	[transform_unit]
		id=Hero
		transform_to=$unit.type
	[/transform_unit]
	[kill]
		[not]
			id=Hero
		[/not]
	[/kill]
	[endlevel]
		result=victory
	[/endlevel]
[/event]
$unit.type represents the type of the unit that moved onto (5, 8), and then the kill should clean up all the units that aren't the hero.

---

I would suggest looking at the tutorial, because that lets you choose (via [option, I think) whether to play as Konrad or Li'sar.

---

Macros: they represent code which is put into the scenario in place of the macro. The mainline ones are defined in data/core/macros; most UMC (I think) uses a utils folder instead of a macros folder. Inside your "ifdef CAMPAIGN_WHATEVER" piece in the _main.cfg file, you put a line something like this:
{~add-ons/Sample_Campaign/utils}
And that will make sure that Wesnoth can find them.
The NAMED_UNIT macro is found inside the mainline macros folder, in the unit-utils.cfg file.
User avatar
octalot
General Code Maintainer
Posts: 786
Joined: July 17th, 2010, 7:40 pm
Location: Austria

Re: 1st Scenario, Leader Selection and general questions

Post by octalot »

A player is automatically defeated if they have no units with [unit]canrecruit=yes. However, a single side can have multiple units with canrecruit=yes. I haven't tested, but I think the concept of 9 starting heroes would work if you:
  • Put them all on the same side
  • Give all of them canrecruit=yes
  • Set [side]save_id to a value instead of just taking the default (otherwise it would default to id of the first canrecruit=yes unit on that side)
  • In the next scenarios, set [side]save_id to the same value
  • Ensure that the selected leader gets recalled automatically at the start of the scenario. To prevent automatic defeat the player needs a unit with canrecruit=yes on the map, not just on their recall list. At the start of each scenario, all of the player's units are on the recall list.
The tutorial uses "save_id=human_player". However, the tutorial's character select uses a dedicated dialog box written in Lua language, so you'd need to handle both of Wesnoth's scripting languages to use it. It's in data/campaigns/tutorial/lua/character_selection.lua.

The tutorial handles the necessary start-of-scenario recall by having [unit]id=student, regardless of whether that unit is Konrad or Li'sar.
Note that you can't use [recall] to handle the necessary start-of-scenario recall, because the [recall] tag will want to check that you already have a leader who can do the recalling. I guess this would work, but haven't tested (and now that I've written it, I think the tutorial's method of having a set id for the leader is better.

Code: Select all

[event]
    name=prestart
    [store_unit]
        [filter]
            side=1
            canrecruit=yes
        [/filter]
        kill=yes
        variable=leader
    [/store_unit]
    [unstore_unit]
        variable=leader
        location_id=1
    [/unstore_unit]
    {CLEAR_VARIABLE leader}
[/event]
JustNatan
Posts: 36
Joined: September 17th, 2020, 6:07 pm

Re: 1st Scenario, Leader Selection and general questions

Post by JustNatan »

I found the "https://wiki.wesnoth.org/WML_for_Complete_Beginners" which is really helpful and now I understand a lot more. Before that I tried to understand wml by reading direct documentation and "https://wiki.wesnoth.org/ScenarioWML" which was really hard.

@Pilauli
Cheers! Why didn't I think about the tutorial before ^^
I actually finished the first selection map already. I created a room with different classes and as soon as you reach the middle you get an option dialog and you can choose the class. I then advance the current hero to the selected type. It seems to work very nicely.

> Is there also a way how I can allow the user to change the leader's name?

@octalot
canrecruit was my issue.

Currently I solved my selection problem like this (I shortened the code by just keeping comments and general structure):

Code: Select all

[scenario]
    
    id=dsa_sel0
    name= _ "The hero"
    map_data="{~add-ons/Dsa_chalice/maps/dsa_selection.map}"   
    next_scenario=dsa_intro
    turns=24
    victory_when_enemies_defeated=no
    [side]
		side=1
		team_name=Heroes
		user_team_name=_ "Heroes"
		controller=human
		{GOLD 0 0 0}
		
		#Create a dummy unit
		type=Mage
		id=hero1
		name="Ulerion Beleren"
		unrenamable=no
		canrecruit=yes
		x,y=8,13
    [/side]
    [side]
        side=2
        controller=null
    [/side]

     [event]
	name=start
	#Create some side 2 controlled units so people can take a look at it.
	#Dune
        #Dwarf
        #Elvish
        #mixed units
    [/event]
    [event]
    	moveto
        #a lot of [option] tags for every type filled with modify unit
        #END_SCENARIO
    [/event]
[/scenario]

Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: 1st Scenario, Leader Selection and general questions

Post by Pilauli »

[message] can include [option]. (At least, according to the page on [message]; the [option] page doesn't mention it.)
https://wiki.wesnoth.org/InterfaceActio ... message.5D
https://wiki.wesnoth.org/OptionWML

Try something like this:

Code: Select all

# Put this inside whichever event will contain the name-change.
[message]
    speaker=narrator
    message= _ "Choose a name for your character."
    [option]
        [entry]
            id=hero_name   # This one is required, but the others can probably be skipped.
            default="Average Joe"
            name="Name:"
            description="This is a text field.  Write in it!"
        [/entry]
    [/option]
[/message]
[modify_unit]
    [filter]
        id=placeholder # (replace with whatever your main character's id is)
    [/filter]
    name=$hero_name  # The text entry option stored the input to the variable hero_name, so now we get it back out by using $hero_name.
[/modify_unit]
EDIT: as Pentarctagon and Ravana have pointed out, this wouldn't actually work. I'm oblivious. :doh:
Last edited by Pilauli on September 19th, 2020, 7:55 pm, edited 1 time in total.
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: 1st Scenario, Leader Selection and general questions

Post by Pentarctagon »

That because, from the OptionWML page: "This tag might be a child of an [era], [multiplayer] or [modification] tag". So those are different options than you'd put in a [message].
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
Ravana
Forum Moderator
Posts: 3005
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: 1st Scenario, Leader Selection and general questions

Post by Ravana »

There are [option] and [options] tags which go to different places.
Pilauli
Posts: 115
Joined: August 18th, 2020, 12:56 pm

Re: 1st Scenario, Leader Selection and general questions

Post by Pilauli »

Arg, yes, it's subtly different. It really doesn't help that the [options] tag is on the page OptionWML, though.

Okay, here's the really simple solution which I should have remembered. Try, when you create the unit, writing "unrenamable=no", and then see if you can right-click on the unit and rename it. (If it works, then just add a line to clue the player in that they can do that.)
https://wiki.wesnoth.org/SingleUnitWML wrote: unrenamable: if 'yes', the user-visible name of the unit cannot be changed by the player (which is only possible when the unit is on the player's side anyway).
User avatar
GForce0
Posts: 63
Joined: May 17th, 2020, 5:58 pm

Re: 1st Scenario, Leader Selection and general questions

Post by GForce0 »

Pilauli wrote: September 18th, 2020, 3:31 pm ... Inside your "ifdef CAMPAIGN_WHATEVER" piece in the _main.cfg file, you put a line something like this:
{~add-ons/Sample_Campaign/utils}
...
Allow me please to interfere with a side-question :)
What is the purpose of putting it inside an ifdef?
User avatar
Ravana
Forum Moderator
Posts: 3005
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: 1st Scenario, Leader Selection and general questions

Post by Ravana »

To not slow down loading of other campaigns.
Post Reply