* Find a free terminal, and assign it if available. * @param v Aircraft to handle. * @param apc Airport state machine. * @return Found a free terminal and assigned it. */
| 2005 | * @return Found a free terminal and assigned it. |
| 2006 | */ |
| 2007 | static bool AirportFindFreeTerminal(Aircraft *v, const AirportFTAClass *apc) |
| 2008 | { |
| 2009 | /* example of more terminalgroups |
| 2010 | * {0,HANGAR,AirportBlock::Nothing,1}, {0,TERMGROUP,AirportBlock::TermGroup1,0}, {0,TERMGROUP,TERM_GROUP2_ENTER_block,1}, {0,0,N,1}, |
| 2011 | * Heading TERMGROUP denotes a group. We see 2 groups here: |
| 2012 | * 1. group 0 -- AirportBlock::TermGroup1 (check block) |
| 2013 | * 2. group 1 -- TERM_GROUP2_ENTER_block (check block) |
| 2014 | * First in line is checked first, group 0. If the block (AirportBlock::TermGroup1) is free, it |
| 2015 | * looks at the corresponding terminals of that group. If no free ones are found, other |
| 2016 | * possible groups are checked (in this case group 1, since that is after group 0). If that |
| 2017 | * fails, then attempt fails and plane waits |
| 2018 | */ |
| 2019 | if (apc->terminals[0] > 1) { |
| 2020 | const Station *st = Station::Get(v->targetairport); |
| 2021 | const AirportFTA *temp = apc->layout[v->pos].next.get(); |
| 2022 | |
| 2023 | while (temp != nullptr) { |
| 2024 | if (temp->heading == TERMGROUP) { |
| 2025 | if (!st->airport.blocks.Any(temp->blocks)) { |
| 2026 | /* read which group do we want to go to? |
| 2027 | * (the first free group) */ |
| 2028 | uint target_group = temp->next_position + 1; |
| 2029 | |
| 2030 | /* at what terminal does the group start? |
| 2031 | * that means, sum up all terminals of |
| 2032 | * groups with lower number */ |
| 2033 | uint group_start = 0; |
| 2034 | for (uint i = 1; i < target_group; i++) { |
| 2035 | group_start += apc->terminals[i]; |
| 2036 | } |
| 2037 | |
| 2038 | uint group_end = group_start + apc->terminals[target_group]; |
| 2039 | if (FreeTerminal(v, group_start, group_end)) return true; |
| 2040 | } |
| 2041 | } else { |
| 2042 | /* once the heading isn't 255, we've exhausted the possible blocks. |
| 2043 | * So we cannot move */ |
| 2044 | return false; |
| 2045 | } |
| 2046 | temp = temp->next.get(); |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | /* if there is only 1 terminalgroup, all terminals are checked (starting from 0 to max) */ |
| 2051 | return FreeTerminal(v, 0, GetNumTerminals(apc)); |
| 2052 | } |
| 2053 | |
| 2054 | /** |
| 2055 | * Find a free helipad, and assign it if available. |
no test coverage detected