Suffix/Prefix for generated name

Brainstorm ideas of possible additions to the game. Read this before posting!

Moderator: Forum Moderators

Forum rules
Before posting a new idea, you must read the following:
User avatar
Eagle_11
Posts: 759
Joined: November 20th, 2013, 12:20 pm

Suffix/Prefix for generated name

Post by Eagle_11 »

Its an idea like,
when an unit type advances into another, can gain an specified suffix/prefix to the generated name.
Fe. if unit was Horseman named Ologwyn becomes Sir Ologwyn upon advancing to Knight.
Or another ex. if unit was orc warrior named Glukk can gain an orky prefix derived from a list upon advancing to warlord, possibilities could be such as becoming Glukk the warmonger, Glukk the bloodthirsty, Glukk the savage, etc.
User avatar
Kwandulin
Art Contributor
Posts: 362
Joined: March 30th, 2014, 7:35 am
Location: Germany

Re: Suffix/Prefix for generated name

Post by Kwandulin »

This sounds like a really great idea.

I don't like the second example with the orcs, though, for the simple reason that their name would then become too long and probably it wouldn't show nicely on the unit panel. Maybe there can be nice pre- or suffixes invented for the rank of an orc.
The example with the knight sounds nice. Also, a dark adept advancing to a dark sorcerer could get the prefix "Mal-", as displayed in Eastern Invasion.

I'd argue in favor of not making this for every unit type, e.g. an elvish archer advancing is still some sort of 'ordinary' archer and certainly doesn't deserve its own title.

The only problem I see with that is, how will that apply to units of a certain unit type that are already on the map? Will the pre- and suffixes apply there? Or will they only be added when a unit advances?
User avatar
Eagle_11
Posts: 759
Joined: November 20th, 2013, 12:20 pm

Re: Suffix/Prefix for generated name

Post by Eagle_11 »

This idea was rather intended for being available to be used in Umcs rather than affecting mainline.

I had seen such a thing in Grafted Era for the original halflings, it was used for adding an surname after the name was given, didnt throughly examine it though.
So, apparently the only thing it does is swap out the generated name for another one that is pre-defined in an seperate list, if i knew an means to store unit's generated name into an variable to be passed to it, could experiment around with it.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Suffix/Prefix for generated name

Post by Celtic_Minstrel »

Try putting something like this in an advancement event:

Code: Select all

[modify_unit]
    [filter]
        type=Dark Sorcerer
    [/filter]
    name=Mal-$this_unit.name
[/modify_unit]
For more advanced string manipulations, you can use a formula. For example, suppose you wanted the Dwarvish Fighter line to gain the title "Sir" at level 2 and replace that with "Lord" at level 3. You could use something like this:

Code: Select all

# Call this when advancing to level 2
[modify_unit]
    [filter]
        x,y=$x1,$y1
    [/filter]
    name="Sir $this_unit.name"
[/modify_unit]
# Call this when advancing to level 3
[modify_unit]
    [filter]
        x,y=$x1,$y1
    [/filter]
    # Note that this could fail if the name contains an apostrophe
    name="Lord $(substring('$this_unit.name', 5))"
[/modify_unit]
If necessary, substring() can take a third argument specifying an exact number of characters to extract (by default it goes to the end of the string). This should even work in 1.12. For more information on functions available in a $() context, see [wiki]Wesnoth Formula Language[/wiki]. Unfortunately, most of the string functions are 1.13-only, but a few (including substring) are available even in 1.12.
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
White_Drag0n
Posts: 55
Joined: January 11th, 2016, 1:42 pm

Re: Suffix/Prefix for generated name

Post by White_Drag0n »

Considering it's possible to manually rename units, I feel like the second event should check if the unit still has the "Sir" part in it.

I'm not sure did I understood the code correctly, but it should look like this?

Code: Select all

[if]
    [variable]
        name='$this_unit.name'.word[0]
        equals="Sir"
    [/variable]
[/if]
User avatar
GunChleoc
Translator
Posts: 506
Joined: September 28th, 2012, 7:35 am
Contact:

Re: Suffix/Prefix for generated name

Post by GunChleoc »

Make sure that this is translatable too - the "Sir" bit might even to to the end of the string in some languages.

In my translation, I actually removed the "Sir" bit, because there is no way that I can fit "An Ridire <name>" into the UI ;)
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Suffix/Prefix for generated name

Post by Celtic_Minstrel »

White_Drag0n wrote:Considering it's possible to manually rename units, I feel like the second event should check if the unit still has the "Sir" part in it.

I'm not sure did I understood the code correctly, but it should look like this?
I think that would probably require the proposed-but-not-yet-existing [variable]formula=. Your code would just give an error. (The .word[0] syntax also requires 1.13.5 or so.)

In 1.12, you could do something like this:

Code: Select all

[store_variable]
name=name_prefix
value="$(substring('$unit.name', 0, 3))"
[/store_variable]
[if]
    [variable]
        name=name_prefix
        equals="Sir"
    [/variable]
    [then]
        # etc
    [/then]
