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

Function ShipTestUpDownOnLock

src/ship_cmd.cpp:566–584  ·  view source on GitHub ↗

* Test if a ship is in the centre of a lock and should move up or down. * @param v Ship being tested. * @return 0 if ship is not moving in lock, or -1 to move down, 1 to move up. */

Source from the content-addressed store, hash-verified

564 * @return 0 if ship is not moving in lock, or -1 to move down, 1 to move up.
565 */
566static int ShipTestUpDownOnLock(const Ship *v)
567{
568 /* Suitable tile? */
569 if (!IsTileType(v->tile, MP_WATER) || !IsLock(v->tile) || GetLockPart(v->tile) != LockPart::Middle) return 0;
570
571 /* Must be at the centre of the lock */
572 if ((v->x_pos & 0xF) != 8 || (v->y_pos & 0xF) != 8) return 0;
573
574 DiagDirection diagdir = GetInclinedSlopeDirection(GetTileSlope(v->tile));
575 assert(IsValidDiagDirection(diagdir));
576
577 if (DirToDiagDir(v->direction) == diagdir) {
578 /* Move up */
579 return (v->z_pos < GetTileMaxZ(v->tile) * (int)TILE_HEIGHT) ? 1 : 0;
580 } else {
581 /* Move down */
582 return (v->z_pos > GetTileZ(v->tile) * (int)TILE_HEIGHT) ? -1 : 0;
583 }
584}
585
586/**
587 * Test and move a ship up or down in a lock.

Callers 1

ShipMoveUpDownOnLockFunction · 0.85

Calls 9

IsTileTypeFunction · 0.85
IsLockFunction · 0.85
GetLockPartFunction · 0.85
GetTileSlopeFunction · 0.85
IsValidDiagDirectionFunction · 0.85
DirToDiagDirFunction · 0.85
GetTileMaxZFunction · 0.85
GetTileZFunction · 0.85

Tested by

no test coverage detected