| 411 | } |
| 412 | |
| 413 | static currency32_t createPort(const PortPlacementArgs& args, const uint8_t flags) |
| 414 | { |
| 415 | setExpenditureType(ExpenditureType::Construction); |
| 416 | setPosition(args.pos + World::Pos3(16, 16, 0)); |
| 417 | |
| 418 | auto& returnState = getLegacyReturnState(); |
| 419 | returnState.lastPlacedDock = StationId::null; |
| 420 | returnState.lastConstructedAdjoiningStationPos = World::Pos2(-1, -1); |
| 421 | returnState.lastConstructedAdjoiningStation = StationId::null; |
| 422 | |
| 423 | if ((flags & Flags::apply) && !(flags & Flags::aiAllocated)) |
| 424 | { |
| 425 | companySetObservation(getUpdatingCompanyId(), ObservationStatus::buildingDock, World::Pos2(args.pos) + World::Pos2{ 16, 16 }, EntityId::null, args.type); |
| 426 | } |
| 427 | |
| 428 | if (!World::TileManager::checkFreeElementsAndReorganise()) |
| 429 | { |
| 430 | return kFailure; |
| 431 | } |
| 432 | |
| 433 | for (auto& frontTile : kRotationToBuildingFront[args.rotation]) |
| 434 | { |
| 435 | const auto frontPos = frontTile + args.pos; |
| 436 | if (!tileHasWater(frontPos)) |
| 437 | { |
| 438 | setErrorText(StringIds::requires_water_in_front_of_dock); |
| 439 | return kFailure; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | if ((flags & Flags::ghost) && (flags & Flags::apply)) |
| 444 | { |
| 445 | returnState.lastConstructedAdjoiningStationPos = args.pos; |
| 446 | auto nearbyStation = flags & Flags::aiAllocated ? findNearbyStationDocksAi(args.pos) : findNearbyStationDocks(args.pos); |
| 447 | returnState.lastConstructedAdjoiningStation = nearbyStation.id; |
| 448 | } |
| 449 | |
| 450 | if (!(flags & Flags::ghost)) |
| 451 | { |
| 452 | if (flags & Flags::apply) |
| 453 | { |
| 454 | auto [result, nearbyStationId] = validateNearbyStation(args.pos, flags); |
| 455 | switch (result) |
| 456 | { |
| 457 | case NearbyStationValidation::failure: |
| 458 | // Odd??? |
| 459 | break; |
| 460 | case NearbyStationValidation::requiresNewStation: |
| 461 | { |
| 462 | const auto newStationId = StationManager::allocateNewStation(args.pos, getUpdatingCompanyId(), 3); |
| 463 | if (newStationId != StationId::null) |
| 464 | { |
| 465 | returnState.lastPlacedDock = newStationId; |
| 466 | auto* station = StationManager::get(newStationId); |
| 467 | station->updateLabel(); |
| 468 | } |
| 469 | } |
| 470 | break; |
nothing calls this directly
no test coverage detected