Skip to content

Commit

Permalink
Merge branch 'master' into upp_ship
Browse files Browse the repository at this point in the history
  • Loading branch information
FslashN authored Feb 8, 2024
2 parents f7f20fd + f7d9237 commit 9e5b867
Show file tree
Hide file tree
Showing 18 changed files with 238 additions and 105 deletions.
5 changes: 4 additions & 1 deletion code/__DEFINES/xeno_ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PROBABILITY CALCULATIONS ARE HERE

#define XENO_SLASH 80

#define XENO_DOOR_BUILDING_CHANCE 25
#define XENO_DOOR_BUILDING_CHANCE 40

#define PLASMA_RETREAT_PERCENTAGE 10
#define HEALTH_RETREAT_PERCENTAGE 20
Expand Down Expand Up @@ -91,3 +91,6 @@ PROBABILITY CALCULATIONS ARE HERE

/// Special blockers for pathfinding or obstacle handling
#define XENO_AI_SPECIAL_BLOCKERS list(/obj/flamer_fire, /obj/vehicle/multitile, /turf/open/space)

// Friend-or-foe universal check
#define IS_SAME_HIVENUMBER(A,B) (A.hivenumber == B.hivenumber)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
return FALSE

processing_xeno.current_target = parent
processing_xeno.resting = FALSE
processing_xeno.set_resting(FALSE, FALSE, TRUE)
if(prob(5))
processing_xeno.emote("hiss")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,21 @@ GLOBAL_LIST_EMPTY(all_ai_behavior_overrides)
game_master.images -= behavior_image

QDEL_NULL(behavior_image)

for(var/assigned_xeno in currently_assigned)
UnregisterSignal(assigned_xeno, COMSIG_PARENT_QDELETING)
currently_assigned = null

. = ..()

/// Override this to check if we want our behavior to be valid for the checked_xeno, passes the common factor of "distance" which is the distance between the checked_xeno and src parent
/datum/component/ai_behavior_override/proc/check_behavior_validity(mob/living/carbon/xenomorph/checked_xeno, distance)
if(length(currently_assigned) >= max_assigned && !(checked_xeno in currently_assigned))
remove_from_queue(checked_xeno)
return FALSE

if(checked_xeno.stat != CONSCIOUS)
remove_from_queue(checked_xeno)
return FALSE

return TRUE
Expand All @@ -51,6 +59,14 @@ GLOBAL_LIST_EMPTY(all_ai_behavior_overrides)
/datum/component/ai_behavior_override/proc/process_override_behavior(mob/living/carbon/xenomorph/processing_xeno, delta_time)
SHOULD_NOT_SLEEP(TRUE)

RegisterSignal(processing_xeno, COMSIG_PARENT_QDELETING, PROC_REF(remove_from_queue), TRUE)
currently_assigned |= processing_xeno

return TRUE

/datum/component/ai_behavior_override/proc/remove_from_queue(mob/removed_xeno)
SIGNAL_HANDLER
if(currently_assigned)
currently_assigned -= removed_xeno

UnregisterSignal(removed_xeno, COMSIG_PARENT_QDELETING)
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
qdel(src)
return FALSE

var/area/current_area = get_area(location)
if(!current_area.is_resin_allowed)
for(var/client/game_master in GLOB.game_masters)
to_chat(game_master, SPAN_XENOBOLDNOTICE("This area doesn't allow xenos to build here"))

qdel(src)
return FALSE

if(distance > 10)
return FALSE

Expand All @@ -46,9 +54,8 @@

if(checked_xeno.get_plasma_percentage() < PLASMA_RETREAT_PERCENTAGE)
var/turf/xeno_loc = get_turf(checked_xeno)
if(xeno_loc.weeds && !checked_xeno.resting)
currently_assigned -= checked_xeno
checked_xeno.lay_down()
if(xeno_loc.weeds)
checked_xeno.set_resting(TRUE, FALSE, TRUE)

return FALSE

Expand All @@ -59,16 +66,21 @@
if(!.)
return

processing_xeno.resting = FALSE
processing_xeno.set_resting(FALSE, FALSE, TRUE)

var/turf/xeno_loc = get_turf(processing_xeno)
if(xeno_loc.density)
return FALSE // We shouldn't stand in a wall, let's act default

var/turf/parent_turf = get_turf(parent)
var/distance = get_dist(processing_xeno, parent)

var/list/turfs_around = xeno_loc.AdjacentTurfs()
if(turfs_around && distance < 1) // We are gonna be stuck after building at our loc, let's step away
return processing_xeno.move_to_next_turf(pick(turfs_around))

