ripping off my own code

This commit is contained in:
silicons
2021-04-26 23:29:37 -07:00
parent eb2c12ceee
commit a415453540
6 changed files with 155 additions and 4 deletions

134
code/__HELPERS/yelling.dm Normal file
View File

@@ -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()

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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"