Skip to content

Commit

Permalink
sidedness now helps determine target validity for automated turrets
Browse files Browse the repository at this point in the history
  • Loading branch information
Fate-JH committed Apr 2, 2024
1 parent 9319f7e commit 51b4cff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package net.psforever.objects.serverobject.turret.auto

import net.psforever.objects.definition.ObjectDefinition
import net.psforever.objects.serverobject.PlanetSideServerObject
import net.psforever.objects.serverobject.interior.InteriorAware
import net.psforever.objects.serverobject.turret.{TurretDefinition, WeaponTurret}
import net.psforever.objects.sourcing.{SourceEntry, SourceUniqueness}
import net.psforever.objects.vital.Vitality

trait AutomatedTurret
extends PlanetSideServerObject
with WeaponTurret {
with WeaponTurret
with InteriorAware {
import AutomatedTurret.Target
private var currentTarget: Option[Target] = None

Expand Down Expand Up @@ -66,5 +68,5 @@ trait AutomatedTurret
}

object AutomatedTurret {
type Target = PlanetSideServerObject with Vitality
type Target = PlanetSideServerObject with Vitality with InteriorAware
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import net.psforever.objects.avatar.scoring.EquipmentStat
import net.psforever.objects.equipment.EffectTarget
import net.psforever.objects.serverobject.PlanetSideServerObject
import net.psforever.objects.serverobject.damage.DamageableEntity
import net.psforever.objects.serverobject.interior.Sidedness
import net.psforever.objects.serverobject.mount.Mountable
import net.psforever.objects.serverobject.turret.Automation
import net.psforever.objects.sourcing.{PlayerSource, SourceEntry, SourceUniqueness}
Expand Down Expand Up @@ -326,6 +327,7 @@ trait AutomatedTurretBehavior {
AutomatedTurretObject.Target.orElse {
val turretPosition = AutomatedTurretObject.Position
val turretGuid = AutomatedTurretObject.GUID
val side = AutomatedTurretObject.WhichSide
val weaponGuid = AutomatedTurretObject.Weapons.values.head.Equipment.get.GUID
val radius = autoStats.get.ranges.trigger
val validation = autoStats.get.checks.validation
Expand All @@ -337,6 +339,7 @@ trait AutomatedTurretBehavior {
.collect { case target
if !target.Destroyed &&
target.Faction != faction &&
Sidedness.equals(target.WhichSide, side) &&
AutomatedTurretBehavior.shapedDistanceCheckAgainstValue(autoStats, target.Position, turretPosition, radius, result = -1) &&
validation.exists(func => func(target)) &&
disqualifiers.takeWhile(func => func(target)).isEmpty =>
Expand Down Expand Up @@ -650,7 +653,7 @@ trait AutomatedTurretBehavior {
* @param cause information about the damaging incident that caused the turret to consider retaliation
* @return something the turret can potentially shoot at
*/
protected def attemptRetaliation(target: Target, cause: DamageResult): Option[Target] = {
protected def attemptRetaliation(target: PlanetSideServerObject with Vitality, cause: DamageResult): Option[PlanetSideServerObject with Vitality] = {
val unique = SourceUniqueness(target)
if (
automaticOperation &&
Expand Down Expand Up @@ -931,7 +934,7 @@ object AutomatedTurretBehavior {
* @return entity that caused the damage
* @see `Vitality`
*/
def getAttackVectorFromCause(zone: Zone, cause: DamageResult): Option[PlanetSideServerObject with Vitality] = {
def getAttackVectorFromCause(zone: Zone, cause: DamageResult): Option[AutomatedTurret.Target] = {
import net.psforever.objects.sourcing._
cause
.interaction
Expand Down Expand Up @@ -962,7 +965,7 @@ object AutomatedTurretBehavior {
}
.flatten
.collect {
case out: PlanetSideServerObject with Vitality => out
case out: AutomatedTurret.Target => out
}
}

Expand Down

0 comments on commit 51b4cff

Please sign in to comment.