var/is_diagonal = (get_dir(processing_xeno, parent_turf) in diagonals)
if(is_diagonal || get_dist(processing_xeno, parent) > 1)
if(is_diagonal || distance > 1)
return processing_xeno.move_to_next_turf(parent_turf)

for(var/obj/structure/blocker in parent_turf.contents)
Expand All @@ -84,19 +96,23 @@
var/list/resin_types = processing_xeno.resin_build_order
processing_xeno.selected_resin = locate(/datum/resin_construction/resin_turf/wall) in resin_types

var/wall_nearby
var/wall_nearby = FALSE
var/blocked_turfs = 0
for(var/turf/blocked_turf in orange(1, parent_turf) - parent_turf.AdjacentTurfs())
blocked_turfs++

if(get_dir(blocked_turf, parent_turf) in diagonals)
continue

if(blocked_turf.density)
wall_nearby = TRUE

blocked_turfs++
var/obj/effect/alien/weeds/turf_weeds = blocked_turf.weeds
if(turf_weeds && turf_weeds.secreting)
wall_nearby = TRUE // Something is being constructed nearby, let's bet this is a new resin wall

if(blocked_turfs)
if(prob(XENO_DOOR_BUILDING_CHANCE) || (wall_nearby && blocked_turfs == 2))
if(wall_nearby)
if(prob(XENO_DOOR_BUILDING_CHANCE) || (wall_nearby && blocked_turfs > 1))
processing_xeno.selected_resin = locate(/datum/resin_construction/resin_obj/door) in resin_types

var/datum/action/xeno_action/activable/secrete_resin/build_action = locate() in processing_xeno.actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
/datum/component/ai_behavior_override/capture/Initialize(...)
. = ..()

if(!istype(parent, /mob))
return COMPONENT_INCOMPATIBLE
if(!ishuman(parent))
var/mob/living/carbon/human/new_parent = locate() in get_turf(parent)
if(new_parent)
new_parent.AddComponent(/datum/component/ai_behavior_override/capture)

if(isxeno(parent))
return COMPONENT_INCOMPATIBLE

/datum/component/ai_behavior_override/capture/check_behavior_validity(mob/living/carbon/xenomorph/checked_xeno, distance)
Expand All @@ -20,10 +21,10 @@

var/mob/parent_mob = parent

var/stat = parent_mob.stat
var/captee_stat = parent_mob.stat
var/mob/pulledby = parent_mob.pulledby

if(stat == DEAD)
if(captee_stat == DEAD)
qdel(src)
return FALSE

Expand All @@ -41,7 +42,7 @@
if(distance > 10)
return FALSE

if(stat == CONSCIOUS)
if(captee_stat == CONSCIOUS)
return FALSE

if(isxeno(pulledby) && pulledby != checked_xeno)
Expand All @@ -55,7 +56,7 @@
return

processing_xeno.current_target = parent
processing_xeno.resting = FALSE
processing_xeno.set_resting(FALSE, FALSE, TRUE)

if(processing_xeno.get_active_hand())
processing_xeno.swap_hand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GLOBAL_LIST_EMPTY(ai_hives)

max_assigned = 0

var/hive_radius = 7
var/hive_radius = 5

/datum/component/ai_behavior_override/hive/Initialize(...)
. = ..()
Expand Down
4 changes: 4 additions & 0 deletions code/game/gamemodes/colonialmarines/ai/colonialmarines_ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@

. = ..()

/datum/game_mode/colonialmarines/ai/post_setup()
set_lz_resin_allowed(TRUE)
return ..()

/datum/game_mode/colonialmarines/ai/announce_bioscans()
return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,29 +149,29 @@

var/list/possible_charge_dirs = list()

for(var/mob/living/carbon/human/base_checked_human as anything in GLOB.alive_human_list)
var/distance_between_base_human_and_xeno = get_dist(processing_xeno, base_checked_human)
for(var/mob/living/carbon/base_checked_carbon as anything in GLOB.alive_mob_list)
var/distance_between_base_carbon_and_xeno = get_dist(processing_xeno, base_checked_carbon)

if(distance_between_base_human_and_xeno > MAXIMUM_TARGET_DISTANCE)
if(distance_between_base_carbon_and_xeno > MAXIMUM_TARGET_DISTANCE)
continue

if(distance_between_base_human_and_xeno < MINIMUM_CHARGE_DISTANCE)
if(distance_between_base_carbon_and_xeno < MINIMUM_CHARGE_DISTANCE)
continue

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

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

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

