Patch: Close airports

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

Post Reply
User avatar
cirdan
Director
Director
Posts: 539
Joined: 07 Apr 2007 18:08

Patch: Close airports

Post by cirdan »

Hello,

This is my first attempt at a patch for OpenTTD. I have implemented a feature that I spotted in the suggestions forum, which is to allow airports to be 'closed'. When closed, aircraft already in the airport will proceed as normal, but those flying to the airport will be denied landing, that is, after the final approximation they will detour as though the landing runway were already in use. This way, the airport will eventually get empty, and this can be useful, for instance, if you try to upgrade a busy airport (you do not have to change the orders of all aircraft with that airport on their schedule).

I am hesitant about the best GUI for this feature, and did not want to spend too long coding an interface for now, so this is the first approach: To close an airport, you have to open the station window and ctrl+click on the airport button; an indicator will appear at the top right corner of the 'waiting' area to show that the airport is now closed. It acts as a toggle, so ctrl+clicking again will reopen the airport. If the airport is destroyed while closed and later rebuilt, it will also be reopened.

The patch itself is quite small. It applies against r10737. Any suggestions or comments will be welcome, particularly about the GUI.

----------------
EDIT: Current status:
Patches against: 0.6.0 | 0.6.1
Disable variant: 0.7.x | 1.0.0 | 1.0.1 | 1.0.[234]
Hide variant: 0.7.x | 1.0.0 | 1.0.1 | 1.0.[234] | in trunk in r24127
Last edited by cirdan on 18 Apr 2012 13:20, edited 15 times in total.

User avatar
rav
Traffic Manager
Traffic Manager
Posts: 253
Joined: 17 May 2007 13:36
Location: Netherlands
Contact:

Re: Patch: Close airports

Post by rav »

wow, thanks! :o

I did the suggestion, and I tried to create a patch for it, but couldn't pull it off, great job!

User avatar
flake
Engineer
Engineer
Posts: 64
Joined: 28 Apr 2004 10:07
Location: Salzburg
Contact:

Re: Patch: Close airports

Post by flake »

Personally i like hotkeys in games, so i have nothing against strg + something to do even important stuff (like switching signals).
I would like to strg + klick on "accepts" to close an airport.
But maybe in this case a button would be better....
*<(:-}

MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Re: Patch: Close airports

Post by MeusH »

It would be nice to make this patch cover all station types (railway, road and water).
A text button or a graphical button would be better than CTRL+click:
I'm almost sure many people won't know about this feature - I don't CTRL+click everything even if I'm bored :p

But I have currently no idea how would graphical button look like. Stop sign would be good, but the graphic must be black & white (actually black & transparent) and have a really small size

User avatar
cirdan
Director
Director
Posts: 539
Joined: 07 Apr 2007 18:08

Re: Patch: Close airports

Post by cirdan »

flake wrote:Personally i like hotkeys in games, so i have nothing against strg + something to do even important stuff (like switching signals).
I would like to strg + klick on "accepts" to close an airport.
But maybe in this case a button would be better....
MeusH wrote:A text button or a graphical button would be better than CTRL+click:
I'm almost sure many people won't know about this feature - I don't CTRL+click everything even if I'm bored :p
This is precisely what I meant about the GUI... I'm just not sure what the best option is. And I didn't want to put effort into that before I received some feedback on the feature itself. Now that I did, we can discuss about the GUI.
MeusH wrote:It would be nice to make this patch cover all station types (railway, road and water).
Yes, it would be nice, but I have no clue as to how to implement it. For planes it was easy, because I knew that, at some point, a check must be made to allow a plane to land or not, so you just add a flag and make the landing also depend on that flag. I guess something similar could be done for road vehicles, so that they would just queue up in front of the stop, and ships should be easier---just arriving at the dock and waiting there without loading/unloading. But I'm sure trains would be a totally different thing.

MeusH
Tycoon
Tycoon
Posts: 4349
Joined: 25 Oct 2004 15:39
Location: Mississauga

Re: Patch: Close airports

Post by MeusH »

cirdan wrote:But I'm sure trains would be a totally different thing.
Maybye bouncing off station just like if there were clear tiles (no railway)?
However, this would require change in code not related to stations I think

richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Re: Patch: Close airports

Post by richk67 »

