diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt index ec18e59e..fbdef3bf 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/ServerConnection.kt @@ -309,40 +309,44 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn var currentFlightJob: Job? = null + suspend fun flyShipInSystem(location: SystemWorldLocation) { + currentFlightJob?.cancel() + val flight = world.flyShip(this, location) + + shipWorld.eventLoop.execute { + shipWorld.sky.startFlying(false) + } + + currentFlightJob = scope.launch { + systemWorldLocation = location + val coords = flight.await() + val action = coords.orbitalAction(world) + currentOrbitalWarpAction = action + + for (client in shipWorld.clients) { + client.client.orbitalWarpAction = action + } + + val sky = coords.skyParameters(world) + + shipWorld.eventLoop.execute { + shipWorld.sky.stopFlyingAt(sky) + } + } + + currentOrbitalWarpAction = KOptional() + + for (client in shipWorld.clients) { + client.client.orbitalWarpAction = KOptional() + } + } + while (true) { val (system, location) = flyShipQueue.receive() if (system == world.location) { // fly ship in current system - currentFlightJob?.cancel() - val flight = world.flyShip(this, location) - - shipWorld.eventLoop.execute { - shipWorld.sky.startFlying(false) - } - - currentFlightJob = scope.launch { - systemWorldLocation = location - val coords = flight.await() - val action = coords.orbitalAction(world) - currentOrbitalWarpAction = action - - for (client in shipWorld.clients) { - client.client.orbitalWarpAction = action - } - - val sky = coords.skyParameters(world) - - shipWorld.eventLoop.execute { - shipWorld.sky.stopFlyingAt(sky) - } - } - - currentOrbitalWarpAction = KOptional() - - for (client in shipWorld.clients) { - client.client.orbitalWarpAction = KOptional() - } + flyShipInSystem(location) } else { // we need to travel to other system val exists = server.universe.parameters(UniversePos(system)) != null @@ -378,6 +382,11 @@ class ServerConnection(val server: StarboundServer, type: ConnectionType) : Conn // this seems to be way too big isn't it? delay((Globals.universeServer.queuedFlightWaitTime * 1000.0).toLong()) + + if (location != SystemWorldLocation.Transit) { + // player clicked on specific planet in remote system view + flyShipInSystem(location) + } } } } diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerSystemWorld.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerSystemWorld.kt index 6770aea2..b0f29af1 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerSystemWorld.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/server/world/ServerSystemWorld.kt @@ -182,6 +182,7 @@ class ServerSystemWorld : SystemWorld { var diff = Globals.systemWorld.objectSpawnCycle.coerceAtMost(clock.time - lastSpawn) lastSpawn = clock.time - diff + // persistent spawning (e.g. we simulate time passing as if we were always loaded) while (diff > objectSpawnTime) { lastSpawn += objectSpawnTime objectSpawnTime = random.nextRange(Globals.systemWorld.objectSpawnInterval)