Skip to content

Commit

Permalink
check_mob_target OOP refactor?
Browse files Browse the repository at this point in the history
  • Loading branch information
xDanilcusx committed Jan 23, 2024
1 parent 98607ba commit 662a63e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@
if(distance_between_base_carbon_and_xeno < MINIMUM_CHARGE_DISTANCE)
continue

if(!processing_xeno.check_mob_target(base_checked_carbon))
if(!base_checked_carbon.check_mob_target(processing_xeno))
continue

var/secondary_count = 0
var/secondary_x_sum = 0
var/secondary_y_sum = 0

for(var/mob/living/carbon/secondary_checked_carbon in range(FLOCK_SCAN_RADIUS, base_checked_carbon))
if(!processing_xeno.check_mob_target(secondary_checked_carbon))
if(!secondary_checked_carbon.check_mob_target(processing_xeno))
continue

secondary_count++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@
registered_turfs += cycled_open_turf

var/mob/living/carbon/human/possible_target = locate() in cycled_open_turf
if(possible_target && (!parent.current_target || get_dist(parent, possible_target) < get_dist(parent, parent.current_target)) && parent.check_mob_target(possible_target))
if(possible_target && (!parent.current_target || get_dist(parent, possible_target) < get_dist(parent, parent.current_target)) && possible_target.check_mob_target(parent))
parent.current_target = possible_target

/datum/xeno_ai_movement/linger/lurking/proc/unregister_turf_signals()
Expand All @@ -286,7 +286,7 @@
return

var/mob/living/carbon/human/possible_target = entering_atom
if(!parent.current_target || get_dist(parent, possible_target) < get_dist(parent, parent.current_target) && parent.check_mob_target(possible_target))
if(!parent.current_target || get_dist(parent, possible_target) < get_dist(parent, parent.current_target) && possible_target.check_mob_target(parent))
parent.current_target = possible_target

/datum/xeno_ai_movement/linger/lurking/proc/lurking_parent_moved(atom/movable/moving_atom, atom/oldloc, direction, Forced)
Expand Down
28 changes: 7 additions & 21 deletions code/modules/mob/living/carbon/xenomorph/ai/xeno_ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
if(z != potential_target.z)
continue

if(!check_mob_target(potential_target))
if(!potential_target.check_mob_target(src))
continue

var/distance = get_dist(src, potential_target)
Expand Down Expand Up @@ -288,8 +288,8 @@
var/skip_vehicle = TRUE

var/list/interior_living_mobs = potential_vehicle_target.interior.get_passengers()
for(var/mob/living/carbon/human/human_mob in interior_living_mobs)
if(!check_mob_target(human_mob))
for(var/mob/living/carbon/carbon_mob in interior_living_mobs)
if(!carbon_mob.check_mob_target(src))
continue

skip_vehicle = FALSE
Expand Down Expand Up @@ -335,27 +335,13 @@

#undef EXTRA_CHECK_DISTANCE_MULTIPLIER

/mob/living/carbon/xenomorph/proc/check_mob_target(mob/living/carbon/checked_target)
if(checked_target.stat == DEAD)
return FALSE

if(hivenumber == checked_target.hivenumber)
return FALSE

if(HAS_TRAIT(checked_target, TRAIT_NESTED))
return FALSE
/mob/living/carbon/proc/check_mob_target(mob/living/carbon/xenomorph/ai_xeno)
if(stat == DEAD)
return FALSE // We leave dead bodies alone

if(can_not_harm(checked_target))
if(ai_xeno.can_not_harm(src))
return FALSE

if(ishuman(checked_target))
var/mob/living/carbon/human/checked_human = checked_target
if(checked_human.species.flags & IS_SYNTHETIC)
return FALSE

if(checked_human.stat != CONSCIOUS)
return FALSE // We leave crit people be

return TRUE

/mob/living/carbon/xenomorph/proc/make_ai()
Expand Down
26 changes: 26 additions & 0 deletions code/modules/mob/living/carbon/xenomorph/xeno_ai_interaction.dm
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ At bare minimum, make sure the relevant checks from parent types gets copied in

. = ..()

/mob/living/carbon/human/check_mob_target(mob/living/carbon/xenomorph/ai_xeno)
. = ..()
if(!.)
return FALSE

if(stat == UNCONSCIOUS)
return FALSE // We also leave crit people be

if(species.flags & IS_SYNTHETIC)
return FALSE

if(HAS_TRAIT(src, TRAIT_NESTED))
return FALSE

return TRUE

// XENOS
/mob/living/carbon/xenomorph/xeno_ai_obstacle(mob/living/carbon/xenomorph/X, direction, turf/target)
. = ..()
Expand All @@ -117,6 +133,16 @@ At bare minimum, make sure the relevant checks from parent types gets copied in

return XENO_PENALTY

/mob/living/carbon/xenomorph/check_mob_target(mob/living/carbon/xenomorph/ai_xeno)
. = ..()
if(!.)
return FALSE

if(ai_xeno.hivenumber == hivenumber)
return FALSE

return TRUE

// VEHICLES
/obj/vehicle/xeno_ai_obstacle(mob/living/carbon/xenomorph/X, direction, turf/target)
. = ..()
Expand Down

0 comments on commit 662a63e

Please sign in to comment.