Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/gabber235/TypeWriter int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
Marten-Mrfc committed Sep 6, 2024
2 parents 5c2ac53 + a80c494 commit cde7dd2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 17 deletions.
6 changes: 5 additions & 1 deletion discord_bot/src/discord/create_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
Context, WinstonError,
};
use poise::{
serenity_prelude::{CreateEmbed, CreateMessage},
serenity_prelude::{CreateEmbed, CreateMessage, EditThread},
CreateReply,
};

Expand Down Expand Up @@ -79,6 +79,10 @@ pub async fn create_task(
)
.await?;

channel
.edit_thread(ctx, EditThread::default().name(title))
.await?;

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions discord_bot/src/webhooks/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async fn update_discord_channel(task_id: &str, moved: bool) -> Result<(), Winsto
.edit_thread(
&discord,
EditThread::default()
.name(task.name)
.applied_tags(new_tags)
.locked(lock)
.archived(lock),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package com.typewritermc.engine.paper.entry.roadnetwork.gps

import com.extollit.gaming.ai.path.HydrazinePathFinder
import com.extollit.gaming.ai.path.model.*
import com.typewritermc.core.entries.Ref
import com.typewritermc.core.utils.point.Vector
import com.typewritermc.engine.paper.entry.entity.toProperty
import com.typewritermc.engine.paper.entry.entries.RoadNetworkEntry
import com.typewritermc.engine.paper.entry.entries.RoadNode
import com.typewritermc.engine.paper.entry.entries.roadNetworkMaxDistance
import com.typewritermc.engine.paper.entry.roadnetwork.pathfinding.PFEmptyEntity
import com.typewritermc.engine.paper.entry.roadnetwork.pathfinding.PFInstanceSpace
import com.typewritermc.core.utils.point.Vector
import com.typewritermc.engine.paper.utils.distanceSqrt
import org.bukkit.Location

interface GPS {
val roadNetwork: Ref<RoadNetworkEntry>
suspend fun findPath(): Result<List<GPSEdge>>
}

Expand All @@ -23,14 +26,23 @@ data class GPSEdge(
val isFastTravel: Boolean
get() = weight == 0.0
}

fun roadNetworkFindPath(
start: RoadNode,
end: RoadNode,
entity: IPathingEntity = PFEmptyEntity(start.location.toProperty(), searchRange = roadNetworkMaxDistance.toFloat()),
instance: PFInstanceSpace = PFInstanceSpace(start.location.world),
nodes: List<RoadNode> = emptyList(),
negativeNodes: List<RoadNode> = emptyList(),
): IPath? {
return roadNetworkFindPath(start, end, HydrazinePathFinder(entity, instance), nodes, negativeNodes)
}

fun roadNetworkFindPath(
start: RoadNode,
end: RoadNode,
pathfinder: HydrazinePathFinder,
nodes: List<RoadNode> = emptyList(),
negativeNodes: List<RoadNode> = emptyList(),
): IPath? {
val interestingNodes = nodes.filter {
if (it.id == start.id) return@filter false
Expand All @@ -42,25 +54,29 @@ fun roadNetworkFindPath(
distance > it.radius * it.radius && distance < roadNetworkMaxDistance * roadNetworkMaxDistance
}

val pathfinder = HydrazinePathFinder(entity, instance)
val additionalRadius = entity.width().toDouble()
val additionalRadius = pathfinder.subject().width().toDouble()

// When the pathfinder wants to go through another intermediary node, we know that we probably want to use that.
// So we don't want this edge to be used.
pathfinder.withGraphNodeFilter { node ->
if (node.isInRangeOf(interestingNegativeNodes, additionalRadius)) return@withGraphNodeFilter Passibility.dangerous
node.passibility()
// We want to avoid going through negative nodes
if (interestingNegativeNodes.isNotEmpty()) {
pathfinder.withGraphNodeFilter { node ->
if (node.isInRangeOf(interestingNegativeNodes, additionalRadius)) {
return@withGraphNodeFilter Passibility.dangerous
}
node.passibility()
}
}

// When the pathfinder wants to go through another intermediary node, we know that we probably want to use that.
// So we don't want this edge to be used.
val path = pathfinder.computePathTo(end.location.x, end.location.y, end.location.z) ?: return null
if (path.any { it.isInRangeOf(interestingNodes, additionalRadius) }) {
if (interestingNodes.isNotEmpty() && path.any { it.isInRangeOf(interestingNodes, additionalRadius) }) {
return null
}

return path
}

private fun INode.isInRangeOf(roadNodes: List<RoadNode>, additionalRadius: Double = 0.0): Boolean {
fun INode.isInRangeOf(roadNodes: List<RoadNode>, additionalRadius: Double = 0.0): Boolean {
return roadNodes.any { roadNode ->
val point = this.coordinates().toVector().mid()
val radius = roadNode.radius + additionalRadius
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,31 @@ import com.extollit.gaming.ai.path.model.IPath
import com.extollit.gaming.ai.path.model.IPathingEntity
import com.extollit.gaming.ai.path.model.Passibility
import com.extollit.linalg.immutable.Vec3d
import com.typewritermc.core.entries.Ref
import com.typewritermc.core.utils.point.Vector
import com.typewritermc.engine.paper.entry.entity.*
import com.typewritermc.engine.paper.entry.entries.RoadNetworkEntry
import com.typewritermc.engine.paper.entry.entries.roadNetworkMaxDistance
import com.typewritermc.engine.paper.entry.roadnetwork.RoadNetworkManager
import com.typewritermc.engine.paper.entry.roadnetwork.gps.GPS
import com.typewritermc.engine.paper.entry.roadnetwork.gps.GPSEdge
import com.typewritermc.engine.paper.entry.roadnetwork.gps.isInRangeOf
import com.typewritermc.engine.paper.entry.roadnetwork.gps.toVector
import com.typewritermc.engine.paper.entry.roadnetwork.pathfinding.PFCapabilities
import com.typewritermc.engine.paper.entry.roadnetwork.pathfinding.PFInstanceSpace
import com.typewritermc.engine.paper.logger
import com.typewritermc.engine.paper.utils.*
import kotlinx.coroutines.Job
import org.bukkit.util.BoundingBox
import org.koin.java.KoinJavaComponent.get
import kotlin.math.atan2
import kotlin.math.cos
import kotlin.math.min
import kotlin.math.sin


class NavigationActivity(
gps: GPS,
private val gps: GPS,
startLocation: PositionProperty,
) : GenericEntityActivity {
private var path: List<GPSEdge>? = null
Expand All @@ -49,7 +55,7 @@ class NavigationActivity(

state = when {
currentEdge.isFastTravel -> NavigationActivityTaskState.FastTravel(currentEdge)
context.isViewed -> NavigationActivityTaskState.Walking(currentEdge, currentPosition)
context.isViewed -> NavigationActivityTaskState.Walking(gps.roadNetwork, currentEdge, currentPosition)

else -> NavigationActivityTaskState.FakeNavigation(currentEdge)
}
Expand All @@ -59,7 +65,7 @@ class NavigationActivity(
// The fake navigation is used to improve the performance, it however, goes through buildings
// So, we switch to walking when the entity is viewed
if (state is NavigationActivityTaskState.FakeNavigation && context.isViewed) {
this.state = NavigationActivityTaskState.Walking(state.edge, currentPosition)
this.state = NavigationActivityTaskState.Walking(gps.roadNetwork, state.edge, currentPosition)
}

// And we switch back to fake navigation when the entity is not viewed
Expand Down Expand Up @@ -133,7 +139,11 @@ private sealed interface NavigationActivityTaskState {
override fun isComplete(): Boolean = true
}

class Walking(val edge: GPSEdge, startLocation: PositionProperty) : NavigationActivityTaskState, IPathingEntity {
class Walking(
roadNetwork: Ref<RoadNetworkEntry>,
val edge: GPSEdge,
startLocation: PositionProperty
) : NavigationActivityTaskState, IPathingEntity {
private var location: PositionProperty = startLocation
private var path: IPath?

Expand All @@ -148,7 +158,25 @@ private sealed interface NavigationActivityTaskState {
val instance = PFInstanceSpace(startLocation.toBukkitLocation().world)
navigator = HydrazinePathFinder(this, instance)

path = navigator.initiatePathTo(edge.end.x, edge.end.y, edge.end.z)
// We want to avoid going through negative nodes
// Since we just queried the network, it is likely that the network is already loaded.
get<RoadNetworkManager>(RoadNetworkManager::class.java).getNetworkOrNull(roadNetwork)?.let { network ->
val interestingNegativeNodes = network.negativeNodes.filter {
val distance = edge.start.distanceSqrt(it.location) ?: 0.0
distance > it.radius * it.radius && distance < roadNetworkMaxDistance * roadNetworkMaxDistance
}
val additionalRadius = navigator.subject().width().toDouble()

navigator.withGraphNodeFilter { node ->
if (node.isInRangeOf(interestingNegativeNodes, additionalRadius)) {
return@withGraphNodeFilter Passibility.dangerous
}
node.passibility()
}
}


path = navigator.computePathTo(edge.end.x, edge.end.y, edge.end.z)
}

override fun location(): PositionProperty = location
Expand Down

0 comments on commit cde7dd2

Please sign in to comment.