Transport Tycoon Forums

The place to talk about Transport Tycoon
It is currently Thu Sep 02, 2010 5:58 pm

All times are UTC




Post new topic Reply to topic  [ 186 posts ]  Go to page 1, 2, 3, 4, 5 ... 10  Next
Author Message
 Post subject: Patch: Close airports
PostPosted: Wed Aug 01, 2007 4:03 pm 
Traffic Manager
Traffic Manager
User avatar
Offline

Joined: Sat Apr 07, 2007 6:08 pm
Posts: 177
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 | 0.7.x - disable | 0.7.x - hide | 1.0.0 - disable | 1.0.0 - hide | 1.0.1 - disable | 1.0.1 - hide | r19740 - disable | r19740 - hide

_________________
My patches: Close airports | Upgrade airports


Last edited by cirdan on Sat May 01, 2010 2:45 pm, edited 13 times in total.

Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Wed Aug 01, 2007 5:04 pm 
Traffic Manager
Traffic Manager
User avatar
Offline

Joined: Thu May 17, 2007 1:36 pm
Posts: 253
Location: Netherlands
wow, thanks! :o

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

_________________
Image
alternate airport building rules (r10663)


Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Wed Aug 01, 2007 5:42 pm 
Engineer
Engineer
User avatar
Offline

Joined: Wed Apr 28, 2004 10:07 am
Posts: 58
Location: Salzburg
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....

_________________
*<(:-}


Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Wed Aug 01, 2007 6:28 pm 
Tycoon
Tycoon
Offline

Joined: Mon Oct 25, 2004 3:39 pm
Posts: 4349
Location: Mississauga
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


Top
 Profile E-mail  
 
 Post subject: Re: Patch: Close airports
PostPosted: Wed Aug 01, 2007 7:05 pm 
Traffic Manager
Traffic Manager
User avatar
Offline

Joined: Sat Apr 07, 2007 6:08 pm
Posts: 177
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.

_________________
My patches: Close airports | Upgrade airports


Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Wed Aug 01, 2007 7:11 pm 
Tycoon
Tycoon
Offline

Joined: Mon Oct 25, 2004 3:39 pm
Posts: 4349
Location: Mississauga
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


Top
 Profile E-mail  
 
 Post subject: Re: Patch: Close airports
PostPosted: Wed Aug 01, 2007 10:52 pm 
Tycoon
Tycoon
Offline

Joined: Thu Jun 05, 2003 4:21 pm
Posts: 2358
Location: Up North
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


Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Thu Aug 02, 2007 6:01 am 
Engineer
Engineer
User avatar
Offline

Joined: Thu Mar 25, 2004 12:32 am
Posts: 97
Great; very useful.

Please add it to all stations. ;)

_________________
A better OS: http://ubuntu.com/
Soon an even better OS: http://haiku-os.org/


Top
 Profile E-mail  
 
 Post subject: Re: Patch: Close airports
PostPosted: Thu Aug 02, 2007 8:04 am 
Traffic Manager
Traffic Manager
User avatar
Offline

Joined: Sat Apr 07, 2007 6:08 pm
Posts: 177
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 143 times

_________________
My patches: Close airports | Upgrade airports
Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Thu Aug 02, 2007 9:08 am 
Tycoon
Tycoon
Offline

Joined: Thu Jun 05, 2003 4:21 pm
Posts: 2358
Location: Up North
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


Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Thu Aug 02, 2007 11:04 am 
Traffic Manager
Traffic Manager
User avatar
Offline

Joined: Sat Apr 07, 2007 6:08 pm
Posts: 177
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 145 times

_________________
My patches: Close airports | Upgrade airports
Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Thu Aug 02, 2007 11:19 am 
Tycoon
Tycoon
Offline

Joined: Thu Jun 05, 2003 4:21 pm
Posts: 2358
Location: Up North
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


Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Sat Aug 04, 2007 1:47 pm 
Traffic Manager
Traffic Manager
User avatar
Offline

Joined: Sat Apr 07, 2007 6:08 pm
Posts: 177
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 132 times

_________________
My patches: Close airports | Upgrade airports
Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Sun Aug 05, 2007 2:43 pm 
Traffic Manager
Traffic Manager
User avatar
Offline

Joined: Sat Apr 07, 2007 6:08 pm
Posts: 177
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 151 times

_________________
My patches: Close airports | Upgrade airports
Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Sun Aug 05, 2007 3:17 pm 
Traffic Manager
Traffic Manager
User avatar
Offline

Joined: Thu May 17, 2007 1:36 pm
Posts: 253
Location: Netherlands
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 :)

_________________
Image
alternate airport building rules (r10663)


Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Sun Aug 05, 2007 3:40 pm 
Traffic Manager
Traffic Manager
User avatar
Offline

Joined: Sat Apr 07, 2007 6:08 pm
Posts: 177
rav wrote:
you might want to update the first post in this topic :)

Done, thanks.

_________________
My patches: Close airports | Upgrade airports


Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Fri Aug 10, 2007 1:34 pm 
Engineer
Engineer
Offline

Joined: Mon Jun 03, 2002 9:55 am
Posts: 66
hi, i tried to compile using build ottd but it say "Unknown patch format"...
why? I'm the only with this problem?


Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Fri Aug 10, 2007 2:53 pm 
Traffic Manager
Traffic Manager
User avatar
Offline

Joined: Sat Apr 07, 2007 6:08 pm
Posts: 177
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.

_________________
My patches: Close airports | Upgrade airports


Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Fri Aug 10, 2007 4:11 pm 
Engineer
Engineer
Offline

Joined: Mon Jun 03, 2002 9:55 am
Posts: 66
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:
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:
File comment: Close Airports Patch v.3 for BuildOTTD
airport-close-v3-r10765-bottd.patch [6.37 KiB]
Downloaded 130 times
File comment: Error trying to bulldoze an airport.
error_closeAirport.PNG [231.11 KiB]
Downloaded 579 times
Top
 Profile  
 
 Post subject: Re: Patch: Close airports
PostPosted: Fri Aug 10, 2007 5:17 pm 
OpenTTD Developer
OpenTTD Developer
User avatar
Offline

Joined: Fri Dec 02, 2005 3:43 pm
Posts: 618
Location: Drancy(93) - France
Why not use svn diff to make the patch ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 186 posts ]  Go to page 1, 2, 3, 4, 5 ... 10  Next

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot], philipabbott and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Wordpress Theme | Adsense Paying Keywords | Submit articles | Submit articles | Debt Help
Powered by phpBB © 2000-2009 phpBB Group

Copyright © Owen Rudge/The Transport Tycoon Forums 2001-2010.
Hosted by Zernebok.