From 2e319c8820df3690f322ca7ff8f8b3196ba3e01c Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 28 Aug 2023 07:54:27 +0200 Subject: [PATCH] [MIRROR] minor improvement to mob run away behavior [MDB IGNORE] (#23377) * minor improvement to mob run away behavior (#77924) ## About The Pull Request my attempt to improve mobs running away from danger ## Why It's Good For The Game improve the running away behavior of mobs here is a before and after of me chasing a rabbit in the church for reference before: https://github.com/tgstation/tgstation/assets/138636438/f6e5e237-a444-4410-9fe1-525810f475fc after: https://github.com/tgstation/tgstation/assets/138636438/94849f4a-aaf6-4862-880b-4a6a44c4341d ## Changelog :cl: fix: mobs do not get stuck when running away from danger /:cl: * minor improvement to mob run away behavior --------- Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> --- .../run_away_from_target.dm | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/code/datums/ai/basic_mobs/basic_ai_behaviors/run_away_from_target.dm b/code/datums/ai/basic_mobs/basic_ai_behaviors/run_away_from_target.dm index fca9e7bd732..486f9a0fdb2 100644 --- a/code/datums/ai/basic_mobs/basic_ai_behaviors/run_away_from_target.dm +++ b/code/datums/ai/basic_mobs/basic_ai_behaviors/run_away_from_target.dm @@ -33,17 +33,33 @@ /datum/ai_behavior/run_away_from_target/proc/plot_path_away_from(datum/ai_controller/controller, atom/target) var/turf/target_destination = get_turf(controller.pawn) - for (var/i in 1 to run_distance) - var/turf/test_destination = get_ranged_target_turf_direct(controller.pawn, target, range = i, offset = 180) - var/list/airlocks = SSmachines.get_machines_by_type_and_subtypes(/obj/machinery/door/airlock) - if (test_destination.is_blocked_turf(exclude_mobs = TRUE, source_atom = controller.pawn, ignore_atoms = airlocks)) + var/static/list/offset_angles = list(45, 90, 135, 180, 225, 270) + for(var/angle in offset_angles) + var/turf/test_turf = get_furthest_turf(controller.pawn, angle, target) + if(isnull(test_turf)) + continue + var/distance_from_target = get_dist(target, test_turf) + if(distance_from_target <= get_dist(target, target_destination)) + continue + target_destination = test_turf + if(distance_from_target == run_distance) //we already got the max running distance break - target_destination = test_destination + if (target_destination == get_turf(controller.pawn)) return FALSE set_movement_target(controller, target_destination) return TRUE +/datum/ai_behavior/run_away_from_target/proc/get_furthest_turf(atom/source, angle, atom/target) + var/turf/return_turf + var/list/airlocks = SSmachines.get_machines_by_type_and_subtypes(/obj/machinery/door/airlock) + for(var/i in 1 to run_distance) + var/turf/test_destination = get_ranged_target_turf_direct(source, target, range = i, offset = angle) + if(test_destination.is_blocked_turf(exclude_mobs = !source.density, source_atom = source, ignore_atoms = airlocks)) + break + return_turf = test_destination + return return_turf + /datum/ai_behavior/run_away_from_target/finish_action(datum/ai_controller/controller, succeeded, target_key, hiding_location_key) . = ..() if (clear_failed_targets)