NML: Generate town names according to parameter

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
ZvikaZ
Engineer
Engineer
Posts: 3
Joined: 05 Aug 2021 07:32

NML: Generate town names according to parameter

Post by ZvikaZ »

I'm trying to change the town names generator's behaviour according to parameter.

I've added a parameter in the `grf` block like this:

Code: Select all

	param 1 {
		use_real_names { // 1st boolean value
			name: string(STR_PARAM_NAME_USE_REAL_NAMES);
			desc: string(STR_PARAM_DESC_USE_REAL_NAMES);
			type: bool;
			bit:  1; // uses 1st bit
		}
	}
and tried to add an `if` like this:

Code: Select all

if (param[1]) {
	town_names {
		styles : string(STR_STYLES);
		{
			town_names(real, 1)
		}
	}
}
I also tried to relocate the `if` in various ways. But I only get errors such as:
nmlc ERROR: "israel.nml", line 1192: town_names-block may not appear inside a conditional block.
or
nmlc ERROR: "israel.nml", line 1192: Syntax error, unexpected token "if"
Of course, I can just create another NewGRF file, thus one file will be for `false` value, and other one for `true` value. But I'd really prefer to keep just one file, and let the user configure it.

Is there a way around these errors, so I could use parameter with town name generator? If not, is it an inherent (and wanted?) limitation? Or maybe it just wasn't implemented (yet) in the nml compiler, and maybe I could try sending a PR to change this?
ZvikaZ
Engineer
Engineer
Posts: 3
Joined: 05 Aug 2021 07:32

Re: NML: Generate town names according to parameter

Post by ZvikaZ »

Update - I've found workaround to the problem, by using two `town_names` blocks. It achieves similar effect, but without using parameter.
Still, I'm curious whether it's possible to do this with parameter and `if`.

Code: Select all

town_names {
	styles : string(STR_STYLES_REAL);
	{
		town_names(real, 1)
	}
}

town_names {
	styles : string(STR_STYLES_FAKE);
	{
		town_names(combined, 1),
	}
}
User avatar
Tomplus
Engineer
Engineer
Posts: 6
Joined: 27 Dec 2016 10:16

Re: NML: Generate town names according to parameter

Post by Tomplus »

I have the same problem.
I don't know how to use IF correctly and if it is possible at all when creating a list with town names.

Code: Select all

if (is_city) {
    if(population >= 2000) {
         town_names(CAPITOLS, 1)
    } else {
         town_names(CITIES, 1)
    }
} else {
     town_names(VILLAGES, 1)
}
if I write the condition in the town_names block, I have an error:
Syntax error, unexpected token "if"
the condition outside the block is:
town_names-block may not appear inside a conditional block.
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: NML: Generate town names according to parameter

Post by Eddi »

what you're trying to achieve cannot be done.
User avatar
Tomplus
Engineer
Engineer
Posts: 6
Joined: 27 Dec 2016 10:16

Re: NML: Generate town names according to parameter

Post by Tomplus »

I would like to assign a specific pool/group of city names when the condition:
is_city and population > 2000
for the others cities, a different pool/group of names

Matching the names to the size of the city/town would be at the beginning of the game.
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: NML: Generate town names according to parameter

Post by Eddi »

the fundamental problem with that idea is that city names are chosen before it is known how large the city will be.
User avatar
Tomplus
Engineer
Engineer
Posts: 6
Joined: 27 Dec 2016 10:16

Re: NML: Generate town names according to parameter

Post by Tomplus »

I see. So the towns should be renamed after the process of "building" the towns.

I would have to use: town_index,
But I don't know how to add the modification to work after the town creation queue.
User avatar
jfs
Tycoon
Tycoon
Posts: 1743
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: NML: Generate town names according to parameter

Post by jfs »

All a town names GRF does is convert a number between 0 and 4294967295 into a name, usually chosen by selecting parts via a bit field. The GRF does not "run", it just gives a basic decision tree, where the only input is the town name ID, which is a random number.

If you want to automatically rename towns based on size after the map generation is finished, you'd need to use something like a game script or a fake multiplayer client.
User avatar
Tomplus
Engineer
Engineer
Posts: 6
Joined: 27 Dec 2016 10:16

Re: NML: Generate town names according to parameter

Post by Tomplus »

Thanks for the explanation!

I just have to prepare the game script.
More specifically, a class that others might use for their scripts. if I can do something of course :)
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 5 guests