MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / AirportMove

Function AirportMove

src/aircraft_cmd.cpp:1824–1869  ·  view source on GitHub ↗

gets pos from vehicle and next orders */

Source from the content-addressed store, hash-verified

1822
1823/* gets pos from vehicle and next orders */
1824static bool AirportMove(Aircraft *v, const AirportFTAClass *apc)
1825{
1826 /* error handling */
1827 if (v->pos >= apc->nofelements) {
1828 Debug(misc, 0, "[Ap] position {} is not valid for current airport. Max position is {}", v->pos, apc->nofelements - 1);
1829 assert(v->pos < apc->nofelements);
1830 }
1831
1832 const AirportFTA *current = &apc->layout[v->pos];
1833 /* we have arrived in an important state (eg terminal, hangar, etc.) */
1834 if (current->heading == v->state) {
1835 uint8_t prev_pos = v->pos; // location could be changed in state, so save it before-hand
1836 uint8_t prev_state = v->state;
1837 _aircraft_state_handlers[v->state](v, apc);
1838 if (v->state != FLYING) v->previous_pos = prev_pos;
1839 if (v->state != prev_state || v->pos != prev_pos) UpdateAircraftCache(v);
1840 return true;
1841 }
1842
1843 v->previous_pos = v->pos; // save previous location
1844
1845 /* there is only one choice to move to */
1846 if (current->next == nullptr) {
1847 if (AirportSetBlocks(v, current, apc)) {
1848 v->pos = current->next_position;
1849 UpdateAircraftCache(v);
1850 } // move to next position
1851 return false;
1852 }
1853
1854 /* there are more choices to choose from, choose the one that
1855 * matches our heading */
1856 do {
1857 if (v->state == current->heading || current->heading == TO_ALL) {
1858 if (AirportSetBlocks(v, current, apc)) {
1859 v->pos = current->next_position;
1860 UpdateAircraftCache(v);
1861 } // move to next position
1862 return false;
1863 }
1864 current = current->next.get();
1865 } while (current != nullptr);
1866
1867 Debug(misc, 0, "[Ap] cannot move further on Airport! (pos {} state {}) for vehicle {}", v->pos, v->state, v->index);
1868 NOT_REACHED();
1869}
1870
1871/** returns true if the road ahead is busy, eg. you must wait before proceeding. */
1872static bool AirportHasBlock(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)

Callers 3

AirportGoToNextPositionFunction · 0.85

Calls 4

UpdateAircraftCacheFunction · 0.85
AirportSetBlocksFunction · 0.85
NOT_REACHEDFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected