diff --git a/code/datums/ai/basic_mobs/basic_ai_behaviors/targeting.dm b/code/datums/ai/basic_mobs/basic_ai_behaviors/targeting.dm index 435b9cb1ef3..8ba9624c21e 100644 --- a/code/datums/ai/basic_mobs/basic_ai_behaviors/targeting.dm +++ b/code/datums/ai/basic_mobs/basic_ai_behaviors/targeting.dm @@ -1,11 +1,12 @@ +/// List of objects that AIs will treat as targets +GLOBAL_LIST_EMPTY_TYPED(hostile_machines, /atom) + /datum/ai_behavior/find_potential_targets action_cooldown = 2 SECONDS /// How far can we see stuff? var/vision_range = 9 /// Blackboard key for aggro range, uses vision range if not specified var/aggro_range_key = BB_AGGRO_RANGE - /// Static typecache list of potentially dangerous objs - var/static/list/hostile_machines = typecacheof(list(/obj/machinery/porta_turret, /obj/vehicle/sealed/mecha)) /datum/ai_behavior/find_potential_targets/perform(seconds_per_tick, datum/ai_controller/controller, target_key, targeting_strategy_key, hiding_location_key) . = ..() @@ -26,9 +27,9 @@ var/list/potential_targets = hearers(aggro_range, get_turf(controller.pawn)) - living_mob //Remove self, so we don't suicide - for(var/HM in typecache_filter_list(range(aggro_range, living_mob), hostile_machines)) //Can we see any hostile machines? - if(can_see(living_mob, HM, aggro_range)) - potential_targets += HM + for (var/atom/hostile_machine as anything in GLOB.hostile_machines) + if (can_see(living_mob, hostile_machine, aggro_range)) + potential_targets += hostile_machine if(!potential_targets.len) finish_action(controller, succeeded = FALSE) diff --git a/code/datums/elements/hostile_machine.dm b/code/datums/elements/hostile_machine.dm new file mode 100644 index 00000000000..0a5f19287bb --- /dev/null +++ b/code/datums/elements/hostile_machine.dm @@ -0,0 +1,15 @@ +/// AIs will attack this as a potential target if they see it +/datum/element/hostile_machine + element_flags = ELEMENT_DETACH_ON_HOST_DESTROY + +/datum/element/hostile_machine/Attach(datum/target) + . = ..() + + if (!isatom(target)) + return ELEMENT_INCOMPATIBLE + + GLOB.hostile_machines += target + +/datum/element/hostile_machine/Detach(datum/source) + GLOB.hostile_machines -= source + return ..() diff --git a/code/game/machinery/porta_turret/portable_turret.dm b/code/game/machinery/porta_turret/portable_turret.dm index 5a7e1da9984..76b1b73ba53 100644 --- a/code/game/machinery/porta_turret/portable_turret.dm +++ b/code/game/machinery/porta_turret/portable_turret.dm @@ -133,6 +133,8 @@ DEFINE_BITFIELD(turret_flags, list( if(!has_cover) INVOKE_ASYNC(src, PROC_REF(popUp)) + AddElement(/datum/element/hostile_machine) + /obj/machinery/porta_turret/proc/toggle_on(set_to) var/current = on if (!isnull(set_to)) diff --git a/code/modules/vehicles/mecha/_mecha.dm b/code/modules/vehicles/mecha/_mecha.dm index 208bd8d68c2..d971b82a856 100644 --- a/code/modules/vehicles/mecha/_mecha.dm +++ b/code/modules/vehicles/mecha/_mecha.dm @@ -267,6 +267,7 @@ equip_by_category[key] -= path AddElement(/datum/element/falling_hazard, damage = 80, wound_bonus = 10, hardhat_safety = FALSE, crushes = TRUE) + AddElement(/datum/element/hostile_machine) /obj/vehicle/sealed/mecha/Destroy() for(var/ejectee in occupants) diff --git a/tgstation.dme b/tgstation.dme index 1615237a9b7..07414c62a5f 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -1495,6 +1495,7 @@ #include "code\datums\elements\haunted.dm" #include "code\datums\elements\high_fiver.dm" #include "code\datums\elements\honkspam.dm" +#include "code\datums\elements\hostile_machine.dm" #include "code\datums\elements\human_biter.dm" #include "code\datums\elements\immerse.dm" #include "code\datums\elements\item_fov.dm"