Skip to content

Commit

Permalink
Refactors retarget delay
Browse files Browse the repository at this point in the history
  • Loading branch information
morrowwolf committed Nov 14, 2023
1 parent ceafe0b commit 2e062cb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,8 @@
/// The turf we force our crusher to walk to when he charges
var/turf/charge_turf


#define AI_NEW_TARGET_COOLDOWN 1 SECONDS

/datum/xeno_ai_movement/crusher/New(mob/living/carbon/xenomorph/parent)
. = ..()
addtimer(CALLBACK(src, PROC_REF(get_new_target), parent), AI_NEW_TARGET_COOLDOWN, TIMER_UNIQUE|TIMER_LOOP|TIMER_DELETE_ME)

/datum/xeno_ai_movement/crusher/proc/get_new_target(mob/living/carbon/xenomorph/parent)
parent.current_target = parent.get_target(parent.ai_range)

#undef AI_NEW_TARGET_COOLDOWN


#define MIN_TARGETS_TO_CHARGE 2
Expand Down
9 changes: 8 additions & 1 deletion code/modules/mob/living/carbon/xenomorph/ai/xeno_ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@

var/datum/xeno_ai_movement/ai_movement_handler

/// The time interval before this xeno should forcefully get a new target
var/forced_retarget_time = (10 SECONDS)

/// The actual cooldown declaration for forceful retargeting, reference forced_retarget_time for time in between checks
COOLDOWN_DECLARE(forced_retarget_cooldown)

/mob/living/carbon/xenomorph/Destroy()
QDEL_NULL(ai_movement_handler)
return ..()
Expand Down Expand Up @@ -68,8 +74,9 @@
var/mob/current_target_mob = current_target
stat_check = (current_target_mob.stat != CONSCIOUS)

if(QDELETED(current_target) || stat_check || get_dist(current_target, src) > ai_range)
if(QDELETED(current_target) || stat_check || get_dist(current_target, src) > ai_range || COOLDOWN_FINISHED(src, forced_retarget_cooldown))
current_target = get_target(ai_range)
COOLDOWN_START(src, forced_retarget_cooldown, forced_retarget_time)
if(QDELETED(src))
return TRUE

Expand Down
1 change: 1 addition & 0 deletions code/modules/mob/living/carbon/xenomorph/castes/Crusher.dm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
icon_xenonid = 'icons/mob/xenonids/crusher.dmi'

ai_range = 28
forced_retarget_time = (3 SECONDS)

/mob/living/carbon/xenomorph/crusher/init_movement_handler()
return new /datum/xeno_ai_movement/crusher(src)
Expand Down

0 comments on commit 2e062cb

Please sign in to comment.