Suffix/Prefix for generated name
Moderator: Forum Moderators
Forum rules
Before posting a new idea, you must read the following:
Before posting a new idea, you must read the following:
Suffix/Prefix for generated name
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.
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.
Re: Suffix/Prefix for generated name
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?
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?
Re: Suffix/Prefix for generated name
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.
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.
- Celtic_Minstrel
- Developer
- Posts: 2214
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Suffix/Prefix for generated name
Try putting something like this in an advancement event:
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:
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.
Code: Select all
[modify_unit]
[filter]
type=Dark Sorcerer
[/filter]
name=Mal-$this_unit.name
[/modify_unit]
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]
- White_Drag0n
- Posts: 55
- Joined: January 11th, 2016, 1:42 pm
Re: Suffix/Prefix for generated name
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'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]
Re: Suffix/Prefix for generated name
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
In my translation, I actually removed the "Sir" bit, because there is no way that I can fit "An Ridire <name>" into the UI
- Celtic_Minstrel
- Developer
- Posts: 2214
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Suffix/Prefix for generated name
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.)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?
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]
Code: Select all
[if]
[variable]
name=unit.name
formula="self.word[0] = 'Sir'" # reference the actual variable by "self"
[/variable]
[then]
# etc
[/then]
[/if]
Re: Suffix/Prefix for generated name
oh man, now i see those replies.
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
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
Instructions may prove of use for this ^ how to properly ?Make sure that this is translatable too -.
Re: Suffix/Prefix for generated name
I don't know - I don't speak WML
Generally, one would use printf placeholders.
Generally, one would use printf placeholders.
Re: Suffix/Prefix for generated name
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 ?
also, what is printf ?
Re: Suffix/Prefix for generated name
How about lua?Celtic_Minstrel wrote: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.)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?
It even provides nice string.format that allows writing translation like
Code: Select all
unit.name = string.format(tostring(_"Sir %s"), unit.name)
- Celtic_Minstrel
- Developer
- Posts: 2214
- Joined: August 3rd, 2012, 11:26 pm
- Location: Canada
- Contact:
Re: Suffix/Prefix for generated name
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.)Re: Suffix/Prefix for generated name
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.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.)
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.
-
- Inactive Developer
- Posts: 503
- Joined: April 24th, 2016, 4:18 pm
Re: Suffix/Prefix for generated name
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.
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.
Re: Suffix/Prefix for generated name
...surely there's nothing tricky in implementing this in simple WML only?
In what situation would that code fail or be insufficient?
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]