Show station catchment area with right mouse button.

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

plaes
Engineer
Engineer
Posts: 18
Joined: 08 Oct 2006 06:56

Show station catchment area with right mouse button.

Post by plaes »

Now, it's possible to view a station catchment area when clicking with the right button on the station.

Code should be feature complete, but some refactoring needs to be done... I just got a headache trying to figure out the correct numbers for SetTileSelectBigSize function ;)

Screenshot here:
http://plaes.org/files/2006-Q4/ottd-sta ... t-area.png


[edit]Changed left to right ;)
Attachments
leftclick-show-station-spread-hack-v3.diff
Feature complete, but some refactoring todo...
(6.09 KiB) Downloaded 298 times
Last edited by plaes on 28 Aug 2007 14:06, edited 3 times in total.
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post by Wolf01 »

good

i'm trying to do this since a long time ago but i never got acceptables results
i'm trying to show the whole station catchement area when pressing a button in the station gui
if you want to cooperate i'll be happy :)
l_Blue_l
Transport Coordinator
Transport Coordinator
Posts: 285
Joined: 29 Mar 2006 22:42
Contact:

Post by l_Blue_l »

i have tried to show station catchement spread aswell but i gave up and achived what i was looking for a different way. Instead i displayed what industries there were around the station in the station window. this was done by useing the industries(that produce cargo(even if the cargo produce amount is 0)) to tell the station that they are there instead of the station looking for them. This is a realivity small patch which i want to release with my fully funtional industry directory for stations but i have been haveing never ending problems with it.

i think you should name this tile spread instead of station spread as i got the wrong idea when you said station spread
User avatar
prissi
Chief Executive
Chief Executive
Posts: 647
Joined: 15 Nov 2004 19:46
Location: Berlin, Germany
Contact:

Post by prissi »

Maybe you should have a look at
UpdateStationAcceptance()
in station_cmd.c. There all tiles are calculated, I think, including modified catchment areas and so on. You could just take the upper half of the function and write a new one, just returning a rectance with the catchment area.
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

prissi wrote:Maybe you should have a look at UpdateStationAcceptance() in station_cmd.c
I just took a quick look in that function. It's not a tiny function, so half of it would be a lot of duplicated code. I think it would be better to write a function to contain the code both functions need. Having only one piece of code for each functionality will make the functionality consistent. It will prevent the issues we had like when building vehicles, the player had to own the tile (depot) the vehicle is build in, but that check was skipped for trains. If we had a single piece of code to verify such data, such inconsistence would not show up.

It would also be nice if somebody takes the time to write good comments in UpdateStationAcceptance() as it leaves room for improvement.

I like this feature, but it have to be done right :wink:
plaes
Engineer
Engineer
Posts: 18
Joined: 08 Oct 2006 06:56

Post by plaes »

Well, I updated the patch, so it now should be feature complete :)

Code: Select all

  * UpdateStationArea was refactored, some of the code was used to create a new GetStationArea function.
  * Moved ottd_Rectangle definition to the station.h (btw, the name sucks ;))
  * FindCatchmentRadius and GetStationArea functions are now public f-s in station_cmd.c
plaes
Engineer
Engineer
Posts: 18
Joined: 08 Oct 2006 06:56

Re: Show station catchment area with left mouse button.

Post by plaes »

I have updated the patch so it would apply and compile with latest svn.
Attachments
leftclick-show-station-spread-hack-v4.diff
(5.51 KiB) Downloaded 191 times
MJS
Director
Director
Posts: 540
Joined: 28 Jul 2005 09:31

Re: Show station catchment area with left mouse button.

Post by MJS »

Works with irregular stations and combined train+bus+whatever stations too, I hope?
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: Show station catchment area with left mouse button.

Post by TrueBrain »

I like your patch! Just one thing that really should be done better: the malloc. A better approach would be:

Code: Select all

ottd_Rectangle *GetStationArea(Station *st, ottd_Rectangle *area) { }
and call it like:

Code: Select all

{
  ottd_Rectangle area;
  GetStationArea(st, &area);
}
No malloc, no need for free(), clean and simple :) You might also want to upload it to http://bugs.openttd.org :) Nice work!
The only thing necessary for the triumph of evil is for good men to do nothing.
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Re: Show station catchment area with left mouse button.

Post by richk67 »

Im not entirely sure how the current system works for working out the cargo acceptance tiles, but it looks from your patch that if you have a string of bus depots attached to an Intercontinental, you would get intercontinental sized catchment area around each tile of the station.

I was intending working on this at some point to handle the irregular shape airports, whose current catchment area is just the basic rectangle.
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
Mchl
Director
Director
Posts: 611
Joined: 05 Jan 2007 15:50
Location: Poland
Contact:

Re: Show station catchment area with left mouse button.

Post by Mchl »

Do you plan to have an irregular catchment areas on your airports? IMHO better solution would be circular/oval catchment areas with center located somewhere near main terminal.
User avatar
antichaos
Engineer
Engineer
Posts: 42
Joined: 13 Feb 2007 21:51
Location: UK

