diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/AIControllerFactories.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/AIControllerFactories.kt index de794adad5..ba25c6eab6 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/AIControllerFactories.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/AIControllerFactories.kt @@ -11,6 +11,7 @@ import net.horizonsend.ion.server.features.ai.module.combat.MultiTargetFrigateCo import net.horizonsend.ion.server.features.ai.module.combat.StarfighterCombatModule import net.horizonsend.ion.server.features.ai.module.debug.AIDebugModule import net.horizonsend.ion.server.features.ai.module.misc.ContactsJammerModule +import net.horizonsend.ion.server.features.ai.module.misc.DifficultyModule import net.horizonsend.ion.server.features.ai.module.misc.GravityWellModule import net.horizonsend.ion.server.features.ai.module.misc.TrackingModule import net.horizonsend.ion.server.features.ai.module.movement.SteeringSolverModule @@ -42,12 +43,13 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() val targetingOriginal = builder.addModule("targeting", ClosestTargetingModule(it, 500.0, null).apply { sticky = false }) - builder.addModule("combat", StarfighterCombatModule(it) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.starfighterDistanceConfiguration)) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", StarfighterCombatModule(it,difficulty) { builder.suppliedModule("targeting").get().findTarget() }) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.starfighterDistanceConfiguration)) val steering = builder.addModule("steering", StarfighterSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.DC)) builder.addModule("debug", AIDebugModule(it)) @@ -62,13 +64,14 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestTargetingModule(it, 500.0, null).apply { sticky = false }) - builder.addModule("combat", StarfighterCombatModule(it) { builder.suppliedModule("targeting").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", StarfighterCombatModule(it,difficulty) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.gunshipDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.gunshipDistanceConfiguration)) val steering = builder.addModule("steering", GunshipSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.DC)) builder.addModule("debug", AIDebugModule(it)) @@ -83,13 +86,14 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestTargetingModule(it, 500.0, null).apply { sticky = false }) - builder.addModule("combat", StarfighterCombatModule(it) { builder.suppliedModule("targeting").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", StarfighterCombatModule(it,difficulty) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.gunshipDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.gunshipDistanceConfiguration)) val steering = builder.addModule("steering", GunshipSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.DC)) builder.addModule("debug", AIDebugModule(it)) @@ -104,9 +108,10 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestTargetingModule(it, 500.0, null).apply { sticky = false }) - builder.addModule("combat", GoonCombatModule(it) { builder.suppliedModule("targeting").get().findTarget() }) - val steering = builder.addModule("steering", BasicSteeringModule(it) {builder.suppliedModule("targeting").get().findTarget()}) - builder.addModule("movement", SteeringSolverModule(it, steering, + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", GoonCombatModule(it,difficulty) { builder.suppliedModule("targeting").get().findTarget() }) + val steering = builder.addModule("steering", BasicSteeringModule(it, difficulty) {builder.suppliedModule("targeting").get().findTarget()}) + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.DC)) builder.addModule("debug", AIDebugModule(it)) builder @@ -119,13 +124,14 @@ object AIControllerFactories : IonServerComponent() { setModuleBuilder { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestPlayerTargetingModule(it, 5000.0)) - builder.addModule("combat", StarfighterCombatModule(it) { builder.suppliedModule("targeting").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", StarfighterCombatModule(it,difficulty) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.gunshipDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.gunshipDistanceConfiguration)) val steering = builder.addModule("steering", GunshipSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.DC)) builder.addModule("jamming", ContactsJammerModule(it, 300.0) { builder.suppliedModule("targeting").get().findTargets() }) @@ -142,14 +148,15 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestTargetingModule(it, 500.0, null).apply { sticky = false }) - builder.addModule("combat", StarfighterCombatModule(it) { builder.suppliedModule("targeting").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", StarfighterCombatModule(it,difficulty) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.gunshipDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.gunshipDistanceConfiguration)) val steering = builder.addModule("steering", GunshipSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}, config = aiSteeringConfig.corvetteBasicSteeringConfiguration) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.DC)) builder.addModule("debug", AIDebugModule(it)) builder @@ -163,15 +170,16 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestTargetingModule(it, 2000.0, null).apply { sticky = false }) - builder.addModule("combat", StarfighterCombatModule(it) { builder.suppliedModule("targeting").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", StarfighterCombatModule(it,difficulty) { builder.suppliedModule("targeting").get().findTarget() }) builder.addModule("gravityWell", GravityWellModule(it, 1800.0, true) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.interdictionCorvetteDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.interdictionCorvetteDistanceConfiguration)) val steering = builder.addModule("steering", GunshipSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}, config = aiSteeringConfig.corvetteBasicSteeringConfiguration) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.DC)) builder.addModule("debug", AIDebugModule(it)) @@ -186,14 +194,15 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestLargeStarshipTargetingModule(it, 2000.0, null, true).apply { sticky = false }) - builder.addModule("combat", MultiTargetFrigateCombatModule(it, toggleRandomTargeting = true) { builder.suppliedModule("targeting").get().findTargets() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", MultiTargetFrigateCombatModule(it,difficulty, toggleRandomTargeting = true) { builder.suppliedModule("targeting").get().findTargets() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.logisticCorvetteDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.logisticCorvetteDistanceConfiguration)) val steering = builder.addModule("steering", GunshipSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}, config = aiSteeringConfig.corvetteBasicSteeringConfiguration) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.DC)) builder.addModule("debug", AIDebugModule(it)) @@ -209,14 +218,15 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestTargetingModule(it, 1500.0, null).apply { sticky = true }) - builder.addModule("combat", FrigateCombatModule(it, toggleRandomTargeting = true) { builder.suppliedModule("targeting").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", FrigateCombatModule(it,difficulty, toggleRandomTargeting = true) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.miniFrigateDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.miniFrigateDistanceConfiguration)) val steering = builder.addModule("steering", GunshipSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}, config = aiSteeringConfig.miniFrigateBasicSteeringConfiguration) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.DC)) builder.addModule("debug", AIDebugModule(it)) @@ -233,13 +243,14 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestTargetingModule(it, 1500.0, null).apply { sticky = true }) - builder.addModule("combat", FrigateCombatModule(it, toggleRandomTargeting = true) { builder.suppliedModule("targeting").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", FrigateCombatModule(it,difficulty, toggleRandomTargeting = true) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.capitalDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.capitalDistanceConfiguration)) val steering = builder.addModule("steering", CapitalSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.CRUISE)) builder.addModule("debug", AIDebugModule(it)) @@ -257,14 +268,15 @@ object AIControllerFactories : IonServerComponent() { builder.addModule("targeting", ClosestSmallStarshipTargetingModule(it, 700.0, null).apply { sticky = true }) builder.addModule("tracking", TrackingModule(it, 5, 1800.0, 15.0) { builder.suppliedModule("targeting").get().findTarget() }) - builder.addModule("combat", FrigateCombatModule(it, toggleRandomTargeting = true) { builder.suppliedModule("tracking").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", FrigateCombatModule(it,difficulty, toggleRandomTargeting = true) { builder.suppliedModule("tracking").get().findTarget() }) builder.addModule("gravityWell", GravityWellModule(it, 2400.0, true) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.advancedCapitalDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.advancedCapitalDistanceConfiguration)) val steering = builder.addModule("steering", CapitalSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.CRUISE)) builder.addModule("debug", AIDebugModule(it)) @@ -281,14 +293,15 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestTargetingModule(it, 5000.0, null).apply { sticky = true }) - builder.addModule("combat", FrigateCombatModule(it, toggleRandomTargeting = true) { builder.suppliedModule("targeting").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", FrigateCombatModule(it,difficulty, toggleRandomTargeting = true) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.capitalDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.capitalDistanceConfiguration)) val steering = builder.addModule("steering", CapitalSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}, config = aiSteeringConfig.destroyerBasicSteeringConfiguration) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.CRUISE)) builder.addModule("debug", AIDebugModule(it)) @@ -305,14 +318,15 @@ object AIControllerFactories : IonServerComponent() { val builder = AIControllerFactory.Builder.ModuleBuilder() builder.addModule("targeting", ClosestLargeStarshipTargetingModule(it, 5000.0, null).apply { sticky = true }) - builder.addModule("combat", FrigateCombatModule(it, toggleRandomTargeting = false) { builder.suppliedModule("targeting").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", FrigateCombatModule(it,difficulty, toggleRandomTargeting = false) { builder.suppliedModule("targeting").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.advancedCapitalDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.advancedCapitalDistanceConfiguration)) val steering = builder.addModule("steering", CapitalSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}, config = aiSteeringConfig.destroyerBasicSteeringConfiguration) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.CRUISE)) builder.addModule("debug", AIDebugModule(it)) @@ -330,14 +344,15 @@ object AIControllerFactories : IonServerComponent() { builder.addModule("targeting", ClosestLargeStarshipTargetingModule(it, 5000.0, null, focusRange = 200.0).apply { sticky = true }) builder.addModule("tracking", TrackingModule(it, 5, 87.5, 35.0) { builder.suppliedModule("targeting").get().findTarget() }) - builder.addModule("combat", FrigateCombatModule(it, toggleRandomTargeting = true) { builder.suppliedModule("tracking").get().findTarget() }) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", FrigateCombatModule(it,difficulty, toggleRandomTargeting = true) { builder.suppliedModule("tracking").get().findTarget() }) - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.advancedCapitalDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.advancedCapitalDistanceConfiguration)) val steering = builder.addModule("steering", CapitalSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}, config = aiSteeringConfig.battlecruiserBasicSteeringConfiguration) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.CRUISE)) builder.addModule("debug", AIDebugModule(it)) @@ -391,15 +406,16 @@ object AIControllerFactories : IonServerComponent() { // Combat handling val targeting = builder.addModule("targeting", HighestDamagerTargetingModule(it)) - builder.addModule("combat", DefensiveCombatModule(it, targeting::findTarget)) + val difficulty = builder.addModule("difficulty", DifficultyModule(it)) + builder.addModule("combat", DefensiveCombatModule(it,difficulty, targeting::findTarget)) // Movement handling - val distance = builder.addModule("distance", DistancePositioningModule(it, aiSteeringConfig.gunshipDistanceConfiguration)) + val distance = builder.addModule("distance", DistancePositioningModule(it,difficulty, aiSteeringConfig.gunshipDistanceConfiguration)) val steering = builder.addModule("steering", TravelSteeringModule( - it, {builder.suppliedModule("targeting").get().findTarget()}, + it,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, {builder.suppliedModule("distance").get().calcDistance()}, cruiseEndpoint.invoke(it).orNull() ?: Vec3i(0, 0, 0)) ) - builder.addModule("movement", SteeringSolverModule(it, steering, + builder.addModule("movement", SteeringSolverModule(it, steering,difficulty, {builder.suppliedModule("targeting").get().findTarget()}, SteeringSolverModule.MovementType.DC)) builder.addModule("debug", AIDebugModule(it)) diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/CombatModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/CombatModule.kt index 9a0e074877..237a3431bc 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/CombatModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/CombatModule.kt @@ -2,6 +2,7 @@ package net.horizonsend.ion.server.features.ai.module.combat import net.horizonsend.ion.common.utils.miscellaneous.randomDouble import net.horizonsend.ion.server.command.admin.debug +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.starship.control.controllers.ai.AIController import net.horizonsend.ion.server.features.starship.control.movement.AIControlUtils @@ -12,8 +13,12 @@ import org.bukkit.block.BlockFace import org.bukkit.util.Vector import java.util.function.Supplier -abstract class CombatModule(controller: AIController, val targetingSupplier: Supplier) : net.horizonsend.ion.server.features.ai.module.AIModule(controller) { - var shotDeviation: Double = 0.025 +abstract class CombatModule( + controller: AIController, + val difficulty : DifficultyModule, + val targetingSupplier: Supplier +) : net.horizonsend.ion.server.features.ai.module.AIModule(controller) { + val shotDeviation: Double get () {return difficulty.shotVariation + 0.025} open var shouldFaceTarget: Boolean = false diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/DefensiveCombatModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/DefensiveCombatModule.kt index d9d9298de1..79e3a4fc35 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/DefensiveCombatModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/DefensiveCombatModule.kt @@ -1,10 +1,15 @@ package net.horizonsend.ion.server.features.ai.module.combat +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.starship.control.controllers.ai.AIController import java.util.function.Supplier -class DefensiveCombatModule(controller: AIController, targetingSupplier: Supplier) : CombatModule(controller, targetingSupplier) { +class DefensiveCombatModule( + controller: AIController, + difficulty: DifficultyModule, + targetingSupplier: Supplier +) : CombatModule(controller, difficulty,targetingSupplier) { override fun tick() { val target = targetingSupplier.get() ?: return diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/FrigateCombatModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/FrigateCombatModule.kt index b09abb007a..c785470118 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/FrigateCombatModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/FrigateCombatModule.kt @@ -1,6 +1,7 @@ package net.horizonsend.ion.server.features.ai.module.combat import net.horizonsend.ion.server.command.admin.debug +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.starship.control.controllers.ai.AIController import net.horizonsend.ion.server.miscellaneous.utils.Vec3i @@ -11,7 +12,12 @@ import net.horizonsend.ion.server.miscellaneous.utils.rightFace import net.horizonsend.ion.server.miscellaneous.utils.vectorToBlockFace import java.util.function.Supplier -class FrigateCombatModule(controller: AIController, private val toggleRandomTargeting: Boolean = true, targetingSupplier: Supplier) : CombatModule(controller, targetingSupplier) { +class FrigateCombatModule( + controller: AIController, + difficulty : DifficultyModule, + private val toggleRandomTargeting: Boolean = true, + targetingSupplier: Supplier +) : CombatModule(controller,difficulty, targetingSupplier) { var leftFace: Boolean = false var ticks = 0 private var aimAtRandom = false diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/GoonCombatModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/GoonCombatModule.kt index fcc5148bc6..5bb2b0d746 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/GoonCombatModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/GoonCombatModule.kt @@ -1,5 +1,6 @@ package net.horizonsend.ion.server.features.ai.module.combat +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.starship.active.ActiveControlledStarship import net.horizonsend.ion.server.features.starship.control.controllers.ai.AIController @@ -8,7 +9,11 @@ import net.horizonsend.ion.server.miscellaneous.utils.getDirection import net.horizonsend.ion.server.miscellaneous.utils.vectorToBlockFace import java.util.function.Supplier -class GoonCombatModule(controller: AIController, targetingSupplier: Supplier) : CombatModule(controller, targetingSupplier) { +class GoonCombatModule( + controller: AIController, + difficulty : DifficultyModule, + targetingSupplier: Supplier +) : CombatModule(controller,difficulty, targetingSupplier) { override var shouldFaceTarget: Boolean = false override fun tick() { diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/MultiTargetCombatModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/MultiTargetCombatModule.kt index 8e10256f3b..147ca165ea 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/MultiTargetCombatModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/MultiTargetCombatModule.kt @@ -2,6 +2,7 @@ package net.horizonsend.ion.server.features.ai.module.combat import net.horizonsend.ion.common.utils.miscellaneous.randomDouble import net.horizonsend.ion.server.command.admin.debug +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.starship.control.controllers.ai.AIController import net.horizonsend.ion.server.features.starship.control.movement.AIControlUtils @@ -12,8 +13,12 @@ import org.bukkit.block.BlockFace import org.bukkit.util.Vector import java.util.function.Supplier -abstract class MultiTargetCombatModule(controller: AIController, val targetingSupplier: Supplier>) : net.horizonsend.ion.server.features.ai.module.AIModule(controller) { - var shotDeviation: Double = 0.025 +abstract class MultiTargetCombatModule( + controller: AIController, + val difficulty : DifficultyModule, + val targetingSupplier: Supplier> +) : net.horizonsend.ion.server.features.ai.module.AIModule(controller) { + val shotDeviation: Double get() {return difficulty.shotVariation + 0.025} open var shouldFaceTarget: Boolean = false diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/MultiTargetFrigateCombatModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/MultiTargetFrigateCombatModule.kt index f49916311a..b544626227 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/MultiTargetFrigateCombatModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/MultiTargetFrigateCombatModule.kt @@ -1,6 +1,7 @@ package net.horizonsend.ion.server.features.ai.module.combat import net.horizonsend.ion.server.command.admin.debug +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.starship.control.controllers.ai.AIController import net.horizonsend.ion.server.miscellaneous.utils.Vec3i @@ -11,7 +12,12 @@ import net.horizonsend.ion.server.miscellaneous.utils.rightFace import net.horizonsend.ion.server.miscellaneous.utils.vectorToBlockFace import java.util.function.Supplier -class MultiTargetFrigateCombatModule(controller: AIController, private val toggleRandomTargeting: Boolean = true, targetingSupplier: Supplier>) : MultiTargetCombatModule(controller, targetingSupplier) { +class MultiTargetFrigateCombatModule( + controller: AIController, + difficulty : DifficultyModule, + private val toggleRandomTargeting: Boolean = true, + targetingSupplier: Supplier> +) : MultiTargetCombatModule(controller,difficulty, targetingSupplier) { var leftFace: Boolean = false var ticks = 0 private var aimAtRandom = false diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/StarfighterCombatModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/StarfighterCombatModule.kt index 092fd49fc0..6e13053bac 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/StarfighterCombatModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/combat/StarfighterCombatModule.kt @@ -1,5 +1,6 @@ package net.horizonsend.ion.server.features.ai.module.combat +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.starship.control.controllers.ai.AIController import net.horizonsend.ion.server.miscellaneous.utils.Vec3i @@ -7,7 +8,11 @@ import net.horizonsend.ion.server.miscellaneous.utils.getDirection import net.horizonsend.ion.server.miscellaneous.utils.vectorToBlockFace import java.util.function.Supplier -class StarfighterCombatModule(controller: AIController, targetingSupplier: Supplier) : CombatModule(controller, targetingSupplier) { +class StarfighterCombatModule( + controller: AIController, + difficulty : DifficultyModule, + targetingSupplier: Supplier +) : CombatModule(controller,difficulty, targetingSupplier) { override var shouldFaceTarget: Boolean = true override fun tick() { diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/misc/DifficultyModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/misc/DifficultyModule.kt new file mode 100644 index 0000000000..2da283eebf --- /dev/null +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/misc/DifficultyModule.kt @@ -0,0 +1,26 @@ +package net.horizonsend.ion.server.features.ai.module.misc + +import net.horizonsend.ion.server.features.ai.module.AIModule +import net.horizonsend.ion.server.features.starship.control.controllers.ai.AIController + +class DifficultyModule( + controller: AIController, + private var internalDifficulty: Int = 3 +) : AIModule(controller){ + + val isShieldAware get() = internalDifficulty >= 3 + val doBackOff get() = internalDifficulty >= 3 + val speedDebuff = internalDifficulty <= 1 + val shotVariation : Double get() { + return when (internalDifficulty) { + 0,1 -> 0.3 + 2 -> 0.15 + else -> 0.0 + } + } + val faceModifier get() = if (internalDifficulty <= 1) 0.5 else 1.0 + + fun setDifficulty(i :Int) { + internalDifficulty = i + } +} diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/movement/SteeringSolverModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/movement/SteeringSolverModule.kt index 465210ddc8..418735a908 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/movement/SteeringSolverModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/movement/SteeringSolverModule.kt @@ -3,6 +3,7 @@ package net.horizonsend.ion.server.features.ai.module.movement import SteeringModule import net.horizonsend.ion.server.features.ai.module.AIModule import net.horizonsend.ion.server.features.ai.module.debug.AIDebugModule +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.starship.Starship import net.horizonsend.ion.server.features.starship.active.ActiveControlledStarship @@ -24,6 +25,7 @@ import kotlin.math.sign class SteeringSolverModule( controller: AIController, val steeringModule: SteeringModule, + val difficulty : DifficultyModule, val target: Supplier, val type : MovementType = MovementType.CRUISE ) : AIModule(controller) { @@ -70,7 +72,7 @@ class SteeringSolverModule( fun updateDirectControl() { if (!controller.starship.isDirectControlEnabled) controller.starship.setDirectControlEnabled(true) - controller.setShiftFlying(true) + if (!difficulty.speedDebuff) controller.setShiftFlying(true) //map onto player slots controller.selectedDirectControlSpeed = round(throttle * 8.0).toInt() + 1 @@ -122,6 +124,10 @@ class SteeringSolverModule( var (accel, maxSpeed) = starship.getThrustData(dx, dz) maxSpeed /= 2 + if (difficulty.speedDebuff) { + maxSpeed = round(0.7 * maxSpeed).toInt() + } + maxSpeed = (maxSpeed * starship.balancing.cruiseSpeedMultiplier).toInt() val finalSpeed = round(throttle * maxSpeed).toInt() starship.speedLimit = finalSpeed diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/positioning/DistancePositioningModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/positioning/DistancePositioningModule.kt index 183f2a05bd..23fd0c9717 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/positioning/DistancePositioningModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/positioning/DistancePositioningModule.kt @@ -2,9 +2,14 @@ package net.horizonsend.ion.server.features.ai.module.positioning import net.horizonsend.ion.server.features.ai.configuration.steering.AISteeringConfiguration import net.horizonsend.ion.server.features.ai.module.AIModule +import net.horizonsend.ion.server.features.ai.module.misc.DifficultyModule import net.horizonsend.ion.server.features.starship.control.controllers.ai.AIController -class DistancePositioningModule(controller: AIController, val config : AISteeringConfiguration.DistanceConfiguration) : AIModule(controller){ +class DistancePositioningModule( + controller: AIController, + val difficulty : DifficultyModule, + val config : AISteeringConfiguration.DistanceConfiguration +) : AIModule(controller){ val ship get() = controller.starship val minDist get() = config.minDist val maxDist get() = config.maxDist @@ -17,6 +22,8 @@ class DistancePositioningModule(controller: AIController, val config : AISteerin var isFleeing = false fun calcDistance() : Double { + if (!difficulty.doBackOff) return optimalDist + if (controller.getMinimumShieldHealth() <= startFleeing) { isFleeing = true } diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/BasicSteeringModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/BasicSteeringModule.kt index d7933eba6e..7f6e55cb34 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/BasicSteeringModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/BasicSteeringModule.kt @@ -1,7 +1,5 @@ -import net.horizonsend.ion.common.utils.miscellaneous.randomDouble -import net.horizonsend.ion.server.IonServer.aiContextConfig 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.BlankContext import net.horizonsend.ion.server.features.ai.module.steering.BorderDangerContext import net.horizonsend.ion.server.features.ai.module.steering.FaceSeekContext @@ -13,28 +11,15 @@ import net.horizonsend.ion.server.features.ai.module.steering.ShipDangerContext import net.horizonsend.ion.server.features.ai.module.steering.WanderContext import net.horizonsend.ion.server.features.ai.module.steering.WorldBlockDangerContext import net.horizonsend.ion.server.features.ai.util.AITarget -import net.horizonsend.ion.server.features.starship.active.ActiveStarship -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.movement.StarshipMovement -import net.horizonsend.ion.server.features.starship.movement.StarshipMovementException -import net.horizonsend.ion.server.features.starship.subsystem.shield.ShieldSubsystem -import net.horizonsend.ion.server.miscellaneous.utils.Vec3i -import org.bukkit.FluidCollisionMode -import org.bukkit.util.Vector -import org.bukkit.util.noise.SimplexOctaveGenerator -import java.util.concurrent.ConcurrentHashMap import java.util.function.Supplier -import kotlin.math.PI -import kotlin.math.abs -import kotlin.math.max -import kotlin.math.min -import kotlin.math.pow /** Basic implementation of a Steering Module, showcasing all the different modulues for */ open class BasicSteeringModule( controller: AIController, - val generalTarget : Supplier) : SteeringModule(controller) { + difficulty: DifficultyModule, + val generalTarget : Supplier +) : SteeringModule(controller, difficulty,) { open val config = aiSteeringConfig.defaultBasicSteeringConfiguration @@ -62,8 +47,8 @@ open class BasicSteeringModule( contexts["danger"]= BlankContext() contexts["wander"] = WanderContext(ship,offset) contexts["offsetSeek"] = OffsetSeekContext(ship, generalTarget,this) - contexts["faceSeek"]= FaceSeekContext(ship,generalTarget) - contexts["shieldAwareness"] = ShieldAwarenessContext(ship) + contexts["faceSeek"]= FaceSeekContext(ship,generalTarget,difficulty) + contexts["shieldAwareness"] = ShieldAwarenessContext(ship,difficulty) contexts["shipDanger"] = ShipDangerContext(ship, { config.defaultMaxSpeed },this) contexts["borderDanger"]= BorderDangerContext(ship) contexts["worldBlockDanger"]=WorldBlockDangerContext(ship) diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/CapitalSteeringModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/CapitalSteeringModule.kt index faede6c5e6..e15d4ce71e 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/CapitalSteeringModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/CapitalSteeringModule.kt @@ -4,16 +4,18 @@ import BasicSteeringModule 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.util.AITarget import net.horizonsend.ion.server.features.starship.control.controllers.ai.AIController import java.util.function.Supplier class CapitalSteeringModule( controller: AIController, + difficulty : DifficultyModule, generalTarget: Supplier, orbitDist : Supplier, override val config: AISteeringConfiguration.BasicSteeringConfiguration = aiSteeringConfig.frigateBasicSteeringConfiguration -) : BasicSteeringModule(controller, generalTarget){ +) : BasicSteeringModule(controller,difficulty, generalTarget){ init { @@ -40,8 +42,8 @@ class CapitalSteeringModule( contexts["danger"]= BlankContext() contexts["wander"] = WanderContext(ship,offset) contexts["offsetSeek"] = OffsetSeekContext(ship, generalTarget,this, aiContextConfig.capitalOffsetSeekContextConfiguration, offsetSupplier = orbitDist) - contexts["faceSeek"]= FaceSeekContext(ship,generalTarget) - contexts["shieldAwareness"] = ShieldAwarenessContext(ship, aiContextConfig.capitalShieldAwarenessContextConfiguration) + contexts["faceSeek"]= FaceSeekContext(ship,generalTarget,difficulty) + contexts["shieldAwareness"] = ShieldAwarenessContext(ship,difficulty, aiContextConfig.capitalShieldAwarenessContextConfiguration) contexts["shipDanger"] = ShipDangerContext(ship, { config.defaultMaxSpeed },this) contexts["borderDanger"]= BorderDangerContext(ship) contexts["worldBlockDanger"]=WorldBlockDangerContext(ship) diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/ContextMaps.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/ContextMaps.kt index bf77eec2a9..dae4f58a91 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/ContextMaps.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/ContextMaps.kt @@ -5,6 +5,7 @@ import SteeringModule import net.horizonsend.ion.common.utils.miscellaneous.randomDouble 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.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.starship.Starship @@ -196,6 +197,7 @@ class OffsetSeekContext( class FaceSeekContext( val ship : Starship, val generalTarget : Supplier, + val difficulty: DifficultyModule, val config : AIContextConfiguration.FaceSeekContextConfiguration = aiContextConfig.defaultFaceSeekContextConfiguration, ) : ContextMap() { override fun populateContext() { @@ -208,9 +210,9 @@ 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) + dotContext(offset,0.0, dist / config.falloff * config.weight * difficulty.faceModifier) for (i in 0 until NUMBINS) { - bins[i] = min(bins[i], config.maxWeight) + bins[i] = min(bins[i], config.maxWeight * difficulty.faceModifier) } checkContext() } @@ -301,6 +303,7 @@ class SquadFormationContext( */ class ShieldAwarenessContext( val ship : Starship, + val difficulty: DifficultyModule, val config : AIContextConfiguration.ShieldAwarenessContextConfiguration = aiContextConfig.defaultShieldAwarenessContextConfiguration, ) : ContextMap() { val incomingFire : ContextMap = object : ContextMap() {} @@ -324,6 +327,7 @@ class ShieldAwarenessContext( } override fun populateContext() { clearContext() + if (!difficulty.isShieldAware) return val shipPos = ship.centerOfMass.toVector() incomingFire.multScalar(config.histDecay) for (shield in ship.shields) { diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/GunshipSteeringModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/GunshipSteeringModule.kt index 662b19d978..7ebd117a21 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/GunshipSteeringModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/GunshipSteeringModule.kt @@ -4,16 +4,19 @@ import BasicSteeringModule 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.util.AITarget import net.horizonsend.ion.server.features.starship.control.controllers.ai.AIController +import org.jline.utils.DiffHelper.Diff import java.util.function.Supplier class GunshipSteeringModule( controller: AIController, + difficulty : DifficultyModule, generalTarget: Supplier, orbitDist : Supplier, override val config: AISteeringConfiguration.BasicSteeringConfiguration = aiSteeringConfig.gunshipBasicSteeringConfiguration -) : BasicSteeringModule(controller, generalTarget){ +) : BasicSteeringModule(controller,difficulty, generalTarget){ init { @@ -40,8 +43,8 @@ class GunshipSteeringModule( contexts["danger"]= BlankContext() contexts["wander"] = WanderContext(ship,offset) contexts["offsetSeek"] = OffsetSeekContext(ship, generalTarget,this, offsetSupplier = orbitDist) - contexts["faceSeek"]= FaceSeekContext(ship,generalTarget, aiContextConfig.gunshipFaceSeekContextConfiguration) - contexts["shieldAwareness"] = ShieldAwarenessContext(ship, aiContextConfig.gunshipShieldAwarenessContextConfiguration) + contexts["faceSeek"]= FaceSeekContext(ship,generalTarget,difficulty, aiContextConfig.gunshipFaceSeekContextConfiguration) + contexts["shieldAwareness"] = ShieldAwarenessContext(ship,difficulty, aiContextConfig.gunshipShieldAwarenessContextConfiguration) contexts["shipDanger"] = ShipDangerContext(ship, { config.defaultMaxSpeed },this) contexts["borderDanger"]= BorderDangerContext(ship) contexts["worldBlockDanger"]=WorldBlockDangerContext(ship) diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/StarfighterSteeringModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/StarfighterSteeringModule.kt index 99f3e26a5c..f6fe8365ca 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/StarfighterSteeringModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/StarfighterSteeringModule.kt @@ -4,16 +4,18 @@ import BasicSteeringModule 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.util.AITarget import net.horizonsend.ion.server.features.starship.control.controllers.ai.AIController import java.util.function.Supplier class StarfighterSteeringModule( controller: AIController, + difficulty : DifficultyModule, generalTarget: Supplier, orbitDist : Supplier, override val config: AISteeringConfiguration.BasicSteeringConfiguration = aiSteeringConfig.starfighterBasicSteeringConfiguration -) : BasicSteeringModule(controller, generalTarget){ +) : BasicSteeringModule(controller, difficulty ,generalTarget){ init { @@ -40,8 +42,8 @@ class StarfighterSteeringModule( contexts["danger"]= BlankContext() contexts["wander"] = WanderContext(ship,offset) contexts["offsetSeek"] = OffsetSeekContext(ship, generalTarget,this,aiContextConfig.starfighterOffsetSeekContextConfiguration, offsetSupplier = orbitDist) - contexts["faceSeek"]= FaceSeekContext(ship,generalTarget, aiContextConfig.starfighterFaceSeekContextConfiguration) - contexts["shieldAwareness"] = ShieldAwarenessContext(ship) + contexts["faceSeek"]= FaceSeekContext(ship,generalTarget,difficulty, aiContextConfig.starfighterFaceSeekContextConfiguration) + contexts["shieldAwareness"] = ShieldAwarenessContext(ship,difficulty) contexts["shipDanger"] = ShipDangerContext(ship, { config.defaultMaxSpeed },this) contexts["borderDanger"]= BorderDangerContext(ship) contexts["worldBlockDanger"]=WorldBlockDangerContext(ship) diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/SteeringModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/SteeringModule.kt index f4bffca54e..7119dd3ccb 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/SteeringModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/SteeringModule.kt @@ -1,4 +1,5 @@ import net.horizonsend.ion.server.features.ai.module.AIModule +import net.horizonsend.ion.server.features.ai.module.misc.DifficultyModule import net.horizonsend.ion.server.features.starship.Starship import net.horizonsend.ion.server.features.starship.control.controllers.ai.AIController import net.horizonsend.ion.server.features.starship.movement.StarshipMovement @@ -41,7 +42,10 @@ should be the LAST step. * * The master steering function that determines thrust and heading * * Each steering module has its own configuration, each Context also has its own configuration */ -abstract class SteeringModule(var controler: AIController) : AIModule(controler){ +abstract class SteeringModule( + var controler: AIController, + val difficulty: DifficultyModule +) : AIModule(controler){ val ship : Starship get() = controler.starship val contexts = mutableMapOf() val offset = Math.random() diff --git a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/TravelSteeringModule.kt b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/TravelSteeringModule.kt index 212fa8b594..8b15e4fe58 100644 --- a/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/TravelSteeringModule.kt +++ b/server/src/main/kotlin/net/horizonsend/ion/server/features/ai/module/steering/TravelSteeringModule.kt @@ -1,7 +1,5 @@ -import net.horizonsend.ion.common.utils.miscellaneous.randomDouble -import net.horizonsend.ion.server.IonServer.aiContextConfig 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.BlankContext import net.horizonsend.ion.server.features.ai.module.steering.BorderDangerContext import net.horizonsend.ion.server.features.ai.module.steering.FaceSeekContext @@ -14,30 +12,18 @@ import net.horizonsend.ion.server.features.ai.module.steering.ShipDangerContext import net.horizonsend.ion.server.features.ai.module.steering.WanderContext import net.horizonsend.ion.server.features.ai.module.steering.WorldBlockDangerContext import net.horizonsend.ion.server.features.ai.util.AITarget -import net.horizonsend.ion.server.features.starship.active.ActiveStarship -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.movement.StarshipMovement -import net.horizonsend.ion.server.features.starship.movement.StarshipMovementException -import net.horizonsend.ion.server.features.starship.subsystem.shield.ShieldSubsystem import net.horizonsend.ion.server.miscellaneous.utils.Vec3i -import org.bukkit.FluidCollisionMode -import org.bukkit.util.Vector -import org.bukkit.util.noise.SimplexOctaveGenerator -import java.util.concurrent.ConcurrentHashMap import java.util.function.Supplier -import kotlin.math.PI -import kotlin.math.abs -import kotlin.math.max -import kotlin.math.min -import kotlin.math.pow /** Steering Module that can travel though space */ open class TravelSteeringModule( controller: AIController, + difficulty: DifficultyModule, val generalTarget : Supplier, orbitDist : Supplier, - val goalPoint : Vec3i) : SteeringModule(controller) { + val goalPoint : Vec3i +) : SteeringModule(controller, difficulty,) { open val config = aiSteeringConfig.gunshipBasicSteeringConfiguration @@ -65,9 +51,9 @@ open class TravelSteeringModule( contexts["danger"]= BlankContext() contexts["wander"] = WanderContext(ship,offset) contexts["offsetSeek"] = OffsetSeekContext(ship, generalTarget,this) - contexts["faceSeek"]= FaceSeekContext(ship,generalTarget) + contexts["faceSeek"]= FaceSeekContext(ship,generalTarget,difficulty) contexts["goalSeek"] = GoalSeekContext(ship,goalPoint) - contexts["shieldAwareness"] = ShieldAwarenessContext(ship) + contexts["shieldAwareness"] = ShieldAwarenessContext(ship,difficulty) contexts["shipDanger"] = ShipDangerContext(ship, { config.defaultMaxSpeed },this) contexts["borderDanger"]= BorderDangerContext(ship) contexts["worldBlockDanger"]=WorldBlockDangerContext(ship)