News: Portal
Our Simutrans site. You can find everything about Simutrans from here.


Started by jameskuyper, November 26, 2022, 05:34:09 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


I'm confused about building_desc_x:can_be_built_underground(). I assumed that it returns true when a building can be built underground, but found that, for pak64, it returns true for almost every building. Instead, I wrote the following code to display the small number of cases where it returns false:

    local building_type_names = {
        [1] = "City Attraction",
        [2] = "Land Attraction",
        [3] = "Monument",
// The wikipedia article for buildings.dat suggests that it should have
// building types for residential, commercial, industrial buildings.
// but there aren't any listed in the API documentation.
        [5] = "Townhalls?",
// factory_desc_x::get_list() seems to be the only way to get a list of
// factory types, even though building_desc_x documentation suggests otherwise.
//      [factory] = "Factory",
        [7] = "Headquarters",
        // Passing any of the following to get_building_list() produces all five
        [11] = "Stops",
        [33] = "Depots",
        [34] = "Stations",
        [35] = "Station Extensions",
        [36] = "Flat Harbors"

    for(local key = 1; key <12; key++)
        local building_list = building_desc_x.get_building_list(key);
            foreach(building in building_list)
                    local cargo = (building.enables_freight() ? "f" : "") +
                        (building.enables_mail() ? "m" : "") +
                        (building.enables_pax() ? "p" : "");

                        building_type_names[building.type] + ":" +
                        building.waytype + " " + + " " +
                        cargo + " cap=" + building.capacity +
                        " cost=" + building.cost +
                        " maint=" + building.maintenance + "\n",
This produced the following output:
QuoteStations:1 PostStop m cap=32 cost=40000 maint=2000
Stations:2 GCGTrainStop p cap=256 cost=480000 maint=16000
Stations:2 TrainStop p cap=128 cost=240000 maint=8000
Stations:2 PSHall2TrainStop p cap=128 cost=240000 maint=8000
Stations:2 PSHall1TrainStop p cap=128 cost=240000 maint=8000
Stations:1 HallBusStop p cap=128 cost=160000 maint=8000
Stations:5 TrainStopMaglevIndicator p cap=32 cost=60000 maint=2000
Stations:5 TrainStopMaglev p cap=32 cost=60000 maint=2000
Stations:2 SandStationMHz p cap=32 cost=60000 maint=2000
Stations:1 BusStop p cap=32 cost=40000 maint=2000
Monument:0 DenkVolker  cap=1920 cost=6000000 maint=120000
Monument:0 DenkTrikky  cap=1920 cost=6000000 maint=120000
Monument:0 DenkTomas  cap=1920 cost=6000000 maint=120000
Monument:0 DenkMHz  cap=1920 cost=6000000 maint=120000
Monument:0 DenkHajo  cap=1920 cost=6000000 maint=120000
Monument:0 DenkFlor  cap=1920 cost=6000000 maint=120000
Monument:0 DenkDirk  cap=1920 cost=6000000 maint=120000
I displayed that information because I realized that would not necessarily match what was displayed in-game.
Experimenting showed me that the following buildings could be built underground:

"Underground Station" 1,200.00 (40.00), 64 Passengers
"Freight Station" 600.00 (20.00) 32 Freight
Note: both of these can be built on tram track in a road tunnel.

Train Depot

Tram Depot (only on Rail - not on tram track in a road tunnel).

"Long Bus Stop", 800.00 (40.00) 64 Passengers
"Freight Yard", 400.00 (20.00) 32 freight

So can_be_built_underground() isn't reversed, either. Not a single one of the buildings that can be built underground shows up in the list, while far too many buildings show up when I list the ones where the function returns true.


Thanks for the report.

In the game, can_be_built_underground/aboveground is only checked for stations, and it is only used to toggle icons in the toolbar. I will adjust the documentation of the api. This setting is not checked when actually placing stations. So an AI player can build any station above/under ground.

The building name is the raw name as in the pak/dat files. To convert it to an ingame visible and translated string use something like
print("name " + ::translate(building_name) )

Added the identifiers city_res/ind/com in r10816.
Parsley, sage, rosemary, and maggikraut.


Parsley, sage, rosemary, and maggikraut.


It's good to know about ::translate(). I didn't realize that it did that kind of translation.
I tried using attraction_city and the like, but I got messages indicating that they weren't recognized. I can get you the exact error message text, but not today. Is there something I need to do to make those enumerator visible?


they can be accessed like
Parsley, sage, rosemary, and maggikraut.


I successfully switched to using building_desc_x.station. I used that as the only value passed to get_building_list(), and I only looked at buildings for which building.type==building_desc_x.station. I changed it to translate( I got results that matched the results of my experimentation, with two exceptions: can_be_built_underground() returns true for both the Jetway and the Airport Stop, which doesn't make any sense, and not-surprisingly, doesn't work.


oh, yes, air stops are also excluded from being built underground, no matter what the can_be_built_underground setting is.

Just curious, what are you trying to do with scripting?
Parsley, sage, rosemary, and maggikraut.


I haven't had much time to play with simutrans for a long time, but recently my 7-year old found it on my computer, and now wants to play it whenever he can.i thought it would be a great way for him to learn about money - how to manage your money to keep your expenses below your income, etc. Then I discovered that he only plays in freeplay mode and pays no attention to the money.
Anyway, that reawakened my own interest in the game. I have three different projects I am interested in, but can_be_built_underground() is only tangentially related to any of them - it was mainly idle curiosity that led me to try and create a list of everything that could be built inderground. I've played Outpost, a computer game where you build an entire underground city on a planet whose surface is too hostile for most purposes. I was idly wondering how close simutrans can get to that. Without the ability to build urban houses underground, it can't get very close.
I noticed something that is oddly restrictive. Trams can run underground on tram track laid in road tunnels, or in railroad tunnels, but a tram depot can only be built underground in a railroad tunnel. While railroad tracks can cross roads at grade above ground, they cannot do so below ground, so trams built underground would have to travel above ground to get on actual tram track. This is not a complaint, just idle curiosity. Simutrans was never intended tto allow an Outpost-style pakset.


I've long thought about writing a program that would read a simutrans save file, extract information about how the pakset it uses works, and use that information to determine which convoy was the most profitable way to transport a given good over a given way type. While I am a retired computer programmer, when I thought about how much work I'd have to put into making that work, I was discouraged. In particular, I was dismayed at the amount of maintenance work I'd have to do to keep it working as you released new versions of simutrans.
When I was reviewing version 123, I suddenly realized that I could implement my program as a scripted tool. I'd have to check the revision history to be sure, but I think you've added some features to the squirrel API in recent versions that now make it feasible.

My oldest scripting idea was to create a Berlin Airlift scenario, for which I would use a German pakset to which I would add some cargo airplanes. The most important airlifted resource was coal, and none of the standard paksets allows that to be transported by air.
I wanted to have the player company concentrate on transport between west Germany and west Berlin, while AI companies would handle transportation within those two areas. However, I wasn't sure that the provided AI companies would be able to cope with the weird restrictions of this scenario. A scripted AI could do a better job, and I think that may be possible only because of changes to the squirrel API since the last time I looked into it.


That airlift scenario sounds very interesting. And pak64 airplanes are open source, sou you could convert them to coal and maybe paint a few pixels on the tail to indicate this.


According to Wikipedia the targets for Berlin airlift
Quotedaily supplies needed at 646 tons of flour and wheat, 125 tons of cereal, 64 tons of fat, 109 tons of meat and fish, 180 tons of dehydrated potatoes, 180 tons of sugar, 11 tons of coffee, 19 tons of powdered milk, 5 tons of whole milk for children, 3 tons of fresh yeast for baking, 144 tons of dehydrated vegetables, 38 tons of salt and 10 tons of cheese. In all, 1,534 tons were required each day to sustain the over two million people of Berlin.[
It occurred to me that simutrans handles timein a very peculiar fashion, so that trains move across the map a speed that is much smaller than an accurate simulation would do. Effectively, each trip should be considered as actually representing N trips in a corresponding real-world situation. That means qthat when I convert those consumption numbers into monthly production rates for simutrans factories, I should miltiply them by 30 days per month, then divide them by some suitable factor. What should that factor be?