Skip to content

Commit

Permalink
add fleet gravity,make ships skirt illius
Browse files Browse the repository at this point in the history
  • Loading branch information
ConsueTerra committed Nov 5, 2024
1 parent 2c2657f commit 31f14f2
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ data class AIContextConfiguration(

val defaultGoalSeekContextConfiguration: GoalSeekContextConfiguration = GoalSeekContextConfiguration(),

val defaultFleetGravityContextConfiguration: FleetGravityContextConfiguration = FleetGravityContextConfiguration(),

val defaultShieldAwarenessContextConfiguration: ShieldAwarenessContextConfiguration = ShieldAwarenessContextConfiguration(),
val gunshipShieldAwarenessContextConfiguration: ShieldAwarenessContextConfiguration = ShieldAwarenessContextConfiguration(weight = 0.5),
val capitalShieldAwarenessContextConfiguration: ShieldAwarenessContextConfiguration = ShieldAwarenessContextConfiguration(weight = 1.0),
Expand Down Expand Up @@ -82,6 +84,13 @@ data class AIContextConfiguration(
val falloff: Double = 1000.0
)

@Serializable
data class FleetGravityContextConfiguration(
val weight: Double = 1.0,
val falloffMod: Double = 16.0//number was estimated by determining the factor needed to keep 2 6k ships at most
//300 blocks apart with wandering only
)

@Serializable
data class ShieldAwarenessContextConfiguration(
val weight: Double = 1.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package net.horizonsend.ion.server.features.ai.module.steering

import SteeringModule
import net.horizonsend.ion.server.IonServer.aiSteeringConfig
import net.horizonsend.ion.server.features.ai.configuration.steering.AIContextConfiguration
import net.horizonsend.ion.server.features.ai.module.misc.DifficultyModule
import net.horizonsend.ion.server.features.ai.module.steering.context.AvoidIlliusContext
import net.horizonsend.ion.server.features.ai.module.steering.context.BlankContext
import net.horizonsend.ion.server.features.ai.module.steering.context.BorderDangerContext
import net.horizonsend.ion.server.features.ai.module.steering.context.ContextMap
import net.horizonsend.ion.server.features.ai.module.steering.context.FaceSeekContext
import net.horizonsend.ion.server.features.ai.module.steering.context.FleetGravityContext
import net.horizonsend.ion.server.features.ai.module.steering.context.MovementInterestContext
import net.horizonsend.ion.server.features.ai.module.steering.context.ObstructionDangerContext
import net.horizonsend.ion.server.features.ai.module.steering.context.OffsetSeekContext
Expand Down Expand Up @@ -52,6 +55,8 @@ open class BasicSteeringModule(
contexts["wander"] = WanderContext(ship,offset)
contexts["offsetSeek"] = OffsetSeekContext(ship, generalTarget,this)
contexts["faceSeek"]= FaceSeekContext(ship, generalTarget,difficulty)
contexts["fleetGravity"] = FleetGravityContext(ship)
contexts["avoidIllius"] = AvoidIlliusContext(ship)
contexts["shieldAwareness"] = ShieldAwarenessContext(ship,difficulty)
contexts["shipDanger"] = ShipDangerContext(ship, { config.defaultMaxSpeed },this)
contexts["borderDanger"]= BorderDangerContext(ship)
Expand All @@ -71,7 +76,9 @@ open class BasicSteeringModule(

contexts["movementInterest"]!!.addAll(
contexts["wander"]!!,
contexts["offsetSeek"]!!
contexts["offsetSeek"]!!,
contexts["fleetGravity"]!!,
contexts["avoidIllius"]!!
)
contexts["movementInterest"]!!.clipZero()//safeguard against neg weights

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import net.horizonsend.ion.server.IonServer.aiContextConfig
import net.horizonsend.ion.server.IonServer.aiSteeringConfig
import net.horizonsend.ion.server.features.ai.configuration.steering.AISteeringConfiguration
import net.horizonsend.ion.server.features.ai.module.misc.DifficultyModule
import net.horizonsend.ion.server.features.ai.module.steering.context.AvoidIlliusContext
import net.horizonsend.ion.server.features.ai.module.steering.context.BlankContext
import net.horizonsend.ion.server.features.ai.module.steering.context.BorderDangerContext
import net.horizonsend.ion.server.features.ai.module.steering.context.FaceSeekContext
import net.horizonsend.ion.server.features.ai.module.steering.context.FleetGravityContext
import net.horizonsend.ion.server.features.ai.module.steering.context.MovementInterestContext
import net.horizonsend.ion.server.features.ai.module.steering.context.ObstructionDangerContext
import net.horizonsend.ion.server.features.ai.module.steering.context.OffsetSeekContext
Expand Down Expand Up @@ -52,6 +54,8 @@ class CapitalSteeringModule(
contexts["wander"] = WanderContext(ship,offset)
contexts["offsetSeek"] = OffsetSeekContext(ship, generalTarget,this, aiContextConfig.capitalOffsetSeekContextConfiguration, offsetSupplier = orbitDist)
contexts["faceSeek"]= FaceSeekContext(ship,generalTarget,difficulty)
contexts["fleetGravity"] = FleetGravityContext(ship)
contexts["avoidIllius"] = AvoidIlliusContext(ship)
contexts["shieldAwareness"] = ShieldAwarenessContext(ship,difficulty, aiContextConfig.capitalShieldAwarenessContextConfiguration)
contexts["shipDanger"] = ShipDangerContext(ship, { config.defaultMaxSpeed },this)
contexts["borderDanger"]= BorderDangerContext(ship)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package net.horizonsend.ion.server.features.ai.module.steering
import net.horizonsend.ion.server.IonServer.aiSteeringConfig
import net.horizonsend.ion.server.features.ai.configuration.steering.AISteeringConfiguration
import net.horizonsend.ion.server.features.ai.module.misc.DifficultyModule
import net.horizonsend.ion.server.features.ai.module.steering.context.AvoidIlliusContext
import net.horizonsend.ion.server.features.ai.module.steering.context.BlankContext
import net.horizonsend.ion.server.features.ai.module.steering.context.BorderDangerContext
import net.horizonsend.ion.server.features.ai.module.steering.context.FaceSeekContext
import net.horizonsend.ion.server.features.ai.module.steering.context.FleetGravityContext
import net.horizonsend.ion.server.features.ai.module.steering.context.MovementInterestContext
import net.horizonsend.ion.server.features.ai.module.steering.context.ObstructionDangerContext
import net.horizonsend.ion.server.features.ai.module.steering.context.OffsetSeekContext
Expand Down Expand Up @@ -50,6 +52,8 @@ class GunshipSteeringModule(
contexts["wander"] = WanderContext(ship,offset)
contexts["offsetSeek"] = OffsetSeekContext(ship, generalTarget,this)
contexts["faceSeek"]= FaceSeekContext(ship, generalTarget,difficulty)
contexts["fleetGravity"] = FleetGravityContext(ship)
contexts["avoidIllius"] = AvoidIlliusContext(ship)
contexts["shieldAwareness"] = ShieldAwarenessContext(ship,difficulty)
contexts["shipDanger"] = ShipDangerContext(ship, { config.defaultMaxSpeed },this)
contexts["borderDanger"]= BorderDangerContext(ship)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import net.horizonsend.ion.server.IonServer.aiContextConfig
import net.horizonsend.ion.server.IonServer.aiSteeringConfig
import net.horizonsend.ion.server.features.ai.configuration.steering.AISteeringConfiguration
import net.horizonsend.ion.server.features.ai.module.misc.DifficultyModule
import net.horizonsend.ion.server.features.ai.module.steering.context.AvoidIlliusContext
import net.horizonsend.ion.server.features.ai.module.steering.context.BlankContext
import net.horizonsend.ion.server.features.ai.module.steering.context.BorderDangerContext
import net.horizonsend.ion.server.features.ai.module.steering.context.FaceSeekContext
import net.horizonsend.ion.server.features.ai.module.steering.context.FleetGravityContext
import net.horizonsend.ion.server.features.ai.module.steering.context.MovementInterestContext
import net.horizonsend.ion.server.features.ai.module.steering.context.ObstructionDangerContext
import net.horizonsend.ion.server.features.ai.module.steering.context.OffsetSeekContext
Expand Down Expand Up @@ -52,6 +54,8 @@ class StarfighterSteeringModule(
contexts["wander"] = WanderContext(ship,offset)
contexts["offsetSeek"] = OffsetSeekContext(ship, generalTarget,this,aiContextConfig.starfighterOffsetSeekContextConfiguration, offsetSupplier = orbitDist)
contexts["faceSeek"]= FaceSeekContext(ship,generalTarget,difficulty, aiContextConfig.starfighterFaceSeekContextConfiguration)
contexts["fleetGravity"] = FleetGravityContext(ship)
contexts["avoidIllius"] = AvoidIlliusContext(ship)
contexts["shieldAwareness"] = ShieldAwarenessContext(ship,difficulty)
contexts["shipDanger"] = ShipDangerContext(ship, { config.defaultMaxSpeed },this)
contexts["borderDanger"]= BorderDangerContext(ship)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package net.horizonsend.ion.server.features.ai.module.steering
import SteeringModule
import net.horizonsend.ion.server.IonServer.aiSteeringConfig
import net.horizonsend.ion.server.features.ai.module.misc.DifficultyModule
import net.horizonsend.ion.server.features.ai.module.steering.context.AvoidIlliusContext
import net.horizonsend.ion.server.features.ai.module.steering.context.BlankContext
import net.horizonsend.ion.server.features.ai.module.steering.context.BorderDangerContext
import net.horizonsend.ion.server.features.ai.module.steering.context.ContextMap
import net.horizonsend.ion.server.features.ai.module.steering.context.FaceSeekContext
import net.horizonsend.ion.server.features.ai.module.steering.context.FleetGravityContext
import net.horizonsend.ion.server.features.ai.module.steering.context.GoalSeekContext
import net.horizonsend.ion.server.features.ai.module.steering.context.MovementInterestContext
import net.horizonsend.ion.server.features.ai.module.steering.context.ObstructionDangerContext
Expand Down Expand Up @@ -57,6 +59,8 @@ open class TravelSteeringModule(
contexts["offsetSeek"] = OffsetSeekContext(ship, generalTarget,this)
contexts["faceSeek"]= FaceSeekContext(ship,generalTarget,difficulty)
contexts["goalSeek"] = GoalSeekContext(ship,goalPoint)
contexts["fleetGravity"] = FleetGravityContext(ship)
contexts["avoidIllius"] = AvoidIlliusContext(ship)
contexts["shieldAwareness"] = ShieldAwarenessContext(ship,difficulty)
contexts["shipDanger"] = ShipDangerContext(ship, { config.defaultMaxSpeed },this)
contexts["borderDanger"]= BorderDangerContext(ship)
Expand All @@ -77,6 +81,8 @@ open class TravelSteeringModule(
contexts["movementInterest"]!!.addAll(
contexts["wander"]!!,
contexts["offsetSeek"]!!,
contexts["fleetGravity"]!!,
contexts["avoidIllius"]!!,
contexts["goalSeek"]!!
)
contexts["movementInterest"]!!.clipZero()//safeguard against neg weights
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package net.horizonsend.ion.server.features.ai.module.steering.context
import SteeringModule
import net.horizonsend.ion.server.IonServer.aiContextConfig
import net.horizonsend.ion.server.features.ai.configuration.steering.AIContextConfiguration
import net.horizonsend.ion.server.features.ai.module.misc.AIFleetManageModule
import net.horizonsend.ion.server.features.ai.module.misc.DifficultyModule
import net.horizonsend.ion.server.features.ai.util.AITarget
import net.horizonsend.ion.server.features.ai.util.StarshipTarget
import net.horizonsend.ion.server.features.space.Space
import net.horizonsend.ion.server.features.starship.Starship
import net.horizonsend.ion.server.features.starship.active.ActiveStarships
import net.horizonsend.ion.server.features.starship.control.controllers.ai.AIController
import net.horizonsend.ion.server.features.starship.subsystem.shield.ShieldSubsystem
import net.horizonsend.ion.server.miscellaneous.utils.Vec3i
import net.horizonsend.ion.server.miscellaneous.utils.vectorToPitchYaw
Expand Down Expand Up @@ -208,7 +211,7 @@ class FaceSeekContext(
val dist = offset.length() + 1e-4
offset.normalize()
offset.multiply(config.faceWeight).add(ship.getTargetForward().direction).normalize()
dotContext(offset,0.0, dist / config.falloff * config.weight * difficulty.faceModifier)
dotContext(offset,-0.2, dist / config.falloff * config.weight * difficulty.faceModifier)
for (i in 0 until NUMBINS) {
bins[i] = min(bins[i], config.maxWeight * difficulty.faceModifier)
}
Expand Down Expand Up @@ -253,6 +256,41 @@ class GoalSeekContext(
checkContext()
}
}
/** makes ships spawned in the same fleet stay close to the center of mass modulated by the sum of cube root block counts
* This Context is meant for **`movementInterest`**
*
* * **`weight`** controls how strong this behavior is
* * **`falloffMod`** controls how this behavior scales with distance, higher
* values will cause a lower weight (ie agent will only move towards fleet from further away)*/
class FleetGravityContext(
val ship : Starship,
val config : AIContextConfiguration.FleetGravityContextConfiguration = aiContextConfig.defaultFleetGravityContextConfiguration,
) : ContextMap(){
override fun populateContext() {
clearContext()
val fleet = (ship.controller as AIController) //get ships in the same fleet in the same world
.getModuleByType<AIFleetManageModule>()?.fleet?.members?.filter {it.get()?.world == ship.world}
fleet ?: return
if (fleet.size <= 1) return
val com = Vector()
fleet.forEach{ it.get()?.centerOfMass?.let { it1 -> com.add(it1.toVector()) } }
com.multiply(1/fleet.size.toDouble())

val shipPos = ship.centerOfMass.toVector()
val target= com.clone()
val offset = target.add(shipPos.clone().multiply(-1.0))
val dist = offset.length() + 1e-4
offset.normalize()

var R3BlockCount = 0.0
fleet.forEach {it.get()?.let { other -> R3BlockCount += other.currentBlockCount.toDouble().pow(1/3.0)}}
//R3BlockCount /= fleet.size.toDouble()

val falloff = R3BlockCount * config.falloffMod

dotContext(offset,0.0, dist / falloff * config.weight )
}
}

class SquadFormationContext(

Expand Down Expand Up @@ -282,6 +320,23 @@ class SquadFormationContext(
}
}

class AvoidIlliusContext(val ship : Starship) : ContextMap() {
override fun populateContext() {
clearContext()
if (ship.world.name != "Asteri") return
val loc = Space.getPlanet("Illius")?.location?.toVector() ?: return
val shipPos = ship.centerOfMass.toVector()
val target= loc.clone()
val offset = target.add(shipPos.clone().multiply(-1.0))
val dist = offset.length() + 1e-4
offset.normalize()

val falloff = 400.0

dotContext(offset,0.0, -1.0*falloff/dist * 1.0)
}
}

/**
* Maps the danger of facing a particular direction for each direction
* Such that the ship will favor rotating ouf of the way if one side gets low.
Expand Down

0 comments on commit 31f14f2

Please sign in to comment.