name_generator query

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
Spannerbag
Posts: 759
Joined: December 18th, 2016, 6:14 pm
Location: Yes

name_generator query

Post by Spannerbag »

First, apologies if I've posted in the wrong place; I'm assuming what I'd like to do is possible in WML. :)

Is it possible to create a WML wrapper around name_generator so that the output can be captured in a WML variable?

I'd like to rename a unit when it advances via an [event] within the [unit_type].
Ideally I'd like to:
  1. Save the old name (in say $unitname_old).
  2. Generate a new name ($unitname_new*).
  3. Rename the unit to:
    "$unitname_new" + " " + "$unitname_old" + "_" + "Rider".
* New name format would be a short (short_name={prefix}{suffix}}) Dwarvish name.

I'd rather not spawn a new unit purely for purposes of acquiring its name because this event fires when the unit advances and could possibly fire in one of several scenarios with different maps etc., so things get fiddly.

Alternatively can use lua if that's easier, but would prefer a WML solution.

All advice and suggestions gratefully received!

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.18, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
Ravana
Forum Moderator
Posts: 3313
Joined: January 29th, 2012, 12:49 am
Location: Estonia
Contact:

Re: name_generator query

Post by Ravana »

Easiest way would be to register new WML tag that does what you need with Lua.

Consider that old name might not be from generator.
User avatar
Spannerbag
Posts: 759
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: name_generator query

Post by Spannerbag »

Ravana wrote: March 14th, 2025, 5:32 pm Easiest way would be to register new WML tag that does what you need with Lua.
Mmm.. given my minimal lua ability this is drifting into "not worth the effort" territory...
Will play around with easier/simpler alternatives first and see how I get on.

Ravana wrote: March 14th, 2025, 5:32 pm Consider that old name might not be from generator.
Good point.

Thanks for your post, it clarified my options, thanks.

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.18, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
tsunami_
Posts: 16
Joined: June 22nd, 2024, 2:07 am
Location: Pacific

Re: name_generator query

Post by tsunami_ »

If your problem is not wanting to spawn units on top of other ones, you can spawn one directly into the recall list.
Here is a macro that does what you want, I think (this one is inside a move-to event).

Code: Select all

#define GAIN_A_NAME

    [label]
        x,y=5,5
	text="<span  color='#76AA2F' size='x-small' weight='normal'>" + _ "Rename unit here" + "</span>"
    [/label]

    [event]
	name=moveto
        [filter]
            side=1
            x,y=5,5
        [/filter]
	first_time_only=no

    	[unit]
            side=1
            type="Dwarvish Ulfserker"
            x=recall
            y=recall
            id=NamePatsy
    	    generate_name=yes
    	[/unit]

        [store_unit]
            [filter]
                id=NamePatsy
            [/filter]
            variable=stored_patsy
        [/store_unit]
        [set_variable]
            name=patsy_name
            value= $stored_patsy.name
    	[/set_variable]
        [unstore_unit]
            variable=stored_patsy
        [/unstore_unit]

    	[kill]
            id=NamePatsy
    	[/kill]

        [set_variable]
            name=old_name
            value= $unit.name
    	[/set_variable]
        [set_variable]
            name=new_name
            value=$patsy_name| + " " + $old_name| + "-Rider" # "|" necessary for separating variables, I think
    	[/set_variable]

	[modify_unit]
	    [filter]
	    	x,y = $x1, $y1
	    [/filter]
	    name=$new_name
	[/modify_unit]

    [/event]

#enddef
Did your unit get climbed on by a dwarf...?

As for generating a short_name specifically, you could make a custom unit and link it to an edited name generator.
Here is the DWARVISH_NAMES macro with long_name, centre and markov section removed:

Code: Select all

#define SHORT_DWARVISH_NAMES
    # po: Generator for male dwarf names; see <https://wiki.wesnoth.org/Context-free_grammar> for syntax
    name_generator= _ <<