cirdan wrote:For planes it was easy, because I knew that, at some point, a check must be made to allow a plane to land or not, so you just add a flag and make the landing also depend on that flag.
There may be a problem with this. When you leave aircraft circling in the holding stack, they are still in the state machine of the airport. When you place the replacement airport, the states will almost certainly not match. (Obviously like-for-like replacements will work.)

So if an aircraft is at position 22 of a commuter airport you are replacing with a city airport, then next position is 23. On the commuter, this is in the holding stack, in the city airport, it is the helilanding position.

What would probably work safer, is to ensure that when you place an airport, any aircraft already at the airport (which can only be flying aircraft), get sent to the airport intercept point using AircraftNextAirportPos_and_Order(v);

Could be quite useful. I intended doing a similar function in my NewGRF_ports branch, but having a fully separate holding stack linked to the station record. Thus, you could happily delete the airport, and there would be no problem as the aircraft would not be in the state machine anyway, but in the holding stack.
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

User avatar
MHTransport
Engineer
Engineer
Posts: 97
Joined: 25 Mar 2004 00:32

Re: Patch: Close airports

Post by MHTransport »

Great; very useful.

Please add it to all stations. ;)
A better OS: http://ubuntu.com/
Soon an even better OS: http://haiku-os.org/

User avatar
cirdan
Director
Director
Posts: 539
Joined: 07 Apr 2007 18:08

Re: Patch: Close airports

Post by cirdan »

richk67 wrote:
cirdan wrote:For planes it was easy, because I knew that, at some point, a check must be made to allow a plane to land or not, so you just add a flag and make the landing also depend on that flag.
There may be a problem with this. When you leave aircraft circling in the holding stack, they are still in the state machine of the airport. When you place the replacement airport, the states will almost certainly not match. (Obviously like-for-like replacements will work.)

So if an aircraft is at position 22 of a commuter airport you are replacing with a city airport, then next position is 23. On the commuter, this is in the holding stack, in the city airport, it is the helilanding position.

What would probably work safer, is to ensure that when you place an airport, any aircraft already at the airport (which can only be flying aircraft), get sent to the airport intercept point using AircraftNextAirportPos_and_Order(v);
You make quite a point here. I've tested what you say and you are partly right: There's a bug, but it's not my patch's fault.

To demonstrate this, take the attached savegame. It was prepared with vanilla r10737 (that is, without my patch, although with a lot of cheating to speed things up). The game should load paused, and there's an aircraft flying above a commuter airport, in position 22 (I think). The cheat to build while paused is enabled, so bulldoze the commuter airport and replace it with a city airport. You will see that, indeed, the plane moves erratically for a while, then gets it straight.

So my opinion is that we have found a bug already present in the code. It seems that removing or readding an airport does not update the state of the planes in its holding stack.
Attachments
Brendbourne Transport, 13th Jan 2000.sav
(10.36 KiB) Downloaded 449 times

richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Re: Patch: Close airports

Post by richk67 »

Yeah, probably a current bug. But your patch is an ideal point at which to correct it! :)

Incidentally, the example I gave is lucky that it picks a position in the air. You could possibly find one where the next position is say landed and taxiing, or at a helipad etc. The helipad one is worst, as helipads rarely contain aircraft movement orders, and so it would die horribly.
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

User avatar
cirdan
Director
Director
Posts: 539
Joined: 07 Apr 2007 18:08

Re: Patch: Close airports

Post by cirdan »

richk67 wrote:Yeah, probably a current bug. But your patch is an ideal point at which to correct it! :)
I've been looking closer and maybe it isn't a bug after all. The 'erratic behaviour' that I observed is caused by the multiple entry points that airports now have (something I didn't know about). When an airport is replaced, the code is careful enough to update all aircraft heading for the station (via UpdateAirplanesOnNewStation).

The only case that is missed is when removing an airport. Planes will automatically switch to using the dummy airport finite state machine, but their position isn't updated. The attached one-line patch would fix this.
Attachments
dummy-holding-stack.patch
(357 Bytes) Downloaded 436 times

richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Re: Patch: Close airports

Post by richk67 »

Juicy! One line patches may yet make trunk ;)
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

User avatar
cirdan
Director
Director
Posts: 539
Joined: 07 Apr 2007 18:08

Re: Patch: Close airports

Post by cirdan »