[/if]
(If [variable]formula= were added it would probably look like this:)

Code: Select all

[if]
    [variable]
        name=unit.name
        formula="self.word[0] = 'Sir'" # reference the actual variable by "self"
    [/variable]
    [then]
        # etc
    [/then]
[/if]
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
User avatar
Eagle_11
Posts: 759
Joined: November 20th, 2013, 12:20 pm

Re: Suffix/Prefix for generated name

Post by Eagle_11 »

oh man, now i see those replies. :doh:
released first version of 'Extended Unit Names' to the server, which i shall update soon using the new knowledge gained here.
meanwhile feel free to suggest any affix-prefix, surname, title that may fall on your heads to be used for the one unit line or other
Make sure that this is translatable too -.
Instructions may prove of use for this ^ how to properly ?
User avatar
GunChleoc
Translator
Posts: 506
Joined: September 28th, 2012, 7:35 am
Contact:

Re: Suffix/Prefix for generated name

Post by GunChleoc »

I don't know - I don't speak WML ;)

Generally, one would use printf placeholders.
User avatar
Eagle_11
Posts: 759
Joined: November 20th, 2013, 12:20 pm

Re: Suffix/Prefix for generated name

Post by Eagle_11 »

Have to filter out so it does not trigger on AMLA, as it multiplies on each level up, but i dont know how. any ideas ?
also, what is printf ?
Pine
Posts: 7
Joined: September 23rd, 2016, 2:37 am

Re: Suffix/Prefix for generated name

Post by Pine »

Celtic_Minstrel wrote:
White_Drag0n wrote:Considering it's possible to manually rename units, I feel like the second event should check if the unit still has the "Sir" part in it.

I'm not sure did I understood the code correctly, but it should look like this?
I think that would probably require the proposed-but-not-yet-existing [variable]formula=. Your code would just give an error. (The .word[0] syntax also requires 1.13.5 or so.)
How about lua?

It even provides nice string.format that allows writing translation like

Code: Select all

unit.name = string.format(tostring(_"Sir %s"), unit.name)
Assuming name has proxy implementation but I didn't check if there is. But even without proxy one can still modify config directly and use wesnoth.put_unit to write the modified unit back to game.
User avatar
Celtic_Minstrel
Developer
Posts: 2207
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: Suffix/Prefix for generated name

Post by Celtic_Minstrel »

string.format is not a good choice for anything that needs to be translated, because you cannot reorder the placeholders. It's fine in this simple case though (since there is only one placeholder). So yes, you could use Lua for this, though it would seem to be less convenient unless you extend [set_variable] or create your own custom WML tag.

(By "extend [set_variable]" I mean replace it with a tag of the same name that adds extra behaviour and then calls the original tag.)
Author of The Black Cross of Aleron campaign and Default++ era.
Former maintainer of Steelhive.
Pine
Posts: 7
Joined: September 23rd, 2016, 2:37 am

Re: Suffix/Prefix for generated name

Post by Pine »

Celtic_Minstrel wrote:string.format is not a good choice for anything that needs to be translated, because you cannot reorder the placeholders. It's fine in this simple case though (since there is only one placeholder). So yes, you could use Lua for this, though it would seem to be less convenient unless you extend [set_variable] or create your own custom WML tag.

(By "extend [set_variable]" I mean replace it with a tag of the same name that adds extra behaviour and then calls the original tag.)
I think standard lua is missing numbered place holders for string formatting. But I guess it shouldn't be hard to forward one from c++ for that purpose.

But I think simple using lua-tag to include code inline would be easiest way if using lua to implement name change logic.

But how to check for amla: You need to have advance event handler that sets flag in unit.variables. If no amla would add prefix then you could just check maximum level in pre_advance event handler.
Tad_Carlucci
Inactive Developer
Posts: 503
Joined: April 24th, 2016, 4:18 pm

Re: Suffix/Prefix for generated name

Post by Tad_Carlucci »

Lua is written in pure ISO/IEC 9899 International Standard "C", or as close to that as possible (there are a couple places where it depends upon unspecified behaviors which seem safe). That means it has available only the formatting functions provided by the standard libraries. The "C" standard does not provide a means to re-map the order of format specifiers to parameters; thus Lua cannot, either.

As suggested, the solution is to provide a Wesnoth-specific function similar to string.format() which does.
I forked real life and now I'm getting merge conflicts.
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Suffix/Prefix for generated name

Post by zookeeper »

...surely there's nothing tricky in implementing this in simple WML only?

Code: Select all

    [event]
        name=pre advance
        first_time_only=no

        [filter]
            type=Horseman
        [/filter]

        [event]
            name=post advance
            id=horseman_knighting

            [filter]
                id=$unit.id
                type=Knight
            [/filter]

            {VARIABLE unit.name _"Sir $unit.name"}

            [unstore_unit]
                variable=unit
            [/unstore_unit]

            [event]
                id=horseman_knighting
                remove=yes
            [/event]
        [/event]
    [/event]
In what situation would that code fail or be insufficient?
Post Reply