main={short_name}
short_name={prefix}{suffix}
prefix=Ai|Al|A|Du|Glam|Dul|Gom|Nar|Pel|Tri|Dun|Do|Bar|Er|Tim|Al|Du|Bu|Bur|Nor|Der|Ur|Gar
suffix=sil|fur|bor|bus|bur|bor|gos|dor|rin|dur|ing|ras|this|tis|rol|sol|las|til|til|tol|los|rol|sol|ril|sil|as|us|lil|fur|mur|fur
>>
#enddef
edit: If I were using this, I would prune the generator a little. I see the possible names "Doing" "Timing" and "Aas".
User avatar
Spannerbag
Posts: 759
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: name_generator query

Post by Spannerbag »

tsunami_ wrote: March 16th, 2025, 4:56 am If your problem is not wanting to spawn units on top of other ones, you can spawn one directly into the recall list...
Thanks for your post; it helps - but you underestimate my ignorance! :)

I did consider creating to recall and understand (I think) how to configure the generator to create short names but this still left the issue of "deploying" this logic for generating a short name; i.e. how to tell [unit] to use the customised generator.

Specifically, the bits of knowledge I'm lacking are how to either:
  1. Capture the generator's output into a variable, or
  2. How to invoke/use the customised version of the generator rather than the standard one.
I've been unable to find anything helpful in the wiki nor in my semi-random wandering around the Wesnoth folders.

I'm working on other bits and bobs as time permits and will probably bodge write a home brewed custom short name generator in WML if need be.
However this feature is a "nice to have" rather than "essential" so I'm presently simply hard coding the names (i.e. they are always the same).
So please don't spend ages on this, it really isn't that important! :)

Again, thanks for your post, much appreciated.

Cheers!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.18, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
User avatar
tsunami_
Posts: 16
Joined: June 22nd, 2024, 2:07 am
Location: Pacific

Re: name_generator query

Post by tsunami_ »

Don't worry, since I have made name generators before, this work-around was very quick to finish. I just copy-paste and delete a lot. Although, I will tell you that I do not know anything about LUA (option a). So maybe there is a better solution there.

For option b:
In short: name generator -> race -> units
So you need a custom race to call your custom name generator.

Longer:
First of all, I think it is not possible to create a short name using the original DWARVISH_NAMES. The generator always returns "main" and main returns "long_name". "short_name" is perhaps legacy code.

Anyway, I have put the SHORT_DWARVISH_NAMES inside the file /utils/names.cfg
Then I put this race definition inside of /utils/units.cfg
I believe this is the minimum race info to avoid error messages.

Code: Select all

[units]
    {~add-ons/fire/units}
    [race]
        id=shortnameddwarves
        name= _ "race^Short named dwarf"
        plural_name= _ "race^Short named dwarves"
        {SHORT_DWARVISH_NAMES}
    [/race]
[/units]
Then, in /units/namedummy.cfg, this unit:

Code: Select all

[unit_type]

    id=Name Dummy
    name= _ "Name Dummy"
    race=shortnameddwarves
    image="units/name-dummy.png"
    hitpoints=1
    level=1
    description= _ "Placeholder description. This is a dummy unit. If it appears, it is an error."

[/unit_type]
name-dummy.png
name-dummy.png (964 Bytes) Viewed 2436 times
Then in the macro from before, replaced "Dwarvish Ulfserker" with "Name Dummy".

Here is the result:
rename_results.png

This is not quite what you wanted, anyway, but hopefully it gives you enough information to create your solution :)

-
User avatar
Spannerbag
Posts: 759
Joined: December 18th, 2016, 6:14 pm
Location: Yes

Re: name_generator query

Post by Spannerbag »

tsunami_ wrote: March 17th, 2025, 8:19 pm Don't worry, since I have made name generators before, this work-around was very quick to finish...
Phew.
Thanks, very helpful and enlightening, much appreciated!
Will experiment with your code, thanks again for your time and trouble!

Cheer!
-- Spannerbag
SP Campaigns: After EI (v1.14) Leafsea Burning (v1.18, v1.16)
I suspect the universe is simpler than we think and stranger than we can know.
Also, I fear that beyond a certain point more intelligence does not necessarily benefit a species...
Post Reply