From 3956c1edad68fc92817d504bcf8979d9ac62559b Mon Sep 17 00:00:00 2001 From: Fate-JH Date: Tue, 17 Jun 2025 13:38:19 -0400 Subject: [PATCH] changing to square distance during mine checks; repeating entity geometric distance check function --- .../objects/ce/InteractWithMines.scala | 7 ++++--- .../net/psforever/objects/zones/Zone.scala | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/scala/net/psforever/objects/ce/InteractWithMines.scala b/src/main/scala/net/psforever/objects/ce/InteractWithMines.scala index 39e3f3fa2..50910628c 100644 --- a/src/main/scala/net/psforever/objects/ce/InteractWithMines.scala +++ b/src/main/scala/net/psforever/objects/ce/InteractWithMines.scala @@ -23,7 +23,7 @@ class InteractWithMines(val range: Float) */ private var skipTargets: List[PlanetSideGUID] = List() - def Type = MineInteraction + def Type: MineInteraction.type = MineInteraction /** * Trample upon active mines in our current detection sector and alert those mines. @@ -32,12 +32,13 @@ class InteractWithMines(val range: Float) */ def interaction(sector: SectorPopulation, target: InteractsWithZone): Unit = { val faction = target.Faction + lazy val targetGeometry = target.Definition.Geometry(target) val targets = sector .deployableList .filter { - case _: BoomerDeployable => false //boomers are specific types of ExplosiveDeployable but do not count here + case _: BoomerDeployable => false //boomers are a specific type of ExplosiveDeployable that do not count here case ex: ExplosiveDeployable => ex.Faction != faction && - Zone.distanceCheck(target, ex, ex.Definition.triggerRadius) + Zone.distanceCheck(targetGeometry, ex, ex.Definition.triggerRadius * ex.Definition.triggerRadius) case _ => false } val notSkipped = targets.filterNot { t => skipTargets.contains(t.GUID) } diff --git a/src/main/scala/net/psforever/objects/zones/Zone.scala b/src/main/scala/net/psforever/objects/zones/Zone.scala index 4a44e36d6..45eb69a12 100644 --- a/src/main/scala/net/psforever/objects/zones/Zone.scala +++ b/src/main/scala/net/psforever/objects/zones/Zone.scala @@ -1901,6 +1901,24 @@ object Zone { distanceCheck(obj1.Definition.Geometry(obj1), obj2.Definition.Geometry(obj2), maxDistance) } + /** + * Two game entities are considered "near" each other if they are within a certain distance of one another. + * A default function literal mainly used for `serverSideDamage`. + * Best used when one entity - `obj1` - is to be reused in tests against multiple other entities + * as it skips repeatedly calculating the volumetric geometry of the repeating entity. + * @see `ObjectDefinition.Geometry` + * @see `serverSideDamage` + * @param obj1 the geometric representation of a game entity + * @param obj2 a game entity + * @param maxDistance the square of the maximum distance permissible between game entities + * before they are no longer considered "near" + * @return `true`, if the two entities are near enough to each other; + * `false`, otherwise + */ + def distanceCheck(obj1: VolumetricGeometry, obj2: PlanetSideGameObject, maxDistance: Float): Boolean = { + distanceCheck(obj1, obj2.Definition.Geometry(obj2), maxDistance) + } + /** * Two game entities are considered "near" each other if they are within a certain distance of one another. * @param g1 the geometric representation of a game entity