* 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. */
| 564 | * @return 0 if ship is not moving in lock, or -1 to move down, 1 to move up. |
| 565 | */ |
| 566 | static 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. |
no test coverage detected