Skip to content

Commit

Permalink
max assigned to behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
morrowwolf committed Nov 1, 2023
1 parent 6907084 commit defc627
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

/datum/component/ai_behavior_override/attack/check_behavior_validity(mob/living/carbon/xenomorph/checked_xeno, distance)
. = ..()
if(!.)
return

if(distance > 10)
return FALSE
Expand All @@ -12,6 +14,8 @@

/datum/component/ai_behavior_override/attack/process_override_behavior(mob/living/carbon/xenomorph/processing_xeno, delta_time)
. = ..()
if(!.)
return

if(processing_xeno.current_target == parent)
return FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ GLOBAL_LIST_EMPTY(all_ai_behavior_overrides)
/// The actual image holder that sits on parent for game masters
var/image/behavior_image

/// The xenos currently handling this task
var/currently_assigned

/// How many xenos we want assigned to this task at max
var/max_assigned = 3

/datum/component/ai_behavior_override/Initialize(...)
. = ..()

Expand All @@ -19,7 +25,9 @@ GLOBAL_LIST_EMPTY(all_ai_behavior_overrides)
behavior_image = new(behavior_icon, parent, behavior_icon_state, layer = ABOVE_FLY_LAYER)

for(var/client/game_master in GLOB.game_masters)
game_master.images += behavior_image
game_master.images |= behavior_image

currently_assigned = list()

/datum/component/ai_behavior_override/Destroy(force, silent, ...)
GLOB.all_ai_behavior_overrides -= src
Expand All @@ -28,15 +36,21 @@ GLOBAL_LIST_EMPTY(all_ai_behavior_overrides)
game_master.images -= behavior_image

QDEL_NULL(behavior_image)
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)
return FALSE
if(length(currently_assigned) >= max_assigned && !(checked_xeno in currently_assigned))
return FALSE

return TRUE

/// Processes what we want this behavior to do, return FALSE if we want to continue in the process_ai() proc or TRUE if we want to handle everything and have process_ai() return
/datum/component/ai_behavior_override/proc/process_override_behavior(mob/living/carbon/xenomorph/processing_xeno, delta_time)
SHOULD_NOT_SLEEP(TRUE)

return FALSE
currently_assigned |= processing_xeno

return TRUE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/datum/component/ai_behavior_override/capture
behavior_icon_state = "capture_order"

max_assigned = 1

/datum/component/ai_behavior_override/capture/Initialize(...)
. = ..()

Expand All @@ -13,6 +15,8 @@

/datum/component/ai_behavior_override/capture/check_behavior_validity(mob/living/carbon/xenomorph/checked_xeno, distance)
. = ..()
if(!.)
return

var/mob/parent_mob = parent

Expand Down Expand Up @@ -47,6 +51,8 @@

/datum/component/ai_behavior_override/capture/process_override_behavior(mob/living/carbon/xenomorph/processing_xeno, delta_time)
. = ..()
if(!.)
return

processing_xeno.current_target = parent
processing_xeno.resting = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ GLOBAL_LIST_EMPTY(ai_hives)
/datum/component/ai_behavior_override/hive
behavior_icon_state = "core"

max_assigned = 0

var/hive_radius = 7

/datum/component/ai_behavior_override/hive/Initialize(...)
. = ..()

if(!istype(parent, /turf/open))
if(!istype(parent, /turf/open) && !istype(parent, /obj/effect/alien))
return COMPONENT_INCOMPATIBLE

GLOB.ai_hives += src
new /obj/effect/alien/weeds/node(get_turf(parent))

if(!istype(parent, /obj/effect/alien))
new /obj/effect/alien/weeds/node(get_turf(parent))

/datum/component/ai_behavior_override/hive/Destroy(force, silent, ...)
GLOB.ai_hives -= src

. = ..()

/datum/component/ai_behavior_override/hive/check_behavior_validity(mob/living/carbon/xenomorph/checked_xeno, distance)
return FALSE

/datum/component/ai_behavior_override/hive/process_override_behavior(mob/living/carbon/xenomorph/processing_xeno, delta_time)
return FALSE
2 changes: 1 addition & 1 deletion code/game/area/areas_event.dm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ structure:
icon_state = "event"

//no bioscan and no tunnels allowed
flags_area = AREA_AVOID_BIOSCAN|AREA_NOTUNNEL
flags_area = AREA_AVOID_BIOSCAN

//events are not part of regular gameplay, therefore, no statistics
statistic_exempt = TRUE
Expand Down
6 changes: 3 additions & 3 deletions code/modules/admin/game_master/game_master.dm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ GLOBAL_VAR_INIT(radio_communication_clarity, 100)
for(var/datum/component/ai_behavior_override/override in GLOB.all_ai_behavior_overrides)
game_master_client.images += override.behavior_image

GLOB.game_masters += game_master_client
GLOB.game_masters |= game_master_client

/datum/game_master/Destroy(force, ...)
. = ..()
Expand Down Expand Up @@ -289,7 +289,7 @@ GLOBAL_VAR_INIT(radio_communication_clarity, 100)
user.client?.click_intercept = src

for(var/datum/component/ai_behavior_override/override in GLOB.all_ai_behavior_overrides)
game_master_client.images += override.behavior_image
game_master_client.images |= override.behavior_image

/datum/game_master/proc/InterceptClickOn(mob/user, params, atom/object)

Expand Down Expand Up @@ -319,7 +319,7 @@ GLOBAL_VAR_INIT(radio_communication_clarity, 100)
var/behavior_type = SELECTABLE_XENO_BEHAVIORS_ASSOC[selected_behavior]

if(LAZYACCESS(modifiers, MIDDLE_CLICK))
if(object.datum_components[behavior_type])
if(object.datum_components?[behavior_type])
var/component_to_remove = object.datum_components[behavior_type]
qdel(component_to_remove)
return TRUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
var/turf/weeded_wall

var/shortest_distance = INFINITY
for(var/turf/potential_nest as anything in RANGE_TURFS(hive_radius, closest_hive))
for(var/turf/potential_nest as anything in shuffle(RANGE_TURFS(hive_radius, closest_hive)))
if(potential_nest.density)
continue

Expand Down
2 changes: 2 additions & 0 deletions code/modules/mob/living/carbon/xenomorph/ai/movement/drone.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
idle_xeno.lay_down()
return

idle_xeno.resting = FALSE

if(home_turf == last_home_turf)
blacklisted_turfs += home_turf
addtimer(CALLBACK(src, PROC_REF(unblacklist_turf), home_turf), BLACKLIST_TURF_TIMEOUT)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/xenomorph/ai/xeno_ai.dm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ GLOBAL_LIST_INIT(ai_target_limbs, list(
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)
current_target = get_target(ai_range)
if(QDELETED(src))
return TRUE
Expand Down

0 comments on commit defc627

Please sign in to comment.