Filter stations by vehicle count

Got an idea for OpenTTD? Post it here!

Moderator: OpenTTD Developers

Post Reply
ICE-T-Fan
Engineer
Engineer
Posts: 13
Joined: 17 Dec 2018 16:05

Filter stations by vehicle count

Post by ICE-T-Fan »

It would be really great if there was a filter for the number of vehicles in the station overview.

Currently you can sort stations by name, station type, freight and rating. I would like to add how many vehicles drive to this station.

So you can find well and poorly frequented stations on large maps easier.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Filter stations by vehicle count

Post by Eddi »

it might be computationally difficult to find out that information, because you have to loop through every station, and every station has to loop through all vehicles, and each vehicle has to loop through all its orders.

that is, unless you add a cache for this kind of information, which in turn would require you to analyze all situations which would need to invalidate and recalculate the cache.

Effort: ca. 100LOC
ICE-T-Fan
Engineer
Engineer
Posts: 13
Joined: 17 Dec 2018 16:05

Re: Filter stations by vehicle count

Post by ICE-T-Fan »

The information is available. When I click on a station it shows me a list of all the trains there. You just have to count that and go through all the stations / stations.
Attachments
Deutsche Reichsbahn, 17. Mai 2066.png
(2.15 MiB) Not downloaded yet
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Filter stations by vehicle count

Post by Eddi »

congratulations, you have terrible reading comprehension.
ICE-T-Fan
Engineer
Engineer
Posts: 13
Joined: 17 Dec 2018 16:05

Re: Filter stations by vehicle count

Post by ICE-T-Fan »

English ist not my favorite language, maybe I misunderstand you in details.

I dont think you need 100 lines of code, because you can reuse the code from station, which shows the value for one station. You only need to iterate through all stations. But you have to do it for the other existing filters, too.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Filter stations by vehicle count

Post by Eddi »

fine, you can ignore my advice and assessment of problems. i'm awaiting your 10loc patch that magically avoids all the problems i mentioned, then. should be done in an hour?
ICE-T-Fan
Engineer
Engineer
Posts: 13
Joined: 17 Dec 2018 16:05

Re: Filter stations by vehicle count

Post by ICE-T-Fan »

Someone who only talks about problems usually has no desire to do anything. I know what I'm talking about, I am a qualified IT specialist myself. However, I have not worked with C ++ or C # for 10 years, since my apprenticeship. Otherwise I would take the time myself.

PS: But I understand the principle problem with the nested iteration.

What I do not understand is why does a vehicle have to go through all its orders? I just want to know how many trains stop at station xy, not how many trains unload or load there.
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: Filter stations by vehicle count

Post by Transportman »

Eddi wrote:fine, you can ignore my advice and assessment of problems. i'm awaiting your 10loc patch that magically avoids all the problems i mentioned, then. should be done in an hour?
But can you explain more on your assessment of problems?

I looked at the code, and the main issue I saw as someone unfamiliar with all the inner workings of OpenTTD and C++, is that there is no object-relation between orders (and thus vehicles) and stations, an order just has an ID that links it to the station (or depot or whatever else an order can point to)*. This would mean that the vehicle list that you can open from a station indeed needs to do a loop in some way to get the vehicles that are having orders for that station, but I couldn't find the piece of code responsible for that...

*I do find this very odd, so I'm not sure if my analysis is correct in any way.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
jfs
Tycoon
Tycoon
Posts: 1757
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Filter stations by vehicle count

Post by jfs »

Yes, to find number of vehicles with orders at a station, you have to search all orders and count how many vehicles have those orders.
Of course, this means if you want to build a map of vehicle count for all stations, it's not much more work than finding vehicle count for a single stations, so you could just do that instead. Question is then if you want to maintain that station-vehicle count map as a cache that then needs ongoing maintenance, as a cache that just gets recomputed once in a while, or not actually cache it.
Regardless, for large games, visiting all orders/vehicles in existence is not a cheap operation.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Filter stations by vehicle count

Post by Eddi »

Transportman wrote:*I do find this very odd, so I'm not sure if my analysis is correct in any way.
yes, that sounds correct. most of this code is from before object oriented programming was a thing.

TTO and TTD were written in pure assembler (back in the 90s this was commonly done because you could squeeze every bit of speed out of it, because compilers were sometimes not generating very optimized code, modern compilers are better in that respect). For OpenTTD that was rewritten in C (not ++), often very close to the original assembler code. C also does not have object orientation, but after OpenTTD got more and more code that resembled object oriented programming concepts, but had to reimplent that with plain C, it was finally decided to move to C++. However, large parts of the code remained untouched since then, still using the old concepts.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Filter stations by vehicle count

Post by Eddi »

Transportman wrote:an order just has an ID that links it to the station
i haven't looked at the actual code, but there should e a static method "Station::FromID(id)" that can resolve this kind of link. (this is an inexpensive operation that hides some pointer/array arithmetics)
Post Reply

Return to “OpenTTD Suggestions”

Who is online

Users browsing this forum: No registered users and 12 guests