TransWikia.com

How Many Passengers?

Arqade Asked by RulerOfTheWorld on May 29, 2021

I’m currently writing an AI to play OpenTTD, and I’m trying to find out how many people & mail will be available if I build a station covering an entire town. (Such as 100 passengers and 20 mail every month)

To calculate this, since I haven’t seen any way to get this directly using the API, I need to use the formulas OpenTTD uses to distribute cargo.

Cargo is split based on the top local rating of each competitor in a city.
For example: If company A has two stations (Rating 50% and Rating 40%), and company B has one station (Rating 50%), half of the cargo goes to A and is split between their two stations, and the other half goes to B’s single station.

Unfortunately, I haven’t yet been able to find a way to find a way to access any of this data using AIStationList.

AIStationList(AIStation.STATION_ANY).IsEmpty() Returns true, despite there being stations from competitors.

I then attempted a workaround by getting the stationID using:

local industry_id = 0; //Industry ID to target, using a coal mine to test
local tile_list = AITileList_IndustryProducing(industry_id, AIStation.GetCoverageRadius(AIStation.STATION_TRAIN));

for (local tile = tile_list.Begin(); tile != 0; tile = tile_list.Next()) { //Tile is 0 when list exhausted
    local station_id = AIStation.GetStationID(tile);
    if (station_id != 65535){ //Empty tiles given ID 65535
        AILog.Info("Tile!   |   "+tile+"   |   StationID: "+station_id+"   |   CargoPlanned: "+AIStation.GetCargoPlanned(station_id, 1)+"   |   CargoRating: "+AIStation.GetCargoRating(station_id, 1));
    }}

This essentially gets checks the tiles around the industry to find any stations, however even with the station IDs, I still can’t get any information about the station ratings, cargo loaded, or the company that owns them.

Code output

So my overall question: How can I find how many passengers and mail will go to my station?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP