Suggestion : Label Cities on Generate

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
Svartypops
Engineer
Engineer
Posts: 28
Joined: 20 Nov 2022 15:15

Suggestion : Label Cities on Generate

Post by Svartypops »

Hello Modders!

Please could you help me with a (seemingly) minor issue?

I would love to be able to see on the map which settlements are Cities and which are not.

I spent ages renaming each city in my previous game to achieve that (I just renamed each city, putting "City" after each city's name). I'd like to automate this process.

Is it possible? Surely it must be, right?

If I have to work out how to do it myself, where should I begin? Script or GRF? Is there a modding tool, what do I need to know?
User avatar
Firrel
Engineer
Engineer
Posts: 118
Joined: 13 Aug 2019 17:06

Re: Suggestion : Label Cities on Generate

Post by Firrel »

Hey, you can use GameScript to do it for you.

Here is an untested code that should do the trick:

Code: Select all

// Get list of towns on map
// https://docs.openttd.org/gs-api/classGSTownList.html
local towns_list = GSTownList();

// GSList contains <item, value> pairs, where item is the id of the town
// and value is used for sorting, valuating, etc...
// https://docs.openttd.org/gs-api/classGSList.html
foreach (town_id, _ in towns_list) {
    // Check if it is a city
    if (GSTown.IsCity(town_id)) {
        // Get name of the town
        // https://docs.openttd.org/gs-api/classGSTown.html#afa4645c09372610446005f92c5b35945
        local town_name = GSTown.GetName(town_id);

        // Add (City) at the end
        town_name += " (City)";

        // Set new name of the town
        // https://docs.openttd.org/gs-api/classGSTown.html#a3d4f59e3a19bec8a8b5c5e6253998b64
        GSTown.SetName(town_id, town_name);
    }
}
You can use Minimmal GS by Zuu as the starting point, adding those lines in main.nut file.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 5 guests