mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
Merge pull request #6132 from Heroman3003/fix-ai-target-priority
Fixes ai priority targeting
This commit is contained in:
@@ -56,12 +56,8 @@
|
||||
/datum/ai_holder/proc/pick_target(list/targets)
|
||||
if(target != null) // If we already have a target, but are told to pick again, calculate the lowest distance between all possible, and pick from the lowest distance targets.
|
||||
targets = target_filter_distance(targets)
|
||||
// for(var/possible_target in targets)
|
||||
// var/atom/A = possible_target
|
||||
// var/target_dist = get_dist(holder, target)
|
||||
// var/possible_target_distance = get_dist(holder, A)
|
||||
// if(target_dist < possible_target_distance)
|
||||
// targets -= A
|
||||
else
|
||||
targets = target_filter_closest(targets)
|
||||
if(!targets.len) // We found nothing.
|
||||
return
|
||||
|
||||
@@ -95,6 +91,23 @@
|
||||
targets -= A
|
||||
return targets
|
||||
|
||||
/datum/ai_holder/proc/target_filter_closest(list/targets)
|
||||
var/lowest_distance = -1
|
||||
var/list/sorted_targets = list()
|
||||
for(var/possible_target in targets)
|
||||
var/atom/A = possible_target
|
||||
var/current_distance = get_dist(holder, A)
|
||||
if(lowest_distance == -1)
|
||||
lowest_distance = current_distance
|
||||
sorted_targets += A
|
||||
else if(current_distance < lowest_distance)
|
||||
targets.Cut()
|
||||
lowest_distance = current_distance
|
||||
sorted_targets += A
|
||||
else if(current_distance == lowest_distance)
|
||||
sorted_targets += A
|
||||
return sorted_targets
|
||||
|
||||
/datum/ai_holder/proc/can_attack(atom/movable/the_target)
|
||||
if(!can_see_target(the_target))
|
||||
return FALSE
|
||||
|
||||
Reference in New Issue
Block a user