secondary_count++
secondary_x_sum += secondary_checked_human.x
secondary_y_sum += secondary_checked_human.y
secondary_x_sum += secondary_checked_carbon.x
secondary_y_sum += secondary_checked_carbon.y

if(secondary_count < MIN_TARGETS_TO_CHARGE)
continue
Expand Down Expand Up @@ -305,6 +305,9 @@
if(hit_human.body_position == LYING_DOWN)
continue

if(xeno.can_not_harm(hit_human))
continue

shake_camera(hit_human, 4, 2)
INVOKE_ASYNC(GLOBAL_PROC, GLOBAL_PROC_REF(xeno_throw_human), hit_human, xeno, get_dir(xeno, hit_human), 1, FALSE)
to_chat(hit_human, SPAN_XENOHIGHDANGER("You fall backwards as [xeno] gives you a glancing blow!"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
xeno_owner.create_stomp()

for(var/mob/living/carbon/carbon_in_range in range(distance, get_turf(xeno_owner)))
if(carbon_in_range.stat == DEAD || xeno_owner.can_not_harm(carbon_in_range))
if(xeno_owner.can_not_harm(carbon_in_range))
continue

var/distance_to_target = get_dist(carbon_in_range, xeno_owner)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
woyer.flick_attack_overlay(carbone, "disarm")
carbone.throw_atom(throw_turf, fling_distance, SPEED_VERY_FAST, woyer, TRUE)

COOLDOWN_RESET(woyer, forced_retarget_cooldown)
apply_cooldown()
return ..()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,27 @@
if(idle_xeno.throwing)
return

if(next_home_search < world.time && (!home_turf || !home_turf.weeds || get_dist(home_turf, idle_xeno) > max_distance_from_home))
if(next_home_search < world.time && (!home_turf || !home_turf.weeds || !IS_SAME_HIVENUMBER(idle_xeno, home_turf.weeds) || get_dist(home_turf, idle_xeno) > max_distance_from_home))
var/turf/T = get_turf(idle_xeno.loc)
next_home_search = world.time + home_search_delay
if(T.weeds)
var/obj/effect/alien/weeds/current_weeds = T.weeds
if(current_weeds && IS_SAME_HIVENUMBER(idle_xeno, current_weeds))
home_turf = T
else
var/shortest_distance = INFINITY
for(var/i in RANGE_TURFS(home_locate_range, T))
var/turf/potential_home = i
if(potential_home.weeds && !potential_home.density && get_dist(idle_xeno, potential_home) < shortest_distance)
var/obj/effect/alien/weeds/potential_weeds = potential_home.weeds
if(potential_weeds && IS_SAME_HIVENUMBER(idle_xeno, potential_weeds) && !potential_home.density && get_dist(idle_xeno, potential_home) < shortest_distance)
home_turf = potential_home
shortest_distance = get_dist(idle_xeno, potential_home)

idle_xeno.set_resting(FALSE, FALSE, TRUE)
if(!home_turf)
return

if(idle_xeno.move_to_next_turf(home_turf, home_locate_range))
if(get_dist(home_turf, idle_xeno) <= 0 && !idle_xeno.resting)
idle_xeno.lay_down()
if(get_dist(home_turf, idle_xeno) <= 0)
idle_xeno.set_resting(TRUE, FALSE, TRUE)
else
home_turf = null

Expand Down
11 changes: 6 additions & 5 deletions code/modules/mob/living/carbon/xenomorph/ai/movement/drone.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@
home_turf = potential_home

if(!home_turf)
if(!idle_xeno.resting)
idle_xeno.lay_down()
idle_xeno.set_resting(TRUE, FALSE, TRUE)
return

idle_xeno.resting = FALSE
idle_xeno.set_resting(FALSE, FALSE, TRUE)

if(home_turf == last_home_turf)
blacklisted_turfs += home_turf
Expand All @@ -79,13 +78,15 @@
if(checked_turf in blacklisted_turfs)
return FALSE

if(checked_turf.weeds)
var/obj/effect/alien/weeds/checked_weeds = checked_turf.weeds
if(checked_weeds && IS_SAME_HIVENUMBER(checked_weeds, parent))
return FALSE

if(checked_turf.is_weedable() < FULLY_WEEDABLE)
return FALSE

if(locate(/obj/effect/alien/weeds/node) in range(3, checked_turf))
var/obj/effect/alien/weeds/found_weeds = locate(/obj/effect/alien/weeds/node) in range(3, checked_turf)
if(found_weeds && IS_SAME_HIVENUMBER(found_weeds, parent))
return FALSE

if(checked_turf.density)
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.ai_can_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.ai_can_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
Loading

0 comments on commit 9e5b867

Please sign in to comment.