From a415453540887b5757b72bb7c3a2db874b6c6dcb Mon Sep 17 00:00:00 2001 From: silicons <2003111+silicons@users.noreply.github.com> Date: Mon, 26 Apr 2021 23:29:37 -0700 Subject: [PATCH] ripping off my own code --- code/__HELPERS/yelling.dm | 134 ++++++++++++++++++ code/game/turfs/closed.dm | 9 +- code/game/turfs/turf.dm | 11 ++ .../modules/mob/living/living_active_parry.dm | 2 +- code/modules/mob/living/say.dm | 2 +- tgstation.dme | 1 + 6 files changed, 155 insertions(+), 4 deletions(-) create mode 100644 code/__HELPERS/yelling.dm diff --git a/code/__HELPERS/yelling.dm b/code/__HELPERS/yelling.dm new file mode 100644 index 0000000000..e9a2697c87 --- /dev/null +++ b/code/__HELPERS/yelling.dm @@ -0,0 +1,134 @@ +/datum/yelling_wavefill + var/stop = FALSE + var/list/atom/collected + +/datum/yelling_wavefill/Destroy(force, ...) + stop = TRUE + return ..() + +/datum/yelling_wavefill/proc/run(atom/source, dist = 50) + collected = list() + do_run(source, dist) + // gc + if(QDELETED(src)) + collected = null + +// blatantly copied from wave explosion code +/datum/yelling_wavefill/proc/do_run(atom/source, dist) + var/list/edges = list(source = (NORTH|SOUTH|EAST|WEST)) + var/list/powers = list(source = dist) + var/list/processed_last = list() + var/turf/T + var/turf/expanding + var/power + var/dir + var/returned +#define RUN_YELL(_T, _P, _D) \ + returned = max(powers[_T] - _T.get_yelling_resistance() - 1, 0); \ + _T.maptext = "[returned]"; + + var/list/turf/edges_next = list() + var/list/turf/powers_next = list() + var/list/turf/powers_returned = list() + var/list/turf/diagonals = list() + var/list/turf/diagonal_powers = list() + var/list/turf/diagonal_powers_max = list() + + while(edges.len) + // process cardinals + for(var/i in edges) + T = i + power = powers[T] + dir = edges[T] + RUN_YELL(T, power, dir) + powers_returned[T] = returned + if(returned) + // get hearing atoms + else + continue + + // diagonal power calc when multiple things hit one diagonal +#define CALCULATE_DIAGONAL_POWER(existing, adding, maximum) min(maximum, existing + adding) + // diagonal hitting cardinal expansion +#define CALCULATE_DIAGONAL_CROSS_POWER(existing, adding) max(existing, adding) + // insanity define to mark the next set of cardinals. +#define CARDINAL_MARK(ndir, cdir, edir) \ + if(edir & cdir) { \ + expanding = get_step(T,ndir); \ + if(expanding && !processed_last[expanding] && !edges[expanding]) { \ + powers_next[expanding] = max(powers_next[expanding], returned); \ + edges_next[expanding] = (cdir | edges_next[expanding]); \ + }; \ + }; + +#define DIAGONAL_SUBSTEP(ndir, cdir, edir) \ + expanding = get_step(T,ndir); \ + if(expanding && !processed_last[expanding] && !edges[expanding]) { \ + if(!edges_next[expanding]) { \ + diagonal_powers_max[expanding] = max(diagonal_powers_max[expanding], returned, powers[T]); \ + diagonal_powers[expanding] = CALCULATE_DIAGONAL_POWER(diagonal_powers[expanding], returned, diagonal_powers_max[expanding]); \ + diagonals[expanding] = (cdir | diagonals[expanding]); \ + }; \ + else { \ + powers_next[expanding] = CALCULATE_DIAGONAL_CROSS_POWER(powers_next[expanding], returned); \ + }; \ + }; + +#define DIAGONAL_MARK(ndir, cdir, edir) \ + if(edir & cdir) { \ + DIAGONAL_SUBSTEP(turn(ndir, 90), turn(cdir, 90), edir); \ + DIAGONAL_SUBSTEP(turn(ndir, -90), turn(cdir, -90), edir); \ + }; + CARDINAL_MARK(NORTH, NORTH, dir) + CARDINAL_MARK(SOUTH, SOUTH, dir) + CARDINAL_MARK(EAST, EAST, dir) + CARDINAL_MARK(WEST, WEST, dir) + CHECK_TICK + + // to_chat(world, "DEBUG: cycle mid edges_next [english_list_assoc(edges_next)]") + + // Sweep after cardinals for diagonals + for(var/i in edges) + T = i + power = powers[T] + dir = edges[T] + returned = powers_returned[T] + DIAGONAL_MARK(NORTH, NORTH, dir) + DIAGONAL_MARK(SOUTH, SOUTH, dir) + DIAGONAL_MARK(EAST, EAST, dir) + DIAGONAL_MARK(WEST, WEST, dir) + CHECK_TICK + + // to_chat(world, "DEBUG: cycle mid diagonals [english_list_assoc(diagonals)]") + + // Process diagonals: + for(var/i in diagonals) + T = i + power = diagonal_powers[T] + dir = diagonals[T] + RUN_YELL(T, power, dir) + if(!returned) + continue + CARDINAL_MARK(NORTH, NORTH, dir) + CARDINAL_MARK(SOUTH, SOUTH, dir) + CARDINAL_MARK(EAST, EAST, dir) + CARDINAL_MARK(WEST, WEST, dir) + CHECK_TICK + + // to_chat(world, "DEBUG: cycle end edges_next [english_list_assoc(edges_next)]") + + // flush lists + processed_last = edges + diagonals + edges = edges_next + powers = powers_next + +#undef RUN_YELL +#undef DIAGONAL_SUBSTEP +#undef DIAGONAL_MARK +#undef CARDINAL_MARK + +/proc/yelling_wavefill(atom/source, dist = 50) + var/datum/yelling_wavefill/Y = new + Y.run(source, dist) + return Y.collected || list() + diff --git a/code/game/turfs/closed.dm b/code/game/turfs/closed.dm index be0c444541..9c6dbf1912 100644 --- a/code/game/turfs/closed.dm +++ b/code/game/turfs/closed.dm @@ -6,6 +6,8 @@ blocks_air = 1 rad_flags = RAD_PROTECT_CONTENTS | RAD_NO_CONTAMINATE rad_insulation = RAD_MEDIUM_INSULATION + /// How much we block yelling + var/yelling_resistance = 40 /turf/closed/Initialize() . = ..() @@ -198,16 +200,19 @@ desc = "A wall made out of a strange metal. The squares on it pulse in a predictable pattern." icon = 'icons/turf/walls/hierophant_wall.dmi' icon_state = "wall" - + /turf/closed/indestructible/rock/glacierrock name = "unaturally hard ice wall" desc = "Ice, hardened over thousands of years, you're not breaking through this." icon = 'icons/turf/walls.dmi' icon_state = "snow_rock" - + /turf/closed/indestructible/rock/glacierrock/blue name = "blue ice wall" desc = "The incredible compressive forces that formed this sturdy ice wall gave it a blue color." icon = 'icons/turf/walls.dmi' icon_state = "ice" canSmoothWith = list(/turf/closed/indestructible/rock/glacierrock/blue) + +/turf/closed/get_yelling_resistance() + return yelling_resistance diff --git a/code/game/turfs/turf.dm b/code/game/turfs/turf.dm index 0808408192..7e61364e2a 100755 --- a/code/game/turfs/turf.dm +++ b/code/game/turfs/turf.dm @@ -594,3 +594,14 @@ GLOBAL_LIST_EMPTY(station_turfs) . = ..() if(. != BULLET_ACT_FORCE_PIERCE) . = BULLET_ACT_TURF + +/turf/proc/get_yelling_resistance() + . = 0 + // don't bother checking fulltile, we don't need accuracy + var/obj/structure/window/W = locate() in src + if(W) + . += 7 + for(var/obj/machinery/door/D in src) + if(!D.density) + continue + . += D.opacity? 7 : 15 diff --git a/code/modules/mob/living/living_active_parry.dm b/code/modules/mob/living/living_active_parry.dm index e062a60aa8..32bc5fd59d 100644 --- a/code/modules/mob/living/living_active_parry.dm +++ b/code/modules/mob/living/living_active_parry.dm @@ -46,7 +46,7 @@ // Point of no return, make sure everything is set. parrying = method if(method == ITEM_PARRY) - active_parry_item = using_item + active_parry_item = tool if(!UseStaminaBuffer(data.parry_stamina_cost, TRUE)) return FALSE parry_start_time = world.time diff --git a/code/modules/mob/living/say.dm b/code/modules/mob/living/say.dm index 2f90f04cef..949a47e50c 100644 --- a/code/modules/mob/living/say.dm +++ b/code/modules/mob/living/say.dm @@ -312,7 +312,7 @@ GLOBAL_LIST_INIT(department_radio_keys, list( /atom/movable/proc/process_yelling(list/already_heard, rendered, atom/movable/speaker, datum/language/message_language, message, list/spans, message_mode, obj/source) var/list/overhearing = list() overhearing = yelling_wavefill(src, 35) - overhearing = get_hearers_in_view(35, src) | get_hearers_in_range(5, src) + // overhearing = get_hearers_in_view(35, src) | get_hearers_in_range(5, src) overhearing -= already_heard for(var/_AM in overhearing) var/atom/movable/AM = _AM diff --git a/tgstation.dme b/tgstation.dme index 017bd393e7..30229b1cda 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -199,6 +199,7 @@ #include "code\__HELPERS\vector.dm" #include "code\__HELPERS\verbs.dm" #include "code\__HELPERS\view.dm" +#include "code\__HELPERS\yelling.dm" #include "code\__HELPERS\sorts\__main.dm" #include "code\__HELPERS\sorts\InsertSort.dm" #include "code\__HELPERS\sorts\MergeSort.dm"