Ok, this is the second version of the patch. As there didn't seem to be objections to the feature itself, I've focused on the interface. After studying the code and improving my GUI skills a little (well, they couldn't get any worse), I've added a new button at the bottom of the station window, which nicely reads 'Close airport' and works as expected, so there's no more need to press ctrl, or even to guess that ctrl should be used.

The patch applies against r10765.
Attachments
airport-close-v2-r10765.patch
(4.27 KiB) Downloaded 441 times

User avatar
cirdan
Director
Director
Posts: 539
Joined: 07 Apr 2007 18:08

Re: Patch: Close airports

Post by cirdan »

Please disregard my previous patches. It appears that OpenTTD has this nice feature called 'Multiplayer' that allows several clients to play the same game and that requires, ahem, that those clients remain in sync, so you can't have code that freely modifies the game state without alerting the other clients.

The good news is that I've fixed it. The attached version of the patch is multiplayer-friendly. Clients won't desync if you close an airport, and you won't be able to close a competitor's airport.
Attachments
airport-close-v3-r10765.patch
(6.24 KiB) Downloaded 459 times

User avatar
rav
Traffic Manager
Traffic Manager
Posts: 253
Joined: 17 May 2007 13:36
Location: Netherlands
Contact:

Re: Patch: Close airports

Post by rav »

cirdan wrote:Please disregard my previous patches. It appears that OpenTTD has this nice feature called 'Multiplayer' that allows several clients to play the same game and that requires, ahem, that those clients remain in sync, so you can't have code that freely modifies the game state without alerting the other clients.

The good news is that I've fixed it. The attached version of the patch is multiplayer-friendly. Clients won't desync if you close an airport, and you won't be able to close a competitor's airport.
you might want to update the first post in this topic :)

User avatar
cirdan
Director
Director
Posts: 539
Joined: 07 Apr 2007 18:08

Re: Patch: Close airports

Post by cirdan »

rav wrote:you might want to update the first post in this topic :)
Done, thanks.

mikeel
Engineer
Engineer
Posts: 69
Joined: 03 Jun 2002 09:55

Re: Patch: Close airports

Post by mikeel »

hi, i tried to compile using build ottd but it say "Unknown patch format"...
why? I'm the only with this problem?

User avatar
cirdan
Director
Director
Posts: 539
Joined: 07 Apr 2007 18:08

Re: Patch: Close airports

Post by cirdan »

mikeel wrote:hi, i tried to compile using build ottd but it say "Unknown patch format"...
why? I'm the only with this problem?
I don't know if I can be of much help with that... I run linux, so I have little use for BuildOTTD. What I can tell you is that the patch is in standard unified format, and applies cleanly (patch -p1) against revision r10765 (and possibly others).

I've searched for the source code of BuildOTTD in SourceForge, but apparently there are only two binaries for download. Browsing through the SourceForge SVN web gateway, however, I've come to the conclusion that BuildOTTD expects patches in some specific format (which I don't know about). I can try to adapt the patch if someone tells me which format it is.

mikeel
Engineer
Engineer
Posts: 69
Joined: 03 Jun 2002 09:55

Re: Patch: Close airports

Post by mikeel »

hi
looking to other patches, i changed your code making it buildOTTD-friendly.
It's a simple change, when you declare the file you want patch you must code in this way:

Code: Select all

Index: src/aircraft_cmd.cpp
===================================================================
--- src/aircraft_cmd.cpp	(revision 10765)
+++ src/aircraft_cmd.cpp	(working copy)
I've changed the lines and now i've compiled it.

I found this patch very intresting, but i think i found a bug: when there are a lot of aircraft in queue, it's quite impossible to bulldoze the airport, becouse it says "aircraft in the way" also if the airpot is empty. maybe becouse everytime there's an aircraft trying to land?
Attachments
airport-close-v3-r10765-bottd.patch
Close Airports Patch v.3 for BuildOTTD
(6.37 KiB) Downloaded 459 times
error_closeAirport.PNG
Error trying to bulldoze an airport.
(231.11 KiB) Downloaded 581 times

User avatar
glx
OpenTTD Developer
OpenTTD Developer
Posts: 620
Joined: 02 Dec 2005 15:43
Location: Drancy(93) - France
Contact:

Re: Patch: Close airports

Post by glx »

Why not use svn diff to make the patch ?

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 3 guests