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

Function SetAircraftPosition

src/aircraft_cmd.cpp:532–565  ·  view source on GitHub ↗

* Set aircraft position. * @param v Aircraft to position. * @param x New X position. * @param y New y position. * @param z New z position. */

Source from the content-addressed store, hash-verified

530 * @param z New z position.
531 */
532void SetAircraftPosition(Aircraft *v, int x, int y, int z)
533{
534 v->x_pos = x;
535 v->y_pos = y;
536 v->z_pos = z;
537
538 v->UpdatePosition();
539 v->UpdateViewport(true, false);
540 if (v->subtype == AIR_HELICOPTER) {
541 GetRotorImage(v, EIT_ON_MAP, &v->Next()->Next()->sprite_cache.sprite_seq);
542 }
543
544 Aircraft *u = v->Next();
545
546 int safe_x = Clamp(x, 0, Map::MaxX() * TILE_SIZE);
547 int safe_y = Clamp(y - 1, 0, Map::MaxY() * TILE_SIZE);
548 u->x_pos = x;
549 u->y_pos = y - ((v->z_pos - GetSlopePixelZ(safe_x, safe_y)) >> 3);
550
551 safe_y = Clamp(u->y_pos, 0, Map::MaxY() * TILE_SIZE);
552 u->z_pos = GetSlopePixelZ(safe_x, safe_y);
553 u->sprite_cache.sprite_seq.CopyWithoutPalette(v->sprite_cache.sprite_seq); // the shadow is never coloured
554
555 u->UpdatePositionAndViewport();
556
557 u = u->Next();
558 if (u != nullptr) {
559 u->x_pos = x;
560 u->y_pos = y;
561 u->z_pos = z + ROTOR_Z_OFFSET;
562
563 u->UpdatePositionAndViewport();
564 }
565}
566
567/**
568 * Handle Aircraft specific tasks when an Aircraft enters a hangar

Callers 6

AircraftControllerFunction · 0.85
HandleCrashedAircraftFunction · 0.85
AircraftLeaveHangarFunction · 0.85
AfterLoadGameFunction · 0.85
UpdateOldAircraftFunction · 0.85

Calls 8

GetRotorImageFunction · 0.85
ClampFunction · 0.85
GetSlopePixelZFunction · 0.85
CopyWithoutPaletteMethod · 0.80
UpdatePositionMethod · 0.45
UpdateViewportMethod · 0.45
NextMethod · 0.45

Tested by

no test coverage detected