[Patch] Open/Close Airport for Aircraft

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

Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

pduthie_au wrote:Got it. Ok, now to work out how to send an Aircraft to the nearest hangar, but leave the current destination correct even if the station is closed, so when it opens it immediately goes to the correct station.
You make current order to goto depot and then it enters the depot (VehicleEnterDepot() in vehicle.c) it resumes the real order. Then you prevent it from leaving by preventing it from leaving the hangar if the flag for target station is set. I'm not 100% sure, but I think this should be done from AircraftEventHandler_InHangar() in aircraft_cmd.c. Maybe as the last check before AircraftLeaveHangar(v). If (flag set) return;

This should also ensure that the aircraft will start on it's own when the airport is ready to be used again.
User avatar
pduthie_au
Engineer
Engineer
Posts: 32
Joined: 31 Aug 2006 01:33

Post by pduthie_au »

Ok, I've tried setting the current order to OT_GOTO_DEPOT, but how do I stop it from going to the depot at the closed airport if that is the closest depot. Anyone have any ideas ?
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

pduthie_au wrote:Ok, I've tried setting the current order to OT_GOTO_DEPOT, but how do I stop it from going to the depot at the closed airport if that is the closest depot. Anyone have any ideas ?
I think now would be a good time to post a diff file. Answering that question would be easier if I know what you did so far :wink:
User avatar
pduthie_au
Engineer
Engineer
Posts: 32
Joined: 31 Aug 2006 01:33

Post by pduthie_au »

Ok, I will post one, but I think the latest is the one in the first post. I'm working through this like this :

1. Get Aircraft to skip closed stations - done
2. Get Aircraft to goto a hangar if the next station is closed
3. Get Aircraft to stay in hangar if the next station is closed
4. Get Aircraft to goto a hangar if none of their orders are to an open station.

I will post what I have, but it's at home unfortunately.
User avatar
pduthie_au
Engineer
Engineer
Posts: 32
Joined: 31 Aug 2006 01:33

Post by pduthie_au »

Ok, I have the redirect to another airport and hangar working (although I just thought, it doesn't check to ensure that the new target airport is open). Updated code has been posted in the first post.
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

You should use FindNearestHangar() instead of duplicating the code. Also if the aircraft is on the ground in an airport with a hangar and it's not closing, it should head for the hangar instead of looping all stations to find the station it's already in :wink:

As for the windows, we had feedback on coloouring some text telling about colourblind people, so we decided not to display info based on text colur only. I think you should make the buttons pressed when they are active. This can be done by

Code: Select all

SetWindowWidgetLoweredState(w, WIDGET_CLOSE_AIRCRAFT, HASBIT(st->closed_to_vehicletype, VEH_Aircraft - VEH_Train))
Modify this line as needed for each button.

Another thing. "HASBIT(st->closed_to_vehicletype,v->type - VEH_Train)" looks a bit messy, so make it a static inline function like

Code: Select all

static inline IsStationClosedForVehicle(Station *st, Vehicle *v)
{
   return HASBIT(st->closed_to_vehicletype,v->type-VEH_Train);
}

IsStationClosedForVehicleType(Station *st, byte vehicle_type)
{
   return HASBIT(st->closed_to_vehicletype, vehicle_type - VEH_Train);
}
This will make the code easier to read. I think the right place for such functions will be station.h
The first line of code will then look like

Code: Select all

SetWindowWidgetLoweredState(w, WIDGET_CLOSE_AIRCRAFT, IsStationClosedForVehicleType(st, VEH_Aircraft))
User avatar
pduthie_au
Engineer
Engineer
Posts: 32
Joined: 31 Aug 2006 01:33

Post by pduthie_au »

Bjarni wrote:You should use FindNearestHangar() instead of duplicating the code. Also if the aircraft is on the ground in an airport with a hangar and it's not closing, it should head for the hangar instead of looping all stations to find the station it's already in :wink:
I'm thinking that it would be better to send the aircraft to a hangar closest to the closed airport, not closest to the aircrafts current location. Maybe I should convert it to a function so other people might be able to use it if necessary.
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

pduthie_au wrote:I'm thinking that it would be better to send the aircraft to a hangar closest to the closed airport, not closest to the aircrafts current location. Maybe I should convert it to a function so other people might be able to use it if necessary.
Good point but is it wise to send the planes to an airport, that's not in their orders. Say we got one airport, that's maxed out and is not that big and a nearby airport got a much larger capacity, but we are replacing it because we need it to be even bigger, then the "small" airport will be totally blocked for the normal traffic with all the planes going there just to enter the depot. We know that it should not hurt a lot to enter a depot in the airport it's already in.
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

Just a thought, but could you have it that an aircraft heads for its closed airport, and if still closed at 20 tiles to go, it enters a holding pattern. (This would need new code as the airport holding patterns are part of the airport movement code - this would be something extra.)

If while in the holding pattern, it needs a service, then it routes to the nearest (open) hangar.

The big advantage of this, is that it disrupts the movement the least - aircraft are waiting in the area for the airport to reopen, not hidden in nearby airport hangars.
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
pduthie_au
Engineer
Engineer
Posts: 32
Joined: 31 Aug 2006 01:33

Post by pduthie_au »

richk67 wrote:Just a thought, but could you have it that an aircraft heads for its closed airport, and if still closed at 20 tiles to go, it enters a holding pattern. (This would need new code as the airport holding patterns are part of the airport movement code - this would be something extra.)

If while in the holding pattern, it needs a service, then it routes to the nearest (open) hangar.

The big advantage of this, is that it disrupts the movement the least - aircraft are waiting in the area for the airport to reopen, not hidden in nearby airport hangars.
Good idea, but isn't the holding pattern code part of MiniIN ? The latest version of this patch will be for the Trunk as it uses some of the new widget stuff that hasn't (or at least I couldn't find in the last version I synced a few minutes ago).

Not sure how to avoid the full airport issue, and I can't get the code to send to the airport on the current one to work. I'm about to upload the Trunk version. I'll leave the previous MiniIN one there for now as well. Have a look and let me know what you think.

EDIT: Just noticed that the buttons don't quite look right. I'll try and fix that - the spacings in the widgets aren't quite right and the text overlaps.

Code: Select all

{ WWT_PUSHTXTBTN,	RESIZE_NONE,	14,	    0,	  61,	110,   120, STR_STATION_OPEN_TRAIN,  STR_STATION_OPEN_TRAIN_TIP},
{ WWT_PUSHTXTBTN,	RESIZE_NONE,	14,	  62,	 123,	110,   120, STR_STATION_OPEN_ROAD,  STR_STATION_OPEN_ROAD_TIP},
{ WWT_PUSHTXTBTN,	RESIZE_NONE,	14,	  124,	 185,	110,   120, STR_STATION_OPEN_SHIP,  STR_STATION_OPEN_SHIP_TIP},
{ WWT_PUSHTXTBTN,	RESIZE_NONE,	14,	  186,	 247,	110,   120, STR_STATION_OPEN_AIRCRAFT,  STR_STATION_OPEN_AIRCRAFT_TIP},
Attached is screenshot for the Trunk version.
Attachments
Screenshot with various windows open with buttons pressed various ways. Trunk Version
Screenshot with various windows open with buttons pressed various ways. Trunk Version
Screenshot with multiple stations with vehicle acceptance buttons trunk version.png (52.58 KiB) Viewed 779 times
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

pduthie_au wrote:EDIT: Just noticed that the buttons don't quite look right. I'll try and fix that - the spacings in the widgets aren't quite right and the text overlaps.

Code: Select all

{ WWT_PUSHTXTBTN,	RESIZE_NONE,	14,	    0,	  61,	110,   120, STR_STATION_OPEN_TRAIN,  STR_STATION_OPEN_TRAIN_TIP},
Each text widget should be 11 pixels tall, not 10, so the low end should be 121
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

pduthie_au wrote:
richk67 wrote:Just a thought...
Good idea, but isn't the holding pattern code part of MiniIN ? The latest version of this patch will be for the Trunk as it uses some of the new widget stuff that hasn't (or at least I couldn't find in the last version I synced a few minutes ago).
Great - if this is going in trunk, thats great news. Congrats.

The aircraft movements are all in trunk - MiniIN has no special airport movement code, it just syncs with trunk. What would work would to have an airport type called "holding pattern", which has a circular pattern, and once each circuit it tests to see if the aircraft is released for onward flight to the newly opened airport. I could throw something together once the core open/close airport code is in place. (Its a really simple airport state machine - should be 5-6 states... a FLYING, 4 for the circling motion, maybe one special new state for leaving the loop.)

It may be possible to borrow the aircraft movement code from the Aircraft queueing patch, but that hasnt been added to MiniIN yet. (One day maybe - Im having a bit of a break ATM).
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
pduthie_au
Engineer
Engineer
Posts: 32
Joined: 31 Aug 2006 01:33

Post by pduthie_au »

I don't know if this is going into the Trunk, but it would be unlikely given that it's my first project and uses some really nasty stuff to work at the moment. The main thing I couldn't work out in the MiniIN is how to make a widget lowered. The new widget stuff in the trunk makes this easy, but can anyone point me to some current MiniIN code that lowers a widget that I could duplicate for the MiniIN version ?

The bulk of the code is now in place, if someone wants to put together a circling path that aircraft could use until their next destination opened up that would be great.

I'm just grabbing the Airport queueing stuff now, and have grabbed a version of the 6612 trunk (which is what the current patch is for) and I'll have a look. At first glance, it appears that there is a section that checks if an aircraft can land, so I'll have a look there and see what I can come up with.

EDIT: Well that was easy ! Aircraft now simply circle a closed airport. Much easier than looking for a new airport, and going to the hangar. I simply changed :

Code: Select all

if (!AirportHasBlock(v, current, Airport)) {
in aircraft_cmd.c:AircraftEventHandler_Flying

to

Code: Select all

if ((!AirportHasBlock(v, current, Airport)) && (can_land)) {
And earlier in the function did this :

Code: Select all

can_land=!IsStationClosedForVehicle(st,v);
And it works ! Don't know why I didn't investigate this earlier. I was thinking too hard about diverting to other airports instead of simply blocking aircraft from landing at a closed airport.

I just did a test with 16 aircraft, and it looks really odd with 16 aircraft circling an airport.

Just wondering though, would it be an idea for a diversion to be put in place to send an aircraft to another airport if all of its orders are to closed airports ? Or just leave them to circle ?
User avatar
pduthie_au
Engineer
Engineer
Posts: 32
Joined: 31 Aug 2006 01:33

Post by pduthie_au »

Ok, first post has been updated with a new MiniIN version. It currently still uses the colour change because I couldn't work out how to make a button lowered, but other than that functionality is the same.
User avatar
belugas
OpenTTD Developer
OpenTTD Developer
Posts: 1507
Joined: 05 Apr 2005 01:48
Location: Deep down the deepest blue
Contact:

Post by belugas »

pduthie_au wrote:Ok, first post has been updated with a new MiniIN version. It currently still uses the colour change because I couldn't work out how to make a button lowered, but other than that functionality is the same.
in MiniIN, since it is not synched, you would need to access the click_state member of the Window struct.
Typically, you would need to set/clear a bit in that 32bit member, representing the widget to lower/raise.
So, somethink like :

Code: Select all

SETBIT(w->click_state, widget_index);
or even better (a bit like what the "new widget stuff" is using)

Code: Select all

SB(w->click_state, widget_index,  bool_state_of_raised/lower);
If you are not ready to work a bit for your ideas, it means they don't count much for you.
OpenTTD and Realism? Well... Here are a few thoughs on the matter.
He he he he
------------------------------------------------------------
Music from the Bloody Time Zones
User avatar
pduthie_au
Engineer
Engineer
Posts: 32
Joined: 31 Aug 2006 01:33

Post by pduthie_au »

Ok, thanks for that - I'll give it a try later on today and see how I go.
User avatar
pduthie_au
Engineer
Engineer
Posts: 32
Joined: 31 Aug 2006 01:33

Post by pduthie_au »

Can anyone help me with where I should put code to keep a road vehicle or ship in a depot ? I tried simply sending it to a depot, but it either says it's going to a depot and but actually goes to the closed station or goes to the depot, leaves again and then crashes the game. Anyone have any ideas ?
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

pduthie_au wrote:Can anyone help me with where I should put code to keep a road vehicle or ship in a depot ? I tried simply sending it to a depot, but it either says it's going to a depot and but actually goes to the closed station or goes to the depot, leaves again and then crashes the game. Anyone have any ideas ?
Look in SendAllVehiclesToDepot() in vehicle.c, mainly at

Code: Select all

DoCommand(v->tile, v->index, service | DEPOT_DONT_CANCEL, flags, CMD_SEND_TO_DEPOT(type));
This will send the vehicle to a depot and make it stay there if service is not set. If it is set, then they will leave right away. I presume that they got some check to see if they can leave in [roadveh, ship, train]_cmd.c and you can make them stay in the depot if they should not leave. This way the vehicles will leave once the station is reopened.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 10 guests