Re: Show station catchment area with left mouse button.

Post by antichaos »

The big problem with catchment areas is that they are not properly defined. They are calculated one way in UpdateStationAcceptance (as the big bounding rectangle in this patch) but this is not the same as the effective area for a station to receive cargo from producing industries, which is done from the industry's point of view, and can result in an irregular shaped area that is effectively the union of the rectangles for each of the station's tiles, which is a little more work to calculate from the station's point of view. This means that with an irregular station, one could have a factory which accepts cargo from the station, but can't deliver to it.
plaes
Engineer
Engineer
Posts: 18
Joined: 08 Oct 2006 06:56

Re: Show station catchment area with left mouse button.

Post by plaes »

TrueLight wrote:I like your patch! Just one thing that really should be done better: the malloc. A better approach would be:

Code: Select all

ottd_Rectangle *GetStationArea(Station *st, ottd_Rectangle *area) { }
and call it like:

Code: Select all

{
  ottd_Rectangle area;
  GetStationArea(st, &area);
}
No malloc, no need for free(), clean and simple :) You might also want to upload it to http://bugs.openttd.org :) Nice work!
Are you sure, that this approach would be better? IMHO, current version makes it easier to check whether the area is either invalid (NULL) or valid...
User avatar
Maedhros
OpenTTD Developer
OpenTTD Developer
Posts: 603
Joined: 30 Mar 2006 18:24
Location: Durham, UK

Re: Show station catchment area with left mouse button.

Post by Maedhros »

You can still return NULL (or make it a bool function and return false if you prefer).
No-one's more important than the earthworm.
plaes
Engineer
Engineer
Posts: 18
Joined: 08 Oct 2006 06:56

Re: Show station catchment area with left mouse button.

Post by plaes »

Code: Select all

v5:
 o Implemented TrueLights malloc/free removal thanks to the tip from Maedhros
I also submitted it to the Flyspray under http://bugs.openttd.org/task/1165
Attachments
leftclick-show-station-spread-hack-v5.diff
(5.45 KiB) Downloaded 155 times
User avatar
Sir A. Boey
Transport Coordinator
Transport Coordinator
Posts: 299
Joined: 17 Nov 2006 17:40
Location: Everywhere and nowhere

Re: Show station catchment area with left mouse button.

Post by Sir A. Boey »

Fabulous Patch...

I always wanted to see the catchment area of a station this because I sometimes found new industries
right next to a station but sometimes I've build them to far, so this is (2 me) a perfect sollution...

Tnx great work...
Image
_____________# If you believe in it, you can achieve it" # ____________
__________________# Check out My Closed Platform #___________________
User avatar
Sir A. Boey
Transport Coordinator
Transport Coordinator
Posts: 299
Joined: 17 Nov 2006 17:40
Location: Everywhere and nowhere

Re: Show station catchment area with left mouse button.

Post by Sir A. Boey »

Hello,

I've asked Chrissicom to take a look at your diff if it would be possible to input this
into his ChrisIN (with your permission that is) and here's what he had to say about that...

[Don't know if I'm alowed to quote other players in a different Thread but here it is anyway]

[quote]Chrissicom wrote: "Have you tested this patch yet? Does it only show the station catchment area when having the button still clicked or is a single short click enough and then the catchment is shown until when... ? I think the problem is that left click is also used to open the station info window so maybe using right click (I think it's unused on stations) would be a good solution."[/quote]

Greetz
Image
_____________# If you believe in it, you can achieve it" # ____________
__________________# Check out My Closed Platform #___________________
plaes
Engineer
Engineer
Posts: 18
Joined: 08 Oct 2006 06:56

Re: Show station catchment area with left mouse button.

Post by plaes »

Sir A. Boey wrote:Hello,

I've asked Chrissicom to take a look at your diff if it would be possible to input this
into his ChrisIN (with your permission that is) and here's what he had to say about that...

[Don't know if I'm alowed to quote other players in a different Thread but here it is anyway]
Chrissicom wrote: "Have you tested this patch yet? Does it only show the station catchment area when having the button still clicked or is a single short click enough and then the catchment is shown until when... ? I think the problem is that left click is also used to open the station info window so maybe using right click (I think it's unused on stations) would be a good solution."
Greetz
Hum.. You discovered the only flaw in the patch description :D

It should be right button not left...
chrissicom
Route Supervisor
Route Supervisor
Posts: 415
Joined: 07 Oct 2004 10:05

Re: Show station catchment area with right mouse button.

Post by chrissicom »

Hehe even better :) I already wondered where a left button is specified in the source. Just one more question, how did you create the .diff file because I can't read it with TortoiseSVN so I would have to "inject" the code manually.
plaes
Engineer
Engineer
Posts: 18
Joined: 08 Oct 2006 06:56

Re: Show station catchment area with right mouse button.

Post by plaes »

I'm using git (specifically git-svn) stuff to do development in my local branch (so I can make in-between commits).
But I have no idea why tortoisesvn doesn't like the patch :(
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 55 guests