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

Function AirportSetBlocks

src/aircraft_cmd.cpp:1903–1939  ·  view source on GitHub ↗

* "reserve" a block for the plane * @param v airplane that requires the operation * @param current_pos of the vehicle in the list of blocks * @param apc airport on which block is requested to be set * @returns true on success. Eg, next block was free and we have occupied it */

Source from the content-addressed store, hash-verified

1901 * @returns true on success. Eg, next block was free and we have occupied it
1902 */
1903static bool AirportSetBlocks(Aircraft *v, const AirportFTA *current_pos, const AirportFTAClass *apc)
1904{
1905 const AirportFTA *next = &apc->layout[current_pos->next_position];
1906 const AirportFTA *reference = &apc->layout[v->pos];
1907
1908 /* if the next position is in another block, check it and wait until it is free */
1909 if (!apc->layout[current_pos->position].blocks.All(next->blocks)) {
1910 AirportBlocks blocks = next->blocks;
1911 /* search for all all elements in the list with the same state, and blocks != N
1912 * this means more blocks should be checked/set */
1913 const AirportFTA *current = current_pos;
1914 if (current == reference) current = current->next.get();
1915 while (current != nullptr) {
1916 if (current->heading == current_pos->heading && current->blocks.Any()) {
1917 blocks.Set(current->blocks);
1918 break;
1919 }
1920 current = current->next.get();
1921 }
1922
1923 /* if the block to be checked is in the next position, then exclude that from
1924 * checking, because it has been set by the airplane before */
1925 if (current_pos->blocks == next->blocks) blocks.Flip(next->blocks);
1926
1927 Station *st = Station::Get(v->targetairport);
1928 if (st->airport.blocks.Any(blocks)) {
1929 v->cur_speed = 0;
1930 v->subspeed = 0;
1931 return false;
1932 }
1933
1934 if (next->blocks != AirportBlock::Nothing) {
1935 st->airport.blocks.Set(blocks); // occupy next block
1936 }
1937 }
1938 return true;
1939}
1940
1941/**
1942 * Combination of aircraft state for going to a certain terminal and the

Callers 1

AirportMoveFunction · 0.85

Calls 4

AllMethod · 0.80
AnyMethod · 0.80
getMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected