diff --git a/_maps/voidcrew/RandomRuins/SpaceRuins/rare_scav_den.dmm b/_maps/voidcrew/RandomRuins/SpaceRuins/rare_scav_den.dmm new file mode 100644 index 00000000000..89e081aa242 --- /dev/null +++ b/_maps/voidcrew/RandomRuins/SpaceRuins/rare_scav_den.dmm @@ -0,0 +1,4262 @@ +//MAP CONVERTED BY dmm2tgm.py THIS HEADER COMMENT PREVENTS RECONVERSION, DO NOT REMOVE +"aa" = ( +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"ab" = ( +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"ac" = ( +/turf/closed/mineral/random, +/area/ruin/space/has_grav/powered) +"ad" = ( +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"ae" = ( +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"af" = ( +/obj/item/stack/rods{ + amount = 4 + }, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"ag" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/landmark/stealth_patrol{ + route = "b"; + order = 2; + facing = 2 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"ah" = ( +/obj/structure/closet/crate/wooden, +/obj/effect/turf_decal/bot, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"ai" = ( +/obj/machinery/door/airlock/external/ruin{ + name = "External Airlock" + }, +/obj/effect/mapping_helpers/airlock/cyclelink_helper{ + dir = 4 + }, +/obj/structure/fans/tiny, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aj" = ( +/turf/closed/wall, +/area/ruin/space/has_grav/powered) +"ak" = ( +/obj/machinery/door/airlock/medical{ + name = "Theatre"; + req_one_access = list("scav") + }, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"al" = ( +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"am" = ( +/obj/machinery/door/airlock{ + name = "Bunks"; + req_one_access = list("scav") + }, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"an" = ( +/obj/machinery/door/airlock/freezer{ + name = "Cold Room"; + req_one_access = list("scav") + }, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"ao" = ( +/obj/machinery/door/airlock/highsecurity{ + name = "Office"; + req_one_access = list("scav") + }, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"ap" = ( +/obj/machinery/door/airlock/maintenance{ + name = "Chrome Bench" + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aq" = ( +/obj/machinery/power/port_gen/pacman, +/obj/effect/turf_decal/stripes/line{ + dir = 4 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"ar" = ( +/obj/machinery/door/airlock/maintenance{ + name = "Scrap" + }, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"as" = ( +/obj/machinery/door/airlock{ + name = "Back Room" + }, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"at" = ( +/obj/structure/rack, +/obj/item/storage/toolbox/mechanical, +/obj/item/weldingtool{ + pixel_y = 6 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"au" = ( +/obj/effect/spawner/structure/window/reinforced, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"av" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"aw" = ( +/obj/machinery/door/airlock/external/glass/ruin{ + name = "External Airlock" + }, +/obj/effect/mapping_helpers/airlock/cyclelink_helper{ + dir = 8 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"ax" = ( +/turf/template_noop, +/area/template_noop) +"ay" = ( +/obj/structure/grille, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"az" = ( +/obj/machinery/door/airlock/maintenance{ + name = "Back Room" + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aA" = ( +/turf/closed/wall/r_wall, +/area/ruin/space/has_grav/powered) +"aB" = ( +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aC" = ( +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"aD" = ( +/obj/machinery/door/airlock/maintenance{ + name = "Generator"; + req_one_access = list("scav") + }, +/obj/effect/turf_decal/tile/red/full, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aE" = ( +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"aF" = ( +/obj/machinery/door/airlock/maintenance{ + name = "Generator"; + req_one_access = list("scav") + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aG" = ( +/obj/machinery/door/window/left/directional/south{ + name = "cage" + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aH" = ( +/obj/machinery/door/airlock/vault{ + name = "Vault"; + req_access = list("scav_vault") + }, +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"aI" = ( +/turf/closed/wall/rust, +/area/ruin/space/has_grav/powered) +"aJ" = ( +/obj/machinery/door/airlock/maintenance{ + name = "Bay Service" + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aK" = ( +/obj/machinery/door/airlock/external/glass/ruin{ + name = "External Airlock" + }, +/obj/effect/mapping_helpers/airlock/cyclelink_helper{ + dir = 2 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aL" = ( +/obj/effect/turf_decal/tile/red/full, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aM" = ( +/obj/item/clothing/head/utility/welding{ + pixel_y = 6 + }, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aN" = ( +/obj/machinery/door/airlock/maintenance{ + name = "Crawlway" + }, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"aO" = ( +/obj/machinery/door/airlock{ + name = "Mess"; + req_one_access = list("scav") + }, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"aP" = ( +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"aQ" = ( +/obj/machinery/light/small/directional/north, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aR" = ( +/obj/machinery/door/airlock/external/ruin{ + name = "External Airlock" + }, +/obj/effect/mapping_helpers/airlock/cyclelink_helper{ + dir = 1 + }, +/obj/structure/fans/tiny, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aS" = ( +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aT" = ( +/obj/effect/decal/cleanable/blood/oil, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aU" = ( +/obj/machinery/door/airlock/security{ + name = "Pens"; + req_one_access = list("scav") + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aV" = ( +/obj/machinery/door/airlock/maintenance{ + name = "Generator" + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aW" = ( +/obj/structure/sign/poster/contraband/random, +/turf/closed/wall/rust, +/area/ruin/space/has_grav/powered) +"aX" = ( +/obj/structure/reagent_dispensers/fueltank, +/obj/effect/decal/cleanable/blood/oil, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"aY" = ( +/obj/machinery/door/airlock/mining{ + name = "Bay"; + req_one_access = list("scav") + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"aZ" = ( +/obj/effect/decal/cleanable/blood/oil, +/obj/item/wirecutters{ + pixel_x = -4 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"bg" = ( +/obj/machinery/light/small/red/directional/east, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"bh" = ( +/obj/structure/table/wood, +/obj/item/reagent_containers/cup/beaker/organ_jar{ + pixel_x = 0; + pixel_y = 6 + }, +/obj/item/paper/crumpled/bloody{ + pixel_x = -6; + pixel_y = -4 + }, +/obj/item/paper{ + name = "price list"; + default_raw_text = "Hearts 4000. Livers 2500. Lungs 2000. Eyes 1500 the pair. Chrome by weight. No refunds."; + pixel_x = 8; + pixel_y = 2 + }, +/turf/open/floor/carpet/red, +/area/ruin/space/has_grav/powered) +"bk" = ( +/obj/structure/closet/crate, +/obj/effect/turf_decal/bot, +/obj/item/stack/rods{ + amount = 10 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"bn" = ( +/obj/item/cigarette{ + pixel_x = 4; + pixel_y = 6 + }, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"br" = ( +/obj/structure/sign/warning/secure_area, +/turf/closed/wall/r_wall, +/area/ruin/space/has_grav/powered) +"bu" = ( +/obj/machinery/light/small/red/dim/directional/north, +/obj/effect/turf_decal/stripes/line{ + dir = 4 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"bv" = ( +/obj/structure/closet/crate/trashcart, +/obj/effect/turf_decal/bot, +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"bw" = ( +/obj/effect/decal/cleanable/dirt, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"cg" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/landmark/stealth_patrol{ + route = "d"; + order = 2; + facing = 1 + }, +/obj/effect/spawner/human_npc/ruin/scav/den/gunner{ + dir = 1 + }, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"ch" = ( +/obj/effect/decal/cleanable/blood/drip, +/obj/effect/decal/cleanable/blood/tracks{ + dir = 8 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"cj" = ( +/obj/structure/rack, +/obj/item/reagent_containers/cup/beaker/organ_jar{ + pixel_x = -6; + pixel_y = 6 + }, +/obj/item/reagent_containers/cup/beaker/organ_jar{ + pixel_x = 6; + pixel_y = 6 + }, +/obj/item/reagent_containers/cup/bottle/formaldehyde{ + pixel_x = 2; + pixel_y = -4 + }, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"ck" = ( +/obj/effect/turf_decal/stripes/line{ + dir = 4 + }, +/obj/effect/decal/cleanable/dirt, +/obj/machinery/light/small/red/dim/directional/west, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"cq" = ( +/obj/structure/chair/stool, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"ct" = ( +/obj/structure/closet/crate/freezer, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"cv" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/landmark/stealth_patrol{ + route = "a"; + order = 3; + wait = 0 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"cL" = ( +/obj/effect/decal/cleanable/cobweb, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"dd" = ( +/obj/structure/table, +/obj/item/organ/liver/cybernetic{ + pixel_x = -4; + pixel_y = 5 + }, +/obj/item/organ/lungs/cybernetic{ + pixel_x = 5; + pixel_y = -2 + }, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"de" = ( +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"df" = ( +/obj/structure/table, +/obj/item/wrench, +/obj/item/crowbar{ + pixel_y = 6 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"dq" = ( +/obj/structure/reagent_dispensers/water_cooler, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"dA" = ( +/obj/structure/closet/cabinet, +/obj/item/clothing/head/fedora, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"dB" = ( +/obj/structure/reagent_dispensers/watertank, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"dJ" = ( +/obj/structure/rack, +/obj/item/bodypart/arm/left/robot, +/obj/item/bodypart/arm/right/robot{ + pixel_y = 6 + }, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"dO" = ( +/obj/item/stack/medical/suture, +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"dR" = ( +/obj/effect/turf_decal/bot, +/obj/effect/decal/cleanable/blood/oil, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"dS" = ( +/obj/structure/chair/comfy/black{ + dir = 4 + }, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"eg" = ( +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"em" = ( +/obj/structure/table, +/obj/item/bodypart/arm/left/robot{ + pixel_y = 4 + }, +/obj/item/screwdriver{ + pixel_x = 8 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"eO" = ( +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"eW" = ( +/obj/structure/table, +/obj/item/reagent_containers/cup/glass/bottle/whiskey{ + pixel_x = -6; + pixel_y = 8 + }, +/obj/item/toy/cards/deck{ + pixel_x = 5 + }, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"fa" = ( +/obj/structure/rack, +/obj/item/stack/spacecash/c100{ + pixel_y = 4 + }, +/obj/effect/turf_decal/bot, +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"fE" = ( +/obj/effect/decal/cleanable/dirt/dust, +/obj/machinery/light/small/red/directional/west, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"fK" = ( +/obj/item/restraints/handcuffs/cable/zipties, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"fN" = ( +/obj/effect/decal/cleanable/blood/oil, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"fS" = ( +/obj/effect/decal/cleanable/cobweb/cobweb2, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"ga" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/blood/tracks{ + dir = 1 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"gu" = ( +/obj/structure/table/optable, +/obj/effect/mob_spawn/corpse/human, +/obj/effect/decal/cleanable/blood/splatter, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"gG" = ( +/obj/machinery/iv_drip, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"ha" = ( +/obj/machinery/light/small/red/dim/directional/north, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"hg" = ( +/obj/item/reagent_containers/cup/glass/bottle/beer{ + pixel_x = -6; + pixel_y = 4 + }, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"hi" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/dirt, +/obj/effect/landmark/stealth_patrol{ + route = "a"; + order = 1; + facing = 8 + }, +/obj/effect/spawner/human_npc/ruin/scav/den/gunner{ + dir = 8 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"ht" = ( +/obj/structure/rack, +/obj/item/knife/combat/survival{ + pixel_y = 4 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"hI" = ( +/obj/effect/decal/cleanable/blood/old, +/obj/effect/decal/cleanable/blood/gibs/old, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"hJ" = ( +/obj/effect/decal/remains/human, +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"hL" = ( +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"hN" = ( +/obj/item/bedsheet/brown, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"hO" = ( +/obj/structure/closet/crate/freezer, +/obj/item/food/meat/slab/human, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"hW" = ( +/obj/machinery/scav_camera/directional/south{ + facing_offset = 45; + sweep = 45 + }, +/obj/effect/decal/cleanable/blood/tracks{ + dir = 1 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"ic" = ( +/obj/effect/decal/cleanable/blood/tracks{ + dir = 1 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"ik" = ( +/obj/effect/decal/cleanable/dirt, +/obj/item/trash/can{ + pixel_x = 5 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"iz" = ( +/obj/effect/decal/cleanable/dirt, +/obj/item/trash/chips, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"iU" = ( +/obj/structure/table, +/obj/item/restraints/handcuffs/cable/zipties{ + pixel_x = -5 + }, +/obj/item/reagent_containers/cup/glass/mug{ + pixel_x = 6; + pixel_y = 4 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"jj" = ( +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"jo" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/dirt, +/obj/effect/landmark/stealth_patrol{ + route = "a"; + order = 5; + wait = 0 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"jA" = ( +/obj/structure/closet/crate/wooden, +/obj/effect/turf_decal/bot, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"jE" = ( +/obj/structure/table/wood, +/obj/item/flashlight/lamp/green{ + pixel_x = -4; + pixel_y = 6 + }, +/turf/open/floor/carpet/red, +/area/ruin/space/has_grav/powered) +"kt" = ( +/obj/effect/decal/cleanable/cobweb, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"kw" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"ky" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/landmark/stealth_patrol{ + route = "a"; + order = 4; + facing = 4 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"kL" = ( +/obj/effect/decal/cleanable/blood/footprints{ + dir = 1 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"kM" = ( +/obj/structure/table, +/obj/effect/spawner/random/food_or_drink/booze, +/obj/item/stack/spacecash/c50{ + pixel_x = 4; + pixel_y = -4 + }, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"kO" = ( +/obj/structure/closet/crate, +/obj/effect/turf_decal/bot, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"kS" = ( +/obj/structure/table, +/obj/machinery/microwave{ + pixel_y = 6 + }, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"kW" = ( +/obj/structure/closet/crate, +/obj/effect/turf_decal/bot, +/obj/effect/spawner/random/maintenance, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"li" = ( +/obj/effect/landmark/stealth_group, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"lp" = ( +/obj/effect/spawner/random/trash/graffiti, +/turf/closed/wall, +/area/ruin/space/has_grav/powered) +"lB" = ( +/obj/structure/closet/crate/internals, +/obj/effect/turf_decal/bot, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"lC" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/dirt/dust, +/obj/effect/landmark/stealth_patrol{ + route = "e"; + order = 4; + wait = 0 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"lY" = ( +/obj/effect/decal/cleanable/blood/gibs/robot_debris/old, +/obj/effect/decal/cleanable/blood/oil, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"mt" = ( +/obj/machinery/light/small/dim/directional/north, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"mu" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"mC" = ( +/obj/effect/decal/cleanable/blood/tracks{ + dir = 8 + }, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"mG" = ( +/obj/structure/bed/maint, +/obj/item/bedsheet/brown, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"mS" = ( +/obj/structure/closet, +/obj/item/storage/medkit/regular, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"mW" = ( +/obj/machinery/light/small/red/dim/directional/north, +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"nz" = ( +/obj/structure/closet, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"nJ" = ( +/obj/effect/decal/cleanable/vomit/old, +/obj/item/reagent_containers/cup/bucket, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"nL" = ( +/obj/machinery/light/small/directional/west, +/obj/effect/decal/cleanable/blood/tracks{ + dir = 1 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"nV" = ( +/obj/effect/turf_decal/tile/red/full, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"oq" = ( +/obj/effect/decal/cleanable/dirt, +/obj/item/ammo_casing/spent{ + pixel_x = 5; + pixel_y = -3 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"oD" = ( +/obj/structure/kitchenspike, +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"oG" = ( +/obj/effect/turf_decal/stripes/line{ + dir = 4 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"oQ" = ( +/obj/effect/decal/cleanable/dirt, +/obj/effect/spawner/random/trash/cigbutt, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"oS" = ( +/obj/effect/decal/cleanable/cobweb, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"oU" = ( +/obj/structure/closet/crate, +/obj/item/storage/box/lethalshot, +/obj/effect/spawner/random/contraband/narcotics, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"oW" = ( +/obj/effect/spawner/random/entertainment/cigarette_pack, +/obj/effect/spawner/random/entertainment/lighter, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"oX" = ( +/obj/effect/decal/cleanable/cobweb, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"oY" = ( +/obj/effect/decal/remains/human, +/obj/effect/decal/cleanable/blood/splatter, +/obj/item/restraints/handcuffs/cable/zipties, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"pb" = ( +/obj/structure/chair/stool, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"pc" = ( +/obj/machinery/light/cold/directional/north, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"ph" = ( +/obj/effect/decal/cleanable/cobweb, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"pk" = ( +/obj/effect/turf_decal/tile/red/full, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"pq" = ( +/obj/machinery/light/cold/directional/south, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"pz" = ( +/obj/effect/turf_decal/stripes/line{ + dir = 1 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"pC" = ( +/obj/machinery/light/small/red/dim/directional/north, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"pR" = ( +/obj/item/reagent_containers/cup/glass/bottle/rum{ + pixel_x = 6 + }, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"pZ" = ( +/obj/effect/decal/cleanable/blood/old, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"qf" = ( +/obj/machinery/light/small/directional/south, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"qh" = ( +/obj/effect/decal/remains/robot, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"qt" = ( +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"qC" = ( +/obj/structure/filingcabinet, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"qO" = ( +/obj/structure/sign/warning/vacuum/external, +/turf/closed/wall, +/area/ruin/space/has_grav/powered) +"qP" = ( +/obj/structure/chair/stool, +/obj/effect/spawner/random/trash/cigbutt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"qX" = ( +/obj/item/flashlight/flare, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"qZ" = ( +/obj/structure/bed/maint, +/obj/effect/spawner/random/bedsheet, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"rc" = ( +/obj/item/reagent_containers/cup/glass/bottle/whiskey{ + pixel_x = 4; + pixel_y = -8 + }, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"rd" = ( +/obj/effect/spawner/random/maintenance/two, +/obj/effect/decal/cleanable/blood/gibs/robot_debris/old, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"re" = ( +/obj/machinery/light/small/red/directional/west, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"rg" = ( +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"rm" = ( +/obj/effect/spawner/random/entertainment/cigarette_pack, +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"ro" = ( +/obj/structure/closet/crate, +/obj/effect/turf_decal/bot, +/obj/effect/spawner/random/entertainment/money_small, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"rq" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/landmark/stealth_patrol{ + route = "b"; + order = 1; + facing = 1; + route_mode = "pingpong" + }, +/obj/effect/spawner/human_npc/ruin/scav/den{ + dir = 1 + }, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"rs" = ( +/obj/item/clothing/head/soft/black{ + pixel_y = 6 + }, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"rF" = ( +/obj/structure/bed/maint, +/obj/item/bedsheet/brown, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"rJ" = ( +/obj/item/clothing/shoes/sneakers/black, +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"rK" = ( +/obj/structure/bookcase/random, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"sf" = ( +/obj/effect/turf_decal/stripes/line{ + dir = 2 + }, +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"sh" = ( +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"sq" = ( +/obj/item/reagent_containers/syringe{ + pixel_x = -5 + }, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"sH" = ( +/obj/structure/chair/wood{ + dir = 1 + }, +/obj/effect/spawner/random/trash/cigbutt, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"sZ" = ( +/obj/structure/closet/crate/zone_loot/medical, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"th" = ( +/obj/structure/closet/crate, +/obj/effect/turf_decal/bot, +/obj/effect/spawner/random/maintenance, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"tk" = ( +/obj/structure/kitchenspike, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"tn" = ( +/obj/effect/decal/cleanable/blood/tracks{ + dir = 8 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"tx" = ( +/obj/structure/table, +/obj/item/reagent_containers/cup/beaker/organ_jar{ + pixel_x = -6; + pixel_y = 5 + }, +/obj/item/reagent_containers/cup/beaker/organ_jar{ + pixel_x = 6; + pixel_y = 7 + }, +/obj/item/reagent_containers/cup/beaker/organ_jar{ + pixel_x = 0; + pixel_y = -3 + }, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"tD" = ( +/obj/effect/spawner/random/structure/chair_flipped, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"tH" = ( +/obj/machinery/scav_camera/directional/north, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"tO" = ( +/obj/structure/rack, +/obj/item/bodypart/leg/right, +/obj/item/bodypart/arm/left, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"tR" = ( +/obj/structure/closet/crate, +/obj/effect/turf_decal/bot, +/obj/item/stack/sheet/iron{ + amount = 20 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"tT" = ( +/obj/structure/sink/directional/south, +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"ub" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/landmark/stealth_patrol{ + route = "c"; + order = 2; + facing = 4 + }, +/obj/effect/spawner/human_npc/ruin/scav/den{ + dir = 4 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"uc" = ( +/obj/machinery/space_heater, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"uf" = ( +/obj/structure/sign/warning/no_smoking, +/turf/closed/wall, +/area/ruin/space/has_grav/powered) +"uj" = ( +/obj/effect/decal/cleanable/dirt, +/obj/item/stack/sheet/plastic{ + amount = 5 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"us" = ( +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"uu" = ( +/obj/structure/table/optable, +/obj/effect/decal/remains/human, +/obj/effect/decal/cleanable/blood/gibs/old, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"ux" = ( +/obj/effect/decal/cleanable/blood/oil, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"vh" = ( +/obj/item/reagent_containers/blood/o_minus{ + pixel_x = 5 + }, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"vE" = ( +/obj/machinery/light/small/directional/north, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"vH" = ( +/obj/effect/decal/cleanable/blood/tracks{ + dir = 4 + }, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"vI" = ( +/obj/effect/decal/cleanable/blood/tracks{ + dir = 4 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"vO" = ( +/obj/effect/decal/cleanable/blood/old, +/obj/item/food/meat/slab/human{ + pixel_x = -4 + }, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"vX" = ( +/obj/structure/chair/office{ + dir = 2 + }, +/obj/effect/spawner/human_npc/ruin/scav/den/boss{ + dir = 2 + }, +/turf/open/floor/carpet/red, +/area/ruin/space/has_grav/powered) +"vY" = ( +/obj/structure/sign/poster/contraband/random, +/turf/closed/wall, +/area/ruin/space/has_grav/powered) +"vZ" = ( +/obj/structure/closet/crate/bin, +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"wg" = ( +/obj/machinery/light/small/red/directional/east, +/obj/item/stack/rods{ + amount = 2 + }, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"wF" = ( +/obj/item/bodybag, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"wR" = ( +/obj/structure/closet/crate/freezer/blood, +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"wW" = ( +/obj/machinery/light/cold/dim/directional/south, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"xm" = ( +/obj/structure/closet/crate, +/obj/effect/spawner/random/maintenance/two, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"xp" = ( +/obj/structure/displaycase/noalert, +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"xq" = ( +/obj/effect/decal/cleanable/dirt, +/obj/machinery/light/small/red/dim/directional/north, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"xt" = ( +/obj/structure/table, +/obj/item/reagent_containers/cup/beaker/organ_jar{ + pixel_x = -5; + pixel_y = 6 + }, +/obj/item/reagent_containers/cup/beaker/organ_jar{ + pixel_x = 6; + pixel_y = 4 + }, +/obj/item/reagent_containers/cup/bottle/formaldehyde{ + pixel_y = -5 + }, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"xz" = ( +/obj/effect/decal/remains/human, +/obj/effect/decal/cleanable/blood/old, +/obj/item/flashlight{ + pixel_x = 6 + }, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"xZ" = ( +/obj/structure/closet/crate/large, +/obj/effect/turf_decal/bot, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"yj" = ( +/obj/structure/table/rolling, +/obj/item/surgical_drapes, +/obj/item/stack/medical/gauze, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"yr" = ( +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"yw" = ( +/obj/structure/closet/crate/freezer, +/obj/item/reagent_containers/blood/random, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"yF" = ( +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"yG" = ( +/obj/structure/table, +/obj/item/bodypart/arm/right/robot{ + pixel_x = -3; + pixel_y = 3 + }, +/obj/item/weldingtool{ + pixel_x = 6; + pixel_y = -6 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"yQ" = ( +/obj/structure/rack, +/obj/item/coin/gold{ + pixel_x = -5 + }, +/obj/item/coin/silver{ + pixel_x = 5; + pixel_y = 4 + }, +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"yR" = ( +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"zh" = ( +/obj/structure/table/wood, +/obj/item/reagent_containers/cup/glass/bottle/whiskey{ + pixel_y = 6 + }, +/obj/item/reagent_containers/cup/glass/drinkingglass{ + pixel_x = 8 + }, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"zq" = ( +/obj/structure/closet/crate, +/obj/item/bodypart/leg/left/robot, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"zw" = ( +/obj/machinery/light/small/directional/south, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"zz" = ( +/obj/effect/decal/cleanable/dirt, +/obj/effect/spawner/random/trash/cigbutt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"zF" = ( +/obj/effect/decal/cleanable/blood/tracks{ + dir = 1 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"zI" = ( +/obj/structure/table, +/obj/item/circular_saw{ + pixel_y = 4 + }, +/obj/item/cautery{ + pixel_x = 6; + pixel_y = -4 + }, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"zZ" = ( +/obj/item/stack/spacecash/c20{ + pixel_x = 4 + }, +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"Ad" = ( +/obj/effect/turf_decal/bot, +/obj/item/storage/box{ + pixel_x = -4; + pixel_y = 3 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"AG" = ( +/obj/machinery/light/small/red/directional/south, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"Be" = ( +/obj/structure/table, +/obj/item/surgicaldrill{ + pixel_y = 3 + }, +/obj/item/clothing/gloves/latex{ + pixel_x = -6; + pixel_y = -5 + }, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"Bf" = ( +/obj/machinery/light/warm/directional/north, +/obj/structure/table, +/obj/item/storage/box/donkpockets{ + pixel_y = 4 + }, +/obj/item/kitchen/fork{ + pixel_x = 8 + }, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"Bp" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"Br" = ( +/obj/item/stack/sheet/cardboard{ + amount = 5 + }, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"BG" = ( +/obj/effect/spawner/random/trash/cigbutt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"BU" = ( +/obj/item/trash/can, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"Ca" = ( +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"CG" = ( +/obj/effect/decal/cleanable/dirt/dust, +/obj/machinery/light/small/red/dim/directional/north, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"CN" = ( +/obj/structure/reagent_dispensers/fueltank, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Do" = ( +/obj/structure/table, +/obj/item/scalpel{ + pixel_x = -6; + pixel_y = 4 + }, +/obj/item/hemostat{ + pixel_x = 4 + }, +/obj/item/retractor{ + pixel_y = -5 + }, +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"Dt" = ( +/obj/item/cigbutt{ + pixel_x = 4 + }, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Dx" = ( +/obj/structure/table, +/obj/item/organ/heart/cybernetic{ + pixel_x = -5; + pixel_y = 4 + }, +/obj/item/organ/eyes/robotic/basic{ + pixel_x = 6 + }, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"DE" = ( +/obj/item/clothing/gloves/latex{ + pixel_x = 6 + }, +/obj/effect/decal/cleanable/blood/splatter, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"DG" = ( +/obj/effect/spawner/random/trash/cigbutt, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"DK" = ( +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"DO" = ( +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"DV" = ( +/obj/effect/decal/cleanable/dirt/dust, +/obj/machinery/light/small/red/dim/directional/east, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"DY" = ( +/obj/effect/turf_decal/tile/red/full, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"Eh" = ( +/obj/structure/reagent_dispensers/beerkeg, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"Eu" = ( +/obj/structure/table, +/obj/item/knife/butcher{ + pixel_y = 5 + }, +/obj/item/stack/spacecash/c200{ + pixel_x = -6; + pixel_y = -4 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Ev" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/landmark/stealth_patrol{ + route = "d"; + order = 1; + facing = 4; + chatter = 1; + route_mode = "pingpong" + }, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"EG" = ( +/obj/structure/mop_bucket, +/obj/item/mop, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"ET" = ( +/obj/item/radio{ + pixel_x = -4 + }, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"Fq" = ( +/obj/machinery/smartfridge/organ, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"Fy" = ( +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"FC" = ( +/obj/effect/decal/cleanable/cobweb, +/obj/machinery/light/small/red/dim/directional/west, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"FH" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/spawner/random/trash/garbage, +/obj/effect/landmark/stealth_patrol{ + route = "e"; + order = 2; + wait = 0 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"FM" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/dirt, +/obj/effect/landmark/stealth_patrol{ + route = "a"; + order = 2; + wait = 0 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"FO" = ( +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"Ge" = ( +/obj/structure/kitchenspike, +/obj/effect/decal/cleanable/blood/old, +/obj/effect/decal/cleanable/blood/gibs/old, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"Gh" = ( +/obj/effect/turf_decal/delivery, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Gn" = ( +/obj/effect/turf_decal/tile/red/full, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"Gp" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/landmark/stealth_patrol{ + route = "e"; + order = 3; + facing = 4 + }, +/obj/effect/spawner/human_npc/ruin/scav/den/lookout{ + dir = 4 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"Gv" = ( +/obj/item/clothing/suit/apron/surgical, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"Gx" = ( +/obj/structure/bed/maint, +/obj/item/bedsheet/brown, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"GE" = ( +/obj/machinery/scav_camera/directional/south, +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"GH" = ( +/obj/effect/spawner/random/structure/crate_abandoned, +/obj/effect/turf_decal/bot, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"GI" = ( +/obj/structure/table, +/obj/item/multitool{ + pixel_x = -4 + }, +/obj/item/stack/cable_coil{ + pixel_x = 6 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"GK" = ( +/obj/effect/spawner/human_npc/ruin/scav/den/lookout{ + dir = 8 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"GO" = ( +/obj/effect/spawner/random/structure/crate_abandoned, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"Hj" = ( +/turf/open/floor/carpet/red, +/area/ruin/space/has_grav/powered) +"Hp" = ( +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"Hq" = ( +/obj/effect/decal/cleanable/dirt, +/obj/effect/decal/cleanable/blood/tracks{ + dir = 1 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"Ht" = ( +/obj/effect/decal/cleanable/vomit/old, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"HH" = ( +/obj/machinery/door/airlock/freezer{ + name = "Cold Room"; + req_one_access = list("scav") + }, +/obj/effect/turf_decal/tile/red/full, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"HM" = ( +/obj/structure/sign/warning/biohazard, +/turf/closed/wall, +/area/ruin/space/has_grav/powered) +"HR" = ( +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"Ik" = ( +/obj/structure/closet/secure_closet/freezer/fridge, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"Iq" = ( +/obj/structure/kitchenspike, +/obj/effect/decal/cleanable/blood/old, +/obj/effect/decal/cleanable/blood/gibs/old, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"Iz" = ( +/obj/effect/spawner/random/food_or_drink/cups, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"II" = ( +/obj/structure/closet/emcloset, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"IL" = ( +/obj/effect/decal/cleanable/dirt/dust, +/obj/item/cigbutt, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"IN" = ( +/obj/structure/closet/crate/wooden, +/obj/effect/spawner/random/food_or_drink/booze, +/obj/effect/spawner/random/food_or_drink/booze, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"JJ" = ( +/obj/machinery/computer/operating{ + dir = 2 + }, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"Kb" = ( +/obj/effect/turf_decal/bot, +/obj/effect/spawner/random/structure/crate_abandoned, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"KD" = ( +/obj/machinery/light/small/directional/south, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"KS" = ( +/obj/machinery/light/small/red/dim/directional/south, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Lh" = ( +/obj/effect/landmark/stealth_restricted{ + allowed = 0 + }, +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"Lp" = ( +/obj/effect/decal/cleanable/blood/old, +/obj/item/stack/medical/gauze{ + pixel_x = 4 + }, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"LH" = ( +/obj/effect/spawner/human_npc/ruin/scav/den{ + dir = 8 + }, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"LO" = ( +/obj/structure/rack, +/obj/item/storage/briefcase{ + pixel_y = 4 + }, +/obj/effect/turf_decal/bot, +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"LZ" = ( +/obj/item/trash/chips, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Md" = ( +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"Mi" = ( +/obj/structure/table/wood, +/obj/item/stack/spacecash/c500{ + pixel_x = 4 + }, +/obj/item/pen{ + pixel_x = -6 + }, +/obj/item/folder/red{ + pixel_x = -8; + pixel_y = 4 + }, +/turf/open/floor/carpet/red, +/area/ruin/space/has_grav/powered) +"Mo" = ( +/obj/item/clothing/suit/apron/surgical{ + pixel_y = -4 + }, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"MI" = ( +/obj/item/storage/box/bodybags, +/obj/item/storage/organbox{ + pixel_y = 8 + }, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"MJ" = ( +/obj/item/reagent_containers/cup/glass/bottle/beer{ + pixel_x = 6 + }, +/obj/item/cigarette{ + pixel_x = -6 + }, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"Nc" = ( +/obj/item/storage/belt/utility, +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Nu" = ( +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"NB" = ( +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"NH" = ( +/obj/effect/decal/cleanable/blood/old, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"NO" = ( +/obj/structure/closet, +/obj/effect/spawner/random/maintenance, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"NP" = ( +/obj/effect/decal/cleanable/dirt, +/obj/structure/table, +/obj/effect/spawner/random/food_or_drink/dinner, +/obj/item/kitchen/fork{ + pixel_x = -8 + }, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"Od" = ( +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"Ok" = ( +/obj/machinery/light/small/red/dim/directional/east, +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"Os" = ( +/obj/machinery/iv_drip, +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"OP" = ( +/obj/structure/table, +/obj/item/stack/cable_coil{ + pixel_x = -4 + }, +/obj/item/screwdriver{ + pixel_x = 6; + pixel_y = 4 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"OT" = ( +/obj/machinery/light/small/directional/north, +/obj/structure/closet/crate/secure/scav_vault, +/obj/effect/turf_decal/bot, +/turf/open/floor/iron/dark/smooth_large, +/area/ruin/space/has_grav/powered) +"Pc" = ( +/obj/effect/spawner/random/trash/food_packaging, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"Pf" = ( +/obj/structure/closet/cabinet, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"Pg" = ( +/obj/item/storage/backpack/duffelbag, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"Pp" = ( +/obj/structure/chair{ + dir = 4 + }, +/obj/effect/spawner/random/trash/cigbutt, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"Pq" = ( +/obj/machinery/light/warm/directional/east, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"Ps" = ( +/obj/machinery/light/small/directional/east, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"Pw" = ( +/obj/machinery/light/cold/dim/directional/north, +/obj/structure/closet/crate/freezer, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"PF" = ( +/obj/effect/spawner/random/trash/food_packaging, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"PS" = ( +/obj/structure/table, +/obj/item/reagent_containers/cup/beaker/organ_jar{ + pixel_x = -4; + pixel_y = 6 + }, +/obj/item/clothing/mask/surgical{ + pixel_x = 6; + pixel_y = -4 + }, +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"QF" = ( +/obj/item/dice/d6{ + pixel_x = 6 + }, +/obj/effect/decal/cleanable/dirt/dust, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"QP" = ( +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"QT" = ( +/obj/item/ammo_box/magazine/m9mm, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Rj" = ( +/obj/structure/closet/crate/wooden, +/obj/effect/spawner/random/food_or_drink/booze, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Ru" = ( +/obj/effect/decal/cleanable/blood/splatter, +/obj/effect/spawner/human_npc/ruin/scav/den{ + dir = 8 + }, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"Ry" = ( +/obj/structure/rack, +/obj/item/tank/internals/oxygen{ + pixel_x = -4 + }, +/obj/item/tank/internals/oxygen{ + pixel_x = 4 + }, +/obj/item/clothing/mask/breath, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"RD" = ( +/obj/machinery/scav_camera/directional/south, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Sa" = ( +/obj/machinery/door/airlock{ + name = "Bunks"; + req_one_access = list("scav") + }, +/obj/effect/turf_decal/tile/red/full, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"Sm" = ( +/obj/item/reagent_containers/syringe{ + pixel_x = 6; + pixel_y = 6 + }, +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"SR" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/dirt, +/obj/effect/landmark/stealth_patrol{ + route = "e"; + order = 1; + facing = 1 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"SV" = ( +/obj/effect/decal/cleanable/blood/splatter, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"SW" = ( +/obj/structure/closet/crate/zone_loot/medical, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"Ta" = ( +/obj/item/clothing/under/color/grey, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"Tl" = ( +/obj/effect/spawner/random/trash/cigbutt, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"Tr" = ( +/obj/structure/ore_box, +/obj/effect/turf_decal/bot, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Tw" = ( +/obj/item/storage/briefcase{ + pixel_x = -4 + }, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"TH" = ( +/obj/structure/table, +/obj/effect/spawner/random/food_or_drink/booze, +/obj/item/reagent_containers/cup/glass/drinkingglass{ + pixel_x = 8 + }, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"TJ" = ( +/obj/effect/decal/cleanable/dirt/dust, +/obj/effect/decal/cleanable/cobweb/cobweb2, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"TV" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/landmark/stealth_patrol{ + route = "c"; + order = 1; + facing = 8; + route_mode = "pingpong" + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"UF" = ( +/obj/effect/decal/cleanable/cobweb/cobweb2, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"UH" = ( +/obj/machinery/light/small/red/dim/directional/west, +/obj/effect/spawner/random/trash/cigbutt, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"UM" = ( +/obj/structure/closet/crate/bin, +/obj/effect/decal/cleanable/cobweb, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"UW" = ( +/obj/effect/decal/cleanable/cobweb/cobweb2, +/obj/machinery/light/small/red/dim/directional/north, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"VG" = ( +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"VN" = ( +/obj/machinery/light/small/directional/south, +/obj/effect/decal/cleanable/blood/tracks{ + dir = 8 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"VQ" = ( +/obj/structure/closet/crate, +/obj/effect/turf_decal/bot, +/obj/item/stack/sheet/mineral/plasma{ + amount = 10 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"VX" = ( +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"VY" = ( +/obj/effect/decal/cleanable/blood/gibs/robot_debris/old, +/obj/effect/decal/cleanable/blood/oil, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Wc" = ( +/obj/structure/chair/stool, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Wg" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/spawner/random/trash/garbage, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"Wu" = ( +/obj/structure/closet/crate/freezer/blood, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"WJ" = ( +/obj/structure/chair/wood{ + dir = 1 + }, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"Xe" = ( +/obj/effect/turf_decal/stripes/line{ + dir = 8 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Xg" = ( +/obj/item/ammo_casing/spent{ + pixel_x = -6; + pixel_y = 2 + }, +/obj/effect/spawner/random/trash/cigbutt, +/obj/effect/spawner/human_npc/ruin/scav/den/gunner{ + dir = 2 + }, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Xn" = ( +/obj/structure/bed/medical, +/obj/item/restraints/handcuffs/cable/zipties, +/obj/effect/decal/cleanable/blood/old, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"Xz" = ( +/obj/structure/closet/crate, +/obj/effect/turf_decal/bot, +/obj/effect/spawner/random/maintenance/two, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"XE" = ( +/obj/effect/decal/cleanable/dirt/dust, +/obj/machinery/light/small/red/directional/south, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"XI" = ( +/obj/item/kirbyplants/random, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"XJ" = ( +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"XK" = ( +/obj/effect/turf_decal/tile/red/full, +/obj/effect/decal/cleanable/dirt, +/obj/effect/decal/cleanable/cobweb, +/turf/open/floor/plating/rust, +/area/ruin/space/has_grav/powered) +"XO" = ( +/obj/structure/closet/secure_closet/freezer/meat, +/turf/open/floor/iron/freezer, +/area/ruin/space/has_grav/powered) +"Yd" = ( +/obj/structure/table, +/obj/item/toy/cards/deck{ + pixel_y = 4 + }, +/obj/item/reagent_containers/cup/glass/bottle/vodka{ + pixel_x = -8; + pixel_y = 8 + }, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"Yj" = ( +/obj/machinery/light/small/red/dim/directional/north, +/obj/effect/decal/cleanable/dirt, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) +"Yx" = ( +/obj/item/bedsheet/brown, +/obj/effect/decal/cleanable/blood/drip, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"YE" = ( +/obj/machinery/light/small/directional/west, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"YK" = ( +/obj/effect/decal/cleanable/blood/gibs/robot_debris/limb, +/obj/effect/decal/cleanable/blood/oil, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"Zk" = ( +/obj/effect/spawner/random/trash/cigbutt, +/turf/open/floor/iron/grimy, +/area/ruin/space/has_grav/powered) +"Zo" = ( +/obj/structure/table, +/obj/effect/spawner/random/food_or_drink/snack, +/obj/item/reagent_containers/cup/glass/mug{ + pixel_x = -6 + }, +/turf/open/floor/iron/cafeteria, +/area/ruin/space/has_grav/powered) +"ZB" = ( +/obj/structure/closet/crate/freezer, +/turf/open/floor/iron/white, +/area/ruin/space/has_grav/powered) +"ZF" = ( +/obj/effect/decal/cleanable/blood/gibs/robot_debris/old, +/turf/open/floor/plating, +/area/ruin/space/has_grav/powered) +"ZV" = ( +/obj/effect/landmark/stealth_restricted, +/turf/open/floor/wood, +/area/ruin/space/has_grav/powered) +"ZX" = ( +/obj/effect/spawner/random/trash/garbage, +/obj/effect/decal/cleanable/blood/tracks{ + dir = 8 + }, +/turf/open/floor/iron/dark, +/area/ruin/space/has_grav/powered) + +(1,1,1) = {" +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +"} +(2,1,1) = {" +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +aj +ai +aj +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +"} +(3,1,1) = {" +ax +ax +ax +ax +ax +ax +ax +ac +ax +ax +ax +ac +ac +ac +ac +ac +ac +ax +ax +ac +ac +ac +ac +ac +ac +ac +ac +qO +bu +aj +ac +ac +ac +ac +ac +ax +ax +ax +ax +ax +"} +(4,1,1) = {" +ax +ax +ax +ax +ax +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +aj +aw +aj +ac +ac +ac +ac +ac +ac +ax +ax +ax +ax +"} +(5,1,1) = {" +ax +ax +ax +ax +ax +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +TJ +aP +xz +fE +aP +aP +Md +de +re +IL +FO +FC +Md +ac +ac +ac +ac +ac +ac +ac +ac +ac +ax +ax +"} +(6,1,1) = {" +ax +ax +ax +ax +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +aP +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ax +ax +"} +(7,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +xq +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ax +ax +"} +(8,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aj +aj +aj +aj +vY +aj +aj +aj +aj +aN +aj +aj +aj +aj +aj +HM +aj +aj +aj +aj +aj +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ax +ax +"} +(9,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aj +qZ +ph +cq +ae +Ta +qZ +aj +oS +sh +aj +Fq +cL +Ca +ad +XO +ad +Dx +ad +SW +aj +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ax +ax +"} +(10,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aj +ae +MJ +Yd +ae +Zk +ae +vY +pC +DO +aj +yw +ad +yr +ad +Sm +ad +ad +wF +Wu +aj +ac +ac +aI +aI +aI +aW +aI +aI +aI +ac +ax +ax +"} +(11,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aj +qZ +ae +cq +ae +QF +ae +aj +Nu +al +aj +Pw +ad +Lp +VX +ad +yj +ad +ad +ct +aj +ac +ac +aI +at +aS +aq +aX +aS +aI +ac +ac +ax +"} +(12,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aj +mt +Pg +ae +cg +ae +ae +am +DO +al +aj +ct +ad +ad +ad +ad +ad +ad +Ht +hO +aj +aI +aI +aI +aQ +aB +aS +aZ +af +aI +ac +ac +ax +"} +(13,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aj +rF +ae +ET +nV +Pc +ae +aj +DO +Tl +aj +ad +ad +rq +pk +pk +pk +pk +pk +pk +HH +XK +av +aD +aL +aL +aL +ag +aS +aI +ac +ac +ax +"} +(14,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aj +ae +yF +oW +nV +ae +VG +aj +pC +al +lp +tk +Ca +ad +Ca +ad +ad +ad +ad +ad +aj +aI +aI +aI +aM +aS +aT +aS +aS +aW +ac +ac +ax +"} +(15,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aj +qZ +rs +ae +nV +ae +mG +aj +al +tD +aj +Iq +pZ +ad +mC +ad +ad +ad +ad +wW +aj +ac +ac +aI +OP +aS +uc +aS +ah +aI +ac +ac +ax +"} +(16,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aj +NO +ae +yF +nV +ae +mS +aj +sh +al +aj +oD +vO +ad +mC +ad +ad +ad +xt +dd +aj +ac +ac +aI +aS +yR +zz +aS +VQ +aI +ac +ac +ax +"} +(17,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aj +aj +aj +aj +Sa +aj +aj +aj +al +al +aj +aj +vY +aj +aj +an +aj +aj +vY +aj +aj +aj +aj +aI +aI +aV +aI +aI +aI +aI +ac +ac +ax +"} +(18,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aj +Ik +aC +iz +Gn +PF +qt +aj +oS +DO +al +Nu +DO +DO +vI +zF +nL +zF +Hq +zF +hW +aj +dB +ux +YE +aS +aS +Br +UM +aj +ac +ac +ax +"} +(19,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aj +kS +aC +pb +Gn +DG +aC +vY +DO +FM +DY +DY +kw +DY +DY +hi +DY +kw +DY +jo +tn +vY +lB +us +aS +pz +GH +kO +aS +aj +ac +ac +ax +"} +(20,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aj +Bf +pb +DG +Gn +aC +aC +aj +al +Bp +aj +aj +HM +aj +ak +aj +vY +aj +aj +DY +ZX +aj +ah +aS +TV +pz +aS +kO +aS +aj +ac +ac +ax +"} +(21,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aj +TH +aC +aC +Ev +PF +aC +aj +Yj +DY +aj +Ge +Mo +Hp +QP +sq +aa +wR +aj +kw +VN +aj +Ry +aS +aL +pz +xZ +aS +zw +aj +ac +ac +ax +"} +(22,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aj +Eh +rg +pb +eW +aC +aC +aO +al +Bp +au +tx +aa +gG +jj +Do +aa +ZB +au +DY +tn +aj +aS +aS +aL +pz +xZ +dR +aS +aj +ac +ac +ax +"} +(23,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aj +aC +BU +aC +Zo +pb +aC +aj +DO +kw +aj +pc +SV +JJ +gu +aa +aa +MI +aj +DY +tn +aj +aQ +Dt +aL +pz +Xz +aT +zz +aj +ac +ac +ax +"} +(24,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aj +aC +NP +hg +LH +aC +pb +vY +al +DY +vY +PS +aa +aa +Ru +aa +jj +EG +aj +DY +ch +aj +Xg +aS +ga +pz +aS +aS +fK +aj +ac +ac +ax +"} +(25,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aj +dq +pb +Iz +aC +Pq +kM +aj +DO +DY +aj +tT +Hp +li +Od +DE +aa +pq +aj +mu +eg +aY +yR +eO +ga +eO +Fy +eO +aS +aj +ac +ac +ax +"} +(26,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aI +aI +aI +aI +aI +aI +aI +aI +al +DY +vY +aa +XJ +aa +NH +zI +Od +aa +uf +DY +Nu +aj +eO +aS +aL +aS +Tr +Ad +RD +aj +ac +ac +ax +"} +(27,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aI +em +yR +yG +Eu +df +aS +aI +CG +Bp +aj +pc +XJ +aa +uu +aa +vh +aa +aj +kw +al +aj +aS +tR +aL +aS +bv +aS +aS +aj +ac +ac +ax +"} +(28,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aI +GI +aS +aS +Wc +aS +YK +aI +al +DY +au +cj +aa +Os +vH +Be +aa +Gv +au +DY +oQ +aj +aS +kW +aL +aS +Kb +aS +Xe +qO +aj +aj +ax +"} +(29,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aI +aS +yR +aS +Nc +aS +aS +ap +al +DY +aj +sZ +aa +aa +vH +Od +dO +Xn +aj +kw +al +vY +aS +aS +aL +oq +aS +pz +Gh +aK +ck +aR +ax +"} +(30,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aI +aQ +aS +VY +aS +uj +aS +au +Tl +DY +aj +aj +vY +aj +ak +aj +vY +aj +aj +DY +al +aj +aS +kL +ub +aS +bk +aS +oG +aj +aj +aj +ax +"} +(31,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aI +xm +aS +aT +aS +ZF +QT +aI +al +cv +kw +DY +DY +DY +Bp +DY +kw +Bp +kw +ky +al +aj +CN +ik +yR +aS +xZ +aS +aS +aj +ac +ac +ax +"} +(32,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aI +tO +aS +aS +aS +aS +vZ +aI +tH +DO +Nu +al +al +Ps +tn +zF +zF +Hq +zF +zF +fN +aj +II +aS +aS +aS +aB +DV +UF +aj +ac +ac +ax +"} +(33,1,1) = {" +ax +ac +ac +ac +ac +ac +ac +aA +aj +aj +aj +vY +aj +aj +aj +Nu +al +aj +aj +aj +aj +aI +aI +au +aI +aI +aU +aI +aI +aj +aj +aj +aJ +aj +aj +aj +aj +ac +ac +ax +"} +(34,1,1) = {" +ax +ac +ac +aA +aA +aA +aA +aA +qC +Tw +rK +dS +zh +XI +aj +al +al +al +Pp +Nu +th +aI +ha +hJ +ay +eO +aS +qP +aI +ac +ac +ac +kt +ac +ac +ac +ac +ac +ac +ax +"} +(35,1,1) = {" +ax +ac +ac +aA +fa +hL +aE +aA +qC +ab +ZV +bn +rc +KD +aj +vE +al +al +al +DO +jA +aI +Yx +LZ +aG +ic +aS +BG +aI +ac +ac +ac +AG +ac +ac +ac +ac +ac +ac +ax +"} +(36,1,1) = {" +ax +ac +ac +aA +LO +aE +GE +br +XI +NB +Hj +Hj +jE +WJ +aj +al +SR +Bp +Bp +lC +al +aW +aI +aI +aI +aS +eO +Fy +aI +ac +ac +ac +aP +ac +ac +ac +ac +ac +ac +ax +"} +(37,1,1) = {" +ax +ac +ac +aA +aE +Lh +sf +aH +ab +ab +Hj +vX +bh +ab +ao +al +kw +sh +al +DY +DO +aI +nJ +aS +ay +aS +yR +KS +aI +ac +ac +ac +Md +ac +ac +ac +ac +ac +ac +ax +"} +(38,1,1) = {" +ax +ac +ac +aA +OT +aE +hL +aA +ab +DK +Hj +Hj +Mi +sH +aj +al +DY +aW +aI +kw +al +aI +aS +oY +aG +ic +aS +aS +aI +ac +ac +ac +FO +ac +ac +ac +ac +ac +ac +ax +"} +(39,1,1) = {" +ax +ac +ac +aA +xp +yQ +aE +aA +UW +ab +ab +ab +ab +zZ +aj +Tl +DY +aI +aI +kw +al +aI +aI +aI +aI +aS +eO +aS +aI +ac +ac +ac +aP +ac +ac +ac +ac +ac +ac +ax +"} +(40,1,1) = {" +ax +ac +ac +aA +aA +aA +aA +aA +ab +ab +ab +ab +ab +Pf +vY +mW +Wg +aI +aI +DY +qf +aI +ha +hN +ay +eO +aS +iU +aI +ac +ac +ac +AG +ac +ac +ac +ac +ac +ac +ax +"} +(41,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aA +aI +aI +as +aI +aI +aI +aI +DO +DY +aI +aW +DY +DO +aI +hI +rJ +aG +aS +GK +nz +aI +ac +ac +ac +Md +ac +ac +ac +ac +ac +ac +ax +"} +(42,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aI +oX +us +aS +aS +UH +dA +aI +sh +DY +al +al +DY +al +aI +aI +aI +aW +aI +aI +aI +aI +ac +ac +ac +aP +ac +ac +ac +ac +ac +ac +ax +"} +(43,1,1) = {" +ax +ax +ac +ac +ac +ac +ac +aI +ht +aS +aS +aB +aS +aS +az +al +FH +DY +DY +Gp +al +aj +aI +dJ +aP +qh +aP +rd +aI +ac +ac +ac +de +ac +ac +ac +ac +ac +ac +ax +"} +(44,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aI +oU +rm +pR +aS +aS +yR +aI +DO +al +sh +sh +DO +ro +vY +aI +GO +aP +lY +aP +aP +aI +ac +ac +ac +de +ac +ac +ac +ac +ac +ac +ax +"} +(45,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aI +Gx +qX +aS +IN +aS +Rj +aI +al +al +Ok +DO +al +al +aj +aI +fS +aP +aP +aP +zq +aI +ac +ac +ac +XE +ac +ac +ac +ac +ac +ac +ax +"} +(46,1,1) = {" +ax +ax +ax +ac +ac +ac +ac +aI +aI +aI +aW +aI +aI +aI +aI +aj +aj +aj +aj +ha +aj +aj +aI +aI +aI +ar +aI +aI +aI +ac +ac +ac +aP +ac +ac +ac +ac +ac +ax +ax +"} +(47,1,1) = {" +ax +ax +ax +ax +ax +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +FO +ac +ac +ac +ac +ac +FO +ac +ac +ac +ac +ac +ac +FO +ac +ac +ac +ac +ac +ax +ax +"} +(48,1,1) = {" +ax +ax +ax +ax +ax +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +fS +aP +HR +bw +bg +FO +aP +FO +aP +wg +aP +FO +Md +fS +ac +ac +ac +ac +ax +ax +ax +"} +(49,1,1) = {" +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ac +ax +ax +ax +ax +ax +"} +(50,1,1) = {" +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +ax +"} diff --git a/tgstation.dme b/tgstation.dme index 8db7849486c..35ee24d7392 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -6749,6 +6749,9 @@ #include "voidcrew\_DEFINES\ship_signals.dm" #include "voidcrew\_DEFINES\shuttles.dm" #include "voidcrew\_DEFINES\sound.dm" +#include "voidcrew\_DEFINES\stealth.dm" +#include "voidcrew\_DEFINES\stealth_hearing.dm" +#include "voidcrew\_DEFINES\stealth_hostage.dm" #include "voidcrew\_DEFINES\subsystems.dm" #include "voidcrew\_DEFINES\techweb_nodes.dm" #include "voidcrew\_DEFINES\trade.dm" @@ -6847,6 +6850,7 @@ #include "voidcrew\edits\datums\alarm.dm" #include "voidcrew\edits\datums\cogbar.dm" #include "voidcrew\edits\datums\communications.dm" +#include "voidcrew\edits\datums\neck_slice_mute.dm" #include "voidcrew\edits\datums\actions\mobs\charge.dm" #include "voidcrew\edits\datums\components\gps.dm" #include "voidcrew\edits\datums\components\jukebox.dm" @@ -6962,6 +6966,7 @@ #include "voidcrew\edits\objects\items\extinguisher.dm" #include "voidcrew\edits\objects\items\kinetic_accelerator_modkits.dm" #include "voidcrew\edits\objects\items\posibrain.dm" +#include "voidcrew\edits\objects\items\shield_rear.dm" #include "voidcrew\edits\objects\items\weapon_ladder.dm" #include "voidcrew\edits\objects\structures\closet_containment.dm" #include "voidcrew\edits\objects\structures\movable_fixtures.dm" @@ -7344,6 +7349,7 @@ #include "voidcrew\modules\hyperviolence\hitlines\npc_blood.dm" #include "voidcrew\modules\hyperviolence\overlays_exec\executions.dm" #include "voidcrew\modules\hyperviolence\overlays_exec\gore_overlays.dm" +#include "voidcrew\modules\hyperviolence\overlays_exec\knife_executions.dm" #include "voidcrew\modules\hyperviolence\overlays_exec\sleeve_mask.dm" #include "voidcrew\modules\hyperviolence\visuals\_defines.dm" #include "voidcrew\modules\hyperviolence\visuals\_motion_core.dm" @@ -7355,6 +7361,7 @@ #include "voidcrew\modules\hyperviolence\visuals\flying_gore.dm" #include "voidcrew\modules\hyperviolence\visuals\gut_motion.dm" #include "voidcrew\modules\hyperviolence\visuals\hit_reactions.dm" +#include "voidcrew\modules\hyperviolence\visuals\knife_execution_motion.dm" #include "voidcrew\modules\hyperviolence\visuals\npc_motion.dm" #include "voidcrew\modules\hyperviolence\wire\_wire_defines.dm" #include "voidcrew\modules\hyperviolence\wire\wire_cut.dm" @@ -7886,6 +7893,30 @@ #include "voidcrew\modules\shuttle\survey\survey_data_disk.dm" #include "voidcrew\modules\shuttle\survey\survey_designs.dm" #include "voidcrew\modules\slime_extract_piles\slime_extract_piles.dm" +#include "voidcrew\modules\stealth\scav_camera.dm" +#include "voidcrew\modules\stealth\scav_den.dm" +#include "voidcrew\modules\stealth\scav_guards.dm" +#include "voidcrew\modules\stealth\stealth_admin.dm" +#include "voidcrew\modules\stealth\stealth_admin_noise.dm" +#include "voidcrew\modules\stealth\stealth_ai.dm" +#include "voidcrew\modules\stealth\stealth_closet.dm" +#include "voidcrew\modules\stealth\stealth_crits.dm" +#include "voidcrew\modules\stealth\stealth_den_planet.dm" +#include "voidcrew\modules\stealth\stealth_disguise.dm" +#include "voidcrew\modules\stealth\stealth_doors.dm" +#include "voidcrew\modules\stealth\stealth_hearing.dm" +#include "voidcrew\modules\stealth\stealth_hostage.dm" +#include "voidcrew\modules\stealth\stealth_hostage_pose.dm" +#include "voidcrew\modules\stealth\stealth_knife.dm" +#include "voidcrew\modules\stealth\stealth_light.dm" +#include "voidcrew\modules\stealth\stealth_meter.dm" +#include "voidcrew\modules\stealth\stealth_noise.dm" +#include "voidcrew\modules\stealth\stealth_noise_sources.dm" +#include "voidcrew\modules\stealth\stealth_patrol.dm" +#include "voidcrew\modules\stealth\stealth_perception.dm" +#include "voidcrew\modules\stealth\stealth_radio.dm" +#include "voidcrew\modules\stealth\stealth_skill.dm" +#include "voidcrew\modules\stealth\stealth_turns.dm" #include "voidcrew\modules\storage\cargo_shelf.dm" #include "voidcrew\modules\storage\smart_locker.dm" #include "voidcrew\modules\storage\wall_locker.dm" diff --git a/voidcrew/_DEFINES/hyperviolence.dm b/voidcrew/_DEFINES/hyperviolence.dm index 323d88097c0..c167e2a0645 100644 --- a/voidcrew/_DEFINES/hyperviolence.dm +++ b/voidcrew/_DEFINES/hyperviolence.dm @@ -106,3 +106,10 @@ #define WOUND_SERIES_HV_CAROTID "wound_series_hv_carotid" /// A torn aorta. #define WOUND_SERIES_HV_AORTA "wound_series_hv_aorta" + +// Knife executions (voidcrew/modules/hyperviolence/overlays_exec/knife_executions.dm). + +/// Wind-up before a knife execution cuts the throat. +#define HV_KNIFE_EXECUTION_WINDUP (1.5 SECONDS) +/// do_after interaction key for a knife execution wind-up. +#define HV_KNIFE_EXECUTION_DOAFTER "hv_knife_execution" diff --git a/voidcrew/_DEFINES/stealth.dm b/voidcrew/_DEFINES/stealth.dm new file mode 100644 index 00000000000..7678f671fc3 --- /dev/null +++ b/voidcrew/_DEFINES/stealth.dm @@ -0,0 +1,315 @@ +// Stealth layer for chosen human NPCs (voidcrew/modules/stealth/). Awareness is AI state only. + +// ===== Awareness states (BB_STEALTH_STATE) ===== +#define STEALTH_UNAWARE "unaware" +#define STEALTH_SUSPICIOUS "suspicious" +#define STEALTH_ALERT "alert" +#define STEALTH_SEARCHING "searching" + +// ===== Blackboard keys ===== +/// One of the STEALTH_* states +#define BB_STEALTH_STATE "stealth_state" +/// world.time of the last state change +#define BB_STEALTH_STATE_SINCE "stealth_state_since" +/// world.time the guard last stopped being unaware (stealth_was_unaware()) +#define BB_STEALTH_UNAWARE_LOST_AT "stealth_unaware_lost_at" +/// The state before the last change, so a blow can be judged by the state it began in (stealth_state_at_blow()) +#define BB_STEALTH_PREV_STATE "stealth_prev_state" +/// TRUE once alerted, searching or hit. Fades after STEALTH_WARY_TIME with nothing new (checked each scan). +#define BB_STEALTH_WARY "stealth_wary" +/// The candidate with the highest notice +#define BB_STEALTH_FOCUS "stealth_focus" +/// world.time it last saw (or was hit from) whoever it is after; the turf is the controller's last_seen_turf +#define BB_STEALTH_LAST_SEEN_AT "stealth_last_seen_at" +/// REFs of fallen group members it has already reacted to +#define BB_STEALTH_BODIES_SEEN "stealth_bodies_seen" + +// Notice entry fields (the controller's notice_map) +#define STEALTH_ENTRY_NOTICE 1 +#define STEALTH_ENTRY_TURF 2 +#define STEALTH_ENTRY_SEEN_AT 3 + +// ===== Bark kinds ===== +#define STEALTH_BARK_SUSPICIOUS "stealth_suspicious" +#define STEALTH_BARK_GIVE_UP "stealth_give_up" +#define STEALTH_BARK_LOST "stealth_lost" +#define STEALTH_BARK_SEARCH "stealth_search" +#define STEALTH_BARK_HIT_UNSEEN "stealth_hit_unseen" +#define STEALTH_BARK_BODY "stealth_body" +#define STEALTH_BARK_CHATTER "stealth_chatter" +/// It just put its target down +#define STEALTH_BARK_DOWNED "stealth_target_downed" +/// It yanks open the locker or crate it saw its target get into (decision 33) +#define STEALTH_BARK_CLOSET_OPEN "stealth_closet_open" +/// It gives up on a locker or crate it can't get open (decision 33) +#define STEALTH_BARK_CLOSET_GIVE_UP "stealth_closet_give_up" + +// ===== What a stealth goto is for ===== +#define STEALTH_GOTO_PATROL "patrol" +#define STEALTH_GOTO_INVESTIGATE "investigate" +#define STEALTH_GOTO_BODY "body" +#define STEALTH_GOTO_SEARCH "search" +#define STEALTH_GOTO_HOME "home" +#define STEALTH_GOTO_CLOSET "closet" + +// ===== Numbers (first playtest defaults; the owner tunes them) ===== +#define STEALTH_SCAN_INTERVAL (1 SECONDS) +#define STEALTH_SIGHT_RANGE 8 +#define STEALTH_ALERT_MAX_RANGE 7 +#define STEALTH_DARK_LUMCOUNT 0.2 +#define STEALTH_DARK_MULT 0.5 +/// Elbow to elbow: someone this close in its cone is seen whatever the light (decision 31) +#define STEALTH_ADJACENT_RANGE 1 +/// Point-blank (decision 32): someone it can see in its cone this close is an alert on that look +#define STEALTH_POINT_BLANK_RANGE 2 +/// Near (decision 32): in its cone up to this far, notice fills STEALTH_NEAR_MULT times faster +#define STEALTH_NEAR_RANGE 4 +#define STEALTH_NEAR_MULT 3 +#define STEALTH_CONE_HALF_ANGLE 60 +#define STEALTH_NOTICE_MIN_FALLOFF 0.25 +#define STEALTH_SUSPICIOUS_AT 1.0 +#define STEALTH_ALERT_AT 2.5 +/// Notice never climbs past this, so nobody banks a lead that hides someone else +#define STEALTH_NOTICE_MAX STEALTH_ALERT_AT +#define STEALTH_NOTICE_DECAY 0.34 +#define STEALTH_NOTICE_FORGET (20 SECONDS) +#define STEALTH_BEHIND_RATE 0.4 +#define STEALTH_STILL_MULT 0.5 +#define STEALTH_LYING_MULT 0.5 +#define STEALTH_SUSPICIOUS_MULT 1.5 +#define STEALTH_SEARCHING_MULT 2 +#define STEALTH_WARY_MULT 1.5 +#define STEALTH_MAX_CANDIDATES 8 +#define STEALTH_LOOK_AROUND_TIME (4 SECONDS) +#define STEALTH_SUSPICIOUS_TIMEOUT (12 SECONDS) +#define STEALTH_LOSE_TARGET_TIME (4 SECONDS) +#define STEALTH_SEARCH_TIME (40 SECONDS) +/// After putting its target down with nobody else about: how long it looks round before calming down +#define STEALTH_CALM_LOOK_TIME (6 SECONDS) +/// How long wary lasts after the last notice gain, hit, touch, alert or search +#define STEALTH_WARY_TIME (60 SECONDS) +#define STEALTH_SEARCH_POINTS 3 +#define STEALTH_SEARCH_RADIUS 5 +#define STEALTH_BODY_SCAN_INTERVAL (2 SECONDS) +#define STEALTH_BARK_KIND_COOLDOWN (8 SECONDS) +#define STEALTH_GROUP_RADIUS 48 +#define STEALTH_ROUTE_CLAIM_RANGE 2 +#define STEALTH_PATROL_DEFAULT_WAIT (6 SECONDS) +#define STEALTH_LOOK_TURN_INTERVAL (3 SECONDS) +#define STEALTH_LOOK_TURN_ARC 90 +#define STEALTH_SENTRY_TURN_INTERVAL (8 SECONDS) +/// How long a sentry looks aside before it faces its post again +#define STEALTH_SENTRY_GLANCE_TIME (2 SECONDS) +#define STEALTH_CHATTER_RANGE 3 +#define STEALTH_CHATTER_COOLDOWN (45 SECONDS) +#define STEALTH_PATROL_MAX_FAILS 3 +#define STEALTH_PATROL_SKIP_TIME (2 MINUTES) +#define STEALTH_PATROL_MAX_PATH 60 +#define STEALTH_LEASH_RANGE 24 +/// Tiles a single walk covers; a destination further off is walked in legs +#define STEALTH_WALK_LEG 40 +/// A sentry that can't get back to its post tries again this often +#define STEALTH_HOME_RETRY_TIME (30 SECONDS) +/// Alert: someone else must be this many tiles nearer than its target before it turns on them +#define STEALTH_SWITCH_MARGIN 2 +/// Alert: the shortest time between two changes of target +#define STEALTH_SWITCH_COOLDOWN (4 SECONDS) +/// Health lost within STEALTH_HARM_WINDOW, with nobody to blame, that sends it looking +#define STEALTH_HARM_HEALTH 10 +#define STEALTH_HARM_WINDOW (10 SECONDS) +/// The shortest time between two reactions to harm nobody can be blamed for +#define STEALTH_HARM_COOLDOWN (10 SECONDS) +/// How far its group hears it being blown up, burned, gassed or stunned +#define STEALTH_HARM_ALERT_RANGE 9 +#define STEALTH_ADMIN_OVERLAY_TIME (5 MINUTES) +/// Seconds of search between "Come on out." lines +#define STEALTH_SEARCH_BARK_INTERVAL (12 SECONDS) + +// Lockers and crates it saw someone get into (decision 33, stealth_closet.dm) +/// Seen on open ground this recently and now in a locker in view: it saw them get in +#define STEALTH_CLOSET_SEEN_WINDOW (1.5 SECONDS) +/// After this long on one locker (walking, opening, bashing) it gives up and searches round it +#define STEALTH_CLOSET_GIVE_UP_TIME (45 SECONDS) +/// A guard that isn't the one opening it stands this close and covers it +#define STEALTH_CLOSET_COVER_RANGE 3 + +// Doors seen moving (decision 37, stealth_doors.dm) +/// A door one of the group opened: its next close this soon after is theirs too (an airlock shuts itself after 6 s) +#define STEALTH_DOOR_GUARD_MEMORY (20 SECONDS) +/// After a door sent someone to look, it only gets glances for this long +#define STEALTH_DOOR_CUE_COOLDOWN (30 SECONDS) +/// A door that sent someone to look STEALTH_DOOR_CUE_MAX times within this long is ignored for the rest of it +#define STEALTH_DOOR_CUE_MEMORY (3 MINUTES) +#define STEALTH_DOOR_CUE_MAX 2 + +// The mark over a guard's head (stealth_meter.dm, owner decision 27) +/// Pixel rows in the "?" and "!" glyphs: fill and drain steps +#define STEALTH_METER_ROWS 7 +/// Tiles from the guard within which a living player makes the mark worth drawing +#define STEALTH_METER_RANGE 10 +/// pixel_z of the glyph's bottom over a standing, medium-height guard: a clear gap over the hair +#define STEALTH_METER_HEAD_Z 36 +/// pixel_z of the glyph's bottom over a guard lying down (its sprite also drops PIXEL_Y_OFFSET_LYING) +#define STEALTH_METER_LYING_Z 29 + +/// The scav den's side +// ===== Flashlights (decision 31, stealth_light.dm) ===== +/// It keeps its light on this long after it last wanted it +#define STEALTH_LIGHT_HOLD (5 SECONDS) +/// A heavy EMP cuts a guard's seclite out for this long +#define STEALTH_LIGHT_EMP_HEAVY (40 SECONDS) +/// A light EMP cuts a guard's seclite out for this long +#define STEALTH_LIGHT_EMP_LIGHT (20 SECONDS) + +// ===== Flashlight beams (decisions 39 and 41, stealth_light.dm) ===== +/// The beam's light range in tiles, from where it starts (lit floor ends 4 tiles ahead: data/stealth/STATUS.md, decision 41) +#define STEALTH_TORCH_RANGE 5 +/// The beam's light power (its seclite blue takes it to about 1.5 white) +#define STEALTH_TORCH_POWER 1.9 +/// Degrees of the beam at full strength; tg fades it to nothing over the next 30 each side +#define STEALTH_TORCH_ANGLE 30 +/// Tiles ahead of the guard's own tile the beam starts (the hand, not the body), so its own tile stays dark +#define STEALTH_TORCH_FORWARD 0.5 +/// tg's seclite colour +#define STEALTH_TORCH_COLOR "#99ccff" +/// A turn of 90 degrees or more shows the beam halfway for this long before it lands +#define STEALTH_TORCH_TURN_STEP (0.15 SECONDS) +/// A step at a walk shows the beam half a tile back for this long +#define STEALTH_TORCH_HALF_STEP (0.2 SECONDS) +/// Suspicious or searching and standing: the beam swings a side, back, the other side, back, one move per this long +#define STEALTH_TORCH_SWEEP_STEP (0.6 SECONDS) +/// A seclite that is cut out sputters: world.time offsets it flashes on at, and how long each flash lasts +#define STEALTH_TORCH_SPUTTER_AT list(0.2 SECONDS, 0.5 SECONDS) +#define STEALTH_TORCH_SPUTTER_FLASH (0.1 SECONDS) +/// Loudness of the click when a guard switches its light +#define STEALTH_TORCH_CLICK_VOLUME 25 +/// The visible cone (decision 42) comes in this many lengths, an eighth of a tile apart; the last is an open beam +#define STEALTH_BEAM_LENGTHS 22 +/// Pixels from the guard's tile centre to its icon's centre (stealth_beam.dmi is 128x192, the guard at its bottom middle) +#define STEALTH_BEAM_PIVOT 96 +/// The longest a guard's cone waits for SSlighting to apply its lamp before it shows anyway (decision 42 sync) +#define STEALTH_BEAM_WAIT_CAP (5 SECONDS) +/// A lit light someone carries within this many tiles of an unaware guard standing in the dark draws its notice +/// even behind it (never further than the light itself reaches) +#define STEALTH_STRAY_LIGHT_RANGE 5 +/// Notice a second from such a light. It only ever fills to suspicious: the guard turns and uses its eyes. +#define STEALTH_STRAY_LIGHT_RATE 0.5 +/// Bark: someone's light is on it +#define STEALTH_BARK_LIGHT "stealth_light" +/// Bark: its own light cut out +#define STEALTH_BARK_LIGHT_DEAD "stealth_light_dead" + +// ===== Readable turns (decision 39, stealth_turns.dm) ===== +/// How long a guard leans towards the side it is about to turn to before it turns +#define STEALTH_TURN_TELL (0.6 SECONDS) +/// Pixels of that lean +#define STEALTH_TURN_LEAN 3 +/// How long the lean takes to show and to go +#define STEALTH_TURN_LEAN_TIME (0.2 SECONDS) + +#define FACTION_SCAV "scav" + +// ===== Disguises (decision 40, stealth_disguise.dm) ===== +/// The den's own doors +#define ACCESS_SCAV "scav" +/// The den boss's vault (scav_den.dm): only his pass opens it +#define ACCESS_SCAV_VAULT "scav_vault" +// What someone wears of the scavs' own +/// Their face is hidden (tg's get_face_name() finds none) +#define STEALTH_PIECE_MASK (1<<0) +/// The scav fatigues, showing, under nothing the guards don't wear +#define STEALTH_PIECE_CLOTHES (1<<1) +/// A scav pass in the ID slot +#define STEALTH_PIECE_ID (1<<2) +/// What someone wears is worked out again when it is older than this (a mask pulled down, a face wrecked) +#define STEALTH_DISGUISE_CACHE_TIME (2 SECONDS) +/// Share of the usual notice gained in the fatigues, in the fatigues and a mask, and in the whole set inside the +/// guard's near range (beyond it the whole set gains none). Scaled by the guard's skill (`disguise`). +#define STEALTH_DISGUISE_FILL_CLOTHES 0.5 +#define STEALTH_DISGUISE_FILL_MASKED 0.25 +#define STEALTH_DISGUISE_FILL_FULL 0.05 +/// Tiles within which a guard that sees them plainly stops them, for the same three. Its skill and being wary add to it. +#define STEALTH_CHALLENGE_RANGE_CLOTHES 5 +#define STEALTH_CHALLENGE_RANGE_MASKED 3 +#define STEALTH_CHALLENGE_RANGE_FULL 2 +/// It reads a pass from this close +#define STEALTH_CHALLENGE_CHECK_RANGE 2 +/// It reads a pass for this long before it lets them go +#define STEALTH_CHALLENGE_CHECK_TIME (2 SECONDS) +/// With no pass shown, it asks again after this long +#define STEALTH_CHALLENGE_WARN_TIME (3 SECONDS) +/// With no pass shown after this long, the disguise is blown +#define STEALTH_CHALLENGE_FAIL_TIME (6 SECONDS) +/// Further than this from where it stopped them is walking off +#define STEALTH_CHALLENGE_LEASH 2 +/// How long a guard that read their pass lets them be +#define STEALTH_PASS_TIME (5 MINUTES) +/// Someone it waved on is stopped again (the pass came off and went back on) within STEALTH_PASS_RECHECK_COOLDOWN of a +/// wave, or after STEALTH_PASS_RECHECK_MAX waves within STEALTH_PASS_RECHECK_MEMORY: it sees through them instead. +#define STEALTH_PASS_RECHECK_COOLDOWN (60 SECONDS) +#define STEALTH_PASS_RECHECK_MEMORY (5 MINUTES) +#define STEALTH_PASS_RECHECK_MAX 2 +/// How long a guard remembers the wearer of a disguise it saw through (a face it remembers for good) +#define STEALTH_MADE_TIME (5 MINUTES) +/// Tiles within which a guard has a word for one of its own +#define STEALTH_GREET_RANGE 4 +#define STEALTH_GREET_COOLDOWN (30 SECONDS) +/// Anything sharp with this much force is a weapon in hand, like any gun or melee weapon +#define STEALTH_WEAPON_FORCE 10 +/// One of its own goes by +#define STEALTH_BARK_GREET "stealth_greet" +/// It asks one of its own for a light +#define STEALTH_BARK_SMOKE "stealth_smoke" +/// It stops someone to see their pass +#define STEALTH_BARK_CHALLENGE "stealth_challenge" +/// The pass is good +#define STEALTH_BARK_ID_PASS "stealth_id_pass" +/// No pass yet: it asks again +#define STEALTH_BARK_ID_FAIL "stealth_id_fail" +/// It has seen through a disguise +#define STEALTH_BARK_BLOWN "stealth_blown" + +// ===== Stealth crits, the head shot and the backstab knife (step 3a, decision 45; stealth_crits.dm, stealth_knife.dm) ===== +// Roll bonuses for hyperviolence's aimed crit roll (crit_roll.dm), on a stealth guard only. They go in before wound armour, +// so armour scales them like the rest of the roll. Numbers argued in data/stealth/STATUS.md, "Step 3a". +/// Added when the guard was unaware of everyone as the blow began +#define STEALTH_CRIT_UNAWARE_BONUS 30 +/// Added when it was only suspicious +#define STEALTH_CRIT_SUSPICIOUS_BONUS 15 +/// Added on top of either when the attacker aimed at the head (head, eyes or mouth) +#define STEALTH_CRIT_HEAD_BONUS 35 +// The head shot (decision 45): a bullet aimed at the head of a guard caught off guard. Graded by what the round can do +// against what is on the head. Numbers and the gun table: data/stealth/STATUS.md, "Decision 45". +// The round's power gives burst, down or nothing; each protection step on the head moves it one down the ladder. +/// Nothing happens beyond the hit itself +#define STEALTH_HEAD_SHOT_NONE 0 +/// Stopped short of the skull: knocked out for STEALTH_HEAD_SHOT_HELMET_TIME +#define STEALTH_HEAD_SHOT_HELMET 1 +/// Through the skull: brain damage, a heavy bleed, out cold until the bleed takes him +#define STEALTH_HEAD_SHOT_DOWN 2 +/// The head bursts (hv_burst_head_apart()) +#define STEALTH_HEAD_SHOT_BURST 3 +/// Head protection (tg's armour against the round after its penetration, plus wound armour) for one step down +#define STEALTH_HEAD_SHOT_STEP_ONE 20 +/// For two steps down +#define STEALTH_HEAD_SHOT_STEP_TWO 50 +/// For three steps down: nothing beyond the hit +#define STEALTH_HEAD_SHOT_STEP_THREE 80 +/// Least power for a round through the skull (power: the round's damage, plus half a positive wound bonus, plus the caliber bonus) +#define STEALTH_HEAD_SHOT_MIN_POWER 15 +/// Power at which the head bursts +#define STEALTH_HEAD_SHOT_BURST_POWER 40 +/// Added to the power of a rifle or shotgun round (stealth_heavy_caliber()), once per shot +#define STEALTH_HEAD_SHOT_HEAVY_CALIBER 15 +/// The power of a round from a suppressed gun is multiplied by this +#define STEALTH_HEAD_SHOT_SUPPRESSED_MULT 0.75 +/// Brain damage a round through the skull deals (BRAIN_DAMAGE_SEVERE is 100, brains die at 200) +#define STEALTH_HEAD_SHOT_BRAIN_DAMAGE 120 +/// Blood flow of the wound a round through the skull leaves (tg's critical puncture is 3, a cut throat about 4) +#define STEALTH_HEAD_SHOT_FLOW 8 +/// How long a round through the skull knocks him out: longer than the bleed takes to put him under for good +#define STEALTH_HEAD_SHOT_DOWN_TIME (90 SECONDS) +/// How long a round a helmet stopped knocks him out +#define STEALTH_HEAD_SHOT_HELMET_TIME (6 SECONDS) +/// A bullet through the head +#define WOUND_SERIES_HV_HEAD_SHOT "wound_series_hv_head_shot" diff --git a/voidcrew/_DEFINES/stealth_hearing.dm b/voidcrew/_DEFINES/stealth_hearing.dm new file mode 100644 index 00000000000..f8a8cd52ed4 --- /dev/null +++ b/voidcrew/_DEFINES/stealth_hearing.dm @@ -0,0 +1,174 @@ +// Stealth guards: hearing (voidcrew/modules/stealth/stealth_noise.dm and friends). Step 2 of the stealth layer. + +// ===== Noise kinds (stealth_noise()) ===== +#define STEALTH_NOISE_GUN_QUIET "gun_quiet" +#define STEALTH_NOISE_GUN_PISTOL "gun_pistol" +#define STEALTH_NOISE_GUN_SMG "gun_smg" +#define STEALTH_NOISE_GUN_LONG "gun_long" +#define STEALTH_NOISE_IMPACT "impact" +#define STEALTH_NOISE_BLAST "blast" +#define STEALTH_NOISE_GLASS "glass" +#define STEALTH_NOISE_THROWN "thrown" +#define STEALTH_NOISE_KNOCK "knock" +#define STEALTH_NOISE_BASH "bash" +#define STEALTH_NOISE_DOOR "door" +#define STEALTH_NOISE_THUD "thud" +#define STEALTH_NOISE_VOICE "voice" +#define STEALTH_NOISE_SCREAM "scream" +#define STEALTH_NOISE_SHOUT "shout" +/// A step on broken glass or a dropped bulb (decision 37) +#define STEALTH_NOISE_CRUNCH "crunch" + +/// Every kind, for the admin verb and the tests +#define STEALTH_NOISE_KINDS list(\ + STEALTH_NOISE_GUN_QUIET,\ + STEALTH_NOISE_GUN_PISTOL,\ + STEALTH_NOISE_GUN_SMG,\ + STEALTH_NOISE_GUN_LONG,\ + STEALTH_NOISE_IMPACT,\ + STEALTH_NOISE_BLAST,\ + STEALTH_NOISE_GLASS,\ + STEALTH_NOISE_THROWN,\ + STEALTH_NOISE_KNOCK,\ + STEALTH_NOISE_BASH,\ + STEALTH_NOISE_DOOR,\ + STEALTH_NOISE_THUD,\ + STEALTH_NOISE_VOICE,\ + STEALTH_NOISE_SCREAM,\ + STEALTH_NOISE_SHOUT,\ + STEALTH_NOISE_CRUNCH,\ +) + +// ===== What a guard does about a noise ===== +/// Turns to face it and carries on +#define STEALTH_HEAR_GLANCE 1 +/// One guard goes to look, then two, then everyone +#define STEALTH_HEAR_INVESTIGATE 2 +/// The nearest few run to it and search; the rest hold, wary +#define STEALTH_HEAR_ALARM 3 +/// A friend calling: whoever hears it runs to the one shouting +#define STEALTH_HEAR_SHOUT 4 + +// Fields of a stealth_noise_profile() list +#define STEALTH_PROFILE_REACH 1 +#define STEALTH_PROFILE_LEVEL 2 +#define STEALTH_PROFILE_FLAGS 3 + +// ===== Noise flags ===== +/// Unheard through any wall or closed door +#define STEALTH_NOISE_LOS_ONLY (1<<0) +/// Walls and doors take half as much off it +#define STEALTH_NOISE_LOUD (1<<1) +/// Heard even when one of their own made it +#define STEALTH_NOISE_ALLIES_COUNT (1<<2) +/// Heard only by the group of the guard that made it +#define STEALTH_NOISE_GROUP_ONLY (1<<3) + +// ===== Radio call kinds, lowest first: a pending call is only replaced by a more urgent one ===== +#define STEALTH_CALL_REPORT 1 +#define STEALTH_CALL_MISSING 2 +#define STEALTH_CALL_ALARM 3 + +// Fields of a controller's pending_call +#define STEALTH_CALL_KIND 1 +#define STEALTH_CALL_WHERE 2 +#define STEALTH_CALL_DUE 3 +#define STEALTH_CALL_NAME 4 + +// ===== Bark kinds ===== +#define STEALTH_BARK_HEARD "stealth_heard" +#define STEALTH_BARK_HEARD_AGAIN "stealth_heard_again" +#define STEALTH_BARK_GUNFIRE "stealth_gunfire" +#define STEALTH_BARK_HOLD "stealth_hold" +#define STEALTH_BARK_HELP "stealth_help" +#define STEALTH_BARK_MISSING "stealth_missing" +#define STEALTH_BARK_RADIO_REPORT "stealth_radio_report" +#define STEALTH_BARK_RADIO_ALARM "stealth_radio_alarm" +#define STEALTH_BARK_RADIO_MISSING "stealth_radio_missing" +#define STEALTH_BARK_COPY "stealth_copy" +#define STEALTH_BARK_RADIO_DEAD "stealth_radio_dead" + +// ===== Numbers (first playtest defaults; the owner tunes them) ===== +// Reach in open air, in tiles. Each is at or under how far a player hears the same tg sound. Lowered in decision 43 +// (playtest 2: "the distance they can hear things from seems a bit absurd, like running for example"). +#define STEALTH_NOISE_RANGE_GUN_QUIET 3 +#define STEALTH_NOISE_RANGE_GUN_PISTOL 8 +#define STEALTH_NOISE_RANGE_GUN_SMG 10 +#define STEALTH_NOISE_RANGE_GUN_LONG 12 +#define STEALTH_NOISE_RANGE_IMPACT 4 +#define STEALTH_NOISE_RANGE_IMPACT_QUIET 1 +#define STEALTH_NOISE_RANGE_BLAST 14 +#define STEALTH_NOISE_RANGE_GLASS 7 +#define STEALTH_NOISE_RANGE_THROWN_SMALL 3 +#define STEALTH_NOISE_RANGE_THROWN_MEDIUM 5 +#define STEALTH_NOISE_RANGE_THROWN_HEAVY 6 +#define STEALTH_NOISE_RANGE_KNOCK 5 +#define STEALTH_NOISE_RANGE_BASH 6 +#define STEALTH_NOISE_RANGE_DOOR 3 +#define STEALTH_NOISE_RANGE_THUD 3 +#define STEALTH_NOISE_RANGE_VOICE 4 +#define STEALTH_NOISE_RANGE_SCREAM 8 +#define STEALTH_NOISE_RANGE_SHOUT 9 +/// A step on glass (tg plays it at 50: a player hears it 12 tiles off) +#define STEALTH_NOISE_RANGE_CRUNCH 4 +/// The same with TRAIT_LIGHT_STEP (tg plays it at 30: 9 tiles) +#define STEALTH_NOISE_RANGE_CRUNCH_LIGHT 2 +/// Tiles of reach a wall eats +#define STEALTH_MUFFLE_WALL 3 +/// Tiles of reach a closed solid door eats +#define STEALTH_MUFFLE_DOOR 2 +/// Gunfire and blasts go through walls better +#define STEALTH_MUFFLE_LOUD_MULT 0.5 +/// Past this many walls and doors nothing is heard +#define STEALTH_MUFFLE_MAX_BLOCKERS 3 +/// Inside this many muffled tiles a guard knows the spot +#define STEALTH_NOISE_EXACT_RANGE 6 +/// One tile of error per this many tiles past exact +#define STEALTH_NOISE_FUZZ_STEP 3 +#define STEALTH_NOISE_FUZZ_MAX 3 +/// The same kind of noise this soon and this near an earlier one is the same noise (a volley is one event, decision 31) +#define STEALTH_NOISE_COALESCE (3 SECONDS) +#define STEALTH_NOISE_COALESCE_RANGE 3 +#define STEALTH_GLANCE_TIME (3 SECONDS) +/// How long a guard told to hold faces the noise before it goes back to its round +#define STEALTH_HOLD_TIME (10 SECONDS) +/// A search moves to a newer noise at most this often +#define STEALTH_RECENTRE_COOLDOWN (4 SECONDS) +/// "The same spot" for counting lures +#define STEALTH_LURE_RADIUS 6 +#define STEALTH_LURE_MEMORY (3 MINUTES) +/// How far a sentry walks from its post toward a small noise before it looks round and goes back. A third lure +/// at one spot it holds wary at its post if the noise is farther than this. +#define STEALTH_SENTRY_INVESTIGATE_RANGE 4 +/// How long a guard that went to look has before its friends miss it +#define STEALTH_CHECKIN_TIME (30 SECONDS) +#define STEALTH_ALARM_RESPONDERS 4 +/// After two alarms in memory +#define STEALTH_ALARM_RESPONDERS_LATER 2 +#define STEALTH_ALARM_MEMORY (3 MINUTES) +/// While alert with its target in view +#define STEALTH_SHOUT_INTERVAL (10 SECONDS) +/// Hand to the earpiece, then this long before the call goes out +#define STEALTH_RADIO_CALL_TIME (3 SECONDS) +/// A call this far past due (its level slept) is never made +#define STEALTH_RADIO_CALL_STALE (5 SECONDS) +/// One alarm delivery per group per this long +#define STEALTH_RADIO_GROUP_COOLDOWN (10 SECONDS) +/// Carriers that move on a call +#define STEALTH_RADIO_RESPONDERS 4 +/// Who a carrier's answer carries to, in muffled tiles +#define STEALTH_RELAY_VOICE_RANGE 5 +#define STEALTH_RELAY_VOICE_RESPONDERS 2 +/// How far a running step on plain floor in shoes carries to a guard +#define STEALTH_FOOTSTEP_RANGE 3 +/// How far a player hears that same step (tg: volume 75, range 17 - 1 - 6) +#define STEALTH_FOOTSTEP_PLAYER_RANGE 8 +/// The furthest any step is listened for +#define STEALTH_FOOTSTEP_MAX_RANGE 5 +#define STEALTH_FOOTSTEP_CRAWL_RANGE 1 +/// Notice a heard step adds +#define STEALTH_FOOTSTEP_NOTICE 0.5 +/// How long the admin noise view keeps one event on screen +#define STEALTH_NOISE_VIEW_TIME (4 SECONDS) +/// icon_state of the empty grey "?" over a guard that heard something (stealth_meter.dmi) +#define STEALTH_METER_HEARD_STATE "q_y0" diff --git a/voidcrew/_DEFINES/stealth_hostage.dm b/voidcrew/_DEFINES/stealth_hostage.dm new file mode 100644 index 00000000000..95505d80be3 --- /dev/null +++ b/voidcrew/_DEFINES/stealth_hostage.dm @@ -0,0 +1,17 @@ +// Hostages (stealth step 5, decisions 47+). voidcrew/modules/stealth/stealth_hostage.dm. +// Balance notes for developers; none of these numbers go in player text. + +/// Guards never stand closer than this to someone holding one of their own. +#define STEALTH_HOSTAGE_HOLD_RANGE 3 +/// "Back off" sends them to at least this far. +#define STEALTH_HOSTAGE_BACK_OFF_RANGE 6 +/// How far a guard hears a demand. +#define STEALTH_HOSTAGE_DEMAND_RANGE 7 +/// Between standoff lines. +#define STEALTH_HOSTAGE_BARK_INTERVAL (6 SECONDS) + +#define STEALTH_BARK_HOSTAGE "stealth_hostage" +#define STEALTH_BARK_HOSTAGE_DROP "stealth_hostage_drop" +#define STEALTH_BARK_HOSTAGE_BACK "stealth_hostage_back" +#define STEALTH_BARK_HOSTAGE_EXECUTED "stealth_hostage_executed" +#define STEALTH_BARK_HOSTAGE_RELEASED "stealth_hostage_released" diff --git a/voidcrew/edits/datums/neck_slice_mute.dm b/voidcrew/edits/datums/neck_slice_mute.dm new file mode 100644 index 00000000000..aa5047d52f3 --- /dev/null +++ b/voidcrew/edits/datums/neck_slice_mute.dm @@ -0,0 +1,13 @@ +// A cut throat can't speak (owner decision 45, voidcrew/modules/hyperviolence/overlays_exec/knife_executions.dm). tg's neck_slice +// (code/datums/status_effects/debuffs/debuffs.dm) lasts while the throat still bleeds from a bad cut; for that long its +// owner has tg's TRAIT_MUTE, so say(), shouting and radios all fail through tg's own can_speak(). Gasps, gags, chokes and +// other emotes still show. Everyone alike: players and NPCs, however the throat was cut. + +/datum/status_effect/neck_slice/on_apply() + . = ..() + if(.) + ADD_TRAIT(owner, TRAIT_MUTE, TRAIT_STATUS_EFFECT(id)) + +/datum/status_effect/neck_slice/on_remove() + REMOVE_TRAIT(owner, TRAIT_MUTE, TRAIT_STATUS_EFFECT(id)) + return ..() diff --git a/voidcrew/edits/objects/items/shield_rear.dm b/voidcrew/edits/objects/items/shield_rear.dm new file mode 100644 index 00000000000..9bf1b7d10b4 --- /dev/null +++ b/voidcrew/edits/objects/items/shield_rear.dm @@ -0,0 +1,35 @@ +// A shield held in front of you doesn't stop a shot in the back (owner decision 45). Everyone alike: players and NPCs, +// whatever they know. tg blocks a projectile with a held shield in two places, both reached from the victim's +// bullet_act() (code/modules/mob/living/carbon/human/human_defense.dm): the energy shield's reflection +// (check_reflect() -> IsReflect()) and every shield's block (check_block() -> hit_reaction()). While a shot that comes +// from behind is being resolved, neither works. +// +// "From behind": the shot travels the way its victim faces (its angle, so a ricochet counts from where it really came +// from), the same rear arc as tg's check_behind(). Lying down doesn't count as behind here: the shield still covers. + +/mob/living/carbon/human + /// Set while a projectile that hits this human in the back is being resolved + var/vc_shot_in_back = FALSE + +/// Whether `shot` hits `victim` from behind: it travels the way the victim faces. +/proc/vc_shot_from_behind(mob/living/victim, obj/projectile/shot) + if(!istype(shot) || isnull(shot.angle)) + return FALSE + return !!(victim.dir & angle2dir(shot.angle)) + +/mob/living/carbon/human/bullet_act(obj/projectile/bullet, def_zone, piercing_hit = FALSE) + var/was_in_back = vc_shot_in_back + vc_shot_in_back = vc_shot_from_behind(src, bullet) + . = ..() + vc_shot_in_back = was_in_back + +/obj/item/shield/hit_reaction(mob/living/carbon/human/owner, atom/movable/hitby, attack_text = "the attack", final_block_chance = 0, damage = 0, attack_type = MELEE_ATTACK, damage_type = BRUTE) + if(attack_type == PROJECTILE_ATTACK && ishuman(owner) && owner.vc_shot_in_back) + return FALSE + return ..() + +/obj/item/shield/energy/IsReflect(def_zone) + var/mob/living/carbon/human/holder = loc + if(ishuman(holder) && holder.vc_shot_in_back) + return FALSE + return ..() diff --git a/voidcrew/icons/effects/scav_camera_cone.dmi b/voidcrew/icons/effects/scav_camera_cone.dmi new file mode 100644 index 00000000000..fad0ef6497f Binary files /dev/null and b/voidcrew/icons/effects/scav_camera_cone.dmi differ diff --git a/voidcrew/icons/effects/stealth_beam.dmi b/voidcrew/icons/effects/stealth_beam.dmi new file mode 100644 index 00000000000..c04a750d959 Binary files /dev/null and b/voidcrew/icons/effects/stealth_beam.dmi differ diff --git a/voidcrew/icons/effects/stealth_meter.dmi b/voidcrew/icons/effects/stealth_meter.dmi new file mode 100644 index 00000000000..d22aa60e03b Binary files /dev/null and b/voidcrew/icons/effects/stealth_meter.dmi differ diff --git a/voidcrew/modules/human_npcs/human_npc_ai.dm b/voidcrew/modules/human_npcs/human_npc_ai.dm index 4d6675b26b8..92c0821d9be 100644 --- a/voidcrew/modules/human_npcs/human_npc_ai.dm +++ b/voidcrew/modules/human_npcs/human_npc_ai.dm @@ -515,7 +515,7 @@ /proc/human_npc_ally_in_line(mob/living/shooter, atom/target) var/turf/shooter_turf = get_turf(shooter) var/turf/target_turf = get_turf(target) - for(var/turf/line_turf as anything in get_line(shooter_turf, target_turf)) + for(var/turf/line_turf as anything in human_npc_shot_path(shooter_turf, target_turf)) if(line_turf == shooter_turf || line_turf == target_turf) continue for(var/mob/living/other in line_turf) @@ -525,6 +525,42 @@ return TRUE return FALSE +/** + * Every turf a shot from the centre of `start_turf` to the centre of `end_turf` passes through, in order. A bullet + * flies the straight line, so at an angle it clips turfs that get_line()'s one-turf-per-step line skips + * (someone beside the target, a tile off that line). Where the line runs exactly through a corner both + * turfs beside it count. + */ +/proc/human_npc_shot_path(turf/start_turf, turf/end_turf) + . = list(start_turf) + if(isnull(start_turf) || isnull(end_turf) || start_turf.z != end_turf.z) + return + var/x_sign = SIGN(end_turf.x - start_turf.x) + var/y_sign = SIGN(end_turf.y - start_turf.y) + var/x_count = abs(end_turf.x - start_turf.x) + var/y_count = abs(end_turf.y - start_turf.y) + var/x = start_turf.x + var/y = start_turf.y + var/x_done = 0 + var/y_done = 0 + while(x_done < x_count || y_done < y_count) + // Which grid line the shot crosses next: a vertical one (< 0), a horizontal one (> 0) or both at a corner. + var/decision = (1 + 2 * x_done) * y_count - (1 + 2 * y_done) * x_count + if(decision == 0) + . += locate(x + x_sign, y, start_turf.z) + . += locate(x, y + y_sign, start_turf.z) + x += x_sign + y += y_sign + x_done++ + y_done++ + else if(decision < 0) + x += x_sign + x_done++ + else + y += y_sign + y_done++ + . += locate(x, y, start_turf.z) + /// One step sideways, keeping no further from the target, for a clear shot. /proc/human_npc_sidestep(mob/living/shooter, atom/target) var/turf/our_turf = get_turf(shooter) diff --git a/voidcrew/modules/human_npcs/human_npc_spawning.dm b/voidcrew/modules/human_npcs/human_npc_spawning.dm index c5f583c9d6b..6a123285c4d 100644 --- a/voidcrew/modules/human_npcs/human_npc_spawning.dm +++ b/voidcrew/modules/human_npcs/human_npc_spawning.dm @@ -288,6 +288,10 @@ SUBSYSTEM_DEF(human_npcs) /// family's own root subtype sets this to itself (tests make one of every type). var/abstract_spawner_type = /obj/effect/spawner/human_npc +/// Called with the NPC once it is built, or null. Must not hold a ref to the spawner: it is gone by then. +/obj/effect/spawner/human_npc/proc/npc_spawned_callback() + return null + /obj/effect/spawner/human_npc/Initialize(mapload) . = ..() if(!ispath(npc_type, /mob/living/carbon/human/npc)) @@ -300,4 +304,4 @@ SUBSYSTEM_DEF(human_npcs) return #endif // The mapped spawner's dir is the way the NPC faces. - spawn_human_npc(npc_type, get_turf(src), name = npc_name, faction = npc_faction, context = get_npc_spawn_context(), dir = dir) + spawn_human_npc(npc_type, get_turf(src), npc_spawned_callback(), name = npc_name, faction = npc_faction, context = get_npc_spawn_context(), dir = dir) diff --git a/voidcrew/modules/hyperviolence/crits/crit_roll.dm b/voidcrew/modules/hyperviolence/crits/crit_roll.dm index 568a95244fd..a656fbcdd59 100644 --- a/voidcrew/modules/hyperviolence/crits/crit_roll.dm +++ b/voidcrew/modules/hyperviolence/crits/crit_roll.dm @@ -18,7 +18,8 @@ // * The roll is tg's own wound roll: rand(1, min(damage, 25) ^ 1.4), so 1 to 90. On top of the // weapon's wound_bonus we add up to +30 for how battered the limb already is (its damage over // its max damage) and +25 if the victim is helpless (lying down, in crit, stunned, cuffed or -// held in an aggressive grab), +15 more if the attacker is the one holding them. Then tg's +// held in an aggressive grab), +15 more if the attacker is the one holding them, plus any +// situation bonus (hv_crit_situation_bonus(): stealth guards caught unaware). Then tg's // check_woundings_mods() adds the limb's existing wound penalties and scales everything by // wound armour (worn WOUND ratings plus the limb's own resistance: head 5%, chest 10%). // * Each crit has a threshold and a minimum damage after armour (crit_types.dm). A fresh, @@ -253,9 +254,14 @@ GLOBAL_LIST_INIT(hv_crits, hv_crit_init_list()) for(var/source in hv_crit_attacker_bonuses) . = max(., hv_crit_attacker_bonuses[source]) -/// The crit roll for this limb. tg's wound roll plus the battered and helpless bonuses, run +/// Roll bonus from how the blow was struck, on top of the helpless bonus: 0 here. The stealth layer adds one for a guard +/// caught unaware or stabbed in the back (voidcrew/modules/stealth/stealth_crits.dm). `source` is the weapon or projectile. +/mob/living/proc/hv_crit_situation_bonus(mob/living/attacker, atom/source, obj/item/bodypart/limb) + return 0 + +/// The crit roll for this limb. tg's wound roll plus the battered, helpless and situation bonuses, run /// through check_woundings_mods() so wound armour and existing wounds count as they do for tg. -/obj/item/bodypart/proc/hv_crit_roll(wounding_type, damage, wound_bonus, exposed_wound_bonus, mob/living/attacker) +/obj/item/bodypart/proc/hv_crit_roll(wounding_type, damage, wound_bonus, exposed_wound_bonus, mob/living/attacker, atom/source) var/easily_wounded = HAS_TRAIT(owner, TRAIT_EASILY_WOUNDED) var/hardly_wounded = HAS_TRAIT(owner, TRAIT_HARDLY_WOUNDED) if(easily_wounded && !hardly_wounded) @@ -265,7 +271,7 @@ GLOBAL_LIST_INIT(hv_crits, hv_crit_init_list()) if(hardly_wounded && !easily_wounded) damage *= 0.85 var/base_roll = rand(1, max(1, round(damage ** WOUND_DAMAGE_EXPONENT))) - var/bonus = wound_bonus + round(HV_CRIT_BATTERED_BONUS * get_damage() / max(max_damage, 1)) + owner.hv_crit_helpless_bonus(attacker) + var/bonus = wound_bonus + round(HV_CRIT_BATTERED_BONUS * get_damage() / max(max_damage, 1)) + owner.hv_crit_helpless_bonus(attacker) + owner.hv_crit_situation_bonus(attacker, source, src) bonus += attacker?.hv_crit_attacker_bonus(owner) || 0 return check_woundings_mods(wounding_type, base_roll, damage, bonus, exposed_wound_bonus, FALSE) @@ -336,7 +342,7 @@ GLOBAL_LIST_INIT(hv_crits, hv_crit_init_list()) if(damage < crit.min_damage) continue if(isnull(roll)) - roll = isnull(forced_roll) ? limb.hv_crit_roll(wounding_type, damage, wound_bonus, exposed_wound_bonus, attacker) : forced_roll + roll = isnull(forced_roll) ? limb.hv_crit_roll(wounding_type, damage, wound_bonus, exposed_wound_bonus, attacker, source) : forced_roll if(roll < crit.threshold) continue if(!crit.apply_carbon(src, limb, damage, attack_direction, source, attacker)) diff --git a/voidcrew/modules/hyperviolence/overlays_exec/executions.dm b/voidcrew/modules/hyperviolence/overlays_exec/executions.dm index 3779c8aaadc..4eab1e33017 100644 --- a/voidcrew/modules/hyperviolence/overlays_exec/executions.dm +++ b/voidcrew/modules/hyperviolence/overlays_exec/executions.dm @@ -26,6 +26,8 @@ /obj/item/gun /// While an execution round is being fired: the damage it has dealt to the victim's head var/hv_execution_head_damage = 0 + /// Counts clicks that went to an execution, so try_fire_gun() can tell its own click took that path + var/hv_execution_claims = 0 /// TRUE while an execution round is being fired: the barrel is on the head, so the shot's flash is drawn there /// (visuals/execution_motion.dm) and not at the hip var/hv_firing_execution = FALSE @@ -33,8 +35,20 @@ /obj/item/gun/handle_suicide(mob/living/carbon/human/user, mob/living/carbon/human/target, params, bypass_timer) if(bypass_timer || !hv_execution_possible(user, target)) return ..() + hv_execution_claims++ hv_start_execution(user, target, params) +/** + * tg's fire_gun() returns nothing after the mouth path and after the marked head execution hook, so its click carries + * on down tg's attack chain and the gun also clubs the target (a pistol-whip on top of the execution). A click that + * went to an execution, whether the barrel was held or the wind-up was refused or broken, ends here instead. + */ +/obj/item/gun/try_fire_gun(atom/target, mob/living/user, params) + var/claims_before = hv_execution_claims + . = ..() + if(hv_execution_claims != claims_before) + return TRUE + /// Called by tg's fire_gun() for a point-blank shot, after its own checks (safeties, firing pins, the /// mouth). A head-aimed one at someone who can be executed starts the execution instead of firing. /// Returns TRUE if it did. @@ -43,6 +57,7 @@ return FALSE if(!hv_execution_possible(user, target)) return FALSE + hv_execution_claims++ hv_start_execution(user, target, params) return TRUE diff --git a/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arm_l.dmi b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arm_l.dmi new file mode 100644 index 00000000000..fb534204f28 Binary files /dev/null and b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arm_l.dmi differ diff --git a/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arm_r.dmi b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arm_r.dmi new file mode 100644 index 00000000000..6d99a2d1c26 Binary files /dev/null and b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arm_r.dmi differ diff --git a/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arms.dmi b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arms.dmi new file mode 100644 index 00000000000..528d0c0c2f8 Binary files /dev/null and b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arms.dmi differ diff --git a/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_far_e.dmi b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_far_e.dmi new file mode 100644 index 00000000000..94bf360b9fc Binary files /dev/null and b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_far_e.dmi differ diff --git a/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_far_w.dmi b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_far_w.dmi new file mode 100644 index 00000000000..94d12a461f5 Binary files /dev/null and b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_far_w.dmi differ diff --git a/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_px.dmi b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_px.dmi new file mode 100644 index 00000000000..c254f818706 Binary files /dev/null and b/voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_px.dmi differ diff --git a/voidcrew/modules/hyperviolence/overlays_exec/knife_executions.dm b/voidcrew/modules/hyperviolence/overlays_exec/knife_executions.dm new file mode 100644 index 00000000000..5aa3164dddc --- /dev/null +++ b/voidcrew/modules/hyperviolence/overlays_exec/knife_executions.dm @@ -0,0 +1,207 @@ +// Hyperviolence: knife executions, the one backstab path (decisions 45 and 46). +// +// A combat-mode click with any sharp-edged knife on an adjacent carbon with a head starts it when: +// - the target is a stealth guard caught off guard (stealth_caught_off_guard()) and the attacker is behind it +// (check_behind()), whatever zone is aimed at (decision 45); +// - or anyone else is taken from behind, or anyone is helpless (hv_can_be_executed()), with the head or mouth aimed at. +// Never on a body the attacker holds in an aggressive grab or tighter (that is tg's own slow throat slit), never on a +// throat already cut. Only players and boss-rank human NPCs do it (hv_can_execute()), never pacifists. +// +// A stealth guard caught off guard from behind is cut on the click (hv_knife_execution_instant()). Anyone else: both +// hold still for HV_KNIFE_EXECUTION_WINDUP; moving, losing the blade or turning to face the attacker breaks the +// wind-up cleanly. If it holds, the cut is decision 45's: tg's throat slit maths (hv_finish_knife_execution()). The +// throat blood follows the wound that landed (hv_knife_exec_spray). Nothing extra kills, stuns or roots the victim; +// death comes only from tg's real damage and bleeding. A cut throat is mute (voidcrew/edits/datums/neck_slice_mute.dm). + +/obj/item/knife + /// Brute and burn damage this knife dealt to the victim's head during an execution stab. + var/hv_knife_execution_head_damage = 0 + /// How far the last execution's throat blood sprays (0-2 tiles), by the worst cut it left on the head. + var/hv_knife_exec_spray = 0 + +/obj/item/knife/attack(mob/living/target_mob, mob/living/user, list/modifiers, list/attack_modifiers) + if(!hv_knife_execution_possible(user, target_mob)) + return ..() + if(!DOING_INTERACTION(user, HV_KNIFE_EXECUTION_DOAFTER)) + var/list/saved_modifiers = islist(modifiers) ? modifiers.Copy() : null + var/list/saved_attack_modifiers = islist(attack_modifiers) ? attack_modifiers.Copy() : null + INVOKE_ASYNC(src, PROC_REF(hv_start_knife_execution), user, target_mob, saved_modifiers, saved_attack_modifiers) + return TRUE + +/// Whether a melee click with this knife by `user` on `target` starts a knife execution (the one backstab path). +/obj/item/knife/proc/hv_knife_execution_possible(mob/living/user, mob/living/target) + if(!isliving(user) || !iscarbon(target) || user == target) + return FALSE + if(!user.combat_mode || HAS_TRAIT(user, TRAIT_PACIFISM) || !user.hv_can_execute()) + return FALSE + if(force <= 0 || !(get_sharpness() & SHARP_EDGED)) + return FALSE + var/mob/living/carbon/victim = target + if(isnull(victim.get_bodypart(BODY_ZONE_HEAD)) || !user.Adjacent(victim)) + return FALSE + // Held in an aggressive grab or tighter: tg's own slow throat slit (butchering.dm), not this. + if(user.pulling == victim && user.grab_state >= GRAB_AGGRESSIVE) + return FALSE + if(victim.has_status_effect(/datum/status_effect/neck_slice)) + return FALSE + var/behind = check_behind(user, victim) + // A stealth guard caught off guard from behind: the throat whatever is aimed at (decision 45). On guard, only helpless. + if(hv_knife_is_stealth_guard(victim)) + var/mob/living/carbon/human/npc/guard = victim + if(behind && guard.stealth_caught_off_guard(user)) + return TRUE + return hv_knife_aims_at_throat(user) && victim.hv_can_be_executed() + if(!hv_knife_aims_at_throat(user)) + return FALSE + return behind || victim.hv_can_be_executed() + +/// Whether `user` aims at the head or the mouth. +/obj/item/knife/proc/hv_knife_aims_at_throat(mob/living/user) + return user.zone_selected == BODY_ZONE_HEAD || user.zone_selected == BODY_ZONE_PRECISE_MOUTH + +/// Whether `victim` is a stealth guard (its awareness decides a backstab, decision 45). +/obj/item/knife/proc/hv_knife_is_stealth_guard(mob/living/victim) + var/mob/living/carbon/human/npc/guard = victim + return istype(guard) && istype(guard.ai_controller, /datum/ai_controller/basic_controller/human_npc/stealth) + +/** + * Whether this execution lands on the click with no hold: a stealth guard caught off guard from behind (decision 45, + * amended). A patrolling guard walks most of the time and tg's do_after breaks on his first step, so a 1.5 s hold + * could only land on a guard standing at a stop. Players, other NPCs and helpless targets keep the hold. + */ +/obj/item/knife/proc/hv_knife_execution_instant(mob/living/user, mob/living/carbon/victim) + if(!hv_knife_is_stealth_guard(victim) || !check_behind(user, victim)) + return FALSE + // tg's check_behind() counts anyone lying down as "behind"; a helpless guard keeps the hold. + if(victim.hv_can_be_executed()) + return FALSE + var/mob/living/carbon/human/npc/guard = victim + return guard.stealth_caught_off_guard(user) + +/// Grabs the victim, presses the blade to their throat and, if both hold still, cuts. An unaware guard is cut at once. +/obj/item/knife/proc/hv_start_knife_execution(mob/living/user, mob/living/carbon/victim, list/modifiers, list/attack_modifiers) + if(DOING_INTERACTION(user, HV_KNIFE_EXECUTION_DOAFTER) || !hv_knife_execution_possible(user, victim)) + return FALSE + // The outcome lands now; the motion's grab and cut play over it as decoration (knife_execution_motion.dm). + if(hv_knife_execution_instant(user, victim)) + return hv_finish_knife_execution(user, victim, modifiers, attack_modifiers) + var/from_behind = check_behind(user, victim) + var/unseen = from_behind || victim.is_blind() || !(user in viewers(7, victim)) + if(from_behind) + user.visible_message( + span_danger("[user] grabs [victim] from behind and presses [src] to [victim.p_their()] throat."), + span_danger("You grab [victim] from behind and press [src] to [victim.p_their()] throat."), + ignored_mobs = victim, + ) + to_chat(victim, span_userdanger((unseen ? "Someone grabs you from behind and presses a blade to your throat!" : "[user] grabs you from behind and presses [src] to your throat!"))) + else + user.visible_message( + span_danger("[user] grabs [victim]'s head and presses [src] to [victim.p_their()] throat."), + span_danger("You grab [victim]'s head and press [src] to [victim.p_their()] throat."), + ignored_mobs = victim, + ) + to_chat(victim, span_userdanger((unseen ? "Someone grabs your head and presses a blade to your throat!" : "[user] grabs your head and presses [src] to your throat!"))) + var/held = do_after( + user, + HV_KNIFE_EXECUTION_WINDUP, + victim, + extra_checks = CALLBACK(src, PROC_REF(hv_knife_execution_holds), user, victim), + interaction_key = HV_KNIFE_EXECUTION_DOAFTER, + hidden = TRUE, // no cog over his head: the grab itself is what people see + ) + if(!held || QDELETED(src) || QDELETED(user) || QDELETED(victim)) + return FALSE + return hv_finish_knife_execution(user, victim, modifiers, attack_modifiers) + +/// do_after check: the attacker still holds a sharp knife to an adjacent victim who hasn't turned to face them. +/obj/item/knife/proc/hv_knife_execution_holds(mob/living/user, mob/living/carbon/victim) + if(!user.is_holding(src) || !user.combat_mode || HAS_TRAIT(user, TRAIT_PACIFISM)) + return FALSE + if(force <= 0 || !(get_sharpness() & SHARP_EDGED)) + return FALSE + if(isnull(victim.get_bodypart(BODY_ZONE_HEAD)) || !user.Adjacent(victim)) + return FALSE + if(user.pulling == victim && user.grab_state >= GRAB_AGGRESSIVE) + return FALSE + // A stealth guard taken from behind goes for the throat whatever is aimed at; anyone else needs the head or mouth. + if(!hv_knife_is_stealth_guard(victim) && !hv_knife_aims_at_throat(user)) + return FALSE + return victim.hv_can_be_executed() || check_behind(user, victim) + +/** + * Lands the knife execution: tg's throat slit (butchering.dm, startNeckSlice()) from its do_after on, as decision 45 built + * it. The knife's force goes to the head through its melee armour; if tg's wound maths lets a critical cut through what + * protects the head (slit_gets_through()), a critical slash and tg's neck_slice (mute, neck_slice_mute.dm). Otherwise + * the blade turns: an ordinary stab to the head with tg's own wound roll, and he can still shout. + */ +/obj/item/knife/proc/hv_finish_knife_execution(mob/living/user, mob/living/carbon/victim, list/modifiers, list/attack_modifiers) + if(!hv_knife_execution_holds(user, victim)) + return FALSE + var/obj/item/bodypart/head/head = victim.get_bodypart(BODY_ZONE_HEAD) + if(isnull(head)) + return FALSE + hv_knife_exec_spray = 0 + hv_knife_execution_head_damage = 0 + RegisterSignal(victim, COMSIG_MOB_APPLY_DAMAGE, PROC_REF(hv_knife_execution_hit)) + user.do_attack_animation(victim) + user.changeNext_move(CLICK_CD_MELEE) + playsound(victim, 'sound/effects/butcher.ogg', 50, TRUE, -1) + var/blocked = victim.run_armor_check(head, MELEE, armour_penetration = armour_penetration, silent = TRUE) + var/slit = slit_gets_through(victim, head) + if(slit) + log_combat(user, victim, "wounded via throat slitting", src, "(knife execution)") + victim.apply_damage(force, BRUTE, head, blocked, wound_bonus = CANT_WOUND, attack_direction = get_dir(user, victim), attacking_item = src) + if(victim.cause_wound_of_type_and_severity(WOUND_SLASH, head, WOUND_SEVERITY_CRITICAL, wound_source = src)) + victim.apply_status_effect(/datum/status_effect/neck_slice) + else + log_combat(user, victim, "stabbed at the throat of", src, "(knife execution, protected throat)") + victim.apply_damage(force, BRUTE, head, blocked, wound_bonus = wound_bonus, exposed_wound_bonus = exposed_wound_bonus, sharpness = get_sharpness(), attack_direction = get_dir(user, victim), attacking_item = src) + if(!QDELETED(victim)) + UnregisterSignal(victim, COMSIG_MOB_APPLY_DAMAGE) + head = victim.get_bodypart(BODY_ZONE_HEAD) + // The blood follows the wound that landed: a cut throat sprays, a lesser cut runs, no wound no spray. + var/worst = 0 + for(var/datum/wound/cut as anything in head?.wounds) + if((istype(cut, /datum/wound/slash) || istype(cut, /datum/wound/pierce)) && cut.severity > worst) + worst = cut.severity + if(worst >= WOUND_SEVERITY_CRITICAL) + hv_knife_exec_spray = 2 + else if(worst >= WOUND_SEVERITY_MODERATE) + hv_knife_exec_spray = 1 + if(victim.has_status_effect(/datum/status_effect/neck_slice)) + victim.hv_add_hit_line("[user] cuts [victim]'s throat!", HV_LINE_HUGE, "[user] cuts your throat!", COMBAT_MESSAGE_RANGE) + else + victim.hv_add_hit_line("[user] stabs at [victim]'s throat, but the blade turns!", HV_LINE_BOLD, "[user] stabs at your throat!", COMBAT_MESSAGE_RANGE) + // The victim felt that: the same signal a normal blow sends (tg's relay_attackers), after the cut. + SEND_SIGNAL(victim, COMSIG_ATOM_AFTER_ATTACKEDBY, src, user, modifiers, attack_modifiers) + hv_execution_witnesses(user, victim) + add_fingerprint(user) + log_combat(user, victim, "knife-executed", src, "([round(hv_knife_execution_head_damage, 0.1)] damage to the head, throat [slit ? "cut" : "protected"])") + return TRUE + +/** + * Whether the slit gets through what protects this throat, by tg's own wound maths (decision 45): a placed cut is the + * best roll tg's wound roll allows (WOUND_MAX_CONSIDERED_DAMAGE to the power WOUND_DAMAGE_EXPONENT), plus this knife's + * wound bonus, through check_woundings_mods() (worn wound armour on the head, physiology wound armour such as dermal + * cyberware, the head's own resistance and its existing wounds). It gets through if that reaches tg's critical slash + * threshold. + */ +/obj/item/knife/proc/slit_gets_through(mob/living/carbon/victim, obj/item/bodypart/throat) + var/datum/wound_pregen_data/critical = GLOB.all_wound_pregen_data[/datum/wound/slash/flesh/critical] + var/best_roll = round(WOUND_MAX_CONSIDERED_DAMAGE ** WOUND_DAMAGE_EXPONENT) + var/roll = throat.check_woundings_mods(WOUND_SLASH, best_roll, force, wound_bonus, exposed_wound_bonus, FALSE) + return roll >= critical.threshold_minimum + +/// Sums brute and burn damage this knife deals to the victim's head during an execution stab. +/obj/item/knife/proc/hv_knife_execution_hit(mob/living/source, damage, damagetype, def_zone, blocked, wound_bonus, exposed_wound_bonus, sharpness, attack_direction, atom/attacking_item) + SIGNAL_HANDLER + if(attacking_item != src || (damagetype != BRUTE && damagetype != BURN)) + return + var/zone + if(isbodypart(def_zone)) + var/obj/item/bodypart/limb = def_zone + zone = limb.body_zone + else + zone = check_zone(def_zone) + if(zone == BODY_ZONE_HEAD) + hv_knife_execution_head_damage += damage diff --git a/voidcrew/modules/hyperviolence/visuals/_defines.dm b/voidcrew/modules/hyperviolence/visuals/_defines.dm index 77c2a4a88be..6c3614ddf5b 100644 --- a/voidcrew/modules/hyperviolence/visuals/_defines.dm +++ b/voidcrew/modules/hyperviolence/visuals/_defines.dm @@ -154,5 +154,67 @@ #define HV_VIS_KILL_SHAKE_TIME 4 #define HV_VIS_KILL_SHAKE_STRENGTH 0.12 #define HV_VIS_KILL_SHAKE_RANGE 7 + +// ---- Knife executions ---- +// The attacker's step-in is a deliberate exception to _motion_core.dm's third-of-a-tile rule: an arm is +// about 7 px long, so he has to stand chest to back before his hands reach a throat. The step is in the +// transform, which never changes the SIDE_MAP sort row, so who is drawn over whom stays as it was. + +/// The one-pixel icon every arm piece is built from. +#define HV_VIS_KNIFE_PX 'voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_px.dmi' +/// Deciseconds: the attacker's step in, and how long his hands take to reach the victim after their start. +#define HV_VIS_KNIFE_STEP_TIME 2.5 +#define HV_VIS_KNIFE_REACH_START 0.5 +#define HV_VIS_KNIFE_REACH_TIME 2.5 +/// Deciseconds: when the grab hauls the victim back, and for how long. +#define HV_VIS_KNIFE_PULL_START 2.5 +#define HV_VIS_KNIFE_PULL_TIME 1 +/// Deciseconds: when the victim's own hand comes up to fight the knife hand, and for how long. +#define HV_VIS_KNIFE_GUARD_START 3.5 +#define HV_VIS_KNIFE_GUARD_TIME 1.5 +/// Deciseconds after the cut: the blade's draw across the throat, then the moment it is held. +#define HV_VIS_KNIFE_CUT_TIME 2.5 +#define HV_VIS_KNIFE_CUT_HOLD 1 +/// Deciseconds: the attacker's hands coming off and his step back to his own tile's centre. +#define HV_VIS_KNIFE_RELEASE_TIME 3 +/// Deciseconds: the victim's way back to his own tile's centre once he is let go. +#define HV_VIS_KNIFE_VICTIM_BACK_TIME 2 +/// Deciseconds: a survivor's hand going to his throat, how long he stays bent over it, and straightening up. +#define HV_VIS_KNIFE_CLUTCH_IN 1.5 +#define HV_VIS_KNIFE_HUNCH_END 8.5 +#define HV_VIS_KNIFE_HUNCH_OUT 3 +/// Deciseconds after the cut: a survivor's hand leaves his throat, and how long it takes to drop. +#define HV_VIS_KNIFE_CLUTCH_END 20 +#define HV_VIS_KNIFE_CLUTCH_OUT 3 +/// Deciseconds a broken wind-up takes to put everything back. +#define HV_VIS_KNIFE_ABORT_TIME 2 +/// Pixels the attacker steps in and the victim is hauled back, by the way the victim faces. +#define HV_VIS_KNIFE_STEP_SOUTH 14 +#define HV_VIS_KNIFE_PULL_SOUTH 8 +#define HV_VIS_KNIFE_STEP_NORTH 18 +#define HV_VIS_KNIFE_PULL_NORTH 8 +#define HV_VIS_KNIFE_STEP_SIDE 14 +#define HV_VIS_KNIFE_PULL_SIDE 5 +/// Degrees, side views: the attacker leans in, the victim is bent back, a survivor hunches forward. +#define HV_VIS_KNIFE_LEAN_ATTACKER 6 +#define HV_VIS_KNIFE_LEAN_VICTIM 8 +#define HV_VIS_KNIFE_HUNCH_TILT 9 +/// Pixels: upper arm, and elbow to the middle of the fist, as the sprites draw a hanging arm. +#define HV_VIS_KNIFE_UPPER_ARM 3.5 +#define HV_VIS_KNIFE_FOREARM 3 +/// The most an arm is drawn longer than that. +#define HV_VIS_KNIFE_ARM_STRETCH 1.3 +/// Pixels the attacker leans toward a victim he can't hold from behind (lying, or from a corner). +#define HV_VIS_KNIFE_PRESS 6 +/// Layers: pieces in front of a body, pieces behind one, and the blade over the hand that holds it. +#define HV_VIS_KNIFE_OVER_LAYER 4.05 +#define HV_VIS_KNIFE_UNDER_LAYER 3.95 +#define HV_VIS_KNIFE_BLADE_OFFSET 0.01 +/// The victim's own stand-in arm: over him, under the attacker's hands. +#define HV_VIS_KNIFE_VICTIM_ARM_LAYER 4.02 +/// Side views: the attacker is drawn a hair under the victim he holds, his far arm a hair under himself. +#define HV_VIS_KNIFE_ATTACKER_LAYER 3.99 +#define HV_VIS_KNIFE_FAR_LAYER 3.985 +#define HV_VIS_KNIFE_FAR_BLADE_LAYER 3.987 /// How long each jolt of a mauled body's shudder lasts. #define HV_VIS_SHUDDER_BEAT (0.02 SECONDS) diff --git a/voidcrew/modules/hyperviolence/visuals/knife_execution_motion.dm b/voidcrew/modules/hyperviolence/visuals/knife_execution_motion.dm new file mode 100644 index 00000000000..b2fd5f82aab --- /dev/null +++ b/voidcrew/modules/hyperviolence/visuals/knife_execution_motion.dm @@ -0,0 +1,1320 @@ +// Hyperviolence visuals: knife executions (overlays_exec/knife_executions.dm). Purely visual: nothing here +// changes what a body can do, and every body ends drawn exactly where it stands. +// +// From directly behind a standing victim (/datum/hv_knife_exec_vis): +// 1. Grab (0 - 0.35 s): the attacker steps in until he stands chest to back, his arms coming up as he closes. His +// free hand takes the victim's shoulder and hauls him back; the knife hand goes to the throat. The victim's own +// hand comes up at the knife hand. +// 2. Hold (to 1.5 s, the game's own wind-up): the victim jerks against the hold, the attacker's hands stay on him. +// 3. Cut (0.25 s, held 0.1 s): the blade draws across the throat and blood goes forward, the way the victim faces. +// 4. Let go (0.3 s): the attacker's hands come off and he steps back to the middle of his own tile. A victim still +// on his feet stumbles forward to the middle of his, bent over, his hand at his throat. Falling is tg's business: +// a victim the cut drops is drawn held up until the blade is through, then falls tg's own way. +// A broken wind-up puts everything back in 0.2 s, no blood. +// +// The attacker's arms are stand-ins: his own arm, sleeve and glove, read a pixel at a time from his own picture and +// drawn as upper arm, forearm and hand between his shoulder and wherever the hand is. The real arm is masked off (or, +// side on, covered with his own chest) while they show, and his held knife is drawn in the stand-in hand, turned to +// lie on the throat. Bodies and arms are tweened through the same moments with straight-line steps, so a hand stays +// on the spot it holds in every frame. +// +// The bodies are moved in their transform by the plain animation sequence (as hv_vis_play_over() does), not a named +// one: the move is played in two parts, the wind-up and then the cut, and a named sequence started while one of the +// same name still runs is sometimes added to it in the client instead of replacing it (seen in recordings: both +// bodies thrown twice as far at the cut). Every part ends on the body's real transform. Named sequences of other +// animations (a flinch, tg's offsets) keep running on top; tg's own turn when a body lies down takes the plain +// sequence over, which is when this one is over anyway. +// +// Draw order (SIDE_MAP sorts by tile row, then layer): from the north the attacker is on the row behind the victim, so +// pieces behind the victim go on the attacker's tile and pieces in front on the victim's. From the south it is the +// other way round and the knife hand goes under the victim: the cut is out of sight behind his head. Side on, both +// stand on one row; the attacker is put a hair under the victim and his far arm a hair under himself. +// +// A victim who is lying down, or an attacker at a back corner, gets the plain version: the attacker leans in, cuts +// and straightens up. + +/mob/living + /// Suppresses tg's attack lunge and floating item picture during the execution's own head stab. + var/hv_vis_knife_executing = FALSE + +/obj/item/knife + /// The pictures of the execution this knife is doing from behind, while they run. + var/datum/hv_knife_exec_vis/hv_vis_exec + /// Weakref to the mob whose held picture of this knife is hidden while a stand-in hand holds it. + var/datum/weakref/hv_vis_holder_ref + /// TRUE while the stand-in hand holds the knife, so build_worn_icon() draws no second one. + var/hv_vis_hide_inhand = FALSE + /// Whether the current execution completed its cut, so hv_start_knife_execution() skips the broken clean-up. + var/hv_vis_cut_landed = FALSE + /// world.time before which a new wind-up gets the plain version: reading two bodies' pictures for the stand-in + /// arms is not free, and a wind-up can be started and broken as fast as its holder can click. + var/hv_vis_hold_after = 0 + /// TRUE while its holder leans in for the plain version (no hold from behind). + var/hv_vis_pressing = FALSE + +/obj/item/knife/Destroy() + hv_vis_drop_exec() + return ..() + +/obj/item/knife/dropped(mob/user, silent = FALSE) + if(hv_vis_exec || hv_vis_hide_inhand) + hv_vis_drop_exec() + return ..() + +/obj/item/knife/equipped(mob/user, slot, initial = FALSE) + if(hv_vis_exec || hv_vis_hide_inhand) + hv_vis_drop_exec() + return ..() + +/obj/item/knife/build_worn_icon( + default_layer = 0, + default_icon_file = null, + isinhands = FALSE, + female_uniform = NO_FEMALE_UNIFORM, + override_state = null, + override_file = null, +) + if(isinhands && hv_vis_hide_inhand) + var/layer2use = alternate_worn_layer || default_layer + return mutable_appearance(layer = -layer2use) + return ..() + +/// Ends the attacker's side of a running execution at once and gives the knife its held picture back. +/obj/item/knife/proc/hv_vis_drop_exec() + if(hv_vis_exec && !QDELETED(hv_vis_exec)) + hv_vis_exec.end_attacker(at_once = TRUE) + hv_vis_restore_held_sprite() + +/// Hides this knife's held picture on `holder` while a stand-in hand holds it. +/obj/item/knife/proc/hv_vis_hide_held_sprite(mob/living/holder) + if(QDELETED(holder)) + return + var/mob/living/prev_holder = hv_vis_holder_ref?.resolve() + if(prev_holder && prev_holder != holder) + UnregisterSignal(prev_holder, COMSIG_QDELETING) + hv_vis_hide_inhand = TRUE + hv_vis_holder_ref = WEAKREF(holder) + RegisterSignal(holder, COMSIG_QDELETING, PROC_REF(hv_on_holder_qdeleting), override = TRUE) + holder.update_held_items() + +/// Puts this knife's held picture back. +/obj/item/knife/proc/hv_vis_restore_held_sprite() + var/was_hidden = hv_vis_hide_inhand + hv_vis_hide_inhand = FALSE + var/mob/living/holder = hv_vis_holder_ref?.resolve() + hv_vis_holder_ref = null + if(holder) + UnregisterSignal(holder, COMSIG_QDELETING) + if(was_hidden && !QDELETED(holder)) + holder.update_held_items() + if(was_hidden && ismob(loc) && loc != holder && !QDELETED(loc)) + var/mob/current_mob = loc + current_mob.update_held_items() + +/obj/item/knife/proc/hv_on_holder_qdeleting(datum/source) + SIGNAL_HANDLER + hv_vis_drop_exec() + +/mob/living/do_attack_animation(atom/A, visual_effect_icon, obj/item/used_item, no_effect) + if(hv_vis_knife_executing) + return + return ..() + +// ---- Hooks on the execution ---- + +/obj/item/knife/hv_start_knife_execution(mob/living/user, mob/living/carbon/victim, list/modifiers, list/attack_modifiers) + var/staging = !DOING_INTERACTION(user, HV_KNIFE_EXECUTION_DOAFTER) && hv_knife_execution_possible(user, victim) && isturf(user.loc) && isturf(victim.loc) + hv_vis_cut_landed = FALSE + if(staging) + hv_vis_begin_knife_windup(user, victim) + . = ..() + if(!staging) + return + if(!hv_vis_cut_landed) + hv_vis_abort_knife_windup(user, victim) + +/obj/item/knife/hv_finish_knife_execution(mob/living/user, mob/living/carbon/victim, list/modifiers, list/attack_modifiers) + if(!isturf(user?.loc) || !isturf(victim?.loc)) + return ..() + var/was_standing = victim.body_position == STANDING_UP + var/pre_pixel_y = victim.pixel_y + var/matrix/pre_base = matrix(victim.transform) + var/obj/item/bodypart/head/head_before = victim.get_bodypart(BODY_ZONE_HEAD) + var/skull_open_before = head_before?.hv_skull_open + + // The stab's own hit spray (hv_blood_on_damaged) is held back: the throat sprays forward instead. + var/prev_spray_until = victim.hv_blood_spray_until + var/prev_spray_strength = victim.hv_blood_spray_strength + victim.hv_blood_spray_until = world.time + HV_BLOOD_SPRAY_WINDOW + victim.hv_blood_spray_strength = HV_BLOOD_MAX_RANGE + + victim.hv_vis_execution_time = world.time + user.hv_vis_knife_executing = TRUE + . = ..() + if(!QDELETED(user)) + user.hv_vis_knife_executing = FALSE + if(!QDELETED(victim)) + victim.hv_blood_spray_until = prev_spray_until + victim.hv_blood_spray_strength = prev_spray_strength + // The picture is a cut throat, not a broken skull: the stab's damage is booked on the head, but it doesn't + // open the skull wound a heavy blow to the head draws (gore_overlays.dm). Picture only. + var/obj/item/bodypart/head/head_after = victim.get_bodypart(BODY_ZONE_HEAD) + if(head_after && head_after == head_before && !skull_open_before && head_after.hv_skull_open) + head_after.hv_skull_open = FALSE + if(head_after.hv_update_skull_wound()) + victim.update_damage_overlays() + if(!.) + return + + hv_vis_cut_landed = TRUE + hv_vis_play_knife_cut(user, victim, was_standing, pre_pixel_y, pre_base) + +/// Whether `user` can hold `victim` from behind for the full picture: both human and on their feet, the attacker on +/// the tile straight behind the victim and facing his back. +/proc/hv_vis_knife_can_hold(mob/living/user, mob/living/victim) + if(!ishuman(user) || !ishuman(victim)) + return FALSE + if(user.body_position != STANDING_UP || victim.body_position != STANDING_UP) + return FALSE + if(!(victim.dir in GLOB.cardinals) || user.dir != victim.dir) + return FALSE + if(get_step(victim, REVERSE_DIR(victim.dir)) != user.loc) + return FALSE + return !user.buckled && !victim.buckled && !HAS_TRAIT(user, TRAIT_MOVE_FLOATING) && !HAS_TRAIT(victim, TRAIT_MOVE_FLOATING) + +/// The wind-up begins: the hold from behind, or the plain lean-in. +/obj/item/knife/proc/hv_vis_begin_knife_windup(mob/living/user, mob/living/carbon/victim) + hv_vis_drop_exec() + victim.hv_vis_stop(list(HV_VIS_TAG_TREMBLE)) + if(world.time >= hv_vis_hold_after && hv_vis_knife_can_hold(user, victim)) + hv_vis_hold_after = world.time + 1 SECONDS + var/datum/hv_knife_exec_vis/exec = new(src, user, victim) + if(!QDELETED(exec)) + return + // The plain version: he leans in over the victim and stays there. + if(HAS_TRAIT(user, TRAIT_MOVE_FLOATING) || user.body_position != STANDING_UP) + return + var/matrix/base = matrix(user.transform) + var/matrix/leaned = hv_vis_knife_pressed(user, victim, base, HV_VIS_KNIFE_PRESS) + hv_vis_pressing = TRUE + animate(user, transform = leaned, time = HV_VIS_KNIFE_STEP_TIME, easing = QUAD_EASING|EASE_OUT) + animate(transform = leaned, time = HV_KNIFE_EXECUTION_WINDUP + 3 SECONDS) + animate(transform = base, time = HV_VIS_KNIFE_RELEASE_TIME, easing = SINE_EASING) + +/// `base` moved `distance` pixels from `user` toward `victim`. +/proc/hv_vis_knife_pressed(mob/living/user, mob/living/victim, matrix/base, distance) + var/toward = get_dir(user, victim) || user.dir || SOUTH + var/matrix/pressed = matrix(base) + pressed.Translate(HV_VIS_DX(toward) * distance, HV_VIS_DY(toward) * distance) + return pressed + +/// The wind-up broke: everything goes back, no blood. +/obj/item/knife/proc/hv_vis_abort_knife_windup(mob/living/user, mob/living/carbon/victim) + if(hv_vis_exec && !QDELETED(hv_vis_exec)) + hv_vis_exec.abort() + return + if(hv_vis_pressing && !QDELETED(user)) + animate(user, transform = matrix(user.transform), time = HV_VIS_KNIFE_ABORT_TIME) + hv_vis_pressing = FALSE + +/// The cut landed: the blade's draw, the blood, the let-go. +/obj/item/knife/proc/hv_vis_play_knife_cut(mob/living/user, mob/living/carbon/victim, was_standing, pre_pixel_y, matrix/pre_base) + if(!QDELETED(user)) + user.hv_vis_stop(list(HV_VIS_TAG_HITSTOP)) + var/datum/hv_knife_exec_vis/exec = hv_vis_exec + var/held = exec && !QDELETED(exec) && !exec.attacker_done && exec.attacker == user && exec.victim == victim && !QDELETED(victim) && isturf(victim.loc) + if(held) + victim.hv_vis_stop(list(HV_VIS_TAG_FLINCH, HV_VIS_TAG_TREMBLE)) + exec.cut(was_standing, pre_pixel_y, pre_base) + else + hv_vis_drop_exec() + if(hv_vis_pressing && !QDELETED(user) && isturf(user.loc) && !QDELETED(victim) && user.body_position == STANDING_UP) + // The plain version: a short jab from the lean, then he straightens up. + var/matrix/base = matrix(user.transform) + var/matrix/leaned = hv_vis_knife_pressed(user, victim, base, HV_VIS_KNIFE_PRESS) + animate(user, transform = leaned, time = 0) + animate(transform = hv_vis_knife_pressed(user, victim, base, HV_VIS_KNIFE_PRESS + 2), time = 1, easing = QUAD_EASING|EASE_OUT) + animate(transform = leaned, time = HV_VIS_KNIFE_CUT_TIME) + animate(transform = base, time = HV_VIS_KNIFE_RELEASE_TIME, easing = SINE_EASING) + hv_vis_pressing = FALSE + if(QDELETED(victim) || !isturf(victim.loc)) + return + + // Blood from the throat, as the wound lands. Held from behind it goes the way he faces, away from the attacker; + // otherwise away from the blade. + var/spray_dir = held ? exec.facing : (QDELETED(user) ? victim.dir : get_dir(user, victim)) + if(!spray_dir) + spray_dir = victim.dir || SOUTH + // As much blood as the wound that landed (hv_knife_exec_spray): none without one. + var/obj/item/bodypart/head/head_after = victim.get_bodypart(BODY_ZONE_HEAD) + var/spray_tiles = hv_knife_exec_spray + if(spray_tiles <= 0 || !(head_after ? head_after.can_bleed() : victim.can_bleed())) + return + victim.hv_blood_spray_until = 0 + victim.hv_blood_spray_strength = 0 + // A cut that armour kept shallow throws no spray of its own: tg's own splash off the wound (a tile or so, from + // the stab) and the short jet below are all the blood there is. + if(spray_tiles >= 2) + victim.hv_blood_spray(spray_dir, spray_tiles) + if(held && exec.facing != NORTH) + var/list/throat = exec.throat_spot() + var/blood_color = get_color_from_blood_list(victim.get_blood_dna_list()) || BLOOD_COLOR_RED + new /obj/effect/temp_visual/hv_throat_spurt(get_turf(victim), throat[1], throat[2], spray_dir, blood_color, spray_tiles) + +// ---- Small maths ---- + +/// Smoothstep from 0 to 1 as `x` goes from 0 to 1. +/proc/hv_ke_smooth(x) + x = clamp(x, 0, 1) + return x * x * (3 - 2 * x) + +/// Fast start, eased stop, from 0 to 1 as `x` goes from 0 to 1. +/proc/hv_ke_ease_out(x) + x = clamp(x, 0, 1) + return 1 - (1 - x) * (1 - x) + +/// Blends two points. +/proc/hv_ke_mix(list/a, list/b, t) + return list(a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t) + +/// The shortest turn from angle `start` to angle `finish`, degrees, counter-clockwise positive. +/proc/hv_ke_turn(start, finish) + var/turn = (finish - start) % 360 + if(turn > 180) + turn -= 360 + else if(turn <= -180) + turn += 360 + return turn + +/// A body's transform for a pose list(x, y, clockwise lean about the feet), over its own `base`. +/proc/hv_ke_body_matrix(matrix/base, list/pose) + var/matrix/posed = matrix() + if(pose[3]) + posed.Translate(0, -HV_VIS_FEET_Y) + posed.Turn(pose[3]) + posed.Translate(0, HV_VIS_FEET_Y) + posed.Translate(pose[1], pose[2]) + return posed * base + +/// Where the pixel `spot` (x, y from the bottom left of the icon) of a body drawn with `posed` is, the body's icon +/// standing with its bottom left corner on `origin`. +/proc/hv_ke_body_point(list/origin, matrix/posed, list/spot) + var/x = spot[1] - 16 + var/y = spot[2] - 16 + return list(origin[1] + 16 + posed.a * x + posed.b * y + posed.c, origin[2] + 16 + posed.d * x + posed.e * y + posed.f) + +/// The elbow of an arm from `shoulder` to `fist` with upper arm `upper` and forearm `fore` long, bent toward the side +/// (hint_x, hint_y) points to. Too far apart, both stretch evenly in a straight line. +/proc/hv_ke_elbow(list/shoulder, list/fist, upper, fore, hint_x, hint_y) + var/dx = fist[1] - shoulder[1] + var/dy = fist[2] - shoulder[2] + var/reach = sqrt(dx * dx + dy * dy) + if(reach < 0.01) + return list(shoulder[1], shoulder[2] - upper) + if(reach >= upper + fore) + return list(shoulder[1] + dx * upper / (upper + fore), shoulder[2] + dy * upper / (upper + fore)) + var/along = clamp((upper * upper - fore * fore + reach * reach) / (2 * reach), -upper, upper) + var/out = sqrt(max(upper * upper - along * along, 0)) + var/side_x = -dy / reach + var/side_y = dx / reach + if(side_x * hint_x + side_y * hint_y < 0) + side_x = -side_x + side_y = -side_y + return list(shoulder[1] + dx * along / reach + side_x * out, shoulder[2] + dy * along / reach + side_y * out) + +/// One arm of `flat` (a body's own picture): rows 11 to 20, the four columns from `first_col`, as colours or null. +/proc/hv_ke_arm_strip(icon/flat, first_col) + var/list/strip = list() + for(var/y in 11 to 20) + var/list/row = new /list(4) + for(var/x in 1 to 4) + row[x] = flat.GetPixel(first_col + x - 1, y) + strip["[y]"] = row + return strip + +/// One-pixel overlays that draw rows `rows` (top first) of an arm strip, four wide about the middle of an icon, the +/// top row's upper edge on the icon's middle line. +/proc/hv_ke_strip_dots(list/strip, list/rows) + var/list/dots = list() + for(var/k in 1 to length(rows)) + var/list/row = strip["[rows[k]]"] + for(var/x in 1 to length(row)) + if(isnull(row[x])) + continue + var/mutable_appearance/dot = mutable_appearance(HV_VIS_KNIFE_PX, "px", FLOAT_LAYER) + dot.pixel_w = 13 + x + dot.pixel_z = 16 - k + dot.color = row[x] + dots += dot + return dots + +/// The pixel of a held knife's picture furthest from the hand that holds it: the tip. list(x, y) or null. +/proc/hv_ke_blade_tip(icon_file, state, facing, hand_x, hand_y) + var/static/list/known = list() + var/key = "[icon_file]|[state]|[facing]|[hand_x]|[hand_y]" + var/found = known[key] + if(found) + return islist(found) ? found : null + var/list/tip + if(icon_exists(icon_file, state)) + var/icon/picture = icon(icon_file, state, facing) + var/furthest = 2 + for(var/x in 1 to 32) + for(var/y in 1 to 32) + if(isnull(picture.GetPixel(x, y))) + continue + var/dx = x - 0.5 - hand_x + var/dy = y - 0.5 - hand_y + if(dx * dx + dy * dy > furthest) + furthest = dx * dx + dy * dy + tip = list(x - 0.5, y - 0.5) + known[key] = tip || "none" + return tip + +// ---- Pieces ---- + +/// A piece of a stand-in arm: a strip of someone's own arm, drawn between two joints. +/obj/effect/abstract/hv_knife_exec_part + name = "arm" + icon = null + plane = GAME_PLANE + layer = HV_VIS_KNIFE_OVER_LAYER + appearance_flags = PIXEL_SCALE | KEEP_TOGETHER + mouse_opacity = MOUSE_OPACITY_TRANSPARENT + animate_movement = NO_STEPS + anchored = TRUE + /// Read by the recording harness. + var/hv_knife_exec_part = TRUE + /// The middle of the icon this is drawn on, in the execution's own pixels. + var/centre_x = 16 + var/centre_y = 16 + /// Rows from the strip's top edge down to its root joint, and from there to its tip joint. + var/root_row = 0 + var/natural = 1 + +/obj/effect/abstract/hv_knife_exec_part/Initialize(mapload, list/dots, root_row = 0, natural = 1, draw_layer = HV_VIS_KNIFE_OVER_LAYER) + . = ..() + src.root_row = root_row + src.natural = natural + layer = draw_layer + if(length(dots)) + add_overlay(dots) + +/obj/effect/abstract/hv_knife_exec_part/ex_act(severity, target) + return FALSE + +/// The transform that draws this with its root joint on `root` and its tip joint on `tip`. +/obj/effect/abstract/hv_knife_exec_part/proc/span(list/root, list/tip) + var/dx = tip[1] - root[1] + var/dy = tip[2] - root[2] + var/length = sqrt(dx * dx + dy * dy) + var/matrix/placed = matrix() + placed.Translate(0, root_row) + placed.Scale(1, max(length, 0.5) / natural) + // The strip points down; Turn() is clockwise. + placed.Turn(length < 0.01 ? 0 : -(arctan(dx, dy) + 90)) + placed.Translate(root[1] - centre_x, root[2] - centre_y) + return placed + +/// The transform that draws this unstretched with its root joint on `spot`, pointing along `angle`. +/obj/effect/abstract/hv_knife_exec_part/proc/pin(list/spot, angle) + var/matrix/placed = matrix() + placed.Translate(0, root_row) + placed.Turn(-(angle + 90)) + placed.Translate(spot[1] - centre_x, spot[2] - centre_y) + return placed + +/// The attacker's held knife, as tg draws it in his hand, carried by the stand-in hand. +/obj/effect/abstract/hv_knife_exec_part/blade + name = "knife" + appearance_flags = PIXEL_SCALE + /// Read by the recording harness. + var/hv_knife_exec_blade = TRUE + /// The hand it is held in and its tip, pixels of its own icon. + var/hand_x = 16 + var/hand_y = 16 + var/tip_x = 16 + var/tip_y = 16 + /// The way it points as held, degrees counter-clockwise from east, and how long it is from the hand. + var/native_angle = 0 + var/reach = 1 + +/// The transform that draws the knife with its hand on `fist`, turned `turn` degrees counter-clockwise from how it +/// is held, and `squeeze` times as long along its own blade. +/obj/effect/abstract/hv_knife_exec_part/blade/proc/hold(list/fist, turn, squeeze = 1) + var/matrix/placed = matrix() + placed.Translate(16 - hand_x, 16 - hand_y) + if(squeeze != 1) + placed.Turn(native_angle) + placed.Scale(squeeze, 1) + placed.Turn(-native_angle) + if(turn) + placed.Turn(-turn) + placed.Translate(fist[1] - centre_x, fist[2] - centre_y) + return placed + +/// One stand-in arm. +/datum/hv_knife_exec_arm + /// Its name in a pose: "k" the knife arm, "f" the attacker's free arm, "v" the victim's own. + var/id + /// TRUE for the victim's own arm. + var/on_victim = FALSE + var/obj/effect/abstract/hv_knife_exec_part/upper + var/obj/effect/abstract/hv_knife_exec_part/fore + var/obj/effect/abstract/hv_knife_exec_part/hand + /// The shoulder joint and the hanging fist, pixels of its owner's icon. + var/list/shoulder + var/list/hang + /// Where the fist goes, pixels of the victim's icon: on the grab, and once the cut is through. For the victim's + /// own arm: fighting the knife hand, and at his throat. + var/list/hold + var/list/after + /// If set, the forearm ends here (pixels of the victim's icon) and the hand goes on from it: over a shoulder. + var/list/wrist_hold + var/list/wrist_after + /// The side its elbow bends toward. + var/hint_x = 0 + var/hint_y = -1 + +/datum/hv_knife_exec_arm/Destroy(force) + QDEL_NULL(upper) + QDEL_NULL(fore) + QDEL_NULL(hand) + return ..() + +// ---- The execution from behind ---- + +/datum/hv_knife_exec_vis + var/obj/item/knife/knife + var/mob/living/carbon/human/attacker + var/mob/living/carbon/human/victim + /// The way the victim faced when it began: the view the poses are drawn for. + var/facing = SOUTH + /// world.time it began, and of the cut (-1 before it). + var/started = 0 + var/cut_time = -1 + /// The attacker's side (his arms, the knife, his step) and the victim's side (his arm, his pose) are over. + var/attacker_done = FALSE + var/victim_done = FALSE + /// The wind-up broke and everything is easing back. + var/aborting = FALSE + /// The tile the victim stood on when it began. + var/turf/vic_turf + /// The cut dropped him: he is drawn held up through it, by tg's own fall after. + var/victim_held = FALSE + /// He is still on his feet after the cut: he stumbles forward bent over (and, with a free hand, clutches his throat). + var/victim_hunches = FALSE + /// Where each body's icon stands at rest (its bottom left corner), in pixels from the victim's tile's corner. + var/list/att_origin + var/list/vic_origin + var/matrix/att_base + var/matrix/vic_base + /// The attacker's step in, the victim's haul back, pixels. + var/step_x = 0 + var/step_y = 0 + var/pull_x = 0 + var/pull_y = 0 + /// Clockwise degrees: the attacker's lean in, the victim bent back. + var/att_lean = 0 + var/vic_lean = 0 + /// The victim's jerks against the hold: pixels and degrees at their peak. + var/jerk_x = 0 + var/jerk_y = 0 + var/jerk_lean = 0 + /// A survivor bent over the cut: pixels and degrees. + var/hunch_x = 0 + var/hunch_y = 0 + var/hunch_lean = 0 + /// Arms by id (/datum/hv_knife_exec_arm). + var/list/arms = list() + var/obj/effect/abstract/hv_knife_exec_part/blade/blade + /// The way the blade points on the victim's icon, degrees counter-clockwise from east: held, and after the cut. + var/blade_hold_angle = 0 + var/blade_after_angle = 0 + /// How long the blade is drawn along its own length while held at the throat, and once the cut is through: under + /// 1 where it points away from or toward the viewer (round the far side of a neck), or swings out of sight. + var/blade_hold_squeeze = 1 + var/blade_after_squeeze = 1 + /// Pixels the knife is drawn pushed back through the hand while held at the throat. The far hand shows only where + /// it sticks out from behind the neck, and the blade should start at what shows of it. + var/blade_slide = 0 + /// The layer the blade drops to as the hand lets go, if any. + var/blade_release_layer + /// Side view with the knife in the attacker's far hand, reaching behind both bodies to the chin. + var/far_cut = FALSE + /// The throat, pixels of the victim's icon: where the blood starts. + var/list/throat = list(15.5, 21.5) + /// Filters and cover overlays on each body, to take off again. + var/list/att_filters = list() + var/list/vic_filters = list() + var/mutable_appearance/att_patch + var/mutable_appearance/vic_patch + /// The attacker's layer before he was put under the victim (side views), or null. + var/att_layer + +/datum/hv_knife_exec_vis/New(obj/item/knife/knife, mob/living/carbon/human/attacker, mob/living/carbon/human/victim) + src.knife = knife + src.attacker = attacker + src.victim = victim + facing = victim.dir + started = world.time + if(!set_up()) + qdel(src) + return + knife.hv_vis_exec = src + RegisterSignals(attacker, list(COMSIG_QDELETING, COMSIG_MOVABLE_MOVED, COMSIG_ATOM_POST_DIR_CHANGE, COMSIG_LIVING_SET_BODY_POSITION), PROC_REF(on_attacker_change)) + RegisterSignals(victim, list(COMSIG_QDELETING, COMSIG_MOVABLE_MOVED, COMSIG_ATOM_POST_DIR_CHANGE, COMSIG_LIVING_SET_BODY_POSITION, COMSIG_LIVING_DEATH), PROC_REF(on_victim_change)) + RegisterSignal(knife, COMSIG_QDELETING, PROC_REF(on_knife_gone)) + // Nothing outlives the move, whatever happens to it. + QDEL_IN(src, HV_KNIFE_EXECUTION_WINDUP + 5 SECONDS) + play(windup_keys()) + if(far_cut && blade) + addtimer(CALLBACK(src, PROC_REF(show_far_blade)), 3.3, TIMER_DELETE_ME) + +/datum/hv_knife_exec_vis/Destroy(force) + end_attacker(at_once = TRUE) + end_victim(at_once = TRUE) + if(knife) + UnregisterSignal(knife, COMSIG_QDELETING) + if(knife.hv_vis_exec == src) + knife.hv_vis_exec = null + if(attacker) + UnregisterSignal(attacker, list(COMSIG_QDELETING, COMSIG_MOVABLE_MOVED, COMSIG_ATOM_POST_DIR_CHANGE, COMSIG_LIVING_SET_BODY_POSITION)) + if(victim) + UnregisterSignal(victim, list(COMSIG_QDELETING, COMSIG_MOVABLE_MOVED, COMSIG_ATOM_POST_DIR_CHANGE, COMSIG_LIVING_SET_BODY_POSITION, COMSIG_LIVING_DEATH)) + QDEL_LIST_ASSOC_VAL(arms) + knife = null + attacker = null + victim = null + vic_turf = null + return ..() + +/// The attacker moved, turned, fell or is gone: his side ends at once. +/datum/hv_knife_exec_vis/proc/on_attacker_change(datum/source) + SIGNAL_HANDLER + if(QDELETED(attacker)) + qdel(src) + return + end_attacker(at_once = TRUE) + +/// The victim moved, turned, fell, died or is gone. During the wind-up that breaks the hold: everything eases back. +/// After the cut his own side ends at once. +/datum/hv_knife_exec_vis/proc/on_victim_change(datum/source) + SIGNAL_HANDLER + if(QDELETED(victim)) + qdel(src) + return + // Inside the cut's own tick tg may lay him down: cut() deals with that. + if(cut_time == world.time || (cut_time < 0 && victim.hv_vis_execution_time == world.time)) + end_victim_arm() + return + if(cut_time < 0) + abort() + return + end_victim(at_once = TRUE) + +/datum/hv_knife_exec_vis/proc/on_knife_gone(datum/source) + SIGNAL_HANDLER + qdel(src) + +/// Brings the far-hand blade in front of the victim's neck once the hand has come round under his chin. +/datum/hv_knife_exec_vis/proc/show_far_blade() + if(aborting || attacker_done || cut_time >= 0 || QDELETED(blade)) + return + blade.layer = HV_VIS_KNIFE_OVER_LAYER + HV_VIS_KNIFE_BLADE_OFFSET + +// ---- Setting up ---- + +/// Reads both bodies, builds the arms and hides the real ones. FALSE if this pair can't be drawn. +/datum/hv_knife_exec_vis/proc/set_up() + vic_turf = get_turf(victim) + var/turf/att_turf = get_turf(attacker) + if(!vic_turf || !att_turf) + return FALSE + var/knife_zone = attacker.get_hand_zone_of_item(knife) + if(!knife_zone || !attacker.get_bodypart(knife_zone)) + return FALSE + var/free_zone = knife_zone == BODY_ZONE_R_ARM ? BODY_ZONE_L_ARM : BODY_ZONE_R_ARM + var/free_arm = attacker.get_bodypart(free_zone) && !attacker.get_item_for_held_index(free_zone == BODY_ZONE_L_ARM ? 1 : 2) + + att_base = matrix(attacker.transform) + vic_base = matrix(victim.transform) + vic_origin = list(victim.pixel_x + victim.pixel_w, victim.pixel_y + victim.pixel_z) + att_origin = list( + (att_turf.x - vic_turf.x) * ICON_SIZE_X + attacker.pixel_x + attacker.pixel_w, + (att_turf.y - vic_turf.y) * ICON_SIZE_Y + attacker.pixel_y + attacker.pixel_z, + ) + + // The knife as tg draws it in his hand. + var/left_hand = knife_zone == BODY_ZONE_L_ARM + var/knife_file = left_hand ? knife.lefthand_file : knife.righthand_file + var/knife_state = knife.inhand_icon_state || knife.icon_state + + // His own picture, without the knife, before anything is masked. + knife.hv_vis_hide_held_sprite(attacker) + var/icon/att_flat = getFlatIcon(attacker, facing, no_anim = TRUE) + var/icon/vic_flat = getFlatIcon(victim, facing, no_anim = TRUE) + if(!att_flat || !vic_flat) + knife.hv_vis_restore_held_sprite() + return FALSE + + var/list/victim_zones + if(facing == NORTH || facing == SOUTH) + // The side of the screen each arm is on: his right is on the left when he faces us. + var/knife_side = ((facing == SOUTH) == (knife_zone == BODY_ZONE_R_ARM)) ? -1 : 1 + var/turf/north_turf = facing == SOUTH ? att_turf : vic_turf + if(facing == SOUTH) + step_y = -HV_VIS_KNIFE_STEP_SOUTH + pull_y = HV_VIS_KNIFE_PULL_SOUTH + hunch_y = -2 + else + step_y = HV_VIS_KNIFE_STEP_NORTH + pull_y = -HV_VIS_KNIFE_PULL_NORTH + hunch_y = 2 + jerk_x = 1.5 + throat = list(15.5, 21.5) + + var/list/knife_strip = hv_ke_arm_strip(att_flat, knife_side < 0 ? 8 : 21) + var/datum/hv_knife_exec_arm/knife_arm + if(facing == SOUTH) + // Behind the victim down to the wrist, the hand and blade in front of his neck. + knife_arm = add_arm("k", knife_strip, north_turf, HV_VIS_KNIFE_OVER_LAYER, vic_turf, HV_VIS_KNIFE_OVER_LAYER) + else + // Over both down to the wrist, which lies on his shoulder; the hand goes on round his neck, out of sight. + knife_arm = add_arm("k", knife_strip, att_turf, HV_VIS_KNIFE_OVER_LAYER, vic_turf, HV_VIS_KNIFE_UNDER_LAYER) + knife_arm.shoulder = list(15.5 + knife_side * 6.5, 19) + knife_arm.hang = list(15.5 + knife_side * 6.5, 12.5) + knife_arm.hint_x = knife_side + knife_arm.hint_y = 0 + add_blade(knife_file, knife_state, knife_arm, vic_turf, (facing == SOUTH ? HV_VIS_KNIFE_OVER_LAYER : HV_VIS_KNIFE_UNDER_LAYER) + HV_VIS_KNIFE_BLADE_OFFSET) + var/blade_reach = blade ? blade.reach : 6 + if(facing == SOUTH) + // The blade lies across the throat from the knife side, its tip on the far edge of the neck. + blade_hold_angle = knife_side < 0 ? 0 : 180 + blade_after_angle = blade_hold_angle + knife_arm.hold = list(15.5 - knife_side * 1.5 + knife_side * blade_reach, 20.6) + knife_arm.after = list(knife_arm.hold[1] + knife_side * 2.8, 20.3) + else + blade_hold_angle = arctan(-knife_side * 0.95, 0.3) + blade_after_angle = blade_hold_angle + // It points on round his neck, away from us: seen end on, and all of it behind his head. Drawn shorter + // still on the stroke, where the hand comes out to the side of his head and a longer blade shows past it. + blade_hold_squeeze = 0.5 + blade_after_squeeze = 0.2 + knife_arm.hold = list(15.5 + knife_side * 0.8, 23.5) + knife_arm.after = list(15.5 + knife_side * 6, 22.5) + knife_arm.wrist_hold = list(15.5 + knife_side * 5.3, 21.3) + knife_arm.wrist_after = list(15.5 + knife_side * 8.3, 20.8) + + if(free_arm) + var/list/free_strip = hv_ke_arm_strip(att_flat, knife_side < 0 ? 21 : 8) + var/datum/hv_knife_exec_arm/free = add_arm("f", free_strip, facing == SOUTH ? north_turf : att_turf, HV_VIS_KNIFE_OVER_LAYER, facing == SOUTH ? vic_turf : att_turf, HV_VIS_KNIFE_OVER_LAYER) + free.shoulder = list(15.5 - knife_side * 6.5, 19) + free.hang = list(15.5 - knife_side * 6.5, 12.5) + free.hint_x = -knife_side + free.hint_y = 0 + // On the victim's other shoulder. + free.hold = facing == SOUTH ? list(15.5 - knife_side * 6, 21) : list(15.5 - knife_side * 5.5, 20.8) + free.after = free.hold + add_mask(attacker, att_filters, "hv_knife_arms", 'voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arms.dmi') + else if(knife_side < 0) + add_mask(attacker, att_filters, "hv_knife_arms", 'voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arm_l.dmi') + else + add_mask(attacker, att_filters, "hv_knife_arms", 'voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arm_r.dmi') + + // The victim's own arm, facing us: the one on the knife's side if that hand is empty, else the other. + if(facing == SOUTH) + var/near_zone = knife_side < 0 ? BODY_ZONE_R_ARM : BODY_ZONE_L_ARM + victim_zones = list(near_zone, near_zone == BODY_ZONE_R_ARM ? BODY_ZONE_L_ARM : BODY_ZONE_R_ARM) + for(var/zone in victim_zones) + if(!victim.get_bodypart(zone) || victim.get_item_for_held_index(zone == BODY_ZONE_L_ARM ? 1 : 2)) + continue + var/side = zone == BODY_ZONE_R_ARM ? -1 : 1 + var/datum/hv_knife_exec_arm/own = add_victim_arm(hv_ke_arm_strip(vic_flat, side < 0 ? 8 : 21)) + own.shoulder = list(15.5 + side * 6.5, 19) + own.hang = list(15.5 + side * 6.5, 12.5) + own.hold = side == knife_side ? list(knife_arm.hold[1] - knife_side * 0.3, knife_arm.hold[2] - 2.3) : list(15.5 + side * 2, 19.5) + own.after = list(15.5 + side * 0.6, 21.2) + add_mask(victim, vic_filters, "hv_knife_arm", side < 0 ? 'voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arm_l.dmi' : 'voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_arm_r.dmi') + break + else + // Side on. Everything below is written for a victim facing east and mirrored for west. + var/east = facing == EAST + var/way = east ? 1 : -1 + var/near_zone = east ? BODY_ZONE_R_ARM : BODY_ZONE_L_ARM + var/near_cut = knife_zone == near_zone + step_x = way * HV_VIS_KNIFE_STEP_SIDE + pull_x = -way * HV_VIS_KNIFE_PULL_SIDE + att_lean = way * HV_VIS_KNIFE_LEAN_ATTACKER + vic_lean = -way * HV_VIS_KNIFE_LEAN_VICTIM + jerk_x = way * 1.5 + jerk_lean = way * 3 + hunch_x = way * 2 + hunch_y = -1 + hunch_lean = way * HV_VIS_KNIFE_HUNCH_TILT + throat = list(mirror(19.3, way), 21.6) + // Both stand on one row: he is drawn a hair under the man he holds. + if(attacker.layer == MOB_LAYER) + att_layer = attacker.layer + attacker.layer = HV_VIS_KNIFE_ATTACKER_LAYER + + var/list/near_strip = hv_ke_arm_strip(att_flat, east ? 13 : 17) + if(near_cut) + // His near arm comes over the victim's shoulder; the blade runs up the side of the neck to the throat. + var/datum/hv_knife_exec_arm/knife_arm = add_arm("k", near_strip, vic_turf, HV_VIS_KNIFE_OVER_LAYER, vic_turf, HV_VIS_KNIFE_OVER_LAYER) + knife_arm.shoulder = list(mirror(14, way), 19) + knife_arm.hang = list(mirror(14, way), 12.5) + knife_arm.hint_x = -way * 0.3 + add_blade(knife_file, knife_state, knife_arm, vic_turf, HV_VIS_KNIFE_OVER_LAYER + HV_VIS_KNIFE_BLADE_OFFSET) + var/blade_reach = blade ? blade.reach : 7 + blade_hold_angle = east ? 15 : 165 + blade_after_angle = blade_hold_angle + var/list/tip = list(mirror(19, way), 21.2) + knife_arm.hold = list(tip[1] - blade_reach * cos(blade_hold_angle), tip[2] - blade_reach * sin(blade_hold_angle)) + knife_arm.after = list(knife_arm.hold[1] - 3.5 * cos(blade_hold_angle), knife_arm.hold[2] - 3.5 * sin(blade_hold_angle) - 0.5) + add_patch(attacker, att_flat, east, FALSE) + else + // His far arm goes round the far side of the neck, out of sight behind both of them; the hand comes + // round under the chin and the blade lies back along the throat. His near hand takes the shoulder. + far_cut = TRUE + var/datum/hv_knife_exec_arm/knife_arm = add_arm("k", near_strip, vic_turf, HV_VIS_KNIFE_FAR_LAYER, vic_turf, HV_VIS_KNIFE_FAR_LAYER) + knife_arm.shoulder = list(mirror(18.5, way), 19) + knife_arm.hang = list(mirror(19.5, way), 12.5) + knife_arm.hint_x = -way * 0.3 + add_blade(knife_file, knife_state, knife_arm, vic_turf, HV_VIS_KNIFE_FAR_BLADE_LAYER) + blade_hold_angle = east ? 176 : 4 + blade_after_angle = blade_hold_angle + blade_after_squeeze = 0.15 + blade_slide = 1.3 + blade_release_layer = HV_VIS_KNIFE_FAR_BLADE_LAYER + knife_arm.hold = list(mirror(21.4, way), 21.4) + knife_arm.after = knife_arm.hold + add_mask(attacker, att_filters, "hv_knife_far", east ? 'voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_far_e.dmi' : 'voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_far_w.dmi') + if(free_arm) + var/datum/hv_knife_exec_arm/free = add_arm("f", near_strip, vic_turf, HV_VIS_KNIFE_OVER_LAYER, vic_turf, HV_VIS_KNIFE_OVER_LAYER) + free.shoulder = list(mirror(14, way), 19) + free.hang = list(mirror(14, way), 12.5) + free.hint_x = -way * 0.3 + free.hold = list(mirror(13.5, way), 19.5) + free.after = free.hold + add_patch(attacker, att_flat, east, FALSE) + + // The victim's own near arm, or his far arm if the near hand is full. + var/far_zone = east ? BODY_ZONE_L_ARM : BODY_ZONE_R_ARM + if(victim.get_bodypart(near_zone) && !victim.get_item_for_held_index(near_zone == BODY_ZONE_L_ARM ? 1 : 2)) + var/datum/hv_knife_exec_arm/own = add_victim_arm(hv_ke_arm_strip(vic_flat, east ? 13 : 17)) + own.shoulder = list(mirror(14, way), 19) + own.hang = list(mirror(14, way), 12.5) + own.hold = list(mirror(18.5, way), 19.6) + own.after = list(mirror(18.6, way), 21) + add_patch(victim, vic_flat, east, TRUE) + else if(victim.get_bodypart(far_zone) && !victim.get_item_for_held_index(far_zone == BODY_ZONE_L_ARM ? 1 : 2)) + var/datum/hv_knife_exec_arm/own = add_arm("v", hv_ke_arm_strip(vic_flat, east ? 13 : 17), get_turf(victim), HV_VIS_KNIFE_FAR_LAYER, get_turf(victim), HV_VIS_KNIFE_FAR_LAYER) + own.on_victim = TRUE + own.shoulder = list(mirror(18.5, way), 19) + own.hang = list(mirror(19.5, way), 12.5) + own.hold = list(mirror(19.8, way), 19.8) + own.after = list(mirror(20, way), 21) + add_mask(victim, vic_filters, "hv_knife_far", east ? 'voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_far_e.dmi' : 'voidcrew/modules/hyperviolence/overlays_exec/icons/knife_exec_mask_far_w.dmi') + + // Everything starts as it hangs. + var/list/rest = snapshot(0, -1) + for(var/id in arms) + var/datum/hv_knife_exec_arm/arm = arms[id] + arm.upper.transform = rest["[id]u"] + arm.fore.transform = rest["[id]f"] + arm.hand.transform = rest["[id]h"] + if(blade) + blade.transform = rest["blade"] + return TRUE + +/// An x on an icon written for a body facing east, as it is for one facing `way` (1 east, -1 west). +/datum/hv_knife_exec_vis/proc/mirror(x, way) + return 16 + way * (x - 16) + +/// The middle of `place`'s tile in the execution's own pixels (from the corner of the victim's tile). +/datum/hv_knife_exec_vis/proc/tile_centre(turf/place) + return list((place.x - vic_turf.x) * ICON_SIZE_X + 16, (place.y - vic_turf.y) * ICON_SIZE_Y + 16) + +/// Builds one of the attacker's arms from `strip`: upper arm and forearm on `arm_turf`, the hand on `hand_turf`. +/datum/hv_knife_exec_vis/proc/add_arm(id, list/strip, turf/arm_turf, arm_layer, turf/hand_turf, hand_layer) + var/datum/hv_knife_exec_arm/arm = new + arm.id = id + arm.upper = new(arm_turf, hv_ke_strip_dots(strip, list(20, 19, 18, 17, 16)), 1, HV_VIS_KNIFE_UPPER_ARM, arm_layer) + arm.fore = new(arm_turf, hv_ke_strip_dots(strip, list(16, 15, 14)), 0.5, HV_VIS_KNIFE_FOREARM - 0.5, arm_layer) + arm.hand = new(hand_turf, hv_ke_strip_dots(strip, list(14, 13, 12, 11)), 1.5, 1, hand_layer) + for(var/obj/effect/abstract/hv_knife_exec_part/part as anything in list(arm.upper, arm.fore, arm.hand)) + var/list/centre = tile_centre(part.loc) + part.centre_x = centre[1] + part.centre_y = centre[2] + arms[id] = arm + return arm + +/// Builds the victim's own arm from `strip`, on his tile, just over him and under the attacker's hands. (Pieces in +/// his vis_contents would not follow a named animation of his transform.) +/datum/hv_knife_exec_vis/proc/add_victim_arm(list/strip) + var/datum/hv_knife_exec_arm/arm = add_arm("v", strip, get_turf(victim), HV_VIS_KNIFE_VICTIM_ARM_LAYER, get_turf(victim), HV_VIS_KNIFE_VICTIM_ARM_LAYER) + arm.on_victim = TRUE + return arm + +/// The held knife's picture, carried by `arm`'s hand. +/datum/hv_knife_exec_vis/proc/add_blade(knife_file, knife_state, datum/hv_knife_exec_arm/arm, turf/place, draw_layer) + if(!knife_file || !knife_state) + return + // tg draws a held thing around the hand of the arm's own sprite: the near hand side on, else the hanging fist. + var/list/held_at = arm.hang + if(facing == EAST || facing == WEST) + var/way = facing == EAST ? 1 : -1 + var/near_zone = facing == EAST ? BODY_ZONE_R_ARM : BODY_ZONE_L_ARM + if(attacker.get_hand_zone_of_item(knife) != near_zone) + held_at = list(mirror(20.5, way), 12.5) + var/list/tip = hv_ke_blade_tip(knife_file, knife_state, facing, held_at[1], held_at[2]) + if(!tip) + return + blade = new(place, null, 0, 1, draw_layer) + blade.icon = knife_file + blade.icon_state = knife_state + blade.setDir(facing) + blade.color = knife.color + // The picture is carried by the fist: where the fist hangs is where its own hand is. + blade.hand_x = arm.hang[1] + blade.hand_y = arm.hang[2] + blade.tip_x = tip[1] + blade.tip_y = tip[2] + blade.native_angle = arctan(tip[1] - arm.hang[1], tip[2] - arm.hang[2]) + blade.reach = sqrt((tip[1] - arm.hang[1]) ** 2 + (tip[2] - arm.hang[2]) ** 2) + var/list/centre = tile_centre(place) + blade.centre_x = centre[1] + blade.centre_y = centre[2] + +/// Cuts a hanging arm out of `body`'s picture with the mask `mask_file`. +/datum/hv_knife_exec_vis/proc/add_mask(mob/living/body, list/names, name, mask_file) + body.add_filter(name, 30, alpha_mask_filter(icon = mask_file, flags = MASK_INVERSE)) + names |= name + +/// Side on, the near arm hangs over the body: covers it with the body's own chest, four pixels further forward. +/datum/hv_knife_exec_vis/proc/add_patch(mob/living/carbon/human/body, icon/flat, east, on_victim) + if(on_victim ? vic_patch : att_patch) + return + var/first_col = east ? 13 : 17 + var/shift = east ? 4 : -4 + var/mutable_appearance/patch = mutable_appearance(layer = -(SUIT_LAYER - 0.5)) + for(var/row in 11 to 19) + for(var/col in first_col to first_col + 3) + if(isnull(flat.GetPixel(col, row))) + continue + var/colour = flat.GetPixel(col + shift, row) + if(isnull(colour)) + continue + var/mutable_appearance/dot = mutable_appearance(HV_VIS_KNIFE_PX, "px", FLOAT_LAYER) + dot.pixel_w = col - 1 + dot.pixel_z = row - 1 + dot.color = colour + patch.overlays += dot + body.add_overlay(patch) + if(on_victim) + vic_patch = patch + else + att_patch = patch + +// ---- Poses ---- + +/// The attacker's pose `since` deciseconds in, `after` deciseconds after the cut (-1 before it): list(x, y, lean). +/datum/hv_knife_exec_vis/proc/attacker_pose(since, after) + var/weight = hv_ke_ease_out(since / HV_VIS_KNIFE_STEP_TIME) + if(after >= 0) + weight *= 1 - hv_ke_smooth((after - HV_VIS_KNIFE_CUT_TIME - HV_VIS_KNIFE_CUT_HOLD) / HV_VIS_KNIFE_RELEASE_TIME) + return list(step_x * weight, step_y * weight, att_lean * weight) + +/// How hard the victim is jerking against the hold `since` deciseconds in: -1 to 1. +/datum/hv_knife_exec_vis/proc/jerk(since) + var/static/list/jerks = list(6, 8, 10.5, 12.5) + for(var/i in 1 to length(jerks)) + var/into = since - jerks[i] + if(into <= 0 || into >= 1.5) + continue + var/size = into < 0.5 ? into / 0.5 : 1 - (into - 0.5) + return (i % 2) ? size : -size + return 0 + +/// The victim's pose: list(x, y, lean). +/datum/hv_knife_exec_vis/proc/victim_pose(since, after) + var/weight = hv_ke_ease_out((since - HV_VIS_KNIFE_PULL_START) / HV_VIS_KNIFE_PULL_TIME) + var/let_go = HV_VIS_KNIFE_CUT_TIME + HV_VIS_KNIFE_CUT_HOLD + if(after >= 0 && !victim_held) + weight *= 1 - hv_ke_smooth((after - let_go) / HV_VIS_KNIFE_VICTIM_BACK_TIME) + var/list/pose = list(pull_x * weight, pull_y * weight, vic_lean * weight) + if(after < 0) + var/struggle = jerk(since) + pose[1] += jerk_x * struggle + pose[2] += jerk_y * struggle + pose[3] += jerk_lean * struggle + else if(victim_hunches) + var/bent = hv_ke_smooth((after - let_go) / HV_VIS_KNIFE_CLUTCH_IN) * (1 - hv_ke_smooth((after - HV_VIS_KNIFE_HUNCH_END) / HV_VIS_KNIFE_HUNCH_OUT)) + pose[1] += hunch_x * bent + pose[2] += hunch_y * bent + pose[3] += hunch_lean * bent + return pose + +/// Every transform of the move `since` deciseconds in and `after` deciseconds after the cut (-1 before it): "A" and +/// "V" the bodies, "[arm id]u", "[arm id]f" and "[arm id]h" each arm's pieces, "blade" the knife. +/datum/hv_knife_exec_vis/proc/snapshot(since, after) + var/list/snap = list() + var/list/att_pose = attacker_pose(since, after) + var/list/vic_pose = victim_pose(since, after) + var/matrix/att_matrix = hv_ke_body_matrix(att_base, att_pose) + var/matrix/vic_matrix = hv_ke_body_matrix(vic_base, vic_pose) + snap["A"] = att_matrix + snap["V"] = vic_matrix + var/let_go = HV_VIS_KNIFE_CUT_TIME + HV_VIS_KNIFE_CUT_HOLD + var/through = 0 + var/held_in = hv_ke_smooth((since - HV_VIS_KNIFE_REACH_START) / HV_VIS_KNIFE_REACH_TIME) + var/held = held_in + if(after >= 0) + through = hv_ke_smooth(after / HV_VIS_KNIFE_CUT_TIME) + held *= 1 - hv_ke_smooth((after - let_go) / HV_VIS_KNIFE_RELEASE_TIME) + for(var/id in arms) + var/datum/hv_knife_exec_arm/arm = arms[id] + if(arm.on_victim) + // His own arm: up at the knife hand, then to his throat, then down. + var/list/goal = arm.hold + var/up = hv_ke_smooth((since - HV_VIS_KNIFE_GUARD_START) / HV_VIS_KNIFE_GUARD_TIME) + if(after >= 0) + if(victim_hunches) + goal = hv_ke_mix(arm.hold, arm.after, hv_ke_smooth((after - let_go) / HV_VIS_KNIFE_CLUTCH_IN)) + up = 1 - hv_ke_smooth((after - HV_VIS_KNIFE_CLUTCH_END) / HV_VIS_KNIFE_CLUTCH_OUT) + else + up *= 1 - hv_ke_smooth((after - let_go) / HV_VIS_KNIFE_VICTIM_BACK_TIME) + var/list/own_fist = hv_ke_body_point(vic_origin, vic_matrix, hv_ke_mix(arm.hang, goal, up)) + place_arm(arm, snap, hv_ke_body_point(vic_origin, vic_matrix, arm.shoulder), own_fist, null) + continue + var/arm_held = (far_cut && id == "k" && after >= 0) ? held_in * (1 - hv_ke_smooth((after - let_go) / (HV_VIS_KNIFE_RELEASE_TIME * 0.5))) : held + var/swing = 4 * arm_held * (1 - arm_held) + var/list/shoulder = hv_ke_body_point(att_origin, att_matrix, arm.shoulder) + var/list/hang = hv_ke_body_point(att_origin, att_matrix, arm.hang) + var/list/target = hv_ke_body_point(vic_origin, vic_matrix, hv_ke_mix(arm.hold, arm.after, through)) + var/list/goal_fist = hv_ke_mix(hang, target, arm_held) + if(facing == SOUTH) + if(id == "k") + goal_fist[1] += arm.hint_x * 4 * swing + goal_fist[2] += 5 * swing + else + goal_fist[1] += arm.hint_x * 2.5 * swing + goal_fist[2] += 3.5 * swing + else if(!far_cut && id == "k" && after >= let_go && facing != NORTH) + goal_fist[2] -= 2.2 * swing + var/list/wrist + if(arm.wrist_hold) + var/list/wrist_target = hv_ke_body_point(vic_origin, vic_matrix, hv_ke_mix(arm.wrist_hold, arm.wrist_after, through)) + wrist = hv_ke_mix(list(hang[1], hang[2] + 0.5), wrist_target, arm_held) + var/list/fist = place_arm(arm, snap, shoulder, goal_fist, wrist) + if(id == "k" && blade) + // As he holds it at his side, turning with his hand to lie on the throat. + var/from_angle = blade.native_angle - att_pose[3] + var/to_angle = blade_hold_angle + (blade_after_angle - blade_hold_angle) * through - vic_pose[3] + var/angle + var/squeeze + if(far_cut) + if(after < 0) + if(arm_held <= 0.45) + angle = from_angle + squeeze = 1 - 0.85 * hv_ke_smooth(arm_held / 0.35) + else + angle = to_angle + squeeze = 0.15 + (blade_hold_squeeze - 0.15) * hv_ke_smooth((arm_held - 0.65) / 0.35) + else if(after < let_go) + angle = to_angle + squeeze = blade_hold_squeeze + (blade_after_squeeze - blade_hold_squeeze) * through + else if(arm_held > 0.45) + angle = to_angle + squeeze = blade_after_squeeze + else + angle = from_angle + squeeze = 1 - (1 - blade_after_squeeze) * hv_ke_smooth(arm_held / 0.35) + else + var/turn_t = arm_held + if(facing == SOUTH) + turn_t = hv_ke_smooth((arm_held - 0.55) / 0.45) + else if(facing != NORTH && after >= let_go) + turn_t = hv_ke_smooth((arm_held - 0.4) / 0.6) + angle = from_angle + hv_ke_turn(from_angle, to_angle) * turn_t + squeeze = 1 + (blade_hold_squeeze + (blade_after_squeeze - blade_hold_squeeze) * through - 1) * arm_held + var/list/held_at = fist + if(blade_slide) + held_at = list(fist[1] - blade_slide * arm_held * cos(angle), fist[2] - blade_slide * arm_held * sin(angle)) + snap["blade"] = blade.hold(held_at, angle - blade.native_angle, squeeze) + return snap + +/// Works out one arm from `shoulder` to `fist` (through `wrist`, if given) and writes its pieces' transforms into +/// `snap`. An arm never stretches past HV_VIS_KNIFE_ARM_STRETCH: the hand stops short instead. Returns the fist. +/datum/hv_knife_exec_vis/proc/place_arm(datum/hv_knife_exec_arm/arm, list/snap, list/shoulder, list/fist, list/wrist) + var/list/end = wrist || fist + var/fore_length = wrist ? HV_VIS_KNIFE_FOREARM - 0.5 : HV_VIS_KNIFE_FOREARM + var/longest = (HV_VIS_KNIFE_UPPER_ARM + fore_length) * HV_VIS_KNIFE_ARM_STRETCH + var/dx = end[1] - shoulder[1] + var/dy = end[2] - shoulder[2] + var/reach = sqrt(dx * dx + dy * dy) + if(reach > longest) + var/short_x = dx * (longest / reach - 1) + var/short_y = dy * (longest / reach - 1) + end = list(end[1] + short_x, end[2] + short_y) + fist = wrist ? list(fist[1] + short_x, fist[2] + short_y) : end + var/list/elbow = hv_ke_elbow(shoulder, end, HV_VIS_KNIFE_UPPER_ARM, fore_length, arm.hint_x, arm.hint_y) + var/fore_x = end[1] - elbow[1] + var/fore_y = end[2] - elbow[2] + var/fore_angle = (abs(fore_x) + abs(fore_y) < 0.01) ? -90 : arctan(fore_x, fore_y) + var/list/wrist_at + var/hand_angle = fore_angle + if(wrist) + wrist_at = end + var/hand_x = fist[1] - end[1] + var/hand_y = fist[2] - end[2] + if(hand_x * hand_x + hand_y * hand_y > 0.09) + hand_angle = arctan(hand_x, hand_y) + else + wrist_at = list(fist[1] - 0.5 * cos(fore_angle), fist[2] - 0.5 * sin(fore_angle)) + snap["[arm.id]u"] = arm.upper.span(shoulder, elbow) + snap["[arm.id]f"] = arm.fore.span(elbow, wrist_at) + snap["[arm.id]h"] = arm.hand.pin(fist, hand_angle) + return fist + +/// Where the blood starts: the throat as he is held, pixels from the middle of his tile. +/datum/hv_knife_exec_vis/proc/throat_spot() + var/list/spot = hv_ke_body_point(vic_origin, hv_ke_body_matrix(vic_base, victim_pose(HV_KNIFE_EXECUTION_WINDUP, -1)), throat) + return list(spot[1] - 16, spot[2] - 16) + +// ---- Playing ---- + +/// Keys for play(): each list(deciseconds since the key before, since, after). +/datum/hv_knife_exec_vis/proc/keys_at(list/moments, after_cut) + var/list/keys = list() + var/last = moments[1] + for(var/moment in moments) + if(after_cut) + keys[++keys.len] = list(moment - last, HV_KNIFE_EXECUTION_WINDUP, moment) + else + keys[++keys.len] = list(moment - last, moment, -1) + last = moment + return keys + +/// The wind-up: the grab, then the hold with the victim's jerks, then (should the cut never come) everything back. +/// The hold is kept well past the wind-up: on a lagging server the cut comes late by a client's clock. +/datum/hv_knife_exec_vis/proc/windup_keys() + var/list/keys = keys_at(list(0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 6, 6.5, 7.5, 8, 8.5, 9.5, 10.5, 11, 12, 12.5, 13, 14, HV_KNIFE_EXECUTION_WINDUP + 3 SECONDS), FALSE) + keys[++keys.len] = list(HV_VIS_KNIFE_ABORT_TIME, 0, -1) + return keys + +/// Tweens everything through `keys`, in step: each body and piece gets the same moments with straight-line steps +/// between them, so what holds what stays together in every frame. +/datum/hv_knife_exec_vis/proc/play(list/keys, attacker_side = TRUE, victim_side = TRUE) + var/list/snaps = list() + for(var/list/key as anything in keys) + snaps[++snaps.len] = snapshot(key[2], key[3]) + if(attacker_side && !attacker_done) + play_on(attacker, "A", keys, snaps, att_base) + for(var/id in arms) + var/datum/hv_knife_exec_arm/arm = arms[id] + if(arm.on_victim) + continue + play_on(arm.upper, "[id]u", keys, snaps) + play_on(arm.fore, "[id]f", keys, snaps) + play_on(arm.hand, "[id]h", keys, snaps) + if(blade) + play_on(blade, "blade", keys, snaps) + if(victim_side && !victim_done) + if(!victim_held) + play_on(victim, "V", keys, snaps, vic_base) + var/datum/hv_knife_exec_arm/own = arms["v"] + if(own) + play_on(own.upper, "vu", keys, snaps) + play_on(own.fore, "vf", keys, snaps) + play_on(own.hand, "vh", keys, snaps) + +/// One thing's tween through `keys`, on its plain animation sequence. A body's ends on `rest`, its real transform. +/datum/hv_knife_exec_vis/proc/play_on(atom/movable/thing, name, list/keys, list/snaps, matrix/rest) + if(QDELETED(thing)) + return + for(var/i in 1 to length(keys)) + var/list/key = keys[i] + var/list/snap = snaps[i] + var/matrix/pose = snap[name] + if(i > 1) + animate(transform = pose, time = key[1], flags = ANIMATION_LINEAR_TRANSFORM) + else + animate(thing, transform = pose, time = key[1], flags = ANIMATION_LINEAR_TRANSFORM) + if(rest) + animate(transform = rest, time = 0) + +/// Puts a body straight back on its real transform, whatever part of the move it was in. +/datum/hv_knife_exec_vis/proc/settle(mob/living/body) + if(!QDELETED(body)) + animate(body, transform = matrix(body.transform), time = 1) + +// ---- The cut, the let-go, the ends ---- + +/// The cut landed. `was_standing`, `pre_pixel_y` and `pre_base` are the victim as he stood just before it. +/datum/hv_knife_exec_vis/proc/cut(was_standing, pre_pixel_y, matrix/pre_base) + if(cut_time >= 0 || attacker_done) + return + cut_time = world.time + var/let_go = HV_VIS_KNIFE_CUT_TIME + HV_VIS_KNIFE_CUT_HOLD + var/on_his_feet = !QDELETED(victim) && victim.stat != DEAD && victim.body_position == STANDING_UP && victim.dir == facing + if(on_his_feet && !victim_done) + victim_hunches = TRUE + else + // He is going down (tg's fall) or already gone: his arm drops, and he is drawn held up until the blade is through. + victim_held = TRUE + end_victim_arm() + if(!QDELETED(victim)) + if(was_standing && victim.body_position == LYING_DOWN && victim.hv_vis_can_hold_fall()) + var/matrix/held_up = hv_ke_body_matrix(pre_base, victim_pose(HV_KNIFE_EXECUTION_WINDUP, -1)) + victim.hv_vis_play_over(list( + list(pre_pixel_y, held_up, 0, LINEAR_EASING), + list(pre_pixel_y, held_up, let_go, LINEAR_EASING), + list(victim.pixel_y, matrix(victim.transform), 3, QUAD_EASING|EASE_IN), + )) + else + settle(victim) + victim_done = TRUE + + var/list/attacker_moments = list(0, 0.5, 1, 1.5, 2, 2.5, let_go) + for(var/i in 1 to 8) + attacker_moments += let_go + i * HV_VIS_KNIFE_RELEASE_TIME / 8 + play(keys_at(attacker_moments, TRUE), TRUE, FALSE) + addtimer(CALLBACK(src, PROC_REF(end_attacker)), let_go + HV_VIS_KNIFE_RELEASE_TIME, TIMER_DELETE_ME) + if(blade && !isnull(blade_release_layer)) + addtimer(VARSET_CALLBACK(blade, layer, blade_release_layer), let_go, TIMER_DELETE_ME) + + if(victim_hunches) + var/list/victim_moments = list(0, 0.5, 1, 1.5, 2, 2.5, let_go) + for(var/i in 1 to 6) + victim_moments += let_go + i * 0.5 + for(var/i in 0 to 4) + victim_moments += HV_VIS_KNIFE_HUNCH_END + i * HV_VIS_KNIFE_HUNCH_OUT / 4 + for(var/i in 0 to 4) + victim_moments += HV_VIS_KNIFE_CLUTCH_END + i * HV_VIS_KNIFE_CLUTCH_OUT / 4 + play(keys_at(victim_moments, TRUE), FALSE, TRUE) + addtimer(CALLBACK(src, PROC_REF(end_victim)), HV_VIS_KNIFE_CLUTCH_END + HV_VIS_KNIFE_CLUTCH_OUT, TIMER_DELETE_ME) + +/// The wind-up broke: everything eases back from where it has got to. +/datum/hv_knife_exec_vis/proc/abort() + if(cut_time >= 0 || aborting) + return + aborting = TRUE + if(attacker_done && victim_done) + qdel(src) + return + var/since = min(world.time - started, HV_KNIFE_EXECUTION_WINDUP) + if(QDELETED(victim) || victim.body_position != STANDING_UP) + // He is gone or going down: tg has his transform now. + end_victim_arm() + victim_done = TRUE + else if(victim.dir != facing || get_turf(victim) != vic_turf) + // His own stand-in arm was drawn for the way he faced, where he stood. + end_victim_arm() + if(!isnull(blade_release_layer) && blade) + blade.layer = blade_release_layer + var/step_time = HV_VIS_KNIFE_ABORT_TIME / 4 + var/list/keys = list( + list(0, since, -1), + list(step_time, since * 0.7, -1), + list(step_time, since * 0.4, -1), + list(step_time, since * 0.15, -1), + list(step_time, 0, -1), + ) + play(keys) + QDEL_IN(src, HV_VIS_KNIFE_ABORT_TIME) + +/// The attacker's arms, knife and step are over: his real arms and held knife show again. +/datum/hv_knife_exec_vis/proc/end_attacker(at_once = FALSE) + if(attacker_done) + return + attacker_done = TRUE + for(var/id in arms) + var/datum/hv_knife_exec_arm/arm = arms[id] + if(arm.on_victim) + continue + arms -= id + qdel(arm) + QDEL_NULL(blade) + if(!QDELETED(attacker)) + for(var/name in att_filters) + attacker.remove_filter(name) + if(att_patch) + attacker.cut_overlay(att_patch) + if(!isnull(att_layer) && attacker.layer == HV_VIS_KNIFE_ATTACKER_LAYER) + attacker.layer = attacker.body_position == LYING_DOWN ? LYING_MOB_LAYER : att_layer + if(at_once) + settle(attacker) + att_filters = list() + att_patch = null + att_layer = null + if(knife && !QDELETED(knife)) + knife.hv_vis_restore_held_sprite() + if(victim_done && !QDELETED(src) && !at_once) + qdel(src) + +/// The victim's own stand-in arm goes; his real one shows again. +/datum/hv_knife_exec_vis/proc/end_victim_arm() + var/datum/hv_knife_exec_arm/own = arms["v"] + if(own) + arms -= "v" + qdel(own) + if(!QDELETED(victim)) + for(var/name in vic_filters) + victim.remove_filter(name) + if(vic_patch) + victim.cut_overlay(vic_patch) + vic_filters = list() + vic_patch = null + +/// The victim's side is over. +/datum/hv_knife_exec_vis/proc/end_victim(at_once = FALSE) + if(victim_done) + return + victim_done = TRUE + end_victim_arm() + if(at_once && !victim_held) + settle(victim) + if(attacker_done && !QDELETED(src) && !at_once) + qdel(src) + +// ---- Blood ---- + +/// A short jet of blood off the front of the neck, the way the victim faces. +/obj/effect/temp_visual/hv_throat_spurt + name = "arterial spray" + icon = HV_BLOOD_SPRAY_ICON + icon_state = "splatter_greyscale" + plane = GAME_PLANE + layer = HV_VIS_KNIFE_VICTIM_ARM_LAYER + 0.01 + appearance_flags = PIXEL_SCALE + randomdir = FALSE + duration = 4 + +/obj/effect/temp_visual/hv_throat_spurt/Initialize(mapload, throat_w = 0, throat_z = 0, spray_dir = SOUTH, blood_color = BLOOD_COLOR_RED, strength = 2) + . = ..() + setDir(spray_dir || SOUTH) + if(dir == NORTH) + layer = HV_VIS_KNIFE_UNDER_LAYER + color = blood_color + var/dx = HV_VIS_DX(dir) + var/dy = HV_VIS_DY(dir) + var/start_reach = 9 + var/mid_reach = strength >= 2 ? 22 : 18 + var/end_reach = strength >= 2 ? 30 : 24 + var/start_scale = strength >= 2 ? 0.40 : 0.32 + var/mid_scale = strength >= 2 ? 0.66 : 0.50 + var/end_scale = strength >= 2 ? 0.74 : 0.56 + var/matrix/start = matrix() + start.Scale(start_scale, start_scale) + start.Translate(throat_w + dx * start_reach, throat_z + dy * start_reach) + transform = start + var/matrix/mid_mat = matrix() + mid_mat.Scale(mid_scale, mid_scale) + mid_mat.Translate(throat_w + dx * mid_reach, throat_z + dy * mid_reach) + var/matrix/end_mat = matrix() + end_mat.Scale(end_scale, end_scale) + end_mat.Translate(throat_w + dx * end_reach, throat_z + dy * end_reach) + animate(src, transform = mid_mat, time = 2.2, easing = QUAD_EASING|EASE_OUT) + animate(transform = end_mat, alpha = 0, time = 1.8, easing = LINEAR_EASING) diff --git a/voidcrew/modules/npc_ships/code/admin_verbs.dm b/voidcrew/modules/npc_ships/code/admin_verbs.dm index c62568887a6..04e08c76142 100644 --- a/voidcrew/modules/npc_ships/code/admin_verbs.dm +++ b/voidcrew/modules/npc_ships/code/admin_verbs.dm @@ -281,6 +281,14 @@ ADMIN_VERB(force_z_level_active, R_DEBUG, "Force Z-Level Active", "Keep a z-leve message_admins("[key_name_admin(user)] forced z-level [z_level] active for AI debugging.") BLACKBOX_LOG_ADMIN_VERB("Force Z-Level Active") +// tg idles an AI unless a living mob with a client is in its nearby grid cells. A ghost isn't living and the +// activator dummy has no client, so on a forced-active level the AI would sit idle and never plan. +/datum/ai_controller/should_idle() + var/turf/pawn_turf = get_turf(pawn) + if(pawn_turf && GLOB.z_level_activator_dummies["[pawn_turf.z]"]) + return FALSE + return ..() + /// Global list of room visualization overlays (ship_ref -> list of overlay images) GLOBAL_LIST_EMPTY(room_visualization_overlays) diff --git a/voidcrew/modules/stealth/scav_camera.dm b/voidcrew/modules/stealth/scav_camera.dm new file mode 100644 index 00000000000..37a2a172a87 --- /dev/null +++ b/voidcrew/modules/stealth/scav_camera.dm @@ -0,0 +1,404 @@ +/** + * # Scav den cameras (owner decision 10) + * + * A wall camera that sweeps a visible cone back and forth across the room in front of it. A player caught in the cone, + * in light (or right under it), fills its notice; while it fills the camera stops and follows them and the cone turns + * amber. Full, it sounds the compound's siren and the den's guards answer as they answer any alarm (stealth_noise() at + * the spot, so the nearest few run there and search, the rest hold wary and the lookouts call it in on the radio). + * + * It sees by the guards' rules: dark tiles hide you past one tile, lockers and boxes hide you, cloaks hide you, and a + * scav disguise of fatigues and mask passes, except in a room marked off limits (stealth_restricted). It never sees + * through walls (can_see()). The cone is drawn on the lighting visual plane and lights nothing: what it shows is where + * it looks, nothing more. + * + * Players can EMP it (off for a while), break it (it has an integrity like any machine) or cut its feed with + * wirecutters (from beside it: the tile under it is in its cone). The guards' skill profile for the den's zone sets + * how fast its notice fills (decision 38). + * + * It runs on SSfastprocess, and only while a player is on its level; otherwise it stands still and costs nothing. + */ + +/// Sweeping its arc +#define SCAV_CAM_SCAN 1 +/// Holding on someone while its notice fills +#define SCAV_CAM_TRACK 2 +/// Siren going +#define SCAV_CAM_ALARM 3 +/// EMP'd, cut or broken +#define SCAV_CAM_OFF 4 + +/// Seconds a camera at yellow skill takes to fill on someone in plain view +#define SCAV_CAM_FILL_TIME 1.5 +/// How much faster it fills within this many tiles +#define SCAV_CAM_NEAR_RANGE 2 +#define SCAV_CAM_NEAR_MULT 3 +/// Notice lost per second with nobody in view +#define SCAV_CAM_DECAY 0.5 +/// Degrees a second it turns to follow someone +#define SCAV_CAM_TRACK_SPEED 120 +/// How long the siren runs +#define SCAV_CAM_ALARM_TIME (12 SECONDS) +/// Time between two alarms from one camera +#define SCAV_CAM_ALARM_COOLDOWN (30 SECONDS) +/// After losing someone, how long it stays on the spot before it sweeps again +#define SCAV_CAM_LOST_HOLD (2 SECONDS) +/// Pause at each end of the sweep +#define SCAV_CAM_END_PAUSE (1 SECONDS) +/// Cone colours: sweeping, following someone, siren +#define SCAV_CAM_COLOR_SCAN "#a8d4ff" +#define SCAV_CAM_COLOR_TRACK "#ffb347" +#define SCAV_CAM_COLOR_ALARM "#ff3b30" +/// How the drawn cone is widened to match the view (the beam icon is about 15 degrees each side) +#define SCAV_CAM_CONE_SCALE 1.25 +/// Pixels back toward the wall the cone starts from (the lens) +#define SCAV_CAM_LENS_BACK 12 + +/obj/machinery/scav_camera + name = "security camera" + desc = "A scuffed camera on a swivel mount. A wire runs from it into the wall." + icon = 'icons/obj/machines/camera.dmi' + icon_state = "camera" + base_icon_state = "camera" + layer = WALL_OBJ_LAYER + use_power = NO_POWER_USE + subsystem_type = /datum/controller/subsystem/processing/fastprocess + anchored = TRUE + density = FALSE + max_integrity = 60 + integrity_failure = 0.5 + armor_type = /datum/armor/machinery_camera + /// Degrees each side of its facing that it sweeps + var/sweep = 50 + /// Degrees clockwise its mount is turned from straight out of its wall (a corner camera looks along both corridors) + var/facing_offset = 0 + /// Degrees each side of its aim that it sees + var/view_half = 18 + /// Tiles it sees + var/view_range = 5 + /// Seconds from one end of the sweep to the other + var/sweep_time = 4 + /// Its aim now, degrees clockwise from north + var/aim = 0 + /// Which way it is sweeping: 1 clockwise, -1 back + var/heading = 1 + /// SCAV_CAM_* + var/cam_state = SCAV_CAM_SCAN + /// 0 to 1: how sure it is about whoever it is following + var/notice = 0 + /// Who it is following, if anyone + var/datum/weakref/watched + /// world.time it last saw them + var/last_seen_at = 0 + /// world.time the sweep resumes after a pause at its end + var/paused_until = 0 + /// world.time the siren stops + var/alarm_until = 0 + /// world.time it may raise the alarm again + var/alarm_ready_at = 0 + /// world.time an EMP wears off + var/emp_until = 0 + /// Its feed is cut for good (wirecutters) + var/feed_cut = FALSE + /// The drawn cone + var/obj/effect/abstract/scav_camera_cone/cone + /// Weakref to its den's guards, once found + var/datum/weakref/group_ref + /// The guards' skill for its zone, once worked out + var/datum/stealth_skill/profile + +MAPPING_DIRECTIONAL_HELPERS(/obj/machinery/scav_camera, 0) + +/obj/machinery/scav_camera/Initialize(mapload) + . = ..() + aim = scav_cam_facing() + cone = new(src) + vis_contents += cone + SET_PLANE_EXPLICIT(cone, O_LIGHTING_VISUAL_PLANE, src) + scav_cam_draw(TRUE) + +/obj/machinery/scav_camera/Destroy() + if(cone) + vis_contents -= cone + QDEL_NULL(cone) + watched = null + group_ref = null + profile = null + return ..() + +/// The way it looks out from its wall, in degrees clockwise from north (a camera hung on the north wall faces south) +/obj/machinery/scav_camera/proc/scav_cam_facing() + return SIMPLIFY_DEGREES(dir2angle(REVERSE_DIR(dir)) + facing_offset) + +/obj/machinery/scav_camera/examine(mob/user) + . = ..() + if(cam_state == SCAV_CAM_OFF) + . += span_notice(feed_cut ? "Its wire hangs cut." : "It's dark.") + +/obj/machinery/scav_camera/update_icon_state() + if(machine_stat & BROKEN) + icon_state = "[base_icon_state]_off" + else if(cam_state == SCAV_CAM_OFF) + icon_state = "[base_icon_state]_[emp_until > world.time ? "emp" : "off"]" + else + icon_state = "[base_icon_state][cam_state == SCAV_CAM_SCAN ? "" : "_in_use"]" + return ..() + +/obj/machinery/scav_camera/atom_break(damage_flag) + . = ..() + scav_cam_off() + +/obj/machinery/scav_camera/emp_act(severity) + . = ..() + if(. & EMP_PROTECT_SELF) + return + emp_until = max(emp_until, world.time + (severity == EMP_LIGHT ? 30 SECONDS : 60 SECONDS)) + scav_cam_off() + +/obj/machinery/scav_camera/wirecutter_act(mob/living/user, obj/item/tool) + if(feed_cut || (machine_stat & BROKEN)) + return ITEM_INTERACT_BLOCKING + balloon_alert(user, "cutting the feed...") + if(!tool.use_tool(src, user, 3 SECONDS, volume = 30)) + return ITEM_INTERACT_BLOCKING + if(feed_cut) + return ITEM_INTERACT_BLOCKING + feed_cut = TRUE + user.log_message("cut the feed of [src] at [AREACOORD(src)].", LOG_GAME) + balloon_alert(user, "feed cut") + scav_cam_off() + return ITEM_INTERACT_SUCCESS + +/// Stops it where it is and hides its cone. +/obj/machinery/scav_camera/proc/scav_cam_off() + cam_state = SCAV_CAM_OFF + notice = 0 + watched = null + if(cone) + cone.alpha = 0 + update_appearance(UPDATE_ICON_STATE) + +/// Its den's guards, or null when there are none in reach. +/obj/machinery/scav_camera/proc/scav_cam_group() + var/datum/stealth_group/group = group_ref?.resolve() + if(!QDELETED(group)) + return group + group = stealth_group_for(get_turf(src)) + group_ref = group ? WEAKREF(group) : null + return group + +/obj/machinery/scav_camera/process(seconds_per_tick) + var/turf/eye = get_turf(src) + if(isnull(eye)) + return + // Nobody to play for: it stands still with its level. + if(eye.z > length(SSmobs.clients_by_zlevel) || !length(SSmobs.clients_by_zlevel[eye.z])) + return + if(cam_state == SCAV_CAM_OFF) + if(feed_cut || (machine_stat & BROKEN) || emp_until > world.time) + return + cam_state = SCAV_CAM_SCAN + aim = scav_cam_facing() + update_appearance(UPDATE_ICON_STATE) + scav_cam_draw(TRUE) + if(isnull(profile)) + profile = stealth_skill_of(stealth_skill_type_for_zone(stealth_zone_of(eye))) + + var/mob/living/target = watched?.resolve() + if(!QDELETED(target) && !scav_cam_sees(target, eye)) + target = null + if(isnull(target)) + target = scav_cam_find(eye) + + if(target) + watched = WEAKREF(target) + last_seen_at = world.time + scav_cam_follow(target, eye, seconds_per_tick) + if(cam_state == SCAV_CAM_SCAN) + cam_state = SCAV_CAM_TRACK + playsound(src, 'sound/machines/beep/twobeep.ogg', 30, FALSE, -3) + update_appearance(UPDATE_ICON_STATE) + if(cam_state == SCAV_CAM_TRACK) + var/rate = (profile?.notice_rate || 1) / SCAV_CAM_FILL_TIME + if(get_dist(eye, target) <= SCAV_CAM_NEAR_RANGE) + rate *= SCAV_CAM_NEAR_MULT + notice = min(1, notice + rate * seconds_per_tick) + if(notice >= 1 && world.time >= alarm_ready_at) + scav_cam_alarm(target) + else + notice = max(0, notice - SCAV_CAM_DECAY * seconds_per_tick) + if(cam_state == SCAV_CAM_TRACK && !notice && world.time - last_seen_at > SCAV_CAM_LOST_HOLD) + cam_state = SCAV_CAM_SCAN + watched = null + update_appearance(UPDATE_ICON_STATE) + + if(cam_state == SCAV_CAM_ALARM && world.time >= alarm_until) + cam_state = target ? SCAV_CAM_TRACK : SCAV_CAM_SCAN + notice = 0 + update_appearance(UPDATE_ICON_STATE) + if(cam_state == SCAV_CAM_SCAN) + scav_cam_sweep(seconds_per_tick) + scav_cam_draw() + +/// Moves its aim along the sweep, pausing at each end. +/obj/machinery/scav_camera/proc/scav_cam_sweep(seconds_per_tick) + if(world.time < paused_until) + return + var/facing = scav_cam_facing() + var/offset = closer_angle_difference(facing, aim) + offset += heading * (2 * sweep / max(sweep_time, 0.5)) * seconds_per_tick + if(abs(offset) >= sweep) + offset = clamp(offset, -sweep, sweep) + heading = -heading + paused_until = world.time + SCAV_CAM_END_PAUSE + aim = SIMPLIFY_DEGREES(facing + offset) + +/// Turns its aim toward `target`, no further round than a little past its sweep. +/obj/machinery/scav_camera/proc/scav_cam_follow(mob/living/target, turf/eye, seconds_per_tick) + var/turf/spot = get_turf(target) + var/wanted = delta_to_angle(spot.x - eye.x, spot.y - eye.y) + var/turn = closer_angle_difference(aim, wanted) + var/step = SCAV_CAM_TRACK_SPEED * seconds_per_tick + aim = SIMPLIFY_DEGREES(aim + clamp(turn, -step, step)) + var/facing = scav_cam_facing() + var/offset = closer_angle_difference(facing, aim) + if(abs(offset) > sweep + view_half) + aim = SIMPLIFY_DEGREES(facing + clamp(offset, -(sweep + view_half), sweep + view_half)) + +/// The nearest person (or player-driven mob) it sees now, or null. +/obj/machinery/scav_camera/proc/scav_cam_find(turf/eye) + var/mob/living/best + var/best_dist = INFINITY + for(var/mob/living/found in SSspatial_grid.orthogonal_range_search(eye, SPATIAL_GRID_CONTENTS_TYPE_HEARING, view_range)) + // People and anyone a player drives; not rats and roaches. + if(!found.ckey && !ishuman(found)) + continue + var/dist = get_dist(eye, found) + if(dist >= best_dist || !scav_cam_sees(found, eye)) + continue + best = found + best_dist = dist + return best + +/// Whether it sees `who` from `eye` now. +/obj/machinery/scav_camera/proc/scav_cam_sees(mob/living/who, turf/eye) + if(!istype(who) || who.stat == DEAD || (FACTION_SCAV in who.faction)) + return FALSE + var/turf/spot = get_turf(who) + if(isnull(spot) || spot.z != eye.z || spot == eye) + return FALSE + var/dist = get_dist(eye, spot) + if(dist > view_range) + return FALSE + if(abs(closer_angle_difference(aim, delta_to_angle(spot.x - eye.x, spot.y - eye.y))) > view_half) + return FALSE + if(stealth_shell_of(who) || stealth_is_cloaked(who)) + return FALSE + if(dist > 1 && stealth_tile_is_dark(spot)) + return FALSE + if(!can_see(eye, spot, view_range)) + return FALSE + return !scav_cam_waves_through(who, spot) + +/// Whether a scav disguise gets `who` past it: fatigues and a mask, anywhere but an off-limits room (a pass excuses +/// one that allows it). +/obj/machinery/scav_camera/proc/scav_cam_waves_through(mob/living/who, turf/spot) + var/pieces = stealth_disguise_of(who) + if(stealth_disguise_stage(pieces) < 3) + return FALSE + var/datum/stealth_group/group = scav_cam_group() + var/list/off_limits = group?.off_limits() + if(isnull(off_limits) || isnull(off_limits[spot])) + return TRUE + return off_limits[spot] && (pieces & STEALTH_PIECE_ID) + +/// Sounds the siren and sends the guards to `target`'s spot. +/obj/machinery/scav_camera/proc/scav_cam_alarm(mob/living/target) + cam_state = SCAV_CAM_ALARM + alarm_until = world.time + SCAV_CAM_ALARM_TIME + alarm_ready_at = world.time + SCAV_CAM_ALARM_COOLDOWN + update_appearance(UPDATE_ICON_STATE) + playsound(src, 'sound/effects/siren.ogg', 70, FALSE, 6) + var/turf/spot = get_turf(target) + target.log_message("was seen by [src] at [AREACOORD(spot)], which sounded the den's alarm.", LOG_GAME) + var/datum/stealth_group/group = scav_cam_group() + if(group) + // Wired to the whole compound: every guard of the den hears it, as if it went off where they were seen. + stealth_noise(spot, STEALTH_NOISE_BLAST, STEALTH_GROUP_RADIUS, target, group) + +/// Points and colours the cone to match its aim and state. `instant` skips the glide. +/obj/machinery/scav_camera/proc/scav_cam_draw(instant = FALSE) + if(isnull(cone)) + return + if(cam_state == SCAV_CAM_OFF) + cone.alpha = 0 + return + var/wanted_color = cam_state == SCAV_CAM_SCAN ? SCAV_CAM_COLOR_SCAN : (cam_state == SCAV_CAM_TRACK ? SCAV_CAM_COLOR_TRACK : SCAV_CAM_COLOR_ALARM) + if(cone.color != wanted_color) + cone.color = wanted_color + var/wanted_alpha = cam_state == SCAV_CAM_ALARM ? (round(world.time / (3 DECISECONDS)) % 2 ? 255 : 120) : 220 + cone.alpha = wanted_alpha + var/state = "beam_[scav_cam_reach()]" + if(cone.icon_state != state) + cone.icon_state = state + var/matrix/pointing = matrix() + pointing.Scale(SCAV_CAM_CONE_SCALE, 1) + pointing.Translate(0, STEALTH_BEAM_PIVOT - SCAV_CAM_LENS_BACK) + pointing.Turn(aim) + // The lens sits back toward the wall it hangs on. + pointing.Translate(0, -STEALTH_BEAM_PIVOT) + if(instant) + animate(cone, transform = pointing, time = 0) + else + // Linear: a turned and stretched matrix tweened by angle can flip and swing the cone the long way round. + animate(cone, transform = pointing, time = 2 DECISECONDS, flags = ANIMATION_LINEAR_TRANSFORM) + +/// How long the drawn cone is along its aim, in quarter tiles: to the first wall or solid door, at most the beam's full length. +/obj/machinery/scav_camera/proc/scav_cam_reach() + var/turf/eye = get_turf(src) + if(isnull(eye)) + return STEALTH_BEAM_LENGTHS + var/dx = sin(aim) + var/dy = cos(aim) + var/lens = SCAV_CAM_LENS_BACK / 32 + for(var/step in 1 to STEALTH_BEAM_LENGTHS) + // a step is a quarter tile, the beam icon's own unit + var/along = step / 4 - lens + var/turf/at = locate(eye.x + round(dx * along, 1), eye.y + round(dy * along, 1), eye.z) + if(isnull(at) || (at != eye && IS_OPAQUE_TURF(at))) + return clamp(step, 1, STEALTH_BEAM_LENGTHS) + return STEALTH_BEAM_LENGTHS + +/// The drawn cone of a den camera: light on the lighting visual plane, lighting nothing. +/obj/effect/abstract/scav_camera_cone + name = "camera sweep" + // The guards' flashlight cone (stealth_beam.dmi) made white and about 4x as opaque, so a tint shows it. + icon = 'voidcrew/icons/effects/scav_camera_cone.dmi' + icon_state = "beam_22" + mouse_opacity = MOUSE_OPACITY_TRANSPARENT + anchored = TRUE + blocks_emissive = EMISSIVE_BLOCK_NONE + blend_mode = BLEND_ADD + appearance_flags = RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM | KEEP_APART | PIXEL_SCALE + vis_flags = NONE + // The icon's bottom middle on the camera tile's centre + pixel_x = -48 + pixel_y = 16 + +#undef SCAV_CAM_SCAN +#undef SCAV_CAM_TRACK +#undef SCAV_CAM_ALARM +#undef SCAV_CAM_OFF +#undef SCAV_CAM_FILL_TIME +#undef SCAV_CAM_NEAR_RANGE +#undef SCAV_CAM_NEAR_MULT +#undef SCAV_CAM_DECAY +#undef SCAV_CAM_TRACK_SPEED +#undef SCAV_CAM_ALARM_TIME +#undef SCAV_CAM_ALARM_COOLDOWN +#undef SCAV_CAM_LOST_HOLD +#undef SCAV_CAM_END_PAUSE +#undef SCAV_CAM_COLOR_SCAN +#undef SCAV_CAM_COLOR_TRACK +#undef SCAV_CAM_COLOR_ALARM +#undef SCAV_CAM_CONE_SCALE +#undef SCAV_CAM_LENS_BACK diff --git a/voidcrew/modules/stealth/scav_den.dm b/voidcrew/modules/stealth/scav_den.dm new file mode 100644 index 00000000000..372c31610f5 --- /dev/null +++ b/voidcrew/modules/stealth/scav_den.dm @@ -0,0 +1,376 @@ +/** + * # The scav den (stealth step 4, owner decisions 3, 6, 10, 11, 21, 38) + * + * A compound of organ and cyberware harvesters dug into an asteroid on the contested lanes. It is a rare space ruin: + * it never seeds by itself, and the only road to it is a rumor chart bought from an outpost trader and revealed from + * the helm (rumor_charts.dm), like every other named tip. One den is on the overmap at a time: while one is out there + * the tip is off the shelf and a sealed chart can't be revealed (it stays sealed and can be revealed once that den is + * cleaned out). A den nobody docks at within an hour of its reveal leaves the overmap, so an unvisited one can't hold + * the slot all round. + * + * The den's guards are the stealth guards of scav_guards.dm with names of their own, so their friends can call them + * by name on the radio and over a body. Their skill comes from the den's zone (decision 38): a den revealed in the + * contested lanes is yellow. The boss, a lookout, carries the only vault pass. The vault's crate rolls cyberware by + * the den's zone, plus one piece of stealth gear from scav_vault_stealth_loot() (the matte knife here; other modules add theirs). + * + * Cameras: scav_camera.dm. + */ + +// ===== The ruin ===== + +/datum/map_template/ruin/space/rare/scav_den + id = "rare_scav_den" + suffix = "rare_scav_den.dmm" + name = "Scav Chop Shop" + description = "A scav crew's den dug into a hollow rock. They take spacers apart for their organs and their chrome, and the best of it sits in the boss's vault." + +/// The live den on the overmap, if there is one +/proc/scav_den_on_map() + for(var/obj/structure/overmap/space_ruin/ruin as anything in GLOB.space_ruin_signals) + if(!QDELETED(ruin) && istype(ruin.ruin_template, /datum/map_template/ruin/space/rare/scav_den)) + return ruin + return null + +// ===== The tip ===== + +/datum/shop_sku/ruin_chart/scav_den + name = "contested-lane tip: scav chop shop" + desc = "A scav crew working out of a hollow rock, buying people off the lanes and selling them back in pieces. They keep their best chrome in the boss's vault. Uploaded sealed to your helm." + price_vouchers = 1 + price_credits = 3600 + spawn_zone = ZONE_YELLOW + ruin_template_path = /datum/map_template/ruin/space/rare/scav_den + chart_type = /datum/rumor_chart/scav_den + rumor_name = "Scav chop shop" + rumor_desc = "Scavs in a hollow rock on the contested lanes, buying people and selling them back in pieces. The boss keeps the good chrome locked up." + +/datum/shop_sku/ruin_chart/scav_den/get_denial_reason(mob/living/user) + . = ..() + if(.) + return + if(scav_den_on_map()) + return "That crew's already been sold out. Wait for the dust to settle." + +/// A sealed den chart. It only opens while no other den is on the overmap. +/datum/rumor_chart/scav_den + +/datum/rumor_chart/scav_den/reveal(obj/structure/overmap/ship/ship) + if(scav_den_on_map()) + return null + . = ..() + if(.) + scav_den_claim(.) + +/// Sets up a den the moment it's revealed. +/proc/scav_den_claim(obj/structure/overmap/space_ruin/den) + // No contract may hold it on the chart: a held den would rebuild fresh (guards, vault and all) on the next visit. + den.mission_exclusive = TRUE + // A den nobody ever flies to would hold the one-den slot for the round: the scavs move on. + addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(scav_den_move_on), WEAKREF(den)), 60 MINUTES) + +/// Takes a revealed den off the overmap if nobody has docked at it (its interior was never built) in the hour since. +/proc/scav_den_move_on(datum/weakref/den_ref) + var/obj/structure/overmap/space_ruin/den = den_ref?.resolve() + if(QDELETED(den) || den.mapzone || den.loading || den.loaded) + return + log_mapping("Scav den '[den.name]' at ([den.x], [den.y]) was never visited and moved on.") + qdel(den) + +// ===== Guards with names ===== + +/// Den guards keep the random name their look gave them instead of their type's ("Scav Guard"), so the radio and +/// their friends can name them (stealth_first_name()). +/mob/living/carbon/human/npc/ruin/trooper/scav/den + npc_name = null + npc_outfit_table = /datum/human_npc_outfit_table/ruin/scav_den + +/mob/living/carbon/human/npc/ruin/trooper/scav/den/npc_dress(datum/human_npc_order/order) + . = ..() + scav_den_name_self() + scav_den_chrome_eyes() + +/mob/living/carbon/human/npc/ruin/trooper/scav/gunner/den + npc_name = null + npc_outfit_table = /datum/human_npc_outfit_table/ruin/scav_den/gunner + +/mob/living/carbon/human/npc/ruin/trooper/scav/gunner/den/npc_dress(datum/human_npc_order/order) + . = ..() + scav_den_name_self() + scav_den_chrome_eyes() + +/mob/living/carbon/human/npc/ruin/trooper/scav/lookout/den + npc_name = null + npc_outfit_table = /datum/human_npc_outfit_table/ruin/scav_den/gunner + +/mob/living/carbon/human/npc/ruin/trooper/scav/lookout/den/npc_dress(datum/human_npc_order/order) + . = ..() + scav_den_name_self() + scav_den_chrome_eyes() + +/// The den's boss: a lookout with the vault pass, dressed as the head harvester. +/mob/living/carbon/human/npc/ruin/trooper/scav/lookout/den/boss + npc_outfit_table = /datum/human_npc_outfit_table/ruin/scav_den/boss + +/mob/living/carbon/human/npc/ruin/trooper/scav/lookout/den/boss/npc_dress(datum/human_npc_order/order) + . = ..() + var/obj/item/card/id/card = wear_id + if(istype(card) && !istype(card, /obj/item/card/id/advanced/black/scav/vault)) + var/obj/item/card/id/vault_card = new /obj/item/card/id/advanced/black/scav/vault(src) + vault_card.registered_name = real_name + qdel(card) + equip_to_slot_or_del(vault_card, ITEM_SLOT_ID) + +/** + * Gives a den guard a person's name if its look left it without one. Its look (a random person) names it, and with + * npc_name null that name stays; its pass is made out to it. + */ +/mob/living/carbon/human/npc/proc/scav_den_name_self() + if(real_name && real_name != initial(name) && real_name != "Unknown") + return + fully_replace_character_name(real_name, generate_random_mob_name()) + var/obj/item/card/id/card = wear_id?.GetID() + if(istype(card, /obj/item/card/id/advanced/black/scav)) + card.registered_name = real_name + +/** + * Gives a den guard chrome eyes that glow red. tg's own robotic eyes (they flash and EMP like anyone's), recoloured; + * the glow is only drawn, it lights nothing. Behind glasses or a mask that hides the eyes it doesn't show. + */ +/mob/living/carbon/human/npc/proc/scav_den_chrome_eyes() + var/obj/item/organ/eyes/robotic/chrome = new() + chrome.eye_color_left = "#ff2a1a" + chrome.eye_color_right = "#ff2a1a" + chrome.overlay_ignore_lighting = TRUE + if(!chrome.Insert(src, special = TRUE, movement_flags = DELETE_IF_REPLACED)) + qdel(chrome) + return + update_body() + // A balaclava's eye holes don't line up with bare eyes: a masked guard without lenses gets the gang's red ones. + if(istype(wear_mask, /obj/item/clothing/mask/balaclava) && isnull(glasses)) + equip_to_slot_or_del(new /obj/item/clothing/glasses/red(src), ITEM_SLOT_EYES) + +// ===== The den guards' look ===== +// A chrome-mad harvester gang. The scavs' fatigues go under everything (scav_guards.dm), and every outfit leaves the +// mask slot free for the scav balaclava, so a guard still carries the disguise set (stealth_disguise.dm). The suits here +// are read into stealth_guard_suits(). Armour by zone never goes above the old sword and gunner tables. + +/// Rippers: leather and a knife, red lenses. +/datum/outfit/ruin_npc/scav_den + name = "Ruin NPC: den ripper" + uniform = /obj/item/clothing/under/syndicate/scav + suit = /obj/item/clothing/suit/jacket/leather/biker + shoes = /obj/item/clothing/shoes/jackboots + gloves = /obj/item/clothing/gloves/fingerless + glasses = /obj/item/clothing/glasses/red + r_hand = /obj/item/knife/combat/survival + +/datum/outfit/ruin_npc/scav_den/vest + name = "Ruin NPC: den ripper in plates" + suit = /obj/item/clothing/suit/armor/vest + r_hand = /obj/item/knife/combat + +/datum/outfit/ruin_npc/scav_den/vest/helmet + name = "Ruin NPC: den ripper, red zone" + head = /obj/item/clothing/head/helmet + l_pocket = /obj/item/reagent_containers/hypospray/medipen + +/// Harvesters: the ones who do the cutting. Bloodied waders and black gloves, and a cleaver or a bone saw; no lenses over the chrome. +/datum/outfit/ruin_npc/scav_den/butcher + name = "Ruin NPC: den harvester" + suit = /obj/item/clothing/suit/apron/waders + gloves = /obj/item/clothing/gloves/color/black + head = /obj/item/clothing/head/utility/surgerycap/black + glasses = null + r_hand = /obj/item/knife/butcher + +/datum/outfit/ruin_npc/scav_den/butcher/saw + name = "Ruin NPC: den harvester with a saw" + r_hand = /obj/item/circular_saw/cruel + +/datum/outfit/ruin_npc/scav_den/butcher/saw/red + name = "Ruin NPC: den harvester, red zone" + l_pocket = /obj/item/reagent_containers/hypospray/medipen + +/// Blood on the apron, the gloves and the blade. +/datum/outfit/ruin_npc/scav_den/butcher/post_equip(mob/living/carbon/human/user, visuals_only = FALSE) + . = ..() + var/list/blood = user.get_blood_dna_list() + if(!length(blood)) + return + for(var/obj/item/stained in list(user.gloves, user.wear_suit) + user.held_items) + stained.add_blood_DNA(blood) + user.update_clothing(ITEM_SLOT_GLOVES | ITEM_SLOT_OCLOTHING | ITEM_SLOT_HANDS) + +/// Gunners: a cheap Makarov, or a mini Uzi in the red zone. +/datum/outfit/ruin_npc/scav_den/gunner + name = "Ruin NPC: den gunner" + suit = /obj/item/clothing/suit/jacket/leather + r_hand = /obj/item/gun/ballistic/automatic/pistol + l_pocket = /obj/item/ammo_box/magazine/m9mm + r_pocket = /obj/item/ammo_box/magazine/m9mm + +/datum/outfit/ruin_npc/scav_den/gunner/vest + name = "Ruin NPC: den gunner in plates" + suit = /obj/item/clothing/suit/armor/vest + +/datum/outfit/ruin_npc/scav_den/gunner/vest/helmet + name = "Ruin NPC: den gunner, red zone" + head = /obj/item/clothing/head/helmet + r_hand = /obj/item/gun/ballistic/automatic/mini_uzi + l_pocket = /obj/item/ammo_box/magazine/uzim9mm + r_pocket = /obj/item/ammo_box/magazine/uzim9mm + +/// The head harvester: the butcher's apron with a pistol. +/datum/outfit/ruin_npc/scav_den/butcher/boss + name = "Ruin NPC: den head harvester" + r_hand = /obj/item/gun/ballistic/automatic/pistol + l_pocket = /obj/item/ammo_box/magazine/m9mm + r_pocket = /obj/item/ammo_box/magazine/m9mm + +/datum/outfit/ruin_npc/scav_den/butcher/boss/smg + name = "Ruin NPC: den head harvester, red zone" + r_hand = /obj/item/gun/ballistic/automatic/mini_uzi + l_pocket = /obj/item/ammo_box/magazine/uzim9mm + r_pocket = /obj/item/ammo_box/magazine/uzim9mm + +/// Den blades: rippers and harvesters, half and half. +/datum/human_npc_outfit_table/ruin/scav_den + green = list(/datum/outfit/ruin_npc/scav_den = 1, /datum/outfit/ruin_npc/scav_den/butcher = 1) + yellow = list(/datum/outfit/ruin_npc/scav_den/vest = 1, /datum/outfit/ruin_npc/scav_den/butcher/saw = 1) + red = list(/datum/outfit/ruin_npc/scav_den/vest/helmet = 1, /datum/outfit/ruin_npc/scav_den/butcher/saw/red = 1) + +/// Den guns: SMGs only in the red zone (the trooper weapon ladder). +/datum/human_npc_outfit_table/ruin/scav_den/gunner + green = list(/datum/outfit/ruin_npc/scav_den/gunner = 1) + yellow = list(/datum/outfit/ruin_npc/scav_den/gunner/vest = 1) + red = list(/datum/outfit/ruin_npc/scav_den/gunner/vest/helmet = 1) + +/datum/human_npc_outfit_table/ruin/scav_den/boss + green = list(/datum/outfit/ruin_npc/scav_den/butcher/boss = 1) + yellow = list(/datum/outfit/ruin_npc/scav_den/butcher/boss = 1) + red = list(/datum/outfit/ruin_npc/scav_den/butcher/boss/smg = 1) + +/obj/effect/spawner/human_npc/ruin/scav/den + name = "den guard spawner" + npc_type = /mob/living/carbon/human/npc/ruin/trooper/scav/den + +/obj/effect/spawner/human_npc/ruin/scav/den/gunner + name = "den gunner spawner" + npc_type = /mob/living/carbon/human/npc/ruin/trooper/scav/gunner/den + +/obj/effect/spawner/human_npc/ruin/scav/den/lookout + name = "den lookout spawner" + npc_type = /mob/living/carbon/human/npc/ruin/trooper/scav/lookout/den + +/obj/effect/spawner/human_npc/ruin/scav/den/boss + name = "den boss spawner" + npc_type = /mob/living/carbon/human/npc/ruin/trooper/scav/lookout/den/boss + +// ===== The vault ===== + +/// The boss's pass: the den's doors and the vault. +/obj/item/card/id/advanced/black/scav/vault + name = "scav pass" + desc = "A scratched black card on a cord, punched with a den's mark. This one has a second hole punched through it." + access = list(ACCESS_SCAV, ACCESS_SCAV_VAULT) + +/** + * The boss's crate. Rolls when first opened, by the zone of the den it was mapped in (moving it doesn't change it): + * cyberware the harvesters pulled or bought, more and better further out, and one piece of stealth gear when + * scav_vault_stealth_loot() has any. Everything in it can be found or bought elsewhere too. + */ +/obj/structure/closet/crate/secure/scav_vault + name = "chrome crate" + desc = "A heavy crate lined with foam. Somebody has scratched a tally of names into the lid." + icon_state = "weaponcrate" + base_icon_state = "weaponcrate" + req_access = list(ACCESS_SCAV_VAULT) + /// The turf it was mapped on: its zone is read there + var/turf/spawn_turf + /// Set once it has rolled + var/vault_rolled = FALSE + +/obj/structure/closet/crate/secure/scav_vault/Initialize(mapload) + spawn_turf = get_turf(src) + return ..() + +/obj/structure/closet/crate/secure/scav_vault/Destroy() + spawn_turf = null + return ..() + +/obj/structure/closet/crate/secure/scav_vault/PopulateContents() + . = ..() + if(vault_rolled) + return + vault_rolled = TRUE + var/zone = SSovermap_zones?.get_zone_type_anywhere(spawn_turf) || ZONE_GREEN + spawn_turf = null + scav_vault_roll(zone) + +/** + * The stealth-gear hook: typepath => weight of stealth gear a vault may pay, one piece per vault. Here only the matte + * knife. Other modules (the garrotte, the gun-fu chip) add theirs by overriding this proc on this type with `. = ..()` + * and adding entries to the list. + */ +/obj/structure/closet/crate/secure/scav_vault/proc/scav_vault_stealth_loot() + return list(/obj/item/knife/combat/matte = 1) + +/** + * Fills it with a den vault's take for `zone`: cyberware drawn without repeats (2 in green, 3 in yellow, 4 in red), + * the better shelf more often further out, and one stealth piece if there are any. Returns what it made. + */ +/obj/structure/closet/crate/secure/scav_vault/proc/scav_vault_roll(zone) + var/atom/destination = src + . = list() + var/list/street = list( + /obj/item/organ/cyberimp/cyberware/gecko = 4, + /obj/item/organ/cyberimp/cyberware/dermal_mesh = 4, + /obj/item/organ/cyberimp/cyberware/shock_coils = 4, + /obj/item/organ/cyberimp/cyberware/chromatic_dermis = 4, + /obj/item/organ/cyberimp/cyberware/cargo_cavity = 4, + /obj/item/organ/cyberimp/cyberware/second_wind = 4, + /obj/item/organ/cyberimp/arm/toolkit/cyberware/rockjaw = 4, + /obj/item/organ/cyberimp/arm/toolkit/cyberware/fixers = 4, + /obj/item/organ/eyes/robotic/cyberware/prospector = 3, + /obj/item/organ/heart/cybernetic = 3, + /obj/item/organ/liver/cybernetic/tier2 = 3, + /obj/item/organ/lungs/cybernetic/tier2 = 3, + ) + var/list/pro = list( + /obj/item/organ/cyberimp/cyberware/slipwire = 3, + /obj/item/organ/cyberimp/cyberware/slabskin = 3, + /obj/item/organ/cyberimp/cyberware/hemoglass = 3, + /obj/item/organ/cyberimp/cyberware/doppler = 3, + /obj/item/organ/cyberimp/cyberware/dead_channel = 3, + /obj/item/organ/eyes/robotic/cyberware/nightshade = 3, + /obj/item/organ/eyes/robotic/cyberware/deadeye = 3, + /obj/item/organ/cyberimp/arm/toolkit/cyberware/icepick = 3, + /obj/item/organ/cyberimp/arm/toolkit/cyberware/skyhook = 3, + /obj/item/organ/cyberimp/arm/toolkit/cyberware/angler = 3, + /obj/item/organ/cyberimp/cyberware/ghostskin = 2, + /obj/item/organ/cyberimp/cyberware/hopper = 2, + /obj/item/organ/cyberimp/cyberware/atlas = 2, + ) + var/draws = 2 + var/pro_chance = 25 + switch(zone) + if(ZONE_YELLOW) + draws = 3 + pro_chance = 40 + if(ZONE_RED) + draws = 4 + pro_chance = 60 + for(var/draw in 1 to draws) + var/list/shelf = (prob(pro_chance) && length(pro)) ? pro : street + if(!length(shelf)) + shelf = length(pro) ? pro : street + if(!length(shelf)) + break + var/picked = pick_weight(shelf) + shelf -= picked + . += new picked(destination) + var/list/stealth = scav_vault_stealth_loot() + if(length(stealth)) + var/stealth_path = pick_weight(stealth) + if(ispath(stealth_path, /atom/movable)) + . += new stealth_path(destination) diff --git a/voidcrew/modules/stealth/scav_guards.dm b/voidcrew/modules/stealth/scav_guards.dm new file mode 100644 index 00000000000..5840410ab52 --- /dev/null +++ b/voidcrew/modules/stealth/scav_guards.dm @@ -0,0 +1,154 @@ +/** + * # Scav den guards + * + * The first NPCs with the stealth controller (owner decisions 6 and 11). Placeholder dress until step 4 + * gives them their own look: the melee guard borrows the Syndicate sword table, the gunner the pistol one. + */ + +/datum/human_npc_voice/scav + lines = list( + RUIN_NPC_BARK_SPOT = list("There! Get 'em!", "Intruder!", "Got you now!", "Over here!"), + HUMAN_NPC_BARK_DOWNED = list("Ugh... I'm hit...", "Somebody..."), + HUMAN_NPC_BARK_RECOVER = list("Still here.", "That all?"), + HUMAN_NPC_BARK_CUFFED = list("You don't know who you're messing with."), + STEALTH_BARK_SUSPICIOUS = list("Hm?", "Who's there?", "Thought I saw something."), + STEALTH_BARK_GIVE_UP = list("Nothing.", "Jumpy tonight.", "Must be the rats."), + STEALTH_BARK_LOST = list("Lost them!", "Where'd they go?"), + STEALTH_BARK_SEARCH = list("Come on out.", "I know you're here."), + STEALTH_BARK_HIT_UNSEEN = list("Contact!", "Where's that coming from?"), + STEALTH_BARK_BODY = list("Man down!", "Who did this?"), + STEALTH_BARK_CHATTER = list("Shipment's late again.", "My feet are killing me.", "You hear that? No? Good.", "Radio check.", "Quiet tonight. I hate quiet."), + STEALTH_BARK_DOWNED = list("Got 'em.", "Stay down.", "That's handled."), + STEALTH_BARK_CLOSET_OPEN = list("Out you come.", "Thought so.", "Found you."), + STEALTH_BARK_CLOSET_GIVE_UP = list("Stay in there, then.", "Fine. Rot in there."), + STEALTH_BARK_HEARD = list("What was that?", "You hear that?", "Hm."), + STEALTH_BARK_HEARD_AGAIN = list("Again?", "That's twice now."), + STEALTH_BARK_GUNFIRE = list("Shots!", "That's gunfire!", "Shots, %SIDE% side!"), + STEALTH_BARK_HOLD = list("Stay put.", "Eyes open."), + STEALTH_BARK_HELP = list("Over here!", "Need a hand!"), + STEALTH_BARK_MISSING = list("%NAME%? ...%NAME%!", "Where's %NAME% got to?", "Should've been back by now."), + STEALTH_BARK_RADIO_REPORT = list("Checking something, %SIDE% side.", "Checking something."), + STEALTH_BARK_RADIO_ALARM = list("Contact, %SIDE% side! Get over here!", "Trouble, %SIDE% side!", "Trouble! Get over here!"), + STEALTH_BARK_RADIO_MISSING = list("%NAME%, come in.", "%NAME%'s not answering.", "Got one not answering."), + STEALTH_BARK_COPY = list("Copy.", "Moving.", "On my way."), + STEALTH_BARK_RADIO_DEAD = list("Radio's dead.", "Nothing but static."), + STEALTH_BARK_GREET = list("Evening.", "All quiet?", "Still breathing, then.", "Evening, %NAME%.", "You're late, %NAME%."), + STEALTH_BARK_SMOKE = list("Got a light?", "Spare a smoke?", "You owe me a smoke, %NAME%."), + STEALTH_BARK_CHALLENGE = list("Hold up. Let's see your card.", "Hey. You. Card.", "Stop there. Who are you with?"), + STEALTH_BARK_ID_PASS = list("Fine. Move along.", "All right. Go on.", "Go on, %NAME%."), + STEALTH_BARK_ID_FAIL = list("No card? Don't move.", "Card. Now.", "I said card."), + STEALTH_BARK_BLOWN = list("You're not one of us!", "That's not one of ours!", "Who the hell are you?"), + STEALTH_BARK_LIGHT = list("Whose light is that?", "Who's got a light on?", "Kill that light."), + STEALTH_BARK_LIGHT_DEAD = list("Light's dead.", "Come on. Work.", "Cheap junk."), + ) + emotes = list( + HUMAN_NPC_BARK_DOWNED = list("collapses."), + STEALTH_BARK_SUSPICIOUS = list("squints into the dark.", "turns, frowning."), + STEALTH_BARK_GIVE_UP = list("shrugs."), + STEALTH_BARK_SEARCH = list("checks behind a crate."), + STEALTH_BARK_HIT_UNSEEN = list("ducks."), + STEALTH_BARK_CHATTER = list("yawns.", "stretches."), + STEALTH_BARK_DOWNED = list("spits."), + STEALTH_BARK_HEARD = list("cocks their head.", "looks round."), + STEALTH_BARK_GUNFIRE = list("flinches."), + STEALTH_BARK_HOLD = list("shifts their grip."), + STEALTH_BARK_RADIO_DEAD = list("taps their earpiece."), + STEALTH_BARK_GREET = list("nods.", "lifts their chin."), + STEALTH_BARK_SMOKE = list("pats their pockets."), + STEALTH_BARK_LIGHT = list("shades their eyes."), + STEALTH_BARK_LIGHT_DEAD = list("smacks their flashlight.", "shakes their flashlight."), + ) + chances = list(RUIN_NPC_BARK_SPOT = 100) + +/datum/human_npc_voice/scav + /// For the bark being said now: "line" or "emote" when its kind has both, else null + var/say_as + /// For the bark being said now: the side of the den a line names ("east"), or null + var/fill_side + /// For the bark being said now: the friend a line asks after, or null. A guard's own name, never player text. + var/fill_name + +// A line and an emote together read as a script: a kind with both gets one or the other, picked once a bark. +// The spot line always comes, even right after a stealth line. +/datum/human_npc_voice/scav/bark(mob/living/carbon/human/npc/speaker, kind, force = FALSE) + say_as = null + if(length(lines[kind]) && length(emotes[kind])) + say_as = (human_npc_can_talk(speaker) && prob(70)) ? "line" : "emote" + . = ..(speaker, kind, force || kind == RUIN_NPC_BARK_SPOT) + say_as = null + +/datum/human_npc_voice/scav/emotes_for(kind) + return say_as == "line" ? null : ..() + +// A line that names a side of the den ("%SIDE%") or a friend ("%NAME%") is only said when there is one to name. +/datum/human_npc_voice/scav/lines_for(kind) + if(say_as == "emote") + return null + var/list/written = ..() + if(!length(written)) + return written + . = list() + for(var/line in written) + if(findtext(line, "%SIDE%")) + if(!fill_side) + continue + line = replacetext(line, "%SIDE%", fill_side) + if(findtext(line, "%NAME%")) + if(!fill_name) + continue + line = replacetext(line, "%NAME%", fill_name) // xss-safe: an NPC guard's own name, set by code, never player text + . += line + +/mob/living/carbon/human/npc/ruin/trooper/scav + name = "scav guard" + npc_name = "Scav Guard" + faction = list(FACTION_SCAV) + ai_controller = /datum/ai_controller/basic_controller/human_npc/stealth + npc_voice = /datum/human_npc_voice/scav + npc_outfit_table = /datum/human_npc_outfit_table/ruin/syndicate/sword + +/// Whatever outfit its table picks, a scav guard wears the scavs' own fatigues under it (stealth_disguise.dm, decision 40). +/mob/living/carbon/human/npc/ruin/trooper/scav/equipOutfit(outfit, visuals_only = FALSE) + var/datum/outfit/dressed = ispath(outfit) ? new outfit() : outfit + if(istype(dressed)) + dressed.uniform = /obj/item/clothing/under/syndicate/scav + return ..(dressed, visuals_only) + +/// Every scav guard carries a seclite it switches on in the dark (stealth_light.dm, decision 31), and a pass in its own +/// name; about half wear a balaclava, where nothing else is on their face (decision 40). +/mob/living/carbon/human/npc/ruin/trooper/scav/npc_dress(datum/human_npc_order/order) + . = ..() + stealth_give_light() + if(isnull(wear_mask) && prob(50)) + equip_to_slot_or_del(new /obj/item/clothing/mask/balaclava/scav(src), ITEM_SLOT_MASK) + if(isnull(wear_id) && w_uniform) + var/obj/item/card/id/card = new /obj/item/card/id/advanced/black/scav(src) + card.registered_name = real_name + equip_to_slot_or_del(card, ITEM_SLOT_ID) + +/mob/living/carbon/human/npc/ruin/trooper/scav/gunner + npc_outfit_table = /datum/human_npc_outfit_table/ruin/syndicate/pistol + +/// A gunner with an earpiece: on its group's radio net (stealth_radio.dm). +/mob/living/carbon/human/npc/ruin/trooper/scav/lookout + name = "scav lookout" + npc_name = "Scav Lookout" + npc_outfit_table = /datum/human_npc_outfit_table/ruin/syndicate/pistol + stealth_radio = TRUE + +/mob/living/carbon/human/npc/ruin/trooper/scav/lookout/npc_dress(datum/human_npc_order/order) + . = ..() + if(isnull(ears)) + equip_to_slot_or_del(new /obj/item/radio/headset(src), ITEM_SLOT_EARS) + +/obj/effect/spawner/human_npc/ruin/scav + name = "scav guard spawner" + npc_type = /mob/living/carbon/human/npc/ruin/trooper/scav + +/obj/effect/spawner/human_npc/ruin/scav/gunner + name = "scav gunner spawner" + npc_type = /mob/living/carbon/human/npc/ruin/trooper/scav/gunner + +/obj/effect/spawner/human_npc/ruin/scav/lookout + name = "scav lookout spawner" + npc_type = /mob/living/carbon/human/npc/ruin/trooper/scav/lookout diff --git a/voidcrew/modules/stealth/stealth_admin.dm b/voidcrew/modules/stealth/stealth_admin.dm new file mode 100644 index 00000000000..cd09d5233e4 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_admin.dm @@ -0,0 +1,356 @@ +/** + * # Stealth guard admin tools + * + * "Stealth Guards" (Debug): lists every stealth guard on your z-level, shows and forces its awareness, + * shows its sight to you alone (one guard, or every guard on the level at once), and acts on whole groups. + * Every action is logged (abuse review P16). + * + * The AI sleeps unless a living player is on the level. An admin watching as a ghost needs + * "Force Z-Level Active" (npc_ships/code/admin_verbs.dm). + */ + +/// The stealth guards on `z`, by group. +/proc/stealth_guards_on_level(z) + . = list() + for(var/datum/stealth_group/group as anything in GLOB.stealth_groups) + for(var/mob/living/guard as anything in group.living_members()) + var/turf/where = get_turf(guard) + if(where?.z == z) + . += guard + +/// One line about `guard`, for admins. +/proc/stealth_guard_summary(mob/living/carbon/human/npc/guard) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + if(!istype(stealth_ai)) + return "[guard] (no stealth AI)" + var/atom/focus = stealth_ai.blackboard[BB_STEALTH_FOCUS] + var/focus_text = "none" + if(focus) + var/list/entry = stealth_ai.notice_map?[REF(focus)] + focus_text = "[focus] [entry ? round(entry[STEALTH_ENTRY_NOTICE], 0.01) : "-"]" + var/since = round((world.time - stealth_ai.blackboard[BB_STEALTH_STATE_SINCE]) / (1 SECONDS)) + var/route_text = stealth_ai.route_id ? "route [stealth_ai.route_id] stop [stealth_ai.route_index]" : "sentry" + var/status_text = list("[AI_STATUS_ON]" = "on", "[AI_STATUS_IDLE]" = "idle", "[AI_STATUS_OFF]" = "off")["[stealth_ai.ai_status]"] || "off" + var/state_text = stealth_ai.calm_until ? "[stealth_ai.stealth_state()] (calming)" : stealth_ai.stealth_state() + var/wary_text = "calm" + if(stealth_ai.blackboard[BB_STEALTH_WARY]) + wary_text = "wary [max(0, round((stealth_ai.stealth_skill().wary_time - (world.time - stealth_ai.wary_at)) / (1 SECONDS)))]s" + // Decision 40: what the one it has stopped, its focus, or else the nearest player wears, and whether it works on this guard. + var/mob/living/stopped = stealth_ai.challenge?.resolve() + var/mob/living/subject = stopped || focus + var/turf/here = get_turf(guard) + if(isnull(subject) && here && here.z <= length(SSmobs.clients_by_zlevel)) + for(var/mob/living/player as anything in SSmobs.clients_by_zlevel[here.z]) + if(get_dist(player, here) <= HUMAN_NPC_SIGHT_RANGE && (isnull(subject) || get_dist(player, here) < get_dist(subject, here))) + subject = player + var/pieces = isliving(subject) ? stealth_disguise_of(subject) : NONE + if(pieces) + var/passed = stealth_ai.passes?[REF(subject)] > world.time + var/works = subject == stopped ? "stopped" : (stealth_ai.stealth_fooled(subject) ? (passed ? "passed" : "holds") : "seen through") + wary_text += " | disguise: [subject] stage [stealth_disguise_stage(pieces)][(pieces & STEALTH_PIECE_ID) ? " +pass" : ""], [works]" + return "[guard.real_name] [REF(guard)] | [stealth_ai.group?.id || "no group"] | [stealth_ai.stealth_skill().name][stealth_ai.skill_forced ? " (set)" : ""] | [state_text] [since]s | focus [focus_text] | [wary_text] | [route_text] | AI [status_text] | [stealth_guard_hearing_summary(guard, stealth_ai)]" + +ADMIN_VERB(stealth_guards, R_DEBUG, "Stealth Guards", "View and force the awareness of stealth guards on your z-level.", ADMIN_CATEGORY_DEBUG) + var/turf/here = get_turf(user.mob) + if(isnull(here)) + to_chat(user, span_warning("You need to be standing somewhere."), confidential = TRUE) + return + var/list/choices = list() + var/list/groups = list() + for(var/mob/living/carbon/human/npc/guard as anything in stealth_guards_on_level(here.z)) + choices[stealth_guard_summary(guard)] = guard + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + if(stealth_ai.group) + groups["Whole group: [stealth_ai.group.id]"] = stealth_ai.group + if(!length(choices)) + to_chat(user, span_notice("No stealth guards on this z-level."), confidential = TRUE) + return + var/level_choice = "Every guard on this level: toggle sight" + var/list/all_choices = list(level_choice) + sort_list(choices) + sort_list(groups) + var/choice = tgui_input_list(user, "Which guard or group?", "Stealth Guards", all_choices) + if(isnull(choice)) + return + if(choice == level_choice) + var/shown = stealth_toggle_level_sight(user, here.z) + stealth_admin_log(user, "[shown ? "showed" : "hid"] the sight of every guard on z[here.z]", here) + else if(groups[choice]) + stealth_admin_group(user, groups[choice]) + else if(choices[choice]) + stealth_admin_guard(user, choices[choice]) + BLACKBOX_LOG_ADMIN_VERB("Stealth Guards") + +/proc/stealth_admin_log(client/user, text, atom/where) + log_admin("[key_name(user)] stealth guards: [text][where ? " at [AREACOORD(where)]" : ""]") + message_admins("[key_name_admin(user)] stealth guards: [text][where ? " at [ADMIN_VERBOSEJMP(where)]" : ""]") + +/proc/stealth_admin_guard(client/user, mob/living/carbon/human/npc/guard) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + if(QDELETED(guard) || !istype(stealth_ai)) + return + var/list/actions = list("Force Unaware", "Force Suspicious at my turf", "Force Alert on me", "Force Alert on a mob I pick", "Force Searching at my turf", "Toggle Wary", "Show its sight", "Jump to it", "Next stop", "Hear a noise here", "Start radio call (alarm at my turf)", "Set skill") + var/action = tgui_input_list(user, stealth_guard_summary(guard), "Stealth Guard", actions) + if(isnull(action) || QDELETED(guard)) + return + var/turf/here = get_turf(user.mob) + switch(action) + if("Force Unaware") + stealth_ai.clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_ai.stealth_go_unaware() + if("Force Suspicious at my turf") + stealth_ai.clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_ai.stealth_go_suspicious(here) + if("Force Alert on me") + if(!isliving(user.mob)) + to_chat(user, span_warning("You need a living body for that."), confidential = TRUE) + return + stealth_ai.stealth_go_alert(user.mob) + if("Force Alert on a mob I pick") + var/list/mobs = list() + for(var/mob/living/someone in range(HUMAN_NPC_SIGHT_RANGE * 2, guard)) + if(someone != guard) + mobs["[someone] ([REF(someone)])"] = someone + var/picked = tgui_input_list(user, "Alert on whom?", "Stealth Guard", sort_list(mobs)) + if(isnull(picked) || QDELETED(mobs[picked])) + return + stealth_ai.stealth_go_alert(mobs[picked]) + if("Force Searching at my turf") + stealth_ai.clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_ai.stealth_go_searching(here) + if("Toggle Wary") + if(stealth_ai.blackboard[BB_STEALTH_WARY]) + stealth_ai.stealth_clear_wary() + else + stealth_ai.stealth_set_wary() + if("Show its sight") + stealth_toggle_sight_overlay(user, guard) + if("Jump to it") + user.mob.forceMove(get_turf(guard)) + if("Hear a noise here") + // The hearing for this one guard, whatever the distance: it goes to look. + stealth_ai.last_heard = list("admin", world.time) + if(stealth_ai.stealth_can_investigate()) + stealth_ai.stealth_go_heard(here) + else + stealth_ai.stealth_respond(here) + if("Start radio call (alarm at my turf)") + if(!stealth_ai.stealth_start_call(STEALTH_CALL_ALARM, here)) + to_chat(user, span_warning("It carries no radio."), confidential = TRUE) + return + if("Set skill") + var/list/skills = list("Green" = /datum/stealth_skill/green, "Yellow" = /datum/stealth_skill/yellow, "Red" = /datum/stealth_skill/red, "Back to its zone's (or mapper's)" = null) + var/picked = tgui_input_list(user, "Its skill is [stealth_ai.stealth_skill().name].", "Stealth Guard", skills) + if(isnull(picked) || QDELETED(guard)) + return + stealth_ai.stealth_force_skill(skills[picked]) + action = "Set skill to [stealth_ai.stealth_skill().name]" + if("Next stop") + var/next = stealth_ai.stealth_next_index() + if(next) + stealth_ai.stealth_drop_walk() + stealth_ai.at_stop = FALSE + stealth_ai.route_index = next + stealth_admin_log(user, "[action] on [key_name(guard)]", guard) + +/proc/stealth_admin_group(client/user, datum/stealth_group/group) + var/list/actions = list("Calm all", "Clear wary", "Alert all on me", "Search all at my turf", "Show every route", "Radio alarm at my turf", "Show noise memory", "Forget noises", "Set skill of all") + var/action = tgui_input_list(user, "[group.id]: [length(group.living_members())] guards", "Stealth Group", actions) + if(isnull(action) || QDELETED(group)) + return + var/turf/here = get_turf(user.mob) + if(action == "Set skill of all") + var/list/skills = list("Green" = /datum/stealth_skill/green, "Yellow" = /datum/stealth_skill/yellow, "Red" = /datum/stealth_skill/red, "Back to their zone's (or mapper's)" = null) + var/picked = tgui_input_list(user, "Skill for every guard in [group.id]", "Stealth Group", skills) + if(isnull(picked) || QDELETED(group)) + return + for(var/mob/living/guard as anything in group.living_members()) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + if(istype(stealth_ai)) + stealth_ai.stealth_force_skill(skills[picked]) + action = "Set skill of all to [picked]" + else if(action == "Show every route") + stealth_show_routes(user, group) + else if(action == "Radio alarm at my turf") + group.next_radio_alarm = 0 + var/told = group.radio_call(null, STEALTH_CALL_ALARM, here) + to_chat(user, span_notice("[told] guard\s with a working radio got it."), confidential = TRUE) + else if(action == "Show noise memory") + stealth_show_noise_memory(user, group) + else if(action == "Forget noises") + group.forget_noises() + else + for(var/mob/living/guard as anything in group.living_members()) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + if(!istype(stealth_ai) || guard.stat == DEAD) + continue + switch(action) + if("Calm all") + stealth_ai.clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_ai.stealth_go_unaware() + if("Clear wary") + stealth_ai.stealth_clear_wary() + if("Alert all on me") + if(isliving(user.mob)) + stealth_ai.stealth_go_alert(user.mob) + if("Search all at my turf") + stealth_ai.clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_ai.stealth_go_searching(here) + stealth_admin_log(user, "[action] on [group.id]", group.home) + +/// Numbered markers on every stop of every route in `group`, for `user` alone, for a minute. +/proc/stealth_show_routes(client/user, datum/stealth_group/group) + var/list/images = list() + for(var/route in group.routes) + var/list/stops = group.routes[route] + for(var/index in 1 to length(stops)) + var/datum/stealth_stop/stop = stops[index] + var/image/marker = image('icons/effects/alphacolors.dmi', stop.spot, "white") + SET_PLANE(marker, ABOVE_LIGHTING_PLANE, stop.spot) + marker.color = stop.chatter ? "#ffaa00" : "#00aaff" + marker.alpha = 110 + marker.maptext = MAPTEXT("[route][index]") + images += marker + user.images |= images + addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(stealth_remove_images), WEAKREF(user), images), 60 SECONDS) + +/proc/stealth_remove_images(datum/weakref/user_ref, list/images) + var/client/user = user_ref?.resolve() + user?.images -= images + +// ===== Sight overlay ===== + +/// Admins watching one guard's sight: admin ckey => overlay +GLOBAL_LIST_EMPTY(stealth_sight_overlays) + +/// The GLOB.stealth_sight_overlays key for `user`'s whole-level view. +#define STEALTH_LEVEL_OVERLAY_KEY(user) "level:[user.ckey]" + +/// Shows or hides the sight of every stealth guard on `z` to `user`. TRUE if now shown. +/proc/stealth_toggle_level_sight(client/user, z) + var/datum/stealth_level_overlay/old = GLOB.stealth_sight_overlays[STEALTH_LEVEL_OVERLAY_KEY(user)] + if(old) + qdel(old) + return FALSE + new /datum/stealth_level_overlay(user, z) + return TRUE + +/** + * Every guard's sight on one level, for one admin: one child overlay per guard. Ends on a second toggle + * or after STEALTH_ADMIN_OVERLAY_TIME; a guard that dies or is deleted drops its own child. + */ +/datum/stealth_level_overlay + var/key + var/list/datum/stealth_sight_overlay/children = list() + +/datum/stealth_level_overlay/New(client/user, z) + key = STEALTH_LEVEL_OVERLAY_KEY(user) + GLOB.stealth_sight_overlays[key] = src + for(var/mob/living/carbon/human/npc/guard as anything in stealth_guards_on_level(z)) + if(guard.stat == DEAD || !istype(guard.ai_controller, /datum/ai_controller/basic_controller/human_npc/stealth)) + continue + children += new /datum/stealth_sight_overlay(user, guard, src) + QDEL_IN(src, STEALTH_ADMIN_OVERLAY_TIME) + +/datum/stealth_level_overlay/Destroy() + if(GLOB.stealth_sight_overlays[key] == src) + GLOB.stealth_sight_overlays -= key + for(var/datum/stealth_sight_overlay/child as anything in children.Copy()) + qdel(child) + children.Cut() + return ..() + +#undef STEALTH_LEVEL_OVERLAY_KEY + +/proc/stealth_toggle_sight_overlay(client/user, mob/living/carbon/human/npc/guard) + var/datum/stealth_sight_overlay/old = GLOB.stealth_sight_overlays[user.ckey] + var/same = old?.guard_ref?.resolve() == guard + if(old) + qdel(old) + if(same) + return + new /datum/stealth_sight_overlay(user, guard) + +/** + * The tiles one guard sees, shown to one admin: green for its lit cone, blue for how far it sees into + * the dark, yellow for the close radius it feels all round. Rebuilt each scan while watched; ends when + * the guard dies, on a second toggle, or after STEALTH_ADMIN_OVERLAY_TIME. + */ +/datum/stealth_sight_overlay + var/datum/weakref/user_ref + var/datum/weakref/guard_ref + var/ckey + var/list/image/images = list() + /// The whole-level view this belongs to, or null for a single guard's + var/datum/stealth_level_overlay/parent + +/datum/stealth_sight_overlay/New(client/user, mob/living/carbon/human/npc/guard, datum/stealth_level_overlay/parent) + user_ref = WEAKREF(user) + guard_ref = WEAKREF(guard) + ckey = user.ckey + src.parent = parent + if(isnull(parent)) + GLOB.stealth_sight_overlays[ckey] = src + QDEL_IN(src, STEALTH_ADMIN_OVERLAY_TIME) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + LAZYADD(stealth_ai.watchers, src) + RegisterSignal(guard, COMSIG_LIVING_DEATH, PROC_REF(on_guard_gone)) + RegisterSignal(guard, COMSIG_QDELETING, PROC_REF(on_guard_gone)) + refresh() + +/datum/stealth_sight_overlay/Destroy() + clear() + if(parent) + parent.children -= src + parent = null + else if(GLOB.stealth_sight_overlays[ckey] == src) + GLOB.stealth_sight_overlays -= ckey + var/mob/living/carbon/human/npc/guard = guard_ref?.resolve() + if(guard) + UnregisterSignal(guard, list(COMSIG_LIVING_DEATH, COMSIG_QDELETING)) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + if(istype(stealth_ai)) + LAZYREMOVE(stealth_ai.watchers, src) + return ..() + +/datum/stealth_sight_overlay/proc/on_guard_gone(datum/source) + SIGNAL_HANDLER + qdel(src) + +/datum/stealth_sight_overlay/proc/clear() + var/client/user = user_ref?.resolve() + user?.images -= images + images.Cut() + +/datum/stealth_sight_overlay/proc/refresh() + clear() + var/client/user = user_ref?.resolve() + var/mob/living/carbon/human/npc/guard = guard_ref?.resolve() + if(isnull(user) || QDELETED(guard)) + return + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + if(!istype(stealth_ai)) + return + var/turf/center = get_turf(guard) + if(isnull(center)) + return + var/eyes = stealth_ai.stealth_eyes_open() + var/half_angle = stealth_ai.stealth_half_angle() + var/night = HAS_TRAIT(guard, TRAIT_NIGHT_VISION) + var/datum/stealth_skill/profile = stealth_ai.stealth_skill() + for(var/turf/tile as anything in RANGE_TURFS(profile.sight_range, center)) + var/dist = get_dist(center, tile) + var/colour + if(eyes && stealth_in_cone(guard, tile, half_angle) && can_see(center, tile, profile.sight_range)) + if(dist <= profile.dark_sight_range || night) + colour = "#3399ff" + else + colour = "#33cc33" + if(dist <= profile.close_range) + colour = colour || "#ffcc00" + if(isnull(colour)) + continue + var/image/marker = image('icons/effects/alphacolors.dmi', tile, "white") + SET_PLANE(marker, ABOVE_LIGHTING_PLANE, tile) + marker.color = colour + marker.alpha = 70 + images += marker + user.images |= images diff --git a/voidcrew/modules/stealth/stealth_admin_noise.dm b/voidcrew/modules/stealth/stealth_admin_noise.dm new file mode 100644 index 00000000000..18da8449950 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_admin_noise.dm @@ -0,0 +1,141 @@ +/** + * # Stealth guard admin tools: noise + * + * "Stealth Noise" (Debug): makes a real stealth_noise() where you stand, of any kind and reach, with or + * without you as its maker, and says how many guards heard it. It can also switch on the noise view: for + * STEALTH_ADMIN_OVERLAY_TIME every noise on your level is drawn for you alone, with its kind and reach at the + * source, a ring at the edge of its reach, and over each guard what it made of it ("heard 6.5/9 -> goes", + * "muffled 11.5/9", "deaf", "busy"). Images are built only while someone watches. Every use is logged. + */ + +/// One admin's noise view. Kept in GLOB.stealth_sight_overlays under "noise:". +/datum/stealth_noise_view + var/datum/weakref/user_ref + var/key + +/datum/stealth_noise_view/New(client/user) + user_ref = WEAKREF(user) + key = "noise:[user.ckey]" + GLOB.stealth_sight_overlays[key] = src + QDEL_IN(src, STEALTH_ADMIN_OVERLAY_TIME) + +/datum/stealth_noise_view/Destroy() + if(GLOB.stealth_sight_overlays[key] == src) + GLOB.stealth_sight_overlays -= key + return ..() + +/// Draws one noise for its admin: the source, its reach, and what each guard made of it (`notes`, guard => text). +/datum/stealth_noise_view/proc/show(turf/where, kind, reach, list/notes, coalesced) + var/client/user = user_ref?.resolve() + if(isnull(user)) + qdel(src) + return + var/list/images = list() + var/image/marker = image('icons/effects/alphacolors.dmi', where, "white") + SET_PLANE(marker, ABOVE_LIGHTING_PLANE, where) + marker.color = coalesced ? "#888888" : "#ff66cc" + marker.alpha = coalesced ? 60 : 140 + if(!coalesced) + marker.maptext = MAPTEXT("[kind] [reach]") + marker.maptext_width = 96 + images += marker + if(!coalesced) + for(var/turf/edge as anything in RANGE_TURFS(reach, where)) + if(get_dist(edge, where) != reach) + continue + var/image/tint = image('icons/effects/alphacolors.dmi', edge, "white") + SET_PLANE(tint, ABOVE_LIGHTING_PLANE, edge) + tint.color = "#ff66cc" + tint.alpha = 40 + images += tint + for(var/mob/living/guard as anything in notes) + var/turf/guard_turf = get_turf(guard) + if(isnull(guard_turf)) + continue + var/image/label = new + label.loc = guard_turf + SET_PLANE(label, ABOVE_LIGHTING_PLANE, guard_turf) + label.maptext = MAPTEXT("[notes[guard]]") + label.maptext_width = 128 + label.maptext_y = 34 + images += label + user.images |= images + addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(stealth_remove_images), user_ref, images), STEALTH_NOISE_VIEW_TIME) + +/// The noise views of admins standing on `z`. +/proc/stealth_noise_views(z) + . = list() + for(var/key in GLOB.stealth_sight_overlays) + var/datum/stealth_noise_view/view = GLOB.stealth_sight_overlays[key] + if(!istype(view)) + continue + var/client/user = view.user_ref?.resolve() + var/turf/user_turf = get_turf(user?.mob) + if(user_turf?.z == z) + . += view + +/// Switches `user`'s noise view on or off. TRUE if now on. +/proc/stealth_toggle_noise_view(client/user) + var/datum/stealth_noise_view/old = GLOB.stealth_sight_overlays["noise:[user.ckey]"] + if(old) + qdel(old) + return FALSE + new /datum/stealth_noise_view(user) + return TRUE + +ADMIN_VERB(stealth_make_noise, R_DEBUG, "Stealth Noise", "Make a noise stealth guards can hear at your turf, or watch the noises on your z-level.", ADMIN_CATEGORY_DEBUG) + var/turf/here = get_turf(user.mob) + if(isnull(here)) + to_chat(user, span_warning("You need to be standing somewhere."), confidential = TRUE) + return + var/view_choice = "Toggle the noise view" + var/choice = tgui_input_list(user, "Which noise?", "Stealth Noise", list(view_choice) + STEALTH_NOISE_KINDS) + if(isnull(choice)) + return + if(choice == view_choice) + var/shown = stealth_toggle_noise_view(user) + to_chat(user, span_notice("Noise view [shown ? "on" : "off"]."), confidential = TRUE) + stealth_admin_log(user, "[shown ? "showed" : "hid"] the noise view", here) + return + var/list/profile = stealth_noise_profile(choice) + var/reach = tgui_input_number(user, "Reach in tiles (0 for its usual [profile[STEALTH_PROFILE_REACH]])", "Stealth Noise", 0, 40, 0) + if(isnull(reach)) + return + var/as_me = isliving(user.mob) && tgui_alert(user, "Who made it?", "Stealth Noise", list("Nobody", "Me")) == "Me" + here = get_turf(user.mob) + var/heard = stealth_noise(here, choice, reach || null, as_me ? user.mob : null) + to_chat(user, span_notice("[heard] guard\s heard it."), confidential = TRUE) + stealth_admin_log(user, "made a [choice] noise[reach ? " (reach [reach])" : ""][as_me ? " as themselves" : ""], heard by [heard]", here) + BLACKBOX_LOG_ADMIN_VERB("Stealth Noise") + +/// The radio, the call on its way out and the last thing heard, for the guard summary. +/proc/stealth_guard_hearing_summary(mob/living/carbon/human/npc/guard, datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai) + var/radio_text = "none" + if(guard.stealth_radio) + var/obj/item/radio/earpiece = guard.ears + if(!istype(earpiece)) + radio_text = "none" + else if(!earpiece.is_on()) + radio_text = "off" + else if(is_within_radio_jammer_range(guard)) + radio_text = "jammed" + else + radio_text = "ok" + . = "radio [radio_text]" + if(stealth_ai.pending_call) + . += " (calling in [max(0, round((stealth_ai.pending_call[STEALTH_CALL_DUE] - world.time) / (1 SECONDS)))]s)" + if(stealth_ai.last_heard) + . += " | heard [stealth_ai.last_heard[1]] [round((world.time - stealth_ai.last_heard[2]) / (1 SECONDS))]s ago" + +/// What `group` remembers of noises, as chat text for `user`. +/proc/stealth_show_noise_memory(client/user, datum/stealth_group/group) + var/list/lines = list("[group.id]: [group.alarm_count()] alarms in memory") + // Prunes as it counts. + group.lure_count(group.home) + for(var/list/lure as anything in group.lures) + var/turf/spot = lure[1] + lines += "lure at ([spot.x], [spot.y]), [round((world.time - lure[2]) / (1 SECONDS))]s ago, [group.lure_count(spot)] near it" + for(var/datum/stealth_check/check as anything in group.checks) + var/mob/living/gone = check.who?.resolve() + lines += "out looking: [gone ? gone.real_name : "(gone)"] at ([check.where.x], [check.where.y]), missed in [round((check.due - world.time) / (1 SECONDS))]s, [length(check.waiters)] waiting" + to_chat(user, span_notice(lines.Join("
")), confidential = TRUE) diff --git a/voidcrew/modules/stealth/stealth_ai.dm b/voidcrew/modules/stealth/stealth_ai.dm new file mode 100644 index 00000000000..f04a00641c3 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_ai.dm @@ -0,0 +1,1778 @@ +/// Signals that mean someone has their hands on it: each names them first. +#define STEALTH_HANDLED_SIGNALS list(\ + COMSIG_CARBON_HELP_ACT,\ + COMSIG_CARBON_CUFF_ATTEMPTED,\ + COMSIG_LIVING_TRY_SYRINGE_INJECT,\ + COMSIG_LIVING_TRY_SYRINGE_WITHDRAW,\ + COMSIG_ATOM_ITEM_INTERACTION,\ + COMSIG_ATOM_ITEM_INTERACTION_SECONDARY,\ +) +/// tg's signals for a stun, knockdown or sleep about to land: each carries its length first. +#define STEALTH_STUN_SIGNALS list(\ + COMSIG_LIVING_STATUS_STUN,\ + COMSIG_LIVING_STATUS_KNOCKDOWN,\ + COMSIG_LIVING_STATUS_IMMOBILIZE,\ + COMSIG_LIVING_STATUS_PARALYZE,\ + COMSIG_LIVING_STATUS_UNCONSCIOUS,\ + COMSIG_LIVING_STATUS_SLEEP,\ +) +/// Its hands stop or start working, or it is cuffed or freed: its flashlight goes out or may come back. +#define STEALTH_LIGHT_SIGNALS list(\ + SIGNAL_ADDTRAIT(TRAIT_HANDS_BLOCKED),\ + SIGNAL_REMOVETRAIT(TRAIT_HANDS_BLOCKED),\ + SIGNAL_ADDTRAIT(TRAIT_RESTRAINED),\ + SIGNAL_REMOVETRAIT(TRAIT_RESTRAINED),\ +) + +/** + * # Stealth guards: awareness + * + * A human NPC type opts in with `ai_controller = /datum/ai_controller/basic_controller/human_npc/stealth`. + * Nothing changes for any other human NPC (owner decision 4). + * + * The guard is unaware, suspicious, alert or searching (BB_STEALTH_STATE). That is AI state only: the + * body takes damage, wounds, stuns and crit through tg exactly as before, and players never get a state. + * + * - Unaware: walks its patrol (stealth_patrol.dm) or stands its post. + * - Suspicious: saw something. Turns to it, says so, stares a moment, walks over and looks around, then + * gives up and goes back to its route. + * - Alert: has a target and fights as every human NPC does. It keeps the target all round with tg's + * can_attack() (no cone, no darkness); out of sight for STEALTH_LOSE_TARGET_TIME, it searches. It still + * notices others, and turns on someone clearly nearer or on anyone who hits it, at most once per + * STEALTH_SWITCH_COOLDOWN (decision 29). + * - Searching: runs to where it last saw someone and sweeps the spots round it, then gives up. A glimpse + * of anyone within its alert range (its skill's alert_max_range) while it searches is an alert at once. + * + * Wary (BB_STEALTH_WARY) is set by any alert, search, hit or surrender: a wider cone and quicker notice + * (abuse review P4). It fades after its skill's wary_time with nothing new: every notice gain, hit, touch and + * scan spent alert or searching starts that clock again (owner decision 23). + * + * Putting its target down (dead or in crit) with nobody else noticed ends the alarm: a short line, a look + * round where it stands for STEALTH_CALM_LOOK_TIME, then back to its route (decision 23). + * + * Every attack or touch gets a reaction, even from out of sight (P3): alert on the attacker if it can see + * them, otherwise a search at their turf. Harm that names nobody (a blast, fire, gas, a flashbang) sends + * it and the friends near it searching where it happened. Detection is a once-a-second scan owned by this + * controller, never tg's movement-triggered target field (P1). + * + * The AI runs while any living player is on its level (can_idle is off: tg's idle mode starved its walks). + * With no player on the level tg switches it off and nothing here runs; timers are world.time stamps, so a + * guard that wakes after its search ran out steps straight back to unaware and stays wary (T1). + * + * A player in the body (an admin driving it) gets none of this: no reactions, no forced run, no marks. The + * guard picks up again, unaware, when they leave. + */ +/datum/ai_controller/basic_controller/human_npc/stealth + blackboard = list( + BB_TARGETING_STRATEGY = /datum/targeting_strategy/basic/human_npc, + BB_TARGET_MINIMUM_STAT = HARD_CRIT, + BB_AGGRO_RANGE = HUMAN_NPC_SIGHT_RANGE, + BB_HUMAN_NPC_SHOT_DELAY = 3 SECONDS, + BB_HUMAN_NPC_FIRE_RANGE = 7, + BB_HUMAN_NPC_KEEP_AWAY = 2, + BB_STEALTH_STATE = STEALTH_UNAWARE, + ) + // The patrol subtree decides what an unaware guard does; no random walk. + idle_behavior = null + ai_movement = /datum/ai_movement/jps/stealth + // tg drops every action, on each step, while the walk's end is further off than this. Its 14 is shorter + // than a patrol leg or a walk home. The alert chase never leaned on it: stealth_keep_target() ends a chase. + max_target_distance = STEALTH_PATROL_MAX_PATH + can_idle = FALSE + planning_subtrees = list( + /datum/ai_planning_subtree/stealth_perception, + /datum/ai_planning_subtree/human_npc_soft_crit, + /datum/ai_planning_subtree/escape_captivity, + /datum/ai_planning_subtree/human_npc_walk_out, + /datum/ai_planning_subtree/human_npc_surrender, + /datum/ai_planning_subtree/stealth_react, + /datum/ai_planning_subtree/human_npc_arm, + /datum/ai_planning_subtree/stealth_closet, + /datum/ai_planning_subtree/stealth_chase_lost, + /datum/ai_planning_subtree/human_npc_shoot, + /datum/ai_planning_subtree/human_npc_melee, + /datum/ai_planning_subtree/stealth_patrol, + ) + /// Its patrol group (stealth_patrol.dm) + var/datum/stealth_group/group + /// Whether it has joined a group and claimed a route + var/stealth_ready = FALSE + /// The route id it walks, or null for a sentry + var/route_id + /// Index of the stop it is heading for or standing at + var/route_index = 1 + /// +1 or -1 along the route + var/route_step = 1 + /// The way a sentry faces at its post + var/sentry_dir = SOUTH + /// The stop it last reached, or the sentry's post. Investigations and searches stay within + /// STEALTH_LEASH_RANGE of it. A var, not a blackboard key: the blackboard drops a turf when it changes. + var/turf/home_turf + /// world.time a sentry next tries to walk back to a post it couldn't reach + var/home_retry_at = 0 + /// Stop index => failed tries to reach it + var/list/stop_fails = list() + /// Stop index => world.time it may be tried again + var/list/stop_skip_until = list() + /// world.time it leaves the stop it stands at + var/wait_until = 0 + /// Whether it has done its arrival at the current stop + var/at_stop = FALSE + /// Where its current stealth walk ends + var/turf/goto_dest + /// The turf it is walking to now: goto_dest, an open tile beside it, or the end of one leg of a long walk + var/turf/goto_turf + /// What that walk is for (STEALTH_GOTO_*) + var/goto_purpose + /// "arrived" or "failed" once the walk to goto_dest is over, else null + var/goto_result + /// Set while it drops its own walk, so a dropped walk doesn't count as a failure + var/dropping_walk = FALSE + /// world.time its current walk began + var/goto_started = 0 + /// Set when a walk ran out of time + var/goto_timed_out = FALSE + /// world.time its current look round ends + var/look_until = 0 + /// The way it faces while standing (a stop's facing, a sentry's post, where it saw something) + var/stand_dir = SOUTH + /// world.time it may next turn its head while standing + var/next_turn = 0 + /// Suspicious: where it walks to look + var/turf/investigate_turf + /// Suspicious: whether it has walked over and looked + var/investigated = FALSE + /// world.time of the last notice gain it saw (suspicion holds STEALTH_SUSPICIOUS_TIMEOUT after it) + var/last_gain = 0 + /// Where it last saw (or was hit from) whoever it is after + var/turf/last_seen_turf + /// Searching: the spot it searches round + var/turf/search_center + /// Searching: the spots still to check + var/list/search_queue = list() + /// Searching: whether it is looking round at the spot it reached + var/search_looking = FALSE + /// world.time of its next search line + var/next_search_bark = 0 + /// Alert: world.time it first failed to see its target in this stretch, or 0 + var/lost_since = 0 + /// Alert: world.time it may next change target + var/next_switch_at = 0 + /// world.time of its next scan + var/next_scan = 0 + /// The turf its last AI step ended on, to tell a diagonal step (stealth_step_cost()) + var/turf/last_step_turf + /// world.time of its next look for fallen friends + var/next_body_scan = 0 + /// Whether its search is over a fallen friend (it doesn't end it with "Nothing.") + var/search_for_body = FALSE + /// Bark kind => world.time it may say that kind again + var/list/bark_ready_at = list() + /// Its stat at the last change, to tell recovery from crit + var/last_stat = CONSCIOUS + /// Admins watching its sight overlay (stealth_admin.dm) + var/list/datum/stealth_sight_overlay/watchers + /// REF(mob) => list(notice, turf last scan, world.time last perceived). Not a blackboard key: the + /// blackboard's qdel sweep indexes every nested list by its values, and these hold plain numbers. + var/list/notice_map + /// REF(mob) => the turf the box, locker or bag it hides in stood on at the last scan (only those close by) + var/list/hidden_spots + /// world.time wary was last set or refreshed + var/wary_at = 0 + /// Searching after putting its target down: world.time it calms down, or 0 + var/calm_until = 0 + /// world.time someone last touched or hit it: harm at about that time is theirs, not a mystery + var/explained_at = 0 + /// Whether harm with nobody named is waiting to be judged + var/harm_pending = FALSE + /// How long before that harm a touch still explains it + var/harm_window = 0 + /// Where it stood when that harm landed + var/turf/harm_turf + /// world.time it may next react to harm with nobody named + var/next_harm_at = 0 + /// Its health when it last had nothing to explain, and when that was + var/health_mark + var/health_mark_at = 0 + +/datum/ai_controller/basic_controller/human_npc/stealth/TryPossessPawn(atom/new_pawn) + . = ..() + if(. & AI_CONTROLLER_INCOMPATIBLE) + return + notice_map = list() + blackboard[BB_STEALTH_BODIES_SEEN] = list() + blackboard[BB_STEALTH_STATE_SINCE] = world.time + RegisterSignal(new_pawn, COMSIG_LIVING_GET_PULLED, PROC_REF(on_pulled)) + RegisterSignal(new_pawn, COMSIG_ATOM_BUMPED, PROC_REF(on_bumped)) + RegisterSignals(new_pawn, STEALTH_HANDLED_SIGNALS, PROC_REF(on_handled)) + RegisterSignal(new_pawn, COMSIG_BEING_STRIPPED, PROC_REF(on_stripped)) + RegisterSignal(new_pawn, COMSIG_ATOM_PREHITBY, PROC_REF(on_prehitby)) + RegisterSignal(new_pawn, COMSIG_PROJECTILE_PREHIT, PROC_REF(on_projectile_prehit)) + RegisterSignals(new_pawn, list(COMSIG_ATOM_EX_ACT, COMSIG_LIVING_IGNITED, COMSIG_MOB_FLASHED), PROC_REF(on_harmed)) + RegisterSignals(new_pawn, STEALTH_STUN_SIGNALS, PROC_REF(on_stunned)) + RegisterSignal(new_pawn, COMSIG_LIVING_STATUS_REMOVED, PROC_REF(on_status_removed)) + RegisterSignal(new_pawn, COMSIG_AI_BLACKBOARD_KEY_SET(BB_BASIC_MOB_CURRENT_TARGET), PROC_REF(on_target_set)) + RegisterSignal(new_pawn, COMSIG_ATOM_POST_DIR_CHANGE, PROC_REF(on_pawn_turned)) + RegisterSignals(new_pawn, STEALTH_LIGHT_SIGNALS, PROC_REF(on_light_cue)) + +/datum/ai_controller/basic_controller/human_npc/stealth/UnpossessPawn(destroy) + if(pawn) + UnregisterSignal(pawn, list( + COMSIG_LIVING_GET_PULLED, + COMSIG_ATOM_BUMPED, + COMSIG_BEING_STRIPPED, + COMSIG_ATOM_PREHITBY, + COMSIG_PROJECTILE_PREHIT, + COMSIG_ATOM_EX_ACT, + COMSIG_LIVING_IGNITED, + COMSIG_MOB_FLASHED, + COMSIG_LIVING_STATUS_REMOVED, + COMSIG_AI_BLACKBOARD_KEY_SET(BB_BASIC_MOB_CURRENT_TARGET), + COMSIG_ATOM_POST_DIR_CHANGE, + ) + STEALTH_HANDLED_SIGNALS + STEALTH_STUN_SIGNALS + STEALTH_LIGHT_SIGNALS) + stealth_drop_turn() + group?.remove_member(pawn) + group = null + stealth_drop_closet() + for(var/datum/stealth_sight_overlay/overlay as anything in watchers?.Copy()) + qdel(overlay) + watchers = null + QDEL_NULL(meter) + QDEL_NULL(beam) + QDEL_NULL(torch) + stealth_cone_stop() + light_lit = FALSE + sweeping = FALSE + torch_aim = 0 + torch_pass = 0 + torch_serial++ + sputter_serial++ + turned_from = null + home_turf = null + last_seen_turf = null + harm_turf = null + goto_turf = null + goto_dest = null + investigate_turf = null + search_center = null + search_queue = null + hidden_spots = null + pending_call = null + heard_map = null + heard_now = null + made = null + passes = null + waved = null + challenge = null + start_turf = null + return ..() + +// With the AI off (nobody on the level, stunned, in crit, a player in the body) nothing scans, so no mark. +/datum/ai_controller/basic_controller/human_npc/stealth/set_ai_status(new_ai_status, additional_flags = NONE) + . = ..() + if(ai_status == AI_STATUS_OFF) + QDEL_NULL(meter) + +/datum/ai_controller/basic_controller/human_npc/stealth/on_sentience_gained() + . = ..() + QDEL_NULL(meter) + stealth_drop_turn() + stealth_update_light() + stealth_drop_call() + stealth_drop_closet() + +// The player has left the body: it is a guard again, with nothing on its mind. +/datum/ai_controller/basic_controller/human_npc/stealth/on_sentience_lost() + . = ..() + addtimer(CALLBACK(src, PROC_REF(stealth_take_back)), 1) + +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_take_back() + var/mob/living/guard = pawn + if(QDELETED(guard) || guard.client) + return + clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + if(stealth_ready && guard.stat != DEAD) + stealth_go_unaware() + reset_ai_status() + +// ===== State ===== + +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_state() + return blackboard[BB_STEALTH_STATE] + +/// Whether a player is in the body. Nothing here reacts, moves or marks it then. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_driven() + var/mob/living/guard = pawn + return !isnull(guard?.client) + +/// Cuffed, held hard, strapped to something or shut in something: tg's escape_captivity has it and it doesn't scan. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_captive() + var/mob/living/guard = pawn + if(!isturf(guard.loc) || HAS_TRAIT(guard, TRAIT_RESTRAINED)) + return TRUE + if(guard.buckled && !ismob(guard.buckled)) + return TRUE + var/mob/living/holder = guard.pulledby + return istype(holder) && holder.grab_state > GRAB_PASSIVE + +/// Whether its scan is running. Its head mark shows only then, so a mark never outlives the scan that feeds it. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_scanning() + var/mob/living/guard = pawn + if(QDELETED(guard) || guard.stat != CONSCIOUS || guard.client || ai_status == AI_STATUS_OFF) + return FALSE + return !stealth_captive() + +/// Changes state, stamping the time, and drops whatever walk it was on. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_set_state(new_state) + var/old_state = blackboard[BB_STEALTH_STATE] + if(old_state == STEALTH_UNAWARE && new_state != STEALTH_UNAWARE) + blackboard[BB_STEALTH_UNAWARE_LOST_AT] = world.time + if(old_state != new_state) + blackboard[BB_STEALTH_PREV_STATE] = old_state + blackboard[BB_STEALTH_STATE] = new_state + blackboard[BB_STEALTH_STATE_SINCE] = world.time + // Only an alert guard goes after a locker it saw someone get into (decision 33). + if(new_state != STEALTH_ALERT) + stealth_drop_closet() + look_until = 0 + lost_since = 0 + calm_until = 0 + // Whoever it had stopped to check is no longer being checked (decision 40). + challenge = null + start_turf = null + stealth_drop_turn() + suspicion_heard = FALSE + if(new_state != STEALTH_UNAWARE) + glance_until = 0 + if(new_state == STEALTH_ALERT || new_state == STEALTH_SEARCHING) + stealth_set_wary() + stealth_drop_walk() + if(!stealth_driven()) + stealth_set_pace(new_state == STEALTH_ALERT || new_state == STEALTH_SEARCHING) + human_npc_set_ai_movement(src, new_state == STEALTH_ALERT ? /datum/ai_movement/basic_avoidance/stealth : /datum/ai_movement/jps/stealth) + stealth_update_light() + for(var/datum/stealth_sight_overlay/overlay as anything in watchers) + overlay.refresh() + stealth_meter_update() + +/// Makes it wary, or starts the wary clock again. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_set_wary() + blackboard[BB_STEALTH_WARY] = TRUE + wary_at = world.time + +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_clear_wary() + blackboard[BB_STEALTH_WARY] = FALSE + wary_at = 0 + +/// Each scan: alert or searching keeps it wary; otherwise wary fades once its skill's wary_time passes with nothing new. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_update_wary() + if(!blackboard[BB_STEALTH_WARY]) + return + var/state = stealth_state() + if(state == STEALTH_ALERT || state == STEALTH_SEARCHING) + wary_at = world.time + else if(world.time - wary_at >= stealth_skill().wary_time) + stealth_clear_wary() + +/// Walks (calm) or runs, through tg's own move intent, as bounty_ai_set_pace() does. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_set_pace(run) + var/mob/living/body = pawn + if(!isliving(body) || QDELETED(body)) + return + if(run != (body.move_intent == MOVE_INTENT_RUN)) + body.toggle_move_intent() + +/// The way `guard` faces, as one of the four ways its sprite can show (a walk can leave it on a diagonal). +/proc/stealth_facing(atom/guard) + var/facing = guard.dir + if(facing & (facing - 1)) + return facing & (EAST | WEST) + return facing + +/// The way from `origin` to `goal`, as one of the four ways a sprite can face: along the longer side. +/proc/stealth_dir_to(atom/origin, atom/goal) + var/turf/start = get_turf(origin) + var/turf/end = get_turf(goal) + var/dx = end.x - start.x + var/dy = end.y - start.y + if(abs(dx) >= abs(dy)) + return dx >= 0 ? EAST : WEST + return dy > 0 ? NORTH : SOUTH + +/// The nearest open tile to `spot` within `reach` tiles (`spot` itself if it is open), or null. +/proc/stealth_open_near(turf/spot, reach = 2) + if(isnull(spot)) + return null + if(isopenturf(spot) && !spot.is_blocked_turf(exclude_mobs = TRUE)) + return spot + for(var/ring in 1 to reach) + for(var/turf/open/near in RANGE_TURFS(ring, spot)) + if(get_dist(near, spot) == ring && !near.is_blocked_turf(exclude_mobs = TRUE)) + return near + return null + +/// `where` pulled back to within STEALTH_LEASH_RANGE of home (abuse R3). Null if nowhere sensible. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_leash(turf/where) + var/turf/home = home_turf + if(isnull(where) || isnull(home) || where.z != home.z) + return where + if(get_dist(home, where) <= STEALTH_LEASH_RANGE) + return where + return stealth_open_near(get_ranged_target_turf_direct(home, where, STEALTH_LEASH_RANGE)) + +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_go_unaware() + var/list/notice = notice_map + notice?.Cut() + clear_blackboard_key(BB_STEALTH_FOCUS) + search_queue?.Cut() + stealth_set_state(STEALTH_UNAWARE) + stealth_rejoin_route() + +/// Suspicious of something at `where`. `purpose` is STEALTH_GOTO_INVESTIGATE or STEALTH_GOTO_BODY. `line` is +/// the bark kind it says, or null for the usual one. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_go_suspicious(turf/where, purpose = STEALTH_GOTO_INVESTIGATE, line = null) + stealth_set_state(STEALTH_SUSPICIOUS) + goto_purpose = purpose + investigated = FALSE + last_gain = world.time + stealth_aim_at(where) + stealth_bark(line || (purpose == STEALTH_GOTO_BODY ? STEALTH_BARK_BODY : STEALTH_BARK_SUSPICIOUS)) + +/// Suspicious: turns to `where` and makes it the place to walk over to. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_aim_at(turf/where) + var/mob/living/body = pawn + investigate_turf = stealth_leash(where) + last_seen_turf = where + blackboard[BB_STEALTH_LAST_SEEN_AT] = world.time + if(where && get_turf(body) != where) + // Never a diagonal: the sprite can't show one, and the cone would point where the guard doesn't look. + stand_dir = stealth_dir_to(body, where) + body.setDir(stand_dir) + +/// Searching round `where`. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_go_searching(turf/where) + stealth_set_wary() + if(isnull(where)) + where = get_turf(pawn) + stealth_set_state(STEALTH_SEARCHING) + search_for_body = FALSE + search_center = stealth_leash(where) || get_turf(pawn) + search_queue = stealth_search_spots(search_center) + search_looking = FALSE + next_search_bark = world.time + STEALTH_SEARCH_BARK_INTERVAL + last_seen_turf = where + blackboard[BB_STEALTH_LAST_SEEN_AT] = world.time + +/// Alert on `target` (a mob, or the mech someone sits in). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_go_alert(atom/target) + if(QDELETED(target)) + return + var/news = stealth_state() != STEALTH_ALERT + if(news) + stealth_set_state(STEALTH_ALERT) + stealth_set_wary() + lost_since = 0 + set_blackboard_key(BB_STEALTH_FOCUS, target) + last_seen_turf = get_turf(target) + blackboard[BB_STEALTH_LAST_SEEN_AT] = world.time + set_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET, target) + // It knows that face from now on: a disguise won't hide it, a mask will (decision 40). + stealth_make(ismecha(target) ? bounty_ai_pilot_of(target) : target, FALSE) + // Every alert is first hand: if they are in a locker or a box, it is the one it just saw or felt (decision 33). + stealth_closet_alerted(target) + // It has seen or felt them itself: it calls for help (decision 8). + if(news) + stealth_first_hand(last_seen_turf) + +/// Alert: turns from its target to `new_target`, and remembers the old one for when this fight ends. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_switch_target(atom/new_target) + var/atom/old_target = blackboard[BB_BASIC_MOB_CURRENT_TARGET] + var/mob/living/old_mob = ismecha(old_target) ? bounty_ai_pilot_of(old_target) : old_target + if(isliving(old_mob) && !QDELETED(old_mob)) + stealth_remember(old_mob) + next_switch_at = world.time + STEALTH_SWITCH_COOLDOWN + // What it was doing was aimed at the old one. + CancelActions() + stealth_go_alert(new_target) + +/// Notes `who` as someone it knows is there and hostile, at alert-level notice. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_remember(mob/living/who) + var/list/notice = notice_map + var/key = REF(who) + var/list/entry = notice[key] + if(isnull(entry)) + entry = list(0, null, 0) + notice[key] = entry + entry[STEALTH_ENTRY_NOTICE] = max(entry[STEALTH_ENTRY_NOTICE], STEALTH_ALERT_AT) + entry[STEALTH_ENTRY_TURF] = get_turf(who) + entry[STEALTH_ENTRY_SEEN_AT] = world.time + +/// The spots a search checks: the centre first, then a few open tiles round it in its line of sight. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_search_spots(turf/center) + . = list() + if(isnull(center)) + return + . += center + var/list/pool = list() + var/datum/region = map_region_for_turf(center) + var/turf/home = home_turf + // No spot further from home than the leash, or than the centre if that is already past it. + var/reach = (home && home.z == center.z) ? max(STEALTH_LEASH_RANGE, get_dist(home, center)) : INFINITY + for(var/turf/open/spot in RANGE_TURFS(STEALTH_SEARCH_RADIUS, center)) + if(spot == center || spot.is_blocked_turf(exclude_mobs = TRUE)) + continue + if(map_region_excludes_turf(region, spot) || (home && get_dist(home, spot) > reach)) + continue + pool += spot + var/picked = 0 + while(length(pool) && picked < STEALTH_SEARCH_POINTS) + var/turf/spot = pick_n_take(pool) + if(!can_see(center, spot, STEALTH_SEARCH_RADIUS)) + continue + . += spot + picked++ + +/** + * Says a stealth line, at most once per STEALTH_BARK_KIND_COOLDOWN for each kind (abuse P14). `about` is the + * place the line is about: a line can name its side of the den. `name` is the friend a line asks after. + * `always` skips the cooldown (a radio call is said every time it is made). + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_bark(kind, turf/about, name, always = FALSE) + var/mob/living/carbon/human/npc/body = pawn + if(!ishumannpc(body) || body.stat != CONSCIOUS || body.client) + return FALSE + if(!always && world.time < bark_ready_at[kind]) + return FALSE + var/datum/human_npc_voice/scav/voice = ispath(body.npc_voice, /datum/human_npc_voice/scav) ? human_npc_singleton(body.npc_voice) : null + if(voice) + var/turf/centre = group?.home + voice.fill_side = (about && centre && about.z == centre.z && about != centre) ? dir2text(get_dir(centre, about)) : null + voice.fill_name = name + . = body.npc_bark(kind, force = TRUE) + if(voice) + voice.fill_side = null + voice.fill_name = null + if(.) + bark_ready_at[kind] = world.time + STEALTH_BARK_KIND_COOLDOWN + +/// Moves every awareness timestamp back by `time`, as if that long had passed (unit tests, admin tools). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_rewind(time) + blackboard[BB_STEALTH_STATE_SINCE] -= time + if(blackboard[BB_STEALTH_LAST_SEEN_AT]) + blackboard[BB_STEALTH_LAST_SEEN_AT] -= time + if(blackboard[BB_STEALTH_UNAWARE_LOST_AT]) + blackboard[BB_STEALTH_UNAWARE_LOST_AT] -= time + last_gain -= time + wary_at -= time + if(calm_until) + calm_until -= time + if(lost_since) + lost_since -= time + wait_until -= time + look_until -= time + next_scan -= time + next_body_scan -= time + next_switch_at -= time + next_harm_at -= time + home_retry_at -= time + health_mark_at -= time + glance_until -= time + next_shout -= time + next_recentre -= time + if(pending_call) + pending_call[STEALTH_CALL_DUE] -= time + if(explained_at) + explained_at -= time + if(shut_in_at) + shut_in_at -= time + if(target_free_seen_at) + target_free_seen_at -= time + if(checked_at) + checked_at -= time + greeted -= time + for(var/kind in bark_ready_at) + bark_ready_at[kind] -= time + for(var/key in stop_skip_until) + stop_skip_until[key] -= time + for(var/key in waved) + var/list/stamps = waved[key] + for(var/index in 1 to length(stamps)) + stamps[index] -= time + +// ===== The scan ===== + +/** + * One scan: expires a suspicion or search whose time has run out (also how a guard catches up after + * sleeping), keeps an alert guard's target, and looks for someone new and for fallen friends. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_scan_once() + var/mob/living/carbon/human/guard = pawn + if(QDELETED(guard) || guard.stat != CONSCIOUS || guard.client) + return + next_scan = world.time + STEALTH_SCAN_INTERVAL + stealth_setup() + stealth_update_wary() + stealth_uncover_eyes() + stealth_check_health() + stealth_check_challenge() + var/state = stealth_state() + if(state == STEALTH_SEARCHING && calm_until) + if(world.time >= calm_until) + stealth_go_unaware() + else if(state == STEALTH_SEARCHING && world.time - blackboard[BB_STEALTH_STATE_SINCE] >= stealth_skill().search_time) + // "Nothing." over a dead friend reads wrong: a search over a body ends without a word. + if(!search_for_body) + stealth_bark(STEALTH_BARK_GIVE_UP) + stealth_go_unaware() + else if(state == STEALTH_SUSPICIOUS && world.time - last_gain >= STEALTH_SUSPICIOUS_TIMEOUT) + stealth_bark(STEALTH_BARK_GIVE_UP) + stealth_go_unaware() + // Its ears, its radio and its missing friends (stealth_hearing.dm, stealth_radio.dm, stealth_noise.dm). + stealth_hear_footsteps() + stealth_deliver_call() + group?.check_overdue() + if(stealth_state() == STEALTH_ALERT) + stealth_keep_target() + // Still fighting: it weighs everyone else. (Losing or downing its target has already looked round.) + if(stealth_state() == STEALTH_ALERT) + stealth_look() + else + stealth_look() + if(stealth_state() != STEALTH_ALERT && world.time >= next_body_scan) + stealth_check_bodies() + heard_now = null + stealth_update_light() + for(var/datum/stealth_sight_overlay/overlay as anything in watchers) + overlay.refresh() + stealth_meter_update() + +/// The cone half-angle it sees with now. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_half_angle() + var/datum/stealth_skill/profile = stealth_skill() + if(stealth_state() == STEALTH_SEARCHING) + return profile.search_half_angle + if(blackboard[BB_STEALTH_WARY]) + return profile.wary_half_angle + return profile.cone_half_angle + +/// Whether its eyes work: not blind, not lying down (the close radius still works either way). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_eyes_open() + var/mob/living/guard = pawn + return !guard.is_blind() && guard.body_position != LYING_DOWN + +/// Something over its eyes that blinds it (a blindfold someone put on it): with a hand free it pulls it off, as anyone would. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_uncover_eyes() + var/mob/living/carbon/human/guard = pawn + if(!ishuman(guard) || !guard.is_blind_from(EYES_COVERED) || HAS_TRAIT(guard, TRAIT_HANDS_BLOCKED)) + return + for(var/obj/item/clothing/worn in list(guard.glasses, guard.wear_mask, guard.head)) + if(worn.tint >= TINT_BLIND && guard.dropItemToGround(worn)) + return + +/// How far it sees onto `tile` in its cone: shorter in the dark unless it sees in the dark. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_range_onto(turf/tile) + var/datum/stealth_skill/profile = stealth_skill() + if(!HAS_TRAIT(pawn, TRAIT_NIGHT_VISION) && stealth_tile_is_dark(tile)) + return profile.dark_sight_range + return profile.sight_range + +/** + * Looks for people: raises notice on whoever it perceives, decays the rest, changes state. Alert, it leaves + * its own target alone (stealth_keep_target() has it) and weighs everyone else as someone to turn on. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_look() + var/mob/living/carbon/human/guard = pawn + var/list/notice = notice_map + var/datum/targeting_strategy/strategy = GET_TARGETING_STRATEGY(blackboard[BB_TARGETING_STRATEGY]) + if(isnull(strategy) || !isturf(guard.loc)) + return + var/state = stealth_state() + var/alert = state == STEALTH_ALERT + var/atom/target = alert ? blackboard[BB_BASIC_MOB_CURRENT_TARGET] : null + var/wary = blackboard[BB_STEALTH_WARY] + var/atom/focus = blackboard[BB_STEALTH_FOCUS] + var/eyes = stealth_eyes_open() + var/half_angle = stealth_half_angle() + var/datum/stealth_skill/profile = stealth_skill() + var/sight_range = profile.sight_range + var/close_range = profile.close_range + var/scan_seconds = STEALTH_SCAN_INTERVAL / (1 SECONDS) + var/list/perceived = list() + var/list/was_hidden = hidden_spots + var/list/now_hidden + var/judged = 0 + // Someone it plainly sees within its point-blank range: an alert on this look (decision 32). Nearest first. + var/mob/living/point_blank + // Just turned: nothing is plain to it at a glance and nothing makes it alert for a moment (decision 39); notice + // still fills as usual, so someone still in front of it when the moment passes is seen. + var/turning = stealth_turn_grace() + var/night_vision = HAS_TRAIT(guard, TRAIT_NIGHT_VISION) + // Decision 41: unaware and standing somewhere the room leaves dark, a lit light someone carries near it draws + // its notice wherever they stand. REF => TRUE for everyone noticed that way this look. + var/stray_lights = state == STEALTH_UNAWARE && eyes && stealth_room_is_dark(guard.loc) + var/list/by_light + // Decision 40 (stealth_disguise.dm): REF => TRUE for everyone whose disguise holds this look, the nearest of + // them close enough to stop, and whoever it has stopped already. + var/list/disguised + var/mob/living/suspect + var/mob/living/stopped = challenge?.resolve() + for(var/mob/living/candidate as anything in stealth_candidates(guard, HUMAN_NPC_SIGHT_RANGE)) + // Only those it could perceive count toward the cap, so bystanders it can't see never crowd a player out. + if(judged >= STEALTH_MAX_CANDIDATES) + break + var/key = REF(candidate) + var/turf/where = candidate.loc + var/boxed = FALSE + if(!isturf(where)) + var/atom/movable/shell = candidate.loc + // A mech is never hidden: seen all round, no darkness, straight to alert (abuse P9). + if(ismecha(shell)) + if(shell == target || !strategy.can_attack(guard, shell, HUMAN_NPC_SIGHT_RANGE)) + continue + judged++ + if(!alert) + stealth_go_alert(shell) + return + stealth_remember(candidate) + perceived[key] = candidate + continue + shell = stealth_shell_of(candidate) + if(isnull(shell)) + continue + where = shell.loc + // Any other vehicle is as plain as its driver would be on that tile. A box, a locker or a bag hides them. + boxed = !isvehicle(shell) + if(candidate == target) + continue + var/dist = get_dist(guard, where) + if(dist > sight_range) + continue + if(boxed) + // Searching, it saw them on open ground a moment ago, and now they are in a locker it can see (decision 33). + if(state == STEALTH_SEARCHING && eyes && dist <= profile.alert_max_range && stealth_closet_glimpsed(candidate, stealth_shell_of(candidate))) + if(strategy.can_attack(guard, candidate, sight_range)) + stealth_go_alert(candidate) + return + // Hidden, unless the thing they hide in moves at its shoulder (decision 29). + if(dist > close_range + 1) + continue + LAZYSET(now_hidden, key, where) + var/turf/stood = was_hidden?[key] + if(dist > close_range || isnull(stood) || stood == where) + continue + if(!strategy.can_attack(guard, candidate, sight_range)) + continue + judged++ + var/rate = 0 + var/plain_sight = FALSE + // In its cone in light it can use, and not in the moment after a turn + var/clear = FALSE + if(boxed) + rate = profile.notice_rate + else if(eyes && !stealth_is_cloaked(candidate) && stealth_in_cone(guard, where, half_angle)) + // Elbow to elbow in front of it: seen whatever the light (decision 31). Behind or side-on, the + // close radius below still applies. + var/cap = dist <= STEALTH_ADJACENT_RANGE ? sight_range : stealth_range_onto(where) + if(dist <= cap) + rate = profile.notice_rate * clamp((cap + 1 - dist) / cap, STEALTH_NOTICE_MIN_FALLOFF, 1) + if(cap < sight_range) + rate *= STEALTH_DARK_MULT + // Close in front of it, seen plainly: no slow double take (decision 32). Not in the dark, and not + // in the moment after it turns (decision 39). + else + clear = !turning + plain_sight = clear && dist <= profile.point_blank_range + if(dist <= profile.near_range) + rate *= profile.near_mult + if(!rate && dist <= close_range && (night_vision || !stealth_tile_is_dark(where))) + // At its shoulder, in light that is really there (abuse P7). Its own beam lands ahead of it, so + // someone right behind it in the dark is not seen (decisions 32 and 39). + rate = STEALTH_BEHIND_RATE + // Someone's light on its back or its side (decision 41). It turns to look; it is never an alert by itself. + var/lit_up = FALSE + if(!rate && stray_lights && !boxed && dist <= min(stealth_carried_light(candidate), STEALTH_STRAY_LIGHT_RANGE)) + rate = STEALTH_STRAY_LIGHT_RATE + lit_up = TRUE + if(!rate) + continue + // A disguise that holds (decision 40): seen doing what no guard would, it is blown; otherwise notice fills + // slower by stage, never jumps to an alert, and close enough they are stopped and asked instead. + var/pieces = boxed ? NONE : stealth_fooled(candidate) + if(pieces && stealth_breaker(candidate, pieces, where)) + if(stealth_blow(candidate)) + return + pieces = NONE + if(pieces) + LAZYSET(disguised, key, TRUE) + // Being checked: stealth_check_challenge() has them. + if(candidate == stopped) + perceived[key] = candidate + continue + var/passed = (pieces & STEALTH_PIECE_ID) && passes?[key] > world.time + if(clear && dist <= STEALTH_GREET_RANGE && (passed || ((pieces & STEALTH_PIECE_ID) && (pieces & STEALTH_PIECE_MASK)))) + stealth_greet(candidate) + if(passed) + continue + plain_sight = FALSE + if(clear && isnull(suspect) && dist <= stealth_challenge_range(pieces)) + suspect = candidate + rate *= stealth_disguise_mult(pieces, dist) + if(!rate) + continue + var/list/entry = notice[key] + if(isnull(entry)) + entry = list(0, null, 0) + notice[key] = entry + // First seen counts as moving: it just came into view. Sight knows moved or still, nothing more: + // running is heard, not seen (stealth_hear_footsteps()). + if(entry[STEALTH_ENTRY_TURF] == where) + rate *= STEALTH_STILL_MULT + if(candidate.body_position == LYING_DOWN) + rate *= STEALTH_LYING_MULT + if(state == STEALTH_SUSPICIOUS && focus == candidate) + rate *= STEALTH_SUSPICIOUS_MULT + if(state == STEALTH_SEARCHING) + rate *= STEALTH_SEARCHING_MULT + if(wary) + rate *= STEALTH_WARY_MULT + wary_at = world.time + if(lit_up) + LAZYSET(by_light, key, TRUE) + entry[STEALTH_ENTRY_NOTICE] = max(entry[STEALTH_ENTRY_NOTICE], min(entry[STEALTH_ENTRY_NOTICE] + rate * scan_seconds, STEALTH_SUSPICIOUS_AT)) + else + entry[STEALTH_ENTRY_NOTICE] = min(entry[STEALTH_ENTRY_NOTICE] + rate * scan_seconds, pieces ? STEALTH_SUSPICIOUS_AT : STEALTH_NOTICE_MAX) + if(plain_sight) + entry[STEALTH_ENTRY_NOTICE] = STEALTH_NOTICE_MAX + if(isnull(point_blank)) + point_blank = candidate + entry[STEALTH_ENTRY_TURF] = where + entry[STEALTH_ENTRY_SEEN_AT] = world.time + perceived[key] = candidate + hidden_spots = now_hidden + // Decay whoever it didn't perceive; forget anyone unseen for long enough. + var/best_key + var/best_notice = 0 + var/seen_key + var/seen_notice = 0 + // What it knows of its own target keeps while it fights them. + var/mob/living/target_mob = ismecha(target) ? bounty_ai_pilot_of(target) : target + var/target_key = isliving(target_mob) ? REF(target_mob) : null + for(var/key in notice) + var/list/entry = notice[key] + if(key == target_key) + continue + if(perceived[key]) + if(entry[STEALTH_ENTRY_NOTICE] > seen_notice) + seen_notice = entry[STEALTH_ENTRY_NOTICE] + seen_key = key + else if(!heard_now?[key]) + // Unseen and unheard this scan. + entry[STEALTH_ENTRY_NOTICE] = max(0, entry[STEALTH_ENTRY_NOTICE] - STEALTH_NOTICE_DECAY * scan_seconds) + if(world.time - entry[STEALTH_ENTRY_SEEN_AT] > STEALTH_NOTICE_FORGET) + notice -= key + continue + if(entry[STEALTH_ENTRY_NOTICE] > best_notice) + best_notice = entry[STEALTH_ENTRY_NOTICE] + best_key = key + if(alert) + stealth_weigh_switch(perceived, strategy) + return + if(point_blank) + stealth_spot_point_blank(point_blank) + return + // Someone in their colours close enough to stop (decision 40). + if(suspect && isnull(stopped) && !calm_until) + stealth_challenge(suspect) + return + // Whoever it sees now decides what it does; a higher entry it can't see no longer speaks for them. + var/judged_key = seen_key || best_key + if(isnull(judged_key)) + clear_blackboard_key(BB_STEALTH_FOCUS) + return + var/mob/living/best = perceived[judged_key] || locate(judged_key) + if(!isliving(best) || QDELETED(best)) + notice -= judged_key + return + set_blackboard_key(BB_STEALTH_FOCUS, best) + var/list/best_entry = notice[judged_key] + var/level = best_entry[STEALTH_ENTRY_NOTICE] + var/turf/best_turf = best_entry[STEALTH_ENTRY_TURF] + var/seen_now = !isnull(seen_key) + // No alert by sight from off-screen (abuse P8). + var/in_reach = get_dist(guard, best_turf) <= profile.alert_max_range + // A disguise that holds is stopped and asked once it has drawn enough notice, never taken for an intruder (decision 40). + if(disguised?[judged_key]) + if(seen_now && level >= STEALTH_SUSPICIOUS_AT && isnull(stopped) && !calm_until) + stealth_challenge(best) + return + switch(state) + if(STEALTH_UNAWARE) + if(level >= STEALTH_SUSPICIOUS_AT) + stealth_go_suspicious(best_turf, line = by_light?[judged_key] ? STEALTH_BARK_LIGHT : null) + if(STEALTH_SUSPICIOUS) + if(!seen_now) + return + // It has someone in sight now: their own "?" takes over from the heard one. + suspicion_heard = FALSE + // Just turned: the alert waits for the moment to pass (decision 39), the notice doesn't. + if(level >= STEALTH_ALERT_AT && in_reach && !turning) + stealth_go_alert(best) + return + last_gain = world.time + // It looks at, and walks to, where they are now, not where it first saw them. + if(!investigated && level >= STEALTH_SUSPICIOUS_AT && last_seen_turf != best_turf) + stealth_aim_at(best_turf) + else + last_seen_turf = best_turf + blackboard[BB_STEALTH_LAST_SEEN_AT] = world.time + if(STEALTH_SEARCHING) + if(!seen_now || level < STEALTH_SUSPICIOUS_AT) + return + // It is primed: a glimpse is enough, once it isn't in the middle of turning (decision 39). + if(in_reach) + if(!turning) + stealth_go_alert(best) + return + // Too far to be sure: the search moves to where it saw them. + var/turf/new_center = stealth_leash(best_turf) + if(calm_until || (new_center && get_dist(new_center, search_center) > 1)) + stealth_go_searching(best_turf) + +/// Someone it plainly sees right in front of it: it turns on them and fights now, no double take (decision 32). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_spot_point_blank(mob/living/who) + var/mob/living/guard = pawn + stealth_go_alert(who) + if(stealth_state() == STEALTH_ALERT && !QDELETED(guard) && !QDELETED(who)) + guard.face_atom(who) + +/** + * Between scans (planning runs every half second, the scan once a second): someone it plainly sees within + * its point-blank range is an alert now, not at the next scan. The same rules as the point-blank part of + * stealth_look(): eyes open, not cloaked, on a turf of their own, in its cone, and lit or at its elbow. + * One spatial grid lookup of two tiles; nothing else. Returns TRUE if it went alert. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_quick_look() + var/mob/living/carbon/human/guard = pawn + if(QDELETED(guard) || guard.stat != CONSCIOUS || guard.client || !isturf(guard.loc) || stealth_state() == STEALTH_ALERT) + return FALSE + if(!stealth_eyes_open() || stealth_turn_grace()) + return FALSE + var/datum/targeting_strategy/strategy = GET_TARGETING_STRATEGY(blackboard[BB_TARGETING_STRATEGY]) + if(isnull(strategy)) + return FALSE + var/half_angle = stealth_half_angle() + var/datum/stealth_skill/profile = stealth_skill() + for(var/mob/living/candidate as anything in stealth_candidates(guard, profile.point_blank_range)) + var/turf/where = candidate.loc + if(!isturf(where) || stealth_is_cloaked(candidate) || !stealth_in_cone(guard, where, half_angle)) + continue + // Someone in their colours is stopped by the scan, not jumped (decision 40). + if(stealth_fooled(candidate)) + continue + var/dist = get_dist(guard, where) + if(dist > STEALTH_ADJACENT_RANGE && stealth_range_onto(where) < profile.sight_range) + continue + if(!strategy.can_attack(guard, candidate, profile.sight_range)) + continue + var/key = REF(candidate) + var/list/entry = notice_map[key] + if(isnull(entry)) + entry = list(0, null, 0) + notice_map[key] = entry + entry[STEALTH_ENTRY_NOTICE] = STEALTH_NOTICE_MAX + entry[STEALTH_ENTRY_TURF] = where + entry[STEALTH_ENTRY_SEEN_AT] = world.time + stealth_spot_point_blank(candidate) + return TRUE + return FALSE + +/** + * Alert: whether to turn on someone else it has noticed. They must be at alert-level notice, in reach, and + * either clearly nearer than its target or in view while the target is not. Never more than once per + * STEALTH_SWITCH_COOLDOWN, so two people can't make it flap between them. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_weigh_switch(list/perceived, datum/targeting_strategy/strategy) + if(world.time < next_switch_at || !length(perceived)) + return + var/mob/living/guard = pawn + var/list/notice = notice_map + var/atom/target = blackboard[BB_BASIC_MOB_CURRENT_TARGET] + if(QDELETED(target)) + return + var/target_dist = get_dist(guard, target) + var/target_unseen = !!lost_since + var/atom/pick + var/pick_dist = INFINITY + for(var/key in perceived) + var/list/entry = notice[key] + if(isnull(entry) || entry[STEALTH_ENTRY_NOTICE] < STEALTH_ALERT_AT) + continue + var/atom/thing = bounty_ai_target_for(perceived[key]) + if(thing == target) + continue + var/dist = get_dist(guard, thing) + if(dist > stealth_skill().alert_max_range || dist >= pick_dist) + continue + if(!target_unseen && dist + STEALTH_SWITCH_MARGIN > target_dist) + continue + if(!strategy.can_attack(guard, thing, HUMAN_NPC_SIGHT_RANGE)) + continue + pick = thing + pick_dist = dist + if(pick) + stealth_switch_target(pick) + +/** + * Alert: whether the light lets it keep `thing` in view (decision 44). All round, since it is hunting them, but by + * the same light as noticing someone: what is lit (the room's lights, anyone's flashlight, its own beam) out to + * its full sight; in the dark only within its dark sight range. Beside it, always. Blind, only what is lit at its + * shoulder. A mech is plain whatever the light (abuse P9). Line of sight is the caller's. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_alert_lit(atom/thing) + var/mob/living/guard = pawn + var/turf/where = get_turf(thing) + if(isnull(where) || !isturf(guard.loc)) + return FALSE + var/dist = get_dist(guard, where) + if(ismecha(thing) || dist <= STEALTH_ADJACENT_RANGE) + return TRUE + var/datum/stealth_skill/profile = stealth_skill() + var/lit = HAS_TRAIT(guard, TRAIT_NIGHT_VISION) || !stealth_tile_is_dark(where) + if(guard.is_blind()) + return lit && dist <= profile.close_range + return lit || dist <= profile.dark_sight_range + +/// Alert: whether it has `thing` in view now, to fight: tg's all-round can_attack() at the NPC's sight range +/// (abuse P2), in light it can see by (stealth_alert_lit()). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_has_in_view(atom/thing) + if(QDELETED(thing) || !stealth_alert_lit(thing)) + return FALSE + var/datum/targeting_strategy/strategy = GET_TARGETING_STRATEGY(blackboard[BB_TARGETING_STRATEGY]) + return !!strategy?.can_attack(pawn, thing, HUMAN_NPC_SIGHT_RANGE) + +/** + * Alert: keeps its target while it has them in view (stealth_has_in_view()). Out of view, it goes where it last + * saw them (/datum/ai_planning_subtree/stealth_chase_lost), and after STEALTH_LOSE_TARGET_TIME it searches there, + * not where they are now. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_keep_target() + var/mob/living/guard = pawn + var/atom/target = blackboard[BB_BASIC_MOB_CURRENT_TARGET] + var/atom/remembered = target || blackboard[BB_STEALTH_FOCUS] + if(QDELETED(remembered)) + stealth_go_searching(last_seen_turf) + return + // In a locker or a box: tracked only if it saw them get in (decision 33, stealth_closet.dm). + if(stealth_closet_track(remembered)) + return + if(stealth_has_in_view(remembered)) + if(isturf(remembered.loc)) + target_free_seen_at = world.time + lost_since = 0 + last_seen_turf = get_turf(remembered) + blackboard[BB_STEALTH_LAST_SEEN_AT] = world.time + // Still has them in view: it keeps calling. + stealth_shout() + if(!target) + set_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET, remembered) + return + // In plain sight but no longer worth fighting. Someone in the dark beyond its dark sight is just out of view. + if(get_dist(guard, remembered) <= HUMAN_NPC_SIGHT_RANGE && stealth_alert_lit(remembered) && can_see(guard, remembered, HUMAN_NPC_SIGHT_RANGE)) + clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + clear_blackboard_key(BB_STEALTH_FOCUS) + var/mob/living/fallen = remembered + if(isliving(fallen) && (fallen.stat != CONSCIOUS || HAS_TRAIT(fallen, TRAIT_INCAPACITATED))) + stealth_target_downed(fallen) + else + // An ally now, or out of reach: look round where it last was. + stealth_go_searching(get_turf(remembered)) + return + if(!lost_since) + lost_since = world.time + if(world.time - lost_since < STEALTH_LOSE_TARGET_TIME) + return + clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_bark(STEALTH_BARK_LOST) + stealth_go_searching(last_seen_turf) + +/** + * Its target is down (decision 23). Anyone else it has noticed keeps the alarm going as usual: alert on + * someone it can see who hit it or was nearly spotted, otherwise suspicious or searching where they were. + * With nobody else it says so, looks round where it stands, and calms down once STEALTH_CALM_LOOK_TIME is + * up. The fallen one is forgotten: if they get up, they are noticed afresh (against a wary guard). + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_target_downed(mob/living/fallen) + var/mob/living/guard = pawn + var/list/notice = notice_map + notice -= REF(fallen) + stealth_set_state(STEALTH_SEARCHING) + search_center = get_turf(guard) + search_queue?.Cut() + search_looking = FALSE + calm_until = world.time + STEALTH_CALM_LOOK_TIME + look_until = calm_until + stand_dir = stealth_facing(guard) + // Anyone it noticed lately or who hit it during the fight, read before this look decays them. + var/best_notice = 0 + var/turf/best_turf + var/mob/living/best + for(var/key in notice) + var/list/entry = notice[key] + if(entry[STEALTH_ENTRY_NOTICE] < STEALTH_SUSPICIOUS_AT || entry[STEALTH_ENTRY_NOTICE] <= best_notice) + continue + if(world.time - entry[STEALTH_ENTRY_SEEN_AT] > STEALTH_NOTICE_FORGET) + continue + var/mob/living/someone = locate(key) + if(!isliving(someone) || QDELETED(someone) || someone.stat == DEAD) + continue + best_notice = entry[STEALTH_ENTRY_NOTICE] + best_turf = entry[STEALTH_ENTRY_TURF] + best = someone + // One look now: anyone else in view goes the normal way (alert, or the search moves to them). + stealth_look() + if(stealth_state() != STEALTH_SEARCHING || !calm_until) + return + if(best) + var/datum/targeting_strategy/strategy = GET_TARGETING_STRATEGY(blackboard[BB_TARGETING_STRATEGY]) + if(best_notice >= STEALTH_ALERT_AT && isnull(stealth_shell_of(best)) && strategy?.can_attack(guard, best, HUMAN_NPC_SIGHT_RANGE)) + stealth_go_alert(best) + else if(best_notice >= STEALTH_ALERT_AT) + stealth_go_searching(best_turf) + else + stealth_go_suspicious(best_turf) + return + stealth_bark(STEALTH_BARK_DOWNED) + +/** + * Fallen friends (abuse P13): group members that are dead, in crit, cuffed or lying down, in its sight. + * It reacts to each fall once: a friend who gets back up and goes down again is news again. The first + * guard to find one is suspicious and walks over; a guard that finds a body someone already reported just + * searches there. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_check_bodies() + next_body_scan = world.time + STEALTH_BODY_SCAN_INTERVAL + if(isnull(group)) + return + var/mob/living/guard = pawn + var/list/seen = blackboard[BB_STEALTH_BODIES_SEEN] + var/eyes = stealth_eyes_open() + var/half_angle = stealth_half_angle() + var/sight_range = stealth_skill().sight_range + for(var/mob/living/member as anything in group.living_members()) + if(member == guard) + continue + var/key = REF(member) + if(!(member.stat == DEAD || HAS_TRAIT(member, TRAIT_CRITICAL_CONDITION) || HAS_TRAIT(member, TRAIT_RESTRAINED) || member.body_position == LYING_DOWN)) + // On its feet again. + seen -= key + group.reported_bodies -= key + continue + if(key in seen) + continue + // A body stuffed in a locker, a crate or a bag is hidden, as a living person there is. + if(!isturf(member.loc)) + continue + var/turf/where = member.loc + if(isnull(where) || where.z != guard.z) + continue + var/dist = get_dist(guard, where) + if(dist > sight_range) + continue + var/in_sight = dist <= stealth_skill().close_range + if(!in_sight && eyes && stealth_in_cone(guard, where, half_angle)) + in_sight = dist <= stealth_range_onto(where) + if(!in_sight || !can_see(guard, where, sight_range)) + continue + seen += key + var/news = !(key in group.reported_bodies) + if(news) + group.reported_bodies += key + if(!news || stealth_state() == STEALTH_SEARCHING) + stealth_go_searching(where) + search_for_body = TRUE + // Already searching, it still says what it found (decision 31: guards that searched beside a + // body without a word looked blind). + if(news) + stealth_bark(STEALTH_BARK_BODY) + else + stealth_go_suspicious(where, STEALTH_GOTO_BODY) + stealth_first_hand(where) + // Someone in their colours standing over it as it is found (decision 40). + for(var/mob/living/carbon/human/near in range(1, where)) + if(near.stat == DEAD || guard.faction_check_atom(near) || !stealth_fooled(near) || !stealth_sees(near)) + continue + stealth_blow(near) + break + return + +// ===== Touches, hits and recovery ===== + +/** + * Anyone touching or hurting it (abuse P3): alert on them if it can see them, otherwise a search at + * their turf. Always wary. Allies are ignored. Alert on someone else already, it turns on whoever hit it + * (at most once per STEALTH_SWITCH_COOLDOWN, unless they are clearly nearer) and otherwise remembers them + * for when that fight ends. Returns TRUE if it took a target. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_touched(atom/source) + var/mob/living/guard = pawn + if(QDELETED(source) || QDELETED(guard) || source == guard || guard.stat == DEAD || guard.client) + return FALSE + // Whatever hurts it at this moment has a name, an ally's stray shot included. + explained_at = world.time + if(ismovable(source) && guard.faction_check_atom(source)) + return FALSE + // Whoever of its group sees it happen sees through a disguise (decision 40). + if(isliving(source)) + group?.witness(source, guard) + stealth_set_wary() + var/atom/who = isliving(source) ? bounty_ai_target_for(source) : source + var/datum/targeting_strategy/strategy = GET_TARGETING_STRATEGY(blackboard[BB_TARGETING_STRATEGY]) + var/atom/target = blackboard[BB_BASIC_MOB_CURRENT_TARGET] + if(stealth_state() == STEALTH_ALERT && !QDELETED(target)) + if(who == target) + return FALSE + if(isliving(source)) + stealth_remember(source) + var/nearer = get_dist(guard, who) + STEALTH_SWITCH_MARGIN <= get_dist(guard, target) + if((nearer || world.time >= next_switch_at) && strategy?.can_attack(guard, who)) + stealth_switch_target(who) + return TRUE + return FALSE + if(strategy?.can_attack(guard, who)) + stealth_go_alert(who) + return TRUE + stealth_go_searching(get_turf(source)) + stealth_bark(STEALTH_BARK_HIT_UNSEEN) + stealth_first_hand(get_turf(source)) + return FALSE + +/datum/ai_controller/basic_controller/human_npc/stealth/on_pawn_attacked(mob/living/source, atom/attacker, attack_flags) + if(source.client) + return + if(stealth_touched(attacker)) + return + if(!blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET)) + return ..() + +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_pulled(mob/living/source, atom/movable/puller) + SIGNAL_HANDLER + stealth_touched(puller) + +/// Someone walked into it, or something with someone inside did (a box on the move). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_bumped(atom/source, atom/movable/bumper) + SIGNAL_HANDLER + if(isliving(bumper)) + // One of its own, so it thinks, walking into it: it wants a look at them (decision 40). + var/pieces = stealth_scanning() ? stealth_fooled(bumper) : NONE + if(!pieces) + stealth_touched(bumper) + else if(!((pieces & STEALTH_PIECE_ID) && passes?[REF(bumper)] > world.time)) + stealth_challenge(bumper) + return + if(!ismovable(bumper)) + return + for(var/mob/living/inside in bumper.get_all_contents()) + stealth_touched(inside) + return + +/// A help-click, cuffs, a syringe, a hand in its pockets or anything else used on it. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_handled(mob/living/source, mob/living/toucher) + SIGNAL_HANDLER + if(ismob(toucher)) + stealth_touched(toucher) + +/** + * A hand in its pockets or on its clothes. Awake, that is being touched. Out cold or helpless, it feels nothing + * (decision 44): whoever of its group sees it done still reacts, through the witness rule here and the body rule + * (stealth_check_bodies()). + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_stripped(mob/living/source, mob/living/stripper) + SIGNAL_HANDLER + if(!ismob(stripper)) + return + if(source.stat != CONSCIOUS || HAS_TRAIT(source, TRAIT_INCAPACITATED)) + if(isliving(stripper) && !source.client && !source.faction_check_atom(stripper)) + group?.witness(stripper, source) + return + stealth_touched(stripper) + +/// Anything thrown that lands on it, harmless or not (relay_attackers only reports what hurts). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_prehitby(atom/source, atom/movable/hit_atom, datum/thrownthing/throwingdatum) + SIGNAL_HANDLER + var/mob/thrower = throwingdatum?.get_thrower() + if(ismob(thrower)) + stealth_touched(thrower) + +/// relay_attackers only reports a mob firer; a turret or other machine shooting it counts the same. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_projectile_prehit(atom/source, obj/projectile/hit_projectile) + SIGNAL_HANDLER + if(!hit_projectile.is_hostile_projectile() || isnull(hit_projectile.firer) || ismob(hit_projectile.firer)) + return + stealth_touched(hit_projectile.firer) + +/// Anything else that sets a target (an admin, another subtree) makes it alert. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_target_set(datum/source) + SIGNAL_HANDLER + var/atom/target = blackboard[BB_BASIC_MOB_CURRENT_TARGET] + if(isnull(target) || stealth_state() == STEALTH_ALERT || stealth_driven()) + return + stealth_set_state(STEALTH_ALERT) + stealth_set_wary() + set_blackboard_key(BB_STEALTH_FOCUS, target) + +/// A blast, flames or a flash on it. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_harmed(datum/source) + SIGNAL_HANDLER + stealth_note_harm() + +/// A stun, a knockdown or sleep about to land on it. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_stunned(datum/source, amount) + SIGNAL_HANDLER + if(amount > 0) + // Whatever it was about to say on the radio is lost. + stealth_drop_call() + stealth_note_harm() + +/** + * Something hurt or stunned it. Judged a moment later, once the blow behind it has had the chance to name + * who dealt it (tg reports an item hit's attacker after its damage). Harm someone is named for within + * `window` is theirs and stealth_touched() has dealt with it. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_note_harm(window = 0.2 SECONDS) + var/mob/living/carbon/human/npc/guard = pawn + if(harm_pending || QDELETED(guard) || guard.stat == DEAD || guard.client) + return + // Its own surrender puts it on the floor. + if(ishumannpc(guard) && guard.npc_surrendering) + return + harm_pending = TRUE + harm_window = window + harm_turf = get_turf(guard) + addtimer(CALLBACK(src, PROC_REF(stealth_judge_harm)), 0.2 SECONDS) + +/// Harm nobody was named for (a blast, fire, gas, a flashbang): it and the friends near it go looking there. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_judge_harm() + harm_pending = FALSE + var/turf/where = harm_turf + harm_turf = null + var/mob/living/guard = pawn + if(QDELETED(guard) || guard.stat == DEAD || guard.client || isnull(where)) + return + if(explained_at && world.time - explained_at <= harm_window + 0.2 SECONDS) + return + if(world.time < next_harm_at) + return + next_harm_at = world.time + STEALTH_HARM_COOLDOWN + stealth_setup() + stealth_trouble_at(where) + if(guard.stat == CONSCIOUS) + stealth_first_hand(where) + for(var/mob/living/friend as anything in group?.living_members()) + if(friend == guard) + continue + var/turf/friend_turf = get_turf(friend) + if(friend_turf?.z != where.z || get_dist(friend_turf, where) > STEALTH_HARM_ALERT_RANGE) + continue + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = friend.ai_controller + if(istype(friend_ai)) + friend_ai.stealth_trouble_at(where) + +/// Trouble at `where` it can't put a face to: wary, and searching there unless it already has someone to fight. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_trouble_at(turf/where) + var/mob/living/guard = pawn + if(QDELETED(guard) || guard.stat != CONSCIOUS || guard.client) + return + stealth_set_wary() + if(blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET)) + return + if(stealth_state() == STEALTH_SEARCHING && !calm_until) + return + stealth_go_searching(where) + stealth_bark(STEALTH_BARK_HIT_UNSEEN) + +/// Each scan: health lost with nobody to blame (gas, acid, bleeding, anything without a signal of its own). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_check_health() + var/mob/living/guard = pawn + var/health = guard.health + if(isnull(health_mark) || health > health_mark || world.time - health_mark_at > STEALTH_HARM_WINDOW) + health_mark = health + health_mark_at = world.time + return + if(health_mark - health < STEALTH_HARM_HEALTH) + return + health_mark = health + health_mark_at = world.time + stealth_note_harm(STEALTH_HARM_WINDOW) + +/// Carried off the level: drops its route and holds where it is (abuse R3). The base controller already +/// listens for the level change. +/datum/ai_controller/basic_controller/human_npc/stealth/on_changed_z_level(atom/source, turf/old_turf, turf/new_turf, same_z_layer, notify_contents) + . = ..() + // Its mark's plane belongs to the old level; the next scan builds a new one. + QDEL_NULL(meter) + if(stealth_ready && new_turf) + stealth_become_sentry(new_turf) + +/datum/ai_controller/basic_controller/human_npc/stealth/on_stat_changed(mob/living/source, new_stat) + . = ..() + var/was = last_stat + last_stat = new_stat + if(new_stat != CONSCIOUS) + QDEL_NULL(meter) + stealth_drop_call() + stealth_drop_closet() + if(new_stat == CONSCIOUS && was != CONSCIOUS && was != DEAD) + stealth_came_round() + if(new_stat != CONSCIOUS) + stealth_drop_turn() + stealth_update_light() + +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_status_removed(mob/living/source, datum/status_effect/effect) + SIGNAL_HANDLER + if(istype(effect, /datum/status_effect/incapacitating)) + stealth_came_round() + +/// Back on its feet after crit, a stun, a knockdown or sleep: it knows something happened. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_came_round() + var/mob/living/guard = pawn + if(QDELETED(guard) || guard.stat != CONSCIOUS || guard.client) + return + stealth_set_wary() + if(blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET)) + return + // Already looking, and only just: one stun often ends as several effects. + if(stealth_state() == STEALTH_SEARCHING && !calm_until && world.time - blackboard[BB_STEALTH_STATE_SINCE] < STEALTH_LOSE_TARGET_TIME) + return + stealth_go_searching(get_turf(guard)) + +// A guard that gives up is wary. +/mob/living/carbon/human/npc/npc_surrender() + . = ..() + if(.) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = ai_controller + if(istype(stealth_ai)) + stealth_ai.stealth_set_wary() + +/** + * Step 3 hook. TRUE if this guard was unaware when the current blow began: unaware now, or it stopped + * being unaware during this same tick (relay_attackers flips it before damage for hands and bullets, + * abuse P12). FALSE for any NPC without the stealth controller. + */ +/mob/living/carbon/human/npc/proc/stealth_was_unaware() + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = ai_controller + if(!istype(stealth_ai)) + return FALSE + if(stealth_ai.stealth_state() == STEALTH_UNAWARE) + return TRUE + return stealth_ai.blackboard[BB_STEALTH_UNAWARE_LOST_AT] == world.time + +/** + * The state this guard was in when the current blow began (step 3a): unaware if stealth_was_unaware(), else the state + * before a change made this same tick (a bullet's prehit alerts it before the damage lands), else its state now. + * Null for any NPC without the stealth controller. + */ +/mob/living/carbon/human/npc/proc/stealth_state_at_blow() + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = ai_controller + if(!istype(stealth_ai)) + return null + if(stealth_was_unaware()) + return STEALTH_UNAWARE + if(stealth_ai.blackboard[BB_STEALTH_STATE_SINCE] == world.time && !isnull(stealth_ai.blackboard[BB_STEALTH_PREV_STATE])) + return stealth_ai.blackboard[BB_STEALTH_PREV_STATE] + return stealth_ai.stealth_state() + +// ===== Planning ===== + +/// Pathfinding movement with room for a long patrol leg. +/datum/ai_movement/jps/stealth + maximum_length = STEALTH_PATROL_MAX_PATH + +/datum/ai_movement/jps/stealth/post_move(datum/move_loop/source, succeeded) + . = ..() + stealth_step_cost(source) + +/// tg's plain chase movement, with a diagonal step costing what it costs a player. +/datum/ai_movement/basic_avoidance/stealth + +/datum/ai_movement/basic_avoidance/stealth/post_move(datum/move_loop/source, succeeded) + . = ..() + stealth_step_cost(source) + +/** + * A player's diagonal step waits sqrt(2) times their move delay (tg's client Move()); tg's AI move loops wait + * the plain delay whatever the step, so a guard cutting corners outran a player at the same run speed + * (decision 32, fix 7). After a diagonal step, the loop waits as long as a player would. + */ +/proc/stealth_step_cost(datum/move_loop/source) + var/datum/ai_controller/basic_controller/human_npc/stealth/controller = source.extra_info + var/atom/movable/moving = source.moving + if(!istype(controller) || QDELETED(moving)) + return + var/turf/now = get_turf(moving) + var/turf/before = controller.last_step_turf + controller.last_step_turf = now + if(isnull(before) || isnull(now) || before == now || before.z != now.z || get_dist(before, now) != 1) + return + if(before.x != now.x && before.y != now.y) + source.delay = controller.movement_delay * sqrt(2) + +/** + * Runs the scan once a second, straight from planning: it never waits in the behaviour queue, where a walk + * or tg's idle mode could starve it or be starved by it. First in the list, and never ends planning. With + * the scan stopped (cuffed, held, a player in the body) it takes the head mark down. + */ +/datum/ai_planning_subtree/stealth_perception + +/datum/ai_planning_subtree/stealth_perception/SelectBehaviors(datum/ai_controller/basic_controller/human_npc/stealth/controller, seconds_per_tick) + if(!istype(controller)) + return + if(!controller.stealth_scanning()) + QDEL_NULL(controller.meter) + return + controller.stealth_setup() + if(controller.blackboard_key_exists(BB_HUMAN_NPC_EXIT)) + return + if(world.time >= controller.next_scan) + controller.stealth_scan_once() + else + // Someone stepping in front of it doesn't wait up to a second for the next scan (decision 32). + controller.stealth_quick_look() + +/// Suspicious: stare, walk over, look round. Searching: sweep the spots. Ends planning while it acts. +/datum/ai_planning_subtree/stealth_react + +/datum/ai_planning_subtree/stealth_react/SelectBehaviors(datum/ai_controller/basic_controller/human_npc/stealth/controller, seconds_per_tick) + if(!istype(controller) || controller.blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET)) + return + var/mob/living/guard = controller.pawn + if(guard.stat != CONSCIOUS) + return + switch(controller.stealth_state()) + if(STEALTH_SUSPICIOUS) + // It has stopped someone to see their pass (decision 40): it walks up to them and stands facing them. + var/mob/living/stopped = controller.challenge?.resolve() + if(stopped) + if(get_dist(guard, stopped) <= STEALTH_CHALLENGE_CHECK_RANGE) + controller.stealth_drop_walk() + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + else + controller.stealth_walk(get_turf(stopped), STEALTH_GOTO_INVESTIGATE) + return SUBTREE_RETURN_FINISH_PLANNING + if(world.time < controller.blackboard[BB_STEALTH_STATE_SINCE] + controller.stealth_skill().reaction_delay) + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + if(!controller.investigated) + var/turf/dest = controller.investigate_turf + if(dest && !controller.stealth_walk_over(dest)) + controller.stealth_walk(dest, controller.goto_purpose) + return SUBTREE_RETURN_FINISH_PLANNING + controller.investigated = TRUE + controller.stealth_drop_walk() + if(controller.goto_purpose == STEALTH_GOTO_BODY) + controller.stealth_go_searching(get_turf(guard)) + controller.search_for_body = TRUE + return SUBTREE_RETURN_FINISH_PLANNING + controller.stand_dir = stealth_facing(guard) + controller.look_until = world.time + STEALTH_LOOK_AROUND_TIME + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + if(STEALTH_SEARCHING) + // Its target is down: it looks round where it stands until it calms down. + if(controller.calm_until) + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + if(world.time >= controller.next_search_bark) + controller.next_search_bark = world.time + STEALTH_SEARCH_BARK_INTERVAL + controller.stealth_bark(STEALTH_BARK_SEARCH) + if(controller.search_looking) + if(world.time < controller.look_until) + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + controller.search_looking = FALSE + if(length(controller.search_queue)) + controller.search_queue.Cut(1, 2) + if(!length(controller.search_queue)) + controller.search_queue = controller.stealth_search_spots(controller.search_center) + if(!length(controller.search_queue)) + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + var/turf/spot = controller.search_queue[1] + if(controller.stealth_walk_over(spot)) + controller.stealth_drop_walk() + controller.search_looking = TRUE + controller.stand_dir = stealth_facing(guard) + controller.look_until = world.time + STEALTH_LOOK_AROUND_TIME + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + controller.stealth_walk(spot, STEALTH_GOTO_SEARCH) + return SUBTREE_RETURN_FINISH_PLANNING + +/** + * Alert with its target out of view (decision 44): it walks to where it last saw them, never to where they are + * now, and only its own eyes find them again (stealth_has_in_view()). Ends planning, so the shooting and melee + * subtrees after it never walk at or fire on someone it can't see. With them in view it leaves the fight to those. + * Other human NPCs never run this. + */ +/datum/ai_planning_subtree/stealth_chase_lost + +/datum/ai_planning_subtree/stealth_chase_lost/SelectBehaviors(datum/ai_controller/basic_controller/human_npc/stealth/controller, seconds_per_tick) + if(!istype(controller) || controller.stealth_state() != STEALTH_ALERT) + return + var/mob/living/guard = controller.pawn + var/atom/target = controller.blackboard[BB_BASIC_MOB_CURRENT_TARGET] + if(guard.stat != CONSCIOUS || QDELETED(target)) + return + if(controller.stealth_has_in_view(target)) + controller.last_seen_turf = get_turf(target) + if(controller.goto_dest) + controller.stealth_drop_walk() + return + var/turf/last = controller.last_seen_turf + if(isnull(last) || controller.stealth_walk_over(last)) + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + controller.stealth_walk(last, STEALTH_GOTO_SEARCH) + return SUBTREE_RETURN_FINISH_PLANNING + +// ===== Walking ===== + +/// Whether its walk to `dest` got there: on the tile, or as near as it could stand. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_walk_arrived(turf/dest) + return get_turf(pawn) == dest || (goto_dest == dest && goto_result == "arrived") + +/// Whether its walk to `dest` is over, there or not. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_walk_over(turf/dest) + return get_turf(pawn) == dest || (goto_dest == dest && !isnull(goto_result)) + +/// Whether the pathfinder gave up on its walk to `dest`. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_walk_gave_up(turf/dest) + return goto_dest == dest && goto_result == "failed" + +/// Ends its own stealth walk, if it has one, without counting it as a failed path. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_drop_walk() + var/datum/ai_behavior/walk = GET_AI_BEHAVIOR(/datum/ai_behavior/stealth_goto) + if(walk && current_behaviors[walk]) + dropping_walk = TRUE + fail_behavior(walk) + dropping_walk = FALSE + goto_turf = null + goto_dest = null + goto_result = null + +/// Starts (or keeps) its stealth walk to `dest`. A walk already over stays over until it is dropped. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_walk(turf/dest, purpose) + if(goto_dest != dest) + stealth_drop_walk() + goto_dest = dest + goto_purpose = purpose + if(goto_result) + return + if(isnull(goto_turf)) + goto_turf = stealth_next_leg(dest) + queue_behavior(/datum/ai_behavior/stealth_goto) + +/** + * The turf to walk to now on the way to `dest`: `dest`, an open tile beside it when something stands on it + * (a crate dropped on a patrol stop), or, when it is more than STEALTH_WALK_LEG off, a point part of the + * way there. A guard drawn a long way out comes home in legs instead of asking for a path too long to find. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_next_leg(turf/dest) + var/turf/here = get_turf(pawn) + if(isnull(here) || here.z != dest.z) + return dest + if(get_dist(here, dest) > STEALTH_WALK_LEG) + return stealth_open_near(get_ranged_target_turf_direct(here, dest, STEALTH_WALK_LEG - 10), 3) || dest + if(dest.is_blocked_turf(exclude_mobs = TRUE)) + return stealth_open_near(dest, 1) || dest + return dest + +/** + * Walks to the controller's goto_turf with its pathfinding movement. Ends on arrival, or as a failure + * when the pathfinder gives up or the leg takes far too long (abuse R2). + */ +/datum/ai_behavior/stealth_goto + required_distance = 0 + action_cooldown = 0.5 SECONDS + behavior_flags = AI_BEHAVIOR_REQUIRE_MOVEMENT | AI_BEHAVIOR_MOVE_AND_PERFORM | AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION + +/datum/ai_behavior/stealth_goto/setup(datum/ai_controller/basic_controller/human_npc/stealth/controller) + . = ..() + if(!istype(controller) || isnull(controller.goto_turf)) + return FALSE + // Stamped each time the walk starts or starts again (after a stun, or the level waking), so time spent + // not walking never counts against it. + controller.goto_started = world.time + set_movement_target(controller, controller.goto_turf) + +/datum/ai_behavior/stealth_goto/perform(seconds_per_tick, datum/ai_controller/basic_controller/human_npc/stealth/controller) + var/turf/dest = controller.goto_turf + if(isnull(dest)) + return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_FAILED + var/turf/here = get_turf(controller.pawn) + if(here == dest) + return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_SUCCEEDED + // Someone stands on the spot: next to it will do. + if(get_dist(here, dest) <= 1 && dest.is_blocked_turf(exclude_mobs = FALSE) && !dest.is_blocked_turf(exclude_mobs = TRUE)) + return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_SUCCEEDED + if(world.time - controller.goto_started > STEALTH_PATROL_MAX_PATH * max(controller.movement_delay, 0.4 SECONDS) * 1.5) + controller.goto_timed_out = TRUE + return AI_BEHAVIOR_DELAY | AI_BEHAVIOR_FAILED + return AI_BEHAVIOR_DELAY + +/datum/ai_behavior/stealth_goto/finish_action(datum/ai_controller/basic_controller/human_npc/stealth/controller, succeeded) + if(istype(controller) && !controller.dropping_walk) + if(succeeded) + if(controller.goto_turf == controller.goto_dest || get_dist(controller.goto_turf, controller.goto_dest) <= 1) + controller.goto_result = "arrived" + else + // One leg of a long walk: the next plan sets out on the next. + controller.goto_turf = null + else + // Only a real path failure counts; being re-planned away from a walk does not. + var/path_failed = controller.goto_timed_out || controller.consecutive_pathing_attempts >= controller.ai_movement.max_pathing_attempts + if(path_failed) + controller.goto_result = "failed" + controller.stealth_walk_failed() + controller.goto_timed_out = FALSE + return ..() + +/** + * Standing: at a stop, a sentry's post, staring at something, or looking round. Turns its head now and + * then. Never finishes by itself; planning replaces it. + */ +/datum/ai_behavior/stealth_stand + action_cooldown = 1 SECONDS + behavior_flags = AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION + +/datum/ai_behavior/stealth_stand/perform(seconds_per_tick, datum/ai_controller/basic_controller/human_npc/stealth/controller) + var/mob/living/guard = controller.pawn + if(!istype(controller) || guard.stat != CONSCIOUS || !isturf(guard.loc)) + return AI_BEHAVIOR_DELAY + if(world.time < controller.look_until) + // Looking round: one side, then the other, over STEALTH_LOOK_AROUND_TIME (decision 39: no random sides). + if(world.time >= controller.next_turn) + controller.next_turn = world.time + STEALTH_LOOK_AROUND_TIME / 2 + controller.stealth_turn_to(turn(controller.stand_dir, STEALTH_LOOK_TURN_ARC * controller.stealth_next_side())) + return AI_BEHAVIOR_DELAY + if(world.time < controller.next_turn) + return AI_BEHAVIOR_DELAY + var/state = controller.stealth_state() + if(state == STEALTH_SUSPICIOUS && !controller.investigated) + guard.setDir(controller.stand_dir) + return AI_BEHAVIOR_DELAY + // A sentry faces its post and only glances aside now and then (decision 31: it used to spend half its + // time, the first eight seconds included, facing sideways). A guard at a stop looks left, back, right, + // back, on a steady beat (decision 39: it used to be a coin toss every 3 s, which no one could read). + var/sentry = isnull(controller.route_id) + controller.next_turn = world.time + (sentry ? STEALTH_SENTRY_TURN_INTERVAL : STEALTH_LOOK_TURN_INTERVAL) + if(guard.dir != controller.stand_dir) + controller.stealth_turn_to(controller.stand_dir) + return AI_BEHAVIOR_DELAY + controller.stealth_turn_to(turn(controller.stand_dir, STEALTH_LOOK_TURN_ARC * controller.stealth_next_side())) + if(sentry) + controller.next_turn = world.time + STEALTH_SENTRY_GLANCE_TIME + return AI_BEHAVIOR_DELAY + +#undef STEALTH_HANDLED_SIGNALS +#undef STEALTH_STUN_SIGNALS +#undef STEALTH_LIGHT_SIGNALS diff --git a/voidcrew/modules/stealth/stealth_closet.dm b/voidcrew/modules/stealth/stealth_closet.dm new file mode 100644 index 00000000000..91693b33117 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_closet.dm @@ -0,0 +1,325 @@ +/** + * # Lockers and crates a guard saw someone get into (owner decision 33) + * + * An alert guard, or a searching one that glimpses someone, that sees its target get into a locker, a crate, a + * coffin, a body bag or a cardboard box (any /obj/structure/closet), or sees the door shut on them, remembers + * that container. It walks up and opens it with tg's own open(). If it won't open (locked or welded), it hits it + * with what it holds, through tg's click path: with a loaded gun it steps back to two tiles off and shoots it (tg + * never fires a gun at a thing beside you: that click is a gun-butt blow, which can't dent a secure locker), or + * it hits it with its melee weapon when that can dent it. A locker that breaks bursts open through tg's atom_break(). It gives up after + * STEALTH_CLOSET_GIVE_UP_TIME and searches round it. + * + * Someone who gets in unseen is still hidden (decision 22): an alert guard whose target is in a container it + * didn't see them get into treats them as out of sight, and never shoots at the container (tg's own + * find_hidden_mobs() would have it shoot any locker its target is in, from across the room). + * + * With several guards on one container the one that claimed it first opens it; the rest stand close and cover it. + */ + +/datum/ai_controller/basic_controller/human_npc/stealth + /// The locker or crate it saw its target get into, or null. Cleared when it is deleted. + var/obj/structure/closet/shut_in + /// Who it saw get in + var/datum/weakref/shut_who + /// world.time it saw them get in + var/shut_in_at = 0 + /// Alert: world.time it last saw its target on open ground + var/target_free_seen_at = 0 + /// Its container wouldn't open for it (locked or welded): a gunner steps back to shoot it + var/closet_stuck = FALSE + +/// The locker, crate or box `who` is shut in (the outermost, if one is inside another), or null. +/proc/stealth_closet_of(mob/living/who) + if(!isliving(who)) + return null + var/atom/movable/shell = stealth_shell_of(who) + return istype(shell, /obj/structure/closet) ? shell : null + +/// Whether it has `box` in view (all round, in the light it can see by, as it keeps an alert target in view). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_sees_closet(obj/structure/closet/box) + var/mob/living/guard = pawn + if(QDELETED(box) || !isturf(guard.loc) || get_dist(guard, box) > HUMAN_NPC_SIGHT_RANGE || !stealth_alert_lit(box)) + return FALSE + return can_see(guard, box, HUMAN_NPC_SIGHT_RANGE) + +/// Remembers that it saw `who` get into `box`. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_claim_closet(obj/structure/closet/box, mob/living/who) + if(shut_in == box) + shut_who = WEAKREF(who) + return + stealth_drop_closet() + shut_in = box + shut_who = WEAKREF(who) + shut_in_at = world.time + RegisterSignal(box, COMSIG_QDELETING, PROC_REF(on_closet_deleted)) + +/// Forgets the container it was after. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_drop_closet() + if(shut_in) + UnregisterSignal(shut_in, COMSIG_QDELETING) + shut_in = null + shut_who = null + shut_in_at = 0 + closet_stuck = FALSE + +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_closet_deleted(datum/source) + SIGNAL_HANDLER + stealth_drop_closet() + +/** + * Its claim, still good: `who` is still inside it (or inside something that went into it, which it then goes + * after instead). Drops a claim that no longer holds and returns null. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_closet_check(mob/living/who) + var/obj/structure/closet/box = shut_in + if(isnull(box)) + return null + if(!isliving(who) || QDELETED(who) || who.stat == DEAD || shut_who?.resolve() != who) + stealth_drop_closet() + return null + var/atom/holder = who.loc + while(holder && holder != box && !isturf(holder)) + holder = holder.loc + var/obj/structure/closet/outer = stealth_closet_of(who) + if(holder != box || isnull(outer)) + // They got out, or someone opened it, or it went into something that isn't a locker. + stealth_drop_closet() + return null + if(outer != box) + // The box it watched was shut inside another one: that is the one to open now. + var/claimed_at = shut_in_at + stealth_claim_closet(outer, who) + shut_in_at = claimed_at + return shut_in + +/// Searching: whether it saw `candidate` on open ground a moment ago, close to the `shell` it can see them in now. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_closet_glimpsed(mob/living/candidate, atom/movable/shell) + if(!istype(shell, /obj/structure/closet)) + return FALSE + var/list/entry = notice_map[REF(candidate)] + if(isnull(entry) || entry[STEALTH_ENTRY_NOTICE] < STEALTH_SUSPICIOUS_AT) + return FALSE + if(world.time - entry[STEALTH_ENTRY_SEEN_AT] > STEALTH_CLOSET_SEEN_WINDOW) + return FALSE + var/turf/was = entry[STEALTH_ENTRY_TURF] + if(isnull(was) || get_dist(was, shell) > 2) + return FALSE + return can_see(pawn, shell, stealth_skill().sight_range) + +/// Just went alert on `target` (always first hand: sight, a touch, a hit). If they are in a container, that's the one. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_closet_alerted(atom/target) + var/mob/living/who = target + if(!isliving(who)) + stealth_drop_closet() + return + if(isturf(who.loc)) + stealth_drop_closet() + target_free_seen_at = world.time + return + var/obj/structure/closet/box = stealth_closet_of(who) + if(box && stealth_sees_closet(box)) + stealth_claim_closet(box, who) + else if(shut_in && shut_who?.resolve() != who) + stealth_drop_closet() + +/** + * Alert, from stealth_keep_target(): its target `remembered` is in a container. Returns FALSE if they are not + * (the usual can_attack() tracking goes on). A container it saw them get into is kept in view like the target + * itself; any other hides them, and they are lost after STEALTH_LOSE_TARGET_TIME as if they had run off. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_closet_track(atom/remembered) + var/mob/living/guard = pawn + var/mob/living/who = remembered + var/obj/structure/closet/outer = stealth_closet_of(who) + if(isnull(outer)) + if(shut_in) + stealth_drop_closet() + return FALSE + var/obj/structure/closet/box = stealth_closet_check(who) + // On open ground a moment ago, and the door shut on them in front of it. + if(isnull(box) && world.time - target_free_seen_at <= STEALTH_CLOSET_SEEN_WINDOW && stealth_eyes_open() && stealth_sees_closet(outer)) + stealth_claim_closet(outer, who) + box = outer + if(box && stealth_sees_closet(box)) + lost_since = 0 + last_seen_turf = get_turf(box) + blackboard[BB_STEALTH_LAST_SEEN_AT] = world.time + if(!blackboard[BB_BASIC_MOB_CURRENT_TARGET]) + set_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET, who) + return TRUE + if(!lost_since) + lost_since = world.time + if(world.time - lost_since < STEALTH_LOSE_TARGET_TIME) + return TRUE + stealth_drop_closet() + clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_bark(STEALTH_BARK_LOST) + stealth_go_searching(last_seen_turf || get_turf(guard)) + return TRUE + +/// Whether it is the one to open `box`: of its group's guards after it, the one that saw them get in first. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_closet_opener(obj/structure/closet/box) + if(isnull(group)) + return TRUE + var/seen_self = FALSE + for(var/datum/weakref/ref as anything in group.members) + var/mob/living/member = ref?.resolve() + if(isnull(member)) + continue + if(member == pawn) + seen_self = TRUE + continue + var/datum/ai_controller/basic_controller/human_npc/stealth/other = member.ai_controller + if(!istype(other) || other.shut_in != box || member.stat != CONSCIOUS || member.client || other.stealth_captive()) + continue + if(other.shut_in_at < shut_in_at || (other.shut_in_at == shut_in_at && !seen_self)) + return FALSE + return TRUE + +/// Out of time on its container: it says so and searches round it. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_closet_give_up() + var/turf/where = get_turf(shut_in) || last_seen_turf + stealth_drop_closet() + clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_bark(STEALTH_BARK_CLOSET_GIVE_UP) + stealth_go_searching(where) + // It knows someone is in there: its search doesn't end with "Nothing." + search_for_body = TRUE + +/** + * Beside its container: opens it with tg's open(), as a hand on the door would. Locked or welded shut, it hits + * it once with what it holds, through tg's click path: a point-blank shot from a loaded gun, or its melee + * weapon if that hits hard enough to dent it (a gun butt can't: a secure locker shrugs off anything under its + * damage_deflection). Bare-handed it can only wait. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_try_closet() + var/mob/living/carbon/human/guard = pawn + var/obj/structure/closet/box = shut_in + if(QDELETED(box) || HAS_TRAIT(guard, TRAIT_HANDS_BLOCKED) || guard.incapacitated) + return + var/obj/item/gun/gun = human_npc_loaded_gun(guard) + var/adjacent = guard.Adjacent(box) + // Stepped back to shoot it (stealth_closet_fire_spot()). + if(!adjacent && !(closet_stuck && gun && stealth_closet_in_fire_spot(box))) + return + var/mob/living/who = shut_who?.resolve() + guard.face_atom(box) + if(adjacent && box.open(guard)) + stealth_drop_closet() + stealth_bark(STEALTH_BARK_CLOSET_OPEN) + if(isliving(who) && !QDELETED(who)) + // Out on the floor in front of it, or still in a box that was inside: either way, in plain view. + if(isturf(who.loc)) + target_free_seen_at = world.time + lost_since = 0 + else + stealth_closet_alerted(who) + return + closet_stuck = TRUE + if(world.time < guard.next_move) + return + if(gun) + if(adjacent || world.time < blackboard[BB_HUMAN_NPC_NEXT_SHOT] || !human_npc_ready_item(guard, gun)) + return + guard.zone_selected = BODY_ZONE_CHEST + ai_interact(target = box, combat_mode = TRUE) + set_blackboard_key(BB_HUMAN_NPC_NEXT_SHOT, world.time + (blackboard[BB_HUMAN_NPC_SHOT_DELAY] || 3 SECONDS)) + return + var/obj/item/weapon = human_npc_held_melee_weapon(guard) + if(isnull(weapon) || (weapon.item_flags & NOBLUDGEON) || weapon.force < max(box.damage_deflection, 1)) + return + human_npc_ready_item(guard, weapon) + human_npc_ready_weapon(guard, weapon) + ai_interact(target = box, combat_mode = TRUE) + +/// Whether it stands two tiles from `box` with a clear line to it: where it shoots a container that won't open. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_closet_in_fire_spot(obj/structure/closet/box) + var/mob/living/guard = pawn + return isturf(guard.loc) && get_dist(guard, box) == 2 && can_see(guard, box, 2) + +/// The nearest open tile two tiles from `box` with a clear line to it, or null. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_closet_fire_spot(obj/structure/closet/box) + var/mob/living/guard = pawn + var/turf/center = get_turf(box) + var/turf/best + var/best_dist = INFINITY + for(var/turf/open/spot in RANGE_TURFS(2, center)) + if(get_dist(spot, center) != 2 || spot.is_blocked_turf(exclude_mobs = TRUE) || !can_see(spot, center, 2)) + continue + var/dist = get_dist(guard, spot) + if(dist < best_dist) + best = spot + best_dist = dist + return best + +/** + * Alert with its target in a container. One it saw them get into: the guard that saw first walks over and opens + * it, the others close in to STEALTH_CLOSET_COVER_RANGE and cover it. One it didn't: it holds its fire and watches + * where it last saw them, rather than shoot whatever its target hides in. Ends planning either way, so the + * shooting and melee subtrees after it never aim at the container from range. + */ +/datum/ai_planning_subtree/stealth_closet + +/datum/ai_planning_subtree/stealth_closet/SelectBehaviors(datum/ai_controller/basic_controller/human_npc/stealth/controller, seconds_per_tick) + if(!istype(controller) || controller.stealth_state() != STEALTH_ALERT) + return + var/mob/living/guard = controller.pawn + if(guard.stat != CONSCIOUS) + return + var/mob/living/who = controller.blackboard[BB_BASIC_MOB_CURRENT_TARGET] || controller.blackboard[BB_STEALTH_FOCUS] + var/obj/structure/closet/outer = stealth_closet_of(who) + if(isnull(outer)) + return + var/obj/structure/closet/box = controller.stealth_closet_check(who) + if(isnull(box)) + controller.stealth_drop_walk() + var/turf/last = controller.last_seen_turf + if(last && last != get_turf(guard)) + controller.stand_dir = stealth_dir_to(guard, last) + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + if(world.time - controller.shut_in_at >= STEALTH_CLOSET_GIVE_UP_TIME) + controller.stealth_drop_walk() + controller.stealth_closet_give_up() + return SUBTREE_RETURN_FINISH_PLANNING + var/turf/spot = get_turf(box) + if(!controller.stealth_closet_opener(box)) + if(get_dist(guard, box) > STEALTH_CLOSET_COVER_RANGE && !controller.stealth_walk_gave_up(spot)) + controller.stealth_walk(spot, STEALTH_GOTO_CLOSET) + return SUBTREE_RETURN_FINISH_PLANNING + controller.stealth_drop_walk() + if(spot != get_turf(guard)) + controller.stand_dir = stealth_dir_to(guard, box) + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + // It wouldn't open: a gunner shoots it from two tiles off. + if(controller.closet_stuck && human_npc_loaded_gun(guard)) + if(controller.stealth_closet_in_fire_spot(box)) + controller.stealth_drop_walk() + controller.queue_behavior(/datum/ai_behavior/stealth_open_closet) + return SUBTREE_RETURN_FINISH_PLANNING + var/turf/fire_spot = controller.stealth_closet_fire_spot(box) + if(fire_spot && !controller.stealth_walk_gave_up(fire_spot)) + controller.stealth_walk(fire_spot, STEALTH_GOTO_CLOSET) + return SUBTREE_RETURN_FINISH_PLANNING + if(!guard.Adjacent(box)) + if(controller.stealth_walk_gave_up(spot)) + // No way to it: it gives up now rather than stand there. + controller.stealth_drop_walk() + controller.stealth_closet_give_up() + return SUBTREE_RETURN_FINISH_PLANNING + controller.stealth_walk(spot, STEALTH_GOTO_CLOSET) + return SUBTREE_RETURN_FINISH_PLANNING + controller.stealth_drop_walk() + controller.queue_behavior(/datum/ai_behavior/stealth_open_closet) + return SUBTREE_RETURN_FINISH_PLANNING + +/// Beside the container: one try a second (stealth_try_closet()). Never finishes by itself; planning replaces it. +/datum/ai_behavior/stealth_open_closet + action_cooldown = 1 SECONDS + behavior_flags = AI_BEHAVIOR_CAN_PLAN_DURING_EXECUTION + +/datum/ai_behavior/stealth_open_closet/perform(seconds_per_tick, datum/ai_controller/basic_controller/human_npc/stealth/controller) + if(istype(controller)) + controller.stealth_try_closet() + return AI_BEHAVIOR_DELAY diff --git a/voidcrew/modules/stealth/stealth_crits.dm b/voidcrew/modules/stealth/stealth_crits.dm new file mode 100644 index 00000000000..53dc636e6e8 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_crits.dm @@ -0,0 +1,233 @@ +/** + * # Stealth guards: crits on a guard caught off guard, and the head shot (step 3a, owner decisions 9, 16, 19, 45) + * + * A blow on a stealth guard that never saw it coming adds to hyperviolence's aimed crit roll (crit_roll.dm, + * hv_crit_situation_bonus()), so it only matters on an aimed hit that could crit anyway, it goes in before wound + * armour scales the roll, and every crit's own armour block still holds. + * + * - Who: a guard with the stealth controller, conscious, not held or cuffed, with no player in the body. Never a + * player (decision 19), never any other NPC. + * - When: by its state as the blow began (stealth_state_at_blow()). Unaware of everyone gets the full bonus; only + * suspicious, a smaller one; searching or alert, none. Searching gets none so that peek, shoot, hide and wait out + * the search can't farm it. + * - Head: aimed at the head, eyes or mouth, the bonus goes up again. + * - A sharp knife from behind cuts the throat instead (knife_executions.dm). + * + * The head shot (decision 45) is not a roll. A bullet aimed at the head of a guard caught off guard does what the + * round can do against how well his head is protected (stealth_head_shot()), all through tg's own systems: + * - a strong round: the head bursts (hyperviolence's hv_burst_head_apart(), a real decapitation); + * - a weak round through the skull: a critical puncture with a heavy bleed, real brain damage and tg's + * Unconscious() long enough that the bleed takes him (blood loss, then oxygen loss, then crit and death); + * - stopped short of the skull: the hit as normal, and tg's Unconscious() for STEALTH_HEAD_SHOT_HELMET_TIME; + * - stopped: the hit as normal. + * Protection (helmets, and physiology armour such as dermal cyberware, by tg's own armour numbers) steps it down. + * Players on players, and everyone else's head shots, are exactly as before. Numbers: data/stealth/STATUS.md. + */ + +/// TRUE if this guard was caught off guard by `attacker`'s blow: unaware or only suspicious as it began, conscious, +/// not held or cuffed, no player in the body. No side effects. +/mob/living/carbon/human/npc/proc/stealth_caught_off_guard(mob/living/attacker) + if(isnull(attacker) || attacker == src || client || stat != CONSCIOUS) + return FALSE + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = ai_controller + if(!istype(stealth_ai) || stealth_ai.stealth_captive()) + return FALSE + var/state = stealth_state_at_blow() + return state == STEALTH_UNAWARE || state == STEALTH_SUSPICIOUS + +/// The roll bonus for this blow (STEALTH_CRIT_*), or 0. No side effects. +/mob/living/carbon/human/npc/proc/stealth_crit_bonus(mob/living/attacker, atom/source, obj/item/bodypart/limb) + if(!stealth_caught_off_guard(attacker)) + return 0 + . = stealth_state_at_blow() == STEALTH_UNAWARE ? STEALTH_CRIT_UNAWARE_BONUS : STEALTH_CRIT_SUSPICIOUS_BONUS + if(limb?.body_zone == BODY_ZONE_HEAD) + . += STEALTH_CRIT_HEAD_BONUS + +/mob/living/carbon/human/npc/hv_crit_situation_bonus(mob/living/attacker, atom/source, obj/item/bodypart/limb) + . = ..() + var/bonus = stealth_crit_bonus(attacker, source, limb) + if(!bonus) + return . + log_combat(attacker, src, "struck a [stealth_state_at_blow()] stealth guard", source, "(crit roll +[bonus], [limb?.body_zone])") + return . + bonus + +// --------------------------------------------------------------------------------------------- +// The head shot (decision 45) + +/obj/projectile + /// The caliber of the casing this was fired from (stealth head shots), or null. + var/vc_caliber + +/obj/item/ammo_casing/ready_proj(atom/target, mob/living/user, quiet, zone_override = "", atom/fired_from) + . = ..() + if(loaded_projectile) + loaded_projectile.vc_caliber = caliber + +/// Whether a round of this caliber is a rifle or shotgun round, which hits a skull harder than its damage says. +/proc/stealth_heavy_caliber(caliber) + switch(caliber) + if(CALIBER_A223, CALIBER_A7MM, CALIBER_STRILKA310, CALIBER_50BMG, CALIBER_SHOTGUN) + return TRUE + return FALSE + +/// Whether `shot` came from a gun with a suppressor. tg's pellet cloud fires every pellet "quiet", so the gun is asked first. +/proc/stealth_shot_suppressed(obj/projectile/shot) + if(isgun(shot.fired_from)) + var/obj/item/gun/gun = shot.fired_from + return !!gun.suppressed + return !!shot.suppressed + +/mob/living/carbon/human/npc + /// world.time of the head shot being resolved: every pellet of one shot lands in the same tick + var/stealth_head_shot_at = -1 + /// Whether the shot being resolved caught it off guard (decided on its first pellet) + var/stealth_head_shot_open = FALSE + /// Power of the shot being resolved so far, before the caliber bonus and the suppressor + var/stealth_head_shot_power = 0 + /// The worst outcome (STEALTH_HEAD_SHOT_*) the shot being resolved has done so far + var/stealth_head_shot_done = STEALTH_HEAD_SHOT_NONE + +/mob/living/carbon/human/npc/hv_crit_check_hit(damage, def_zone, wound_bonus, exposed_wound_bonus, sharpness, attack_direction, atom/source) + if(stealth_head_shot(damage, def_zone, wound_bonus, attack_direction, source)) + return + return ..() + +/** + * A round that has just hit this guard's head, after tg dealt its damage. If it was aimed there and caught the guard off + * guard, grades it and does what it earns. Returns TRUE if the hit was a stealth head shot (the aimed crit roll is then + * skipped), FALSE to leave it to the ordinary crit roll. + */ +/mob/living/carbon/human/npc/proc/stealth_head_shot(damage, def_zone, wound_bonus, attack_direction, atom/source) + if(!isprojectile(source) || !isbodypart(def_zone)) + return FALSE + var/obj/item/bodypart/limb = def_zone + if(limb.owner != src || limb.body_zone != BODY_ZONE_HEAD) + return FALSE + var/obj/projectile/shot = source + if(shot.damage_type != BRUTE || shot.stamina > shot.damage) + return FALSE + var/mob/living/carbon/shooter = hv_crit_get_aimer(shot) + if(isnull(shooter) || shooter == src || check_zone(shooter.zone_selected) != BODY_ZONE_HEAD) + return FALSE + if(stealth_head_shot_at != world.time) + stealth_head_shot_at = world.time + stealth_head_shot_power = 0 + stealth_head_shot_done = STEALTH_HEAD_SHOT_NONE + stealth_head_shot_open = stealth_caught_off_guard(shooter) + if(!stealth_head_shot_open) + return FALSE + var/grade = stealth_head_shot_grade(limb, shot, damage, wound_bonus) + // Bursting a head is an execution: only those hyperviolence lets execute (players and boss NPCs). + if(grade == STEALTH_HEAD_SHOT_BURST && !shooter.hv_can_execute()) + grade = STEALTH_HEAD_SHOT_DOWN + if(grade > stealth_head_shot_done) + stealth_head_shot_apply(grade, limb, shot, shooter, attack_direction || get_dir(shooter, src)) + return stealth_head_shot_done != STEALTH_HEAD_SHOT_NONE + +/** + * What this round does to this head (STEALTH_HEAD_SHOT_*), counting every pellet of the shot that has landed so far. + * The round's power (its own numbers, before armour) gives burst, down or nothing; then each protection step + * (stealth_head_protection()) moves that one down the ladder: burst, down, knocked out, nothing. + */ +/mob/living/carbon/human/npc/proc/stealth_head_shot_grade(obj/item/bodypart/limb, obj/projectile/shot, damage, wound_bonus) + stealth_head_shot_power += shot.damage + max(0, shot.wound_bonus) / 2 + var/power = stealth_head_shot_power + if(stealth_heavy_caliber(shot.vc_caliber)) + power += STEALTH_HEAD_SHOT_HEAVY_CALIBER + if(stealth_shot_suppressed(shot)) + power *= STEALTH_HEAD_SHOT_SUPPRESSED_MULT + var/grade = STEALTH_HEAD_SHOT_NONE + if(power >= STEALTH_HEAD_SHOT_BURST_POWER) + grade = STEALTH_HEAD_SHOT_BURST + else if(power >= STEALTH_HEAD_SHOT_MIN_POWER) + grade = STEALTH_HEAD_SHOT_DOWN + if(grade == STEALTH_HEAD_SHOT_NONE) + return grade + var/protection = stealth_head_protection(limb, shot) + var/steps = 0 + if(protection >= STEALTH_HEAD_SHOT_STEP_THREE) + steps = 3 + else if(protection >= STEALTH_HEAD_SHOT_STEP_TWO) + steps = 2 + else if(protection >= STEALTH_HEAD_SHOT_STEP_ONE) + steps = 1 + return max(STEALTH_HEAD_SHOT_NONE, grade - steps) + +/** + * How well this head is protected against this round, with tg's own numbers: the armour tg's damage code uses against it + * (run_armor_check(): covering clothes and physiology armour, where protective cyberware lives, stacked as + * check_armor() stacks them, less the round's penetration), plus the wound armour tg's wound roll uses + * (check_woundings_mods(): covering clothes and physiology), bar the head's own resistance everyone has. + */ +/mob/living/carbon/human/npc/proc/stealth_head_protection(obj/item/bodypart/limb, obj/projectile/shot) + . = run_armor_check(limb, shot.armor_flag, armour_penetration = shot.armour_penetration, silent = TRUE, weak_against_armour = shot.weak_against_armour) + for(var/obj/item/clothing/worn as anything in get_clothing_on_part(limb)) + . += worn.get_armor_rating(WOUND) + . += physiology?.armor.get_rating(WOUND) || 0 + +/// Does what a graded head shot earns, through tg's own systems. +/mob/living/carbon/human/npc/proc/stealth_head_shot_apply(grade, obj/item/bodypart/limb, obj/projectile/shot, mob/living/shooter, shot_dir) + switch(grade) + if(STEALTH_HEAD_SHOT_BURST) + if(hv_burst_head_apart(shot_dir)) + stealth_head_shot_done = grade + log_combat(shooter, src, "burst the head of an unsuspecting stealth guard", shot) + return + // A head that can't come off: a round through the skull instead. + grade = STEALTH_HEAD_SHOT_DOWN + if(STEALTH_HEAD_SHOT_HELMET) + stealth_head_shot_done = grade + Unconscious(STEALTH_HEAD_SHOT_HELMET_TIME) + if(head) + hv_add_hit_line("The shot cracks off [src]'s [head.name]!", HV_LINE_BOLD, "Something cracks off your [head.name]!") + else + hv_add_hit_line("The shot glances off [src]'s skull!", HV_LINE_BOLD, "Something cracks against your skull!") + playsound(src, SFX_RICOCHET, 60, TRUE) + log_combat(shooter, src, "knocked out an unsuspecting stealth guard through head protection", shot) + return + if(grade != STEALTH_HEAD_SHOT_DOWN || stealth_head_shot_done >= grade) + return + if(!hv_crit_apply_wound(limb, /datum/wound/pierce/bleed/critical/hv_head_shot, shot_dir, shot)) + return + stealth_head_shot_done = grade + hv_blood_spray(shot_dir, 2) + hv_add_hit_line("[src] is shot through the head!", HV_LINE_HUGE, "Something punches through your skull!", DEFAULT_MESSAGE_RANGE) + playsound(src, 'sound/effects/wounds/pierce3.ogg', 80, TRUE, falloff_exponent = SOUND_FALLOFF_EXPONENT + 2, ignore_walls = FALSE, falloff_distance = 0) + // He drops and twitches as he goes under (hyperviolence's own twitches). + hv_vis_twitches(4, 8) + log_combat(shooter, src, "shot an unsuspecting stealth guard through the head", shot) + +/** + * A round through the skull: tg's ruptured cavity on the head with a heavier bleed, real brain damage and tg's + * unconsciousness. Treated like any critical puncture (gauze, sutures, cautery, surgery); the brain damage heals like any + * other. Only a stealth head shot gives it (can_be_randomly_generated is off). + */ +/datum/wound/pierce/bleed/critical/hv_head_shot + name = "Penetrating Head Wound" + undiagnosed_name = "Head Wound" + desc = "Patient has been shot through the skull. The wound is bleeding heavily and the brain is injured." + simple_desc = "A bullet has gone through the skull." + examine_desc = "has a bloody hole punched through it" + occur_text = "is punched through" + initial_flow = STEALTH_HEAD_SHOT_FLOW + clot_rate = 0 + +/datum/wound/pierce/bleed/critical/hv_head_shot/wound_injury(datum/wound/old_wound = null, attack_direction = null) + . = ..() + if(!victim) + return + victim.adjustOrganLoss(ORGAN_SLOT_BRAIN, STEALTH_HEAD_SHOT_BRAIN_DAMAGE) + if(victim.stat == DEAD) + return + victim.Unconscious(STEALTH_HEAD_SHOT_DOWN_TIME) + +/datum/wound_pregen_data/flesh_pierce/hv_head_shot + abstract = FALSE + wound_path_to_generate = /datum/wound/pierce/bleed/critical/hv_head_shot + required_wounding_types = list(WOUND_PIERCE) + wound_series = WOUND_SERIES_HV_HEAD_SHOT + required_limb_biostate = (BIO_FLESH|BIO_BLOODED) + ignore_cannot_bleed = FALSE + viable_zones = list(BODY_ZONE_HEAD) + can_be_randomly_generated = FALSE + threshold_minimum = 100 diff --git a/voidcrew/modules/stealth/stealth_den_planet.dm b/voidcrew/modules/stealth/stealth_den_planet.dm new file mode 100644 index 00000000000..d2f92649e53 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_den_planet.dm @@ -0,0 +1,324 @@ +/** + * TEMPORARY PLAYTEST TOOL for the stealth branch (feature/stealth). Remove before merge. + * + * "Stealth: Scav Den Planet" (Debug) builds a fresh jungle planet through the normal overmap path and worldgen + * queue, loads the scav chop shop (scav_den.dm) on it at a cleared spot, then dresses the admin in a mortal body + * with the stealth playtest kit and drops them in the jungle south of the den's front airlock. + */ + +/// Cleared ground around the den, so both airlocks and the arrival spot are open jungle +#define STEALTH_TEST_MARGIN 8 +/// No ground fauna may spawn this close to the ruin +#define STEALTH_TEST_FAUNA_CLEARANCE 10 +/// The ruin and its cleared margin stay at least this far from the planet's edge +#define STEALTH_TEST_EDGE 5 +/// Structure spawners (nests, tendrils) are removed this close to the ruin +#define STEALTH_TEST_SPAWNER_CLEARANCE 20 +/// How long the planet may take to come up, queue wait included +#define STEALTH_TEST_PLANET_TIMEOUT (8 MINUTES) +/// How long to wait for the guards to spawn before choosing the arrival spot +#define STEALTH_TEST_GUARD_WAIT (20 SECONDS) +/// The den's outer front airlock in map-local coordinates (1-based, from the bottom left) +#define STEALTH_TEST_DOOR_X 29 +#define STEALTH_TEST_DOOR_Y 2 + +ADMIN_VERB(stealth_den_planet, R_ADMIN|R_DEBUG, "Stealth: Scav Den Planet", "TEMPORARY: build a jungle planet with the scav chop shop and drop you outside it in the stealth playtest kit.", ADMIN_CATEGORY_DEBUG) + // The planet's overmap zone sets how sharp the guards are (green, yellow or red skill profile). + var/static/list/zone_choices = list("Green" = ZONE_GREEN, "Yellow" = ZONE_YELLOW, "Red" = ZONE_RED) + var/zone_name = tgui_input_list(user, "Which zone should the planet be in? Guards are sharper in harder zones.", "Stealth: Scav Den Planet", zone_choices, "Yellow") + if(isnull(zone_name) || isnull(zone_choices[zone_name])) + return + message_admins("[key_name_admin(user)] is building a scav den test planet in the [zone_name] zone.") + log_admin("[key_name(user)] is building a scav den test planet in the [zone_name] zone.") + BLACKBOX_LOG_ADMIN_VERB("Stealth Scav Den Planet") + INVOKE_ASYNC(GLOBAL_PROC, GLOBAL_PROC_REF(stealth_test_planet_for_client), user, zone_choices[zone_name]) + +/// Builds the site in `zone`, then gives `user` a mortal body there. +/proc/stealth_test_planet_for_client(client/user, zone = ZONE_YELLOW) + var/turf/arrival = stealth_test_planet_build(user, zone) + if(isnull(arrival) || QDELETED(user)) + return + var/mob/living/carbon/human/body = stealth_test_planet_body(user, arrival) + if(isnull(body)) + to_chat(user, span_warning("Stealth test: could not make you a body.")) + return + to_chat(user, span_notice("Stealth test: you are on [get_area_name(arrival, TRUE)], in the jungle south of the scav den's front airlock.")) + message_admins("[key_name_admin(user)] arrived at the scav den test planet [ADMIN_VERBOSEJMP(arrival)].") + +/** + * Spawns a jungle planet on the overmap, builds it through load_level() (which queues on the worldgen + * queue), and loads the scav den on a clear spot. Returns the arrival turf, or null. + * `feedback` is told how it is going; it may be null (tests). + */ +/proc/stealth_test_planet_build(client/feedback, zone = ZONE_YELLOW) + var/mob/feedback_mob = feedback?.mob + var/datum/map_template/ruin/template + for(var/name in SSmapping.ruins_templates) + var/datum/map_template/ruin/candidate = SSmapping.ruins_templates[name] + if(istype(candidate, /datum/map_template/ruin/space/rare/scav_den)) + template = candidate + break + if(isnull(template) || !template.width || !template.height) + stealth_test_say(feedback, "the scav den template is missing.", TRUE) + return null + + // strict_band: the guards read the zone from the planet's overmap square, so it must really be in that band. + var/obj/structure/overmap/planet/planet = SSovermap.spawn_dynamic_planet(/obj/structure/overmap/planet/jungle, 1, zone, strict_band = TRUE) + if(isnull(planet)) + stealth_test_say(feedback, "no free overmap square for a planet in that zone.", TRUE) + return null + // Kept until an admin unloads it, so a test run is not torn down while the tester walks around. + planet.preserve_level = TRUE + var/started = world.time + stealth_test_say(feedback, "building [planet.name] at overmap ([planet.x], [planet.y]), [list("green", "yellow", "red")[clamp(SSovermap_zones.get_zone_type_anywhere(get_turf(planet)) || ZONE_GREEN, ZONE_GREEN, ZONE_RED)]] zone. This takes about a minute.") + INVOKE_ASYNC(planet, TYPE_PROC_REF(/obj/structure/overmap/planet, load_level), feedback_mob, 5 MINUTES) + var/next_note = world.time + 30 SECONDS + while(!planet.loaded) + if(QDELETED(planet) || (!planet.loading && !planet.loaded)) + stealth_test_say(feedback, "the planet failed to build (see the mapping log).", TRUE) + return null + if(world.time > started + STEALTH_TEST_PLANET_TIMEOUT) + stealth_test_say(feedback, "gave up waiting for the planet after [DisplayTimeText(world.time - started)].", TRUE) + return null + if(world.time >= next_note) + next_note = world.time + 30 SECONDS + stealth_test_say(feedback, "still building ([DisplayTimeText(world.time - started)] so far).") + sleep(1 SECONDS) + var/datum/map_footprint/footprint = planet.footprint + var/z = footprint?.z_value + if(!z) + stealth_test_say(feedback, "the planet loaded without a footprint.", TRUE) + return null + stealth_test_say(feedback, "planet up in [DisplayTimeText(world.time - started)]. Loading the den.") + + if(!SSovermap.worldgen_claim(planet, "scav den test ([planet.name])", feedback_mob, 2 MINUTES)) + stealth_test_say(feedback, "the worldgen queue stayed busy; the planet is up but the den was not loaded.", TRUE) + return null + var/datum/space_level/level = SSmapping.get_level(z) + var/turf/center = stealth_test_pick_site(planet, level, template) + if(isnull(center)) + SSovermap.worldgen_release(planet) + stealth_test_say(feedback, "found no clear spot for the den on the planet.", TRUE) + return null + var/area/surface_area = get_area(center) + var/list/ruin_rect = stealth_test_ruin_rect(center, template) + stealth_test_clear_site(ruin_rect, z) + + // Loaded straight over the ground, the way try_to_place() loads a ruin once it has picked a spot. + planet_ruin_area_instancing_begin(z) + var/loaded = template.load(center, centered = TRUE) + planet_ruin_area_instancing_end(z) + if(!loaded) + SSovermap.worldgen_release(planet) + stealth_test_say(feedback, "the den failed to load at [center.x],[center.y].", TRUE) + return null + template.loaded++ + for(var/turf/ruin_turf as anything in template.get_affected_turfs(center, TRUE)) + ruin_turf.turf_flags |= NO_RUINS + new /obj/effect/landmark/ruin(center, template) + planet.generate_ruin_terrain(level) + planet.light_ruin_terrain(level, surface_area) + footprint.add_planetary_faction_to_existing_mobs() + stealth_test_prune_fauna(planet, ruin_rect) + SSovermap.worldgen_release(planet) + + // The guards come through the human NPC spawn queue a moment after the load. + var/list/door = stealth_test_door_coords(center, template) + var/turf/door_turf = locate(door[1], door[2], z) + var/guard_deadline = world.time + STEALTH_TEST_GUARD_WAIT + var/list/guards = stealth_test_guards_near(door_turf) + while(length(guards) < 8 && world.time < guard_deadline) + sleep(1 SECONDS) + guards = stealth_test_guards_near(door_turf) + + var/turf/arrival + for(var/south in list(5, 4, 6, 7)) + for(var/east in list(0, -1, 1, -2, 2)) + var/turf/spot = locate(door[1] + east, door[2] - south, z) + if(isnull(spot) || spot.is_blocked_turf(exclude_mobs = FALSE) || stealth_test_watched(spot, guards)) + continue + arrival = spot + break + if(arrival) + break + if(isnull(arrival)) + arrival = locate(door[1], door[2] - 5, z) + log_admin("Scav den test planet '[planet.name]' built: den at [center.x],[center.y],[z], [length(guards)] guards, [DisplayTimeText(world.time - started)].") + return arrival + +/proc/stealth_test_say(client/feedback, text, failed = FALSE) + if(feedback) + to_chat(feedback, failed ? span_warning("Stealth test: [text]") : span_notice("Stealth test: [text]")) + if(failed) + log_admin("Stealth test planet: [text]") + +/// list(low_x, low_y, high_x, high_y) of the ruin when loaded centred on `center` +/proc/stealth_test_ruin_rect(turf/center, datum/map_template/template) + var/low_x = center.x - round(template.width / 2) + var/low_y = center.y - round(template.height / 2) + return list(low_x, low_y, low_x + template.width - 1, low_y + template.height - 1) + +/// World x,y of the front airlock when the ruin is loaded centred on `center` +/proc/stealth_test_door_coords(turf/center, datum/map_template/template) + var/list/rect = stealth_test_ruin_rect(center, template) + return list(rect[1] + STEALTH_TEST_DOOR_X - 1, rect[2] + STEALTH_TEST_DOOR_Y - 1) + +/proc/stealth_test_block(list/rect, pad, z) + return block(rect[1] - pad, rect[2] - pad, z, rect[3] + pad, rect[4] + pad, z) + +/** + * The ruin's centre turf: the middle of the planet, moved up clear of the dock strip if needed, and kept far + * enough in that the ruin and its cleared margin sit at least STEALTH_TEST_EDGE tiles from the planet's edge. + * The load overwrites whatever is there. + */ +/proc/stealth_test_pick_site(obj/structure/overmap/planet/planet, datum/space_level/level, datum/map_template/template) + var/list/bounds = planet.get_terrain_bounds(level) + if(length(bounds) < 4) + return null + var/rect_pad = STEALTH_TEST_MARGIN + STEALTH_TEST_EDGE + var/half_w = round(template.width / 2) + var/half_h = round(template.height / 2) + var/min_x = bounds[1] + rect_pad + half_w + var/max_x = bounds[3] - rect_pad - (template.width - half_w - 1) + var/min_y = bounds[2] + rect_pad + half_h + var/max_y = bounds[4] - rect_pad - (template.height - half_h - 1) + if(min_x > max_x || min_y > max_y) + return null + var/center_x = round((bounds[1] + bounds[3]) / 2) + var/center_y = max(round((bounds[2] + bounds[4]) / 2), planet.get_dock_strip_top_y(level) + 1 + STEALTH_TEST_FAUNA_CLEARANCE + half_h) + return locate(clamp(center_x, min_x, max_x), clamp(center_y, min_y, max_y), level.z_value) + +/// Clears the ruin's block plus the margin to open jungle ground, and fauna and nests further out. +/proc/stealth_test_clear_site(list/rect, z) + for(var/turf/tile as anything in stealth_test_block(rect, STEALTH_TEST_SPAWNER_CLEARANCE, z)) + for(var/atom/movable/thing as anything in tile) + if(thing.GetComponent(/datum/component/spawner) || istype(thing, /obj/structure/spawner)) + qdel(thing) + CHECK_TICK + for(var/turf/tile as anything in stealth_test_block(rect, STEALTH_TEST_FAUNA_CLEARANCE, z)) + for(var/mob/living/critter in tile) + if(!critter.key && !critter.client) + qdel(critter) + CHECK_TICK + // Under the den and its margin, everything goes but the ground itself: items, structures, machines, + // flora, NPCs and anything a seeded ruin left there. Non-ground turfs (another ruin's walls or floors) + // become jungle grass. Players and abstract effects stay. + for(var/turf/tile as anything in stealth_test_block(rect, STEALTH_TEST_MARGIN, z)) + for(var/atom/movable/thing as anything in tile) + if(ismob(thing)) + var/mob/occupant = thing + if(occupant.key || occupant.client) + continue + else if(!isobj(thing) || istype(thing, /obj/effect/abstract)) + continue + qdel(thing) + if(!istype(tile, /turf/open/misc/grass) && !istype(tile, /turf/open/misc/dirt)) + tile.ChangeTurf(/turf/open/misc/grass/jungle) + CHECK_TICK + +/// Drops this planet's deferred fauna spawn points near the ruin. +/proc/stealth_test_prune_fauna(obj/structure/overmap/planet/planet, list/rect) + var/datum/planet_mob_tracker/tracker = SSplanet_mobs.tracked_planets[planet.planet_key] + if(isnull(tracker)) + return + var/pad = STEALTH_TEST_FAUNA_CLEARANCE + for(var/turf/tile as anything in tracker.surface_spawn_turfs.Copy()) + if(tile.x >= rect[1] - pad && tile.x <= rect[3] + pad && tile.y >= rect[2] - pad && tile.y <= rect[4] + pad) + tracker.surface_spawn_turfs -= tile + +/// Stealth guards near the front door +/proc/stealth_test_guards_near(turf/door_turf) + . = list() + if(isnull(door_turf)) + return + for(var/mob/living/guard as anything in stealth_guards_on_level(door_turf.z)) + if(get_dist(guard, door_turf) <= 30) + . += guard + +/// Whether any of `guards` has `spot` in its sight cone right now +/proc/stealth_test_watched(turf/spot, list/guards) + for(var/mob/living/guard as anything in guards) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + if(!istype(stealth_ai) || !stealth_ai.stealth_eyes_open()) + continue + var/datum/stealth_skill/profile = stealth_ai.stealth_skill() + var/turf/eye = get_turf(guard) + if(get_dist(eye, spot) > profile.sight_range) + continue + if(stealth_in_cone(guard, spot, stealth_ai.stealth_half_angle()) && can_see(eye, spot, profile.sight_range)) + return TRUE + return FALSE + +/** + * Gives `user` a mortal human body at `arrival` in the playtest kit. A living human is re-dressed and healed; + * a ghost, a lobby player or any other mob gets a new body from their character preferences. + */ +/proc/stealth_test_planet_body(client/user, turf/arrival) + var/mob/living/carbon/human/body = user.mob + if(ishuman(body) && body.stat != DEAD) + body.delete_equipment() + body.revive(ADMIN_HEAL_ALL) + body.forceMove(arrival) + else + body = new /mob/living/carbon/human(arrival) + user.prefs.safe_transfer_prefs_to(body, is_antag = TRUE) + body.PossessByPlayer(user.key) + stealth_test_dress(body) + return body + +/// Mortal and dressed in the playtest kit +/proc/stealth_test_dress(mob/living/carbon/human/body) + // Guards ignore godmode targets, so the tester must be mortal. + REMOVE_TRAIT(body, TRAIT_GODMODE, null) + body.equipOutfit(/datum/outfit/stealth_playtest) + +/// The stealth baseline: no night vision, no armour, no cloak. +/datum/outfit/stealth_playtest + name = "Stealth Playtest" + uniform = /obj/item/clothing/under/syndicate/camo + shoes = /obj/item/clothing/shoes/jackboots + gloves = /obj/item/clothing/gloves/fingerless + ears = /obj/item/radio/headset + id = /obj/item/card/id/advanced + id_trim = /datum/id_trim/admin + back = /obj/item/storage/backpack + backpack_contents = list( + /obj/item/gun/ballistic/automatic/pistol = 1, + /obj/item/ammo_box/magazine/m9mm = 3, + /obj/item/reagent_containers/cup/glass/bottle/beer = 3, + /obj/item/storage/medkit/regular = 1, + /obj/item/wirecutters = 1, + /obj/item/grenade/empgrenade = 1, + ) + belt = /obj/item/storage/belt/military + belt_contents = list( + /obj/item/grenade/empgrenade = 1, + /obj/item/grenade/flashbang = 1, + /obj/item/jammer = 1, + /obj/item/restraints/handcuffs/cable/zipties = 1, + /obj/item/weldingtool = 1, + /obj/item/crowbar = 1, + ) + l_pocket = /obj/item/knife/combat/matte + r_pocket = /obj/item/flashlight + +/datum/outfit/stealth_playtest/post_equip(mob/living/carbon/human/user, visuals_only = FALSE) + if(visuals_only) + return + var/obj/item/gun/ballistic/automatic/pistol/pistol = locate() in user.back + if(pistol && !pistol.suppressed) + var/obj/item/suppressor/suppressor = new(pistol) + pistol.install_suppressor(suppressor) + var/obj/item/card/id/card = user.wear_id + if(istype(card)) + card.registered_name = user.real_name + card.update_label() + +#undef STEALTH_TEST_MARGIN +#undef STEALTH_TEST_FAUNA_CLEARANCE +#undef STEALTH_TEST_SPAWNER_CLEARANCE +#undef STEALTH_TEST_EDGE +#undef STEALTH_TEST_PLANET_TIMEOUT +#undef STEALTH_TEST_GUARD_WAIT +#undef STEALTH_TEST_DOOR_X +#undef STEALTH_TEST_DOOR_Y diff --git a/voidcrew/modules/stealth/stealth_disguise.dm b/voidcrew/modules/stealth/stealth_disguise.dm new file mode 100644 index 00000000000..d76339ba8c8 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_disguise.dm @@ -0,0 +1,451 @@ +/** + * # Stealth guards: disguises (owner decision 40) + * + * Guards look at what someone wears. It is guard AI perception only: nothing here touches the wearer's body, and + * nothing but the stealth controller reads it, so a disguise does nothing against players or any other NPC. + * + * The pieces (STEALTH_PIECE_*): + * - clothing: the scavs' own fatigues, showing, with nothing over them but what the guards' own outfits wear over + * theirs (stealth_guard_suits()); + * - mask: tg's own "face hidden" (get_face_name() finds no face), whatever hides it; + * - ID: a scav pass where a door would read it (stealth_scav_pass()). + * + * A disguise holds for a guard while the clothing is on and the guard hasn't seen through it (stealth_fooled()). + * While it holds, notice fills slower by stage (stealth_look()), never jumps to an alert, and stops at suspicious, + * where the guard stops them and asks for their pass instead (stealth_challenge()). In the full set, beyond the + * guard's near range, they are one of its own: no notice, and a nod. + * + * What ends it for a guard (stealth_blow(), stealth_make()): a weapon in hand, pulling a fallen guard, an off-limits + * room, being seen laying hands on a guard, standing over a body as it is found, a failed challenge (running while + * stopped is one), and a face it has gone alert on before (a mask hides the face). The guard remembers faces for good + * and a blown disguise's wearer for STEALTH_MADE_TIME. Another guard knows only what it saw itself or what a shout or + * radio call that reached it carried (stealth_tell(), decision 44): nothing spreads through the group by itself. + * + * Cost: what someone wears is cached on them (/datum/component/stealth_disguise) and thrown away when they put + * anything on or take anything off; a guard's scan reads two numbers and a list or two. + */ + +// ===== The pieces ===== + +/// The scavs' own clothes: the only uniform guards take for theirs. +/obj/item/clothing/under/syndicate/scav + name = "scav fatigues" + desc = "A patched black turtleneck and cargo trousers. Half the den wears the same pair." + +/obj/item/clothing/mask/balaclava/scav + name = "scav balaclava" + desc = "A black balaclava that has seen a lot of dust." + +/// A guard's card. It opens the den's own doors (ACCESS_SCAV). +/obj/item/card/id/advanced/black/scav + name = "scav pass" + desc = "A scratched black card on a cord, punched with a den's mark." + assignment = "Scav" + access = list(ACCESS_SCAV) + +/obj/item/card/id/advanced/black/scav/update_label() + name = initial(name) + +/// The suit types the guards' own outfits wear over their fatigues: type => TRUE. Read from the scav types' outfit +/// tables, so a new dress is picked up. Not kept in a static: the unit test build has no room for one more +/// (data/stealth/STATUS.md, "Decision 40"), and it is only asked for someone wearing a suit over the fatigues. +/proc/stealth_guard_suits() + var/list/suits = list() + for(var/mob/living/carbon/human/npc/guard_type as anything in typesof(/mob/living/carbon/human/npc/ruin/trooper/scav)) + var/table_type = initial(guard_type.npc_outfit_table) + if(!ispath(table_type, /datum/human_npc_outfit_table)) + continue + var/datum/human_npc_outfit_table/table = human_npc_singleton(table_type) + for(var/list/outfits as anything in list(table.green, table.yellow, table.red)) + for(var/datum/outfit/outfit as anything in outfits) + var/suit = initial(outfit.suit) + if(suit) + suits[suit] = TRUE + return suits + +/// What a human wears of the scavs' own, kept until they change clothes. +/datum/component/stealth_disguise + /// STEALTH_PIECE_* flags, or null when they have changed since it was last worked out + var/pieces + /// The name tg reads off their face, or "" when it can't be seen + var/face + /// world.time it was last worked out + var/checked_at = 0 + +/datum/component/stealth_disguise/Initialize() + if(!ishuman(parent)) + return COMPONENT_INCOMPATIBLE + +/datum/component/stealth_disguise/RegisterWithParent() + RegisterSignals(parent, list(COMSIG_MOB_EQUIPPED_ITEM, COMSIG_MOB_UNEQUIPPED_ITEM), PROC_REF(on_change)) + +/datum/component/stealth_disguise/UnregisterFromParent() + UnregisterSignal(parent, list(COMSIG_MOB_EQUIPPED_ITEM, COMSIG_MOB_UNEQUIPPED_ITEM)) + +/datum/component/stealth_disguise/proc/on_change(datum/source) + SIGNAL_HANDLER + pieces = null + +/datum/component/stealth_disguise/proc/refresh() + var/mob/living/carbon/human/wearer = parent + checked_at = world.time + face = wearer.get_face_name("") + pieces = face ? NONE : STEALTH_PIECE_MASK + if(istype(wearer.w_uniform, /obj/item/clothing/under/syndicate/scav) && !(wearer.check_obscured_slots() & ITEM_SLOT_ICLOTHING)) + if(isnull(wearer.wear_suit) || stealth_guard_suits()[wearer.wear_suit.type]) + pieces |= STEALTH_PIECE_CLOTHES + if(stealth_scav_pass(wearer)) + pieces |= STEALTH_PIECE_ID + +/** + * The scav pass `who` carries where a door reads a card (tg's get_idcard(): a hand, the ID slot, the belt), a wallet + * read as a door reads it (any card in it) and a PDA by the card in it. Null if none: one in a bag never shows. + */ +/proc/stealth_scav_pass(mob/living/carbon/human/who) + for(var/obj/item/place in who.held_items + list(who.wear_id, who.belt)) + if(istype(place, /obj/item/storage/wallet)) + var/obj/item/card/id/advanced/black/scav/in_wallet = locate() in place + if(in_wallet) + return in_wallet + continue + var/obj/item/card/id/card = place.GetID() + if(istype(card, /obj/item/card/id/advanced/black/scav)) + return card + return null + +/// The cache on `who`, worked out afresh if they changed clothes or it is older than STEALTH_DISGUISE_CACHE_TIME +/// (a mask pulled down, a face wrecked). Null for anyone but a human. +/proc/stealth_disguise_cache(mob/living/carbon/human/who) + if(!ishuman(who)) + return null + var/datum/component/stealth_disguise/cache = who.GetComponent(/datum/component/stealth_disguise) || who.AddComponent(/datum/component/stealth_disguise) + if(isnull(cache.pieces) || world.time - cache.checked_at > STEALTH_DISGUISE_CACHE_TIME) + cache.refresh() + return cache + +/// What `who` wears of the scavs' own: STEALTH_PIECE_* flags, 0 for anyone but a human. +/proc/stealth_disguise_of(mob/living/who) + var/datum/component/stealth_disguise/cache = stealth_disguise_cache(who) + return cache ? cache.pieces : NONE + +/// The stage of `pieces`, for admins and tests: 0 nothing, 1 mask, 2 clothing, 3 clothing and mask, 4 with the pass too. +/proc/stealth_disguise_stage(pieces) + if(!(pieces & STEALTH_PIECE_CLOTHES)) + return (pieces & STEALTH_PIECE_MASK) ? 1 : 0 + if(!(pieces & STEALTH_PIECE_MASK)) + return 2 + return (pieces & STEALTH_PIECE_ID) ? 4 : 3 + +// ===== Off-limits rooms ===== + +/// Marks the room it stands in as off limits: a disguise seen in it is blown. Its room is every open tile it can +/// reach within `reach` without passing a door, a window or a grille. +/obj/effect/landmark/stealth_restricted + name = "stealth off-limits room" + icon_state = "x2" + /// Tiles from here its room is followed, at most + var/reach = 6 + /// Whether wearing a scav pass excuses being here + var/allowed = TRUE + +/datum/stealth_group + /// Off-limits turf => whether a pass excuses being there. Null until first asked for. + var/list/restricted + +/// Its off-limits tiles, worked out once from the marks in its region. +/datum/stealth_group/proc/off_limits() + if(!isnull(restricted)) + return restricted + restricted = list() + for(var/obj/effect/landmark/stealth_restricted/mark in GLOB.landmarks_list) + var/turf/origin = get_turf(mark) + if(isnull(origin) || origin.z != home?.z || get_dist(origin, home) > STEALTH_GROUP_RADIUS || !region_matches(origin)) + continue + var/list/frontier = list(origin) + restricted[origin] = mark.allowed + while(length(frontier)) + var/turf/here = frontier[1] + frontier.Cut(1, 2) + for(var/turf/open/next as anything in get_adjacent_open_turfs(here)) + if(!isnull(restricted[next]) || get_dist(next, origin) > mark.reach) + continue + if((locate(/obj/machinery/door) in next) || (locate(/obj/structure/window) in next) || (locate(/obj/structure/grille) in next)) + continue + restricted[next] = mark.allowed + frontier += next + return restricted + +/// One of its guards has been touched or hit by `attacker`: every other guard that sees them do it in a disguise +/// that still held sees through it. +/datum/stealth_group/proc/witness(mob/living/attacker, mob/living/victim) + if(!(stealth_disguise_of(attacker) & STEALTH_PIECE_CLOTHES)) + return + for(var/mob/living/friend as anything in living_members()) + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = friend.ai_controller + if(friend == victim || !istype(friend_ai) || friend.client || friend_ai.stealth_captive()) + continue + if(friend_ai.stealth_fooled(attacker) && friend_ai.stealth_sees(attacker)) + friend_ai.stealth_blow(attacker) + +// ===== The guard's side ===== + +/datum/ai_controller/basic_controller/human_npc/stealth + /// Face name => TRUE, or REF(mob) => world.time the mark runs out: disguises it has seen through itself + var/list/made + /// REF(mob) => world.time until which it lets them be, after it checked their pass + var/list/passes + /// REF(mob) => list of world.time it waved them on after reading their pass (stealth_rechecked()) + var/list/waved + /// Weakref to whoever it has stopped to check + var/datum/weakref/challenge + /// Where they stood when it stopped them + var/turf/start_turf + /// world.time it got near enough to look at their pass, or 0 + var/checked_at = 0 + /// Whether it has asked a second time + var/warned = FALSE + /// world.time it may next greet one of its own + var/greeted = 0 + +/// Whether it sees through `who`: it knows the face, or the wearer of a disguise it saw blown or was told of. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_knows(mob/living/who) + if(!made) + return FALSE + var/datum/component/stealth_disguise/cache = stealth_disguise_cache(who) + if(isnull(cache)) + return FALSE + var/face = cache.face + return !!((face && made[face]) || made[REF(who)] > world.time) + +/** + * A shout or a radio call of its reached `listener` (dispatch_shout(), radio_call()): the faces it knows and the + * disguises it saw through go with it (decision 44). Nothing else passes word between guards. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_tell(datum/ai_controller/basic_controller/human_npc/stealth/listener) + if(!made || !istype(listener) || listener == src) + return + for(var/key in made) + var/mark = made[key] + if(mark == TRUE) + LAZYSET(listener.made, key, TRUE) + continue + if(mark <= world.time || listener.made?[key] >= mark) + continue + LAZYSET(listener.made, key, mark) + if(listener.passes) + listener.passes -= key + +/// `who`'s STEALTH_PIECE_* flags if their disguise holds for this guard: the clothing is on and it hasn't seen +/// through them. 0 otherwise. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_fooled(mob/living/who) + var/pieces = stealth_disguise_of(who) + if(!(pieces & STEALTH_PIECE_CLOTHES) || stealth_knows(who)) + return NONE + return pieces + +/** + * Remembers `who`, seen with its own eyes: their face for good, if it shows. `blown`: also the wearer, face or no + * face, for STEALTH_MADE_TIME (a disguise it saw through; a mask won't fix that). Only it knows, until it tells + * someone (stealth_tell()). + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_make(mob/living/who, blown = TRUE) + var/datum/component/stealth_disguise/cache = stealth_disguise_cache(who) + if(isnull(cache)) + return + var/key = REF(who) + if(cache.face) + LAZYSET(made, cache.face, TRUE) + if(!blown) + return + LAZYSET(made, key, world.time + STEALTH_MADE_TIME) + if(passes) + passes -= key + +/// Whether it sees `who` plainly now: eyes open, in its cone, in the light it needs, nothing in the way. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_sees(mob/living/who) + var/mob/living/guard = pawn + var/turf/where = who.loc + if(!isturf(where) || !isturf(guard.loc) || guard.stat != CONSCIOUS || !stealth_eyes_open() || stealth_is_cloaked(who)) + return FALSE + var/dist = get_dist(guard, where) + if(dist > STEALTH_ADJACENT_RANGE && dist > stealth_range_onto(where)) + return FALSE + if(!stealth_in_cone(guard, where, stealth_half_angle())) + return FALSE + var/datum/targeting_strategy/strategy = GET_TARGETING_STRATEGY(blackboard[BB_TARGETING_STRATEGY]) + return !!strategy?.can_attack(guard, who, stealth_skill().sight_range) + +/// Whether `who`, seen on `where` in a disguise of `pieces`, is doing something no guard of the den would: a weapon +/// in hand, pulling a fallen guard, or standing in an off-limits room the pass doesn't excuse. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_breaker(mob/living/carbon/human/who, pieces, turf/where) + for(var/obj/item/held in who.held_items) + if(isgun(held) || istype(held, /obj/item/melee) || (held.force >= STEALTH_WEAPON_FORCE && held.get_sharpness())) + return TRUE + var/mob/living/pulled = who.pulling + var/mob/living/guard = pawn + if(isliving(pulled) && guard.faction_check_atom(pulled) && (pulled.stat != CONSCIOUS || pulled.body_position == LYING_DOWN || HAS_TRAIT(pulled, TRAIT_RESTRAINED))) + return TRUE + var/list/rooms = group?.off_limits() + var/excused = rooms?[where] + return !isnull(excused) && !(excused && (pieces & STEALTH_PIECE_ID)) + +/** + * It has seen through `who`. It remembers them, says so, and goes alert if they are near enough to be sure of and + * can be fought. Already fighting someone, it only remembers them. Returns TRUE if it went alert on them. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_blow(mob/living/who) + var/mob/living/guard = pawn + stealth_make(who) + challenge = null + start_turf = null + if(stealth_state() == STEALTH_ALERT) + stealth_remember(who) + return FALSE + stealth_bark(STEALTH_BARK_BLOWN, null, null, TRUE) + var/datum/targeting_strategy/strategy = GET_TARGETING_STRATEGY(blackboard[BB_TARGETING_STRATEGY]) + if(get_dist(guard, who) > stealth_skill().alert_max_range || !strategy?.can_attack(guard, who, HUMAN_NPC_SIGHT_RANGE)) + return FALSE + stealth_go_alert(bounty_ai_target_for(who)) + return stealth_state() == STEALTH_ALERT + +/// The tiles within which it stops someone in a disguise of `pieces` that it sees plainly. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_challenge_range(pieces) + . = STEALTH_CHALLENGE_RANGE_CLOTHES + if(pieces & STEALTH_PIECE_MASK) + . = (pieces & STEALTH_PIECE_ID) ? STEALTH_CHALLENGE_RANGE_FULL : STEALTH_CHALLENGE_RANGE_MASKED + . = max(1, . + stealth_skill().challenge + (blackboard[BB_STEALTH_WARY] ? 1 : 0)) + +/// How much of its usual notice someone in a disguise of `pieces` gains at `dist` tiles. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_disguise_mult(pieces, dist) + var/datum/stealth_skill/profile = stealth_skill() + if(!(pieces & STEALTH_PIECE_MASK)) + return STEALTH_DISGUISE_FILL_CLOTHES * profile.disguise + if(!(pieces & STEALTH_PIECE_ID)) + return STEALTH_DISGUISE_FILL_MASKED * profile.disguise + // The whole set: one of its own at a distance, whatever its skill. + return dist > profile.near_range ? 0 : STEALTH_DISGUISE_FILL_FULL * profile.disguise + +/// The name on the pass `who` wears, if it is one of its group's own: what its friends called them. An NPC's +/// name, never player text; null for a pass in nobody's name or a guard with only its type's name. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_card_name(mob/living/carbon/human/who) + var/obj/item/card/id/card = ishuman(who) ? (stealth_scav_pass(who) || who.wear_id?.GetID()) : null + if(!istype(card) || !card.registered_name) + return null + for(var/mob/living/carbon/human/npc/friend as anything in group?.living_members()) + if(friend != pawn && friend.real_name == card.registered_name) + return stealth_first_name(friend) + return null + +/// One of its own goes by (so it thinks): a nod or a word, now and then. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_greet(mob/living/who) + if(world.time < greeted || stealth_state() != STEALTH_UNAWARE) + return + greeted = world.time + STEALTH_GREET_COOLDOWN + stealth_bark(prob(25) ? STEALTH_BARK_SMOKE : STEALTH_BARK_GREET, null, stealth_card_name(who)) + +/** + * Whether stopping the one under `key` again is a stop too many: it waved them on within + * STEALTH_PASS_RECHECK_COOLDOWN, or STEALTH_PASS_RECHECK_MAX times within STEALTH_PASS_RECHECK_MEMORY. The same shape + * as a door's cue throttle (stealth_doors.dm), so taking the pass off and on can't pull a guard over again and again. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_rechecked(key) + var/list/stamps = waved?[key] + if(!stamps) + return FALSE + for(var/index in length(stamps) to 1 step -1) + if(world.time - stamps[index] > STEALTH_PASS_RECHECK_MEMORY) + stamps.Cut(index, index + 1) + if(!length(stamps)) + LAZYREMOVE(waved, key) + return FALSE + return length(stamps) >= STEALTH_PASS_RECHECK_MAX || world.time - stamps[length(stamps)] < STEALTH_PASS_RECHECK_COOLDOWN + +/** + * Stops `who` to see their pass: suspicious of them, facing and pointing at them, with the challenge line. From + * here stealth_check_challenge() decides, once a scan. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_challenge(mob/living/who) + var/mob/living/guard = pawn + if(QDELETED(who) || stealth_driven() || stealth_state() == STEALTH_ALERT || challenge?.resolve() == who) + return + // Waved on a moment ago, or too often: a pass that keeps coming off is no pass (decision 40 throttle). + if(stealth_rechecked(REF(who))) + stealth_blow(who) + return + var/turf/where = get_turf(who) + if(stealth_state() == STEALTH_SUSPICIOUS) + investigated = FALSE + stealth_drop_walk() + stealth_aim_at(where) + stealth_bark(STEALTH_BARK_CHALLENGE, null, null, TRUE) + else + // The line always comes with the stop. + bark_ready_at -= STEALTH_BARK_CHALLENGE + stealth_go_suspicious(where, STEALTH_GOTO_INVESTIGATE, STEALTH_BARK_CHALLENGE) + if(stealth_state() != STEALTH_SUSPICIOUS) + return + challenge = WEAKREF(who) + start_turf = where + checked_at = 0 + warned = FALSE + suspicion_heard = FALSE + goto_purpose = STEALTH_GOTO_INVESTIGATE + stealth_remember(who) + notice_map[REF(who)][STEALTH_ENTRY_NOTICE] = STEALTH_SUSPICIOUS_AT + set_blackboard_key(BB_STEALTH_FOCUS, who) + INVOKE_ASYNC(guard, TYPE_PROC_REF(/mob, _pointed), who) + stealth_meter_update() + +/** + * The scan, while it has someone stopped. Blown: the clothing is off, it knows them now, they run, they are more + * than STEALTH_CHALLENGE_LEASH from where it stopped them, it can't see them, they do what no guard would, or + * they still show no pass STEALTH_CHALLENGE_FAIL_TIME after it got to them. Passed: the pass is on them and it has + * looked at it for STEALTH_CHALLENGE_CHECK_TIME from within STEALTH_CHALLENGE_CHECK_RANGE. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_check_challenge() + var/mob/living/carbon/human/who = challenge?.resolve() + if(isnull(who)) + challenge = null + return + var/mob/living/guard = pawn + if(QDELETED(who) || who.stat == DEAD || stealth_state() != STEALTH_SUSPICIOUS) + challenge = null + start_turf = null + return + var/key = REF(who) + var/list/entry = notice_map[key] + var/turf/where = get_turf(who) + var/pieces = stealth_fooled(who) + // It keeps its eyes on them. + if(get_turf(guard) != where) + stand_dir = stealth_dir_to(guard, where) + guard.setDir(stand_dir) + var/ran = who.move_intent == MOVE_INTENT_RUN && entry && entry[STEALTH_ENTRY_TURF] != where + var/late = checked_at && !(pieces & STEALTH_PIECE_ID) && world.time - checked_at >= STEALTH_CHALLENGE_FAIL_TIME + if(!pieces || ran || late || get_dist(where, start_turf) > STEALTH_CHALLENGE_LEASH || !stealth_sees(who) || stealth_breaker(who, pieces, where)) + if(!stealth_blow(who) && stealth_state() == STEALTH_SUSPICIOUS) + stealth_go_searching(where) + stealth_first_hand(where) + return + last_gain = world.time + investigate_turf = where + last_seen_turf = where + stealth_remember(who) + notice_map[key][STEALTH_ENTRY_NOTICE] = STEALTH_SUSPICIOUS_AT + if(get_dist(guard, where) > STEALTH_CHALLENGE_CHECK_RANGE) + return + if(!checked_at) + checked_at = world.time + if(pieces & STEALTH_PIECE_ID) + if(world.time - checked_at < STEALTH_CHALLENGE_CHECK_TIME) + return + stealth_bark(STEALTH_BARK_ID_PASS, null, stealth_card_name(who), TRUE) + // Waving them on is the greeting: no nod straight after it. + greeted = world.time + STEALTH_GREET_COOLDOWN + LAZYSET(passes, key, world.time + STEALTH_PASS_TIME) + LAZYADDASSOCLIST(waved, key, world.time) + stealth_go_unaware() + return + if(!warned && world.time - checked_at >= STEALTH_CHALLENGE_WARN_TIME) + warned = TRUE + stealth_bark(STEALTH_BARK_ID_FAIL, null, null, TRUE) diff --git a/voidcrew/modules/stealth/stealth_doors.dm b/voidcrew/modules/stealth/stealth_doors.dm new file mode 100644 index 00000000000..f83846dc109 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_doors.dm @@ -0,0 +1,170 @@ +/** + * # Stealth guards: doors (owner decision 37) + * + * Every door a player opens or shuts makes a small noise (STEALTH_NOISE_DOOR: those who hear it glance), and a + * guard who sees one move in its cone is suspicious and goes to look. The door's own movement is the cue, so it + * works without seeing who moved it. + * + * Doors: airlocks, windoors, shutters and blast doors (every /obj/machinery/door through tg's run_animation()), + * and mineral and wooden doors (their Open() and Close()). Firelocks are left out: they move by themselves on + * every air alarm, and tg plays no sound for them. + * + * Their own doors: a door that moves with one of the group beside it is theirs, and so is its next close within + * STEALTH_DOOR_GUARD_MEMORY (an airlock a guard walked through shuts itself 6 s later, when it is far off). + * + * In the dark a guard sees a door move out to its dark sight range, in the light out to its full sight range: + * a door is no easier to make out in the dark than a person. + * + * Throttle: a door that sent someone to look only gets glances for STEALTH_DOOR_CUE_COOLDOWN, and after + * STEALTH_DOOR_CUE_MAX looks within STEALTH_DOOR_CUE_MEMORY it is ignored for the rest of that time, so a door + * cycling by itself can't keep a guard walking back and forth. The noise is coalesced as any noise is. + * + * Cost: one length() check while no stealth group is alive; otherwise one look per guard of a group on that level. + */ + +/datum/stealth_group + /// REF(door) => world.time one of the group was beside it when it moved + var/list/door_guard_used = list() + /// REF(door) => list of world.time it sent someone to look + var/list/door_cues = list() + +// Opening and closing, on every machinery door. Firelocks excepted (see above). +/obj/machinery/door/run_animation(animation, force_type = DEFAULT_DOOR_CHECKS) + . = ..() + if(!length(GLOB.stealth_groups) || istype(src, /obj/machinery/door/firedoor)) + return + if(animation != DOOR_OPENING_ANIMATION && animation != DOOR_CLOSING_ANIMATION) + return + // Forced open with a crowbar or the like: that is already a bash (stealth_noise_sources.dm). + stealth_door_moved(src, animation == DOOR_OPENING_ANIMATION, force_type != BYPASS_DOOR_CHECKS) + +/obj/structure/mineral_door/Open() + if(length(GLOB.stealth_groups) && !door_opened) + stealth_door_moved(src, TRUE) + return ..() + +/obj/structure/mineral_door/Close() + // tg's Close() does nothing while it is moving, already shut, or someone stands in the doorway. + if(length(GLOB.stealth_groups) && !isSwitchingStates && door_opened && !(locate(/mob/living) in get_turf(src))) + stealth_door_moved(src, FALSE) + return ..() + +/** + * `door` began to open (`opening`) or close. Its noise (unless `noisy` is off), then the guards that see it. + * Returns the number of guards sent to look (tests). + */ +/proc/stealth_door_moved(atom/door, opening, noisy = TRUE) + . = 0 + if(!length(GLOB.stealth_groups)) + return + var/turf/where = get_turf(door) + if(isnull(where)) + return + // Nobody to play for: guards sleep with their level. + if(where.z > length(SSmobs.clients_by_zlevel) || !length(SSmobs.clients_by_zlevel[where.z])) + return + var/key = REF(door) + for(var/datum/stealth_group/group as anything in GLOB.stealth_groups.Copy()) + if(QDELETED(group) || group.home?.z != where.z || !group.region_matches(where)) + continue + if(group.door_is_theirs(key, where, opening)) + continue + if(noisy) + stealth_noise(door, STEALTH_NOISE_DOOR, null, null, group) + . += group.door_seen(key, where) + +/// Whether a door moving at `where` is one of their own going through: one of them beside it, or the close +/// that follows such an opening. Remembers the opening. +/datum/stealth_group/proc/door_is_theirs(key, turf/where, opening) + for(var/stamped in door_guard_used) + if(world.time - door_guard_used[stamped] > STEALTH_DOOR_GUARD_MEMORY) + door_guard_used -= stamped + if(member_beside(where, living_members())) + door_guard_used[key] = world.time + return TRUE + if(!opening && door_guard_used[key]) + door_guard_used -= key + return TRUE + return FALSE + +/** + * The guards who see a door move at `where`: the nearest one free to look goes (suspicious, as at a sighting), + * a searching one moves its search there, the rest of the unaware ones glance. Returns how many went. + */ +/datum/stealth_group/proc/door_seen(key, turf/where) + . = 0 + var/list/stamps = door_cues[key] + if(stamps) + for(var/index in length(stamps) to 1 step -1) + if(world.time - stamps[index] > STEALTH_DOOR_CUE_MEMORY) + stamps.Cut(index, index + 1) + if(!length(stamps)) + door_cues -= key + stamps = null + var/throttled = length(stamps) && (length(stamps) >= STEALTH_DOOR_CUE_MAX || world.time - stamps[length(stamps)] < STEALTH_DOOR_CUE_COOLDOWN) + // Nearest first. + var/list/seers = list() + for(var/mob/living/carbon/human/npc/guard as anything in living_members()) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + if(!istype(guard_ai) || !guard_ai.stealth_sees_door(where)) + continue + // Someone it takes for one of its own at the door: nothing to look at (decision 40). + var/own = FALSE + for(var/mob/living/carbon/human/near in range(1, where)) + if(!guard.faction_check_atom(near) && guard_ai.stealth_fooled(near)) + own = TRUE + break + if(own) + continue + var/dist = get_dist(guard, where) + var/index = 1 + while(index <= length(seers) && get_dist(seers[index], where) <= dist) + index++ + seers.Insert(index, guard) + var/went = FALSE + for(var/mob/living/carbon/human/npc/guard as anything in seers) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + var/turf/spot = stealth_hear_spot(where, get_turf(guard)) + if(!throttled && !went && guard_ai.stealth_can_investigate()) + went = TRUE + guard_ai.stealth_door_look(spot) + .++ + continue + switch(guard_ai.stealth_state()) + if(STEALTH_UNAWARE) + guard_ai.stealth_glance(spot) + if(STEALTH_SEARCHING) + if(!throttled && guard_ai.stealth_respond(spot)) + went = TRUE + .++ + if(went) + LAZYADDASSOCLIST(door_cues, key, world.time) + +/// Whether it sees a door move at `where` now: awake, its eyes open, not fighting, in its cone, in view, and +/// within its sight range onto that spot (shorter in the dark). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_sees_door(turf/where) + var/mob/living/guard = pawn + if(QDELETED(guard) || guard.stat != CONSCIOUS || guard.client || ai_status == AI_STATUS_OFF) + return FALSE + if(!isturf(guard.loc) || stealth_captive() || blackboard_key_exists(BB_HUMAN_NPC_EXIT)) + return FALSE + if(!stealth_ready || stealth_state() == STEALTH_ALERT || !stealth_eyes_open()) + return FALSE + var/dist = get_dist(guard, where) + if(dist < 1 || dist > stealth_range_onto(where)) + return FALSE + if(!stealth_in_cone(guard, where, stealth_half_angle())) + return FALSE + return can_see(guard, where, stealth_skill().sight_range) + +/// It saw a door move: suspicious of `spot`, the side of the door it is on, as at a sighting. Already +/// suspicious and not yet on its way, it turns there instead. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_door_look(turf/spot) + if(isnull(spot) || stealth_driven()) + return + if(stealth_state() == STEALTH_SUSPICIOUS) + last_gain = world.time + if(!investigated) + stealth_aim_at(spot) + return + stealth_go_suspicious(spot) diff --git a/voidcrew/modules/stealth/stealth_hearing.dm b/voidcrew/modules/stealth/stealth_hearing.dm new file mode 100644 index 00000000000..cd4e4d41df2 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_hearing.dm @@ -0,0 +1,249 @@ +/** + * # Stealth guards: what a guard does about what it hears + * + * The group decides who goes (stealth_noise.dm); these are the things one guard can be told to do, the + * shout that passes first-hand knowledge on by earshot, and the footsteps its own scan listens for. + * + * - stealth_go_heard(): suspicious of a noise. The same stare, walk over and look round as a sighting, with + * a heard line and the grey "?" (stealth_meter.dm). It never makes a guard wary by itself. + * - stealth_glance(): turns to face a noise for a moment without leaving its state, route or post. + * - stealth_hold(): stays where it is, wary, facing the noise. + * - stealth_respond(): runs to a spot and searches there (an alarm, a shout, a radio call, a missing friend). + * - stealth_shout(): calls for help. Only for what it learned first hand: a guard that came because of a + * shout or a call never shouts onward, so one sighting can't chain the whole den awake. + * + * Footsteps (owner decision 13) follow tg's own rules: walking is silent, running is heard, and anything + * that silences a player's steps for players silences them for guards (stealth_footstep_reach()). They are + * pulled by the guard's scan, so a walker pays nothing per step. Steps alone can make a guard turn and + * look, never alert. + */ +/datum/ai_controller/basic_controller/human_npc/stealth + /// Suspicious because of a noise, not a sighting: it shows the grey "?" + var/suspicion_heard = FALSE + /// world.time its glance at a noise ends + var/glance_until = 0 + /// The way it glances + var/glance_dir = SOUTH + /// REF(mob) => the turf it stood on at the last scan, for everyone in earshot of a footstep + var/list/heard_map + /// REF(mob) => TRUE for everyone whose steps it heard this scan (their notice doesn't decay) + var/list/heard_now + /// Its radio call on the way out: list(kind, turf, world.time due, name), or null + var/list/pending_call + /// world.time it may next shout for help + var/next_shout = 0 + /// world.time its search may next move to a newer noise + var/next_recentre = 0 + /// list(noise kind, world.time) of the last thing it heard, for admins + var/list/last_heard + +/// Whether it can be sent to look at a noise: unaware, or suspicious and not yet on its way. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_can_investigate() + switch(stealth_state()) + if(STEALTH_UNAWARE) + return TRUE + if(STEALTH_SUSPICIOUS) + return !investigated && isnull(goto_dest) && goto_purpose != STEALTH_GOTO_BODY + return FALSE + +/// Heard something worth a look at `where`. Suspicious with the heard flag set: same stare, walk and look +/// round as a sighting, a heard line instead of "Hm?", and the heard mark. Already suspicious, it re-aims. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_go_heard(turf/where, again = FALSE) + var/turf/spot = stealth_hear_spot(where, get_turf(pawn)) + if(isnull(spot) || stealth_driven()) + return + if(stealth_state() == STEALTH_SUSPICIOUS) + last_gain = world.time + if(investigated) + return + stealth_aim_at(spot) + else + stealth_go_suspicious(spot, STEALTH_GOTO_INVESTIGATE, again ? STEALTH_BARK_HEARD_AGAIN : STEALTH_BARK_HEARD) + suspicion_heard = TRUE + stealth_meter_update() + // A sentry walks only a few steps toward it, looks round there and goes back to its post and facing. + var/turf/home = home_turf + if(isnull(route_id) && home && investigate_turf?.z == home.z && get_dist(home, investigate_turf) > STEALTH_SENTRY_INVESTIGATE_RANGE) + investigate_turf = stealth_open_near(get_ranged_target_turf_direct(home, investigate_turf, STEALTH_SENTRY_INVESTIGATE_RANGE)) || home + +/// Turns to face `where` for `time` without leaving its state, route or post. No line: the turn is the read. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_glance(turf/where, time = STEALTH_GLANCE_TIME) + var/mob/living/guard = pawn + if(isnull(where) || stealth_driven() || get_turf(guard) == where) + return + glance_dir = stealth_dir_to(guard, where) + glance_until = max(glance_until, world.time + time) + if(stealth_state() == STEALTH_UNAWARE && !blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET)) + stealth_drop_walk() + guard.setDir(glance_dir) + +/// Stays where it is, wary, facing `where` (sentries, and guards past the responder cap). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_hold(turf/where) + if(stealth_driven()) + return + stealth_set_wary() + if(stealth_state() != STEALTH_UNAWARE) + return + stealth_glance(where, STEALTH_HOLD_TIME) + stealth_bark(STEALTH_BARK_HOLD) + +/** + * Runs to `where` and searches there: an alarm, a friend's shout, a radio call, a missing friend. Wary. + * Not while it fights. Already searching, it moves its search there only if that is somewhere else, and at + * most once per STEALTH_RECENTRE_COOLDOWN. Returns TRUE if it is now searching at or near `where`. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_respond(turf/where) + var/mob/living/guard = pawn + if(isnull(where) || QDELETED(guard) || guard.stat != CONSCIOUS || stealth_driven()) + return FALSE + if(stealth_state() == STEALTH_ALERT || blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET)) + return FALSE + var/turf/spot = stealth_hear_spot(where, get_turf(guard)) + if(stealth_state() == STEALTH_SEARCHING && !calm_until) + if(search_center && get_dist(search_center, spot) <= STEALTH_SEARCH_RADIUS) + return TRUE + if(world.time < next_recentre) + return FALSE + next_recentre = world.time + STEALTH_RECENTRE_COOLDOWN + stealth_go_searching(spot) + return TRUE + +/// Calls for help: a noise its own group hears. It has to be able to speak (tg's can_speak()), so a muted +/// or muzzled guard calls nobody. At most once per STEALTH_SHOUT_INTERVAL. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_shout() + var/mob/living/guard = pawn + if(world.time < next_shout || QDELETED(guard) || stealth_driven() || !human_npc_can_talk(guard)) + return FALSE + next_shout = world.time + STEALTH_SHOUT_INTERVAL + stealth_noise(guard, STEALTH_NOISE_SHOUT, null, guard) + return TRUE + +/// It has just learned something first hand at `where` (a sighting, a touch, a hit from nowhere, a body): +/// it shouts, and calls it in if it carries a radio. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_first_hand(turf/where) + var/mob/living/carbon/human/npc/guard = pawn + if(QDELETED(guard) || guard.stat != CONSCIOUS || stealth_driven() || !stealth_ready) + return + stealth_shout() + if(ishumannpc(guard) && guard.stealth_radio) + stealth_start_call(STEALTH_CALL_ALARM, where || get_turf(guard)) + +// ===== Footsteps ===== + +/** + * How far `walker`'s last step carried to a guard, in tiles, by tg's own footstep rules (the footstep + * element's prepare_step() and play_humanstep()). 0 for silent: walking, silent shoes or any other source of + * TRAIT_SILENT_FOOTSTEPS, in a box, a locker or a mech, buckled, thrown, flying, crawling in a vent, held + * still, or on a turf with no footstep sound. + * + * A running step on plain floor in shoes carries STEALTH_FOOTSTEP_RANGE. Any other floor or footwear scales + * that by how far tg plays its sound to players compared with the plain one (tg's own tables: plating and + * wood ring a little further, bare feet on carpet and the Light Step quirk a little less). A living mob that + * is not a carbon counts as running whenever it moves. + */ +/proc/stealth_footstep_reach(mob/living/walker) + if(SHOULD_DISABLE_FOOTSTEPS(walker)) + return 0 + var/turf/open/ground = walker.loc + if(!istype(ground) || isnull(ground.footstep)) + return 0 + if(walker.buckled || walker.throwing || (walker.movement_type & (VENTCRAWLING | FLYING)) || HAS_TRAIT(walker, TRAIT_IMMOBILIZED)) + return 0 + if(walker.body_position == LYING_DOWN) + return STEALTH_FOOTSTEP_CRAWL_RANGE + if(!iscarbon(walker)) + return STEALTH_FOOTSTEP_RANGE + if(walker.move_intent == MOVE_INTENT_WALK) + return 0 + if(!ishuman(walker)) + return STEALTH_FOOTSTEP_RANGE + var/mob/living/carbon/human/person = walker + // The sound tg plays for this floor and what is on its feet: list(sounds, volume, extra range). + var/list/step_sound + if((person.wear_suit?.body_parts_covered | person.w_uniform?.body_parts_covered | person.shoes?.body_parts_covered) & FEET) + step_sound = GLOB.footstep[ground.footstep] + else + var/obj/item/bodypart/leg/leg = person.get_bodypart(BODY_ZONE_R_LEG) || person.get_bodypart(BODY_ZONE_L_LEG) + switch(leg?.footstep_type) + if(FOOTSTEP_MOB_CLAW) + step_sound = GLOB.clawfootstep[ground.clawfootstep] + if(FOOTSTEP_MOB_BAREFOOT) + step_sound = GLOB.barefootstep[ground.barefootstep] + if(FOOTSTEP_MOB_HEAVY) + step_sound = GLOB.heavyfootstep[ground.heavyfootstep] + if(FOOTSTEP_MOB_SHOE) + step_sound = GLOB.footstep[ground.footstep] + if(length(step_sound) < 3) + return 0 + var/volume = step_sound[2] + // The human footstep element plays at -6 range (human.dm). + var/sound_range = SOUND_RANGE + step_sound[3] - 6 + if(HAS_TRAIT(person, TRAIT_LIGHT_STEP)) + volume *= 0.6 + sound_range -= 2 + if(volume <= SOUND_AUDIBLE_VOLUME_MIN || sound_range <= 1) + return 0 + var/audible = CALCULATE_MAX_SOUND_AUDIBLE_DISTANCE(volume, sound_range, 1, SOUND_FALLOFF_EXPONENT) + return clamp(round(STEALTH_FOOTSTEP_RANGE * audible / STEALTH_FOOTSTEP_PLAYER_RANGE, 1), 0, STEALTH_FOOTSTEP_MAX_RANGE) + +/** + * The scan's ear for footsteps, before it looks. Everyone near whose turf changed since the last scan and + * whose step carries this far (walls and doors muffle it) is heard: no line of sight needed. + * - Unaware or suspicious: their notice gains STEALTH_FOOTSTEP_NOTICE, never past STEALTH_SUSPICIOUS_AT; at + * its shoulder it jumps there at once. At that level it turns to the steps and goes to look. From there + * sight decides: steps alone never make it alert. + * - Searching: the search moves to the steps. Someone hunted who runs is followed by ear; one who walks isn't. + * Footsteps are its own senses, not a dispatch: they open no check and count as no lure. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_hear_footsteps() + heard_now = null + var/mob/living/carbon/human/guard = pawn + var/state = stealth_state() + if(state == STEALTH_ALERT || !isturf(guard.loc) || !guard.can_hear()) + heard_map = null + return + var/turf/here = guard.loc + var/list/was = heard_map + var/list/now = list() + var/list/notice = notice_map + var/datum/stealth_skill/profile = stealth_skill() + var/hearing_mult = profile.hearing_mult + for(var/mob/living/walker as anything in stealth_candidates(guard, STEALTH_FOOTSTEP_MAX_RANGE)) + var/key = REF(walker) + var/turf/where = get_turf(walker) + now[key] = where + var/turf/stood = was?[key] + if(isnull(stood) || stood == where) + continue + // A sharper or duller ear than the yellow tuning (decision 38), never past the furthest step listened for. + var/reach = min(round(stealth_footstep_reach(walker) * hearing_mult, 1), STEALTH_FOOTSTEP_MAX_RANGE) + if(!reach || get_dist(here, where) > reach || stealth_muffled_dist(where, here) > reach) + continue + LAZYSET(heard_now, key, TRUE) + last_heard = list("footsteps", world.time) + // Running steps are only steps, disguise or not: the ear can't tell who ran. It turns to look, and once it + // sees them in its colours it stops them; running while stopped gives a disguise away (decision 44). + if(state == STEALTH_SEARCHING) + if(!calm_until && world.time >= next_recentre && get_dist(search_center, where) > 1) + next_recentre = world.time + STEALTH_RECENTRE_COOLDOWN + stealth_go_searching(where) + state = stealth_state() + continue + var/list/entry = notice[key] + if(isnull(entry)) + entry = list(0, where, 0) + notice[key] = entry + if(entry[STEALTH_ENTRY_NOTICE] < STEALTH_SUSPICIOUS_AT) + var/gained = get_dist(here, where) <= profile.close_range ? STEALTH_SUSPICIOUS_AT : entry[STEALTH_ENTRY_NOTICE] + STEALTH_FOOTSTEP_NOTICE + entry[STEALTH_ENTRY_NOTICE] = min(gained, STEALTH_SUSPICIOUS_AT) + entry[STEALTH_ENTRY_SEEN_AT] = world.time + if(blackboard[BB_STEALTH_WARY]) + wary_at = world.time + if(entry[STEALTH_ENTRY_NOTICE] >= STEALTH_SUSPICIOUS_AT) + stealth_go_heard(where) + if(state == STEALTH_SUSPICIOUS && investigated && where != here) + // Looking round already: it turns to the steps. + stand_dir = stealth_dir_to(guard, where) + guard.setDir(stand_dir) + state = stealth_state() + heard_map = now diff --git a/voidcrew/modules/stealth/stealth_hostage.dm b/voidcrew/modules/stealth/stealth_hostage.dm new file mode 100644 index 00000000000..31920b57326 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_hostage.dm @@ -0,0 +1,243 @@ +/** + * # Hostages (stealth step 5, decisions 47+) + * + * Holding one of the guards' own people at gunpoint: tg's neck grab (they are on your tile, held in front of you) + * with a gun in hand. Anyone can do it, and the hold is drawn as such (stealth_hostage_pose.dm). Everything stays + * tg's: the grab, the hostage's own struggling (tg's resist, through escape_captivity), and a shot into them is a + * real shot. + * + * A stealth guard alert on whoever holds a friend of his (same faction) goes into a standoff instead of fighting: + * - he holds fire and keeps his distance (never closer than STEALTH_HOSTAGE_HOLD_RANGE), facing the holder, and + * talks ("Let him go!"); + * - told to drop it, he drops what he holds, once; told to back off, he backs off to STEALTH_HOSTAGE_BACK_OFF_RANGE, + * once. Plain words the holder says out loud within STEALTH_HOSTAGE_DEMAND_RANGE; + * - the hostage let go alive, or slipping free: the fight picks up where it was; + * - the holder hurting or killing the hostage, or the hostage dying in his hands: no more deals with that holder, + * ever, for that guard. He fights. + * - out of sight of the holder, he chases as usual and stands off again when he sees them. + * + * Only for their own people. Someone they don't count as one of theirs (a player, a stranger) held up in front is + * no reason to hold fire: they shoot. Never a fake state on anyone: the hostage is only held, and the guards only + * choose not to shoot. + */ + +/datum/ai_controller/basic_controller/human_npc/stealth + /// The holder it is standing off against, and the friend they hold. + var/datum/weakref/standoff_holder + var/datum/weakref/standoff_hostage + /// What it already gave in to this standoff. + var/standoff_dropped = FALSE + var/standoff_backed_off = FALSE + /// world.time of its next standoff line. + var/next_standoff_bark = 0 + /// REFs of holders who hurt or killed a hostage in front of it: it never stands off against them again. + var/list/no_deals + +/datum/ai_controller/basic_controller/human_npc/stealth/init_subtrees() + if(LAZYLEN(planning_subtrees) && !(/datum/ai_planning_subtree/stealth_hostage in planning_subtrees)) + var/list/subtrees = planning_subtrees.Copy() + var/at = subtrees.Find(/datum/ai_planning_subtree/human_npc_arm) + if(at) + subtrees.Insert(at, /datum/ai_planning_subtree/stealth_hostage) + planning_subtrees = subtrees + return ..() + +/// The body `holder` holds at gunpoint now: a neck grab or tighter on a living body on their tile, a gun in a hand. +/proc/stealth_hostage_of(mob/living/holder) + if(!isliving(holder) || holder.stat != CONSCIOUS) + return null + var/mob/living/held = holder.pulling + if(!isliving(held) || held.stat == DEAD || holder.grab_state < GRAB_NECK || held.loc != holder.loc) + return null + if(!isgun(holder.get_active_held_item()) && !isgun(holder.get_inactive_held_item())) + return null + return held + +/// Whether it stands off against `holder` holding `hostage`: one of its own, and a holder it still deals with. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_standoff_with(mob/living/holder, mob/living/hostage) + var/mob/living/guard = pawn + if(isnull(hostage) || hostage == guard || LAZYFIND(no_deals, REF(holder))) + return FALSE + return guard.faction_check_atom(hostage) + +/// Starts (or keeps) the standoff against `holder` holding `hostage`. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_standoff_start(mob/living/holder, mob/living/hostage) + var/mob/living/old_holder = standoff_holder?.resolve() + var/mob/living/old_hostage = standoff_hostage?.resolve() + if(old_holder == holder && old_hostage == hostage) + return + stealth_standoff_end() + standoff_holder = WEAKREF(holder) + standoff_hostage = WEAKREF(hostage) + standoff_dropped = FALSE + standoff_backed_off = FALSE + next_standoff_bark = 0 + stealth_drop_walk() + RegisterSignal(holder, COMSIG_MOB_SAY, PROC_REF(on_standoff_demand)) + RegisterSignal(hostage, COMSIG_MOB_AFTER_APPLY_DAMAGE, PROC_REF(on_hostage_hurt)) + RegisterSignal(hostage, COMSIG_LIVING_DEATH, PROC_REF(on_hostage_died)) + var/mob/living/guard = pawn + log_combat(guard, holder, "held fire on a hostage holder", null, "(hostage [key_name(hostage)], [get_area_name(guard, TRUE)])") + +/// Ends the standoff, if any. `line` is the bark it says as it does. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_standoff_end(line) + var/mob/living/holder = standoff_holder?.resolve() + var/mob/living/hostage = standoff_hostage?.resolve() + if(holder) + UnregisterSignal(holder, COMSIG_MOB_SAY) + if(hostage) + UnregisterSignal(hostage, list(COMSIG_MOB_AFTER_APPLY_DAMAGE, COMSIG_LIVING_DEATH)) + var/was_on = !isnull(standoff_holder) + standoff_holder = null + standoff_hostage = null + if(was_on) + stealth_drop_walk() + if(line) + stealth_bark(line, always = TRUE) + +/// The holder hurt or killed the hostage: no more deals with them. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_standoff_broken(mob/living/holder) + if(holder) + LAZYOR(no_deals, REF(holder)) + var/mob/living/guard = pawn + log_combat(guard, holder, "stopped holding fire: the hostage was hurt", null, "([get_area_name(guard, TRUE)])") + stealth_set_wary() + stealth_standoff_end(STEALTH_BARK_HOSTAGE_EXECUTED) + +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_hostage_hurt(mob/living/source, damage_dealt, damagetype, def_zone, blocked, wound_bonus, exposed_wound_bonus, sharpness, attack_direction, attacking_item) + SIGNAL_HANDLER + if(damage_dealt <= 0) + return + var/mob/living/holder = standoff_holder?.resolve() + if(holder && hv_vis_attacker_of(attacking_item) == holder) + stealth_standoff_broken(holder) + +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_hostage_died(mob/living/source, gibbed) + SIGNAL_HANDLER + var/mob/living/holder = standoff_holder?.resolve() + if(holder?.pulling == source) + stealth_standoff_broken(holder) + else + stealth_standoff_end() + +/// The holder says something. A demand it hears gets done once each: drop the weapon, or back off. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_standoff_demand(mob/living/source, list/speech_args) + SIGNAL_HANDLER + var/mob/living/carbon/human/guard = pawn + if(guard.stat != CONSCIOUS || HAS_TRAIT(guard, TRAIT_DEAF) || get_dist(guard, source) > STEALTH_HOSTAGE_DEMAND_RANGE) + return + if(stealth_hostage_of(source) != standoff_hostage?.resolve()) + return + var/message = speech_args[SPEECH_MESSAGE] + if(!istext(message)) + return + var/static/regex/drop_words = regex(@"\b(drop|guns?|weapons?|piece|disarm)\b", "i") + var/static/regex/back_words = regex(@"\b(back|away|off|step|move|leave|go)\b", "i") + if(!standoff_dropped && drop_words.Find(message)) + INVOKE_ASYNC(src, PROC_REF(stealth_standoff_drop)) + else if(!standoff_backed_off && back_words.Find(message)) + standoff_backed_off = TRUE + stealth_drop_walk() + stealth_bark(STEALTH_BARK_HOSTAGE_BACK, always = TRUE) + log_combat(guard, source, "backed off from a hostage holder") + +/// Drops what it holds in its hands, through tg's own drop. Gear locked to its body (human_npc_gear.dm, decision D3) +/// can't leave it, so that goes away onto its belt, back or suit instead: empty hands either way, and no loot. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_standoff_drop() + var/mob/living/carbon/human/guard = pawn + if(QDELETED(guard) || standoff_dropped) + return + standoff_dropped = TRUE + var/dropped = FALSE + for(var/obj/item/held in guard.held_items) + if(guard.dropItemToGround(held) || guard.equip_to_appropriate_slot(held)) + dropped = TRUE + if(dropped) + stealth_bark(STEALTH_BARK_HOSTAGE_DROP, always = TRUE) + var/mob/living/holder = standoff_holder?.resolve() + log_combat(guard, holder, "dropped their weapon for a hostage holder") + +/// Where it stands in the standoff: the band of distance it keeps from the holder. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_standoff_band() + return standoff_backed_off ? list(STEALTH_HOSTAGE_BACK_OFF_RANGE, STEALTH_HOSTAGE_BACK_OFF_RANGE + 2) : list(STEALTH_HOSTAGE_HOLD_RANGE, STEALTH_HOSTAGE_DEMAND_RANGE - 1) + +/** + * Alert on someone holding one of its own at gunpoint, in view: the standoff. Holds fire (ends planning before the + * arming, shooting and melee subtrees), keeps its distance, faces them and talks. Placed before human_npc_arm, so a + * guard that dropped its weapon doesn't pick another up while the standoff lasts. + */ +/datum/ai_planning_subtree/stealth_hostage + +/datum/ai_planning_subtree/stealth_hostage/SelectBehaviors(datum/ai_controller/basic_controller/human_npc/stealth/controller, seconds_per_tick) + if(!istype(controller)) + return + var/mob/living/carbon/human/guard = controller.pawn + var/mob/living/holder = controller.blackboard[BB_BASIC_MOB_CURRENT_TARGET] + var/mob/living/hostage = isliving(holder) ? stealth_hostage_of(holder) : null + var/in_standoff = !isnull(controller.standoff_holder) + if(guard.stat != CONSCIOUS || controller.stealth_state() != STEALTH_ALERT || isnull(hostage) \ + || !controller.stealth_standoff_with(holder, hostage) || !controller.stealth_has_in_view(holder)) + if(in_standoff) + var/mob/living/old_hostage = controller.standoff_hostage?.resolve() + var/mob/living/old_holder = controller.standoff_holder?.resolve() + var/released = old_hostage && old_hostage.stat != DEAD && old_holder && stealth_hostage_of(old_holder) != old_hostage + controller.stealth_standoff_end(released ? STEALTH_BARK_HOSTAGE_RELEASED : null) + return + controller.stealth_standoff_start(holder, hostage) + controller.last_seen_turf = get_turf(holder) + controller.stealth_set_wary() + if(world.time >= controller.next_standoff_bark) + controller.next_standoff_bark = world.time + STEALTH_HOSTAGE_BARK_INTERVAL + controller.stealth_bark(STEALTH_BARK_HOSTAGE) + var/list/band = controller.stealth_standoff_band() + var/distance = get_dist(guard, holder) + var/turf/dest + if(distance < band[1]) + dest = stealth_open_near(get_ranged_target_turf_direct(holder, guard, band[1]), 1) + else if(distance > band[2]) + dest = stealth_open_near(get_ranged_target_turf_direct(holder, guard, band[2]), 1) + if(dest && dest != get_turf(guard) && !controller.stealth_walk_over(dest)) + controller.stealth_walk(dest, STEALTH_GOTO_INVESTIGATE) + return SUBTREE_RETURN_FINISH_PLANNING + controller.stealth_drop_walk() + controller.stand_dir = stealth_dir_to(guard, holder) + controller.look_until = 0 + if(guard.dir != controller.stand_dir) + controller.stealth_turn_to(controller.stand_dir) + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + +// --------------------------------------------------------------------------------------------- +// What they say + +/datum/human_npc_voice/scav/New() + . = ..() + lines[STEALTH_BARK_HOSTAGE] = list("Let 'em go!", "Easy. Easy now.", "Put the gun down!", "You won't get far.", "Nobody has to die here.") + lines[STEALTH_BARK_HOSTAGE_DROP] = list("All right! It's down!", "Okay, okay. It's down.", "There. Happy?") + lines[STEALTH_BARK_HOSTAGE_BACK] = list("I'm backing off.", "Okay. Backing up.", "Fine. Fine.") + lines[STEALTH_BARK_HOSTAGE_EXECUTED] = list("You son of a-", "Take them down!", "No more talking!") + lines[STEALTH_BARK_HOSTAGE_RELEASED] = list("Now!", "Take them!", "Get clear!") + emotes[STEALTH_BARK_HOSTAGE] = list("raises a hand slowly.", "keeps their gun low.") + emotes[STEALTH_BARK_HOSTAGE_DROP] = list("puts their weapon down.") + +// --------------------------------------------------------------------------------------------- +// Held at gunpoint, held upright (decision 62) + +/** + * tg's neck grab floors the held body (TRAIT_FLOORED from CHOKEHOLD_TRAIT). Held at gunpoint as a hostage, it is held + * up on its feet instead: still tg's chokehold (immobilized, hands blocked), only not floored, so it stands in front of + * its holder and takes the shots that come at them (tg's projectiles skip a floored, pinned body). Called every time + * tg places a held body (the grab, each step, each turn: set_pull_offsets() in stealth_hostage_pose.dm); tg's own + * release clears the chokehold either way. Puts tg's chokehold floor back when it is no longer held at gunpoint. + */ +/mob/living/proc/stealth_hold_upright(mob/living/held) + if(!isliving(held) || pulling != held) + return + if(stealth_hostage_of(src) == held) + if(HAS_TRAIT_FROM(held, TRAIT_FLOORED, CHOKEHOLD_TRAIT)) + REMOVE_TRAIT(held, TRAIT_FLOORED, CHOKEHOLD_TRAIT) + // tg's own stand-up after the floor goes is a 1 s do_after; held up, they're on their feet at once. + // get_up() still refuses a body that is resting or floored by anything else (a stun, crit). + held.get_up(instant = TRUE) + else if(grab_state >= GRAB_NECK && !HAS_TRAIT_FROM(held, TRAIT_FLOORED, CHOKEHOLD_TRAIT)) + ADD_TRAIT(held, TRAIT_FLOORED, CHOKEHOLD_TRAIT) diff --git a/voidcrew/modules/stealth/stealth_hostage_pose.dm b/voidcrew/modules/stealth/stealth_hostage_pose.dm new file mode 100644 index 00000000000..fff95c47bed --- /dev/null +++ b/voidcrew/modules/stealth/stealth_hostage_pose.dm @@ -0,0 +1,565 @@ +/** + * # Hostages: the hold at gunpoint (stealth step 5, decision 62) + * + * Visual only, under hyperviolence's motion rules (voidcrew/modules/hyperviolence/visuals/_motion_core.dm): nothing + * here moves, stuns, roots or hurts anyone. + * + * A body held at gunpoint (stealth_hostage_of()) is drawn tight against the front of its holder, facing his way, + * through tg's own grab offsets (GRABBING_TRAIT), which tg clears when he lets go: + * - facing south it stands low in front of him, to his free-hand side, so his gun shows beside its head; + * - facing north it stands beyond him, to the same side, and he is drawn over it; + * - side-on it stands a quarter of a tile ahead and he is drawn over it, so his gun shows against its back. + * The gun is never touched: it is tg's own in-hand picture, in his hand. + * + * Draw order is never set here. The body's pixel_y puts it on a screen row in front of or behind its holder, and the + * client draws rows back to front (SIDE_MAP), so whoever is higher on the screen is behind, on every frame of a turn. + * + * Only the drawing between poses is ours, as a named animation (HOSTAGE_POSE_ANIM) that ends on the real offsets: + * - the neck grab landing: tg moves the body onto the holder's tile at once and glides it there. For those few ticks + * the body is hidden by a colour filter (not its alpha or invisibility, which sight and AI read) and a copy of its + * look (/obj/effect/abstract/hostage_standin, unclickable) is drawn pulled into the pose instead; then the copy goes + * and the body shows again in place; + * - a turn: the holder turns at once; the body swings round him to his new front, facing outward from him as it goes; + * - letting go: tg leaves the two on one tile. The holder shoves and the freed body is pushed a few pixels out from + * where it was held, and goes on standing there (HOSTAGE_POSE_FREED offsets) until either of them moves, it falls + * or it is grabbed again; then it is back on the middle of its tile within a tick or two. If it is still held, only + * no longer at gunpoint (the gun put away), it goes straight back to tg's grab spot. + * - the holder's own part is two short named sequences that end where he stands: a reach and tug as the neck grab + * lands, and the shove as he lets go. + */ + +/// The filter that hides a body while its stand-in is drawn. +#define HOSTAGE_VIS_HIDE_FILTER "hostage_vis_hide" + +/mob/living + /// The copy drawn in this body's place while the neck grab lands, if any. + var/obj/effect/abstract/hostage_standin/hostage_standin + +/obj/effect/abstract/hostage_standin + name = "" + mouse_opacity = MOUSE_OPACITY_TRANSPARENT + anchored = TRUE + animate_movement = NO_STEPS + /// The body this is drawn in place of. + var/atom/movable/body + /// The steps it is playing, as given to play(), and when they started: for whoever takes over from here. + var/list/steps + var/steps_started = 0 + /// The timer that ends it. + var/life_timer + +/** + * Hides `body` and stands a copy of its look on `at` for `time` deciseconds. The copy starts with no offsets and the + * body's own facing and transform; the caller plays it from there (play()). A body that already has a copy gets a new + * one in its place. + */ +/obj/effect/abstract/hostage_standin/Initialize(mapload, atom/movable/body, time = 5) + . = ..() + if(QDELETED(body)) + return INITIALIZE_HINT_QDEL + if(isliving(body)) + var/mob/living/alive = body + if(alive.hostage_standin) + qdel(alive.hostage_standin) + alive.hostage_standin = src + src.body = body + appearance = body.appearance + // a look does not bring its facing with it + setDir(body.dir) + name = "" + mouse_opacity = MOUSE_OPACITY_TRANSPARENT + pixel_x = 0 + pixel_y = 0 + pixel_w = 0 + pixel_z = 0 + body.add_filter(HOSTAGE_VIS_HIDE_FILTER, 20, color_matrix_filter(list(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,0))) + RegisterSignal(body, COMSIG_QDELETING, PROC_REF(body_gone)) + live_for(time) + +/obj/effect/abstract/hostage_standin/Destroy() + if(life_timer) + deltimer(life_timer) + life_timer = null + if(body) + UnregisterSignal(body, COMSIG_QDELETING) + body.remove_filter(HOSTAGE_VIS_HIDE_FILTER) + if(isliving(body)) + var/mob/living/alive = body + if(alive.hostage_standin == src) + alive.hostage_standin = null + body = null + return ..() + +/obj/effect/abstract/hostage_standin/proc/body_gone(datum/source) + SIGNAL_HANDLER + qdel(src) + +/// The copy goes, and the body shows again, `time` deciseconds from now (instead of when it was going to). +/obj/effect/abstract/hostage_standin/proc/live_for(time) + if(life_timer) + deltimer(life_timer) + life_timer = QDEL_IN_STOPPABLE(src, time) + +/** + * Plays `steps` on the copy, from the first step's values at once: each is + * list(time, pixel_x, pixel_y, pixel_z, transform, facing, easing). pixel_y is where it stands on the floor (which + * also puts it on its screen row, so it is drawn in front of or behind the bodies it passes), pixel_z how high off the + * floor it is drawn. Offsets are from the tile the copy stands on. A null transform, facing or easing keeps the last. + */ +/obj/effect/abstract/hostage_standin/proc/play(list/new_steps) + steps = new_steps + steps_started = world.time + var/matrix/turned = matrix(transform) + var/facing = dir + for(var/i in 1 to length(steps)) + var/list/step = steps[i] + if(step[5]) + turned = step[5] + if(step[6]) + facing = step[6] + if(i == 1) + animate(src, pixel_x = step[2], pixel_y = step[3], pixel_z = step[4], transform = turned, dir = facing, time = 0) + continue + var/list/before = steps[i - 1] + animate(pixel_x = step[2], pixel_y = step[3], pixel_z = step[4], transform = turned, dir = facing, time = step[1] - before[1], easing = step[7] || LINEAR_EASING) + +/// Where the copy is drawn now, list(pixel_x, pixel_y, pixel_z): along its steps (straight lines between them). +/obj/effect/abstract/hostage_standin/proc/now() + if(!length(steps)) + return list(pixel_x, pixel_y, pixel_z) + var/elapsed = world.time - steps_started + var/list/before = steps[1] + for(var/list/step as anything in steps) + if(elapsed < step[1]) + var/frac = (elapsed - before[1]) / max(step[1] - before[1], 0.01) + return list(before[2] + (step[2] - before[2]) * frac, before[3] + (step[3] - before[3]) * frac, before[4] + (step[4] - before[4]) * frac) + before = step + return list(before[2], before[3], before[4]) + +/// The animation tag for the held body's path, so a new one takes over from wherever the last one got to. +#define HOSTAGE_POSE_ANIM "hostage_pose" +/// The offset source a let-go body keeps its held spot under. +#define HOSTAGE_POSE_FREED "hostage_pose_freed" +/// The holder's own small moves (the tug as the neck grab lands, the shove as he lets go), a named sequence. +#define HOSTAGE_POSE_HOLDER_ANIM "hostage_pose_holder" +/// How far a let-go body is shoved out from where it was held, in pixels. +#define HOSTAGE_POSE_SHOVE 3 +/// Facing south: how far in front (down the screen) the body is held. Facing north: how far beyond. +#define HOSTAGE_POSE_NEAR_S 10 +#define HOSTAGE_POSE_NEAR_N 12 +/// Facing south or north: how far it sits toward the holder's free hand. +#define HOSTAGE_POSE_SIDE 4 +/// Side-on: how far ahead it is held. +#define HOSTAGE_POSE_AHEAD 8 +/// Side-on: one screen row beyond the holder (so he is drawn over it), and drawn a pixel lower to stand level with him. +#define HOSTAGE_POSE_ROW 1 +#define HOSTAGE_POSE_ROW_DROP -1 +/// Times, deciseconds (a game tick is half of one). +#define HOSTAGE_POSE_QUARTER_TIME 2 +#define HOSTAGE_POSE_HALF_TIME 3 +#define HOSTAGE_POSE_LAND_TIME 2 +#define HOSTAGE_POSE_SETTLE_TIME 2 + +/mob/living + /// The holder's facing this body is posed for as his hostage, or 0. + var/hostage_pose_dir = 0 + /// Which hand ("L"/"R") holds the gun the pose was made for. + var/hostage_pose_hand + /// Counts poses, so steps queued for an old one are dropped. + var/hostage_pose_serial = 0 + /// The path being drawn: list(start world.time, list of list(time, x, y, z)), grab offsets from the holder. + var/list/hostage_pose_path + /// Keeps this body standing where it was held, once let go, until it or its holder moves. + var/datum/hostage_pose_freed/hostage_pose_freed + +/mob/living/carbon/human + /// The tick this body's grip last tightened to a neck grab: tg pulls the held body onto its tile in that tick. + var/hostage_neck_grab_tick = -1 + +/mob/living/carbon/human/setGrabState(newstate) + . = ..() + if(newstate == GRAB_NECK) + hostage_neck_grab_tick = world.time + +// --------------------------------------------------------------------------------------------- +// The poses + +/// The held body's offset from its holder, list(pixel_x, pixel_y, pixel_z), for his `facing` and gun `hand` ("L"/"R"). +/proc/hostage_pose_offset(facing, hand = "L") + // his left hand is on the viewer's right when he faces south, and on the viewer's left when he faces north + var/gun_side = hand == "R" ? -1 : 1 + switch(facing) + if(SOUTH) + return list(-gun_side * HOSTAGE_POSE_SIDE, -HOSTAGE_POSE_NEAR_S, 0) + if(NORTH) + return list(gun_side * HOSTAGE_POSE_SIDE, HOSTAGE_POSE_NEAR_N, 0) + if(EAST) + return list(HOSTAGE_POSE_AHEAD, HOSTAGE_POSE_ROW, HOSTAGE_POSE_ROW_DROP) + if(WEST) + return list(-HOSTAGE_POSE_AHEAD, HOSTAGE_POSE_ROW, HOSTAGE_POSE_ROW_DROP) + return list(0, 0, 0) + +/// The way a held body faces at `angle` degrees round its holder (0 east, 90 north): outward from him. +/proc/hostage_pose_facing_at(angle) + if(angle > 45 && angle <= 135) + return NORTH + if(angle > -45 && angle <= 45) + return EAST + if(angle > -135 && angle <= -45) + return SOUTH + return WEST + +/// Fast start, eased stop (cubic), 0 to 1. +/proc/hostage_pose_ease_out(u) + return 1 - (1 - u) ** 3 + +/// Which hand holds the gun the hostage is held with ("L"/"R"): the active hand's gun first. +/mob/living/carbon/human/proc/hostage_pose_hand() + var/obj/item/gun = get_active_held_item() + if(!isgun(gun)) + gun = get_inactive_held_item() + return (isgun(gun) && IS_RIGHT_INDEX(get_held_index_of_item(gun))) ? "R" : "L" + +// --------------------------------------------------------------------------------------------- +// tg's grab offsets, taken over while the body is held at gunpoint + +/mob/living/set_pull_offsets(mob/living/mob_to_set, grab_state = GRAB_PASSIVE, animate = TRUE) + stealth_hold_upright(mob_to_set) + var/mob/living/carbon/human/holder = ishuman(src) ? src : null + if(stealth_hostage_of(holder) == mob_to_set) + holder.hostage_pose_apply(mob_to_set, animate) + return + if(mob_to_set.hostage_pose_dir) + mob_to_set.hostage_pose_end() + QDEL_NULL(mob_to_set.hostage_pose_freed) + return ..() + +/mob/living/reset_pull_offsets(mob/living/M, override) + if(M.hostage_pose_dir && (override || !M.buckled)) + M.hostage_pose_end(src) + return ..() + +/// A turn swings the hostage round to the holder's new front, on the same tick. +/mob/living/carbon/human/setDir(newdir) + var/old_dir = dir + . = ..() + if(dir == old_dir || !isliving(pulling)) + return + var/mob/living/held = pulling + if(held.hostage_pose_dir || stealth_hostage_of(src) == held) + set_pull_offsets(held, grab_state) + +/// The pose comes and goes with the gun in his hand: posed when one comes out mid-hold, dropped back to tg's grab +/// when it goes away, moved across when it changes hands. +/mob/living/carbon/human/update_held_items() + . = ..() + var/mob/living/held = pulling + if(!isliving(held)) + return + if(stealth_hostage_of(src) == held) + if(held.hostage_pose_dir == dir && held.hostage_pose_hand == hostage_pose_hand()) + return + else if(!held.hostage_pose_dir) + return + set_pull_offsets(held, grab_state) + +// --------------------------------------------------------------------------------------------- +// Posing + +/// Poses `held` against this holder's front for his facing, drawn from wherever it is now. +/mob/living/carbon/human/proc/hostage_pose_apply(mob/living/held, animate = TRUE) + var/hand = hostage_pose_hand() + var/old_dir = held.hostage_pose_dir + if(old_dir == dir && held.hostage_pose_hand == hand) + return + // where the body is drawn now: tg's grab offset at the neck grab, else along our own path + var/list/from = held.hostage_pose_now() + if(held.hostage_standin) + // turned again while the neck grab's stand-in was still being pulled in: carry on from where that got to + from = held.hostage_standin.now() + qdel(held.hostage_standin) + var/list/target = hostage_pose_offset(dir, hand) + if(held.hostage_pose_freed) + held.hostage_pose_note(HOSTAGE_POSE_FREED) + QDEL_NULL(held.hostage_pose_freed) + // the new spot is only noted here: the path below draws the way to it and ends on it (written first and drawn + // after, the body could show at the new spot for a frame before its swing started) + held.hostage_pose_note(GRABBING_TRAIT, target) + held.hostage_pose_dir = dir + held.hostage_pose_hand = hand + var/pose = ++held.hostage_pose_serial + if(!animate || !isturf(held.loc)) + held.hostage_pose_path = null + animate(held, tag = HOSTAGE_POSE_ANIM) + held.update_offsets(FALSE) + hostage_pose_face(held, pose, dir) + return + if(!old_dir) + hostage_pose_land(held, from, target) + else if(old_dir == dir) + hostage_pose_settle(held, from, target) + else + hostage_pose_swing(held, pose, from, target, old_dir) + +/// The neck grab landing: the body faces the holder's way at once and is pulled into the pose (fast start, eased +/// stop). tg has just moved it onto this tile from the next one and glides it across at a pace each client sets for +/// itself, so for those ticks a stand-in is drawn making the pull, from tg's grab spot into the pose, and the body +/// shows again where it then really is. +/mob/living/carbon/human/proc/hostage_pose_land(mob/living/held, list/grab, list/target) + if(held.body_position == STANDING_UP) + held.setDir(dir) + // tg's neck grab floors the body and the hold stands it straight back up (stealth_hold_upright()), both this + // tick: tg's lying turn would still play there and back. It stands, so it is drawn standing from the first + // frame. (A whole-animation call, so it goes before anything else.) + if(!held.lying_angle) + animate(held, transform = held.transform, time = 0) + // tg's passive or aggressive grab draws the body toward its holder along one axis. If this tick's neck grab pulled + // it in from the next tile that way, it is still drawn there: a tile further out than its offsets say. + var/pulled_in = (!grab[1] != !grab[2]) && hostage_neck_grab_tick == world.time + if(!pulled_in || held.body_position != STANDING_UP) + hostage_pose_settle(held, grab, target) + return + held.hostage_pose_path = null + held.update_offsets(FALSE) + var/from_x = grab[1] - SIGN(grab[1]) * world.icon_size + var/from_y = grab[2] - SIGN(grab[2]) * world.icon_size + var/ticks = max(2, round(HOSTAGE_POSE_LAND_TIME / world.tick_lag)) + // a tick longer than the pull, so tg's glide is over on every client before the body shows + var/obj/effect/abstract/hostage_standin/copy = new(loc, held, (ticks + 1) * world.tick_lag) + var/list/steps = list() + // pulled in from the side, it is on the pose's screen row (and so under or over him as in the pose) from the first + // frame: the client reads a row where a step starts, not along it + var/side_on = !from_y + for(var/i in 0 to ticks) + var/eased = hostage_pose_ease_out(i / ticks) + steps += list(list( + i * world.tick_lag, + from_x + (target[1] - from_x) * eased, + side_on ? target[2] : from_y + (target[2] - from_y) * eased, + side_on ? target[3] : grab[3] + (target[3] - grab[3]) * eased, + null, + dir, + null, + )) + copy.play(steps) + // his side of it: a reach toward the body, then a tug back as it comes in + hostage_pose_holder(SIGN(from_x), SIGN(from_y), 2, -1, HOSTAGE_POSE_LAND_TIME) + +/// The holder's small move: `reach` pixels along (toward_x, toward_y) in a tick, then `back` pixels along it over +/// `time`, then home. +/mob/living/carbon/human/proc/hostage_pose_holder(toward_x, toward_y, reach, back, time) + if(!isturf(loc) || body_position != STANDING_UP) + return + var/matrix/still = matrix(transform) + hv_vis_play(HOSTAGE_POSE_HOLDER_ANIM, list( + list(pixel_w + toward_x * reach, pixel_z + toward_y * reach, still, world.tick_lag, SINE_EASING | EASE_OUT), + list(pixel_w + toward_x * back, pixel_z + toward_y * back, still, time - world.tick_lag, SINE_EASING | EASE_OUT), + list(pixel_w, pixel_z, still, world.tick_lag * 2, SINE_EASING), + )) + +/// Same facing, new spot (the gun changed hands): a short eased slide across. +/mob/living/carbon/human/proc/hostage_pose_settle(mob/living/held, list/from, list/target) + var/ticks = max(1, round(HOSTAGE_POSE_SETTLE_TIME / world.tick_lag)) + var/list/keys = list() + for(var/i in 0 to ticks) + var/eased = hostage_pose_ease_out(i / ticks) + keys += list(list(i * world.tick_lag, from[1] + (target[1] - from[1]) * eased, from[2] + (target[2] - from[2]) * eased, from[3] + (target[3] - from[3]) * eased)) + held.hostage_pose_play(keys) + +/// A turn: the holder already faces his new way. The body swings round him to his new front (fast start, eased stop), +/// the short way round on a quarter turn; on a half turn across the front of him (side to side), or round his +/// free-hand side (front to back). It faces outward from him each tick, his way on the last. +/mob/living/carbon/human/proc/hostage_pose_swing(mob/living/held, pose, list/from, list/target, old_dir) + var/half = REVERSE_DIR(old_dir) == dir + var/ticks = max(1, round((half ? HOSTAGE_POSE_HALF_TIME : HOSTAGE_POSE_QUARTER_TIME) / world.tick_lag)) + var/from_angle = arctan(from[1], from[2]) + var/from_far = sqrt(from[1] ** 2 + from[2] ** 2) + var/target_far = sqrt(target[1] ** 2 + target[2] ** 2) + var/sweep = arctan(target[1], target[2]) - from_angle + if(sweep > 180) + sweep -= 360 + else if(sweep <= -180) + sweep += 360 + // side to side goes across the front of him (down the screen), where it stays in view + if(half && (dir & (EAST|WEST)) && sin(from_angle + sweep / 2) > 0) + sweep += sweep > 0 ? -360 : 360 + var/list/keys = list() + var/facing = held.dir + for(var/i in 0 to ticks) + var/eased = hostage_pose_ease_out(i / ticks) + var/angle = from_angle + sweep * eased + var/far = from_far + (target_far - from_far) * eased + if(i == ticks) + keys += list(list(i * world.tick_lag, target[1], target[2], target[3])) + else + keys += list(list(i * world.tick_lag, round(cos(angle) * far, 0.01), round(sin(angle) * far, 0.01), from[3] + (target[3] - from[3]) * eased)) + if(!i) + continue + while(angle > 180) + angle -= 360 + while(angle <= -180) + angle += 360 + var/now_facing = i == ticks ? dir : hostage_pose_facing_at(angle) + if(now_facing != facing) + facing = now_facing + addtimer(CALLBACK(src, PROC_REF(hostage_pose_face), held, pose, facing), i * world.tick_lag, TIMER_DELETE_ME) + held.hostage_pose_play(keys) + +/// Turns the held body to `facing`, unless posed again since. A body on the floor keeps tg's lying side. +/mob/living/carbon/human/proc/hostage_pose_face(mob/living/held, pose, facing) + if(QDELETED(held) || pose != held.hostage_pose_serial || !held.hostage_pose_dir) + return + if(held.body_position == STANDING_UP) + held.setDir(facing) + +/// No longer held at gunpoint. Let go by `freed_by` on his own tile, it stays drawn where it was held; otherwise +/// the pose's offsets come off (tg's eased slide to wherever tg has it now). +/mob/living/proc/hostage_pose_end(mob/living/freed_by) + // where it is drawn now: its pose, or part way round a swing that was still playing + var/list/held_at = hostage_pose_now() + hostage_pose_dir = 0 + hostage_pose_hand = null + hostage_pose_serial++ + hostage_pose_path = null + if(!QDELETED(freed_by) && loc == freed_by.loc && isturf(loc) && body_position == STANDING_UP) + // both in this tick, so nothing jumps: tg's grab offsets off, the spot it is drawn at back on under our name + // (a swing still playing stops there). Then the shove: a few pixels further out from him, tg's own eased slide. + held_at = list(round(held_at[1], 1), round(held_at[2], 1), round(held_at[3], 1)) + hostage_pose_note(GRABBING_TRAIT) + hostage_pose_note(HOSTAGE_POSE_FREED, held_at) + animate(src, tag = HOSTAGE_POSE_ANIM) + update_offsets(FALSE) + var/far = max(sqrt(held_at[1] ** 2 + held_at[2] ** 2), 1) + var/out_x = held_at[1] / far + var/out_y = held_at[2] / far + add_offsets(HOSTAGE_POSE_FREED, x_add = round(held_at[1] + out_x * HOSTAGE_POSE_SHOVE, 1), y_add = round(held_at[2] + out_y * HOSTAGE_POSE_SHOVE, 1), animate = TRUE) + hostage_pose_freed = new(src, freed_by) + if(ishuman(freed_by)) + var/mob/living/carbon/human/shover = freed_by + shover.hostage_pose_holder(out_x, out_y, 2, 1, UPDATE_TRANSFORM_ANIMATION_TIME) + return + animate(src, tag = HOSTAGE_POSE_ANIM) + remove_offsets(GRABBING_TRAIT, animate = TRUE) + +/// Keeps a let-go body standing where it was held until it or its holder moves, it falls, or it is grabbed again. +/datum/hostage_pose_freed + var/mob/living/body + var/mob/living/holder + +/datum/hostage_pose_freed/New(mob/living/body, mob/living/holder) + src.body = body + src.holder = holder + RegisterSignals(body, list(COMSIG_MOVABLE_MOVED, COMSIG_LIVING_SET_BODY_POSITION, COMSIG_QDELETING), PROC_REF(over)) + RegisterSignals(holder, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING), PROC_REF(over)) + +/datum/hostage_pose_freed/Destroy() + if(body) + UnregisterSignal(body, list(COMSIG_MOVABLE_MOVED, COMSIG_LIVING_SET_BODY_POSITION, COMSIG_QDELETING)) + if(body.hostage_pose_freed == src) + body.hostage_pose_freed = null + if(!QDELETED(body)) + // back onto the middle of its tile in two ticks (quicker than any glide it is making, so the two never + // add up to a step past where it is going) + var/list/was = body.hostage_pose_real(HOSTAGE_POSE_FREED) + body.hostage_pose_note(HOSTAGE_POSE_FREED) + if(isturf(body.loc) && (was[1] || was[2] || was[3])) + body.hostage_pose_play(list(list(0, was[1], was[2], was[3]), list(world.tick_lag * 2, 0, 0, 0))) + body = null + if(holder) + UnregisterSignal(holder, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING)) + holder = null + return ..() + +/datum/hostage_pose_freed/proc/over(datum/source) + SIGNAL_HANDLER + qdel(src) + +// --------------------------------------------------------------------------------------------- +// Drawing the path + +/// Notes this body's offsets from `source` as `spot` (list(x, y, z), or null for none) without drawing the change: the +/// path played next draws it, or update_offsets() does. +/mob/living/proc/hostage_pose_note(source, list/spot) + if(isnull(spot)) + for(var/offset in offsets) + LAZYREMOVE(offsets[offset], source) + ASSOC_UNSETEMPTY(offsets, offset) + UNSETEMPTY(offsets) + return + LAZYINITLIST(offsets) + LAZYSET(offsets[PIXEL_X_OFFSET], source, spot[1]) + LAZYSET(offsets[PIXEL_Y_OFFSET], source, spot[2]) + LAZYSET(offsets[PIXEL_Z_OFFSET], source, spot[3]) + +/// One of this body's pixel offsets as its noted offsets add up to (what update_offsets() would set). +/mob/living/proc/hostage_pose_sum(pixel, base) + . = base + for(var/source in LAZYACCESS(offsets, pixel)) + . += offsets[pixel][source] + +/// Draws this body along `keys` (list of list(time, x, y, z): its grab offsets over time, from 0), on top of its other +/// offsets, and ends it on its real offsets as noted (the last key's). +/mob/living/proc/hostage_pose_play(list/keys) + var/list/last = keys[length(keys)] + var/rest_x = hostage_pose_sum(PIXEL_X_OFFSET, base_pixel_x) - last[2] + var/rest_y = hostage_pose_sum(PIXEL_Y_OFFSET, base_pixel_y) - last[3] + var/rest_z = hostage_pose_sum(PIXEL_Z_OFFSET, base_pixel_z) - last[4] + // The client draws whoever stands on the lower screen row in front, and reads a body's row where a step of its + // animation starts. So a step that would carry the body across its holder's row (pixel_y 0) is cut in two there, + // the cut a pixel onto the new side: the two swap over as it crosses, not a tick late. + var/list/cut = list(keys[1]) + for(var/i in 2 to length(keys)) + var/list/before = keys[i - 1] + var/list/key = keys[i] + var/from_row = rest_y + before[3] + var/to_row = rest_y + key[3] + if((from_row > 0 && to_row < -1) || (from_row < 0 && to_row > 1)) + var/part = (SIGN(to_row) - from_row) / (to_row - from_row) + cut += list(list(before[1] + (key[1] - before[1]) * part, before[2] + (key[2] - before[2]) * part, before[3] + (key[3] - before[3]) * part, before[4] + (key[4] - before[4]) * part)) + cut += list(key) + keys = cut + hostage_pose_path = list(world.time, keys) + var/list/first = keys[1] + animate(src, pixel_x = rest_x + first[2], pixel_y = rest_y + first[3], pixel_z = rest_z + first[4], time = 0, tag = HOSTAGE_POSE_ANIM) + for(var/i in 2 to length(keys)) + var/list/key = keys[i] + var/list/before = keys[i - 1] + animate(pixel_x = rest_x + key[2], pixel_y = rest_y + key[3], pixel_z = rest_z + key[4], time = key[1] - before[1]) + +/// The offsets this body is drawn at now as a hostage (or just let go), list(x, y, z): along our path while it plays, +/// else its real ones. +/mob/living/proc/hostage_pose_now() + var/list/path = hostage_pose_path + if(length(path)) + var/elapsed = world.time - path[1] + var/list/keys = path[2] + var/list/before = keys[1] + for(var/list/key as anything in keys) + if(elapsed < key[1]) + var/frac = (elapsed - before[1]) / max(key[1] - before[1], 0.01) + return list(before[2] + (key[2] - before[2]) * frac, before[3] + (key[3] - before[3]) * frac, before[4] + (key[4] - before[4]) * frac) + before = key + return hostage_pose_real(hostage_pose_freed ? HOSTAGE_POSE_FREED : GRABBING_TRAIT) + +/// This body's real offsets from `source`, list(x, y, z). +/mob/living/proc/hostage_pose_real(source) + return list( + LAZYACCESS(LAZYACCESS(offsets, PIXEL_X_OFFSET), source) || 0, + LAZYACCESS(LAZYACCESS(offsets, PIXEL_Y_OFFSET), source) || 0, + LAZYACCESS(LAZYACCESS(offsets, PIXEL_Z_OFFSET), source) || 0, + ) + +#undef HOSTAGE_POSE_ANIM +#undef HOSTAGE_POSE_FREED +#undef HOSTAGE_POSE_HOLDER_ANIM +#undef HOSTAGE_POSE_SHOVE +#undef HOSTAGE_POSE_NEAR_S +#undef HOSTAGE_POSE_NEAR_N +#undef HOSTAGE_POSE_SIDE +#undef HOSTAGE_POSE_AHEAD +#undef HOSTAGE_POSE_ROW +#undef HOSTAGE_POSE_ROW_DROP +#undef HOSTAGE_POSE_QUARTER_TIME +#undef HOSTAGE_POSE_HALF_TIME +#undef HOSTAGE_POSE_LAND_TIME +#undef HOSTAGE_POSE_SETTLE_TIME diff --git a/voidcrew/modules/stealth/stealth_knife.dm b/voidcrew/modules/stealth/stealth_knife.dm new file mode 100644 index 00000000000..1e0a01ab1d1 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_knife.dm @@ -0,0 +1,14 @@ +/** + * # The matte combat knife (step 3a, owner decisions 5, 12, 45 and 46) + * + * tg's combat knife with a blackened blade. Its backstab is the one every sharp-edged knife has (the knife execution, + * voidcrew/modules/hyperviolence/overlays_exec/knife_executions.dm): from behind on a stealth guard caught off guard, + * whatever zone is aimed at, it is tg's throat slit without the grab, after a short hold; a cut throat can't speak, + * shout or use a radio (voidcrew/edits/datums/neck_slice_mute.dm). tg's grab slit works as before. + * + * Players get it as scav den loot (step 4). It has no buy, print or craft route. + */ +/obj/item/knife/combat/matte + name = "matte combat knife" + desc = "A combat knife with a blackened blade that doesn't catch the light." + color = "#6E6E7D" diff --git a/voidcrew/modules/stealth/stealth_light.dm b/voidcrew/modules/stealth/stealth_light.dm new file mode 100644 index 00000000000..b9ed901ff08 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_light.dm @@ -0,0 +1,620 @@ +/** + * # Stealth guards: flashlights (owner decisions 31, 39 and 41) + * + * A scav guard carries a real seclite clipped to its belt (or its vest, or a pocket). What it lights is a real + * light (decision 39): a hidden lamp, /obj/effect/abstract/stealth_torch, on the guard's own tile, that throws a + * beam the way it faces through tg's own static lighting (a directional light, as tg's wall lamps are). Everyone + * sees the beam, round corners too, and the darkness rule (stealth_tile_is_dark()) reads the same light the + * players see, so what looks dark is dark to the guards as well. The seclite item itself stays off and stays a + * plain tg seclite: a looted one works like any other, and nothing draws two beams. + * + * The beam (decision 41): a wedge that starts at the guard's hand, half a tile ahead of it, widens to three tiles + * and lights the floor up to four tiles ahead, brightest two and three tiles out. Its own tile, its sides and its + * back stay dark. tg's lighting stops it at walls and closed solid doors and lets it through glass, like any lamp + * (numbers in data/stealth/STATUS.md, decision 41). + * + * What the eye sees on top (decision 42): a cone in the air from the guard's lamp and a small glow there + * (/obj/effect/abstract/stealth_beam), so the beam visibly starts at the guard. Only the eye sees it. + * + * The beam moves like a hand moves it. Before a turn the guard makes on its own, the beam swings halfway there + * while the body leans (stealth_turns.dm), so the light shows where it is about to look. Any other turn of 90 + * degrees or more passes through the halfway point. A step at a walk carries the beam half a tile at a time. A + * guard that is searching, or looking round where it thought it saw something, swings the beam to one side, back, + * and to the other while it stands. + * + * The guard switches it as before: on when it stands somewhere dark (judged without any guard's light, decision 32, + * so two guards never switch each other off), always on while suspicious, alert or searching, off in lit places + * while unaware. It keeps it on for STEALTH_LIGHT_HOLD after it last wanted it, so walking along the edge of a lit + * room doesn't flick it on and off. The switch clicks. + * + * Beating it is tg's: you see the beam coming; an EMP or the saboteur gun cuts the seclite out for a while (the scav + * seclite takes an EMP as tg's saboteur hit; a stock seclite ignores EMPs), and it sputters twice as it dies; a + * guard that is down, stunned, cuffed, held, asleep or dead has no light; nor does one whose seclite was taken + * (decision 34: it can be stripped, knocked loose and looted like anyone's seclite). + * + * Other people's lights (decision 41): a lit light someone carries near an unaware guard that stands in the dark + * draws its notice even from behind (stealth_look()). It only ever makes the guard suspicious: it turns to look. + * + * Cost: the lamp updates only when the guard's turf or the beam's direction changes, or when it switches. A step + * at a walk is two static light updates (the half step and the landing), a turn one or two, a sweep one per + * STEALTH_TORCH_SWEEP_STEP while the guard is suspicious or searching and standing. A guard asleep in a dormant + * level moves, scans and sweeps nothing, so its lamp costs nothing. + */ + +/// Every guard's lamp, so a guard can leave them all out when it judges how dark its own spot is (decision 32) +GLOBAL_LIST_EMPTY(stealth_guard_torches) + +/// A guard's seclite: an EMP blinds it for a while, as tg's saboteur gun does. +/obj/item/flashlight/seclite/scav + +/obj/item/flashlight/seclite/scav/emp_act(severity) + . = ..() + if(. & EMP_PROTECT_SELF) + return + on_saboteur(null, severity == EMP_HEAVY ? STEALTH_LIGHT_EMP_HEAVY : STEALTH_LIGHT_EMP_LIGHT) + +/obj/item/flashlight/seclite/scav/on_saboteur(datum/source, disrupt_duration) + . = ..() + stealth_tell_holder(loc) + +/// Off a guard's body (looted, stripped, dropped), the guard's beam goes out at once. +/obj/item/flashlight/seclite/scav/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE) + . = ..() + stealth_tell_holder(old_loc) + +/// Tells the guard `holder` (if it is one) that its light changed. +/obj/item/flashlight/seclite/scav/proc/stealth_tell_holder(atom/holder) + if(!ishumannpc(holder)) + return + var/mob/living/carbon/human/npc/guard = holder + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + if(istype(stealth_ai)) + stealth_ai.stealth_update_light() + +/// Decision 34: a guard's seclite is loot like anyone's, so it is never locked to the body (D3 holds for the rest). +/// Decision 40: so are the scavs' fatigues, balaclava and pass (stealth_disguise.dm). +/mob/living/carbon/human/npc/npc_lock_item(obj/item/item) + if(istype(item, /obj/item/flashlight/seclite/scav) || istype(item, /obj/item/clothing/under/syndicate/scav)) + return FALSE + if(istype(item, /obj/item/clothing/mask/balaclava/scav) || istype(item, /obj/item/card/id/advanced/black/scav)) + return FALSE + return ..() + +/mob/living/carbon/human/npc + /// Weakref to the flashlight a stealth guard switches on in the dark, or null for none + var/datum/weakref/stealth_light + +/// Clips a seclite on: belt, vest, then a pocket. Returns it, or null if there was nowhere to put it. +/mob/living/carbon/human/npc/proc/stealth_give_light() + var/obj/item/flashlight/seclite/scav/light = new(src) + for(var/slot in list(ITEM_SLOT_BELT, ITEM_SLOT_SUITSTORE, ITEM_SLOT_LPOCKET, ITEM_SLOT_RPOCKET)) + if(equip_to_slot_if_possible(light, slot, disable_warning = TRUE)) + stealth_light = WEAKREF(light) + return light + qdel(light) + return null + +/** + * The lamp behind a guard's flashlight beam: a real static light with no sprite, on the guard's own tile. It is + * never entered into a turf (abstract_move()), so it trips nothing, and nothing can touch, move or burn it. + */ +/obj/effect/abstract/stealth_torch + name = "flashlight beam" + icon = null + mouse_opacity = MOUSE_OPACITY_TRANSPARENT + anchored = TRUE + blocks_emissive = EMISSIVE_BLOCK_NONE + light_system = COMPLEX_LIGHT + light_range = STEALTH_TORCH_RANGE + light_power = STEALTH_TORCH_POWER + light_color = STEALTH_TORCH_COLOR + light_angle = STEALTH_TORCH_ANGLE + light_flags = LIGHT_IGNORE_OFFSET + light_on = FALSE + /// Where the beam starts, in tiles from the middle of the lamp's tile, as tg's light offset: a negative x is east + var/beam_x = 0 + var/beam_y = 0 + /// The guard's AI that owns it (it deletes the lamp with itself), so a test that applies the light can land its cone + var/datum/ai_controller/basic_controller/human_npc/stealth/owner_ai + +/obj/effect/abstract/stealth_torch/Initialize(mapload) + . = ..() + GLOB.stealth_guard_torches += src + +/obj/effect/abstract/stealth_torch/Destroy() + GLOB.stealth_guard_torches -= src + owner_ai = null + return ..() + +/obj/effect/abstract/stealth_torch/get_light_offset() + return list(beam_x, beam_y) + +/** + * What the eye sees of a guard's beam (decision 42): a cone of light in the air, narrow at its lamp and widening + * ahead, with a small glow at the lamp. It sits on tg's overlay-light plane and adds to the light there, as tg's own + * flashlight cones do, so it brightens what it falls on, shows in the dark and all but vanishes in a lit room. It is + * part of the guard (vis_contents), so it glides with every step. It is only for the eye: guards see, and tiles count + * as lit, by the real lamp alone. It stops at the first wall or solid door ahead (stealth_beam_reach()). + * It never shows ahead of the lamp's light on the floor: a new aim waits until SSlighting has applied the lamp + * (stealth_queue(), stealth_cone_check()), so when lighting runs slow the whole flashlight is slow together. + */ +/obj/effect/abstract/stealth_beam + name = "flashlight beam" + icon = 'voidcrew/icons/effects/stealth_beam.dmi' + icon_state = "beam_22" + mouse_opacity = MOUSE_OPACITY_TRANSPARENT + anchored = TRUE + blocks_emissive = EMISSIVE_BLOCK_NONE + blend_mode = BLEND_ADD + appearance_flags = RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM | KEEP_APART | PIXEL_SCALE + // The icon's bottom middle on the guard's tile centre + pixel_x = -48 + pixel_y = 16 + /// The guard it is shown on, or null + var/mob/living/holder + /// The way it points now, or 0 + var/shown_dir = 0 + /// The facing of the guard when it was last aimed (the lamp's place on the body follows that) + var/shown_body_dir = 0 + /// Its length now, in the icon's steps (STEALTH_BEAM_LENGTHS when nothing stops it), or 0 + var/shown_reach = 0 + /// The guard it waits to be shown on once the lamp's light is applied, or null + var/mob/living/pending_guard + /// What it will show then: the way it points, its length and the guard's facing + var/pending_dir = 0 + var/pending_reach = 0 + var/pending_body_dir = 0 + +/obj/effect/abstract/stealth_beam/Destroy() + stealth_hide() + return ..() + +/// Takes it off its guard. +/obj/effect/abstract/stealth_beam/proc/stealth_hide() + pending_guard = null + if(holder) + holder.vis_contents -= src + holder = null + shown_dir = 0 + shown_body_dir = 0 + shown_reach = 0 + +/// Shows it as stealth_show() once the lamp's light has been applied (stealth_flush()). Until then it stays as it was. +/obj/effect/abstract/stealth_beam/proc/stealth_queue(mob/living/guard, beam_dir, reach) + pending_guard = guard + pending_dir = beam_dir + pending_reach = reach + pending_body_dir = guard.dir + +/// The lamp's light is applied: shows what was waiting for it, if its guard is still about. +/obj/effect/abstract/stealth_beam/proc/stealth_flush() + var/mob/living/guard = pending_guard + pending_guard = null + if(!QDELETED(guard)) + stealth_show(guard, pending_dir, pending_reach, pending_body_dir) + +/// Shows it on `guard`, pointing `beam_dir` and `reach` eighths of a tile long, for the guard facing `body_dir` (its +/// facing now by default). Touches nothing that is already so. +/obj/effect/abstract/stealth_beam/proc/stealth_show(mob/living/guard, beam_dir, reach, body_dir) + pending_guard = null + if(!body_dir) + body_dir = guard.dir + if(holder != guard) + stealth_hide() + holder = guard + guard.vis_contents += src + SET_PLANE_EXPLICIT(src, O_LIGHTING_VISUAL_PLANE, guard) + // Pointing away from the camera, the guard's body hides the lamp: no glow, and the cone comes out past its back. + var/away = body_dir & NORTH + var/state = "[away ? "back" : "beam"]_[reach]" + shown_reach = reach + if(icon_state != state) + icon_state = state + if(shown_dir == beam_dir && shown_body_dir == body_dir) + return + shown_dir = beam_dir + shown_body_dir = body_dir + // The lamp is at its belt: a little ahead facing away, a little below the middle facing the camera or sideways. + var/forward = away ? 4 : ((body_dir & SOUTH) ? -6 : 0) + var/drop = (body_dir & (EAST|WEST)) && !(body_dir & (NORTH|SOUTH)) ? -3 : 0 + var/matrix/aim = matrix() + aim.Translate(0, STEALTH_BEAM_PIVOT + forward) + aim.Turn(dir2angle(beam_dir)) + aim.Translate(0, drop - STEALTH_BEAM_PIVOT) + transform = aim + +/** + * Cuts what it shows now down to `reach` steps; never makes it longer. While a new aim waits on the lamp + * (stealth_queue()) the old cone stays on the guard, who may have walked on or round a corner since: this keeps + * that old cone from running past a wall from where the guard is now. + */ +/obj/effect/abstract/stealth_beam/proc/stealth_trim(reach) + if(isnull(holder) || reach >= shown_reach) + return + shown_reach = reach + icon_state = "[(shown_body_dir & NORTH) ? "back" : "beam"]_[reach]" + +/// How long a guard's visible cone is from `spot` pointing `beam_dir`, in eighths of a tile: up to a little onto the +/// first wall or solid door (what stops tg's light), or STEALTH_BEAM_LENGTHS for nothing in its reach. +/proc/stealth_beam_reach(turf/spot, beam_dir) + var/diagonal = !(beam_dir in GLOB.cardinals) + var/turf/here = spot + for(var/steps in 1 to STEALTH_TORCH_RANGE) + var/turf/next = get_step(here, beam_dir) + var/blocked = isnull(next) || IS_OPAQUE_TURF(next) + if(!blocked && diagonal) + // Light doesn't squeeze between two corners. + var/turf/one_side = get_step(here, beam_dir & (NORTH|SOUTH)) + var/turf/other_side = get_step(here, beam_dir & (EAST|WEST)) + blocked = (isnull(one_side) || IS_OPAQUE_TURF(one_side)) && (isnull(other_side) || IS_OPAQUE_TURF(other_side)) + if(blocked) + // to the blocker's near face, then 6 px onto it + var/pixels = (steps - 0.5) * (diagonal ? 45 : 32) + 6 + return clamp(round(pixels / 8, 1), 1, STEALTH_BEAM_LENGTHS - 1) + here = next + return STEALTH_BEAM_LENGTHS + +/// How much every guard's lamp adds to `tile` right now, in get_lumcount() units. +/proc/stealth_torch_share(turf/tile) + . = 0 + if(!isturf(tile)) + return + for(var/obj/effect/abstract/stealth_torch/torch as anything in GLOB.stealth_guard_torches) + var/datum/light_source/source = torch.light + var/list/strengths = source?.effect_str + if(!length(strengths) || torch.z != tile.z || get_dist(torch, tile) > STEALTH_TORCH_RANGE + 2) + continue + var/channels = source.applied_lum_r + source.applied_lum_g + source.applied_lum_b + for(var/datum/lighting_corner/corner as anything in list(tile.lighting_corner_NE, tile.lighting_corner_SE, tile.lighting_corner_SW, tile.lighting_corner_NW)) + if(corner) + . += (strengths[corner] || 0) * channels + . /= 12 // as get_lumcount(): 4 corners, 3 channels each + +/// How far the lit light `who` carries reaches, in tiles: a flashlight in a hand or on a belt, a lit PDA, a flare. +/// 0 with nothing lit. +/proc/stealth_carried_light(mob/living/who) + . = 0 + // tg's overlay lights (flashlights, PDAs, helmet lights): light => reach + 1, listed only while lit + for(var/glow in who.affected_dynamic_lights) + . = max(., who.affected_dynamic_lights[glow] - 1) + // tg's static lights carried on the body (flares, lanterns) + for(var/datum/light_source/source as anything in who.light_sources) + if(source.top_atom == who) + . = max(., CEILING(source.light_range, 1)) + +/// The swing between two facings in degrees, -180 to 179: positive when `first` is clockwise of `second`. +/proc/stealth_swing(first, second) + return (dir2angle(first) - dir2angle(second) + 540) % 360 - 180 + +/datum/ai_controller/basic_controller/human_npc/stealth + /// world.time until which it keeps its light on after it last wanted it + var/light_hold_until = 0 + /// Whether it has its light on (the beam shows whenever it stands on a turf) + var/light_lit = FALSE + /// The lamp behind its beam, made the first time it is switched on + var/obj/effect/abstract/stealth_torch/torch + /// The cone players see over its beam (decision 42), made with the lamp + var/obj/effect/abstract/stealth_beam/beam + /// Where it points the beam off its facing, in 45 degree steps anticlockwise: a sweep, or the lead of a turn + var/torch_aim = 0 + /// The way the beam points for a moment in the middle of a turn, or 0 + var/torch_pass = 0 + /// world.time of that turn: a step in the same tick (tg turns a walker before it moves) keeps it + var/torch_passed_at = 0 + /// How far behind its tile the beam still is in the middle of a step, in tiles + var/torch_lag_x = 0 + var/torch_lag_y = 0 + /// Counts beam moves, so a timer from an older one does nothing + var/torch_serial = 0 + /// world.time it last stepped + var/torch_moved_at = 0 + /// Whether its sweep timer is running + var/sweeping = FALSE + /// Where it is in the sweep: 1 one side, 2 back, 3 the other side, 4 back + var/sweep_step = 0 + /// Counts switches, so a light that comes back stops a sputter + var/sputter_serial = 0 + /// The timer that shows its cone once its lamp's light is applied, or null when nothing waits + var/cone_timer + /// world.time its cone started waiting on the lamp + var/cone_wait_since = 0 + /// The tile it stepped off while its body still glides from it (the cone is drawn on the body), or null + var/turf/torch_from + /// world.time that glide ends + var/torch_from_until = 0 + +/// Its flashlight, if it still has it on its body; else null. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_light() + var/mob/living/carbon/human/npc/guard = pawn + if(!ishumannpc(guard)) + return null + var/obj/item/flashlight/light = guard.stealth_light?.resolve() + if(QDELETED(light) || light.loc != guard) + return null + return light + +/// Whether it can use its light at all: awake, its own, free, hands working, and the seclite on it and not cut out. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_light_usable() + var/mob/living/carbon/human/npc/guard = pawn + if(QDELETED(guard) || guard.stat != CONSCIOUS || stealth_driven() || stealth_captive() || HAS_TRAIT(guard, TRAIT_HANDS_BLOCKED)) + return FALSE + var/obj/item/flashlight/light = stealth_light() + return !isnull(light) && COOLDOWN_FINISHED(light, disabled_time) + +/// Switches its light on or off for where it stands and what it is doing. Off at once when it can't use it. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_update_light() + if(!stealth_light_usable()) + var/was_lit = light_lit + light_hold_until = 0 + stealth_set_light(FALSE) + if(was_lit) + stealth_light_cut() + return + var/mob/living/guard = pawn + // Its own spot judged by the room's light alone: a friend's passing beam doesn't switch it off (decision 32). + var/wanted = stealth_state() != STEALTH_UNAWARE || stealth_tile_is_dark(get_turf(guard), no_guard_lights = TRUE) + if(wanted) + light_hold_until = world.time + STEALTH_LIGHT_HOLD + else if(world.time < light_hold_until) + stealth_place_torch() + return + stealth_set_light(wanted, TRUE) + stealth_sweep_check() + +/// `click`: it worked the switch itself, which is heard. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_set_light(lit, click = FALSE) + if(lit != light_lit) + if(click && !QDELETED(pawn)) + playsound(pawn, lit ? 'sound/items/weapons/magin.ogg' : 'sound/items/weapons/magout.ogg', STEALTH_TORCH_CLICK_VOLUME, TRUE, -4) + sputter_serial++ + torch_serial++ + torch_aim = 0 + torch_pass = 0 + torch_lag_x = 0 + torch_lag_y = 0 + light_lit = lit + stealth_place_torch() + +/// The way its beam points now: its facing, off to a side in a sweep or ahead of a turn, or halfway through a turn. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_beam_dir() + if(torch_pass) + return torch_pass + var/mob/living/guard = pawn + return torch_aim ? turn(guard.dir, 45 * torch_aim) : guard.dir + +/// Points the lamp where its beam goes now, or puts it out. Touches the light only when something changed. +/// `flash` shows the beam with the light off (a dying seclite's sputter). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_place_torch(flash = FALSE) + var/mob/living/guard = pawn + var/turf/spot = ((light_lit || flash) && !QDELETED(guard) && isturf(guard.loc)) ? guard.loc : null + if(isnull(spot)) + beam?.stealth_hide() + stealth_cone_stop() + if(torch?.light_on) + torch.set_light_on(FALSE) + torch.update_light() + return + if(QDELETED(torch)) + torch = new(spot) + torch.owner_ai = src + if(QDELETED(beam)) + beam = new(null) + var/beam_dir = stealth_beam_dir() + // The cone glides with the guard, so it needs no half steps; it is cut where the light is stopped. + var/reach = stealth_cone_reach(spot, beam_dir) + // The beam starts at its hand, ahead of its own tile, less whatever a step in progress still holds back. + var/start_x = torch_lag_x - STEALTH_TORCH_FORWARD * ((beam_dir & EAST) ? 1 : ((beam_dir & WEST) ? -1 : 0)) + var/start_y = torch_lag_y - STEALTH_TORCH_FORWARD * ((beam_dir & NORTH) ? 1 : ((beam_dir & SOUTH) ? -1 : 0)) + var/changed = !torch.light_on || torch.light_dir != beam_dir || torch.beam_x != start_x || torch.beam_y != start_y + // A move rebuilds the light by itself (the source follows its host's Moved). + if(torch.loc != spot) + torch.abstract_move(spot) + if(changed) + torch.beam_x = start_x + torch.beam_y = start_y + torch.set_light_dir(beam_dir) + torch.set_light_on(TRUE) + // tg's light setters don't rebuild a COMPLEX_LIGHT source on their own (see /obj/item/flashlight/update_brightness()). + torch.update_light() + // The cone never shows ahead of the light on the floor: while the lamp waits on SSlighting, so does the cone. + if(torch.light?.needs_update) + beam.stealth_queue(guard, beam_dir, reach) + // What still shows was aimed from where it stood then: cut it at the walls round where it stands now. + if(beam.shown_dir) + beam.stealth_trim(stealth_cone_reach(spot, beam.shown_dir)) + if(!cone_timer) + cone_wait_since = world.time + cone_timer = addtimer(CALLBACK(src, PROC_REF(stealth_cone_check)), world.tick_lag, TIMER_STOPPABLE) + else + beam.stealth_show(guard, beam_dir, reach) + stealth_cone_stop() + +/** + * How long its cone may be pointing `beam_dir` from `spot`, in the icon's steps: to the first wall or solid door + * (stealth_beam_reach()). Mid-step the body is drawn between the tile it left and `spot`, so the cone also stops at + * whatever is ahead of the tile it left. Without this, a guard backing away from a wall would show its cone through it + * until the glide ended. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_cone_reach(turf/spot, beam_dir) + . = stealth_beam_reach(spot, beam_dir) + if(torch_from && world.time < torch_from_until) + . = min(., stealth_beam_reach(torch_from, beam_dir)) + +/// Its body has finished gliding off the tile it stepped from: the cone may reach as far as the light again. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_cone_landed() + if(isnull(torch_from) || world.time < torch_from_until) + return + torch_from = null + if(light_lit) + stealth_place_torch() + +/// Its cone waits on the lamp: shown once SSlighting has applied the lamp's light (or after STEALTH_BEAM_WAIT_CAP), +/// else looked at again next tick. Runs only while something waits. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_cone_check() + cone_timer = null + if(QDELETED(beam) || isnull(beam.pending_guard)) + return + if(torch?.light?.needs_update && world.time < cone_wait_since + STEALTH_BEAM_WAIT_CAP) + cone_timer = addtimer(CALLBACK(src, PROC_REF(stealth_cone_check)), world.tick_lag, TIMER_STOPPABLE) + return + beam.stealth_flush() + +/// Stops waiting on the lamp (the cone was shown or hidden). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_cone_stop() + if(cone_timer) + deltimer(cone_timer) + cone_timer = null + +/// Whether its light is on with its beam showing (for admins and tests). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_light_shows() + return light_lit && !QDELETED(torch) && torch.light_on + +/// It stepped from `old_loc`: the beam follows, half a tile at a time at a walk. Nothing to do with its light off. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_light_stepped(atom/old_loc) + if(!light_lit) + return + if(!stealth_light_usable()) + stealth_update_light() + return + var/mob/living/guard = pawn + var/walked = isturf(old_loc) && isturf(guard.loc) && guard.move_intent == MOVE_INTENT_WALK && old_loc.z == guard.z && get_dist(old_loc, guard) == 1 + torch_moved_at = world.time + torch_aim = 0 + // A step that turns a corner keeps its turn's halfway point, so the beam doesn't snap round the corner. + if(torch_passed_at != world.time) + torch_pass = 0 + torch_lag_x = 0 + torch_lag_y = 0 + sweep_step = 0 + torch_serial++ + // The body glides off the old tile over its step; until it lands the cone also stops at walls ahead of that tile. + torch_from = null + if(isturf(old_loc) && isturf(guard.loc) && old_loc.z == guard.z && get_dist(old_loc, guard) == 1 && guard.glide_size > 0) + var/glide = min(CEILING(ICON_SIZE_ALL / guard.glide_size, 1) * world.tick_lag, 1 SECONDS) + torch_from = old_loc + torch_from_until = world.time + glide + addtimer(CALLBACK(src, PROC_REF(stealth_cone_landed)), glide) + if(walked) + torch_lag_x = 0.5 * (guard.x - old_loc.x) + torch_lag_y = 0.5 * (guard.y - old_loc.y) + addtimer(CALLBACK(src, PROC_REF(stealth_torch_settle), torch_serial), STEALTH_TORCH_HALF_STEP) + else if(torch_pass) + addtimer(CALLBACK(src, PROC_REF(stealth_torch_settle), torch_serial), STEALTH_TORCH_TURN_STEP) + stealth_place_torch() + +/// It turned from `old_dir`: the beam follows, through the halfway point when the turn is 90 degrees or more. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_light_turned(old_dir, new_dir) + if(!light_lit) + return + if(!stealth_light_usable()) + stealth_update_light() + return + // Where the beam points now: ahead of the turn already, if it led it. + var/was = torch?.light_on ? torch.light_dir : old_dir + torch_aim = 0 + torch_pass = 0 + sweep_step = 0 + var/swing = stealth_swing(was, new_dir) + // Mid-step (a diagonal step turns the walker after it moves) the half step's timer lands the beam; a turn on the + // spot gets its own. + if(abs(swing) > 45) + torch_pass = turn(new_dir, swing > 0 ? -45 : 45) + torch_passed_at = world.time + if(!torch_lag_x && !torch_lag_y) + torch_serial++ + addtimer(CALLBACK(src, PROC_REF(stealth_torch_settle), torch_serial), STEALTH_TORCH_TURN_STEP) + stealth_place_torch() + +/// The beam lands: the half step or the halfway point of a turn is over. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_torch_settle(serial) + if(serial != torch_serial) + return + torch_pass = 0 + torch_lag_x = 0 + torch_lag_y = 0 + stealth_place_torch() + +/// About to turn to `new_dir` on its own (stealth_turn_to()): the beam goes halfway there first. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_torch_lead(new_dir) + if(!light_lit) + return + var/mob/living/guard = pawn + var/swing = stealth_swing(new_dir, guard.dir) + if(!swing) + return + torch_pass = 0 + torch_aim = swing > 0 ? -1 : 1 + stealth_place_torch() + +/// The turn it led never came, or the sweep is over: the beam goes back to its facing. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_torch_straighten() + if(!torch_aim) + return + torch_aim = 0 + stealth_place_torch() + +/// Whether it swings its beam about: searching, or looking round where it thought it saw something. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_sweeps() + if(!light_lit || !stealth_scanning()) + return FALSE + switch(stealth_state()) + if(STEALTH_SEARCHING) + return TRUE + if(STEALTH_SUSPICIOUS) + // Not while it stares at the spot, and not into the face of someone it has stopped (decision 40). + return investigated && isnull(challenge) + return FALSE + +/// Starts its sweep if it should be sweeping and isn't. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_sweep_check() + if(sweeping || !stealth_sweeps()) + return + sweeping = TRUE + sweep_step = 0 + addtimer(CALLBACK(src, PROC_REF(stealth_sweep_tick)), STEALTH_TORCH_SWEEP_STEP) + +/// One move of the sweep: a side, back, the other side, back. It waits out steps and turns, and ends by itself. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_sweep_tick() + if(!stealth_sweeps()) + sweeping = FALSE + sweep_step = 0 + if(!turn_pending) + stealth_torch_straighten() + return + addtimer(CALLBACK(src, PROC_REF(stealth_sweep_tick)), STEALTH_TORCH_SWEEP_STEP) + // Walking, about to turn, or just turned: the beam is spoken for. + if(turn_pending || torch_pass || world.time < torch_moved_at + STEALTH_TORCH_SWEEP_STEP || (turned_at && world.time < turned_at + STEALTH_TORCH_SWEEP_STEP)) + sweep_step = 0 + return + sweep_step = (sweep_step % 4) + 1 + switch(sweep_step) + if(1) + torch_aim = look_side + if(3) + torch_aim = -look_side + else + torch_aim = 0 + stealth_place_torch() + +/// Its light went out under it. A seclite that was cut out (an EMP, the saboteur gun) sputters twice, and it says so. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_light_cut() + var/mob/living/guard = pawn + if(QDELETED(guard) || guard.stat != CONSCIOUS || stealth_driven() || stealth_captive() || HAS_TRAIT(guard, TRAIT_HANDS_BLOCKED)) + return + var/obj/item/flashlight/light = stealth_light() + if(isnull(light) || COOLDOWN_FINISHED(light, disabled_time)) + return + var/serial = sputter_serial + for(var/flash_at in STEALTH_TORCH_SPUTTER_AT) + addtimer(CALLBACK(src, PROC_REF(stealth_sputter), serial, TRUE), flash_at) + addtimer(CALLBACK(src, PROC_REF(stealth_sputter), serial, FALSE), flash_at + STEALTH_TORCH_SPUTTER_FLASH) + stealth_bark(STEALTH_BARK_LIGHT_DEAD) + +/// One flash of a dying seclite, on or off again. Nothing if the light is back, gone, or its guard is down. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_sputter(serial, on) + if(serial != sputter_serial || light_lit) + return + var/mob/living/guard = pawn + if(on && (QDELETED(guard) || guard.stat != CONSCIOUS || isnull(stealth_light()))) + return + stealth_place_torch(flash = on) diff --git a/voidcrew/modules/stealth/stealth_meter.dm b/voidcrew/modules/stealth/stealth_meter.dm new file mode 100644 index 00000000000..5695a3842c0 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_meter.dm @@ -0,0 +1,310 @@ +/** + * # Stealth guards: the mark over the head (owner decisions 24 and 27, draft D) + * + * - Its notice of you above 0: a "?" only you see (a client image). It fills yellow from the bottom to + * STEALTH_SUSPICIOUS_AT, then red rises through the yellow toward STEALTH_ALERT_AT. + * - Alert: a solid red "!" everyone sees. Target out of sight: the red drains from the top over + * STEALTH_LOSE_TARGET_TIME and refills when it sees them again. + * - Searching: a yellow "?" everyone sees, draining from the top over the search (or until calm_until + * after it put its target down). Empty: gone. + * - While alert or searching, nobody sees their own "?" on that guard. + * - Suspicious of a noise (stealth_hearing.dm): an empty grey "?" for every player near who has no fill of + * their own on that guard. Someone it has started to see gets their own filling "?" instead, so nothing + * stacks. A glance, a hold and a radio call show no mark: the turn, the raised hand and the line are the read. + * + * Both are drawn on the guard (vis_contents for the public mark, an image located on the guard for the + * private one), so they show only when the guard itself is in view, never through walls; above the + * lighting so they read in the dark. Fills round to the nearest row; drains round up, so the last row + * stays lit until the time really runs out. + * + * Cost: the meter is built only while a living player is within STEALTH_METER_RANGE of a guard whose scan + * is running (or an admin is watching its sight), updated by the guard's 1 s scan and its state changes, + * and changes an icon_state only when the step changes. A drain steps on a timer at each row change (at + * most STEALTH_METER_ROWS per drain); animate() is not used, because a chained icon_state animation can't + * snap back when the target is seen again. + * + * The mark lives only while the scan that feeds it runs. A guard that is cuffed, held, stunned, down, asleep + * with its level, or driven by a player has no mark, so none is ever left stale over its head. + */ +/datum/stealth_meter + /// The guard's controller, which owns this meter + var/datum/ai_controller/basic_controller/human_npc/stealth/controller + var/mob/living/guard + /// The public mark, in the guard's vis_contents while it shows + var/obj/effect/abstract/stealth_mark/mark + /// icon_state of the public mark, or null + var/public_state + /// REF(player), or "watch:ckey" for an admin watching its sight => list(image, client it was given to) + var/list/private_marks = list() + /// Timer for the next drain step + var/drain_timer + +/datum/stealth_meter/New(datum/ai_controller/basic_controller/human_npc/stealth/controller, mob/living/guard) + src.controller = controller + src.guard = guard + RegisterSignal(guard, COMSIG_LIVING_SET_BODY_POSITION, PROC_REF(on_body_position)) + +/datum/stealth_meter/Destroy() + if(drain_timer) + deltimer(drain_timer) + drain_timer = null + set_public(null) + for(var/key in private_marks.Copy()) + remove_private(key) + if(guard) + UnregisterSignal(guard, COMSIG_LIVING_SET_BODY_POSITION) + controller = null + guard = null + return ..() + +/// Reads the controller and shows what it says. Changes nothing that hasn't changed. +/datum/stealth_meter/proc/update() + if(QDELETED(guard) || isnull(controller)) + return + var/state = controller.stealth_state() + var/new_public = stealth_meter_public_state(state, world.time, controller.lost_since, controller.blackboard[BB_STEALTH_STATE_SINCE], controller.calm_until, controller.stealth_skill().search_time) + set_public(new_public) + // Alert and searching own the mark even once it has drained: no private "?" in the moment before the scan + // sends it back to unaware (and clears its notice). + var/public_owned = new_public || state == STEALTH_ALERT || state == STEALTH_SEARCHING + update_private(public_owned ? null : controller.notice_map, !public_owned && stealth_meter_heard(state, controller.suspicion_heard)) + schedule_drain() + +/datum/stealth_meter/proc/set_public(new_state) + if(new_state == public_state) + return + public_state = new_state + if(isnull(new_state)) + if(mark) + guard?.vis_contents -= mark + QDEL_NULL(mark) + return + if(isnull(mark)) + mark = new + SET_PLANE_EXPLICIT(mark, ABOVE_LIGHTING_PLANE, guard) + mark.pixel_z = stealth_meter_offset(guard) + guard.vis_contents += mark + mark.icon_state = new_state + +/// The players near the guard who get the empty grey "?" of a heard noise: every living player within +/// STEALTH_METER_RANGE with no fill of their own in `notice`. +/datum/stealth_meter/proc/heard_viewers(list/notice) + . = list() + var/turf/here = get_turf(guard) + if(isnull(here) || here.z > length(SSmobs.clients_by_zlevel)) + return + for(var/mob/living/viewer as anything in SSmobs.clients_by_zlevel[here.z]) + if(viewer == guard || get_dist(get_turf(viewer), here) > STEALTH_METER_RANGE) + continue + var/list/entry = notice?[REF(viewer)] + if(entry && stealth_meter_notice_state(entry[STEALTH_ENTRY_NOTICE])) + continue + . += viewer + +/// Gives each nearby player their own "?" for their notice entry, and takes away the rest. An admin watching +/// the guard's sight gets the fullest one, whoever it is for. `heard`: the guard is suspicious of a noise, so +/// everyone near without a fill of their own gets the empty "?". +/datum/stealth_meter/proc/update_private(list/notice, heard = FALSE) + // key => list(icon_state, client to show it to) + var/list/wanted = list() + var/turf/here = get_turf(guard) + if(heard && here) + for(var/mob/living/viewer as anything in heard_viewers(notice)) + if(viewer.client) + wanted[REF(viewer)] = list(STEALTH_METER_HEARD_STATE, viewer.client) + for(var/datum/stealth_sight_overlay/overlay as anything in controller.watchers) + var/client/admin = overlay.user_ref?.resolve() + if(admin && !wanted[REF(admin.mob)]) + wanted["watch:[admin.ckey]"] = list(STEALTH_METER_HEARD_STATE, admin) + if(length(notice) && here) + var/top_state + var/top_notice = 0 + for(var/key in notice) + var/list/entry = notice[key] + var/state = stealth_meter_notice_state(entry[STEALTH_ENTRY_NOTICE]) + if(isnull(state)) + continue + if(entry[STEALTH_ENTRY_NOTICE] > top_notice) + top_notice = entry[STEALTH_ENTRY_NOTICE] + top_state = state + var/mob/viewer = locate(key) + if(!ismob(viewer) || isnull(viewer.client)) + continue + // By its turf: someone hiding in a box has no z of their own. + var/turf/viewer_turf = get_turf(viewer) + if(viewer_turf?.z != here.z || get_dist(viewer_turf, here) > STEALTH_METER_RANGE) + continue + wanted[key] = list(state, viewer.client) + if(top_state) + for(var/datum/stealth_sight_overlay/overlay as anything in controller.watchers) + var/client/admin = overlay.user_ref?.resolve() + if(isnull(admin)) + continue + var/list/own = wanted[REF(admin.mob)] + if(own && own[1] != STEALTH_METER_HEARD_STATE) + continue + // The fullest fill takes the place of the admin's empty heard "?": one glyph at a time. + wanted -= REF(admin.mob) + wanted["watch:[admin.ckey]"] = list(top_state, admin) + for(var/key in private_marks.Copy()) + var/list/held = private_marks[key] + var/list/want = wanted[key] + if(isnull(want) || want[2] != held[2]) + remove_private(key) + for(var/key in wanted) + var/list/want = wanted[key] + var/list/held = private_marks[key] + if(held) + var/image/shown = held[1] + if(shown.icon_state != want[1]) + shown.icon_state = want[1] + continue + var/client/viewer = want[2] + var/image/shown = image('voidcrew/icons/effects/stealth_meter.dmi', guard, want[1]) + shown.appearance_flags = RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM | KEEP_APART + shown.mouse_opacity = MOUSE_OPACITY_TRANSPARENT + SET_PLANE_EXPLICIT(shown, ABOVE_LIGHTING_PLANE, guard) + shown.pixel_z = stealth_meter_offset(guard) + viewer.images += shown + private_marks[key] = list(shown, viewer) + +/datum/stealth_meter/proc/remove_private(key) + var/list/held = private_marks[key] + private_marks -= key + if(!held) + return + var/image/shown = held[1] + var/client/given_to = held[2] + given_to?.images -= shown + shown.loc = null + +/// A draining mark steps at each row change rather than waiting for the next scan. +/datum/stealth_meter/proc/schedule_drain() + if(drain_timer) + deltimer(drain_timer) + drain_timer = null + var/delay = stealth_meter_next_step(controller.stealth_state(), world.time, controller.lost_since, controller.blackboard[BB_STEALTH_STATE_SINCE], controller.calm_until, controller.stealth_skill().search_time) + if(delay > 0) + drain_timer = addtimer(CALLBACK(src, PROC_REF(on_drain_step)), delay, TIMER_STOPPABLE) + +/datum/stealth_meter/proc/on_drain_step() + drain_timer = null + controller?.stealth_meter_update() + +/datum/stealth_meter/proc/on_body_position(datum/source) + SIGNAL_HANDLER + var/offset = stealth_meter_offset(guard) + if(mark) + mark.pixel_z = offset + for(var/key in private_marks) + var/list/held = private_marks[key] + var/image/shown = held[1] + shown.pixel_z = offset + +/// The public mark. Lives only in its guard's vis_contents. +/obj/effect/abstract/stealth_mark + name = "" + icon = 'voidcrew/icons/effects/stealth_meter.dmi' + icon_state = null + mouse_opacity = MOUSE_OPACITY_TRANSPARENT + appearance_flags = RESET_COLOR | RESET_ALPHA | RESET_TRANSFORM | KEEP_APART + anchored = TRUE + +// ===== The controller's side ===== + +/datum/ai_controller/basic_controller/human_npc/stealth + /// The mark over its head while anyone is near to see it (stealth_meter.dm) + var/datum/stealth_meter/meter + +/// Builds, updates or drops the mark. Nothing while its scan isn't running (stealth_scanning()), or with no +/// living player near and no admin watching its sight. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_meter_update() + var/mob/living/guard = pawn + if(!stealth_scanning() || (!length(watchers) && !stealth_meter_viewers_near(guard))) + QDEL_NULL(meter) + return + if(isnull(meter)) + meter = new(src, guard) + meter.update() + +/// Whether a living player is close enough to the guard to see its mark. +/proc/stealth_meter_viewers_near(mob/living/guard) + var/turf/here = get_turf(guard) + if(isnull(here) || here.z > length(SSmobs.clients_by_zlevel)) + return FALSE + for(var/mob/viewer as anything in SSmobs.clients_by_zlevel[here.z]) + if(get_dist(viewer, here) <= STEALTH_METER_RANGE) + return TRUE + return FALSE + +/// pixel_z for the glyph's bottom over `guard`: clear of its head, lower when it lies down. +/proc/stealth_meter_offset(mob/living/guard) + if(guard.body_position == LYING_DOWN) + return STEALTH_METER_LYING_Z + . = STEALTH_METER_HEAD_Z + if(ishuman(guard)) + var/mob/living/carbon/human/person = guard + // The head rides the upper body offset (measured in a live client: a dwarf's head sits 5 px lower, not 9). + var/list/offsets = GLOB.human_heights_to_offsets["[person.mob_height]"] + if(length(offsets)) + . += offsets[1] + +// ===== Pure: state to icon_state ===== + +/// Whether a guard in `state` shows the heard "?". +/proc/stealth_meter_heard(state, suspicion_heard) + return suspicion_heard && state == STEALTH_SUSPICIOUS + +/// The private "?" for a notice level, or null for none. Fills round to the nearest row. +/proc/stealth_meter_notice_state(notice) + if(!(notice > 0)) + return null + if(notice < STEALTH_SUSPICIOUS_AT) + return "q_y[clamp(round(notice / STEALTH_SUSPICIOUS_AT * STEALTH_METER_ROWS, 1), 0, STEALTH_METER_ROWS)]" + var/red = clamp(round((notice - STEALTH_SUSPICIOUS_AT) / (STEALTH_ALERT_AT - STEALTH_SUSPICIOUS_AT) * STEALTH_METER_ROWS, 1), 0, STEALTH_METER_ROWS) + return red ? "q_r[red]" : "q_y[STEALTH_METER_ROWS]" + +/// Rows still lit with `time_left` of `total`: rounded up, 0 once the time is up. +/proc/stealth_meter_drain_rows(time_left, total) + if(total <= 0 || time_left <= 0) + return 0 + return clamp(CEILING(time_left / total * STEALTH_METER_ROWS - 0.001, 1), 0, STEALTH_METER_ROWS) + +/// When a public drain ends and how long it lasts, as list(end, total), or null when nothing drains. +/proc/stealth_meter_drain_span(state, lost_since, state_since, calm_until, search_time = STEALTH_SEARCH_TIME) + switch(state) + if(STEALTH_ALERT) + if(lost_since) + return list(lost_since + STEALTH_LOSE_TARGET_TIME, STEALTH_LOSE_TARGET_TIME) + if(STEALTH_SEARCHING) + var/end = calm_until || (state_since + search_time) + return list(end, end - state_since) + return null + +/// The public mark for a guard's state, or null for none. +/proc/stealth_meter_public_state(state, now, lost_since, state_since, calm_until, search_time = STEALTH_SEARCH_TIME) + switch(state) + if(STEALTH_ALERT) + if(!lost_since) + return "ex_r[STEALTH_METER_ROWS]" + var/list/span = stealth_meter_drain_span(state, lost_since, state_since, calm_until, search_time) + var/rows = stealth_meter_drain_rows(span[1] - now, span[2]) + // Drained: the full searching "?" it is about to become. + return rows ? "ex_r[rows]" : "q_y[STEALTH_METER_ROWS]" + if(STEALTH_SEARCHING) + var/list/span = stealth_meter_drain_span(state, lost_since, state_since, calm_until, search_time) + var/rows = stealth_meter_drain_rows(span[1] - now, span[2]) + return rows ? "q_y[rows]" : null + return null + +/// Deciseconds until a draining public mark loses its next row, or 0 when nothing drains. +/proc/stealth_meter_next_step(state, now, lost_since, state_since, calm_until, search_time = STEALTH_SEARCH_TIME) + var/list/span = stealth_meter_drain_span(state, lost_since, state_since, calm_until, search_time) + if(isnull(span) || span[2] <= 0) + return 0 + var/time_left = span[1] - now + var/rows = stealth_meter_drain_rows(time_left, span[2]) + if(rows <= 0) + return 0 + // The row goes when the time left reaches (rows - 1) sevenths; a tick later to land past it. + return max(world.tick_lag, time_left - (rows - 1) * span[2] / STEALTH_METER_ROWS + world.tick_lag) diff --git a/voidcrew/modules/stealth/stealth_noise.dm b/voidcrew/modules/stealth/stealth_noise.dm new file mode 100644 index 00000000000..af8ea362731 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_noise.dm @@ -0,0 +1,518 @@ +/** + * # Stealth guards: noise + * + * stealth_noise() is the only way a guard hears anything but footsteps (those its own scan listens for, + * stealth_hearing.dm). The sources are tg's own actions (stealth_noise_sources.dm). + * + * No sound ever gives a guard a target. Hearing turns a guard, moves it, makes it search and makes it wary; + * only sight and touch set BB_BASIC_MOB_CURRENT_TARGET. + * + * A noise reaches the stealth groups of its own level and map region. Walls and closed doors on the straight + * line to each guard eat reach (stealth_muffled_dist()). What the hearers do is decided for the group as a + * whole (dispatch_noise()): a door makes them glance; a small noise sends one guard to look, the next one at + * the same spot two, the third everyone; gunfire, blasts and screams send the nearest few running while + * sentries hold their posts. A guard that went to look and isn't back in STEALTH_CHECKIN_TIME is missed by + * the ones who watched it go. + * + * Cost: with no group alive, one length() check. With no living player on the level, or in airless space, + * the noise is dropped before any guard is looked at. The same kind of noise within STEALTH_NOISE_COALESCE + * and STEALTH_NOISE_COALESCE_RANGE of the last is dropped before any per-guard work. Listeners come from the + * group's roster, never from view() or hearers(). Nothing here runs on a timer: lures, alarms and checks + * are small lists of world.time stamps on the group, pruned when read. + */ + +/// A guard that went to look at a noise, and the ones who know it went. +/datum/stealth_check + /// Weakref to the guard that went + var/datum/weakref/who + /// What its friends call it, or null if it has no name of its own + var/name + /// Where the noise was + var/turf/where + /// world.time it is missed + var/due = 0 + /// Weakrefs to the guards that saw or heard it go + var/list/datum/weakref/waiters = list() + +/datum/stealth_group + /// Noise kind => list(world.time, turf) of the last one its guards heard + var/list/noise_stamps = list() + /// list(turf, world.time) for each small noise it sent someone to + var/list/lures = list() + /// list(world.time, weight) for each alarm it answered (a lure counts half) + var/list/alarms = list() + /// Guards out looking at a noise + var/list/datum/stealth_check/checks = list() + /// world.time the checks are next looked over + var/next_overdue_check = 0 + /// world.time the next radio alarm may go out + var/next_radio_alarm = 0 + /// Admin noise view only: guard => what it made of the noise being dealt with, else null + var/list/noise_notes + /// Reach of the noise being dealt with + var/noise_reach = 0 + +/// list(reach, level, flags) for a STEALTH_NOISE_* kind, or null. +/proc/stealth_noise_profile(kind) + var/static/list/profiles + if(isnull(profiles)) + profiles = list( + STEALTH_NOISE_GUN_QUIET = list(STEALTH_NOISE_RANGE_GUN_QUIET, STEALTH_HEAR_INVESTIGATE, STEALTH_NOISE_LOS_ONLY), + STEALTH_NOISE_GUN_PISTOL = list(STEALTH_NOISE_RANGE_GUN_PISTOL, STEALTH_HEAR_ALARM, STEALTH_NOISE_LOUD), + STEALTH_NOISE_GUN_SMG = list(STEALTH_NOISE_RANGE_GUN_SMG, STEALTH_HEAR_ALARM, STEALTH_NOISE_LOUD), + STEALTH_NOISE_GUN_LONG = list(STEALTH_NOISE_RANGE_GUN_LONG, STEALTH_HEAR_ALARM, STEALTH_NOISE_LOUD), + STEALTH_NOISE_IMPACT = list(STEALTH_NOISE_RANGE_IMPACT, STEALTH_HEAR_INVESTIGATE, NONE), + STEALTH_NOISE_BLAST = list(STEALTH_NOISE_RANGE_BLAST, STEALTH_HEAR_ALARM, STEALTH_NOISE_LOUD), + STEALTH_NOISE_GLASS = list(STEALTH_NOISE_RANGE_GLASS, STEALTH_HEAR_INVESTIGATE, NONE), + STEALTH_NOISE_THROWN = list(STEALTH_NOISE_RANGE_THROWN_SMALL, STEALTH_HEAR_INVESTIGATE, NONE), + STEALTH_NOISE_KNOCK = list(STEALTH_NOISE_RANGE_KNOCK, STEALTH_HEAR_INVESTIGATE, NONE), + STEALTH_NOISE_BASH = list(STEALTH_NOISE_RANGE_BASH, STEALTH_HEAR_INVESTIGATE, NONE), + STEALTH_NOISE_DOOR = list(STEALTH_NOISE_RANGE_DOOR, STEALTH_HEAR_GLANCE, NONE), + STEALTH_NOISE_THUD = list(STEALTH_NOISE_RANGE_THUD, STEALTH_HEAR_INVESTIGATE, STEALTH_NOISE_ALLIES_COUNT), + STEALTH_NOISE_VOICE = list(STEALTH_NOISE_RANGE_VOICE, STEALTH_HEAR_INVESTIGATE, NONE), + STEALTH_NOISE_SCREAM = list(STEALTH_NOISE_RANGE_SCREAM, STEALTH_HEAR_ALARM, STEALTH_NOISE_LOUD | STEALTH_NOISE_ALLIES_COUNT), + STEALTH_NOISE_SHOUT = list(STEALTH_NOISE_RANGE_SHOUT, STEALTH_HEAR_SHOUT, STEALTH_NOISE_LOUD | STEALTH_NOISE_GROUP_ONLY), + STEALTH_NOISE_CRUNCH = list(STEALTH_NOISE_RANGE_CRUNCH, STEALTH_HEAR_INVESTIGATE, NONE), + ) + return profiles[kind] + +/// Whether `kind` is a gunshot loud enough to be a call for help when one of their own fires it. +/proc/stealth_noise_is_gunfire(kind) + return kind == STEALTH_NOISE_GUN_PISTOL || kind == STEALTH_NOISE_GUN_SMG || kind == STEALTH_NOISE_GUN_LONG + +/** + * Something made a noise guards can hear. Does nothing unless a stealth group has awake members on that level. + * source: where it happened (any atom; its turf is used). kind: STEALTH_NOISE_*. reach: tiles in open air, or + * null for the kind's default. actor: the living mob that made it, if known. only: one group to tell, or null + * for every group in earshot. + * Returns the number of guards that heard it (tests and the admin view). + */ +/proc/stealth_noise(atom/source, kind, reach = null, mob/living/actor = null, datum/stealth_group/only = null) + if(!length(GLOB.stealth_groups)) + return 0 + var/turf/where = get_turf(source) + var/list/profile = stealth_noise_profile(kind) + if(isnull(where) || isnull(profile)) + return 0 + // Nobody to play for: guards sleep with their level. + if(where.z > length(SSmobs.clients_by_zlevel) || !length(SSmobs.clients_by_zlevel[where.z])) + return 0 + if(isnull(reach)) + reach = profile[STEALTH_PROFILE_REACH] + if(reach <= 0) + return 0 + // A door nobody is named for may be one of their own going through. + var/door = isnull(actor) && istype(source, /obj/machinery/door) + var/aired = FALSE + . = 0 + for(var/datum/stealth_group/group as anything in (only ? list(only) : GLOB.stealth_groups.Copy())) + if(QDELETED(group) || group.home?.z != where.z || !group.region_matches(where)) + continue + if(!aired) + aired = TRUE + if(!stealth_noise_carries(where, actor)) + return 0 + . += group.hear(where, kind, reach, profile[STEALTH_PROFILE_LEVEL], profile[STEALTH_PROFILE_FLAGS], actor, door) + +/// Whether there is air at `where` to carry a sound, as for players (playsound_local scales by pressure). A +/// noise on a wall or a window tile is judged where its maker stands. +/proc/stealth_noise_carries(turf/where, mob/living/actor) + var/turf/air_turf = where + if(isclosedturf(air_turf)) + air_turf = get_turf(actor) + if(isnull(air_turf) || isclosedturf(air_turf)) + return TRUE + var/datum/gas_mixture/air = air_turf.return_air() + return !isnull(air) && air.return_pressure() >= SOUND_MINIMUM_PRESSURE + +/** + * How far off a sound from `origin` seems at `ear`: the distance plus STEALTH_MUFFLE_WALL for each wall and + * STEALTH_MUFFLE_DOOR for each closed solid door (or anything else you can't see through) on the straight + * line between them. Glass costs nothing. Loud sounds lose half as much. INFINITY when unheard: more than + * STEALTH_MUFFLE_MAX_BLOCKERS in the way, or any at all for a STEALTH_NOISE_LOS_ONLY sound. The two end + * turfs are never counted, so a knock on a wall is heard on both sides of it. + */ +/proc/stealth_muffled_dist(turf/origin, turf/ear, flags = NONE) + if(isnull(origin) || isnull(ear) || origin.z != ear.z) + return INFINITY + var/dist = get_dist(origin, ear) + if(dist <= 1) + return dist + var/list/line = get_line(origin, ear) + var/blockers = 0 + var/penalty = 0 + for(var/index in 2 to length(line) - 1) + var/turf/between = line[index] + var/cost = 0 + if(isclosedturf(between)) + cost = STEALTH_MUFFLE_WALL + else if(between.directional_opacity == ALL_CARDINALS) + cost = STEALTH_MUFFLE_DOOR + if(!cost) + continue + if(flags & STEALTH_NOISE_LOS_ONLY) + return INFINITY + blockers++ + if(blockers > STEALTH_MUFFLE_MAX_BLOCKERS) + return INFINITY + penalty += cost + if(flags & STEALTH_NOISE_LOUD) + penalty *= STEALTH_MUFFLE_LOUD_MULT + return dist + penalty + +/// Where a guard standing on `listener` goes to look at a noise at `where`: the spot, or, when the spot is a +/// wall or a window tile, the open tile beside it nearest the guard (its own side of the wall). +/proc/stealth_hear_spot(turf/where, turf/listener) + if(isnull(where)) + return null + if(isopenturf(where) && !where.is_blocked_turf(exclude_mobs = TRUE)) + return where + var/turf/best + var/best_dist = INFINITY + for(var/turf/open/near in RANGE_TURFS(1, where)) + if(near == where || near.is_blocked_turf(exclude_mobs = TRUE)) + continue + // Straight-line distance: of two tiles as many steps away, the one more directly on its side. + var/dist = listener ? get_dist_euclidean(near, listener) : 0 + if(dist < best_dist) + best = near + best_dist = dist + return best || where + +// ===== The group's side ===== + +/// Its guards hear a noise at `where`, those that can. Returns how many did. +/datum/stealth_group/proc/hear(turf/where, kind, reach, level, flags, mob/living/actor, door = FALSE) + var/list/views = length(GLOB.stealth_sight_overlays) ? stealth_noise_views(where.z) : null + // The same noise again (full auto, a burst, pellets): one event, not ten. + var/list/stamp = noise_stamps[kind] + if(stamp && world.time - stamp[1] < STEALTH_NOISE_COALESCE && get_dist(stamp[2], where) <= STEALTH_NOISE_COALESCE_RANGE) + for(var/datum/stealth_noise_view/view as anything in views) + view.show(where, kind, reach, null, TRUE) + return 0 + var/list/guards = living_members() + if(!length(guards)) + return 0 + if((flags & STEALTH_NOISE_GROUP_ONLY) && !(actor in guards)) + return 0 + if(door && member_beside(where, guards)) + return 0 + var/mob/living/any_guard = guards[1] + var/ally = !isnull(actor) && any_guard.faction_check_atom(actor) + var/gunfire = stealth_noise_is_gunfire(kind) + // One of their own making an everyday noise. + if(ally && !gunfire && !(flags & (STEALTH_NOISE_ALLIES_COUNT | STEALTH_NOISE_GROUP_ONLY))) + return 0 + // An ally's gunfire means an ally is in a fight: it is a call for help from where they stand. + if(ally && gunfire) + level = STEALTH_HEAR_SHOUT + noise_notes = views ? list() : null + noise_reach = reach + // list(guard, muffled distance), nearest first + var/list/hearers = list() + for(var/mob/living/carbon/human/npc/guard as anything in guards) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + if(guard == actor || !istype(guard_ai)) + continue + var/turf/guard_turf = get_turf(guard) + if(guard_turf?.z != where.z) + continue + // Its ear (decision 38): quiet noises carry further to a sharp guard, less far to a sloppy one. + var/guard_reach = reach + if(!gunfire && !(flags & STEALTH_NOISE_LOUD) && kind != STEALTH_NOISE_GUN_QUIET) + guard_reach = round(reach * guard_ai.stealth_skill().hearing_mult, 1) + var/dist = get_dist(guard_turf, where) + if(dist > guard_reach) + continue + if(guard_ai.ai_status == AI_STATUS_OFF || guard.client || guard.stat != CONSCIOUS || guard_ai.stealth_captive() || guard_ai.blackboard_key_exists(BB_HUMAN_NPC_EXIT)) + note(guard, "busy") + continue + if(!guard.can_hear()) + note(guard, "deaf") + continue + // Fighting: only an alarm made by someone else tells it anything, and that before the line walk. + if(guard_ai.stealth_state() == STEALTH_ALERT && (level != STEALTH_HEAR_ALARM || !isliving(actor))) + note(guard, "busy") + continue + var/muffled = stealth_muffled_dist(where, guard_turf, flags) + if(muffled > guard_reach) + note(guard, muffled == INFINITY ? "muffled" : "muffled [muffled]/[guard_reach]") + continue + var/index = 1 + while(index <= length(hearers) && hearers[index][2] <= muffled) + index++ + hearers.Insert(index, null) + hearers[index] = list(guard, muffled) + guard_ai.last_heard = list(kind, world.time) + note(guard, "heard [muffled]/[guard_reach]") + if(length(hearers)) + noise_stamps[kind] = list(world.time, where) + // Far off, they misjudge the spot: all of them by the same error, so they end up in one place. + var/turf/spot = where + var/list/nearest = hearers[1] + var/fuzz = min(STEALTH_NOISE_FUZZ_MAX, round((nearest[2] - STEALTH_NOISE_EXACT_RANGE) / STEALTH_NOISE_FUZZ_STEP, 1)) + if(fuzz > 0 && level != STEALTH_HEAR_SHOUT) + var/turf/guess = locate(clamp(where.x + rand(-fuzz, fuzz), 1, world.maxx), clamp(where.y + rand(-fuzz, fuzz), 1, world.maxy), where.z) + guess = stealth_open_near(guess, 2) + if(guess && region_matches(guess)) + spot = guess + dispatch_noise(hearers, where, kind, level, actor, spot) + for(var/datum/stealth_noise_view/view as anything in views) + view.show(where, kind, reach, noise_notes, FALSE) + noise_notes = null + return length(hearers) + +/// Admin noise view: what `guard` made of the noise being dealt with. +/datum/stealth_group/proc/note(mob/living/guard, text, append = FALSE) + if(isnull(noise_notes)) + return + noise_notes[guard] = append ? "[noise_notes[guard]] -> [text]" : text + +/// Whether a conscious guard of the group stands within a tile of `where`. +/datum/stealth_group/proc/member_beside(turf/where, list/guards) + for(var/mob/living/guard as anything in guards) + if(guard.stat == CONSCIOUS && guard.z == where.z && get_dist(guard, where) <= 1) + return TRUE + return FALSE + +/// How many small noises it sent someone to within STEALTH_LURE_RADIUS of `where` and STEALTH_LURE_MEMORY. +/datum/stealth_group/proc/lure_count(turf/where) + . = 0 + for(var/list/lure as anything in lures) + if(world.time - lure[2] > STEALTH_LURE_MEMORY) + lures -= list(lure) + continue + if(get_dist(lure[1], where) <= STEALTH_LURE_RADIUS) + .++ + +/// How many alarms it answered within STEALTH_ALARM_MEMORY (a lure counts half). +/datum/stealth_group/proc/alarm_count() + . = 0 + for(var/list/alarm as anything in alarms) + if(world.time - alarm[1] > STEALTH_ALARM_MEMORY) + alarms -= list(alarm) + continue + . += alarm[2] + +/// Forgets every noise (admin tools). +/datum/stealth_group/proc/forget_noises() + noise_stamps = list() + lures = list() + alarms = list() + checks = list() + next_radio_alarm = 0 + door_guard_used = list() + door_cues = list() + +/// Moves every noise stamp back by `time`, as if that long had passed (unit tests, admin tools). +/datum/stealth_group/proc/rewind(time) + for(var/kind in noise_stamps) + var/list/stamp = noise_stamps[kind] + stamp[1] -= time + for(var/list/lure as anything in lures) + lure[2] -= time + for(var/list/alarm as anything in alarms) + alarm[1] -= time + for(var/datum/stealth_check/check as anything in checks) + check.due -= time + next_overdue_check -= time + next_radio_alarm -= time + for(var/key in door_guard_used) + door_guard_used[key] -= time + for(var/key in door_cues) + var/list/stamps = door_cues[key] + for(var/index in 1 to length(stamps)) + stamps[index] -= time + +/** + * What the guards that heard a noise do, decided for the group. `hearers` is list(guard, muffled distance), + * nearest first. `where` is where it really was (lures are counted there); `spot` is where they think it was. + */ +/datum/stealth_group/proc/dispatch_noise(list/hearers, turf/where, kind, level, mob/living/actor, turf/spot) + spot ||= where + switch(level) + if(STEALTH_HEAR_GLANCE) + for(var/list/hearer as anything in hearers) + var/mob/living/guard = hearer[1] + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + if(guard_ai.stealth_state() == STEALTH_UNAWARE) + guard_ai.stealth_glance(spot) + note(guard, "glance", TRUE) + if(STEALTH_HEAR_INVESTIGATE) + dispatch_investigate(hearers, where, spot) + if(STEALTH_HEAR_ALARM) + dispatch_alarm(hearers, where, spot, kind, actor) + if(STEALTH_HEAR_SHOUT) + dispatch_shout(hearers, spot, actor) + +/// A small noise: one guard goes to look, the rest glance. The second time at one spot two go; from the third +/// everyone who hears it searches there, and they call it in. +/datum/stealth_group/proc/dispatch_investigate(list/hearers, turf/where, turf/spot) + var/earlier = lure_count(where) + lures += list(list(where, world.time)) + alarms += list(list(world.time, 0.5)) + if(earlier >= 2) + var/shouted = FALSE + for(var/list/hearer as anything in hearers) + var/mob/living/carbon/human/npc/guard = hearer[1] + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + // A sentry still doesn't leave its door for something far off. + if(isnull(guard_ai.route_id) && get_dist(guard, spot) > STEALTH_SENTRY_INVESTIGATE_RANGE) + guard_ai.stealth_hold(spot) + note(guard, "holds", TRUE) + else if(guard_ai.stealth_respond(spot)) + note(guard, "searches", TRUE) + if(!shouted) + shouted = TRUE + guard_ai.stealth_bark(STEALTH_BARK_HELP) + guard_ai.stealth_shout() + if(guard.stealth_radio) + guard_ai.stealth_start_call(STEALTH_CALL_ALARM, spot) + return + var/wanted = earlier + 1 + var/list/went = list() + var/list/stayed = list() + for(var/list/hearer as anything in hearers) + var/mob/living/carbon/human/npc/guard = hearer[1] + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + // A sentry goes too, but only a few steps toward it (stealth_go_heard()). + if(length(went) < wanted && guard_ai.stealth_can_investigate()) + guard_ai.stealth_go_heard(spot, earlier >= 1 && !length(went)) + went += guard + note(guard, "goes", TRUE) + if(guard.stealth_radio) + guard_ai.stealth_start_call(STEALTH_CALL_REPORT, spot) + continue + stayed += WEAKREF(guard) + switch(guard_ai.stealth_state()) + if(STEALTH_UNAWARE) + guard_ai.stealth_glance(spot) + note(guard, "glance", TRUE) + if(STEALTH_SEARCHING) + if(guard_ai.stealth_respond(spot)) + note(guard, "searches", TRUE) + for(var/mob/living/carbon/human/npc/guard as anything in went) + var/datum/stealth_check/check = new + check.who = WEAKREF(guard) + check.name = stealth_first_name(guard) + check.where = where + check.due = world.time + STEALTH_CHECKIN_TIME + check.waiters = stayed.Copy() + checks += check + +/// Gunfire, a blast, a scream: the nearest few that aren't sentries run to it and search; every other hearer +/// holds where it is, wary. After two alarms in memory fewer go: it may be a draw. +/datum/stealth_group/proc/dispatch_alarm(list/hearers, turf/where, turf/spot, kind, mob/living/actor) + var/cap = alarm_count() >= 2 ? STEALTH_ALARM_RESPONDERS_LATER : STEALTH_ALARM_RESPONDERS + alarms += list(list(world.time, 1)) + var/responders = 0 + for(var/list/hearer as anything in hearers) + var/mob/living/carbon/human/npc/guard = hearer[1] + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + if(guard_ai.stealth_state() == STEALTH_ALERT) + // Fighting someone else: it now knows there is another one about (never a target from sound). + var/atom/target = guard_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET] + if(isliving(actor) && actor != target && bounty_ai_target_for(actor) != target && !guard.faction_check_atom(actor)) + guard_ai.stealth_remember(actor) + note(guard, "notes", TRUE) + continue + if(!isnull(guard_ai.route_id) && responders < cap) + if(guard_ai.stealth_respond(spot)) + if(!responders) + guard_ai.stealth_bark(stealth_noise_is_gunfire(kind) ? STEALTH_BARK_GUNFIRE : STEALTH_BARK_HEARD, spot) + note(guard, "goes", TRUE) + responders++ + else + guard_ai.stealth_hold(spot) + note(guard, "holds", TRUE) + if(guard.stealth_radio) + guard_ai.stealth_start_call(STEALTH_CALL_ALARM, spot) + +/// A friend calling for help from `spot`: whoever hears it and isn't a sentry runs to them. They heard a +/// friend, they saw nobody, so they search where the friend stood. Who it was goes with the shout (decision 44). +/datum/stealth_group/proc/dispatch_shout(list/hearers, turf/spot, mob/living/shouter) + var/datum/ai_controller/basic_controller/human_npc/stealth/shouter_ai = shouter?.ai_controller + for(var/list/hearer as anything in hearers) + var/mob/living/carbon/human/npc/guard = hearer[1] + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + if(istype(shouter_ai)) + shouter_ai.stealth_tell(guard_ai) + if(guard_ai.stealth_state() == STEALTH_ALERT) + continue + if(isnull(guard_ai.route_id)) + guard_ai.stealth_hold(spot) + note(guard, "holds", TRUE) + else if(guard_ai.stealth_respond(spot)) + note(guard, "goes", TRUE) + if(guard.stealth_radio) + guard_ai.stealth_start_call(STEALTH_CALL_ALARM, spot) + +/** + * The guard who never came back (abuse P6). Run from each member's scan, at most once per + * STEALTH_SCAN_INTERVAL. A guard that went to look and is back on its round, or found someone, closes its + * check. One that is past due and gone, down, cuffed or still out is missed: the nearest two who know it + * went search where it went, and the next noise there brings everyone. + */ +/datum/stealth_group/proc/check_overdue() + if(world.time < next_overdue_check || !length(checks)) + return + next_overdue_check = world.time + STEALTH_SCAN_INTERVAL + for(var/datum/stealth_check/check as anything in checks.Copy()) + var/mob/living/carbon/human/npc/gone = check.who?.resolve() + var/datum/ai_controller/basic_controller/human_npc/stealth/gone_ai = gone?.ai_controller + var/down = QDELETED(gone) || !istype(gone_ai) || gone.stat != CONSCIOUS || HAS_TRAIT(gone, TRAIT_RESTRAINED) + // Already found and called out as a body: nobody asks where it got to (decision 32). + if(down && !QDELETED(gone) && (REF(gone) in reported_bodies)) + checks -= check + continue + if(!down) + var/state = gone_ai.stealth_state() + if(state == STEALTH_UNAWARE || state == STEALTH_ALERT) + checks -= check + continue + if(world.time < check.due) + continue + checks -= check + // Who misses it: conscious, free, not fighting. Nearest to the spot first. + var/list/missers = list() + for(var/datum/weakref/waiter_ref as anything in check.waiters) + var/mob/living/carbon/human/npc/waiter = waiter_ref.resolve() + var/datum/ai_controller/basic_controller/human_npc/stealth/waiter_ai = waiter?.ai_controller + if(QDELETED(waiter) || waiter == gone || !istype(waiter_ai) || waiter.stat != CONSCIOUS || waiter.client) + continue + if(waiter_ai.ai_status == AI_STATUS_OFF || waiter_ai.stealth_captive() || waiter_ai.stealth_state() == STEALTH_ALERT) + continue + var/dist = get_dist(waiter, check.where) + var/index = 1 + while(index <= length(missers) && get_dist(missers[index], check.where) <= dist) + index++ + missers.Insert(index, waiter) + if(!length(missers)) + continue + // The next noise there brings everyone. + lures += list(list(check.where, world.time), list(check.where, world.time)) + var/sent = 0 + for(var/mob/living/carbon/human/npc/waiter as anything in missers) + var/datum/ai_controller/basic_controller/human_npc/stealth/waiter_ai = waiter.ai_controller + if(sent < 2 && (!isnull(waiter_ai.route_id) || get_dist(waiter, check.where) <= STEALTH_SENTRY_INVESTIGATE_RANGE)) + if(waiter_ai.stealth_respond(check.where)) + sent++ + waiter_ai.stealth_bark(STEALTH_BARK_MISSING, check.where, check.name) + if(waiter.stealth_radio) + waiter_ai.stealth_start_call(STEALTH_CALL_MISSING, check.where, check.name) + +/// A blast anywhere: its own guards hear it if it is near enough. Registered per group, not per guard. +/datum/stealth_group/proc/on_explosion(datum/source, turf/epicenter) + SIGNAL_HANDLER + if(isnull(epicenter) || epicenter.z != home?.z) + return + INVOKE_ASYNC(GLOBAL_PROC, GLOBAL_PROC_REF(stealth_noise), epicenter, STEALTH_NOISE_BLAST, null, null, src) + +/// What its friends call `guard`: the first word of its name, or null when it has only its type's name +/// ("Scav Guard"). An NPC's name, never player text. +/proc/stealth_first_name(mob/living/carbon/human/npc/guard) + var/full = guard.real_name + if(!istext(full) || !length(full) || full == guard.npc_name || full == initial(guard.name)) + return null + var/space = findtext(full, " ") + return space ? copytext(full, 1, space) : full diff --git a/voidcrew/modules/stealth/stealth_noise_sources.dm b/voidcrew/modules/stealth/stealth_noise_sources.dm new file mode 100644 index 00000000000..23ac4490279 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_noise_sources.dm @@ -0,0 +1,285 @@ +/** + * # Stealth guards: where noise comes from + * + * Every hook that turns one of tg's own sounds into a stealth_noise() guards can hear. Each is a chained + * override: the same proc defined again on the same type in this later-compiled file, calling ..() (the + * model is cyberware_stealth.dm). No upstream file is edited. Each hook costs one call that returns at once + * while no stealth group is alive, and does no work per object in the room. + * + * Every reach is at or under how far a player hears the same tg sound (abuse H2): a guard never hears what + * a player standing in its place could not. + * + * Not hooked: mech and ship weapons (a mech is seen all round anyway), speech, machines. + */ + +// ===== Guns (owner decisions 2 and 7) ===== + +/obj/item/gun + /// How loud it is to stealth guards when it isn't suppressed (STEALTH_NOISE_GUN_*). A gun that sets + /// nothing is as loud as a pistol. + var/stealth_loudness = STEALTH_NOISE_GUN_PISTOL + +// Quiet by nature +/obj/item/gun/ballistic/bow + stealth_loudness = STEALTH_NOISE_GUN_QUIET + +/obj/item/gun/ballistic/rifle/rebarxbow + stealth_loudness = STEALTH_NOISE_GUN_QUIET + +/obj/item/gun/syringe + stealth_loudness = STEALTH_NOISE_GUN_QUIET + +/obj/item/gun/chem + stealth_loudness = STEALTH_NOISE_GUN_QUIET + +// SMGs: the automatic root, with its pistols set back +/obj/item/gun/ballistic/automatic + stealth_loudness = STEALTH_NOISE_GUN_SMG + +/obj/item/gun/ballistic/automatic/pistol + stealth_loudness = STEALTH_NOISE_GUN_PISTOL + +/obj/item/gun/ballistic/automatic/gyropistol + stealth_loudness = STEALTH_NOISE_GUN_PISTOL + +/obj/item/gun/ballistic/automatic/toy + stealth_loudness = STEALTH_NOISE_GUN_QUIET + +// Long guns, launchers and heavy energy +/obj/item/gun/ballistic/rifle + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/ballistic/shotgun + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/ballistic/shotgun/toy + stealth_loudness = STEALTH_NOISE_GUN_QUIET + +/obj/item/gun/ballistic/automatic/ar + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/ballistic/automatic/battle_rifle + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/ballistic/automatic/m90 + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/ballistic/automatic/l6_saw + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/ballistic/automatic/smartgun + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/ballistic/rocketlauncher + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/ballistic/revolver/grenadelauncher + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/grenadelauncher + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/blastcannon + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/energy/lasercannon + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/energy/pulse + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/energy/ionrifle + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/energy/tesla_cannon + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/obj/item/gun/energy/minigun + stealth_loudness = STEALTH_NOISE_GUN_LONG + +/** + * list(noise kind, reach) for a shot from this gun now. Any suppressed gun is in the quietest tier, whatever + * it is (owner decision 7): a fitted suppressor, an integral one, the syringe gun. The reach is never more + * than how far tg plays the gun's own sound to players, so a quiet custom gun doesn't carry further for + * guards than for people. + */ +/obj/item/gun/proc/stealth_shot_noise() + var/kind = suppressed ? STEALTH_NOISE_GUN_QUIET : stealth_loudness + var/list/profile = stealth_noise_profile(kind) + var/volume = suppressed ? suppressed_volume : fire_sound_volume + if(isnull(profile) || volume <= SOUND_AUDIBLE_VOLUME_MIN) + return list(kind, 0) + // As fire_sounds() plays it. Plain numbers: the macro doesn't bracket its arguments. + var/sound_range = SOUND_RANGE + var/falloff = SOUND_DEFAULT_FALLOFF_DISTANCE + if(suppressed) + sound_range += SILENCED_SOUND_EXTRARANGE + falloff = 0 + var/audible = CALCULATE_MAX_SOUND_AUDIBLE_DISTANCE(volume, sound_range, falloff, SOUND_FALLOFF_EXPONENT) + return list(kind, min(profile[STEALTH_PROFILE_REACH], audible)) + +// Once per shot, bursts included, with the shooter. fire_sounds() is the wrong place: five types override it +// without calling the parent. +/obj/item/gun/shoot_live_shot(mob/living/user, pointblank = FALSE, atom/pbtarget = null, message = TRUE) + . = ..() + if(!length(GLOB.stealth_groups)) + return + var/list/noise = stealth_shot_noise() + stealth_noise(src, noise[1], noise[2], isliving(user) ? user : null) + +// A round striking a wall, a window, a crate. A suppressed round's strike is nearly silent in tg (volume 5), +// so it is no lure; what it breaks is. +/obj/projectile/on_hit(atom/target, blocked = 0, pierce_hit) + . = ..() + if(!length(GLOB.stealth_groups) || isliving(target) || isnull(target)) + return + stealth_noise(target, STEALTH_NOISE_IMPACT, suppressed ? STEALTH_NOISE_RANGE_IMPACT_QUIET : STEALTH_NOISE_RANGE_IMPACT, isliving(firer) ? firer : null) + +// ===== Thrown things ===== + +/obj/item + /// The noise it makes when a throw ends (STEALTH_NOISE_*), or null for a plain landing by its weight + var/stealth_throw_noise + +/// The noise this makes landing from a throw. +/obj/item/proc/stealth_throw_kind() + return stealth_throw_noise || STEALTH_NOISE_THROWN + +// A glass or a bottle smashes; a carton or a plastic bottle only lands. +/obj/item/reagent_containers/cup/glass/stealth_throw_kind() + return isGlass ? STEALTH_NOISE_GLASS : ..() + +// Landing, or hitting something that isn't a person. A throw that lands on a guard is a touch, which the +// guard's own controller deals with. +/obj/item/throw_impact(atom/hit_atom, datum/thrownthing/throwingdatum) + // Read first: a bottle is gone once it has smashed. + var/noisy = length(GLOB.stealth_groups) && !isliving(hit_atom) + var/kind = noisy ? stealth_throw_kind() : null + var/size = w_class + . = ..() + if(!noisy) + return + var/reach + if(kind == STEALTH_NOISE_THROWN) + if(size <= WEIGHT_CLASS_SMALL) + reach = STEALTH_NOISE_RANGE_THROWN_SMALL + else if(size == WEIGHT_CLASS_NORMAL) + reach = STEALTH_NOISE_RANGE_THROWN_MEDIUM + else + reach = STEALTH_NOISE_RANGE_THROWN_HEAVY + var/mob/living/thrower = throwingdatum?.get_thrower() + stealth_noise(hit_atom, kind, reach, isliving(thrower) ? thrower : null) + +// ===== Glass ===== + +/obj/structure/window/atom_deconstruct(disassembled = TRUE) + if(!disassembled) + stealth_noise(src, STEALTH_NOISE_GLASS) + return ..() + +// Shot out or smashed: only a tube that was whole makes the sound (tg's own rule). +/obj/machinery/light/break_light_tube(skip_sound_and_sparks = FALSE) + var/whole = !skip_sound_and_sparks && (status == LIGHT_OK || status == LIGHT_BURNED) + . = ..() + if(whole) + stealth_noise(src, STEALTH_NOISE_GLASS) + +// Stepping on broken glass (decision 37): tg's own crunch, which plays at a walk too and through shoes. Shards of +// every kind and dropped bulbs and tubes are the things tg plays it for. Broken bottles hurt but make no sound in +// tg, so they make none here; prescription glasses crunch only under a running step, which is heard anyway. +/obj/item/shard/on_entered(datum/source, atom/movable/AM) + . = ..() + stealth_glass_step(src, AM) + +/obj/item/light/on_entered(datum/source, atom/movable/moving_atom) + . = ..() + stealth_glass_step(src, moving_atom) + +/// `stepper` walked onto `glass`: the crunch tg played, under tg's own rule for when it plays. +/proc/stealth_glass_step(atom/glass, atom/movable/stepper) + if(!length(GLOB.stealth_groups) || !isliving(stepper) || QDELETED(glass)) + return + var/mob/living/walker = stepper + if((walker.movement_type & MOVETYPES_NOT_TOUCHING_GROUND) && !walker.buckled) + return + // A mouse or a roach on the glass is no lure: only something that weighs something carries. + if(walker.mob_size <= MOB_SIZE_TINY) + return + var/reach = HAS_TRAIT(walker, TRAIT_LIGHT_STEP) ? STEALTH_NOISE_RANGE_CRUNCH_LIGHT : STEALTH_NOISE_RANGE_CRUNCH + INVOKE_ASYNC(GLOBAL_PROC, GLOBAL_PROC_REF(stealth_noise), get_turf(glass), STEALTH_NOISE_CRUNCH, reach, walker) + +// ===== Knocks ===== + +// Knuckles on a window with combat mode off, a fist with it on. Repeats the parent's two guards. +/obj/structure/window/attack_hand(mob/living/user, list/modifiers) + . = ..() + if(. || !length(GLOB.stealth_groups) || !can_be_reached(user)) + return + stealth_noise(src, user.combat_mode ? STEALTH_NOISE_BASH : STEALTH_NOISE_KNOCK, null, user) + +// "You push the wall but nothing happens!" +/turf/closed/wall/attack_hand(mob/user, list/modifiers) + . = ..() + if(. || !length(GLOB.stealth_groups)) + return + stealth_noise(src, STEALTH_NOISE_KNOCK, null, isliving(user) ? user : null) + +// An airlock refusing someone, or being forced. Nobody is named: a door with one of the group beside it is one +// of their own going through (stealth_noise()). An airlock opening or closing is every door's hook (stealth_doors.dm). +/obj/machinery/door/airlock/animation_effects(animation, force_type = DEFAULT_DOOR_CHECKS) + . = ..() + if(!length(GLOB.stealth_groups)) + return + if(force_type == BYPASS_DOOR_CHECKS) + stealth_noise(src, STEALTH_NOISE_BASH) + return + if(animation == DOOR_DENY_ANIMATION) + stealth_noise(src, STEALTH_NOISE_KNOCK) + +// Tools at work: a wrench or a crowbar is a knock, a welder or a drill is louder. Breaking in is a choice +// between slow and quiet, and fast and loud. Guards don't use tools. +/obj/item/play_tool_sound(atom/target, volume = 50) + . = ..() + if(!length(GLOB.stealth_groups) || !target || !usesound || !volume) + return + var/loud = tool_behaviour == TOOL_WELDER || tool_behaviour == TOOL_DRILL || tool_behaviour == TOOL_MINING + stealth_noise(target, loud ? STEALTH_NOISE_BASH : STEALTH_NOISE_KNOCK, null, isliving(loc) ? loc : null) + +// ===== Bodies and voices ===== + +// A body hitting the floor. Someone held in an aggressive grab or tighter is let down by whoever holds them: +// no thud. That is a rule about noise only; what happened to the body is whatever tg did to it. +/turf/handle_fall(mob/faller) + . = ..() + if(!length(GLOB.stealth_groups) || !isliving(faller) || !has_gravity(src)) + return + if(faller.pulledby && faller.pulledby.grab_state >= GRAB_AGGRESSIVE) + return + stealth_noise(src, STEALTH_NOISE_THUD, null, faller) + +// A whistle, a clap, a snap, a cough, a laugh, a scream: any emote whose sound tg plays now, under tg's own +// rules for when it plays (its cooldowns included). +/datum/emote/run_emote(mob/user, params, type_override, intentional = FALSE) + var/sounded = FALSE + if(length(GLOB.stealth_groups) && isliving(user)) + sounded = get_sound(user) && should_play_sound(user, intentional) && TIMER_COOLDOWN_FINISHED(user, "general_emote_audio_cooldown") && TIMER_COOLDOWN_FINISHED(user, type) + . = ..() + if(!sounded || QDELETED(user)) + return + var/kind = STEALTH_NOISE_VOICE + switch(key) + if("scream", "screech") + kind = STEALTH_NOISE_SCREAM + if("deathgasp") + kind = STEALTH_NOISE_THUD + stealth_noise(user, kind, null, user) + +// ===== Blasts ===== +// Explosions: each group listens for COMSIG_GLOB_EXPLOSION (stealth_noise.dm). + +// The parent deletes the grenade, and deafens whoever it catches before anyone hears it. +/obj/item/grenade/flashbang/detonate(mob/living/lanced_by) + var/turf/where = get_turf(src) + . = ..() + if(. && where) + stealth_noise(where, STEALTH_NOISE_BLAST) diff --git a/voidcrew/modules/stealth/stealth_patrol.dm b/voidcrew/modules/stealth/stealth_patrol.dm new file mode 100644 index 00000000000..b11d1252656 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_patrol.dm @@ -0,0 +1,451 @@ +/** + * # Stealth patrols + * + * A template maps one group marker (/obj/effect/landmark/stealth_group) and any number of patrol points + * (/obj/effect/landmark/stealth_patrol). Points and guards belong to the nearest marker in their own map + * region within STEALTH_GROUP_RADIUS, so two dens on one packed planet never share routes (abuse R1). + * Nothing is matched by z-level alone, and no group processes on a timer. + * + * A guard claims the route with a stop within STEALTH_ROUTE_CLAIM_RANGE of where it spawned, starting at + * that stop. With none in range it is a sentry at its spawn turf, facing the way the spawner faced. + * + * A guard drawn off its route or post (a chase, a search) walks back, however far. One that can't get back + * waits and tries again. Only being carried to another level or map region makes it a sentry where it is. + */ + +/// Every live patrol group +GLOBAL_LIST_EMPTY(stealth_groups) +/// Patrol points not yet handed to a group +GLOBAL_LIST_EMPTY(stealth_unassigned_points) + +/datum/stealth_stop + var/turf/spot + var/wait = STEALTH_PATROL_DEFAULT_WAIT + /// The way the guard turns to here, or 0 to keep facing the way it walked in + var/dir = 0 + var/chatter = FALSE + var/order = 0 + +/datum/stealth_group + /// A unique id, for admins + var/id + /// Weakref to its map region (a footprint or reservation), or null on an unpacked level + var/datum/weakref/region_ref + /// Whether its region was null when made (so a null region is a match, not a lost one) + var/no_region = FALSE + /// Where its marker stood + var/turf/home + /// Its marker, while it exists + var/obj/effect/landmark/stealth_group/marker + /// Route id => list of /datum/stealth_stop in order + var/list/routes = list() + /// Route id => "loop" or "pingpong" + var/list/route_modes = list() + /// Weakrefs to its guards + var/list/datum/weakref/members = list() + /// REFs of fallen members someone has already reported + var/list/reported_bodies = list() + /// world.time chatter is next allowed + var/next_chatter = 0 + +GLOBAL_VAR_INIT(stealth_group_count, 0) + +/datum/stealth_group/New(turf/where) + id = "group-[++GLOB.stealth_group_count]" + home = where + var/datum/region = map_region_for_turf(where) + if(region) + region_ref = WEAKREF(region) + else + no_region = TRUE + GLOB.stealth_groups += src + RegisterSignal(SSdcs, COMSIG_GLOB_EXPLOSION, PROC_REF(on_explosion)) + +/datum/stealth_group/Destroy() + GLOB.stealth_groups -= src + UnregisterSignal(SSdcs, COMSIG_GLOB_EXPLOSION) + noise_stamps = null + lures = null + alarms = null + checks = null + noise_notes = null + if(marker) + marker.group = null + marker = null + members = null + routes = null + home = null + restricted = null + return ..() + +/// Whether `tile` is in this group's map region. +/datum/stealth_group/proc/region_matches(turf/tile) + var/datum/region = map_region_for_turf(tile) + if(no_region) + return isnull(region) + return !isnull(region) && region == region_ref?.resolve() + +/datum/stealth_group/proc/add_member(mob/living/guard) + members |= WEAKREF(guard) + +/datum/stealth_group/proc/remove_member(mob/living/guard) + if(isnull(members)) + return + members -= WEAKREF(guard) + prune() + +/// Its guards that still exist. +/datum/stealth_group/proc/living_members() + . = list() + for(var/datum/weakref/ref as anything in members?.Copy()) + var/mob/living/guard = ref?.resolve() + if(QDELETED(guard)) + members -= ref + continue + . += guard + +/// Removes the group once its marker and every member are gone. +/datum/stealth_group/proc/prune() + if(QDELETED(src)) + return + if(marker || length(living_members())) + return + qdel(src) + +/datum/stealth_group/proc/add_point(obj/effect/landmark/stealth_patrol/point) + var/datum/stealth_stop/stop = new + stop.spot = get_turf(point) + stop.wait = point.wait < 0 ? STEALTH_PATROL_DEFAULT_WAIT : point.wait + stop.dir = point.facing + stop.chatter = point.chatter + stop.order = point.order + var/list/route = routes[point.route] + if(isnull(route)) + routes[point.route] = route = list() + var/index = 1 + while(index <= length(route)) + var/datum/stealth_stop/other = route[index] + if(other.order > stop.order) + break + index++ + route.Insert(index, stop) + if(point.order == 1 || isnull(route_modes[point.route])) + route_modes[point.route] = point.route_mode + +/// The nearest group to `tile` in its own region within STEALTH_GROUP_RADIUS, or null. +/proc/stealth_group_for(turf/tile) + if(isnull(tile)) + return null + stealth_assign_points() + var/datum/stealth_group/best + var/best_dist = INFINITY + for(var/datum/stealth_group/group as anything in GLOB.stealth_groups) + if(group.home?.z != tile.z) + continue + var/dist = get_dist(group.home, tile) + if(dist > STEALTH_GROUP_RADIUS || dist >= best_dist || !group.region_matches(tile)) + continue + best = group + best_dist = dist + return best + +/// Hands every loaded patrol point to its group. Points with no group yet wait for one. +/proc/stealth_assign_points() + for(var/obj/effect/landmark/stealth_patrol/point as anything in GLOB.stealth_unassigned_points) + if(QDELETED(point)) + GLOB.stealth_unassigned_points -= point + continue + var/turf/spot = get_turf(point) + var/datum/stealth_group/best + var/best_dist = INFINITY + for(var/datum/stealth_group/group as anything in GLOB.stealth_groups) + if(group.home?.z != spot?.z || !group.marker) + continue + var/dist = get_dist(group.home, spot) + if(dist > STEALTH_GROUP_RADIUS || dist >= best_dist || !group.region_matches(spot)) + continue + best = group + best_dist = dist + if(best) + best.add_point(point) + GLOB.stealth_unassigned_points -= point + +// ===== Landmarks ===== + +/// One per template: the patrol group its points and guards join. +/obj/effect/landmark/stealth_group + name = "stealth patrol group" + icon_state = "x" + var/datum/stealth_group/group + +/obj/effect/landmark/stealth_group/Initialize(mapload) + . = ..() + group = new(get_turf(src)) + group.marker = src + +/obj/effect/landmark/stealth_group/Destroy() + var/datum/stealth_group/old = group + group = null + if(old) + old.marker = null + old.prune() + return ..() + +/// A stop on a guard route. A guard arrives facing the way it walked, unless `facing` is set. +/obj/effect/landmark/stealth_patrol + name = "stealth patrol point" + icon_state = "x3" + /// The way the guard turns to at this stop (NORTH, SOUTH, EAST or WEST), or 0 to keep facing the way it walked in + /// (decision 39: turning back on the way it came faced anyone following it) + var/facing = 0 + /// The route it belongs to ("a", "b", ...) + var/route = "a" + /// Its place on the route, from 1 + var/order = 1 + /// Deciseconds to stand here; -1 for STEALTH_PATROL_DEFAULT_WAIT, 0 to walk straight through + var/wait = -1 + /// TRUE: guards here talk to each other + var/chatter = FALSE + /// "loop" or "pingpong", read from the order 1 point + var/route_mode = "loop" + +/obj/effect/landmark/stealth_patrol/Initialize(mapload) + . = ..() + GLOB.stealth_unassigned_points += src + +/obj/effect/landmark/stealth_patrol/Destroy() + GLOB.stealth_unassigned_points -= src + return ..() + +// ===== Guards on routes ===== + +/// Joins a group and claims a route, once, on its first plan (after its map has loaded). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_setup() + if(stealth_ready) + return + stealth_ready = TRUE + var/mob/living/guard = pawn + var/turf/spawn_turf = get_turf(guard) + // Its skill comes from where it starts (decision 38), settled now, before it walks anywhere. + stealth_skill() + // A calm guard walks (decision 39: tg starts every mob at a run, and nothing set the pace before its first + // change of state, so fresh patrols ran their routes). + if(!stealth_driven()) + stealth_set_pace(FALSE) + home_turf = spawn_turf + sentry_dir = stealth_facing(guard) + stand_dir = sentry_dir + // A sentry's first look aside comes after a full turn at its post, not on its first step. + next_turn = world.time + STEALTH_SENTRY_TURN_INTERVAL + group = stealth_group_for(spawn_turf) + if(isnull(group)) + group = new(spawn_turf) + group.add_member(guard) + // The route with a stop nearest its spawn, within reach. + var/best_dist = INFINITY + for(var/route in group.routes) + var/list/stops = group.routes[route] + for(var/index in 1 to length(stops)) + var/datum/stealth_stop/stop = stops[index] + var/dist = get_dist(stop.spot, spawn_turf) + if(dist > STEALTH_ROUTE_CLAIM_RANGE || dist >= best_dist) + continue + best_dist = dist + route_id = route + route_index = index + if(route_id) + var/datum/stealth_stop/start = group.routes[route_id][route_index] + home_turf = start.spot + +/// Drops its route and holds `where` as a sentry from now on: it was carried off its level or out of its +/// region (abuse R3). A guard that only walked or was chased away keeps its route and walks back. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_become_sentry(turf/where) + route_id = null + at_stop = FALSE + home_retry_at = 0 + stealth_drop_walk() + if(where) + home_turf = where + sentry_dir = stealth_facing(pawn) + stand_dir = sentry_dir + next_turn = world.time + STEALTH_SENTRY_TURN_INTERVAL + +/// Its route's stops, or null. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_stops() + if(isnull(route_id) || isnull(group)) + return null + return group.routes[route_id] + +/// Back from a suspicion, a search or a chase: heads for the nearest stop of its route it can still try. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_rejoin_route() + at_stop = FALSE + wait_until = 0 + home_retry_at = 0 + var/list/stops = stealth_stops() + if(!length(stops)) + return + var/turf/here = get_turf(pawn) + var/best_dist = INFINITY + for(var/index in 1 to length(stops)) + if(world.time < stop_skip_until["[index]"]) + continue + var/datum/stealth_stop/stop = stops[index] + var/dist = get_dist(stop.spot, here) + if(dist < best_dist) + best_dist = dist + route_index = index + +/// The next stop after the current one that isn't being skipped, or 0 if every stop is skipped. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_next_index() + var/list/stops = stealth_stops() + var/count = length(stops) + if(!count) + return 0 + var/pingpong = group.route_modes[route_id] == "pingpong" + var/index = route_index + for(var/tries in 1 to count * 2) + index += route_step + if(index > count || index < 1) + if(pingpong && count > 1) + route_step = -route_step + index += route_step * 2 + else + index = index > count ? 1 : count + if(world.time >= stop_skip_until["[index]"]) + return index + return 0 + +/** + * A walk the pathfinder gave up on (abuse R2). A stop that fails often enough is skipped for a while; with + * every stop skipped it waits where it is and tries again when the first skip runs out. A sentry that can't + * reach its post waits and tries again too. Neither gives up its route or post for good: only being carried + * off does that. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_walk_failed() + if(goto_purpose == STEALTH_GOTO_HOME) + home_retry_at = world.time + STEALTH_HOME_RETRY_TIME + return + if(goto_purpose != STEALTH_GOTO_PATROL || isnull(route_id)) + return + var/key = "[route_index]" + stop_fails[key]++ + if(stop_fails[key] < STEALTH_PATROL_MAX_FAILS) + return + stop_fails[key] = 0 + stop_skip_until[key] = world.time + STEALTH_PATROL_SKIP_TIME + var/next = stealth_next_index() + if(next) + route_index = next + +/// Unaware with no target: walks its route or holds its post. Last in the list: it always leaves the guard +/// something to do, so planning never comes up empty. +/datum/ai_planning_subtree/stealth_patrol + +/datum/ai_planning_subtree/stealth_patrol/SelectBehaviors(datum/ai_controller/basic_controller/human_npc/stealth/controller, seconds_per_tick) + if(!istype(controller)) + return + var/mob/living/guard = controller.pawn + if(guard.stat != CONSCIOUS) + return + if(controller.stealth_state() == STEALTH_UNAWARE && !controller.blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET)) + // Glancing at a noise, or holding for one: it stops and faces it, then carries on. + if(world.time < controller.glance_until) + controller.stealth_drop_walk() + controller.next_turn = controller.glance_until + if(guard.dir != controller.glance_dir) + guard.setDir(controller.glance_dir) + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + if(length(controller.stealth_stops())) + controller.stealth_plan_route() + else + controller.stealth_plan_post() + // Alert with nobody in reach of the fighting subtrees, or holding: it stands and looks about. + if(!length(controller.planned_behaviors)) + controller.queue_behavior(/datum/ai_behavior/stealth_stand) + return SUBTREE_RETURN_FINISH_PLANNING + +/// A sentry: stands its post, or walks back to it. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_plan_post() + var/mob/living/guard = pawn + var/turf/here = get_turf(guard) + route_id = null + var/turf/post = home_turf + if(post && here != post) + if(post.z != here.z || map_region_for_turf(post) != map_region_for_turf(here)) + // Carried off: this is its post now. + stealth_become_sentry(here) + else if(world.time >= home_retry_at) + if(stealth_walk_gave_up(post)) + stealth_drop_walk() + if(!stealth_walk_arrived(post)) + stealth_walk(post, STEALTH_GOTO_HOME) + return + stand_dir = sentry_dir + queue_behavior(/datum/ai_behavior/stealth_stand) + +/// A route guard: waits at its stop, then walks to the next one it can reach. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_plan_route() + var/mob/living/guard = pawn + var/turf/here = get_turf(guard) + var/list/stops = stealth_stops() + if(at_stop) + if(world.time < wait_until) + queue_behavior(/datum/ai_behavior/stealth_stand) + return + var/next = stealth_next_index() + if(!next) + // Every other stop is shut off: it stays here until one opens. + queue_behavior(/datum/ai_behavior/stealth_stand) + return + at_stop = FALSE + route_index = next + if(world.time < stop_skip_until["[route_index]"]) + var/next = stealth_next_index() + if(!next) + // Shut in: it waits, and tries again when the first skip runs out. + stand_dir = stealth_facing(guard) + queue_behavior(/datum/ai_behavior/stealth_stand) + return + route_index = next + var/datum/stealth_stop/stop = stops[route_index] + // Leash (abuse R3): a stop on another level or in another region means it was carried off. + if(stop.spot.z != here.z || !group.region_matches(here)) + stealth_become_sentry(here) + queue_behavior(/datum/ai_behavior/stealth_stand) + return + if(stealth_walk_arrived(stop.spot)) + stealth_drop_walk() + stealth_arrive(stop) + queue_behavior(/datum/ai_behavior/stealth_stand) + return + // A failed try that hasn't yet shut the stop off: it tries again. + if(stealth_walk_gave_up(stop.spot)) + stealth_drop_walk() + stealth_walk(stop.spot, STEALTH_GOTO_PATROL) + +/// At a stop: faces its way, waits, and talks if it's a chatter stop and a friend is near. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_arrive(datum/stealth_stop/stop) + at_stop = TRUE + home_turf = stop.spot + stop_fails["[route_index]"] = 0 + wait_until = world.time + stop.wait + if(stop.dir) + stand_dir = stop.dir + stealth_turn_to(stop.dir) + else + stand_dir = stealth_facing(pawn) + next_turn = world.time + STEALTH_LOOK_TURN_INTERVAL + if(!stop.chatter || world.time < group.next_chatter) + return + var/mob/living/guard = pawn + for(var/mob/living/friend as anything in group.living_members()) + if(friend == guard || friend.stat != CONSCIOUS || get_dist(friend, guard) > STEALTH_CHATTER_RANGE) + continue + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = friend.ai_controller + if(!istype(friend_ai) || friend_ai.stealth_state() != STEALTH_UNAWARE) + continue + group.next_chatter = world.time + STEALTH_CHATTER_COOLDOWN + var/datum/ai_controller/basic_controller/human_npc/stealth/speaker = pick(src, friend_ai) + speaker.stealth_bark(STEALTH_BARK_CHATTER) + return diff --git a/voidcrew/modules/stealth/stealth_perception.dm b/voidcrew/modules/stealth/stealth_perception.dm new file mode 100644 index 00000000000..5e498be593b --- /dev/null +++ b/voidcrew/modules/stealth/stealth_perception.dm @@ -0,0 +1,150 @@ +/** + * # Stealth perception + * + * Sight for guards that opted into stealth (stealth_ai.dm). It is AI math only: no fov_view on the body + * (a player who later takes it over must not inherit it), and the cone and darkness are never added to + * can_attack(), so an alert guard keeps tg's all-round check and an attack from behind still lands on a + * guard that can turn round (abuse review P1, P2). + * + * A scan, once a second while the AI is awake: the living mobs near it on the HEARING grid (every mob is + * hearing-sensitive, so SSD bodies and other NPCs count), nearest first, without its own side or the dead. + * Each goes through the guard's own can_attack() (faction, stat, line of sight, invisibility, the + * packed-level cordon, Ghostskin camo), and the first STEALTH_MAX_CANDIDATES that pass get the cone, light + * and movement rules that raise or decay its "notice". Only mobs it could perceive count toward that cap, + * so a pile of corpses, mice or its own friends can't crowd a player out. + */ + +#ifdef UNIT_TESTS +/// Unit tests: turf => TRUE to treat it as dark, FALSE as lit (reserved test space has no light of its own) +GLOBAL_LIST_EMPTY(stealth_test_dark_turfs) +#endif + +/// Whether `target` is within `half_angle` degrees of `viewer`'s facing. Integer math, no trig per call. +/// The same tile is in the cone; a target exactly side-on is not, even at 90 degrees. +/proc/stealth_in_cone(atom/viewer, atom/target, half_angle) + var/turf/from = get_turf(viewer) + var/turf/target_turf = get_turf(target) + if(isnull(from) || isnull(target_turf)) + return FALSE + var/dx = target_turf.x - from.x + var/dy = target_turf.y - from.y + if(!dx && !dy) + return TRUE + var/facing = viewer.dir + var/sx = (facing & EAST) ? 1 : ((facing & WEST) ? -1 : 0) + var/sy = (facing & NORTH) ? 1 : ((facing & SOUTH) ? -1 : 0) + var/facing_len2 = sx * sx + sy * sy + if(!facing_len2) + return FALSE + var/forward = dx * sx + dy * sy + if(forward <= 0) + return FALSE + return forward * forward >= (dx * dx + dy * dy) * facing_len2 * stealth_cos2(half_angle) + +/// cos^2 of `angle` degrees, from a table for the angles the stealth layer uses. +/proc/stealth_cos2(angle) + switch(angle) + if(60) + return 0.25 + if(75) + return 0.0669873 + if(90) + return 0 + var/c = cos(angle) + return c * c + +/** + * Whether `tile` is dark enough to hide in. A turf with no lighting object (planet ground lit only by its + * area's ambient light) reads its area's base light, which get_lumcount() skips (it returns 1 there). + * Same rule as the bounty AI's ai_tile_is_dark() (bounty_ai_meek.dm), which is a type proc. + * Every light counts, a guard's own flashlight beam too: it is real light that players see (decision 39). + * `no_guard_lights` leaves out every guard's beam, so a guard deciding whether its spot needs a light judges by + * the room's own light, not by a friend walking past with one (decision 32: no flicker when guards meet). + */ +/proc/stealth_tile_is_dark(turf/tile, no_guard_lights = FALSE) + if(!isturf(tile)) + return FALSE +#ifdef UNIT_TESTS + if(tile in GLOB.stealth_test_dark_turfs) + return GLOB.stealth_test_dark_turfs[tile] +#endif + if(!tile.lighting_object) + var/area/tile_area = tile.loc + return (tile_area.base_lighting_alpha / 255) + tile.dynamic_lumcount < STEALTH_DARK_LUMCOUNT + var/guard_light = no_guard_lights ? stealth_torch_share(tile) : 0 + return tile.get_lumcount() - guard_light < STEALTH_DARK_LUMCOUNT + +/** + * Whether the room itself leaves `tile` dark: its fixed lights only, without any guard's beam and without the + * lights people carry (tg's overlay lights, which get_lumcount() adds on top). A guard standing somewhere like + * that has a reason to wonder whose light it is seeing (decision 41). + */ +/proc/stealth_room_is_dark(turf/tile) + if(!isturf(tile)) + return FALSE +#ifdef UNIT_TESTS + if(tile in GLOB.stealth_test_dark_turfs) + return GLOB.stealth_test_dark_turfs[tile] +#endif + if(!tile.lighting_object) + var/area/tile_area = tile.loc + return (tile_area.base_lighting_alpha / 255) < STEALTH_DARK_LUMCOUNT + var/room = 0 + for(var/datum/lighting_corner/corner as anything in list(tile.lighting_corner_NE, tile.lighting_corner_SE, tile.lighting_corner_SW, tile.lighting_corner_NW)) + if(corner) + room += corner.lum_r + corner.lum_g + corner.lum_b + return room / 12 - stealth_torch_share(tile) < STEALTH_DARK_LUMCOUNT + +/** + * What `who` is shut inside, as it stands on a turf: the box, locker, bag or car, or the outermost of them. + * Null on a turf of their own, or when someone is carrying them (the carrier is the one to see). + */ +/proc/stealth_shell_of(mob/living/who) + if(isturf(who.loc)) + return null + var/atom/movable/shell = who.loc + while(shell && !isturf(shell.loc)) + shell = shell.loc + if(!ismovable(shell)) + return null + if(isnull(shell) || ismob(shell)) + return null + return shell + +/** + * Whether a cloak hides `who` from a guard's sight beyond the close radius (owner decision 20: cyberware + * cloaks and boon abilities). Ghostskin camo is already refused by can_attack() past its spot range + * (cyberware_stealth.dm); this adds the heretic shadow cloak a Vestige boon grants. + */ +/proc/stealth_is_cloaked(mob/living/who) + if(HAS_TRAIT(who, TRAIT_CYBER_CAMO)) + return TRUE + return !!who.has_status_effect(/datum/status_effect/shadow_cloak) + +/** + * The living mobs a guard might notice within `range`, nearest first: not itself, not its own side, not the + * dead. Uses the spatial grid, never view() or hearers(). The caller caps how many it judges. + */ +/proc/stealth_candidates(mob/living/guard, range) + var/turf/center = get_turf(guard) + if(isnull(center)) + return list() + var/list/buckets = new /list(range + 1) + for(var/mob/living/found in SSspatial_grid.orthogonal_range_search(center, SPATIAL_GRID_CONTENTS_TYPE_HEARING, range)) + if(found == guard || found.stat == DEAD) + continue + var/turf/found_turf = get_turf(found) + if(isnull(found_turf) || found_turf.z != center.z) + continue + var/dist = get_dist(center, found_turf) + if(dist > range) + continue + if(guard.faction_check_atom(found)) + continue + var/list/bucket = buckets[dist + 1] + if(isnull(bucket)) + buckets[dist + 1] = bucket = list() + bucket += found + . = list() + for(var/list/bucket in buckets) + . += bucket diff --git a/voidcrew/modules/stealth/stealth_radio.dm b/voidcrew/modules/stealth/stealth_radio.dm new file mode 100644 index 00000000000..13e1e3f7711 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_radio.dm @@ -0,0 +1,158 @@ +/** + * # Stealth guards: radios (owner decision 8) + * + * Some guard types carry an earpiece (`stealth_radio` on the type, and a working headset in its ears). A + * carrier that learns of trouble raises a hand to its earpiece, and STEALTH_RADIO_CALL_TIME later says it + * out loud; every other carrier in its group then knows, wherever it stands, and passes it on by voice to + * whoever stands next to it. + * + * Players stop a call with tg's own tools and nothing else: drop, stun or silence the speaker before the call + * is due; run a radio jammer near the speaker or the receiver; EMP the earpiece (tg switches a radio off for + * 20 s); deafen the receiver. The headset can't be stripped: it is locked gear like the rest of the kit. + * + * No timers: a pending call is a stamp the guard's scan reads. One alarm delivery per group per + * STEALTH_RADIO_GROUP_COOLDOWN, so a den full of carriers doesn't echo itself. + */ + +/mob/living/carbon/human/npc + /// Whether this type is on its group's radio net (it still needs a working headset in its ears) + var/stealth_radio = FALSE + +/// Its working headset, or null: on the net, headset in the ears and switched on, not in a jammer's range. +/mob/living/carbon/human/npc/proc/stealth_radio_ready() + if(!stealth_radio) + return null + var/obj/item/radio/earpiece = ears + if(!istype(earpiece) || !earpiece.is_on() || is_within_radio_jammer_range(src)) + return null + return earpiece + +/** + * Starts a radio call about `where`: a hand to the earpiece now, the call STEALTH_RADIO_CALL_TIME later if it + * can still make it (stealth_deliver_call()). A call already on its way out is kept unless this one is more + * urgent, so a run of noises never puts the call off. Returns TRUE if a call is now pending. + */ +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_start_call(kind, turf/where, name) + var/mob/living/carbon/human/npc/guard = pawn + if(!ishumannpc(guard) || !guard.stealth_radio || !istype(guard.ears, /obj/item/radio)) + return FALSE + if(guard.stat != CONSCIOUS || stealth_driven() || isnull(where)) + return FALSE + // A guard that can't speak (a cut throat, a gag) doesn't reach for the earpiece (decision 45). + if(!human_npc_can_talk(guard)) + return FALSE + if(pending_call) + if(pending_call[STEALTH_CALL_KIND] >= kind) + return TRUE + pending_call = list(kind, where, world.time + STEALTH_RADIO_CALL_TIME, name) + guard.visible_message(span_emote("[guard] raises a hand to [guard.p_their()] earpiece.")) + return TRUE + +/// The scan: makes its pending call once it is due, if it still can. A call it can't make is lost, never +/// retried; if only the radio failed, it says so. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_deliver_call() + if(isnull(pending_call) || world.time < pending_call[STEALTH_CALL_DUE]) + return + var/list/call_made = pending_call + pending_call = null + // Its level slept through it: nobody finishes a call that late. + if(world.time > call_made[STEALTH_CALL_DUE] + STEALTH_RADIO_CALL_STALE) + return + var/mob/living/carbon/human/npc/guard = pawn + if(guard.stat != CONSCIOUS || HAS_TRAIT(guard, TRAIT_INCAPACITATED) || !human_npc_can_talk(guard)) + return + if(!guard.stealth_radio_ready()) + stealth_bark(STEALTH_BARK_RADIO_DEAD) + return + var/turf/where = call_made[STEALTH_CALL_WHERE] + var/bark_kind = STEALTH_BARK_RADIO_ALARM + switch(call_made[STEALTH_CALL_KIND]) + if(STEALTH_CALL_REPORT) + bark_kind = STEALTH_BARK_RADIO_REPORT + if(STEALTH_CALL_MISSING) + bark_kind = STEALTH_BARK_RADIO_MISSING + // Said out loud, always: anyone in earshot of the speaker hears where the others are being sent. + stealth_bark(bark_kind, where, call_made[STEALTH_CALL_NAME], TRUE) + group?.radio_call(guard, call_made[STEALTH_CALL_KIND], where) + +/// A call that can't go out any more (the speaker was stunned, dropped or taken over). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_drop_call() + pending_call = null + +/// Whether `guard` can take a radio call now. +/datum/stealth_group/proc/radio_receiver(mob/living/carbon/human/npc/guard) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + if(!istype(guard_ai) || guard.stat != CONSCIOUS || guard.client || guard_ai.ai_status == AI_STATUS_OFF) + return FALSE + return guard.stealth_radio_ready() && guard.can_hear() && !guard_ai.stealth_captive() + +/** + * `speaker` has made its call. Every other member with a working radio that can hear gets it. + * - A report ("checking something"): they know it went, so they miss it if it doesn't come back. Nobody moves. + * - An alarm or a missing friend: at most one per STEALTH_RADIO_GROUP_COOLDOWN. The nearest + * STEALTH_RADIO_RESPONDERS receivers that aren't sentries search at the spot and answer; each brings up to + * STEALTH_RELAY_VOICE_RESPONDERS friends without radios from within earshot of its answer. Sentries and the + * rest hold. + * Returns how many receivers got it. + */ +/datum/stealth_group/proc/radio_call(mob/living/carbon/human/npc/speaker, kind, turf/where) + . = 0 + var/list/guards = living_members() + if(kind == STEALTH_CALL_REPORT) + var/list/speaker_checks = list() + for(var/datum/stealth_check/check as anything in checks) + if(check.who?.resolve() == speaker) + speaker_checks += check + for(var/mob/living/carbon/human/npc/guard as anything in guards) + if(guard == speaker || !radio_receiver(guard)) + continue + .++ + for(var/datum/stealth_check/check as anything in speaker_checks) + check.waiters |= WEAKREF(guard) + return + // Who it was goes out with the alarm to every receiver that got it, even inside the cooldown (decision 44). + var/datum/ai_controller/basic_controller/human_npc/stealth/speaker_ai = speaker.ai_controller + if(istype(speaker_ai)) + for(var/mob/living/carbon/human/npc/guard as anything in guards) + if(guard != speaker && radio_receiver(guard)) + speaker_ai.stealth_tell(guard.ai_controller) + if(world.time < next_radio_alarm) + return 0 + next_radio_alarm = world.time + STEALTH_RADIO_GROUP_COOLDOWN + // Receivers, nearest to the spot first. + var/list/receivers = list() + for(var/mob/living/carbon/human/npc/guard as anything in guards) + if(guard == speaker || !radio_receiver(guard)) + continue + var/dist = get_dist(guard, where) + var/index = 1 + while(index <= length(receivers) && get_dist(receivers[index], where) <= dist) + index++ + receivers.Insert(index, guard) + var/moved = 0 + for(var/mob/living/carbon/human/npc/receiver as anything in receivers) + .++ + var/datum/ai_controller/basic_controller/human_npc/stealth/receiver_ai = receiver.ai_controller + if(receiver_ai.stealth_state() == STEALTH_ALERT) + continue + if(isnull(receiver_ai.route_id) || moved >= STEALTH_RADIO_RESPONDERS || !receiver_ai.stealth_respond(where)) + receiver_ai.stealth_hold(where) + continue + moved++ + receiver_ai.stealth_bark(STEALTH_BARK_COPY, null, null, TRUE) + // Its answer carries to whoever stands near it. + var/turf/receiver_turf = get_turf(receiver) + var/brought = 0 + for(var/mob/living/carbon/human/npc/friend as anything in guards) + if(brought >= STEALTH_RELAY_VOICE_RESPONDERS) + break + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = friend.ai_controller + if(friend == receiver || friend == speaker || friend.stealth_radio || !istype(friend_ai) || isnull(friend_ai.route_id)) + continue + if(friend.stat != CONSCIOUS || friend.client || friend_ai.ai_status == AI_STATUS_OFF || !friend.can_hear()) + continue + var/turf/friend_turf = get_turf(friend) + if(get_dist(friend_turf, receiver_turf) > STEALTH_RELAY_VOICE_RANGE || stealth_muffled_dist(receiver_turf, friend_turf) > STEALTH_RELAY_VOICE_RANGE) + continue + if(friend_ai.stealth_respond(where)) + brought++ diff --git a/voidcrew/modules/stealth/stealth_skill.dm b/voidcrew/modules/stealth/stealth_skill.dm new file mode 100644 index 00000000000..a11fffb14df --- /dev/null +++ b/voidcrew/modules/stealth/stealth_skill.dm @@ -0,0 +1,174 @@ +/** + * # Stealth guards: skill by zone (owner decision 38) + * + * How sharp a guard's eyes and ears are. One profile per skill level; yellow is the tuning the den was built + * and playtested on, so a yellow guard behaves exactly as before. The numbers are argued in + * data/stealth/STATUS.md, "Decisions 37-38". + * + * Skill is perception only. It never touches damage, health, armour, aim or fire rate: a red guard sees and + * hears better, it doesn't shoot better or take more killing. Armour and weapons stay the zone's job. + * + * Which profile a guard gets, first that applies: + * 1. an admin's pick (Stealth Guards > the guard > Set skill), which lasts until changed; + * 2. the mapper's `stealth_skill` on the guard, or on the spawner that made it; + * 3. the overmap zone of the planet or ruin it stands on when it first scans; + * 4. yellow, when that place can't be tied to a zone. + */ +/datum/stealth_skill + /// For admins + var/name = "yellow" + /// Tiles it notices someone at in its cone, in the light + var/sight_range = 8 + /// Tiles within which a sighting can turn into an alert (decision 18 holds it at 7 or under: on screen) + var/alert_max_range = 7 + /// Tiles it notices someone at in its cone, in the dark + var/dark_sight_range = 4 + /// Cone half-angle, calm + var/cone_half_angle = 60 + /// Cone half-angle while wary + var/wary_half_angle = 75 + /// Cone half-angle while searching (90 at most: the cone never takes in what is behind it) + var/search_half_angle = 90 + /// Notice gained per second on someone in plain view at its feet (less further off) + var/notice_rate = 1.0 + /// In its cone, seen plainly, this close: an alert on that look (decision 32) + var/point_blank_range = 2 + /// In its cone this close: notice fills near_mult times faster (decision 32) + var/near_range = 4 + var/near_mult = 3 + /// All round, in light that is there anyway, this close: noticed (abuse P7). Never in the dark (decision 32). + var/close_range = 2 + /// Multiplies how far it hears quiet noises (steps, doors, glass, knocks, voices). Gunfire, blasts, screams + /// and shouts are heard as before: they already carry as far as a player hears them (abuse H2). + var/hearing_mult = 1 + /// How long a suspicious guard stares before it walks over to look + var/reaction_delay = 2 SECONDS + /// How long it searches before it gives up + var/search_time = 40 SECONDS + /// How long it stays wary with nothing new + var/wary_time = 60 SECONDS + /// After it turns where it stands, how long before anything is plain to it at a glance (decision 39) + var/turn_grace = 1 SECONDS + /// Multiplies the notice someone in a disguise still gains: under 1 is easier to fool (decision 40) + var/disguise = 1 + /// Tiles added to the range within which it stops someone in a disguise to see their pass (decision 40) + var/challenge = 0 + +/datum/stealth_skill/yellow + +/// Sloppy: a narrower cone, slower to notice, shorter sight and hearing, quicker to give up. +/datum/stealth_skill/green + name = "green" + sight_range = 7 + alert_max_range = 6 + dark_sight_range = 3 + cone_half_angle = 45 + wary_half_angle = 60 + search_half_angle = 75 + notice_rate = 0.7 + point_blank_range = 1 + near_range = 3 + near_mult = 2 + close_range = 1 + hearing_mult = 0.75 + reaction_delay = 3 SECONDS + search_time = 25 SECONDS + wary_time = 40 SECONDS + turn_grace = 1.2 SECONDS + disguise = 0.6 + challenge = -1 + +/// Sharp: sees further and wider, notices faster, hears more, searches longer. Still blind behind in the dark. +/datum/stealth_skill/red + name = "red" + sight_range = 9 + alert_max_range = 7 + dark_sight_range = 5 + cone_half_angle = 65 + wary_half_angle = 80 + search_half_angle = 90 + notice_rate = 1.3 + point_blank_range = 2 + near_range = 5 + near_mult = 3 + close_range = 2 + hearing_mult = 1.25 + reaction_delay = 1 SECONDS + search_time = 60 SECONDS + wary_time = 90 SECONDS + turn_grace = 0.8 SECONDS + disguise = 1.6 + challenge = 1 + +/// The shared profile of type `skill_type`, or null if it isn't one. +/proc/stealth_skill_of(skill_type) + var/static/list/profiles = list() + if(!ispath(skill_type, /datum/stealth_skill)) + return null + var/datum/stealth_skill/profile = profiles[skill_type] + if(isnull(profile)) + profile = new skill_type() + profiles[skill_type] = profile + return profile + +/// The profile type for a ZONE_* (yellow when the zone is unknown). +/proc/stealth_skill_type_for_zone(zone) + switch(zone) + if(ZONE_GREEN) + return /datum/stealth_skill/green + if(ZONE_RED) + return /datum/stealth_skill/red + return /datum/stealth_skill/yellow + +/// The ZONE_* of the planet or ruin `where` belongs to, or null when it can't be tied to the overmap. +/proc/stealth_zone_of(turf/where) + if(isnull(where)) + return null + return get_zone_type_for_player_turf(where) + +/mob/living/carbon/human/npc + /// Mapper's override of a stealth guard's skill: a /datum/stealth_skill subtype, or null for its zone's + var/stealth_skill + +/obj/effect/spawner/human_npc + /// Mapper's override of the skill of the stealth guard this makes: a /datum/stealth_skill subtype, or null + var/stealth_skill + +/obj/effect/spawner/human_npc/npc_spawned_callback() + if(ispath(stealth_skill, /datum/stealth_skill)) + return CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(stealth_set_mapped_skill), stealth_skill) + return ..() + +/// A spawner's skill override, handed to the guard it made. A global proc so the order holds no ref to the spawner. +/proc/stealth_set_mapped_skill(skill_type, mob/living/carbon/human/npc/made) + if(!istype(made)) + return + made.stealth_skill = skill_type + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = made.ai_controller + if(istype(stealth_ai) && !stealth_ai.skill_forced) + stealth_ai.skill = null + +/datum/ai_controller/basic_controller/human_npc/stealth + /// Its skill profile (stealth_skill()); null until first asked for + var/datum/stealth_skill/skill + /// Set when an admin picked its skill: the mapper's and the zone's no longer apply + var/skill_forced = FALSE + +/// Its skill profile: an admin's pick, else the mapper's, else its zone's, else yellow. Settled the first time it is asked. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_skill() + if(skill) + return skill + var/mob/living/carbon/human/npc/guard = pawn + var/skill_type = istype(guard) ? guard.stealth_skill : null + if(!ispath(skill_type, /datum/stealth_skill)) + skill_type = stealth_skill_type_for_zone(istype(guard) ? stealth_zone_of(get_turf(guard)) : null) + skill = stealth_skill_of(skill_type) + return skill + +/// Admins: sets its skill to `skill_type`, or back to the mapper's or zone's with null. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_force_skill(skill_type) + skill_forced = ispath(skill_type, /datum/stealth_skill) + skill = skill_forced ? stealth_skill_of(skill_type) : null + stealth_skill() + for(var/datum/stealth_sight_overlay/overlay as anything in watchers) + overlay.refresh() diff --git a/voidcrew/modules/stealth/stealth_turns.dm b/voidcrew/modules/stealth/stealth_turns.dm new file mode 100644 index 00000000000..89e434f14a5 --- /dev/null +++ b/voidcrew/modules/stealth/stealth_turns.dm @@ -0,0 +1,108 @@ +/** + * # Stealth guards: readable turns (decision 39, playtest fixes) + * + * A guard that turns on its own (a look aside at a stop, a sentry's glance, the look round when suspicious or + * searching, back to the way it faces) leans a few pixels towards the new side for STEALTH_TURN_TELL first, then + * turns. A player watching it sees which way it is about to look and has a moment to move. + * + * After any turn made where it stands (its own, or one to a noise or a door), nothing is plain to it at a glance for + * its skill's turn_grace: no instant point-blank alert (decision 32), and no alert by sight at all until the moment + * passes. Its notice still fills as usual (it can go "?"), so someone who stays in front of it is seen on the first + * look after. A turn made by stepping is a walk, not a look round, and gives nothing. + * + * Its flashlight beam (stealth_light.dm) follows every turn and step from here, and goes halfway ahead of a turn it + * makes on its own while it leans (decision 41). + */ + +/datum/ai_controller/basic_controller/human_npc/stealth + /// world.time of its last turn made standing still, or 0 + var/turned_at = 0 + /// The turf it stood on for that turn + var/turf/turned_from + /// The way it is about to turn while its tell shows, or 0 + var/turn_pending = 0 + /// world.time that turn was planned (tells an old timer from the current one) + var/turn_planned_at = 0 + /// Where it stood when it planned that turn + var/turf/turn_planned_from + /// The lean its tell put on the body (list(pixel_w, pixel_z)), to take back, or null + var/list/turn_lean + /// +1 or -1: the side its next look aside goes (turn() takes positive as anticlockwise) + var/look_side = -1 + +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_pawn_turned(atom/source, old_dir, new_dir) + SIGNAL_HANDLER + if(old_dir == new_dir) + return + // Not before it has set up: a mapper's facing or a test's setDir is not a turn. + if(stealth_ready) + turned_at = world.time + turned_from = get_turf(source) + stealth_light_turned(old_dir, new_dir) + +// tg hooks this to the pawn's COMSIG_MOVABLE_MOVED: its second argument is where the pawn came from. +/datum/ai_controller/basic_controller/human_npc/stealth/update_grid(datum/source, datum/spatial_grid_cell/new_cell) + . = ..() + stealth_light_stepped(new_cell) + +/// Its hands or its freedom changed: its light may have to go out or may come back. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/on_light_cue(datum/source) + SIGNAL_HANDLER + stealth_update_light() + +/// Whether it turned where it stands within its skill's turn_grace: nothing is plain to it at a glance yet. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_turn_grace() + if(!turned_at || world.time >= turned_at + stealth_skill().turn_grace) + return FALSE + return get_turf(pawn) == turned_from + +/// The side of its next look aside: they alternate, so a player can count on the next one. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_next_side() + look_side = -look_side + return look_side + +/// Turns to `new_dir` on its own: leans that way for STEALTH_TURN_TELL, then turns. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_turn_to(new_dir) + var/mob/living/guard = pawn + if(QDELETED(guard) || !new_dir) + return + if(turn_pending) + if(turn_pending == new_dir) + return + stealth_drop_turn() + if(guard.dir == new_dir) + return + turn_pending = new_dir + turn_planned_at = world.time + turn_planned_from = get_turf(guard) + var/lean_w = (new_dir & EAST) ? STEALTH_TURN_LEAN : ((new_dir & WEST) ? -STEALTH_TURN_LEAN : 0) + var/lean_z = (new_dir & NORTH) ? STEALTH_TURN_LEAN : ((new_dir & SOUTH) ? -STEALTH_TURN_LEAN : 0) + turn_lean = list(lean_w, lean_z) + animate(guard, pixel_w = lean_w, pixel_z = lean_z, time = STEALTH_TURN_LEAN_TIME, flags = ANIMATION_RELATIVE | ANIMATION_PARALLEL) + stealth_torch_lead(new_dir) + addtimer(CALLBACK(src, PROC_REF(stealth_finish_turn), new_dir, turn_planned_at), STEALTH_TURN_TELL) + +/// The tell is over: it turns, unless the moment has passed (it moved, went down, changed state, or a player took it). +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_finish_turn(new_dir, planned_at) + if(turn_pending != new_dir || turn_planned_at != planned_at) + return + var/mob/living/guard = pawn + var/turf/planned_from = turn_planned_from + // Its beam is halfway there already and stays there until the body follows. + stealth_drop_turn(TRUE) + if(!QDELETED(guard) && guard.stat == CONSCIOUS && !stealth_driven() && get_turf(guard) == planned_from) + guard.setDir(new_dir) + stealth_torch_straighten() + +/// Drops a turn it was about to make and takes its lean back, and its beam with it unless it is `turning` now. +/datum/ai_controller/basic_controller/human_npc/stealth/proc/stealth_drop_turn(turning = FALSE) + if(turn_pending && !turning) + stealth_torch_straighten() + turn_pending = 0 + turn_planned_from = null + if(isnull(turn_lean)) + return + var/mob/living/guard = pawn + if(!QDELETED(guard)) + animate(guard, pixel_w = -turn_lean[1], pixel_z = -turn_lean[2], time = STEALTH_TURN_LEAN_TIME, flags = ANIMATION_RELATIVE | ANIMATION_PARALLEL) + turn_lean = null diff --git a/voidcrew/modules/trade/rumor_charts.dm b/voidcrew/modules/trade/rumor_charts.dm index cf0a41507c5..757cfc03f6e 100644 --- a/voidcrew/modules/trade/rumor_charts.dm +++ b/voidcrew/modules/trade/rumor_charts.dm @@ -147,6 +147,8 @@ var/rumor_desc /// Zone band the ruin spawns in on reveal var/spawn_zone = ZONE_RED + /// The sealed rumor a purchase uploads (a subtype can refuse to reveal, e.g. the one-at-a-time scav den) + var/chart_type = /datum/rumor_chart /datum/shop_sku/ruin_chart/get_denial_reason(mob/living/user) . = ..() @@ -178,7 +180,7 @@ stock-- - var/datum/rumor_chart/chart = new + var/datum/rumor_chart/chart = new chart_type chart.name = rumor_name || name chart.desc = rumor_desc || desc chart.ruin_template_path = ruin_template_path diff --git a/voidcrew/modules/trade/shop_catalog_black_market.dm b/voidcrew/modules/trade/shop_catalog_black_market.dm index 6dc207b6fe8..423d8c5029a 100644 --- a/voidcrew/modules/trade/shop_catalog_black_market.dm +++ b/voidcrew/modules/trade/shop_catalog_black_market.dm @@ -154,6 +154,7 @@ /datum/shop_sku/ruin_chart/survey, /datum/shop_sku/ruin_chart/blacksite, /datum/shop_sku/ruin_chart/bitrunner_den, + /datum/shop_sku/ruin_chart/scav_den, ) chart_picks = 3 rotating_pool = list( diff --git a/voidcrew/modules/trade/shop_catalog_general.dm b/voidcrew/modules/trade/shop_catalog_general.dm index a324885a399..d79153438d5 100644 --- a/voidcrew/modules/trade/shop_catalog_general.dm +++ b/voidcrew/modules/trade/shop_catalog_general.dm @@ -154,6 +154,7 @@ /datum/shop_sku/ruin_chart/survey, /datum/shop_sku/ruin_chart/blacksite, /datum/shop_sku/ruin_chart/bitrunner_den, + /datum/shop_sku/ruin_chart/scav_den, ) chart_picks = 3 // Barnaby buys honest prospecting hauls at honest prices, plus whatever diff --git a/voidcrew/modules/trade/shop_catalog_outfitter.dm b/voidcrew/modules/trade/shop_catalog_outfitter.dm index 61df3e97f3b..9ce4f9ce3f3 100644 --- a/voidcrew/modules/trade/shop_catalog_outfitter.dm +++ b/voidcrew/modules/trade/shop_catalog_outfitter.dm @@ -149,6 +149,7 @@ /datum/shop_sku/ruin_chart/survey, /datum/shop_sku/ruin_chart/blacksite, /datum/shop_sku/ruin_chart/bitrunner_den, + /datum/shop_sku/ruin_chart/scav_den, ) chart_picks = 3 rotating_pool = list( diff --git a/voidcrew/modules/unit_tests/_unit_tests.dm b/voidcrew/modules/unit_tests/_unit_tests.dm index 1dc35663ab1..7745fc6617a 100644 --- a/voidcrew/modules/unit_tests/_unit_tests.dm +++ b/voidcrew/modules/unit_tests/_unit_tests.dm @@ -148,6 +148,7 @@ #include "voidcrew_human_npcs_ruins.dm" #include "voidcrew_human_npcs_shared.dm" #include "voidcrew_hv_finishers.dm" +#include "voidcrew_hv_knife_executions.dm" #include "voidcrew_hyperviolence_blood.dm" #include "voidcrew_hyperviolence_braingut.dm" #include "voidcrew_hyperviolence_crits.dm" @@ -308,6 +309,19 @@ #include "voidcrew_simple_mob_ai.dm" #include "voidcrew_slime_extract_piles.dm" #include "voidcrew_smart_locker.dm" +#include "voidcrew_stealth.dm" +#include "voidcrew_stealth_closet.dm" +#include "voidcrew_stealth_crits.dm" +#include "voidcrew_stealth_d32.dm" +#include "voidcrew_stealth_d37.dm" +#include "voidcrew_stealth_d39.dm" +#include "voidcrew_stealth_d44.dm" +#include "voidcrew_stealth_d45.dm" +#include "voidcrew_stealth_den.dm" +#include "voidcrew_stealth_disguise.dm" +#include "voidcrew_stealth_hearing.dm" +#include "voidcrew_stealth_hostage.dm" +#include "voidcrew_stealth_light.dm" #include "voidcrew_survey_archive.dm" #include "voidcrew_survey_capabilities.dm" #include "voidcrew_survey_identity.dm" diff --git a/voidcrew/modules/unit_tests/voidcrew_human_npcs.dm b/voidcrew/modules/unit_tests/voidcrew_human_npcs.dm index 7916bed68e1..d7fa9db4e58 100644 --- a/voidcrew/modules/unit_tests/voidcrew_human_npcs.dm +++ b/voidcrew/modules/unit_tests/voidcrew_human_npcs.dm @@ -431,3 +431,41 @@ ware.forceMove(elsewhere) TEST_ASSERT(human_npc_wait_deleted(ware), "Chrome taken out of a living NPC stayed working") TEST_ASSERT_NOTNULL(locate(/obj/item/burnt_chrome) in elsewhere, "Chrome taken out of a living NPC left no scrap") + +/// A gunner holds fire with an ally anywhere on the bullet's path, including beside the target where a +/// diagonal shot clips the corner of their turf (owner playtest: a gunner shot the knife guard beside its target). +/datum/unit_test/voidcrew_human_npc_ally_in_line + +/datum/unit_test/voidcrew_human_npc_ally_in_line/Run() + var/turf/corner = run_loc_floor_bottom_left + TEST_ASSERT(run_loc_floor_top_right.x - corner.x >= 3 && run_loc_floor_top_right.y - corner.y >= 4, "Test fixture: the test room is too small") + var/mob/living/carbon/human/npc/sample/gunner/shooter = allocate(/mob/living/carbon/human/npc/sample/gunner, locate(corner.x, corner.y + 4, corner.z)) + var/mob/living/carbon/human/consistent/target = allocate(/mob/living/carbon/human/consistent, locate(corner.x + 3, corner.y, corner.z)) + var/mob/living/carbon/human/consistent/ally = allocate(/mob/living/carbon/human/consistent, locate(corner.x + 3, corner.y + 1, corner.z)) + ally.faction = shooter.faction.Copy() + TEST_ASSERT(!(ally.loc in get_line(shooter, target)), "Test fixture: the ally is on get_line(), so this doesn't test the clipped corner") + TEST_ASSERT(human_npc_ally_in_line(shooter, target), "A gunner fired past an ally standing beside its target") + // Straight down a corridor. + ally.forceMove(locate(corner.x + 2, corner.y + 2, corner.z)) + TEST_ASSERT(human_npc_ally_in_line(shooter, target), "A gunner fired through an ally between it and its target") + // Lying down: shots pass over. + ally.set_body_position(LYING_DOWN) + TEST_ASSERT(!human_npc_ally_in_line(shooter, target), "A gunner held fire for an ally lying down") + ally.set_body_position(STANDING_UP) + // Well off the path. + ally.forceMove(locate(corner.x + 3, corner.y + 4, corner.z)) + TEST_ASSERT(!human_npc_ally_in_line(shooter, target), "A gunner held fire for an ally nowhere near the path") + // A stranger on the path is not an ally. + ally.faction = list("ally_in_line_stranger") + ally.forceMove(locate(corner.x + 2, corner.y + 2, corner.z)) + TEST_ASSERT(!human_npc_ally_in_line(shooter, target), "A gunner held fire for someone not on its side") + +/// An ally's stray shot doesn't turn a human NPC on them. +/datum/unit_test/voidcrew_human_npc_ally_stray_hit + +/datum/unit_test/voidcrew_human_npc_ally_stray_hit/Run() + var/mob/living/carbon/human/npc/sample/gunner/npc = allocate(/mob/living/carbon/human/npc/sample/gunner, run_loc_floor_bottom_left) + var/mob/living/carbon/human/consistent/ally = allocate(/mob/living/carbon/human/consistent, locate(run_loc_floor_bottom_left.x + 1, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z)) + ally.faction = npc.faction.Copy() + SEND_SIGNAL(npc, COMSIG_ATOM_WAS_ATTACKED, ally, ATTACKER_DAMAGING_ATTACK) + TEST_ASSERT_NULL(npc.ai_controller.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "An ally's stray shot made the NPC target them") diff --git a/voidcrew/modules/unit_tests/voidcrew_human_npcs_ruins.dm b/voidcrew/modules/unit_tests/voidcrew_human_npcs_ruins.dm index 390f714e048..6a009143b0f 100644 --- a/voidcrew/modules/unit_tests/voidcrew_human_npcs_ruins.dm +++ b/voidcrew/modules/unit_tests/voidcrew_human_npcs_ruins.dm @@ -26,7 +26,9 @@ if(isnull(npc)) continue TEST_ASSERT_NOTNULL(npc.w_uniform, "[npc_type] has no clothes in zone [zone]") - TEST_ASSERT(human_npc_gear_locked(npc.w_uniform), "[npc_type]'s clothes aren't locked to it in zone [zone]") + // The scavs' fatigues are loot on purpose (stealth_disguise.dm); their boots stand in for the rest of their dress. + var/obj/item/clothes = istype(npc.w_uniform, /obj/item/clothing/under/syndicate/scav) ? npc.shoes : npc.w_uniform + TEST_ASSERT(human_npc_gear_locked(clothes), "[npc_type]'s clothes aren't locked to it in zone [zone]") var/obj/item/gun/gun = human_npc_held_gun(npc) var/unarmed_ok = npc_type == /mob/living/carbon/human/npc/ruin/hermit && zone == 1 if(!unarmed_ok) diff --git a/voidcrew/modules/unit_tests/voidcrew_hv_knife_executions.dm b/voidcrew/modules/unit_tests/voidcrew_hv_knife_executions.dm new file mode 100644 index 00000000000..00ba9952ca1 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_hv_knife_executions.dm @@ -0,0 +1,239 @@ +// Knife executions (voidcrew/modules/hyperviolence/overlays_exec/knife_executions.dm). Unit tests are included before +// voidcrew/_DEFINES, so these use the module's procs and plain numbers, never its HV_* defines. + +/// Puts `attacker` on the tile west of `victim`'s tile, a combat knife in hand, aiming at the head. +/datum/unit_test/proc/hv_knife_exec_setup(mob/living/carbon/human/attacker, mob/living/carbon/human/victim) + var/turf/east = get_step(attacker, EAST) + victim.forceMove(east) + var/obj/item/knife/combat/knife = allocate(/obj/item/knife/combat) + attacker.put_in_active_hand(knife, forced = TRUE) + attacker.set_combat_mode(TRUE) + attacker.zone_selected = BODY_ZONE_HEAD + attacker.setDir(EAST) + return knife + +/// The slash wound on the head at `severity` or worse, if any. +/proc/hv_knife_exec_test_slash(mob/living/carbon/victim, severity) + var/obj/item/bodypart/head/head = victim.get_bodypart(BODY_ZONE_HEAD) + for(var/datum/wound/slash/cut in head?.wounds) + if(cut.severity >= severity) + return cut + return null + +/// From behind on anyone; from the front only on the helpless. +/datum/unit_test/hv_knife_execution_trigger + +/datum/unit_test/hv_knife_execution_trigger/Run() + var/mob/living/carbon/human/consistent/attacker = allocate(/mob/living/carbon/human/consistent) + var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent) + var/obj/item/knife/combat/knife = hv_knife_exec_setup(attacker, victim) + + victim.setDir(EAST) // back to the attacker + TEST_ASSERT(knife.hv_knife_execution_possible(attacker, victim), "A knife from behind could not start an execution") + victim.setDir(WEST) // facing him + TEST_ASSERT(!knife.hv_knife_execution_possible(attacker, victim), "A knife from the front started an execution on an aware, standing target") + attacker.zone_selected = BODY_ZONE_CHEST + victim.setDir(EAST) + TEST_ASSERT(!knife.hv_knife_execution_possible(attacker, victim), "A chest-aimed knife started an execution") + attacker.zone_selected = BODY_ZONE_PRECISE_MOUTH + TEST_ASSERT(knife.hv_knife_execution_possible(attacker, victim), "A mouth-aimed knife from behind could not start an execution") + attacker.set_combat_mode(FALSE) + TEST_ASSERT(!knife.hv_knife_execution_possible(attacker, victim), "A knife out of combat mode started an execution") + attacker.set_combat_mode(TRUE) + TEST_ASSERT(!knife.hv_knife_execution_possible(attacker, attacker), "The attacker could execute himself") + attacker.start_pulling(victim, supress_message = TRUE) + attacker.setGrabState(GRAB_AGGRESSIVE) + TEST_ASSERT(!knife.hv_knife_execution_possible(attacker, victim), "A knife execution took over tg's grab slit") + attacker.stop_pulling() + + victim.setDir(WEST) + victim.Knockdown(30 SECONDS) + TEST_ASSERT(knife.hv_knife_execution_possible(attacker, victim), "A helpless target could not be executed from the front") + + var/obj/item/knife/plastic/spork = allocate(/obj/item/knife/plastic) + if(!(spork.get_sharpness() & SHARP_EDGED) || spork.force <= 0) + TEST_ASSERT(!spork.hv_knife_execution_possible(attacker, victim), "A blunt plastic knife started an execution") + +/// A held wind-up from behind ends in tg's real throat slit (decision 45's maths). A player victim keeps the 1.5 s hold; +/// only an unaware stealth guard is cut on the click (voidcrew_stealth_d45_backstab). +/datum/unit_test/hv_knife_execution_kill + +/datum/unit_test/hv_knife_execution_kill/Run() + var/mob/living/carbon/human/consistent/attacker = allocate(/mob/living/carbon/human/consistent) + var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent) + var/obj/item/knife/combat/knife = hv_knife_exec_setup(attacker, victim) + victim.setDir(EAST) + + TEST_ASSERT(!knife.hv_knife_execution_instant(attacker, victim), "A non-guard victim was cut without the hold") + knife.melee_attack_chain(attacker, victim, list()) + TEST_ASSERT(DOING_INTERACTION(attacker, "hv_knife_execution"), "The knife click did not start the wind-up") + var/obj/item/bodypart/head/head = victim.get_bodypart(BODY_ZONE_HEAD) + TEST_ASSERT_EQUAL(head.brute_dam, 0, "The knife click hurt the victim before the wind-up ended") + sleep(2.5 SECONDS) + TEST_ASSERT(!DOING_INTERACTION(attacker, "hv_knife_execution"), "The wind-up never ended") + TEST_ASSERT(victim.has_status_effect(/datum/status_effect/neck_slice), "An unarmoured victim's neck was not sliced") + TEST_ASSERT_NOTNULL(hv_knife_exec_test_slash(victim, WOUND_SEVERITY_CRITICAL), "An unarmoured victim got no critical slash on the head") + TEST_ASSERT(head.brute_dam > 0, "The cut did no damage to the head") + TEST_ASSERT_EQUAL(attacker.pixel_w, 0, "The attacker was left offset after the move") + TEST_ASSERT_EQUAL(attacker.pixel_z, 0, "The attacker was left offset after the move") + +/// Turning to face the attacker breaks the wind-up: no cut, no damage. +/datum/unit_test/hv_knife_execution_break + +/datum/unit_test/hv_knife_execution_break/Run() + var/mob/living/carbon/human/consistent/attacker = allocate(/mob/living/carbon/human/consistent) + var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent) + var/obj/item/knife/combat/knife = hv_knife_exec_setup(attacker, victim) + victim.setDir(EAST) + + knife.melee_attack_chain(attacker, victim, list()) + TEST_ASSERT(DOING_INTERACTION(attacker, "hv_knife_execution"), "The knife click did not start the wind-up") + sleep(0.5 SECONDS) + victim.setDir(WEST) + sleep(2 SECONDS) + TEST_ASSERT(!DOING_INTERACTION(attacker, "hv_knife_execution"), "The wind-up did not stop") + TEST_ASSERT(!victim.has_status_effect(/datum/status_effect/neck_slice), "A broken wind-up still sliced the neck") + TEST_ASSERT_NULL(hv_knife_exec_test_slash(victim, WOUND_SEVERITY_MODERATE), "A broken wind-up still cut the throat") + var/obj/item/bodypart/head/head = victim.get_bodypart(BODY_ZONE_HEAD) + TEST_ASSERT_EQUAL(head.brute_dam, 0, "A broken wind-up still hurt the head") + TEST_ASSERT_EQUAL(attacker.pixel_w, 0, "The attacker was left offset after a broken wind-up") + TEST_ASSERT_EQUAL(victim.pixel_w, 0, "The victim was left offset after a broken wind-up") + + // Walking away breaks it too. + victim.setDir(EAST) + knife.melee_attack_chain(attacker, victim, list()) + TEST_ASSERT(DOING_INTERACTION(attacker, "hv_knife_execution"), "The second knife click did not start the wind-up") + sleep(0.5 SECONDS) + victim.forceMove(get_step(victim, EAST)) + sleep(2 SECONDS) + TEST_ASSERT(!victim.has_status_effect(/datum/status_effect/neck_slice), "Stepping away did not break the wind-up") + +/// Head protection works as tg's slit maths says (decision 45): melee armour weakens the stab, wound armour (worn, or +/// physiology armour such as dermal cyberware) keeps the throat from being cut. +/datum/unit_test/hv_knife_execution_armour + +/datum/unit_test/hv_knife_execution_armour/Run() + var/mob/living/carbon/human/consistent/attacker = allocate(/mob/living/carbon/human/consistent) + var/mob/living/carbon/human/consistent/bare = allocate(/mob/living/carbon/human/consistent) + var/obj/item/knife/combat/knife = hv_knife_exec_setup(attacker, bare) + bare.setDir(EAST) + TEST_ASSERT(knife.hv_finish_knife_execution(attacker, bare, list(), list()), "The bare execution did not land") + var/bare_brute = bare.get_bodypart(BODY_ZONE_HEAD).brute_dam + TEST_ASSERT(bare.has_status_effect(/datum/status_effect/neck_slice), "A bare throat was not cut") + + var/mob/living/carbon/human/consistent/helmeted = allocate(/mob/living/carbon/human/consistent) + helmeted.equip_to_slot_or_del(allocate(/obj/item/clothing/head/helmet/swat), ITEM_SLOT_HEAD) + bare.forceMove(run_loc_floor_top_right) + helmeted.forceMove(get_step(attacker, EAST)) + helmeted.setDir(EAST) + TEST_ASSERT(knife.hv_finish_knife_execution(attacker, helmeted, list(), list()), "The helmeted execution did not land") + var/helmet_brute = helmeted.get_bodypart(BODY_ZONE_HEAD).brute_dam + TEST_ASSERT(helmet_brute < bare_brute, "A helmet did not weaken the stab ([helmet_brute] vs [bare_brute])") + TEST_ASSERT(!helmeted.has_status_effect(/datum/status_effect/neck_slice), "A SWAT helmet did not keep the neck from being cut") + TEST_ASSERT_NULL(hv_knife_exec_test_slash(helmeted, WOUND_SEVERITY_CRITICAL), "A SWAT helmet did not keep the critical slash out") + + var/mob/living/carbon/human/consistent/plated = allocate(/mob/living/carbon/human/consistent) + plated.physiology.armor = plated.physiology.armor.generate_new_with_modifiers(list(MELEE = 30, WOUND = 20)) + helmeted.forceMove(run_loc_floor_top_right) + plated.forceMove(get_step(attacker, EAST)) + plated.setDir(EAST) + TEST_ASSERT(knife.hv_finish_knife_execution(attacker, plated, list(), list()), "The plated execution did not land") + var/plated_brute = plated.get_bodypart(BODY_ZONE_HEAD).brute_dam + TEST_ASSERT(plated_brute < bare_brute, "Plating under the skin did not weaken the stab ([plated_brute] vs [bare_brute])") + TEST_ASSERT(!plated.has_status_effect(/datum/status_effect/neck_slice), "Plating under the skin did not keep the neck from being cut") + +/// Human NPCs below boss rank never execute; bosses and players do. +/datum/unit_test/hv_knife_execution_npc_rank + +/datum/unit_test/hv_knife_execution_npc_rank/Run() + var/mob/living/carbon/human/npc/npc = allocate(/mob/living/carbon/human/npc) + QDEL_NULL(npc.ai_controller) + var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent) + var/obj/item/knife/combat/knife = hv_knife_exec_setup(npc, victim) + victim.setDir(EAST) + TEST_ASSERT(!npc.hv_can_execute(), "Test fixture: a regular NPC can execute") + TEST_ASSERT(!knife.hv_knife_execution_possible(npc, victim), "A regular human NPC started a knife execution") + knife.melee_attack_chain(npc, victim, list()) + TEST_ASSERT(!DOING_INTERACTION(npc, "hv_knife_execution"), "A regular human NPC's knife click started the wind-up") + npc.npc_rank = 2 // HUMAN_NPC_RANK_BOSS + TEST_ASSERT(knife.hv_knife_execution_possible(npc, victim), "A boss NPC could not start a knife execution") + +/// How many stand-in arm pieces and knives of the hold from behind exist anywhere. +/proc/hv_knife_exec_test_pieces() + . = 0 + for(var/obj/effect/abstract/hv_knife_exec_part/piece in world) + if(!QDELETED(piece)) + .++ + +/// The hold from behind puts stand-in arms on both bodies and takes every one of them away again, cut or broken. +/datum/unit_test/hv_knife_execution_visuals + +/datum/unit_test/hv_knife_execution_visuals/Run() + var/mob/living/carbon/human/consistent/attacker = allocate(/mob/living/carbon/human/consistent) + var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent) + var/obj/item/knife/combat/knife = hv_knife_exec_setup(attacker, victim) + victim.setDir(EAST) + var/attacker_filters = length(attacker.filters) + var/victim_filters = length(victim.filters) + var/attacker_overlays = length(attacker.overlays) + var/victim_overlays = length(victim.overlays) + var/attacker_layer = attacker.layer + + // Broken: the victim turns round. + knife.melee_attack_chain(attacker, victim, list()) + sleep(0.5 SECONDS) + TEST_ASSERT_NOTNULL(knife.hv_vis_exec, "The hold from behind drew nothing") + TEST_ASSERT(hv_knife_exec_test_pieces() > 0, "The hold from behind made no stand-in arm") + TEST_ASSERT(knife.hv_vis_hide_inhand, "The held knife was still drawn in the real hand under the stand-in one") + TEST_ASSERT(length(victim.filters) > victim_filters || length(victim.overlays) > victim_overlays, "The victim's own arm did not come up") + victim.setDir(WEST) + sleep(1 SECONDS) + TEST_ASSERT_NULL(knife.hv_vis_exec, "A broken hold's pictures were still running a second later") + TEST_ASSERT_EQUAL(hv_knife_exec_test_pieces(), 0, "A broken hold left stand-in arm pieces behind") + TEST_ASSERT(!knife.hv_vis_hide_inhand, "A broken hold left the held knife hidden") + TEST_ASSERT_EQUAL(length(attacker.filters), attacker_filters, "A broken hold left a mask on the attacker") + TEST_ASSERT_EQUAL(length(victim.filters), victim_filters, "A broken hold left a mask on the victim") + TEST_ASSERT_EQUAL(length(attacker.overlays), attacker_overlays, "A broken hold left a cover on the attacker") + TEST_ASSERT_EQUAL(length(victim.overlays), victim_overlays, "A broken hold left a cover on the victim") + TEST_ASSERT_EQUAL(attacker.layer, attacker_layer, "A broken hold left the attacker on another layer") + + // Carried through: every piece is gone once the victim's hand has left his throat. + victim.setDir(EAST) + knife.melee_attack_chain(attacker, victim, list()) + TEST_ASSERT(DOING_INTERACTION(attacker, "hv_knife_execution"), "The second knife click did not start the wind-up") + sleep(2.2 SECONDS) + TEST_ASSERT(!knife.hv_vis_hide_inhand, "The held knife was still hidden after the attacker let go") + TEST_ASSERT_EQUAL(length(attacker.filters), attacker_filters, "The attacker kept a mask after letting go") + TEST_ASSERT_EQUAL(attacker.layer, attacker_layer, "The attacker was left on another layer after letting go") + sleep(2.5 SECONDS) + TEST_ASSERT_NULL(knife.hv_vis_exec, "The execution's pictures never ended") + TEST_ASSERT_EQUAL(hv_knife_exec_test_pieces(), 0, "The execution left stand-in arm pieces behind") + TEST_ASSERT_EQUAL(length(victim.filters), victim_filters, "The victim kept a mask") + + // Far-hand side view with the victim's near hand full: blade starts behind the attacker, rises at the chin, and + // the victim's far arm still comes up. + var/mob/living/carbon/human/consistent/west_victim = allocate(/mob/living/carbon/human/consistent) + west_victim.forceMove(get_step(attacker, WEST)) + west_victim.setDir(WEST) + attacker.setDir(WEST) + attacker.dropItemToGround(knife, force = TRUE) + attacker.swap_hand(2) + attacker.put_in_active_hand(knife, forced = TRUE) + var/obj/item/universal_scanner/held_tool = allocate(/obj/item/universal_scanner) + west_victim.put_in_l_hand(held_tool) + var/west_vic_filters = length(west_victim.filters) + sleep(1.1 SECONDS) // clear the 1 s visual cooldown + knife.melee_attack_chain(attacker, west_victim, list()) + sleep(0.1 SECONDS) + var/datum/hv_knife_exec_vis/west_vis = knife.hv_vis_exec + TEST_ASSERT_NOTNULL(west_vis, "The west far-hand hold drew nothing") + TEST_ASSERT(west_vis.far_cut, "West right-hand hold was not marked far_cut") + TEST_ASSERT(west_vis.blade.layer < attacker.layer, "Far-hand blade started over the attacker ([west_vis.blade.layer] vs [attacker.layer])") + TEST_ASSERT(west_vis.blade_release_layer < attacker.layer, "Far-hand blade release layer is over the attacker") + TEST_ASSERT_NOTNULL(west_vis.arms["v"], "Victim's far arm did not come up when his near hand held a tool") + sleep(0.35 SECONDS) + TEST_ASSERT(west_vis.blade.layer > MOB_LAYER, "Far-hand blade did not come in front of the neck at the chin") + west_victim.setDir(EAST) + sleep(1 SECONDS) + TEST_ASSERT_EQUAL(hv_knife_exec_test_pieces(), 0, "Broken west hold left stand-in pieces behind") + TEST_ASSERT_EQUAL(length(west_victim.filters), west_vic_filters, "Broken west hold left a mask on the victim") diff --git a/voidcrew/modules/unit_tests/voidcrew_hyperviolence_overlays_exec.dm b/voidcrew/modules/unit_tests/voidcrew_hyperviolence_overlays_exec.dm index eb1d81bf4cc..e0ff484f167 100644 --- a/voidcrew/modules/unit_tests/voidcrew_hyperviolence_overlays_exec.dm +++ b/voidcrew/modules/unit_tests/voidcrew_hyperviolence_overlays_exec.dm @@ -185,6 +185,49 @@ TEST_ASSERT(head.brute_dam >= round_damage * 1.5, "A head-aimed point-blank shot at a downed target was not an execution ([head.brute_dam] head damage from a [round_damage] round)") TEST_ASSERT(head.hv_skull_wound >= 1, "A head-aimed light execution left no skull wound for its damage") // light: 40 head brute +/// An execution click ends tg's attack chain: the gun isn't also swung at the victim (no pistol-whip), whether the +/// shot went off or the wind-up was refused. +/datum/unit_test/hv_execution_no_pistol_whip + /// Gun blows tg's attack chain landed on the victim + var/bashes = 0 + +/datum/unit_test/hv_execution_no_pistol_whip/Run() + var/mob/living/carbon/human/consistent/gunner = allocate(/mob/living/carbon/human/consistent) + var/mob/living/carbon/human/consistent/victim = allocate(/mob/living/carbon/human/consistent) + ADD_TRAIT(victim, TRAIT_PIERCEIMMUNE, INNATE_TRAIT) // no stray shrapnel + var/obj/item/gun/ballistic/automatic/pistol/gun = allocate(/obj/item/gun/ballistic/automatic/pistol) + gun.can_misfire = FALSE + gunner.put_in_active_hand(gun, forced = TRUE) + gunner.set_combat_mode(TRUE) + gunner.zone_selected = BODY_ZONE_HEAD + gun.chambered.loaded_projectile.damage = 20 // doubled at the muzzle: 40, under the burst line + victim.Knockdown(30 SECONDS) + TEST_ASSERT(gun.hv_execution_possible(gunner, victim), "Test fixture: the downed victim can't be executed") + RegisterSignal(gun, COMSIG_ITEM_ATTACK, PROC_REF(on_bash)) + // The real click: tg's attack chain, through try_fire_gun(), the wind-up and the shot. + var/obj/item/bodypart/head/head = victim.get_bodypart(BODY_ZONE_HEAD) + TEST_ASSERT(gun.melee_attack_chain(gunner, victim, list()), "The execution click didn't end the attack chain") + TEST_ASSERT(head.brute_dam > 0, "Test fixture: the execution didn't fire") + TEST_ASSERT_EQUAL(bashes, 0, "The gun clubbed the victim after the execution") + // A refused wind-up (the gun still busy) ends the chain too. + gun.fire_cd = TRUE + TEST_ASSERT(gun.melee_attack_chain(gunner, victim, list()), "A refused execution click didn't end the attack chain") + TEST_ASSERT_EQUAL(bashes, 0, "The gun clubbed the victim when the execution was refused") + gun.fire_cd = FALSE + // Someone who can't be executed is still clubbed as tg does (combat mode, point blank, nothing to shoot). + victim.SetKnockdown(0) + victim.fully_heal(HEAL_ALL) + gun.magazine.stored_ammo.Cut() + QDEL_NULL(gun.chambered) + TEST_ASSERT(!gun.hv_execution_possible(gunner, victim), "Test fixture: an empty gun could still execute") + gun.melee_attack_chain(gunner, victim, list()) + TEST_ASSERT_EQUAL(bashes, 1, "Test fixture: an empty gun's point-blank click didn't club, so the counts above prove nothing") + UnregisterSignal(gun, COMSIG_ITEM_ATTACK) + +/datum/unit_test/hv_execution_no_pistol_whip/proc/on_bash(obj/item/source, mob/living/target, mob/living/user) + SIGNAL_HANDLER + bashes++ + /// A human NPC is helpless only in tg's states (stunned, cuffed, held, down), never because of its health. /datum/unit_test/hv_npc_executable_states diff --git a/voidcrew/modules/unit_tests/voidcrew_loot.dm b/voidcrew/modules/unit_tests/voidcrew_loot.dm index 6c404215e63..7b8b002d141 100644 --- a/voidcrew/modules/unit_tests/voidcrew_loot.dm +++ b/voidcrew/modules/unit_tests/voidcrew_loot.dm @@ -198,7 +198,8 @@ // a hand-placed setpiece (elite, or an arena's megafauna) counts as // the guard/boss, e.g. Pandora's ruin, the blood-drunk shrines var/has_setpiece = has_megafauna || findtext(text, "/mob/living/simple_animal/hostile/asteroid/elite") - if(!findtext(text, "/obj/effect/zone_mobs") && !has_setpiece) + // Human NPC guards (a stealth den's scavs) defend a cache as well as a zone_mobs marker does. + if(!findtext(text, "/obj/effect/zone_mobs") && !findtext(text, "/obj/effect/spawner/human_npc") && !has_setpiece) TEST_FAIL("[map_file] places a loot cache but no zone_mobs guard marker or hand-placed setpiece") // ---- rumor charts point at real, stocked, guarded ruins ---- @@ -235,8 +236,8 @@ chart_caches++ if(!chart_caches) TEST_FAIL("[map_path] (rumor chart [chart_path]) contains no zone loot caches. The chart sells an empty prize") - if(!findtext(text, "/obj/effect/zone_mobs")) - TEST_FAIL("[map_path] (rumor chart [chart_path]) has no zone_mobs guards") + if(!findtext(text, "/obj/effect/zone_mobs") && !findtext(text, "/obj/effect/spawner/human_npc")) + TEST_FAIL("[map_path] (rumor chart [chart_path]) has no zone_mobs or human NPC guards") var/chart_has_boss = findtext(text, "/boss,") || findtext(text, "/boss{") || findtext(text, "/boss)") var/chart_setpiece = findtext(text, "/mob/living/simple_animal/hostile/megafauna") \ || findtext(text, "/mob/living/basic/boss") \ diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth.dm b/voidcrew/modules/unit_tests/voidcrew_stealth.dm new file mode 100644 index 00000000000..3f6ffd357a6 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth.dm @@ -0,0 +1,876 @@ +// Stealth guards (voidcrew/modules/stealth/). Unit tests compile before voidcrew/_DEFINES, so values from +// there are written out: states "unaware", "suspicious", "alert", "searching"; blackboard keys +// "stealth_state", "stealth_wary"; STEALTH_PATROL_MAX_FAILS 3, STEALTH_LOSE_TARGET_TIME 4 s, +// STEALTH_SEARCH_TIME 40 s, STEALTH_CALM_LOOK_TIME 6 s, STEALTH_WARY_TIME 60 s, STEALTH_SWITCH_COOLDOWN 4 s. +// +// The tests down to voidcrew_stealth_body_again call the scan and the state procs directly, with the AI off. The +// voidcrew_stealth_live tests at the bottom run the real AI: planning, the scan and real walking. + +#define STEALTH_TEST_GUARD /mob/living/carbon/human/npc/ruin/trooper/scav + +/// A floored block of `width` x `height` tiles for one test. Released by the caller. +/datum/unit_test/proc/stealth_block(width, height) + var/datum/turf_reservation/block = SSmapping.request_turf_block_reservation(width, height, 1) + if(isnull(block)) + return null + var/turf/corner = block.bottom_left_turfs[1] + for(var/turf/spot as anything in block(corner.x, corner.y, corner.z, corner.x + width - 1, corner.y + height - 1, corner.z)) + spot.ChangeTurf(/turf/open/floor/iron) + GLOB.stealth_test_dark_turfs[spot] = FALSE + return block + +/datum/unit_test/proc/stealth_at(datum/turf_reservation/block, dx, dy) + var/turf/corner = block.bottom_left_turfs[1] + return locate(corner.x + dx, corner.y + dy, corner.z) + +/// A guard at (dx, dy) of `block`, facing `facing`. +/datum/unit_test/proc/stealth_guard(datum/turf_reservation/block, dx, dy, facing = EAST) + var/mob/living/carbon/human/npc/guard = allocate(STEALTH_TEST_GUARD, stealth_at(block, dx, dy)) + guard.setDir(facing) + return guard + +/// A walking, ordinary person at (dx, dy) of `block`. +/datum/unit_test/proc/stealth_person(datum/turf_reservation/block, dx, dy) + var/mob/living/carbon/human/consistent/person = allocate(/mob/living/carbon/human/consistent, stealth_at(block, dx, dy)) + if(person.move_intent == MOVE_INTENT_RUN) + person.toggle_move_intent() + return person + +/datum/unit_test/proc/stealth_ai(mob/living/guard) + return guard.ai_controller + +/datum/unit_test/proc/stealth_scans(mob/living/guard, count) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + for(var/i in 1 to count) + stealth_ai.stealth_scan_once() + +/// Cone math against a guard facing east. +/datum/unit_test/voidcrew_stealth_cone + +/datum/unit_test/voidcrew_stealth_cone/Run() + var/datum/turf_reservation/block = stealth_block(9, 9) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/obj/item/viewer = allocate(/obj/item/pen, stealth_at(block, 4, 4)) + viewer.setDir(EAST) + // offset => expected at 60, 75, 90 + var/list/cases = list( + list(3, 0, TRUE, TRUE, TRUE), + list(3, 2, TRUE, TRUE, TRUE), + list(2, 3, TRUE, TRUE, TRUE), + list(1, 3, FALSE, TRUE, TRUE), + list(0, 3, FALSE, FALSE, FALSE), + list(-2, 0, FALSE, FALSE, FALSE), + list(0, 0, TRUE, TRUE, TRUE), + ) + var/list/angles = list(60, 75, 90) + for(var/list/test_case as anything in cases) + var/turf/spot = stealth_at(block, 4 + test_case[1], 4 + test_case[2]) + for(var/i in 1 to 3) + TEST_ASSERT_EQUAL(!!stealth_in_cone(viewer, spot, angles[i]), test_case[2 + i], "Offset ([test_case[1]], [test_case[2]]) at half-angle [angles[i]]") + qdel(block) + +/// The dark helper reads the test lists: a dark-listed turf is dark, a lit-listed one is not. +/datum/unit_test/voidcrew_stealth_dark + +/datum/unit_test/voidcrew_stealth_dark/Run() + var/datum/turf_reservation/block = stealth_block(3, 3) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/turf/lit = stealth_at(block, 0, 0) + var/turf/dark = stealth_at(block, 1, 0) + GLOB.stealth_test_dark_turfs[dark] = TRUE + TEST_ASSERT(!stealth_tile_is_dark(lit), "A lit test turf reads as dark") + TEST_ASSERT(stealth_tile_is_dark(dark), "A turf in the test dark list reads as lit") + GLOB.stealth_test_dark_turfs[dark] = FALSE + qdel(block) + +/// Sight: behind stays unaware, in front goes suspicious then alert, dark at range and off-screen never alert. +/datum/unit_test/voidcrew_stealth_sight + +/datum/unit_test/voidcrew_stealth_sight/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + // Behind, 3 tiles, lit, still. + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 3, 2) + stealth_scans(guard, 10) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard noticed someone standing 3 tiles behind it") + qdel(guard) + // In front, 2 tiles, lit: an alert on the first look (decision 32). + guard = stealth_guard(block, 6, 2) + stealth_ai = stealth_ai(guard) + person.forceMove(stealth_at(block, 8, 2)) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard wasn't alert on someone 2 tiles in front after one scan") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "The alert guard has no target") + qdel(guard) + // In front, 6 tiles, dark. + guard = stealth_guard(block, 6, 2) + stealth_ai = stealth_ai(guard) + var/turf/dark = stealth_at(block, 12, 2) + GLOB.stealth_test_dark_turfs[dark] = TRUE + person.forceMove(dark) + stealth_scans(guard, 10) + GLOB.stealth_test_dark_turfs[dark] = FALSE + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard saw someone 6 tiles off in the dark") + qdel(guard) + // In front, 8 tiles, lit: never alert from off-screen. + guard = stealth_guard(block, 6, 2) + stealth_ai = stealth_ai(guard) + person.forceMove(stealth_at(block, 14, 2)) + for(var/i in 1 to 30) + stealth_ai.stealth_scan_once() + TEST_ASSERT(stealth_ai.stealth_state() != "alert", "A guard went alert on someone 8 tiles off") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "A guard never grew suspicious of someone 8 tiles in front in the light") + qdel(guard) + qdel(block) + +/// Alert: keeps its target all round; loses it behind a wall and searches where it last saw it. +/datum/unit_test/voidcrew_stealth_alert + +/datum/unit_test/voidcrew_stealth_alert/Run() + var/datum/turf_reservation/block = stealth_block(16, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 9, 2) + stealth_ai.stealth_go_alert(person) + person.forceMove(stealth_at(block, 3, 2)) + stealth_scans(guard, 5) + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "An alert guard dropped a target that stepped behind it") + // Behind a wall now. + var/turf/last_seen = stealth_at(block, 9, 2) + person.forceMove(last_seen) + stealth_scans(guard, 1) + for(var/dy in 0 to 4) + var/turf/wall_spot = stealth_at(block, 11, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + person.forceMove(stealth_at(block, 13, 2)) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard gave up on a target the moment it went out of sight") + stealth_ai.stealth_rewind(5 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "searching", "A guard that lost its target isn't searching") + TEST_ASSERT_EQUAL(stealth_ai.last_seen_turf, last_seen, "The search isn't at the last place it saw them") + TEST_ASSERT_NULL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "A searching guard still has a target") + qdel(block) + +/// Hit from out of sight: searches the attacker's turf, wary. Pulled: alert on the puller. The step 3 hook. +/datum/unit_test/voidcrew_stealth_touched + +/datum/unit_test/voidcrew_stealth_touched/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 15, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 1, 2) + SEND_SIGNAL(guard, COMSIG_ATOM_WAS_ATTACKED, person, ATTACKER_DAMAGING_ATTACK) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "searching", "A guard hit from out of sight isn't searching") + TEST_ASSERT_EQUAL(stealth_ai.last_seen_turf, get_turf(person), "The search isn't at the attacker's turf") + TEST_ASSERT(stealth_ai.blackboard["stealth_wary"], "A guard that was hit isn't wary") + qdel(guard) + // Pulled. + guard = stealth_guard(block, 15, 2) + stealth_ai = stealth_ai(guard) + person.forceMove(stealth_at(block, 14, 2)) + person.start_pulling(guard) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A pulled guard isn't alert") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "A pulled guard isn't after the puller") + person.stop_pulling() + qdel(guard) + // The hook: unaware when the blow began, even though the blow made it alert. + guard = stealth_guard(block, 15, 2) + stealth_ai = stealth_ai(guard) + TEST_ASSERT(guard.stealth_was_unaware(), "An unaware guard doesn't read as unaware") + SEND_SIGNAL(guard, COMSIG_ATOM_WAS_ATTACKED, person, ATTACKER_DAMAGING_ATTACK) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard hit by someone beside it isn't alert") + TEST_ASSERT(guard.stealth_was_unaware(), "The hook forgot the guard was unaware in the same tick") + stealth_ai.stealth_rewind(1) + TEST_ASSERT(!guard.stealth_was_unaware(), "The hook still reads unaware after time passed") + var/mob/living/carbon/human/npc/plain = allocate(/mob/living/carbon/human/npc/ruin/trooper/syndicate, stealth_at(block, 3, 2)) + TEST_ASSERT(!plain.stealth_was_unaware(), "An NPC without stealth reads as unaware") + qdel(block) + +/// A fallen friend in view: suspicious once; the same body never sets it off again. +/datum/unit_test/voidcrew_stealth_bodies + +/datum/unit_test/voidcrew_stealth_bodies/Run() + var/datum/turf_reservation/block = stealth_block(12, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + allocate(/obj/effect/landmark/stealth_group, stealth_at(block, 6, 4)) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/mob/living/carbon/human/npc/friend = stealth_guard(block, 5, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = stealth_ai(friend) + stealth_ai.stealth_setup() + friend_ai.stealth_setup() + TEST_ASSERT_EQUAL(stealth_ai.group, friend_ai.group, "Two guards by one marker aren't in one group") + friend.death() + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "A guard didn't react to a dead friend in view") + stealth_ai.stealth_go_unaware() + stealth_ai.next_body_scan = 0 + stealth_scans(guard, 3) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "The same body set a guard off twice") + qdel(block) + +/// Routes: each guard claims only its own group's stops, in order; a guard far from any stop is a sentry. +/// A stop it can't reach is skipped after STEALTH_PATROL_MAX_FAILS failures. +/datum/unit_test/voidcrew_stealth_routes + +/datum/unit_test/voidcrew_stealth_routes/Run() + var/datum/turf_reservation/first = stealth_block(10, 5) + var/datum/turf_reservation/second = stealth_block(10, 5) + TEST_ASSERT(first && second, "No room for the test") + var/list/guards = list() + for(var/datum/turf_reservation/block in list(first, second)) + allocate(/obj/effect/landmark/stealth_group, stealth_at(block, 9, 4)) + // Made out of order, so the group has to sort them. + var/obj/effect/landmark/stealth_patrol/third = allocate(/obj/effect/landmark/stealth_patrol, stealth_at(block, 7, 0)) + third.order = 3 + var/obj/effect/landmark/stealth_patrol/second_stop = allocate(/obj/effect/landmark/stealth_patrol, stealth_at(block, 4, 0)) + second_stop.order = 2 + var/obj/effect/landmark/stealth_patrol/first_stop = allocate(/obj/effect/landmark/stealth_patrol, stealth_at(block, 1, 0)) + first_stop.order = 1 + guards += stealth_guard(block, 1, 0) + var/list/stop_columns = list(1, 4, 7) + for(var/i in 1 to 2) + var/datum/turf_reservation/block = i == 1 ? first : second + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guards[i]) + stealth_ai.stealth_setup() + TEST_ASSERT_EQUAL(stealth_ai.route_id, "a", "Guard [i] didn't claim the route it spawned on") + var/list/stops = stealth_ai.stealth_stops() + TEST_ASSERT_EQUAL(length(stops), 3, "Guard [i]'s route has [length(stops)] stops, not its own group's 3") + for(var/index in 1 to length(stops)) + var/datum/stealth_stop/stop = stops[index] + TEST_ASSERT_EQUAL(stop.order, index, "Guard [i]'s stop [index] is out of order") + TEST_ASSERT_EQUAL(stop.spot, stealth_at(block, stop_columns[index], 0), "Guard [i]'s stop [index] isn't in its own block") + var/mob/living/carbon/human/npc/sentry = stealth_guard(first, 1, 4, SOUTH) + var/datum/ai_controller/basic_controller/human_npc/stealth/sentry_ai = stealth_ai(sentry) + // Four tiles from the nearest stop, beyond STEALTH_ROUTE_CLAIM_RANGE (2). + sentry_ai.stealth_setup() + TEST_ASSERT_NULL(sentry_ai.route_id, "A guard away from every stop claimed a route") + TEST_ASSERT_EQUAL(sentry_ai.sentry_dir, SOUTH, "The sentry doesn't face the way it spawned") + // Unreachable stop. + var/datum/ai_controller/basic_controller/human_npc/stealth/walker = stealth_ai(guards[1]) + walker.route_index = 2 + walker.goto_purpose = "patrol" + for(var/i in 1 to 3) + walker.stealth_walk_failed() + TEST_ASSERT(walker.stop_skip_until["2"] > world.time, "A stop that failed 3 times isn't skipped") + TEST_ASSERT(walker.route_index != 2, "The guard still heads for a skipped stop") + qdel(first) + qdel(second) + +/// A search that ran out while the guard slept ends on waking: unaware, still wary. +/datum/unit_test/voidcrew_stealth_wake + +/datum/unit_test/voidcrew_stealth_wake/Run() + var/datum/turf_reservation/block = stealth_block(5, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_ai.stealth_go_searching(stealth_at(block, 3, 3)) + stealth_ai.stealth_rewind(41 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A search past its time didn't end on waking") + TEST_ASSERT(stealth_ai.blackboard["stealth_wary"], "A guard that searched isn't wary") + qdel(block) + +/// Someone in a locker in front of a guard is unseen; a mech in range is alert at once. +/datum/unit_test/voidcrew_stealth_containers + +/datum/unit_test/voidcrew_stealth_containers/Run() + var/datum/turf_reservation/block = stealth_block(10, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 4, 2) + var/obj/structure/closet/locker = allocate(/obj/structure/closet, stealth_at(block, 4, 2)) + locker.close() + person.forceMove(locker) + stealth_scans(guard, 10) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard saw someone shut in a locker") + person.forceMove(stealth_at(block, 6, 2)) + var/obj/vehicle/sealed/mecha/ripley/mech = allocate(/obj/vehicle/sealed/mecha/ripley, stealth_at(block, 6, 2)) + person.forceMove(mech) + mech.add_occupant(person) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard wasn't alert on a mech in front of it") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], mech, "The guard isn't after the mech") + mech.remove_occupant(person) + person.forceMove(stealth_at(block, 8, 2)) + qdel(block) + +/// Deleting a guard takes it out of its group; with the marker and every guard gone the group goes too. +/datum/unit_test/voidcrew_stealth_cleanup + +/datum/unit_test/voidcrew_stealth_cleanup/Run() + var/datum/turf_reservation/block = stealth_block(6, 4) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/obj/effect/landmark/stealth_group/marker = new(stealth_at(block, 5, 3)) + var/datum/stealth_group/group = marker.group + var/mob/living/carbon/human/npc/guard = new STEALTH_TEST_GUARD(stealth_at(block, 1, 1)) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + stealth_ai.stealth_setup() + TEST_ASSERT_EQUAL(stealth_ai.group, group, "The guard didn't join the marker's group") + qdel(guard) + TEST_ASSERT_EQUAL(length(group.living_members()), 0, "A deleted guard is still in its group") + TEST_ASSERT(group in GLOB.stealth_groups, "A group with its marker standing was removed") + qdel(marker) + TEST_ASSERT(!(group in GLOB.stealth_groups), "A group with no marker and no guards is still registered") + qdel(block) + +/// Its target dead with nobody else about: a short look round, then unaware. Anyone else in view or hurting it +/// keeps the alarm going. +/datum/unit_test/voidcrew_stealth_calm + +/datum/unit_test/voidcrew_stealth_calm/Run() + var/datum/turf_reservation/block = stealth_block(12, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/target = stealth_person(block, 4, 2) + stealth_ai.stealth_go_alert(target) + stealth_scans(guard, 1) + target.death() + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "searching", "A guard that killed its target isn't looking round") + TEST_ASSERT(stealth_ai.calm_until, "A guard that killed its target with nobody about isn't calming down") + TEST_ASSERT_NULL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "A guard still has a dead target") + stealth_ai.stealth_rewind(7 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard didn't calm down after its target died") + TEST_ASSERT(stealth_ai.blackboard["stealth_wary"], "A guard that just fought isn't wary") + qdel(guard) + qdel(target) + // Someone else in plain view: no calming down. + guard = stealth_guard(block, 2, 2) + stealth_ai = stealth_ai(guard) + target = stealth_person(block, 4, 2) + var/mob/living/carbon/human/bystander = stealth_person(block, 5, 3) + stealth_ai.stealth_go_alert(target) + target.death() + stealth_scans(guard, 1) + TEST_ASSERT(stealth_ai.stealth_state() == "suspicious" || stealth_ai.stealth_state() == "alert", "A guard calmed down with someone else in front of it") + TEST_ASSERT(!stealth_ai.calm_until, "A guard is calming down with someone else in front of it") + qdel(guard) + qdel(target) + qdel(bystander) + // Someone behind it hits it during the fight: it turns on them, and not straight back when the first one hits it. + guard = stealth_guard(block, 6, 2) + stealth_ai = stealth_ai(guard) + target = stealth_person(block, 8, 2) + var/mob/living/carbon/human/flanker = stealth_person(block, 3, 2) + stealth_ai.stealth_go_alert(target) + SEND_SIGNAL(guard, COMSIG_ATOM_WAS_ATTACKED, flanker, ATTACKER_DAMAGING_ATTACK) + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], flanker, "A guard didn't turn on someone else who hit it") + SEND_SIGNAL(guard, COMSIG_ATOM_WAS_ATTACKED, target, ATTACKER_DAMAGING_ATTACK) + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], flanker, "A guard hit by two people flapped straight back to the first") + // The one it turned on dies: the other is still there, and remembered. + flanker.death() + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard calmed down while someone else was hurting it") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], target, "The guard didn't go back to whoever else hit it") + qdel(block) + +/// Wary fades after STEALTH_WARY_TIME with nothing new; a notice gain starts the clock again. +/datum/unit_test/voidcrew_stealth_wary_fade + +/datum/unit_test/voidcrew_stealth_wary_fade/Run() + var/datum/turf_reservation/block = stealth_block(12, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_ai.stealth_go_searching(stealth_at(block, 3, 3)) + stealth_ai.stealth_rewind(41 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "The search didn't end") + TEST_ASSERT(stealth_ai.blackboard["stealth_wary"], "A guard that searched isn't wary") + stealth_ai.stealth_rewind(40 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT(stealth_ai.blackboard["stealth_wary"], "Wary faded too soon") + // A glimpse of someone far off starts the clock again. + var/mob/living/carbon/human/person = stealth_person(block, 9, 2) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A glimpse at the edge of sight made the guard suspicious") + qdel(person) + stealth_ai.stealth_rewind(40 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT(stealth_ai.blackboard["stealth_wary"], "A notice gain didn't refresh wary") + stealth_ai.stealth_rewind(30 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT(!stealth_ai.blackboard["stealth_wary"], "Wary didn't fade with nothing new") + TEST_ASSERT(stealth_ai.stealth_half_angle() == 60, "A guard no longer wary still has the wary cone") + // A hit makes it wary again. + var/mob/living/carbon/human/attacker = stealth_person(block, 11, 4) + SEND_SIGNAL(guard, COMSIG_ATOM_WAS_ATTACKED, attacker, ATTACKER_DAMAGING_ATTACK) + TEST_ASSERT(stealth_ai.blackboard["stealth_wary"], "A hit didn't make the guard wary again") + qdel(block) + +/// The mark over a guard's head: notice and state to icon_state (draft D: fills round to nearest, drains round up). +/datum/unit_test/voidcrew_stealth_meter_states + +/datum/unit_test/voidcrew_stealth_meter_states/Run() + // Private "?": yellow to 1.0, then red to 2.5. + TEST_ASSERT_NULL(stealth_meter_notice_state(0), "No notice still shows a mark") + TEST_ASSERT_EQUAL(stealth_meter_notice_state(0.05), "q_y0", "A little notice isn't an empty grey ?") + TEST_ASSERT_EQUAL(stealth_meter_notice_state(0.3), "q_y2", "0.3 notice") + TEST_ASSERT_EQUAL(stealth_meter_notice_state(0.5), "q_y4", "Half notice doesn't round to the nearest row") + TEST_ASSERT_EQUAL(stealth_meter_notice_state(1), "q_y7", "Suspicious isn't a full yellow ?") + TEST_ASSERT_EQUAL(stealth_meter_notice_state(1.75), "q_r4", "Halfway to alert isn't half red") + TEST_ASSERT_EQUAL(stealth_meter_notice_state(2.5), "q_r7", "Alert notice isn't a full red ?") + TEST_ASSERT_EQUAL(stealth_meter_notice_state(4), "q_r7", "Notice past alert overflows the glyph") + // Public marks. Times in deciseconds; now = 10000. + TEST_ASSERT_NULL(stealth_meter_public_state("unaware", 10000, 0, 9000, 0), "An unaware guard has a public mark") + TEST_ASSERT_NULL(stealth_meter_public_state("suspicious", 10000, 0, 9000, 0), "A suspicious guard has a public mark") + TEST_ASSERT_EQUAL(stealth_meter_public_state("alert", 10000, 0, 9000, 0), "ex_r7", "Alert with the target in sight isn't a full red !") + TEST_ASSERT_EQUAL(stealth_meter_public_state("alert", 10000, 9980, 9000, 0), "ex_r4", "Target lost 2 of 4 s: the ! doesn't drain rounding up") + TEST_ASSERT_EQUAL(stealth_meter_public_state("alert", 10000, 9961, 9000, 0), "ex_r1", "The last row of the ! went out early") + TEST_ASSERT_EQUAL(stealth_meter_public_state("alert", 10000, 9960, 9000, 0), "q_y7", "A drained ! doesn't become the yellow ?") + TEST_ASSERT_EQUAL(stealth_meter_public_state("searching", 10000, 0, 10000, 0), "q_y7", "A fresh search isn't a full yellow ?") + TEST_ASSERT_EQUAL(stealth_meter_public_state("searching", 10000, 0, 9800, 0), "q_y4", "Halfway through the 40 s search") + TEST_ASSERT_NULL(stealth_meter_public_state("searching", 10000, 0, 9600, 0), "A finished search still shows") + TEST_ASSERT_EQUAL(stealth_meter_public_state("searching", 10000, 0, 9970, 10030), "q_y4", "Calming down doesn't drain to calm_until") + // The drain steps at each row: the full ! loses its top row after 1/7 of 4 s. + var/step = stealth_meter_next_step("alert", 10000, 10000, 9000, 0) + TEST_ASSERT(step > 40 / 7 && step < 40 / 7 + 1, "The first drain step isn't at 1/7 of the lose time (got [step])") + TEST_ASSERT_EQUAL(stealth_meter_next_step("alert", 10000, 0, 9000, 0), 0, "A steady ! schedules a drain") + +/// The mark goes with its guard: death, deletion, and the public mark hides the private one. +/datum/unit_test/voidcrew_stealth_meter_cleanup + +/datum/unit_test/voidcrew_stealth_meter_cleanup/Run() + var/datum/turf_reservation/block = stealth_block(8, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 4, 2) + stealth_ai.stealth_go_alert(person) + // No client is near in a test, so build it by hand. + stealth_ai.meter = new /datum/stealth_meter(stealth_ai, guard) + var/datum/stealth_meter/meter = stealth_ai.meter + meter.update() + var/obj/effect/abstract/stealth_mark/mark = meter.mark + TEST_ASSERT_NOTNULL(mark, "An alert guard has no mark") + TEST_ASSERT_EQUAL(mark.icon_state, "ex_r7", "An alert guard's mark isn't a full red !") + TEST_ASSERT(mark in guard.vis_contents, "The mark isn't drawn on the guard") + TEST_ASSERT_EQUAL(mark.pixel_z, stealth_meter_offset(guard), "The mark isn't just over a standing guard's head") + TEST_ASSERT(mark.pixel_z > 29, "The mark sits in a standing guard's face") + guard.set_body_position(LYING_DOWN) + TEST_ASSERT_EQUAL(mark.pixel_z, 29, "The mark didn't drop when the guard lay down") + guard.set_body_position(STANDING_UP) + guard.death() + TEST_ASSERT(QDELETED(meter), "A dead guard kept its mark") + TEST_ASSERT(!(mark in guard.vis_contents), "A dead guard still draws its mark") + TEST_ASSERT(QDELETED(mark), "A dead guard's mark wasn't deleted") + // Deletion. + var/mob/living/carbon/human/npc/second = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/second_ai = stealth_ai(second) + second_ai.stealth_go_searching(stealth_at(block, 6, 3)) + second_ai.meter = new /datum/stealth_meter(second_ai, second) + meter = second_ai.meter + meter.update() + mark = meter.mark + TEST_ASSERT_EQUAL(mark?.icon_state, "q_y7", "A searching guard's mark isn't a full yellow ?") + qdel(second) + TEST_ASSERT(QDELETED(meter), "A deleted guard's meter lived on") + TEST_ASSERT(QDELETED(mark), "A deleted guard's mark lived on") + qdel(block) + +/// A stealth guard hit by an ally's stray shot doesn't turn on them or raise the alarm. +/datum/unit_test/voidcrew_stealth_ally_hit + +/datum/unit_test/voidcrew_stealth_ally_hit/Run() + var/datum/turf_reservation/block = stealth_block(6, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/mob/living/carbon/human/npc/ally = stealth_guard(block, 4, 2, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + SEND_SIGNAL(guard, COMSIG_ATOM_WAS_ATTACKED, ally, ATTACKER_DAMAGING_ATTACK) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "An ally's stray shot raised the alarm") + TEST_ASSERT_NULL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "An ally's stray shot made the guard target them") + TEST_ASSERT(!stealth_ai.blackboard["stealth_wary"], "An ally's stray shot made the guard wary") + qdel(block) + +/// The candidate cap counts only those it could perceive: a crowd of its own side at its feet doesn't hide someone further off. +/datum/unit_test/voidcrew_stealth_cap + +/datum/unit_test/voidcrew_stealth_cap/Run() + var/datum/turf_reservation/block = stealth_block(10, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + // More than STEALTH_MAX_CANDIDATES (8) of its own side, all nearer than the person. + for(var/i in 1 to 10) + var/mob/living/basic/mouse/mouse = allocate(/mob/living/basic/mouse, stealth_at(block, 3, 2)) + mouse.faction = list("scav") // FACTION_SCAV + stealth_person(block, 5, 2) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "A crowd of its own side hid someone 3 tiles in front of a guard") + qdel(block) + +/// Notice stops at STEALTH_ALERT_AT (2.5), so someone out of reach can't bank a lead that hides a second person. +/datum/unit_test/voidcrew_stealth_notice_cap + +/datum/unit_test/voidcrew_stealth_notice_cap/Run() + var/datum/turf_reservation/block = stealth_block(20, 7) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 3) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + // Eight tiles off: noticed, never alert (STEALTH_ALERT_MAX_RANGE 7). + var/mob/living/carbon/human/far = stealth_person(block, 14, 3) + stealth_scans(guard, 30) + var/list/entry = stealth_ai.notice_map[REF(far)] + TEST_ASSERT_NOTNULL(entry, "A guard never noticed someone 8 tiles in front of it") + TEST_ASSERT(entry[1] <= 2.5, "Notice climbed past the alert level ([entry[1]])") + // They step out of sight behind it; someone else walks up in front. + far.forceMove(stealth_at(block, 0, 3)) + var/mob/living/carbon/human/near = stealth_person(block, 8, 3) + stealth_scans(guard, 5) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "Someone it could no longer see kept a guard from alerting on the person in front of it") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], near, "The guard isn't after the person in front of it") + qdel(block) + +/// A friend who went down, got up and went down again is news again. +/datum/unit_test/voidcrew_stealth_body_again + +/datum/unit_test/voidcrew_stealth_body_again/Run() + var/datum/turf_reservation/block = stealth_block(12, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + allocate(/obj/effect/landmark/stealth_group, stealth_at(block, 6, 4)) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/mob/living/carbon/human/npc/friend = stealth_guard(block, 5, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = stealth_ai(friend) + stealth_ai.stealth_setup() + friend_ai.stealth_setup() + friend.set_body_position(LYING_DOWN) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "A guard didn't react to a friend on the floor") + stealth_ai.stealth_go_unaware() + friend.set_body_position(STANDING_UP) + stealth_ai.next_body_scan = 0 + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A friend back on its feet set a guard off") + friend.death() + stealth_ai.next_body_scan = 0 + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "A guard ignored a friend killed after getting back up") + qdel(block) + +// ===== The real AI ===== + +/** + * Tests that run the guard's real AI: planning, the scan and real walking, over a few seconds of game time. A + * person on SSmobs' list of players keeps the level awake, as a player there does. Every wait is on game time + * with a long deadline and ends as soon as the thing happens, so a slow machine only makes them slower. + */ +/datum/unit_test/voidcrew_stealth_live + abstract_type = /datum/unit_test/voidcrew_stealth_live + /// The walled room this test runs in + var/datum/turf_reservation/room + /// person => the z-level they were listed on + var/list/players = list() + +/datum/unit_test/voidcrew_stealth_live/Destroy() + for(var/mob/living/person as anything in players) + SSmobs.clients_by_zlevel[players[person]] -= person + players = null + . = ..() + QDEL_NULL(room) + +/// Builds a lit, walled, floored room `width` x `height` inside (walls keep its air in). FALSE if there is no room. +/datum/unit_test/voidcrew_stealth_live/proc/make_room(width, height) + room = SSmapping.request_turf_block_reservation(width + 2, height + 2, 1) + if(isnull(room)) + return FALSE + var/turf/corner = room.bottom_left_turfs[1] + for(var/turf/spot as anything in block(corner.x, corner.y, corner.z, corner.x + width + 1, corner.y + height + 1, corner.z)) + var/edge = spot.x == corner.x || spot.y == corner.y || spot.x == corner.x + width + 1 || spot.y == corner.y + height + 1 + spot.ChangeTurf(edge ? /turf/closed/wall : /turf/open/floor/iron) + GLOB.stealth_test_dark_turfs[spot] = FALSE + return TRUE + +/// The floor (dx, dy) from the room's inside corner. +/datum/unit_test/voidcrew_stealth_live/proc/at(dx, dy) + var/turf/corner = room.bottom_left_turfs[1] + return locate(corner.x + 1 + dx, corner.y + 1 + dy, corner.z) + +/datum/unit_test/voidcrew_stealth_live/proc/guard_at(dx, dy, facing = EAST) + var/mob/living/carbon/human/npc/guard = allocate(STEALTH_TEST_GUARD, at(dx, dy)) + guard.setDir(facing) + guard.AddElement(/datum/element/forced_gravity, 1) + return guard + +/// A walking person the guards can't hurt (the tests are about what the guards do, not how the fight goes). +/// `listed` puts them on SSmobs' list of players. +/datum/unit_test/voidcrew_stealth_live/proc/person_at(dx, dy, listed = TRUE) + var/mob/living/carbon/human/consistent/person = allocate(/mob/living/carbon/human/consistent, at(dx, dy)) + if(person.move_intent == MOVE_INTENT_RUN) + person.toggle_move_intent() + person.AddElement(/datum/element/forced_gravity, 1) + person.physiology.brute_mod = 0 + person.physiology.burn_mod = 0 + person.physiology.stamina_mod = 0 + if(listed) + var/turf/where = get_turf(person) + SSmobs.clients_by_zlevel[where.z] += person + players[person] = where.z + return person + +/// Switches a guard's AI on, as someone arriving on its level does. +/datum/unit_test/voidcrew_stealth_live/proc/wake(mob/living/guard) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + stealth_ai.reset_ai_status() + return stealth_ai + +/// A stop on route "a". +/datum/unit_test/voidcrew_stealth_live/proc/stop_at(dx, dy, order, wait = 5) + var/obj/effect/landmark/stealth_patrol/stop = allocate(/obj/effect/landmark/stealth_patrol, at(dx, dy)) + stop.order = order + stop.wait = wait + return stop + +/// A route leg longer than tg's 14-tile walk limit, with the only player far off behind a wall: it gets there. +/datum/unit_test/voidcrew_stealth_live/patrol + +/datum/unit_test/voidcrew_stealth_live/patrol/Run() + TEST_ASSERT(make_room(40, 5), "No room for the test") + allocate(/obj/effect/landmark/stealth_group, at(0, 4)) + stop_at(1, 2, 1) + stop_at(26, 2, 2) + // A wall between the far stop and the player, who is 37 tiles from the guard: past tg's idle radius. + for(var/dy in 0 to 4) + var/turf/wall_spot = at(32, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + person_at(38, 2) + var/mob/living/carbon/human/npc/guard = guard_at(1, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + TEST_ASSERT_EQUAL(stealth_ai.ai_status, AI_STATUS_ON, "A guard with a player far off on its level isn't fully awake") + var/turf/far_stop = at(26, 2) + var/deadline = world.time + 90 SECONDS + while(get_turf(guard) != far_stop && world.time < deadline) + sleep(2) + TEST_ASSERT_EQUAL(stealth_ai.route_id, "a", "The guard never claimed its route") + TEST_ASSERT_EQUAL(get_turf(guard), far_stop, "A guard didn't finish a 25-tile route leg (it is [get_dist(guard, far_stop)] tiles short)") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A patrolling guard with nobody in sight isn't unaware") + // And back: the route goes on. + var/turf/near_stop = at(1, 2) + deadline = world.time + 90 SECONDS + while(get_turf(guard) != near_stop && world.time < deadline) + sleep(2) + TEST_ASSERT_EQUAL(get_turf(guard), near_stop, "A guard didn't walk back along its route") + TEST_ASSERT_NOTNULL(stealth_ai.route_id, "A guard gave up its route") + +/// Left far from its route by a chase, a guard walks back to it; a sentry walks back to its post. +/datum/unit_test/voidcrew_stealth_live/walk_home + +/datum/unit_test/voidcrew_stealth_live/walk_home/Run() + TEST_ASSERT(make_room(52, 5), "No room for the test") + allocate(/obj/effect/landmark/stealth_group, at(0, 2)) + stop_at(1, 0, 1, 50) + stop_at(4, 0, 2, 50) + for(var/dy in 0 to 4) + var/turf/wall_spot = at(49, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + person_at(50, 2) + var/mob/living/carbon/human/npc/walker = guard_at(1, 0) + // Four tiles from the nearest stop: past STEALTH_ROUTE_CLAIM_RANGE (2), so a sentry. + var/mob/living/carbon/human/npc/sentry = guard_at(1, 4, SOUTH) + var/datum/ai_controller/basic_controller/human_npc/stealth/walker_ai = wake(walker) + var/datum/ai_controller/basic_controller/human_npc/stealth/sentry_ai = wake(sentry) + walker_ai.stealth_setup() + sentry_ai.stealth_setup() + TEST_ASSERT_EQUAL(walker_ai.route_id, "a", "The guard on the route didn't claim it") + TEST_ASSERT_NULL(sentry_ai.route_id, "The guard off the route claimed it") + var/turf/post = at(1, 4) + // Where a long chase ends: 43 tiles from the route. Further than STEALTH_LEASH_RANGE (24), and than one walk + // (STEALTH_WALK_LEG 40), so the way back is in two legs. + walker.forceMove(at(47, 0)) + sentry.forceMove(at(47, 4)) + walker_ai.stealth_go_searching(at(47, 0)) + sentry_ai.stealth_go_searching(at(47, 4)) + walker_ai.stealth_rewind(41 SECONDS) + sentry_ai.stealth_rewind(41 SECONDS) + var/deadline = world.time + 120 SECONDS + while(world.time < deadline && !(get_turf(sentry) == post && walker_ai.at_stop)) + sleep(2) + TEST_ASSERT_EQUAL(walker_ai.route_id, "a", "A guard left far from its route became a sentry") + TEST_ASSERT(walker_ai.at_stop, "A guard left far from its route never got back to a stop (it is at [walker.x - at(0, 0).x], [walker.y - at(0, 0).y])") + TEST_ASSERT(get_dist(walker, at(4, 0)) <= 3, "The guard is at a stop that isn't on its route") + TEST_ASSERT_EQUAL(get_turf(sentry), post, "A sentry left far from its post didn't walk back (it is [get_dist(sentry, post)] tiles off)") + TEST_ASSERT_EQUAL(sentry_ai.home_turf, post, "A sentry's post moved") + +/// Searching, it goes straight to alert on someone it glimpses, never down to suspicious. +/datum/unit_test/voidcrew_stealth_live/search_to_alert + +/datum/unit_test/voidcrew_stealth_live/search_to_alert/Run() + TEST_ASSERT(make_room(14, 5), "No room for the test") + var/mob/living/carbon/human/npc/guard = guard_at(3, 2) + var/mob/living/carbon/human/person = person_at(12, 0) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + stealth_ai.stealth_go_searching(at(3, 2)) + // Three tiles in front of it: one scan's worth of notice is past suspicious but short of alert. + person.forceMove(at(6, 2)) + var/went_suspicious = FALSE + var/deadline = world.time + 20 SECONDS + while(stealth_ai.stealth_state() != "alert" && world.time < deadline) + if(stealth_ai.stealth_state() == "suspicious") + went_suspicious = TRUE + sleep(1) + TEST_ASSERT(!went_suspicious, "A searching guard that glimpsed someone dropped to suspicious") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A searching guard didn't go alert on someone three tiles in front of it") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "The guard isn't after the person it glimpsed") + +/// Alert on a decoy it can't reach, it still notices someone nearer and turns on them; it doesn't flap back. +/datum/unit_test/voidcrew_stealth_live/switch_target + +/datum/unit_test/voidcrew_stealth_live/switch_target/Run() + TEST_ASSERT(make_room(14, 5), "No room for the test") + // A glass wall: the decoy beyond it is in plain sight and out of reach. + for(var/dy in 0 to 4) + allocate(/obj/structure/window/reinforced/fulltile, at(8, dy)) + var/mob/living/carbon/human/npc/guard = guard_at(3, 2) + var/mob/living/carbon/human/decoy = person_at(11, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + stealth_ai.stealth_go_alert(decoy) + sleep(3 SECONDS) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard gave up on someone standing in plain sight behind glass") + // tg drops the target key each time the walk at the glass fails; the next scan takes it back. Its focus stays. + TEST_ASSERT_EQUAL(stealth_ai.blackboard["stealth_focus"], decoy, "A guard forgot the person behind the glass") + // Someone else beside it, on its side of the glass. + var/mob/living/carbon/human/intruder = person_at(1, 2, FALSE) + intruder.forceMove(get_step(guard, WEST) || at(1, 2)) + var/deadline = world.time + 30 SECONDS + while(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET] != intruder && world.time < deadline) + // Kept at its shoulder, wherever it has got to. + if(get_dist(intruder, guard) > 1) + var/turf/beside = get_step(guard, WEST) + if(beside && !beside.is_blocked_turf()) + intruder.forceMove(beside) + sleep(2) + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], intruder, "A guard busy with a decoy never turned on someone at its shoulder") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard that changed target isn't alert") + // The decoy hits it at once: too soon to turn back (STEALTH_SWITCH_COOLDOWN 4 s), and the decoy is no nearer. + SEND_SIGNAL(guard, COMSIG_ATOM_WAS_ATTACKED, decoy, ATTACKER_DAMAGING_ATTACK) + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], intruder, "A guard flapped back to its old target the moment it was hit") + var/flapped = FALSE + deadline = world.time + 3 SECONDS + while(world.time < deadline) + if(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET] == decoy) + flapped = TRUE + sleep(2) + TEST_ASSERT(!flapped, "A guard flapped back to the decoy while someone stood nearer") + // Later, a hit from the decoy does turn it. + stealth_ai.stealth_rewind(5 SECONDS) + SEND_SIGNAL(guard, COMSIG_ATOM_WAS_ATTACKED, decoy, ATTACKER_DAMAGING_ATTACK) + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], decoy, "A guard didn't turn on someone who hit it once the cooldown had passed") + +/// Someone in a cardboard box: unseen while it sits still, noticed when it moves at the guard's shoulder, found when it bumps it. +/datum/unit_test/voidcrew_stealth_live/box + +/datum/unit_test/voidcrew_stealth_live/box/Run() + TEST_ASSERT(make_room(16, 7), "No room for the test") + person_at(15, 6) + var/mob/living/carbon/human/npc/guard = guard_at(3, 3, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + var/mob/living/carbon/human/stowaway = person_at(6, 3, FALSE) + var/obj/structure/closet/cardboard/box = allocate(/obj/structure/closet/cardboard, at(6, 3)) + stowaway.forceMove(box) + // Still, three tiles behind it, then still at two. + sleep(3 SECONDS) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard noticed a box that never moved") + TEST_ASSERT(LAZYACCESS(stealth_ai.hidden_spots, REF(stowaway)), "The guard's scan never found the person in the box (the test can't tell hidden from missing)") + // It shuffles about within two tiles. + var/list/spots = list(at(5, 3), at(5, 4), at(5, 3), at(5, 2)) + var/spot_index = 0 + var/deadline = world.time + 30 SECONDS + while(stealth_ai.stealth_state() == "unaware" && world.time < deadline) + spot_index = (spot_index % length(spots)) + 1 + box.forceMove(spots[spot_index]) + sleep(1.2 SECONDS) + TEST_ASSERT(stealth_ai.stealth_state() != "unaware", "A guard ignored a box shuffling about at its shoulder") + // A second guard, and a box that walks into it. + var/mob/living/carbon/human/npc/second = guard_at(12, 1, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/second_ai = wake(second) + second_ai.stealth_setup() + var/mob/living/carbon/human/second_person = person_at(14, 1, FALSE) + var/obj/structure/closet/cardboard/second_box = allocate(/obj/structure/closet/cardboard, at(13, 1)) + second_person.forceMove(second_box) + step(second_box, WEST) + TEST_ASSERT_EQUAL(second_ai.stealth_state(), "alert", "A box that walked into a guard wasn't found out") + TEST_ASSERT_EQUAL(second_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], second_person, "The guard isn't after whoever is in the box") + +/// A blast with nobody to blame: the guard it hits and the friend near it both go looking there. A hit with a name doesn't rouse the friend. +/datum/unit_test/voidcrew_stealth_live/blast + +/datum/unit_test/voidcrew_stealth_live/blast/Run() + TEST_ASSERT(make_room(30, 5), "No room for the test") + allocate(/obj/effect/landmark/stealth_group, at(0, 4)) + for(var/dy in 0 to 4) + var/turf/wall_spot = at(20, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + var/mob/living/carbon/human/person = person_at(25, 2) + var/mob/living/carbon/human/npc/struck = guard_at(3, 2, WEST) + var/mob/living/carbon/human/npc/friend = guard_at(8, 2, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/struck_ai = wake(struck) + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = wake(friend) + sleep(2 SECONDS) + TEST_ASSERT_EQUAL(struck_ai.group, friend_ai.group, "Two guards by one marker aren't in one group") + TEST_ASSERT_EQUAL(friend_ai.stealth_state(), "unaware", "A guard with nothing going on isn't unaware") + // A named hit first: the friend, facing away, hears nothing of it. + SEND_SIGNAL(struck, COMSIG_ATOM_WAS_ATTACKED, person, ATTACKER_DAMAGING_ATTACK) + struck.Stun(0.5 SECONDS) + sleep(1 SECONDS) + TEST_ASSERT_EQUAL(struck_ai.stealth_state(), "searching", "A guard hit from out of sight isn't searching") + TEST_ASSERT_EQUAL(friend_ai.stealth_state(), "unaware", "A hit with a name on it roused the guard's friend") + // Now a blast. + struck_ai.stealth_go_unaware() + struck_ai.stealth_clear_wary() + struck_ai.stealth_rewind(30 SECONDS) + var/turf/where_hit = get_turf(struck) + EX_ACT(struck, EXPLODE_LIGHT) + var/deadline = world.time + 5 SECONDS + while(friend_ai.stealth_state() != "searching" && world.time < deadline) + sleep(1) + TEST_ASSERT_EQUAL(friend_ai.stealth_state(), "searching", "A blast on a guard didn't send its friend looking") + TEST_ASSERT_EQUAL(friend_ai.last_seen_turf, where_hit, "The friend isn't looking where the blast was") + TEST_ASSERT(friend_ai.blackboard["stealth_wary"], "The friend isn't wary after the blast") + TEST_ASSERT(struck_ai.blackboard["stealth_wary"], "A guard caught in a blast isn't wary") + TEST_ASSERT(struck.stat != CONSCIOUS || struck_ai.stealth_state() == "searching", "A guard caught in a blast went back to its post") + +/// The mark over an alert guard's head goes when it is cuffed, and stays gone while it is. +/datum/unit_test/voidcrew_stealth_live/cuffed_mark + +/datum/unit_test/voidcrew_stealth_live/cuffed_mark/Run() + TEST_ASSERT(make_room(10, 5), "No room for the test") + var/mob/living/carbon/human/npc/guard = guard_at(3, 2) + var/mob/living/carbon/human/person = person_at(5, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + stealth_ai.stealth_go_alert(person) + var/deadline = world.time + 10 SECONDS + while(isnull(stealth_ai.meter?.mark) && world.time < deadline) + sleep(1) + TEST_ASSERT_NOTNULL(stealth_ai.meter?.mark, "An alert guard with someone beside it has no mark") + var/obj/effect/abstract/stealth_mark/mark = stealth_ai.meter.mark + TEST_ASSERT(mark in guard.vis_contents, "The mark isn't drawn on the guard") + guard.set_handcuffed(new /obj/item/restraints/handcuffs(guard)) + guard.update_handcuffed() + TEST_ASSERT(HAS_TRAIT(guard, TRAIT_RESTRAINED), "The cuffs didn't go on") + deadline = world.time + 5 SECONDS + while(!isnull(stealth_ai.meter) && world.time < deadline) + sleep(1) + TEST_ASSERT_NULL(stealth_ai.meter, "A cuffed guard kept its mark") + TEST_ASSERT(!(mark in guard.vis_contents), "A cuffed guard still draws its mark") + // Hitting it while it is cuffed doesn't bring the mark back. + SEND_SIGNAL(guard, COMSIG_ATOM_WAS_ATTACKED, person, ATTACKER_DAMAGING_ATTACK) + var/came_back = FALSE + deadline = world.time + 3 SECONDS + while(world.time < deadline) + if(stealth_ai.meter) + came_back = TRUE + sleep(1) + TEST_ASSERT(!came_back, "A mark came back over a cuffed guard") + +#undef STEALTH_TEST_GUARD diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_closet.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_closet.dm new file mode 100644 index 00000000000..44e2d0e6d90 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_closet.dm @@ -0,0 +1,164 @@ +// Stealth guards, owner decision 33 (voidcrew/modules/stealth/stealth_closet.dm): a guard that saw its target get into +// a locker opens it; one that didn't leaves it shut. Values from voidcrew/_DEFINES are written out: +// STEALTH_LOSE_TARGET_TIME 4 s, STEALTH_CLOSET_SEEN_WINDOW 1.5 s. States are written as text. + +/// Claims, with the AI off: the locker it sees someone in when it goes alert; dropped when they get out, when it is +/// deleted, and when the guard stops being alert. +/datum/unit_test/voidcrew_stealth_closet_claim + +/datum/unit_test/voidcrew_stealth_closet_claim/Run() + var/datum/turf_reservation/block = stealth_block(8, 3) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 1, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 5, 1) + var/obj/structure/closet/locker = allocate(/obj/structure/closet, stealth_at(block, 4, 1)) + person.forceMove(locker) + stealth_ai.stealth_go_alert(person) + TEST_ASSERT_EQUAL(stealth_ai.shut_in, locker, "A guard alerted on someone in a locker in plain view didn't claim it") + // Out of it: the claim goes. + person.forceMove(stealth_at(block, 5, 1)) + TEST_ASSERT_NULL(stealth_ai.stealth_closet_check(person), "A claim held after its target got out") + TEST_ASSERT_NULL(stealth_ai.shut_in, "A guard kept a locker its target had left") + // Back in, then the locker is destroyed. + person.forceMove(locker) + stealth_ai.stealth_go_alert(person) + TEST_ASSERT_EQUAL(stealth_ai.shut_in, locker, "A guard didn't claim the locker the second time") + // Broken up: tg tips out whoever is inside, then deletes it (a bare qdel would delete them too). + locker.deconstruct(FALSE) + TEST_ASSERT(QDELETED(locker), "The locker wasn't deleted") + TEST_ASSERT_NULL(stealth_ai.shut_in, "A guard kept a deleted locker") + // A new one, and the guard calms down. + var/obj/structure/closet/second = allocate(/obj/structure/closet, stealth_at(block, 4, 1)) + person.forceMove(second) + stealth_ai.stealth_go_alert(person) + TEST_ASSERT_EQUAL(stealth_ai.shut_in, second, "A guard didn't claim the second locker") + stealth_ai.stealth_go_searching(stealth_at(block, 4, 1)) + TEST_ASSERT_NULL(stealth_ai.shut_in, "A guard that stopped being alert kept its locker") + +/// Real AI: alert on someone who walks into an open locker and pulls the door shut in front of it, it opens the locker. +/datum/unit_test/voidcrew_stealth_live/closet_seen + +/datum/unit_test/voidcrew_stealth_live/closet_seen/Run() + TEST_ASSERT(make_room(12, 5), "No room for the test") + var/mob/living/carbon/human/npc/guard = guard_at(2, 2, EAST) + var/mob/living/carbon/human/person = person_at(6, 2) + var/obj/structure/closet/locker = allocate(/obj/structure/closet, at(7, 2)) + locker.open() + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + stealth_ai.stealth_go_alert(person) + step(person, EAST) + TEST_ASSERT_EQUAL(get_turf(person), at(7, 2), "The person couldn't step into the open locker") + TEST_ASSERT(locker.close(person), "The person couldn't shut the locker on themselves") + TEST_ASSERT_EQUAL(person.loc, locker, "The person isn't in the locker") + var/start_integrity = locker.get_integrity() + var/deadline = world.time + 30 SECONDS + while(!locker.opened && world.time < deadline) + sleep(2) + TEST_ASSERT(locker.opened, "A guard that saw someone shut themselves in a locker never opened it (claim: [stealth_ai.shut_in ? "yes" : "no"], state [stealth_ai.stealth_state()])") + TEST_ASSERT(get_dist(guard, locker) <= 1, "The locker opened with the guard [get_dist(guard, locker)] tiles away") + TEST_ASSERT_EQUAL(locker.get_integrity(), start_integrity, "A guard hit a locker it could just open") + TEST_ASSERT(isturf(person.loc), "The person is still shut in after the locker opened") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "The guard isn't alert on whoever was in the locker") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "The guard isn't after whoever was in the locker") + +/// Real AI: alert on someone who got into a locker behind a wall, it can see the locker once the wall is gone, but +/// leaves it shut: it loses them, searches, and never hits or opens it. +/datum/unit_test/voidcrew_stealth_live/closet_unseen + +/datum/unit_test/voidcrew_stealth_live/closet_unseen/Run() + TEST_ASSERT(make_room(12, 5), "No room for the test") + for(var/dy in 0 to 4) + var/turf/wall_spot = at(6, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + var/mob/living/carbon/human/npc/guard = guard_at(2, 2, EAST) + var/mob/living/carbon/human/person = person_at(9, 2) + var/obj/structure/closet/locker = allocate(/obj/structure/closet, at(9, 2)) + person.forceMove(locker) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + stealth_ai.stealth_go_alert(person) + TEST_ASSERT_NULL(stealth_ai.shut_in, "A guard claimed a locker behind a wall") + for(var/dy in 0 to 4) + var/turf/gap = at(6, dy) + gap.ChangeTurf(/turf/open/floor/iron) + GLOB.stealth_test_dark_turfs[gap] = FALSE + var/start_integrity = locker.get_integrity() + var/deadline = world.time + 15 SECONDS + while(stealth_ai.stealth_state() == "alert" && world.time < deadline) + sleep(2) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "searching", "A guard whose target hid unseen didn't lose them") + sleep(6 SECONDS) + TEST_ASSERT(!locker.opened, "A guard opened a locker it never saw anyone get into") + TEST_ASSERT_EQUAL(person.loc, locker, "The person was taken out of the locker") + TEST_ASSERT_EQUAL(locker.get_integrity(), start_integrity, "A guard hit a locker it never saw anyone get into") + TEST_ASSERT_NULL(stealth_ai.shut_in, "A searching guard claimed a locker") + +/// Real AI: a gunner that saw someone shut in a locker that is then locked tries it, steps back two tiles and shoots it +/// open (tg never fires at a thing beside you), never from range. +/datum/unit_test/voidcrew_stealth_live/closet_locked + +/datum/unit_test/voidcrew_stealth_live/closet_locked/Run() + TEST_ASSERT(make_room(12, 5), "No room for the test") + var/mob/living/carbon/human/npc/guard = allocate(/mob/living/carbon/human/npc/ruin/trooper/scav/gunner, at(2, 2)) + guard.setDir(EAST) + guard.AddElement(/datum/element/forced_gravity, 1) + var/mob/living/carbon/human/person = person_at(6, 2) + var/obj/structure/closet/secure_closet/locker = allocate(/obj/structure/closet/secure_closet, at(7, 2)) + locker.locked = FALSE + locker.open() + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + stealth_ai.stealth_go_alert(person) + step(person, EAST) + TEST_ASSERT(locker.close(person), "The person couldn't shut the locker on themselves") + locker.locked = TRUE + locker.update_appearance() + // Near breaking, so the test takes a couple of shots, not a magazine. + locker.update_integrity(locker.max_integrity * locker.integrity_failure + 25) + var/start_integrity = locker.get_integrity() + var/first_hit_dist + var/deadline = world.time + 40 SECONDS + while(!locker.opened && world.time < deadline) + if(isnull(first_hit_dist) && locker.get_integrity() < start_integrity) + first_hit_dist = get_dist(guard, locker) + sleep(1) + TEST_ASSERT(locker.opened, "A gunner never broke open a locked locker it saw someone get into (claim: [stealth_ai.shut_in ? "yes" : "no"], integrity [locker.get_integrity()]/[start_integrity])") + TEST_ASSERT_NOTNULL(first_hit_dist, "The locked locker opened without being hit") + TEST_ASSERT(first_hit_dist <= 2, "A gunner shot a locker from [first_hit_dist] tiles away") + TEST_ASSERT(isturf(person.loc), "The person is still shut in after the locker broke") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "The gunner isn't after whoever was in the locker") + +/// Real AI: two guards saw it; only one opens the locker, the other covers it. +/datum/unit_test/voidcrew_stealth_live/closet_two_guards + +/datum/unit_test/voidcrew_stealth_live/closet_two_guards/Run() + TEST_ASSERT(make_room(12, 5), "No room for the test") + allocate(/obj/effect/landmark/stealth_group, at(0, 4)) + var/mob/living/carbon/human/npc/first = guard_at(2, 1, EAST) + var/mob/living/carbon/human/npc/second = guard_at(2, 3, EAST) + var/mob/living/carbon/human/person = person_at(6, 2) + var/obj/structure/closet/locker = allocate(/obj/structure/closet, at(7, 2)) + locker.open() + var/datum/ai_controller/basic_controller/human_npc/stealth/first_ai = wake(first) + var/datum/ai_controller/basic_controller/human_npc/stealth/second_ai = wake(second) + first_ai.stealth_setup() + second_ai.stealth_setup() + TEST_ASSERT_NOTNULL(first_ai.group, "The guards have no group") + TEST_ASSERT_EQUAL(first_ai.group, second_ai.group, "The guards aren't in one group") + first_ai.stealth_go_alert(person) + second_ai.stealth_go_alert(person) + step(person, EAST) + TEST_ASSERT(locker.close(person), "The person couldn't shut the locker on themselves") + var/datum/ai_behavior/opening = GET_AI_BEHAVIOR(/datum/ai_behavior/stealth_open_closet) + var/list/openers = list() + var/both_claimed = FALSE + var/deadline = world.time + 30 SECONDS + while(!locker.opened && world.time < deadline) + if(first_ai.shut_in == locker && second_ai.shut_in == locker) + both_claimed = TRUE + for(var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai as anything in list(first_ai, second_ai)) + if(opening in guard_ai.current_behaviors) + openers |= guard_ai + sleep(1) + TEST_ASSERT(locker.opened, "Two guards that saw someone shut in a locker never opened it") + TEST_ASSERT(both_claimed, "The two guards never both went after the locker (the test can't tell one opener from one watcher)") + TEST_ASSERT_EQUAL(length(openers), 1, "[length(openers)] guards tried to open one locker") diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_crits.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_crits.dm new file mode 100644 index 00000000000..499b6ca0450 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_crits.dm @@ -0,0 +1,105 @@ +// Stealth crits and lootable seclites (step 3a, voidcrew/modules/stealth/stealth_crits.dm, stealth_light.dm). The head +// shot and the backstab are decision 45 (voidcrew_stealth_d45.dm). Values from voidcrew/_DEFINES are written out: +// STEALTH_CRIT_UNAWARE_BONUS 30, STEALTH_CRIT_SUSPICIOUS_BONUS 15, STEALTH_CRIT_HEAD_BONUS 35. + +/// The bonus by state: full when unaware, smaller when suspicious, none when searching or alert, more on the head; +/// never on a player or an NPC without the stealth controller. +/datum/unit_test/voidcrew_stealth_crit_bonus + +/datum/unit_test/voidcrew_stealth_crit_bonus/Run() + var/datum/turf_reservation/block = stealth_block(8, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 4, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 5, 2) + var/obj/item/knife/combat/knife = allocate(/obj/item/knife/combat) + person.put_in_active_hand(knife) + var/obj/item/bodypart/head = guard.get_bodypart(BODY_ZONE_HEAD) + var/obj/item/bodypart/chest = guard.get_bodypart(BODY_ZONE_CHEST) + TEST_ASSERT_EQUAL(guard.stealth_crit_bonus(person, knife, chest), 30, "Wrong bonus on an unaware guard") + TEST_ASSERT_EQUAL(guard.stealth_crit_bonus(person, knife, head), 65, "Wrong bonus on an unaware guard's head") + TEST_ASSERT_EQUAL(guard.hv_crit_situation_bonus(person, knife, head), 65, "The crit roll doesn't get the stealth bonus") + stealth_ai.stealth_go_suspicious(stealth_at(block, 1, 2)) + TEST_ASSERT_EQUAL(guard.stealth_crit_bonus(person, knife, chest), 30, "A guard that turned suspicious this tick lost the unaware bonus") + stealth_ai.stealth_rewind(1) + TEST_ASSERT_EQUAL(guard.stealth_crit_bonus(person, knife, chest), 15, "Wrong bonus on a suspicious guard") + TEST_ASSERT_EQUAL(guard.stealth_crit_bonus(person, knife, head), 50, "Wrong bonus on a suspicious guard's head") + // The blow that alerts it still counts as one on a suspicious guard (a bullet's prehit alerts it first). + stealth_ai.stealth_go_alert(person) + TEST_ASSERT_EQUAL(guard.stealth_crit_bonus(person, knife, chest), 15, "The blow that alerted a suspicious guard lost its bonus") + stealth_ai.stealth_rewind(1) + TEST_ASSERT_EQUAL(guard.stealth_crit_bonus(person, knife, head), 0, "An alert guard gives a stealth bonus") + stealth_ai.stealth_go_searching(stealth_at(block, 1, 2)) + stealth_ai.stealth_rewind(1) + TEST_ASSERT_EQUAL(guard.stealth_crit_bonus(person, knife, head), 0, "A searching guard gives a stealth bonus") + // Unaware, but down or held: the helpless bonus is the one that counts there. + stealth_ai.stealth_go_unaware() + stealth_ai.stealth_rewind(1) + TEST_ASSERT_EQUAL(guard.stealth_crit_bonus(person, knife, chest), 30, "Back to unaware, no bonus") + var/obj/item/restraints/handcuffs/cuffs = allocate(/obj/item/restraints/handcuffs) + TEST_ASSERT(guard.equip_to_slot_if_possible(cuffs, ITEM_SLOT_HANDCUFFED), "Test fixture: the guard can't be cuffed") + TEST_ASSERT_EQUAL(guard.stealth_crit_bonus(person, knife, chest), 0, "A cuffed guard gives a stealth bonus") + // Never on a player, nor on an NPC without the stealth controller. + var/mob/living/carbon/human/player = stealth_person(block, 2, 4) + TEST_ASSERT_EQUAL(player.hv_crit_situation_bonus(person, knife, player.get_bodypart(BODY_ZONE_HEAD)), 0, "A person gets a stealth bonus") + var/mob/living/carbon/human/npc/plain = allocate(/mob/living/carbon/human/npc/ruin/trooper/syndicate, stealth_at(block, 1, 4)) + TEST_ASSERT_EQUAL(plain.stealth_crit_bonus(person, knife, plain.get_bodypart(BODY_ZONE_HEAD)), 0, "An NPC without stealth gets a stealth bonus") + qdel(block) + +/// Wound armour scales the bonus with the rest of the roll. +/datum/unit_test/voidcrew_stealth_crit_armour + +/datum/unit_test/voidcrew_stealth_crit_armour/Run() + var/datum/turf_reservation/block = stealth_block(8, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 4, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 6, 2) + var/obj/item/knife/combat/knife = allocate(/obj/item/knife/combat) + person.put_in_active_hand(knife) + var/obj/item/bodypart/head = guard.get_bodypart(BODY_ZONE_HEAD) + if(guard.head) + qdel(guard.head) + // 1 damage makes tg's own roll 1, so the rest of the roll is exact. + var/bare = head.hv_crit_roll(WOUND_SLASH, 1, 0, 0, person, knife) + TEST_ASSERT(bare > 55, "An unaware bare head rolled only [bare]") + var/obj/item/clothing/head/helmet/swat/helmet = new(guard) + TEST_ASSERT(guard.equip_to_slot_if_possible(helmet, ITEM_SLOT_HEAD, disable_warning = TRUE), "Couldn't put a helmet on the guard") + var/armoured = head.hv_crit_roll(WOUND_SLASH, 1, 0, 0, person, knife) + TEST_ASSERT(armoured < bare, "A helmet didn't lower the stealth roll ([armoured] vs [bare])") + qdel(helmet) + // Alert: no stealth bonus. + stealth_ai.stealth_go_alert(person) + stealth_ai.stealth_rewind(1) + var/roll = head.hv_crit_roll(WOUND_SLASH, 1, 0, 0, person, knife) + TEST_ASSERT(roll < 5, "An alert guard's roll still has a bonus ([roll])") + qdel(block) + +/// Decision 34: the seclite strips and drops like anyone's; the rest of the kit stays locked; the guard carries on without it. +/datum/unit_test/voidcrew_stealth_seclite_loot + +/datum/unit_test/voidcrew_stealth_seclite_loot/Run() + var/datum/turf_reservation/block = stealth_block(8, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 4, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/obj/item/flashlight/light = stealth_ai.stealth_light() + TEST_ASSERT_NOTNULL(light, "A scav guard has no flashlight") + TEST_ASSERT(!HAS_TRAIT(light, TRAIT_NO_STRIP), "The seclite can't be stripped") + TEST_ASSERT(!human_npc_gear_locked(light), "The seclite is locked gear") + TEST_ASSERT(human_npc_gear_locked(guard.shoes), "The rest of the guard's kit isn't locked any more") + var/mob/living/carbon/human/person = stealth_person(block, 3, 2) + TEST_ASSERT(guard.dropItemToGround(light), "The seclite can't be taken off") + TEST_ASSERT(person.put_in_hands(light), "The seclite can't be picked up") + TEST_ASSERT(!QDELETED(light), "The looted seclite was deleted") + // The guard goes without: no light to switch, and it still scans and sees. + TEST_ASSERT_NULL(stealth_ai.stealth_light(), "The guard still counts the light it lost") + GLOB.stealth_test_dark_turfs[get_turf(guard)] = TRUE + stealth_ai.stealth_update_light() + TEST_ASSERT(!stealth_ai.stealth_light_shows(), "The guard lights a pool with a light a player holds") + TEST_ASSERT(!light.light_on, "The guard switched on a light a player holds") + GLOB.stealth_test_dark_turfs[get_turf(guard)] = FALSE + person.forceMove(stealth_at(block, 5, 2)) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard without its light didn't see someone in front of it") + qdel(block) diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_d32.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_d32.dm new file mode 100644 index 00000000000..1fb57b7c342 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_d32.dm @@ -0,0 +1,236 @@ +// Stealth guards, owner decision 32 (voidcrew/modules/stealth/): point-blank sight, behind in the dark, the overdue +// line over a body already reported, guards' lights ignoring each other, and a running guard's pace. Values from +// voidcrew/_DEFINES are written out: STEALTH_POINT_BLANK_RANGE 2, STEALTH_NEAR_RANGE 4, STEALTH_NEAR_MULT 3, +// STEALTH_ALERT_AT 2.5, STEALTH_LIGHT_HOLD 5 s. States are written as text: "unaware", "suspicious", "alert". + +/// Point-blank: seen plainly within 2 tiles in front is an alert on that look; 3-4 tiles fill fast; further is as before. +/datum/unit_test/voidcrew_stealth_point_blank + +/datum/unit_test/voidcrew_stealth_point_blank/Run() + var/datum/turf_reservation/block = stealth_block(12, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/person = stealth_person(block, 0, 0) + // Lit, one and two tiles ahead (and two ahead, one aside): alert on the first scan, after them. + for(var/list/offset as anything in list(list(1, 0), list(2, 0), list(2, 1))) + person.forceMove(stealth_at(block, 2 + offset[1], 2 + offset[2])) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "Someone at offset ([offset[1]], [offset[2]]) in the light wasn't an alert on the first look") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "A point-blank alert has no target") + qdel(guard) + // Three ahead: suspicious on the first look, alert on the second. + person.forceMove(stealth_at(block, 5, 2)) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "Someone 3 tiles ahead in the light: [stealth_ai.stealth_state()] after one look") + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "Someone 3 tiles ahead in the light: [stealth_ai.stealth_state()] after two looks") + qdel(guard) + // Six ahead: unchanged (0.375 a look, so one look is not suspicious). + person.forceMove(stealth_at(block, 8, 2)) + guard = stealth_guard(block, 2, 2) + stealth_ai = stealth_ai(guard) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "Someone 6 tiles ahead was noticed in one look") + qdel(guard) + // Two ahead in the dark (not at its elbow): no instant alert. + var/turf/dark = stealth_at(block, 4, 2) + GLOB.stealth_test_dark_turfs[dark] = TRUE + person.forceMove(dark) + guard = stealth_guard(block, 2, 2) + stealth_ai = stealth_ai(guard) + stealth_scans(guard, 1) + TEST_ASSERT(stealth_ai.stealth_state() != "alert", "Someone 2 tiles ahead in the dark was an alert on the first look") + GLOB.stealth_test_dark_turfs[dark] = FALSE + qdel(guard) + // Between scans: someone who steps in front of it is an alert without waiting for the next scan. + person.forceMove(stealth_at(block, 1, 2)) + guard = stealth_guard(block, 2, 2) + stealth_ai = stealth_ai(guard) + stealth_scans(guard, 1) + TEST_ASSERT(stealth_ai.next_scan > world.time, "The scan didn't set its next time") + TEST_ASSERT(!stealth_ai.stealth_quick_look(), "The quick look saw someone behind it") + person.forceMove(stealth_at(block, 3, 2)) + TEST_ASSERT(stealth_ai.stealth_quick_look(), "The quick look missed someone a tile in front") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "The quick look didn't make it alert") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "The quick look's alert has no target") + qdel(guard) + qdel(block) + +/// Real lighting: standing still right behind a guard in the dark, its light on, is never seen; two ahead is. +/datum/unit_test/voidcrew_stealth_behind_dark + +/datum/unit_test/voidcrew_stealth_behind_dark/Run() + var/datum/turf_reservation/block = stealth_block(9, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + stealth_unlist(block, 9, 5) + var/mob/living/carbon/human/person = stealth_person(block, 1, 2) + var/turf/behind = get_turf(person) + TEST_ASSERT(stealth_tile_is_dark(behind), "Reserved test space isn't dark, so the light can't be tested") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A guard in the dark didn't switch its light on") + stealth_settle_light(stealth_ai.torch) + // Its pool lands ahead of it (decision 39): the tile behind it stays dark. + TEST_ASSERT(stealth_tile_is_dark(behind), "The guard's pool lights the tile behind it") + stealth_scans(guard, 10) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard saw someone standing still right behind it in the dark") + var/list/entry = stealth_ai.notice_map[REF(person)] + TEST_ASSERT(isnull(entry) || entry[1] == 0, "A guard built notice on someone right behind it in the dark ([entry?[1]])") + // Two tiles ahead, in its pool: an alert. + person.forceMove(stealth_at(block, 4, 2)) + TEST_ASSERT(!stealth_tile_is_dark(get_turf(person)), "The guard's pool doesn't reach 2 tiles ahead") + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard didn't see someone 2 tiles ahead in its own light") + qdel(guard) + qdel(block) + +/// Decision 39: someone walking about behind a guard in the dark, never touching it, gains no notice at all. +/datum/unit_test/voidcrew_stealth_behind_walking + +/datum/unit_test/voidcrew_stealth_behind_walking/Run() + var/datum/turf_reservation/block = stealth_block(9, 7) + TEST_ASSERT_NOTNULL(block, "No room for the test") + stealth_unlist(block, 9, 7) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 5, 3) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 4, 3) + TEST_ASSERT_EQUAL(person.move_intent, MOVE_INTENT_WALK, "Test fixture: the person isn't walking") + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A guard in the dark didn't switch its light on") + stealth_settle_light(stealth_ai.torch) + // A walk round its back: behind, behind-diagonal and the tiles two back, every step a new tile. + var/list/path = list(list(4, 3), list(4, 4), list(3, 4), list(3, 3), list(3, 2), list(4, 2), list(4, 3), list(3, 3)) + for(var/list/step as anything in path) + var/turf/tile = stealth_at(block, step[1], step[2]) + TEST_ASSERT(stealth_tile_is_dark(tile), "Behind the guard at ([step[1]], [step[2]]) isn't dark") + person.forceMove(tile) + stealth_scans(guard, 1) + var/list/entry = stealth_ai.notice_map[REF(person)] + TEST_ASSERT(isnull(entry) || entry[1] == 0, "Walking behind a guard in the dark at ([step[1]], [step[2]]) built notice ([entry?[1]])") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard noticed someone walking behind it in the dark") + qdel(block) + +/// A friend's passing light doesn't make a guard switch its own off: its spot is judged by the room's light. Where a +/// friend's pool really lands, it is real light. +/datum/unit_test/voidcrew_stealth_light_friends + +/datum/unit_test/voidcrew_stealth_light_friends/Run() + var/datum/turf_reservation/block = stealth_block(12, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + stealth_unlist(block, 12, 5) + var/mob/living/carbon/human/npc/first = stealth_guard(block, 2, 2) + var/mob/living/carbon/human/npc/second = stealth_guard(block, 5, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/first_ai = stealth_ai(first) + var/datum/ai_controller/basic_controller/human_npc/stealth/second_ai = stealth_ai(second) + first_ai.stealth_update_light() + TEST_ASSERT(first_ai.stealth_light_shows(), "The first guard didn't switch its light on in the dark") + stealth_settle_light(first_ai.torch) + var/turf/spot = get_turf(second) + TEST_ASSERT(!stealth_tile_is_dark(spot), "The first guard's pool doesn't reach the second, so this test proves nothing") + TEST_ASSERT(stealth_tile_is_dark(spot, no_guard_lights = TRUE), "Without guard lights the second guard's spot isn't dark") + second_ai.stealth_update_light() + TEST_ASSERT(second_ai.stealth_light_shows(), "A guard in the dark left its light off because a friend's light was on it") + stealth_settle_light(second_ai.torch) + second_ai.light_hold_until = 0 + second_ai.stealth_update_light() + TEST_ASSERT(second_ai.stealth_light_shows(), "A guard switched its light off because a friend's light was on it") + first_ai.light_hold_until = 0 + first_ai.stealth_update_light() + TEST_ASSERT(first_ai.stealth_light_shows(), "A guard switched its light off because a friend's light was on it") + qdel(block) + +/// A guard already found and called out as a body is not asked after as missing. +/datum/unit_test/voidcrew_stealth_live/hear/missing_reported + +/datum/unit_test/voidcrew_stealth_live/hear/missing_reported/Run() + TEST_ASSERT(hear_room(20, 3), "No room for the test") + var/mob/living/carbon/human/npc/first = walker(5, 1) + var/mob/living/carbon/human/npc/second = walker(7, 1) + var/mob/living/carbon/human/npc/third = walker(9, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/first_ai = first.ai_controller + var/datum/stealth_group/group = first_ai.group + stealth_noise(at(4, 1), "knock") + TEST_ASSERT_EQUAL(length(group.checks), 1, "No check was opened on the guard that went") + first.death() + group.reported_bodies += REF(first) + group.rewind(31 SECONDS) + group.check_overdue() + TEST_ASSERT_EQUAL(length(group.checks), 0, "The check on a reported body wasn't closed") + TEST_ASSERT_EQUAL(state_of(second), "unaware", "A guard went looking for a friend whose body was already reported") + TEST_ASSERT_EQUAL(state_of(third), "unaware", "A guard went looking for a friend whose body was already reported") + no_targets(list(second, third)) + +/** + * A running guard never steps faster than a player running: the delay follows its move intent, its kit doesn't + * make it quicker than a bare player, and a diagonal step costs what a player's does. Logs the measured times. + */ +/datum/unit_test/voidcrew_stealth_live/run_speed + +/datum/unit_test/voidcrew_stealth_live/run_speed/Run() + TEST_ASSERT(make_room(16, 16), "No room for the test") + var/mob/living/carbon/human/person = person_at(15, 15, FALSE) + if(person.move_intent != MOVE_INTENT_RUN) + person.toggle_move_intent() + var/player_run = person.cached_multiplicative_slowdown + var/mob/living/carbon/human/npc/guard = guard_at(1, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + stealth_ai.stealth_set_pace(FALSE) + var/walk_delay = stealth_ai.movement_delay + stealth_ai.stealth_set_pace(TRUE) + TEST_ASSERT_EQUAL(guard.move_intent, MOVE_INTENT_RUN, "A running guard isn't on run") + TEST_ASSERT_EQUAL(stealth_ai.movement_delay, guard.cached_multiplicative_slowdown, "The guard's AI step delay didn't follow its move intent") + TEST_ASSERT(stealth_ai.movement_delay < walk_delay, "Running isn't faster than walking for a guard ([stealth_ai.movement_delay] vs [walk_delay])") + TEST_ASSERT(stealth_ai.movement_delay >= player_run, "A running guard's step delay [stealth_ai.movement_delay] is under a running player's [player_run]") + var/stock_diagonal = time_walk(guard, /datum/ai_movement/basic_avoidance, at(1, 1), at(13, 13)) + var/stealth_diagonal = time_walk(guard, /datum/ai_movement/basic_avoidance/stealth, at(1, 1), at(13, 13)) + var/stealth_straight = time_walk(guard, /datum/ai_movement/basic_avoidance/stealth, at(1, 1), at(13, 1)) + // The path movement (jps/stealth) shares stealth_step_cost(); it isn't timed here because tg's JPS loop stops at the + // controller's minimum distance, which with no behaviour running is its whole target range. + TEST_NOTICE(src, "Run speed: player run delay [player_run] ds, guard walk [walk_delay] ds, guard run [stealth_ai.movement_delay] ds. 12 tiles: stock tg diagonal [stock_diagonal] ds, guard diagonal [stealth_diagonal] ds, guard straight [stealth_straight] ds; a player takes [12 * player_run] ds straight, [round(12 * player_run * sqrt(2), 0.1)] ds diagonal.") + TEST_ASSERT(stealth_diagonal >= 0, "The guard never finished the diagonal run") + TEST_ASSERT(stealth_straight >= 0, "The guard never finished the straight run") + // One tick of slack for the move loop's timing. + var/slack = world.tick_lag + TEST_ASSERT(stealth_straight >= 12 * player_run - slack, "12 straight tiles took a running guard [stealth_straight] ds, a player [12 * player_run] ds") + TEST_ASSERT(stealth_diagonal >= 12 * player_run * sqrt(2) - slack, "12 diagonal tiles took a running guard [stealth_diagonal] ds, a player [12 * player_run * sqrt(2)] ds") + +/// Moves `guard` from `start` to `goal` with `movement_type`'s own move loop and returns how long it took, or -1. +/datum/unit_test/voidcrew_stealth_live/proc/time_walk(mob/living/carbon/human/npc/guard, movement_type, turf/start, turf/goal) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + guard.forceMove(start) + stealth_ai.last_step_turf = start + var/datum/ai_movement/mover = SSai_movement.movement_types[movement_type] + var/began = world.time + mover.start_moving_towards(stealth_ai, goal, 0) + var/deadline = world.time + 15 SECONDS + while(get_turf(guard) != goal && world.time < deadline) + sleep(world.tick_lag) + var/took = world.time - began + mover.stop_moving_towards(stealth_ai) + return get_turf(guard) == goal ? took : -1 + +/// Decision 39: a fresh guard walks its route from its first plan (tg starts every mob at a run), and a diagonal +/// step at a walk still costs what a player's does (decision 32). +/datum/unit_test/voidcrew_stealth_live/walk_pace + +/datum/unit_test/voidcrew_stealth_live/walk_pace/Run() + TEST_ASSERT(make_room(16, 16), "No room for the test") + // Not on SSmobs' player list, as in run_speed: an awake guard would walk back to its post and take over the + // movement being timed. + person_at(15, 15, FALSE) + var/mob/living/carbon/human/npc/guard = guard_at(1, 1) + TEST_ASSERT_EQUAL(guard.move_intent, MOVE_INTENT_RUN, "Test fixture: tg no longer starts mobs at a run, so this test proves nothing") + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + var/run_delay = stealth_ai.movement_delay + stealth_ai.stealth_setup() + TEST_ASSERT_EQUAL(guard.move_intent, MOVE_INTENT_WALK, "A fresh guard isn't walking once it has set up") + var/walk_delay = stealth_ai.movement_delay + TEST_ASSERT(walk_delay > run_delay, "A walking guard's step delay [walk_delay] isn't over its running one [run_delay]") + var/diagonal = time_walk(guard, /datum/ai_movement/basic_avoidance/stealth, at(1, 1), at(13, 13)) + TEST_NOTICE(src, "Walk pace: guard walk delay [walk_delay] ds, run [run_delay] ds; 12 diagonal tiles at a walk took [diagonal] ds.") + TEST_ASSERT(diagonal >= 0, "The guard never finished the diagonal walk") + TEST_ASSERT(diagonal >= 12 * walk_delay * sqrt(2) - world.tick_lag, "12 diagonal tiles took a walking guard [diagonal] ds, a walking player [12 * walk_delay * sqrt(2)] ds") diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_d37.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_d37.dm new file mode 100644 index 00000000000..1c53d140431 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_d37.dm @@ -0,0 +1,238 @@ +// Stealth guards, owner decisions 37 (glass and doors) and 38 (skill by zone). voidcrew/modules/stealth/stealth_doors.dm, +// stealth_skill.dm, and the glass step in stealth_noise_sources.dm. Values from voidcrew/_DEFINES are written out: +// STEALTH_NOISE_RANGE_CRUNCH 4, STEALTH_DOOR_CUE_COOLDOWN 30 s, STEALTH_DOOR_CUE_MAX 2, STEALTH_DOOR_GUARD_MEMORY 20 s; +// ZONE_GREEN 1, ZONE_YELLOW 2, ZONE_RED 3. States and noise kinds are written as text. + +/// Stepping on a shard, even at a walk: the guard in earshot goes to look. A guard's own step on one is nothing, +/// and a green guard's duller ear misses a crunch a yellow one hears. +/datum/unit_test/voidcrew_stealth_live/hear/glass_crunch + +/datum/unit_test/voidcrew_stealth_live/hear/glass_crunch/Run() + TEST_ASSERT(hear_room(20, 3), "No room for the test") + var/mob/living/carbon/human/npc/guard = sentry(8, 1, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + var/obj/item/shard/shard = allocate(/obj/item/shard, at(5, 1)) + var/mob/living/carbon/human/walker = person_at(4, 1, FALSE) + walker.equip_to_slot_or_del(new /obj/item/clothing/shoes/sneakers/black(walker), ITEM_SLOT_FEET) + TEST_ASSERT_EQUAL(walker.move_intent, MOVE_INTENT_WALK, "The walker isn't walking") + walker.forceMove(get_turf(shard)) + TEST_ASSERT_EQUAL(guard_ai.last_heard?[1], "crunch", "A guard 3 tiles off didn't hear a shard stepped on at a walk") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "A crunch didn't send the guard to look") + no_targets(list(guard)) + // One of their own stepping on it. + settle(guard) + guard_ai.group.forget_noises() + guard_ai.last_heard = null + walker.forceMove(at(2, 0)) + var/mob/living/carbon/human/npc/friend = sentry(4, 1, EAST) + friend.forceMove(get_turf(shard)) + TEST_ASSERT_NULL(guard_ai.last_heard, "A guard heard its friend step on glass") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A friend's crunch sent a guard to look") + friend.forceMove(at(0, 0)) + // A bulb on the floor crunches too. + var/obj/item/light/bulb/bulb = allocate(/obj/item/light/bulb, at(6, 2)) + walker.forceMove(get_turf(bulb)) + TEST_ASSERT_EQUAL(guard_ai.last_heard?[1], "crunch", "Stepping on a bulb wasn't heard") + // A green guard 4 tiles off: 4 x 0.75 = 3, out of reach. A yellow one there hears it. + settle(guard) + guard_ai.group.forget_noises() + guard_ai.last_heard = null + guard_ai.stealth_force_skill(/datum/stealth_skill/green) + walker.forceMove(at(3, 1)) + shard.forceMove(at(4, 1)) + walker.forceMove(at(4, 1)) + TEST_ASSERT_NULL(guard_ai.last_heard, "A green guard heard a crunch 4 tiles off") + guard_ai.stealth_force_skill(/datum/stealth_skill/yellow) + guard_ai.group.forget_noises() + walker.forceMove(at(3, 1)) + walker.forceMove(at(4, 1)) + TEST_ASSERT_EQUAL(guard_ai.last_heard?[1], "crunch", "A yellow guard didn't hear a crunch 4 tiles off") + +/// A door seen opening in a guard's cone makes it suspicious of its own side of the door; behind it, out of its +/// dark sight in the dark, or with one of their own beside the door, nothing; a door that keeps moving is throttled. +/datum/unit_test/voidcrew_stealth_live/hear/door_seen + +/datum/unit_test/voidcrew_stealth_live/hear/door_seen/Run() + TEST_ASSERT(hear_room(20, 5), "No room for the test") + var/mob/living/carbon/human/npc/guard = sentry(2, 2, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + var/turf/door_spot = at(9, 2) + var/obj/machinery/door/poddoor/shutters/shutter = allocate(/obj/machinery/door/poddoor/shutters, door_spot) + TEST_ASSERT(shutter.density, "The shutter isn't shut") + // Seven tiles ahead, lit, opened through tg's own open(): it goes to look at its side of it. + INVOKE_ASYNC(shutter, TYPE_PROC_REF(/obj/machinery/door, open)) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "A guard didn't react to a shutter opening in front of it") + TEST_ASSERT_EQUAL(guard_ai.investigate_turf, at(8, 2), "It isn't going to its own side of the door") + TEST_ASSERT(!guard_ai.suspicion_heard, "A door it saw counts as one it only heard") + no_targets(list(guard)) + // The same door again at once: throttled, a glance at most. + settle(guard) + TEST_ASSERT_EQUAL(stealth_door_moved(shutter, FALSE), 0, "A door sent someone to look twice within 30 s") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A throttled door made a guard suspicious") + // After the cooldown it works once more; then that door is ignored for the rest of 3 minutes. + // (No forget_noises() here: it forgets doors too.) + guard_ai.group.rewind(31 SECONDS) + TEST_ASSERT_EQUAL(stealth_door_moved(shutter, TRUE), 1, "A door didn't draw a look after its cooldown") + settle(guard) + guard_ai.group.rewind(31 SECONDS) + TEST_ASSERT_EQUAL(stealth_door_moved(shutter, FALSE), 0, "A door drew a third look within 3 minutes") + guard_ai.group.rewind(3 MINUTES) + TEST_ASSERT_EQUAL(stealth_door_moved(shutter, TRUE), 1, "A door was still ignored after 3 minutes") + settle(guard) + guard_ai.group.forget_noises() + guard_ai.group.rewind(31 SECONDS) + // Behind it: nothing. + guard.setDir(WEST) + TEST_ASSERT_EQUAL(stealth_door_moved(shutter, FALSE), 0, "A guard saw a door behind it") + guard.setDir(EAST) + // In the dark, 7 tiles off (past its dark sight of 4): nothing. 3 tiles off: it sees it. + GLOB.stealth_test_dark_turfs[door_spot] = TRUE + TEST_ASSERT_EQUAL(stealth_door_moved(shutter, TRUE), 0, "A guard saw a dark doorway 7 tiles off") + guard.forceMove(at(6, 2)) + TEST_ASSERT_EQUAL(stealth_door_moved(shutter, FALSE), 1, "A guard didn't see a dark doorway 3 tiles off") + GLOB.stealth_test_dark_turfs[door_spot] = FALSE + no_targets(list(guard)) + +/// Their own doors: a door that moves with one of them beside it draws nobody, and neither does the close that +/// follows once that guard has walked on. A wooden door a player opens is seen and heard. +/datum/unit_test/voidcrew_stealth_live/hear/door_own + +/datum/unit_test/voidcrew_stealth_live/hear/door_own/Run() + TEST_ASSERT(hear_room(20, 5), "No room for the test") + var/mob/living/carbon/human/npc/watcher = sentry(2, 2, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/watcher_ai = watcher.ai_controller + var/obj/machinery/door/poddoor/shutters/shutter = allocate(/obj/machinery/door/poddoor/shutters, at(8, 2)) + var/mob/living/carbon/human/npc/passer = sentry(9, 2, WEST) + TEST_ASSERT_EQUAL(stealth_door_moved(shutter, TRUE), 0, "A door one of them stood beside drew a look") + TEST_ASSERT_EQUAL(watcher_ai.stealth_state(), "unaware", "A guard was suspicious of its friend's door") + TEST_ASSERT_EQUAL(watcher_ai.glance_until, 0, "A guard glanced at its friend's door") + passer.forceMove(at(15, 2)) + TEST_ASSERT_EQUAL(stealth_door_moved(shutter, FALSE), 0, "The close after a friend's opening drew a look") + TEST_ASSERT_EQUAL(watcher_ai.stealth_state(), "unaware", "A guard was suspicious of its friend's door shutting itself") + // Long after that, a close with nobody beside it is someone else's. + watcher_ai.group.rewind(21 SECONDS) + TEST_ASSERT_EQUAL(stealth_door_moved(shutter, TRUE), 1, "A door with nobody beside it drew no look") + settle(watcher) + watcher_ai.group.forget_noises() + // A wooden door, opened through tg's own Open(). + var/obj/structure/mineral_door/wood/wood = allocate(/obj/structure/mineral_door/wood, at(5, 3)) + INVOKE_ASYNC(wood, TYPE_PROC_REF(/obj/structure/mineral_door, Open)) + TEST_ASSERT_EQUAL(watcher_ai.stealth_state(), "suspicious", "A guard didn't react to a wooden door opening in front of it") + TEST_ASSERT_EQUAL(watcher_ai.last_heard?[1], "door", "A wooden door made no noise") + no_targets(list(watcher, passer)) + +/// The skill profile: yellow is today's tuning; zone, mapper and admin pick it in that order of strength. +/datum/unit_test/voidcrew_stealth_skill + +/datum/unit_test/voidcrew_stealth_skill/Run() + var/datum/stealth_skill/yellow = stealth_skill_of(/datum/stealth_skill/yellow) + // The numbers the den was tuned on (STEALTH_SIGHT_RANGE, STEALTH_CONE_HALF_ANGLE, ... in _DEFINES/stealth.dm). + TEST_ASSERT_EQUAL(yellow.sight_range, 8, "Yellow sight range changed") + TEST_ASSERT_EQUAL(yellow.alert_max_range, 7, "Yellow alert range changed") + TEST_ASSERT_EQUAL(yellow.dark_sight_range, 4, "Yellow dark sight changed") + TEST_ASSERT_EQUAL(yellow.cone_half_angle, 60, "Yellow cone changed") + TEST_ASSERT_EQUAL(yellow.wary_half_angle, 75, "Yellow wary cone changed") + TEST_ASSERT_EQUAL(yellow.search_half_angle, 90, "Yellow search cone changed") + TEST_ASSERT_EQUAL(yellow.notice_rate, 1, "Yellow notice rate changed") + TEST_ASSERT_EQUAL(yellow.point_blank_range, 2, "Yellow point-blank range changed") + TEST_ASSERT_EQUAL(yellow.near_range, 4, "Yellow near range changed") + TEST_ASSERT_EQUAL(yellow.near_mult, 3, "Yellow near multiplier changed") + TEST_ASSERT_EQUAL(yellow.close_range, 2, "Yellow close range changed") + TEST_ASSERT_EQUAL(yellow.hearing_mult, 1, "Yellow hearing changed") + TEST_ASSERT_EQUAL(yellow.reaction_delay, 2 SECONDS, "Yellow reaction delay changed") + TEST_ASSERT_EQUAL(yellow.search_time, 40 SECONDS, "Yellow search time changed") + TEST_ASSERT_EQUAL(yellow.wary_time, 60 SECONDS, "Yellow wary time changed") + TEST_ASSERT_EQUAL(yellow.turn_grace, 1 SECONDS, "Yellow turn grace changed") + // Every profile keeps decision 18 (no alert from off screen) and a cone that never takes in what is behind. + for(var/skill_type in subtypesof(/datum/stealth_skill)) + var/datum/stealth_skill/profile = stealth_skill_of(skill_type) + TEST_ASSERT(profile.alert_max_range <= 7, "[skill_type] goes alert from off screen") + TEST_ASSERT(profile.search_half_angle <= 90, "[skill_type] searches with eyes in the back of its head") + TEST_ASSERT(profile.sight_range <= 9, "[skill_type] sees past the range it gathers people from") + // Zones. + TEST_ASSERT_EQUAL(stealth_skill_type_for_zone(1), /datum/stealth_skill/green, "Green zone isn't green skill") + TEST_ASSERT_EQUAL(stealth_skill_type_for_zone(2), /datum/stealth_skill/yellow, "Yellow zone isn't yellow skill") + TEST_ASSERT_EQUAL(stealth_skill_type_for_zone(3), /datum/stealth_skill/red, "Red zone isn't red skill") + TEST_ASSERT_EQUAL(stealth_skill_type_for_zone(null), /datum/stealth_skill/yellow, "An unknown zone isn't yellow") + var/datum/turf_reservation/block = stealth_block(3, 3) + TEST_ASSERT_NOTNULL(block, "No room for the test") + // Reserved test space belongs to no zone: yellow. + var/mob/living/carbon/human/npc/guard = allocate(/mob/living/carbon/human/npc/ruin/trooper/scav, stealth_at(block, 1, 1)) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + TEST_ASSERT_NULL(stealth_zone_of(get_turf(guard)), "Reserved test space belongs to a zone") + TEST_ASSERT_EQUAL(stealth_ai.stealth_skill().name, "yellow", "A guard with no zone isn't yellow") + // A spawner's pick reaches the guard and beats the zone. + stealth_set_mapped_skill(/datum/stealth_skill/red, guard) + TEST_ASSERT_EQUAL(guard.stealth_skill, /datum/stealth_skill/red, "A spawner's skill didn't reach its guard") + TEST_ASSERT_EQUAL(stealth_ai.stealth_skill().name, "red", "A mapped skill didn't beat the zone") + // An admin's pick beats the mapper's, and lets go again. + stealth_ai.stealth_force_skill(/datum/stealth_skill/green) + TEST_ASSERT_EQUAL(stealth_ai.stealth_skill().name, "green", "An admin's skill didn't beat the mapper's") + stealth_set_mapped_skill(/datum/stealth_skill/red, guard) + TEST_ASSERT_EQUAL(stealth_ai.stealth_skill().name, "green", "A mapper's skill overrode an admin's") + stealth_ai.stealth_force_skill(null) + TEST_ASSERT_EQUAL(stealth_ai.stealth_skill().name, "red", "Clearing an admin's skill didn't go back to the mapper's") + // A spawner hands its pick over without a reference to itself. (The family root places nothing.) + var/obj/effect/spawner/human_npc/spawner = new(stealth_at(block, 0, 0)) + spawner.stealth_skill = /datum/stealth_skill/green + var/datum/callback/handover = spawner.npc_spawned_callback() + TEST_ASSERT_NOTNULL(handover, "A spawner with a skill hands nothing over") + TEST_ASSERT(handover.object == GLOBAL_PROC, "The spawner's handover holds the spawner") + spawner.stealth_skill = null + TEST_ASSERT_NULL(spawner.npc_spawned_callback(), "A spawner without a skill hands something over") + if(!QDELETED(spawner)) + qdel(spawner) + qdel(guard) + qdel(block) + +/// The knobs reach the guard: green is narrower, shorter-sighted, no instant alert at 2 tiles, gives up sooner. +/datum/unit_test/voidcrew_stealth_skill_knobs + +/datum/unit_test/voidcrew_stealth_skill_knobs/Run() + var/datum/turf_reservation/block = stealth_block(14, 7) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/person = stealth_person(block, 0, 0) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 3) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + // Cone: two ahead and three aside is 56 degrees off its facing. + var/turf/aside = stealth_at(block, 4, 6) + TEST_ASSERT(stealth_in_cone(guard, aside, stealth_ai.stealth_half_angle()), "56 degrees is outside a yellow cone") + stealth_ai.stealth_force_skill(/datum/stealth_skill/green) + TEST_ASSERT(!stealth_in_cone(guard, aside, stealth_ai.stealth_half_angle()), "56 degrees is inside a green cone") + TEST_ASSERT_EQUAL(stealth_ai.stealth_range_onto(aside), 7, "A green guard's sight isn't 7") + // Eight ahead in the light: a yellow guard notices, a green one doesn't see that far. + person.forceMove(stealth_at(block, 10, 3)) + stealth_scans(guard, 1) + TEST_ASSERT_NULL(stealth_ai.notice_map[REF(person)], "A green guard noticed someone 8 tiles off") + stealth_ai.stealth_force_skill(/datum/stealth_skill/yellow) + stealth_scans(guard, 1) + TEST_ASSERT_NOTNULL(stealth_ai.notice_map[REF(person)], "A yellow guard didn't notice someone 8 tiles off") + qdel(guard) + // Two ahead in the light: yellow is an alert on that look; green is not (its point-blank is 1). + person.forceMove(stealth_at(block, 4, 3)) + guard = stealth_guard(block, 2, 3) + stealth_ai = stealth_ai(guard) + stealth_ai.stealth_force_skill(/datum/stealth_skill/green) + stealth_scans(guard, 1) + TEST_ASSERT(stealth_ai.stealth_state() != "alert", "A green guard went alert at once at 2 tiles") + qdel(guard) + guard = stealth_guard(block, 2, 3) + stealth_ai = stealth_ai(guard) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A yellow guard didn't go alert at once at 2 tiles") + stealth_ai.clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + qdel(guard) + // Search length: 30 s in, a green search is over and a yellow one isn't. + person.forceMove(stealth_at(block, 0, 0)) + guard = stealth_guard(block, 12, 3, WEST) + stealth_ai = stealth_ai(guard) + stealth_scans(guard, 1) + stealth_ai.stealth_go_searching(stealth_at(block, 10, 3)) + stealth_ai.stealth_rewind(30 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "searching", "A yellow search ended within 30 s") + stealth_ai.stealth_force_skill(/datum/stealth_skill/green) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A green search didn't end by 30 s") + qdel(guard) + qdel(block) diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_d39.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_d39.dm new file mode 100644 index 00000000000..2034ac36bf4 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_d39.dm @@ -0,0 +1,115 @@ +// Stealth guards, decision 39 and the 2026-11-11 playtest fixes (voidcrew/modules/stealth/stealth_turns.dm, +// stealth_patrol.dm): readable turns, the grace after a turn, stop look-rounds and arrival facing. Values from +// voidcrew/_DEFINES are written out: STEALTH_TURN_TELL 0.6 s, STEALTH_LOOK_TURN_ARC 90; yellow turn_grace 1 s. +// States are written as text. + +/// After a turn where it stands (to a noise, a door or on its own), someone right in front is not an instant alert; +/// notice still fills, and once the moment has passed they are. +/datum/unit_test/voidcrew_stealth_turn_grace + +/datum/unit_test/voidcrew_stealth_turn_grace/Run() + var/datum/turf_reservation/block = stealth_block(7, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/person = stealth_person(block, 4, 2) + // "glance" is a noise or a door's glance; "suspicious" is a door seen moving or a noise worth a look. + for(var/how in list("glance", "suspicious")) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 3, 2, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_ai.stealth_setup() + TEST_ASSERT(!stealth_ai.stealth_turn_grace(), "A guard that hasn't turned is in its turn grace") + if(how == "glance") + stealth_ai.stealth_glance(stealth_at(block, 6, 2)) + else + stealth_ai.stealth_go_suspicious(stealth_at(block, 6, 2)) + TEST_ASSERT_EQUAL(guard.dir, EAST, "[how]: the guard didn't turn to face the spot") + TEST_ASSERT(stealth_ai.stealth_turn_grace(), "[how]: a guard that just turned isn't in its turn grace") + TEST_ASSERT(!stealth_ai.stealth_quick_look(), "[how]: the quick look made someone at its elbow an alert the moment it turned") + stealth_scans(guard, 1) + TEST_ASSERT(stealth_ai.stealth_state() != "alert", "[how]: someone at its elbow was an alert on the look right after it turned") + var/list/entry = stealth_ai.notice_map[REF(person)] + TEST_ASSERT(entry && entry[1] > 0, "[how]: notice didn't fill during the turn grace") + // The moment passes: they are seen plainly. + stealth_ai.turned_at = world.time - 2 SECONDS + TEST_ASSERT(!stealth_ai.stealth_turn_grace(), "[how]: the turn grace outlasted its time") + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "[how]: someone at its elbow wasn't an alert once the turn grace was over") + qdel(guard) + // A step is not a look round: turning by walking gives no grace. + var/mob/living/carbon/human/npc/walker = stealth_guard(block, 1, 2, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/walker_ai = stealth_ai(walker) + walker_ai.stealth_setup() + walker.Move(stealth_at(block, 1, 3), NORTH) + TEST_ASSERT(!walker_ai.stealth_turn_grace(), "Turning by stepping gave a turn grace") + qdel(block) + +/// A turn on its own shows a lean first and lands after STEALTH_TURN_TELL; a change of state drops it. +/datum/unit_test/voidcrew_stealth_turn_tell + +/datum/unit_test/voidcrew_stealth_turn_tell/Run() + var/datum/turf_reservation/block = stealth_block(5, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_ai.stealth_setup() + stealth_ai.stealth_turn_to(NORTH) + TEST_ASSERT_EQUAL(guard.dir, EAST, "A guard turned on its own with no tell first") + TEST_ASSERT_EQUAL(stealth_ai.turn_pending, NORTH, "No turn is pending after the tell started") + TEST_ASSERT_NOTNULL(stealth_ai.turn_lean, "The tell shows no lean") + sleep(0.8 SECONDS) + TEST_ASSERT_EQUAL(guard.dir, NORTH, "The turn didn't land after its tell") + TEST_ASSERT_NULL(stealth_ai.turn_lean, "The lean stayed on after the turn") + // A turn that is overtaken by events is dropped, lean and all. + stealth_ai.stealth_turn_to(WEST) + stealth_ai.stealth_go_suspicious(stealth_at(block, 2, 0)) + TEST_ASSERT_EQUAL(stealth_ai.turn_pending, 0, "A change of state kept the pending turn") + TEST_ASSERT_NULL(stealth_ai.turn_lean, "A dropped turn left its lean on") + sleep(0.8 SECONDS) + TEST_ASSERT_EQUAL(guard.dir, SOUTH, "A dropped turn still landed") + qdel(block) + +/// At a stop it looks left, back, right, back: a steady beat, not a coin toss. +/datum/unit_test/voidcrew_stealth_look_rounds + +/datum/unit_test/voidcrew_stealth_look_rounds/Run() + var/datum/turf_reservation/block = stealth_block(5, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_ai.stealth_setup() + stealth_ai.route_id = "a" // a route guard, not a sentry + stealth_ai.stand_dir = EAST + var/datum/ai_behavior/stealth_stand/stand = GET_AI_BEHAVIOR(/datum/ai_behavior/stealth_stand) + var/list/seen = list() + for(var/i in 1 to 4) + stealth_ai.next_turn = 0 + stand.perform(1, stealth_ai) + sleep(0.8 SECONDS) + seen += dir2text(guard.dir) + TEST_ASSERT_EQUAL(jointext(seen, ","), "north,east,south,east", "A guard at a stop looked [jointext(seen, ",")] instead of left, back, right, back") + qdel(block) + +/// A guard arrives at a stop facing the way it walked, unless the stop sets a facing (then it turns, with a tell). +/datum/unit_test/voidcrew_stealth_arrival_facing + +/datum/unit_test/voidcrew_stealth_arrival_facing/Run() + var/datum/turf_reservation/block = stealth_block(5, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + allocate(/obj/effect/landmark/stealth_group, stealth_at(block, 4, 4)) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_ai.stealth_setup() + var/datum/stealth_stop/plain = new + plain.spot = get_turf(guard) + stealth_ai.stealth_arrive(plain) + TEST_ASSERT_EQUAL(guard.dir, WEST, "A guard turned at a stop with no facing set") + TEST_ASSERT_EQUAL(stealth_ai.stand_dir, WEST, "A guard at a stop with no facing doesn't keep the way it walked") + TEST_ASSERT_EQUAL(stealth_ai.turn_pending, 0, "A guard at a stop with no facing is about to turn") + var/datum/stealth_stop/faced = new + faced.spot = get_turf(guard) + faced.dir = NORTH + stealth_ai.stealth_arrive(faced) + TEST_ASSERT_EQUAL(stealth_ai.stand_dir, NORTH, "A stop's facing wasn't taken") + TEST_ASSERT_EQUAL(stealth_ai.turn_pending, NORTH, "A guard turned to a stop's facing with no tell") + sleep(0.8 SECONDS) + TEST_ASSERT_EQUAL(guard.dir, NORTH, "A guard didn't turn to its stop's facing") + qdel(block) diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_d44.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_d44.dm new file mode 100644 index 00000000000..7fbdd705ba8 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_d44.dm @@ -0,0 +1,290 @@ +// Stealth guards, owner decision 44 (playtest 2: disguises and tracking). voidcrew/modules/stealth/stealth_disguise.dm, +// stealth_hearing.dm, stealth_noise.dm, stealth_radio.dm, stealth_ai.dm and stealth_closet.dm. Values from voidcrew/_DEFINES +// are written out: STEALTH_LOSE_TARGET_TIME 4 s, STEALTH_RADIO_CALL_TIME 3 s; a yellow guard's dark sight is 4 tiles, its +// close range 2, its challenge range for the whole set 2. Pieces: clothing 2, pass 4. States and the blackboard key +// BB_HUMAN_NPC_NEXT_SHOT ("human_npc_next_shot") are written as text. +// The tests down to voidcrew_stealth_d44_alert_dark call the scan directly; the voidcrew_stealth_live ones run the real AI. + +#define STEALTH_TEST_GUNNER /mob/living/carbon/human/npc/ruin/trooper/scav/gunner +#define STEALTH_TEST_LOOKOUT /mob/living/carbon/human/npc/ruin/trooper/scav/lookout + +/// Running in the whole set behind a guard is only footsteps: it turns, stops them, and running while stopped gives +/// them away. +/datum/unit_test/voidcrew_stealth_d44_run_disguised + +/datum/unit_test/voidcrew_stealth_d44_run_disguised/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 10, 2) + stealth_dress(person) + person.equip_to_slot_or_del(new /obj/item/clothing/shoes/jackboots(person), ITEM_SLOT_FEET) + stealth_scans(guard, 1) + person.toggle_move_intent() + person.forceMove(stealth_at(block, 8, 2)) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(guard_ai.last_heard?[1], "footsteps", "The guard didn't hear someone run up two tiles behind it") + TEST_ASSERT(guard_ai.stealth_fooled(person), "Running behind a guard gave the disguise away by ear") + TEST_ASSERT(!length(guard_ai.made), "The guard marked someone it only heard") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "Running two tiles behind a guard drew no look") + TEST_ASSERT_EQUAL(guard.dir, EAST, "The guard didn't turn to the steps") + TEST_ASSERT_NULL(guard_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "The guard went for someone it only heard") + // The moment after the turn has passed: it sees them in its colours and stops them. + guard_ai.turned_at = 0 + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(guard_ai.challenge?.resolve(), person, "The guard didn't stop someone in its colours two tiles in front of it") + TEST_ASSERT_NULL(guard_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "The guard went for someone it stopped") + // Running off while stopped. + person.forceMove(stealth_at(block, 9, 2)) + stealth_scans(guard, 1) + TEST_ASSERT(!guard_ai.stealth_fooled(person), "Running off while stopped didn't give the disguise away") + TEST_ASSERT(guard_ai.made?[REF(person)] > world.time, "The guard doesn't remember who ran off") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "alert", "The guard let someone run off from a stop") + qdel(block) + +/// Stripping a guard that is out cold is no touch: it learns nothing. A friend who sees it done still sees through +/// the disguise; one looking away doesn't. An awake guard being stripped turns on them. +/datum/unit_test/voidcrew_stealth_d44_strip + +/datum/unit_test/voidcrew_stealth_d44_strip/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/watcher = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/watcher_ai = stealth_ai(watcher) + watcher_ai.stealth_setup() + var/mob/living/carbon/human/npc/away = stealth_guard(block, 2, 2, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/away_ai = stealth_ai(away) + away_ai.stealth_setup() + var/mob/living/carbon/human/npc/victim = stealth_guard(block, 11, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/victim_ai = stealth_ai(victim) + victim_ai.stealth_setup() + TEST_ASSERT_EQUAL(victim_ai.group, watcher_ai.group, "The guards aren't one group") + var/mob/living/carbon/human/person = stealth_person(block, 10, 2) + stealth_dress(person) + victim.Unconscious(100 SECONDS) + TEST_ASSERT(victim.stat != CONSCIOUS || HAS_TRAIT(victim, TRAIT_INCAPACITATED), "The guard isn't out cold") + SEND_SIGNAL(victim, COMSIG_BEING_STRIPPED, person, victim.wear_id) + TEST_ASSERT(!length(victim_ai.made), "A guard out cold learned who stripped it") + TEST_ASSERT_NULL(victim_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "A guard out cold took a target") + TEST_ASSERT_EQUAL(watcher_ai.stealth_state(), "alert", "A guard watched a friend being stripped and did nothing") + TEST_ASSERT_EQUAL(watcher_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "The watching guard isn't after the one stripping") + TEST_ASSERT(away_ai.stealth_fooled(person), "A guard looking away saw the stripping") + qdel(watcher) + qdel(victim) + // Awake, it is a touch. + var/mob/living/carbon/human/npc/awake = stealth_guard(block, 11, 3) + var/datum/ai_controller/basic_controller/human_npc/stealth/awake_ai = stealth_ai(awake) + awake_ai.stealth_setup() + SEND_SIGNAL(awake, COMSIG_BEING_STRIPPED, person, awake.wear_id) + TEST_ASSERT_EQUAL(awake_ai.stealth_state(), "alert", "An awake guard being stripped didn't turn on them") + qdel(block) + +/// The pass counts where a door would read it: in a hand, in a wallet or a PDA, on the belt. Not in a bag. +/datum/unit_test/voidcrew_stealth_d44_pass_places + +/datum/unit_test/voidcrew_stealth_d44_pass_places/Run() + var/datum/turf_reservation/block = stealth_block(3, 3) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/person = stealth_person(block, 1, 1) + stealth_dress(person, TRUE, FALSE, FALSE) + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 2, "The fatigues alone aren't the clothing piece") + var/obj/item/card/id/advanced/black/scav/pass = new(person) + TEST_ASSERT(person.put_in_hands(pass), "The pass wouldn't go in a hand") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 6, "A pass held in a hand doesn't count") + TEST_ASSERT(person.dropItemToGround(pass), "The pass wouldn't drop") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 2, "A pass on the floor still counts") + // In a wallet in the ID slot. + var/obj/item/storage/wallet/wallet = new(person) + pass.forceMove(wallet) + TEST_ASSERT(person.equip_to_slot_if_possible(wallet, ITEM_SLOT_ID), "The wallet wouldn't go on") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 6, "A pass in a wallet in the ID slot doesn't count") + TEST_ASSERT(person.dropItemToGround(wallet), "The wallet wouldn't come off") + // In a PDA on the belt. + var/obj/item/modular_computer/pda/pda = new(person) + pass.forceMove(person) + pda.InsertID(pass, null) + TEST_ASSERT_EQUAL(pda.computer_id_slot, pass, "The pass didn't go in the PDA") + TEST_ASSERT(person.equip_to_slot_if_possible(pda, ITEM_SLOT_BELT), "The PDA wouldn't go on the belt") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 6, "A pass in a PDA on the belt doesn't count") + // Deep in a bag. + var/obj/item/storage/backpack/bag = new(person) + TEST_ASSERT(person.equip_to_slot_if_possible(bag, ITEM_SLOT_BACK), "The bag wouldn't go on") + new /obj/item/card/id/advanced/black/scav(bag) + TEST_ASSERT(person.dropItemToGround(pda), "The PDA wouldn't come off") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 2, "A pass in a bag counts") + qdel(block) + +/// Alert, it keeps its target all round, in the light it can see by: lit, out to its sight; dark, within its dark +/// sight. Lost in the dark long enough, it searches where it last saw them. +/datum/unit_test/voidcrew_stealth_d44_alert_dark + +/datum/unit_test/voidcrew_stealth_d44_alert_dark/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 9, 2) + for(var/dx in 0 to 19) + GLOB.stealth_test_dark_turfs[stealth_at(block, dx, 2)] = TRUE + guard_ai.stealth_go_alert(person) + // Three tiles off in the dark: within its dark sight. + guard_ai.stealth_keep_target() + TEST_ASSERT(!guard_ai.lost_since, "An alert guard lost someone three tiles off in the dark") + // Three tiles behind it in the dark: all round. + person.forceMove(stealth_at(block, 3, 2)) + guard_ai.stealth_keep_target() + TEST_ASSERT(!guard_ai.lost_since, "An alert guard lost someone three tiles behind it") + // Six tiles off in the dark: out of view. + person.forceMove(stealth_at(block, 12, 2)) + TEST_ASSERT(!guard_ai.stealth_has_in_view(person), "An alert guard has someone six tiles off in the dark in view") + guard_ai.stealth_keep_target() + TEST_ASSERT(guard_ai.lost_since, "An alert guard kept someone six tiles off in the dark") + // Lit there: back in view. + GLOB.stealth_test_dark_turfs[stealth_at(block, 12, 2)] = FALSE + guard_ai.stealth_keep_target() + TEST_ASSERT(!guard_ai.lost_since, "An alert guard didn't see someone lit six tiles off") + TEST_ASSERT_EQUAL(guard_ai.last_seen_turf, stealth_at(block, 12, 2), "The guard didn't note where it saw them") + // Into the dark further on, and long enough: it searches where it last saw them, not where they are. + person.forceMove(stealth_at(block, 14, 2)) + guard_ai.stealth_keep_target() + TEST_ASSERT(guard_ai.lost_since, "An alert guard kept someone eight tiles off in the dark") + guard_ai.stealth_rewind(5 SECONDS) + guard_ai.stealth_keep_target() + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "searching", "A guard that lost someone in the dark isn't searching") + TEST_ASSERT_EQUAL(guard_ai.last_seen_turf, stealth_at(block, 12, 2), "The guard searches somewhere it never saw them") + TEST_ASSERT_NULL(guard_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "The guard kept a target it lost") + qdel(block) + +/// A gunner, a lookout or a plain guard at (dx, dy) of the room, as guard_at() places one. +/datum/unit_test/voidcrew_stealth_live/proc/npc_at(npc_type, dx, dy, facing = EAST) + var/mob/living/carbon/human/npc/guard = allocate(npc_type, at(dx, dy)) + guard.setDir(facing) + guard.AddElement(/datum/element/forced_gravity, 1) + return guard + +/// The real AI: a lookout sees through a disguise. The friend in earshot of its shout is told, the friend on the radio +/// is told when the call goes out, and a wary friend neither reached knows nothing. +/datum/unit_test/voidcrew_stealth_live/d44_word + +/datum/unit_test/voidcrew_stealth_live/d44_word/Run() + TEST_ASSERT(make_room(30, 5), "No room for the test") + allocate(/obj/effect/landmark/stealth_group, at(0, 4)) + for(var/dy in 0 to 4) + var/turf/wall_spot = at(14, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + var/mob/living/carbon/human/person = person_at(9, 2) + stealth_dress(person) + var/mob/living/carbon/human/npc/lookout = npc_at(STEALTH_TEST_LOOKOUT, 6, 2, EAST) + var/mob/living/carbon/human/npc/near = guard_at(2, 2, WEST) + var/mob/living/carbon/human/npc/far_radio = npc_at(STEALTH_TEST_LOOKOUT, 22, 2, EAST) + var/mob/living/carbon/human/npc/far_plain = guard_at(26, 2, EAST) + TEST_ASSERT(istype(lookout.ears, /obj/item/radio) && istype(far_radio.ears, /obj/item/radio), "A lookout has no earpiece") + var/datum/ai_controller/basic_controller/human_npc/stealth/lookout_ai = wake(lookout) + var/datum/ai_controller/basic_controller/human_npc/stealth/near_ai = wake(near) + var/datum/ai_controller/basic_controller/human_npc/stealth/far_radio_ai = wake(far_radio) + var/datum/ai_controller/basic_controller/human_npc/stealth/far_plain_ai = wake(far_plain) + sleep(2 SECONDS) + TEST_ASSERT(lookout_ai.group && lookout_ai.group == near_ai.group && lookout_ai.group == far_radio_ai.group && lookout_ai.group == far_plain_ai.group, "The four guards aren't one group") + TEST_ASSERT(lookout_ai.stealth_fooled(person), "The lookout saw through the whole set before anything happened") + far_radio_ai.stealth_set_wary() + far_plain_ai.stealth_set_wary() + var/key = REF(person) + // A gun in hand gives it away. + person.put_in_hands(new /obj/item/gun/ballistic/automatic/pistol(person)) + var/deadline = world.time + 10 SECONDS + while(world.time < deadline && lookout_ai.stealth_state() != "alert") + sleep(1) + TEST_ASSERT_EQUAL(lookout_ai.stealth_state(), "alert", "The lookout never saw through someone in its colours holding a gun") + TEST_ASSERT(lookout_ai.made?[key] > world.time, "The lookout doesn't remember who it saw through") + TEST_ASSERT(near_ai.made?[key] > world.time, "The guard in earshot of the shout wasn't told who it was") + TEST_ASSERT(!far_radio_ai.made?[key], "The guard on the radio knew before the call went out") + TEST_ASSERT(!far_plain_ai.stealth_knows(person), "A wary guard nobody told knew the disguise") + deadline = world.time + 10 SECONDS + while(world.time < deadline && !far_radio_ai.made?[key]) + sleep(1) + TEST_ASSERT(far_radio_ai.made?[key] > world.time, "The radio call didn't tell the guard on the radio who it was") + TEST_ASSERT(!far_plain_ai.made?[key], "A wary guard neither the shout nor the radio reached knew the disguise") + +/// The real AI: an alert gunner loses someone round a corner. It goes to where it last saw them, never toward where +/// they are now, and drops to a search there. +/datum/unit_test/voidcrew_stealth_live/d44_lost_corner + +/datum/unit_test/voidcrew_stealth_live/d44_lost_corner/Run() + TEST_ASSERT(make_room(16, 9), "No room for the test") + // A wall up from the corner tile's west side, and one across the east part of the room: the far corner is + // reached only round the gap at the east end, and seen from neither the guard's side nor the corner. + for(var/dy in 2 to 8) + var/turf/wall_spot = at(8, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + for(var/dx in 9 to 13) + var/turf/wall_spot = at(dx, 4) + wall_spot.ChangeTurf(/turf/closed/wall) + var/turf/corner = at(9, 1) + var/mob/living/carbon/human/person = person_at(9, 1) + var/mob/living/carbon/human/npc/guard = npc_at(STEALTH_TEST_GUNNER, 4, 1, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = wake(guard) + guard_ai.stealth_go_alert(person) + sleep(2 SECONDS) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "alert", "The guard isn't alert on someone in plain sight") + TEST_ASSERT_EQUAL(guard_ai.last_seen_turf, corner, "The guard didn't note where it saw them") + // Round the corner and away. + person.forceMove(at(10, 7)) + TEST_ASSERT(!can_see(guard, person, 9), "The test's walls don't hide the far corner from the guard") + var/chased = FALSE + var/strayed = FALSE + var/reached = FALSE + // One plan to catch up: a walk at them from the moment before they moved isn't a chase. + var/settled_at = world.time + 1 SECONDS + var/deadline = world.time + 10 SECONDS + while(world.time < deadline && guard_ai.stealth_state() == "alert") + if(world.time >= settled_at && guard_ai.current_movement_target == person) + chased = TRUE + if(guard.x > corner.x + 2 || guard.y > corner.y + 2) + strayed = TRUE + if(get_dist(guard, corner) <= 1) + reached = TRUE + sleep(1) + TEST_ASSERT(!chased, "A guard that lost someone round a corner walked at where they are now") + TEST_ASSERT(!strayed, "A guard that lost someone round a corner went past where it last saw them") + TEST_ASSERT(reached, "A guard that lost someone round a corner didn't go to where it last saw them (it is [get_dist(guard, corner)] tiles off)") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "searching", "A guard that lost someone round a corner isn't searching") + TEST_ASSERT_EQUAL(guard_ai.last_seen_turf, corner, "The guard searches somewhere it never saw them") + +/// The real AI: an alert gunner behind glass can't shoot someone unlit six tiles off, and loses them. Lit, it shoots. +/datum/unit_test/voidcrew_stealth_live/d44_dark_shot + +/datum/unit_test/voidcrew_stealth_live/d44_dark_shot/Run() + TEST_ASSERT(make_room(14, 5), "No room for the test") + // A glass wall beside it: in sight, out of reach, so the guard can't walk up into its dark sight. + for(var/dy in 0 to 4) + allocate(/obj/structure/window/reinforced/fulltile, at(2, dy)) + var/list/dark_spots = list() + for(var/dx in 3 to 13) + for(var/dy in 0 to 4) + var/turf/spot = at(dx, dy) + GLOB.stealth_test_dark_turfs[spot] = TRUE + dark_spots += spot + var/mob/living/carbon/human/person = person_at(6, 2) + var/mob/living/carbon/human/npc/guard = npc_at(STEALTH_TEST_GUNNER, 0, 2, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = wake(guard) + guard_ai.stealth_go_alert(person) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "alert", "The guard didn't go alert") + var/shot_in_dark = FALSE + var/deadline = world.time + 7 SECONDS + while(world.time < deadline) + if(guard_ai.blackboard["human_npc_next_shot"]) + shot_in_dark = TRUE + sleep(1) + TEST_ASSERT(!shot_in_dark, "An alert guard shot at someone unlit six tiles off") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "searching", "An alert guard didn't lose someone unlit six tiles off") + // The lights come on: it sees them and shoots. + for(var/turf/spot as anything in dark_spots) + GLOB.stealth_test_dark_turfs[spot] = FALSE + deadline = world.time + 20 SECONDS + while(world.time < deadline && !guard_ai.blackboard["human_npc_next_shot"]) + sleep(2) + TEST_ASSERT(guard_ai.blackboard["human_npc_next_shot"], "The guard never shot at someone lit six tiles off (state [guard_ai.stealth_state()]): the test can't tell the dark from a guard that doesn't shoot") + +#undef STEALTH_TEST_GUNNER +#undef STEALTH_TEST_LOOKOUT diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_d45.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_d45.dm new file mode 100644 index 00000000000..ccfab0450c0 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_d45.dm @@ -0,0 +1,268 @@ +// Decision 45: the stealth head shot graded by the round and the head's protection, shields and shots in the back, and +// the throat cut from behind (voidcrew/modules/stealth/stealth_crits.dm, hyperviolence/overlays_exec/knife_executions.dm, +// voidcrew/edits/objects/items/shield_rear.dm, voidcrew/edits/datums/neck_slice_mute.dm). Unit tests compile before +// voidcrew/_DEFINES, so values are written out: STEALTH_HEAD_SHOT_BRAIN_DAMAGE 120, STEALTH_CALL_ALARM 3. + +/// A gun of `gun_type` in `shooter`'s hand, aimed at the head. +/datum/unit_test/proc/d45_arm(mob/living/carbon/human/shooter, gun_type, suppressed = FALSE) + var/obj/item/gun/ballistic/gun = allocate(gun_type) + gun.can_misfire = FALSE + if(suppressed) + gun.install_suppressor(new /obj/item/suppressor(gun)) + shooter.put_in_active_hand(gun, forced = TRUE) + shooter.zone_selected = BODY_ZONE_HEAD + return gun + +/// A bare-headed guard (no helmet, no mask) at (dx, dy), facing east. +/datum/unit_test/proc/d45_bare_guard(datum/turf_reservation/block, dx, dy) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, dx, dy) + if(guard.head) + qdel(guard.head) + if(guard.wear_mask) + qdel(guard.wear_mask) + return guard + +/// Puts `helmet_type` on `guard`. +/datum/unit_test/proc/d45_helmet(mob/living/carbon/human/guard, helmet_type) + var/obj/item/clothing/helmet = new helmet_type(guard) + TEST_ASSERT(guard.equip_to_slot_if_possible(helmet, ITEM_SLOT_HEAD, disable_warning = TRUE), "Couldn't put [helmet] on the guard") + +/// (a) A .357 to the back of an unaware guard's bare head bursts it: no head, dead. +/datum/unit_test/voidcrew_stealth_d45_burst + +/datum/unit_test/voidcrew_stealth_d45_burst/Run() + var/datum/turf_reservation/block = stealth_block(8, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = d45_bare_guard(block, 4, 2) + var/mob/living/carbon/human/person = stealth_person(block, 3, 2) + var/obj/item/gun/gun = d45_arm(person, /obj/item/gun/ballistic/revolver) + gun.fire_gun(guard, person, TRUE, null) + TEST_ASSERT_NULL(guard.get_bodypart(BODY_ZONE_HEAD), "A .357 to an unaware guard's bare head didn't burst it") + TEST_ASSERT_EQUAL(guard.stat, DEAD, "A guard whose head burst is alive") + qdel(block) + +/// (b) A suppressed 9mm to an unaware guard's bare head: through the skull, brain damage, a heavy bleed, out cold. A +/// .357 to a guard with Dermal Mesh is stepped down to the same. +/datum/unit_test/voidcrew_stealth_d45_down + +/datum/unit_test/voidcrew_stealth_d45_down/Run() + var/datum/turf_reservation/block = stealth_block(8, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = d45_bare_guard(block, 4, 2) + var/mob/living/carbon/human/person = stealth_person(block, 3, 2) + var/obj/item/gun/gun = d45_arm(person, /obj/item/gun/ballistic/automatic/pistol, suppressed = TRUE) + gun.fire_gun(guard, person, TRUE, null) + var/obj/item/bodypart/head = guard.get_bodypart(BODY_ZONE_HEAD) + TEST_ASSERT_NOTNULL(head, "A suppressed 9mm burst a head") + TEST_ASSERT_NOTNULL(head.get_wound_type(/datum/wound/pierce/bleed/critical/hv_head_shot), "A suppressed 9mm head shot left no wound through the skull") + TEST_ASSERT(guard.get_organ_loss(ORGAN_SLOT_BRAIN) >= 120, "The head shot did too little brain damage ([guard.get_organ_loss(ORGAN_SLOT_BRAIN)])") + TEST_ASSERT(guard.IsUnconscious(), "The guard shot through the head isn't out cold") + TEST_ASSERT(guard.stat >= UNCONSCIOUS, "The guard shot through the head is still conscious") + TEST_ASSERT(guard.get_bleed_rate() >= 5, "The head shot doesn't bleed heavily ([guard.get_bleed_rate()])") + // Dermal Mesh (physiology armour, as the implant applies it) steps a .357 down from a burst to the same. + var/mob/living/carbon/human/npc/meshed = d45_bare_guard(block, 4, 4) + meshed.physiology.armor = meshed.physiology.armor.add_other_armor(/datum/armor/cyberware_dermal_mesh) + var/mob/living/carbon/human/second = stealth_person(block, 3, 4) + gun = d45_arm(second, /obj/item/gun/ballistic/revolver) + gun.fire_gun(meshed, second, TRUE, null) + head = meshed.get_bodypart(BODY_ZONE_HEAD) + TEST_ASSERT_NOTNULL(head, "Dermal Mesh didn't step a .357 down from a burst") + TEST_ASSERT_NOTNULL(head.get_wound_type(/datum/wound/pierce/bleed/critical/hv_head_shot), "A .357 through Dermal Mesh didn't go through the skull") + qdel(block) + +/// (c) A 9mm into a SWAT helmet: knocked out for a few seconds, no wound through the skull. A heavy helmet stops it: only +/// the hit. An alert guard and an ordinary person: only the hit. +/datum/unit_test/voidcrew_stealth_d45_helmet + +/datum/unit_test/voidcrew_stealth_d45_helmet/Run() + var/datum/turf_reservation/block = stealth_block(8, 7) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = d45_bare_guard(block, 4, 1) + d45_helmet(guard, /obj/item/clothing/head/helmet/swat) + var/mob/living/carbon/human/person = stealth_person(block, 3, 1) + var/obj/item/gun/gun = d45_arm(person, /obj/item/gun/ballistic/automatic/pistol) + gun.fire_gun(guard, person, TRUE, null) + var/obj/item/bodypart/head = guard.get_bodypart(BODY_ZONE_HEAD) + TEST_ASSERT_NOTNULL(head, "A 9mm burst a helmeted head") + TEST_ASSERT_NULL(head.get_wound_type(/datum/wound/pierce/bleed/critical/hv_head_shot), "A 9mm went through a SWAT helmet") + TEST_ASSERT(guard.IsUnconscious(), "A 9mm into a SWAT helmet didn't knock the guard out") + TEST_ASSERT(guard.AmountUnconscious() <= 8 SECONDS, "The helmet knockout is too long ([guard.AmountUnconscious()])") + // A heavy helmet (bullet 60): just the hit. + var/mob/living/carbon/human/npc/heavy = d45_bare_guard(block, 4, 3) + d45_helmet(heavy, /obj/item/clothing/head/helmet/alt) + var/mob/living/carbon/human/second = stealth_person(block, 3, 3) + gun = d45_arm(second, /obj/item/gun/ballistic/automatic/pistol) + gun.fire_gun(heavy, second, TRUE, null) + TEST_ASSERT(!heavy.IsUnconscious(), "A 9mm into a heavy helmet knocked the guard out") + TEST_ASSERT(heavy.getBruteLoss() > 0, "Test fixture: the shot into the heavy helmet missed") + // An alert guard, bare headed: just the hit. + var/mob/living/carbon/human/npc/alert = d45_bare_guard(block, 4, 5) + var/datum/ai_controller/basic_controller/human_npc/stealth/alert_ai = stealth_ai(alert) + var/mob/living/carbon/human/third = stealth_person(block, 3, 5) + alert_ai.stealth_go_alert(third) + alert_ai.stealth_rewind(1) + gun = d45_arm(third, /obj/item/gun/ballistic/automatic/pistol) + gun.fire_gun(alert, third, TRUE, null) + TEST_ASSERT(!alert.IsUnconscious(), "An alert guard was knocked out by a head shot") + TEST_ASSERT_NULL(alert.get_bodypart(BODY_ZONE_HEAD)?.get_wound_type(/datum/wound/pierce/bleed/critical/hv_head_shot), "An alert guard was shot through the skull") + // An ordinary person: just the hit. + var/mob/living/carbon/human/victim = stealth_person(block, 6, 1) + victim.setDir(EAST) + var/mob/living/carbon/human/fourth = stealth_person(block, 5, 2) + fourth.forceMove(stealth_at(block, 5, 1)) + gun = d45_arm(fourth, /obj/item/gun/ballistic/automatic/pistol) + gun.fire_gun(victim, fourth, TRUE, null) + TEST_ASSERT(!victim.IsUnconscious(), "A person was knocked out by a stealth head shot") + TEST_ASSERT_NULL(victim.get_bodypart(BODY_ZONE_HEAD)?.get_wound_type(/datum/wound/pierce/bleed/critical/hv_head_shot), "A person was shot through the skull") + qdel(block) + +/// A held shield stops a shot from the front, never one in the back. +/datum/unit_test/voidcrew_stealth_d45_shield + +/datum/unit_test/voidcrew_stealth_d45_shield/Run() + var/datum/turf_reservation/block = stealth_block(8, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/holder = stealth_person(block, 4, 2) + var/obj/item/shield/riot/shield = allocate(/obj/item/shield/riot) + shield.block_chance = 200 + holder.put_in_hands(shield, forced = TRUE) + holder.setDir(EAST) + // From the front: blocked. + var/mob/living/carbon/human/front = stealth_person(block, 5, 2) + var/obj/item/gun/gun = d45_arm(front, /obj/item/gun/ballistic/automatic/pistol) + front.zone_selected = BODY_ZONE_CHEST + holder.setDir(EAST) + gun.fire_gun(holder, front, TRUE, null) + TEST_ASSERT_EQUAL(holder.getBruteLoss(), 0, "A shield didn't stop a shot from the front") + // From behind: through. + var/mob/living/carbon/human/back = stealth_person(block, 3, 2) + gun = d45_arm(back, /obj/item/gun/ballistic/automatic/pistol) + back.zone_selected = BODY_ZONE_CHEST + holder.setDir(EAST) + gun.fire_gun(holder, back, TRUE, null) + TEST_ASSERT(holder.getBruteLoss() > 0, "A shield stopped a shot in the back") + TEST_ASSERT(!holder.vc_shot_in_back, "The shot-in-the-back mark stayed on after the shot") + qdel(block) + +/// The backstab (one path for every sharp knife, the knife execution): from behind on an unaware guard it goes for the +/// throat whatever is aimed at, and the cut is tg's critical slash and neck_slice; the guard can't speak. Not from the +/// front, not a blunt blade, not through a SWAT helmet, not when held in a grab (tg's own slit). The mute goes with the +/// cut. An unaware guard is cut on the click itself, with no hold (decision 45 amended): a patrolling guard would walk out +/// of a 1.5 s hold. A helpless guard still gets the hold. +/datum/unit_test/voidcrew_stealth_d45_backstab + +/datum/unit_test/voidcrew_stealth_d45_backstab/Run() + var/datum/turf_reservation/block = stealth_block(8, 7) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = d45_bare_guard(block, 4, 1) + var/mob/living/carbon/human/person = stealth_person(block, 3, 1) + var/obj/item/knife/combat/knife = allocate(/obj/item/knife/combat) + person.put_in_active_hand(knife, forced = TRUE) + person.set_combat_mode(TRUE) + person.zone_selected = BODY_ZONE_CHEST + // From the front: no backstab. + person.forceMove(stealth_at(block, 5, 1)) + TEST_ASSERT(!knife.hv_knife_execution_possible(person, guard), "The knife backstabs from the front") + person.forceMove(stealth_at(block, 3, 1)) + TEST_ASSERT(knife.hv_knife_execution_possible(person, guard), "The knife doesn't backstab an unaware guard from behind with the chest aimed at") + TEST_ASSERT(knife.hv_knife_execution_instant(person, guard), "An unaware guard from behind waits for the hold") + // The cut lands on the click, no hold. + knife.melee_attack_chain(person, guard, list()) + TEST_ASSERT(!DOING_INTERACTION(person, "hv_knife_execution"), "The backstab on an unaware guard started a hold") + TEST_ASSERT(guard.has_status_effect(/datum/status_effect/neck_slice), "A backstab didn't cut the throat on the click") + var/obj/item/bodypart/head = guard.get_bodypart(BODY_ZONE_HEAD) + var/critical_slash = FALSE + for(var/datum/wound/cut as anything in head.wounds) + if(istype(cut, /datum/wound/slash) && cut.severity == WOUND_SEVERITY_CRITICAL) + critical_slash = TRUE + TEST_ASSERT(critical_slash, "A backstab left no critical slash on the head") + TEST_ASSERT_EQUAL(knife.hv_knife_exec_spray, 2, "A cut throat didn't spray the most blood") + TEST_ASSERT(HAS_TRAIT(guard, TRAIT_MUTE), "A cut throat isn't mute") + TEST_ASSERT(!guard.can_speak(), "A guard with a cut throat can speak") + TEST_ASSERT(!knife.hv_knife_execution_possible(person, guard), "A cut throat can be cut again") + guard.remove_status_effect(/datum/status_effect/neck_slice) + TEST_ASSERT(!HAS_TRAIT(guard, TRAIT_MUTE), "The mute stayed after the cut") + // Any sharp-edged knife backstabs; a blunt one doesn't. + var/mob/living/carbon/human/npc/second = d45_bare_guard(block, 4, 3) + var/mob/living/carbon/human/stabber = stealth_person(block, 3, 3) + var/obj/item/knife/combat/blade = allocate(/obj/item/knife/combat) + stabber.put_in_active_hand(blade, forced = TRUE) + stabber.set_combat_mode(TRUE) + stabber.zone_selected = BODY_ZONE_CHEST + TEST_ASSERT(blade.hv_knife_execution_possible(stabber, second), "A plain combat knife doesn't backstab") + // A helpless guard taken from the front keeps the hold. + stabber.forceMove(stealth_at(block, 5, 3)) + stabber.zone_selected = BODY_ZONE_HEAD + second.Knockdown(30 SECONDS) + TEST_ASSERT(blade.hv_knife_execution_possible(stabber, second), "A knife can't execute a helpless guard from the front") + TEST_ASSERT(!blade.hv_knife_execution_instant(stabber, second), "A helpless guard from the front was cut without the hold") + second.SetKnockdown(0) + stabber.forceMove(stealth_at(block, 3, 3)) + stabber.zone_selected = BODY_ZONE_CHEST + var/obj/item/knife/plastic/spork = allocate(/obj/item/knife/plastic) + if(!(spork.get_sharpness() & SHARP_EDGED) || spork.force <= 0) + TEST_ASSERT(!spork.hv_knife_execution_possible(stabber, second), "A blunt plastic knife backstabs") + // A SWAT helmet (wound 15): tg's wound maths keeps the critical slash out; an ordinary stab to the head. + var/mob/living/carbon/human/npc/helmeted = d45_bare_guard(block, 4, 5) + d45_helmet(helmeted, /obj/item/clothing/head/helmet/swat) + var/mob/living/carbon/human/third = stealth_person(block, 3, 5) + var/obj/item/knife/combat/other_knife = allocate(/obj/item/knife/combat) + third.put_in_active_hand(other_knife, forced = TRUE) + third.set_combat_mode(TRUE) + TEST_ASSERT(!other_knife.slit_gets_through(helmeted, helmeted.get_bodypart(BODY_ZONE_HEAD)), "A slit got through a SWAT helmet") + TEST_ASSERT(other_knife.hv_finish_knife_execution(third, helmeted, list(), list()), "The stab at a helmeted guard didn't land") + TEST_ASSERT(!helmeted.has_status_effect(/datum/status_effect/neck_slice), "A helmeted guard's throat was cut") + TEST_ASSERT(helmeted.get_bodypart(BODY_ZONE_HEAD).brute_dam > 0, "The stab at a protected throat did nothing") + TEST_ASSERT(other_knife.hv_knife_exec_spray < 2, "A protected throat sprayed like a cut one") + TEST_ASSERT(helmeted.can_speak(), "A guard whose throat was protected can't speak") + // Held in an aggressive grab: tg's own slit, not this one. + var/mob/living/carbon/human/npc/held = d45_bare_guard(block, 6, 5) + third.forceMove(stealth_at(block, 5, 5)) + third.start_pulling(held, supress_message = TRUE) + third.setGrabState(GRAB_AGGRESSIVE) + TEST_ASSERT(!other_knife.hv_knife_execution_possible(third, held), "The backstab took over tg's grab slit") + third.stop_pulling() + qdel(block) + +/// A lookout with a cut throat makes no radio call and no shout; one with its throat whole does. +/datum/unit_test/voidcrew_stealth_d45_quiet + var/says = 0 + +/datum/unit_test/voidcrew_stealth_d45_quiet/proc/on_say(datum/source) + SIGNAL_HANDLER + says++ + +/datum/unit_test/voidcrew_stealth_d45_quiet/Run() + var/datum/turf_reservation/block = stealth_block(8, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/obj/effect/landmark/stealth_group/marker = allocate(/obj/effect/landmark/stealth_group, stealth_at(block, 6, 4)) + var/datum/stealth_group/group = marker.group + var/mob/living/carbon/human/npc/cut = allocate(/mob/living/carbon/human/npc/ruin/trooper/scav/lookout, stealth_at(block, 2, 2)) + var/mob/living/carbon/human/npc/whole = allocate(/mob/living/carbon/human/npc/ruin/trooper/scav/lookout, stealth_at(block, 5, 2)) + var/datum/ai_controller/basic_controller/human_npc/stealth/cut_ai = cut.ai_controller + var/datum/ai_controller/basic_controller/human_npc/stealth/whole_ai = whole.ai_controller + cut_ai.stealth_setup() + whole_ai.stealth_setup() + TEST_ASSERT(cut_ai.group == group && whole_ai.group == group, "Test fixture: the lookouts aren't in the marker's group") + TEST_ASSERT(cut.stealth_radio_ready() && whole.stealth_radio_ready(), "Test fixture: a lookout's earpiece doesn't work") + cut.apply_status_effect(/datum/status_effect/neck_slice) + TEST_ASSERT(HAS_TRAIT(cut, TRAIT_MUTE), "Test fixture: no throat wound to keep the cut") + var/turf/spot = stealth_at(block, 1, 1) + // The cut throat. + RegisterSignal(cut, COMSIG_MOB_SAY, PROC_REF(on_say)) + TEST_ASSERT(!cut_ai.stealth_shout(), "A guard with a cut throat shouted") + TEST_ASSERT(!cut_ai.stealth_start_call(3, spot), "A guard with a cut throat reached for its earpiece") + cut_ai.pending_call = list(3, spot, world.time, null) + group.next_radio_alarm = 0 + cut_ai.stealth_deliver_call() + TEST_ASSERT_EQUAL(group.next_radio_alarm, 0, "A guard with a cut throat made a radio call") + TEST_ASSERT_EQUAL(says, 0, "A guard with a cut throat said something") + UnregisterSignal(cut, COMSIG_MOB_SAY) + // The whole throat, the same way. + RegisterSignal(whole, COMSIG_MOB_SAY, PROC_REF(on_say)) + whole_ai.pending_call = list(3, spot, world.time, null) + whole_ai.stealth_deliver_call() + TEST_ASSERT(group.next_radio_alarm > 0, "Test fixture: the lookout with a whole throat made no radio call") + TEST_ASSERT(says > 0, "Test fixture: the lookout with a whole throat said nothing") + UnregisterSignal(whole, COMSIG_MOB_SAY) + qdel(block) diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_den.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_den.dm new file mode 100644 index 00000000000..251c1f79f6a --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_den.dm @@ -0,0 +1,171 @@ +// Stealth step 4: the scav den (voidcrew/modules/stealth/scav_den.dm, scav_camera.dm). Unit tests compile before +// voidcrew/_DEFINES, so values are written out: ACCESS_SCAV_VAULT "scav_vault", ZONE_GREEN/YELLOW/RED 1/2/3, camera +// states SCAN 1, TRACK 2, ALARM 3, OFF 4. + +/// Den guards carry a person's name, their pass is in it, and their friends can call them by it. The boss's pass opens the vault. +/datum/unit_test/voidcrew_stealth_den_names + +/datum/unit_test/voidcrew_stealth_den_names/Run() + for(var/guard_type in list(/mob/living/carbon/human/npc/ruin/trooper/scav/den, /mob/living/carbon/human/npc/ruin/trooper/scav/gunner/den, /mob/living/carbon/human/npc/ruin/trooper/scav/lookout/den)) + var/mob/living/carbon/human/npc/guard = allocate(guard_type, run_loc_floor_bottom_left) + TEST_ASSERT(guard.real_name && guard.real_name != "Scav Guard" && guard.real_name != "Scav Lookout", "[guard_type] has no name of its own ([guard.real_name])") + TEST_ASSERT_NOTNULL(stealth_first_name(guard), "[guard_type]'s friends can't call it by name") + var/obj/item/card/id/card = guard.wear_id?.GetID() + TEST_ASSERT(istype(card, /obj/item/card/id/advanced/black/scav), "[guard_type] has no scav pass") + TEST_ASSERT_EQUAL(card.registered_name, guard.real_name, "[guard_type]'s pass is in someone else's name") + var/mob/living/carbon/human/npc/boss = allocate(/mob/living/carbon/human/npc/ruin/trooper/scav/lookout/den/boss, run_loc_floor_bottom_left) + var/obj/item/card/id/boss_card = boss.wear_id?.GetID() + TEST_ASSERT(istype(boss_card, /obj/item/card/id/advanced/black/scav/vault), "The den boss has no vault pass") + TEST_ASSERT(("scav_vault" in boss_card.access) && ("scav" in boss_card.access), "The vault pass doesn't open the vault and the den") + TEST_ASSERT_EQUAL(boss_card.registered_name, boss.real_name, "The boss's pass is in someone else's name") + TEST_ASSERT(boss.stealth_radio, "The den boss has no radio") + +/// The vault rolls cyberware by zone, never the same piece twice, plus one piece of stealth gear from its hook. +/datum/unit_test/voidcrew_stealth_den_vault + +/datum/unit_test/voidcrew_stealth_den_vault/Run() + var/list/expected = list(2, 3, 4) + for(var/zone in 1 to 3) + var/obj/structure/closet/crate/secure/scav_vault/crate = allocate(/obj/structure/closet/crate/secure/scav_vault, run_loc_floor_bottom_left) + var/list/made = crate.scav_vault_roll(zone) + TEST_ASSERT_EQUAL(length(made), expected[zone] + 1, "A zone [zone] vault paid the wrong number of pieces") + var/list/seen = list() + var/stealth_pieces = 0 + for(var/obj/item/piece as anything in made) + if(crate.scav_vault_stealth_loot()[piece.type]) + stealth_pieces++ + continue + TEST_ASSERT(istype(piece, /obj/item/organ), "A vault paid [piece.type], which isn't chrome") + TEST_ASSERT(!seen[piece.type], "A vault paid [piece.type] twice") + seen[piece.type] = TRUE + TEST_ASSERT_EQUAL(piece.loc, crate, "A vault piece landed outside the crate") + TEST_ASSERT_EQUAL(stealth_pieces, 1, "A vault didn't pay one piece of stealth gear") + var/obj/structure/closet/crate/secure/scav_vault/locked = allocate(/obj/structure/closet/crate/secure/scav_vault, run_loc_floor_bottom_left) + TEST_ASSERT(locked.locked, "The vault crate isn't locked") + TEST_ASSERT("scav_vault" in locked.req_access, "The vault crate doesn't want the vault pass") + +/// The tip points at a registered den in the contested lanes, and a sealed den chart won't open while a den is out there. +/datum/unit_test/voidcrew_stealth_den_chart + +/datum/unit_test/voidcrew_stealth_den_chart/Run() + var/datum/map_template/ruin/space/template + for(var/template_name in SSmapping.space_ruins_templates) + var/datum/map_template/ruin/space/candidate = SSmapping.space_ruins_templates[template_name] + if(candidate.type == /datum/map_template/ruin/space/rare/scav_den) + template = candidate + TEST_ASSERT_NOTNULL(template, "The scav den template isn't registered") + TEST_ASSERT(template.width && template.height, "The scav den map didn't load its size") + TEST_ASSERT(template.unpickable, "The scav den can seed by itself") + TEST_ASSERT_EQUAL(/datum/shop_sku/ruin_chart/scav_den::spawn_zone, 2, "The den tip doesn't point at the contested lanes") + TEST_ASSERT_EQUAL(/datum/shop_sku/ruin_chart/scav_den::chart_type, /datum/rumor_chart/scav_den, "The den tip uploads a chart that ignores the one-den rule") + TEST_ASSERT_NULL(scav_den_on_map(), "A den is on the map before any was revealed") + var/obj/structure/overmap/space_ruin/den = allocate(/obj/structure/overmap/space_ruin, run_loc_floor_bottom_left) + den.set_ruin_template(template) + TEST_ASSERT_EQUAL(scav_den_on_map(), den, "A den on the map isn't found") + var/datum/rumor_chart/scav_den/chart = allocate(/datum/rumor_chart/scav_den) + chart.ruin_template_path = /datum/map_template/ruin/space/rare/scav_den + chart.spawn_zone = 2 + TEST_ASSERT_NULL(chart.reveal(null), "A second den opened while one was out there") + TEST_ASSERT(!chart.revealed, "A refused den chart was used up") + // A revealed den is never a contract's site (a held den would rebuild with a fresh vault). + scav_den_claim(den) + TEST_ASSERT(den.mission_exclusive, "A revealed den can be held by a contract") + // Nobody docked within the hour: it leaves and frees the slot. + scav_den_move_on(WEAKREF(den)) + TEST_ASSERT(QDELETED(den), "An unvisited den stayed on the overmap") + TEST_ASSERT_NULL(scav_den_on_map(), "A den that moved on still holds the slot") + +/// The camera sees a person in its cone in light, not in the dark, not out of its cone, not through a wall, and lets a +/// scav disguise by; held on someone long enough it sounds the alarm, and the den's guard goes to look. +/datum/unit_test/voidcrew_stealth_live/den_camera + +/datum/unit_test/voidcrew_stealth_live/den_camera/Run() + TEST_ASSERT(make_room(11, 9), "No room for the test") + allocate(/obj/effect/landmark/stealth_group, at(0, 0)) + // Hung on the north wall, looking south. + var/obj/machinery/scav_camera/camera = allocate(/obj/machinery/scav_camera/directional/north, at(5, 8)) + var/turf/eye = get_turf(camera) + TEST_ASSERT_EQUAL(camera.aim, 180, "A camera hung on the north wall doesn't look south") + var/mob/living/carbon/human/person = person_at(5, 4) + TEST_ASSERT(camera.scav_cam_sees(person, eye), "The camera doesn't see a person in front of it") + GLOB.stealth_test_dark_turfs[get_turf(person)] = TRUE + TEST_ASSERT(!camera.scav_cam_sees(person, eye), "The camera sees a person standing in the dark") + GLOB.stealth_test_dark_turfs[get_turf(person)] = FALSE + person.forceMove(at(10, 7)) + TEST_ASSERT(!camera.scav_cam_sees(person, eye), "The camera sees a person off to its side") + person.forceMove(at(5, 4)) + var/turf/wall_spot = at(5, 6) + wall_spot.ChangeTurf(/turf/closed/wall) + TEST_ASSERT(!camera.scav_cam_sees(person, eye), "The camera sees through a wall") + wall_spot.ChangeTurf(/turf/open/floor/iron) + GLOB.stealth_test_dark_turfs[wall_spot] = FALSE + var/obj/item/clothing/under/syndicate/scav/fatigues = allocate(/obj/item/clothing/under/syndicate/scav) + var/obj/item/clothing/mask/balaclava/scav/mask = allocate(/obj/item/clothing/mask/balaclava/scav) + var/obj/item/clothing/under/own_clothes = person.w_uniform + if(own_clothes) + person.temporarilyRemoveItemFromInventory(own_clothes, force = TRUE) + person.equip_to_slot_if_possible(fatigues, ITEM_SLOT_ICLOTHING, disable_warning = TRUE) + person.equip_to_slot_if_possible(mask, ITEM_SLOT_MASK, disable_warning = TRUE) + var/datum/component/stealth_disguise/cache = stealth_disguise_cache(person) + cache.refresh() + TEST_ASSERT(!camera.scav_cam_sees(person, eye), "The camera doesn't let a scav disguise by") + person.temporarilyRemoveItemFromInventory(mask, force = TRUE) + cache.refresh() + TEST_ASSERT(camera.scav_cam_sees(person, eye), "The camera lets fatigues alone by") + + // The alarm. + var/mob/living/carbon/human/npc/guard = guard_at(1, 1, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = wake(guard) + sleep(1 SECONDS) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "The guard isn't unaware before the alarm") + person.forceMove(at(5, 4)) + for(var/tick in 1 to 15) + camera.process(0.2) + if(camera.cam_state == 3) + break + TEST_ASSERT_EQUAL(camera.cam_state, 3, "Two seconds in plain view didn't sound the camera's alarm") + var/deadline = world.time + 5 SECONDS + while(guard_ai.stealth_state() == "unaware" && world.time < deadline) + sleep(1) + TEST_ASSERT(guard_ai.stealth_state() != "unaware", "The den's guard didn't answer the camera's alarm") + + // An EMP shuts it off and hides its cone. + camera.emp_act(EMP_LIGHT) + TEST_ASSERT_EQUAL(camera.cam_state, 4, "An EMP didn't shut the camera off") + TEST_ASSERT_EQUAL(camera.cone.alpha, 0, "An EMP'd camera still shows its cone") + +/// The den's harvester gang: every outfit keeps the disguise set reachable (scav fatigues showing, the mask slot free for +/// the balaclava, its suit read as a guard's own), and no den guard carries Syndicate kit. Their fatigues are loot, the +/// rest stays locked. They have red chrome eyes, and a harvester's apron, gloves and blade are bloodied. +/datum/unit_test/voidcrew_stealth_den_look + +/datum/unit_test/voidcrew_stealth_den_look/Run() + var/list/suits = stealth_guard_suits() + for(var/table_type in list(/datum/human_npc_outfit_table/ruin/scav_den, /datum/human_npc_outfit_table/ruin/scav_den/gunner, /datum/human_npc_outfit_table/ruin/scav_den/boss)) + var/datum/human_npc_outfit_table/table = human_npc_singleton(table_type) + for(var/list/outfits in list(table.green, table.yellow, table.red)) + for(var/datum/outfit/outfit as anything in outfits) + TEST_ASSERT_NULL(initial(outfit.mask), "[outfit] takes the mask slot the balaclava needs") + var/obj/item/clothing/suit/suit = initial(outfit.suit) + if(suit) + TEST_ASSERT(!(initial(suit.flags_inv) & HIDEJUMPSUIT), "[outfit]'s suit hides the fatigues") + TEST_ASSERT(suits[suit], "[outfit]'s suit isn't read as a guard's own") + for(var/hand in list(initial(outfit.r_hand), initial(outfit.l_hand))) + TEST_ASSERT(!ispath(hand, /obj/item/melee/energy) && !ispath(hand, /obj/item/shield/energy), "[outfit] still carries Syndicate kit") + for(var/guard_type in list(/mob/living/carbon/human/npc/ruin/trooper/scav/den, /mob/living/carbon/human/npc/ruin/trooper/scav/gunner/den, /mob/living/carbon/human/npc/ruin/trooper/scav/lookout/den, /mob/living/carbon/human/npc/ruin/trooper/scav/lookout/den/boss)) + var/mob/living/carbon/human/npc/guard = allocate(guard_type, run_loc_floor_bottom_left) + TEST_ASSERT(istype(guard.w_uniform, /obj/item/clothing/under/syndicate/scav), "[guard_type] isn't in scav fatigues") + TEST_ASSERT(!HAS_TRAIT(guard.w_uniform, TRAIT_NO_STRIP), "[guard_type]'s fatigues are locked to it") + if(guard.wear_suit) + TEST_ASSERT(HAS_TRAIT(guard.wear_suit, TRAIT_NO_STRIP), "[guard_type]'s [guard.wear_suit] can be looted") + var/obj/item/organ/eyes/eyes = guard.get_organ_slot(ORGAN_SLOT_EYES) + TEST_ASSERT(istype(eyes, /obj/item/organ/eyes/robotic), "[guard_type] has no chrome eyes") + TEST_ASSERT_EQUAL(eyes.eye_color_left, "#ff2a1a", "[guard_type]'s chrome eyes aren't red") + var/mob/living/carbon/human/consistent/butcher = allocate(/mob/living/carbon/human/consistent, run_loc_floor_bottom_left) + butcher.equipOutfit(/datum/outfit/ruin_npc/scav_den/butcher/saw) + TEST_ASSERT(istype(butcher.wear_suit, /obj/item/clothing/suit/apron/waders), "The harvester has no waders") + TEST_ASSERT(GET_ATOM_BLOOD_DNA_LENGTH(butcher.wear_suit), "The harvester's apron is clean") + TEST_ASSERT(GET_ATOM_BLOOD_DNA_LENGTH(butcher.gloves), "The harvester's gloves are clean") + var/obj/item/circular_saw/cruel/saw = locate() in butcher.held_items + TEST_ASSERT_NOTNULL(saw, "The harvester has no saw") + TEST_ASSERT(GET_ATOM_BLOOD_DNA_LENGTH(saw), "The harvester's saw is clean") diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_disguise.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_disguise.dm new file mode 100644 index 00000000000..63c6c49e2a0 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_disguise.dm @@ -0,0 +1,519 @@ +// Stealth guards, decision 40: disguises (voidcrew/modules/stealth/stealth_disguise.dm). Values from voidcrew/_DEFINES are +// written out: pieces mask 1, clothing 2, pass 4; fill x0.5 clothing, x0.25 with a mask, x0.05 the whole set inside near +// range (4) and 0 beyond; challenge range 5 / 3 / 2; the pass is read for 2 s, asked for again at 3 s, blown at 6 s; +// more than 2 tiles from where they were stopped is walking off. States and bark kinds are written as text. +// The tests down to voidcrew_stealth_disguise_loot call the scan directly; the voidcrew_stealth_live ones run the real AI. + +/// Puts the scavs' own things on `person`: the fatigues, a balaclava, a pass. +/datum/unit_test/proc/stealth_dress(mob/living/carbon/human/person, uniform = TRUE, mask = TRUE, card = TRUE) + if(uniform) + person.equip_to_slot_or_del(new /obj/item/clothing/under/syndicate/scav(person), ITEM_SLOT_ICLOTHING) + if(mask) + person.equip_to_slot_or_del(new /obj/item/clothing/mask/balaclava/scav(person), ITEM_SLOT_MASK) + if(card) + person.equip_to_slot_or_del(new /obj/item/card/id/advanced/black/scav(person), ITEM_SLOT_ID) + +/// The guard's notice of `person`, 0 if it has none. +/datum/unit_test/proc/stealth_notice_of(mob/living/guard, mob/living/person) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + var/list/entry = stealth_ai.notice_map?[REF(person)] + return entry ? entry[1] : 0 + +/// What counts as each piece, and that changing clothes is seen at once. +/datum/unit_test/voidcrew_stealth_disguise_pieces + +/datum/unit_test/voidcrew_stealth_disguise_pieces/Run() + var/datum/turf_reservation/block = stealth_block(3, 3) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/person = stealth_person(block, 1, 1) + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 0, "Someone in nothing of theirs wears a piece") + stealth_dress(person, TRUE, FALSE, FALSE) + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 2, "The fatigues aren't the clothing piece") + stealth_dress(person, FALSE, TRUE, FALSE) + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 3, "A balaclava over the fatigues isn't clothing and mask") + stealth_dress(person, FALSE, FALSE, TRUE) + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 7, "The pass in the ID slot isn't the ID piece") + TEST_ASSERT_EQUAL(stealth_disguise_stage(7), 4, "The whole set isn't stage 4") + TEST_ASSERT_EQUAL(stealth_disguise_stage(3), 3, "Clothing and mask isn't stage 3") + TEST_ASSERT_EQUAL(stealth_disguise_stage(6), 2, "Clothing and pass with a bare face isn't stage 2") + TEST_ASSERT_EQUAL(stealth_disguise_stage(1), 1, "A mask alone isn't stage 1") + // The vest the guards wear over theirs keeps the clothing; a coat they don't wear loses it. + TEST_ASSERT(stealth_guard_suits()[/obj/item/clothing/suit/armor/vest], "The guards' own vest isn't read from their outfits") + var/obj/item/clothing/suit/vest = new /obj/item/clothing/suit/armor/vest(person) + TEST_ASSERT(person.equip_to_slot_if_possible(vest, ITEM_SLOT_OCLOTHING), "The vest wouldn't go on") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 7, "The guards' own vest over the fatigues lost the clothing piece") + TEST_ASSERT(person.dropItemToGround(vest), "The vest wouldn't come off") + var/obj/item/clothing/suit/coat = new /obj/item/clothing/suit/toggle/labcoat(person) + TEST_ASSERT(person.equip_to_slot_if_possible(coat, ITEM_SLOT_OCLOTHING), "The coat wouldn't go on") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 5, "A lab coat over the fatigues still passes for the guards' dress") + TEST_ASSERT(person.dropItemToGround(coat), "The coat wouldn't come off") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 7, "Taking the coat off didn't bring the clothing piece back") + // Any mask that hides the face is the mask; a bare face is none. + TEST_ASSERT(person.dropItemToGround(person.wear_mask), "The balaclava wouldn't come off") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 6, "A bare face still counts as masked") + person.equip_to_slot_or_del(new /obj/item/clothing/mask/gas(person), ITEM_SLOT_MASK) + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 7, "A gas mask doesn't hide the face") + // The fatigues off: the pass drops with them, and only the mask is left. + TEST_ASSERT(person.dropItemToGround(person.w_uniform), "The fatigues wouldn't come off") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 1, "With the fatigues off something but the mask still counts") + person.equip_to_slot_or_del(new /obj/item/clothing/under/color/grey(person), ITEM_SLOT_ICLOTHING) + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 1, "A grey jumpsuit passes for the guards' dress") + qdel(block) + +/// Each stage's notice fill at 6 tiles in the light, and the same through the green and red skills. +/datum/unit_test/voidcrew_stealth_disguise_fill + +/datum/unit_test/voidcrew_stealth_disguise_fill/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + // uniform, mask, card, share of the plain fill (0.375 a scan for a yellow guard at 6 tiles) + var/list/cases = list( + list(FALSE, FALSE, FALSE, 1), + list(FALSE, TRUE, FALSE, 1), + list(TRUE, FALSE, FALSE, 0.5), + list(TRUE, TRUE, FALSE, 0.25), + list(TRUE, FALSE, TRUE, 0.5), + list(TRUE, TRUE, TRUE, 0), + ) + for(var/list/test_case as anything in cases) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/mob/living/carbon/human/person = stealth_person(block, 12, 2) + stealth_dress(person, test_case[1], test_case[2], test_case[3]) + stealth_scans(guard, 1) + var/expected = 0.375 * test_case[4] + var/found = stealth_notice_of(guard, person) + TEST_ASSERT(abs(found - expected) < 0.001, "Fatigues [test_case[1]], mask [test_case[2]], pass [test_case[3]]: one look at 6 tiles gave [found] notice, not [expected]") + qdel(guard) + qdel(person) + // Skill: clothing and mask fills at a quarter of the guard's plain rate, times 0.6 green, 1 yellow, 1.6 red. + var/list/scales = list(/datum/stealth_skill/green = 0.6, /datum/stealth_skill/yellow = 1, /datum/stealth_skill/red = 1.6) + var/last = 0 + for(var/skill_type in scales) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + guard.stealth_skill = skill_type + var/mob/living/carbon/human/person = stealth_person(block, 12, 2) + stealth_scans(guard, 1) + var/plain = stealth_notice_of(guard, person) + qdel(guard) + guard = stealth_guard(block, 6, 2) + guard.stealth_skill = skill_type + stealth_dress(person, TRUE, TRUE, FALSE) + stealth_scans(guard, 1) + var/found = stealth_notice_of(guard, person) + TEST_ASSERT(plain > 0, "[skill_type]: a plain person 6 tiles in front wasn't noticed at all") + TEST_ASSERT(abs(found - plain * 0.25 * scales[skill_type]) < 0.001, "[skill_type]: clothing and mask gave [found] notice against [plain] plain") + TEST_ASSERT(found > last, "[skill_type] is fooled no less than the skill below it") + last = found + qdel(guard) + qdel(person) + qdel(block) + +/// The whole set: one of their own at range, a greeting nearer, and a challenge only for lingering close. +/datum/unit_test/voidcrew_stealth_disguise_friend + +/datum/unit_test/voidcrew_stealth_disguise_friend/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 12, 2) + stealth_dress(person) + stealth_scans(guard, 30) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard grew suspicious of someone in the whole set 6 tiles off") + TEST_ASSERT_EQUAL(stealth_notice_of(guard, person), 0, "Someone in the whole set 6 tiles off gained notice") + TEST_ASSERT(guard.npc_last_bark != "stealth_greet" && guard.npc_last_bark != "stealth_smoke", "A guard greeted someone 6 tiles off") + // Three tiles off: inside its near range, outside its challenge range. A word, and a slow fill. + person.forceMove(stealth_at(block, 9, 2)) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard did more than greet someone in the whole set 3 tiles off") + TEST_ASSERT(guard.npc_last_bark == "stealth_greet" || guard.npc_last_bark == "stealth_smoke", "A guard had no word for one of its own 3 tiles off") + var/found = stealth_notice_of(guard, person) + TEST_ASSERT(abs(found - 0.1125) < 0.001, "One look at the whole set 3 tiles off gave [found] notice, not 0.1125") + TEST_ASSERT_NULL(stealth_ai.challenge, "A guard stopped someone in the whole set 3 tiles off on its first look") + // They stay: in the end it stops them. + stealth_scans(guard, 30) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "A guard never stopped someone in the whole set who stood 3 tiles in front of it") + TEST_ASSERT_EQUAL(stealth_ai.challenge?.resolve(), person, "The suspicious guard hasn't stopped the one who lingered") + TEST_ASSERT_NULL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "A guard took a target in a disguise that held") + qdel(block) + +/// Up close with the pass: stopped, checked for 2 s, waved on, and then left alone by that guard. +/datum/unit_test/voidcrew_stealth_disguise_pass + +/datum/unit_test/voidcrew_stealth_disguise_pass/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 8, 2) + stealth_dress(person) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "A guard didn't stop someone in the whole set 2 tiles in front of it") + TEST_ASSERT_EQUAL(stealth_ai.challenge?.resolve(), person, "The guard hasn't stopped the person in front of it") + TEST_ASSERT_EQUAL(guard.npc_last_bark, "stealth_challenge", "The guard stopped them without a word") + TEST_ASSERT_NULL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "Stopping someone gave the guard a target") + stealth_scans(guard, 1) + TEST_ASSERT(stealth_ai.checked_at, "The guard isn't reading the pass of someone 2 tiles off") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "The guard was done with the pass in no time") + stealth_ai.stealth_rewind(2 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard that read a good pass for 2 s didn't let them go") + TEST_ASSERT_EQUAL(guard.npc_last_bark, "stealth_id_pass", "The guard let them go without a word") + TEST_ASSERT(stealth_ai.passes[REF(person)] > world.time, "The guard doesn't remember the pass it read") + stealth_scans(guard, 10) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard stopped someone again right after reading their pass") + TEST_ASSERT_EQUAL(stealth_notice_of(guard, person), 0, "Someone it has passed gained notice") + // The pass comes off a while later: the guard's leave goes with it. + stealth_ai.stealth_rewind(61 SECONDS) + TEST_ASSERT(person.dropItemToGround(person.wear_id), "The pass wouldn't come off") + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.challenge?.resolve(), person, "With the pass gone the guard didn't stop them again") + qdel(block) + +/// Taking the pass off and on to pull a guard over: a second stop within 60 s of a wave, or a third within 5 min, sees +/// through them. Waves older than 5 min are forgotten. +/datum/unit_test/voidcrew_stealth_disguise_recheck + +/datum/unit_test/voidcrew_stealth_disguise_recheck/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + for(var/how in list("at once", "third time")) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 8, 2) + stealth_dress(person) + var/waves = how == "at once" ? 1 : 2 + for(var/wave in 1 to waves) + if(wave > 1) + stealth_ai.stealth_rewind(61 SECONDS) + TEST_ASSERT(person.dropItemToGround(person.wear_id), "[how]: the pass wouldn't come off") + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.challenge?.resolve(), person, "[how]: a minute after a wave the guard didn't stop them") + stealth_dress(person, FALSE, FALSE, TRUE) + else + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.challenge?.resolve(), person, "[how]: the guard didn't stop someone in the whole set") + stealth_scans(guard, 1) + stealth_ai.stealth_rewind(2 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(guard.npc_last_bark, "stealth_id_pass", "[how]: wave [wave] didn't pass") + TEST_ASSERT_EQUAL(length(stealth_ai.waved?[REF(person)]), wave, "[how]: the guard didn't count wave [wave]") + if(how == "third time") + stealth_ai.stealth_rewind(61 SECONDS) + TEST_ASSERT(person.dropItemToGround(person.wear_id), "[how]: the pass wouldn't come off") + stealth_scans(guard, 1) + TEST_ASSERT_NULL(stealth_ai.challenge?.resolve(), "[how]: the guard stopped them once more instead of seeing through it") + TEST_ASSERT(stealth_ai.made?[REF(person)] > world.time, "[how]: the guard doesn't remember who it saw through") + // The spot line follows the blown one at once, so the last bark is "spot": the blown line's cooldown shows it was said. + TEST_ASSERT(stealth_ai.bark_ready_at["stealth_blown"] > world.time, "[how]: the guard saw through them without a word") + TEST_ASSERT(!stealth_ai.stealth_fooled(person), "[how]: the disguise still holds for that guard") + qdel(guard) + qdel(person) + // Old waves are forgotten. + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + LAZYADDASSOCLIST(stealth_ai.waved, "someone", world.time) + LAZYADDASSOCLIST(stealth_ai.waved, "someone", world.time) + TEST_ASSERT(stealth_ai.stealth_rechecked("someone"), "Two fresh waves didn't count") + stealth_ai.stealth_rewind(5 MINUTES + 1 SECONDS) + TEST_ASSERT(!stealth_ai.stealth_rechecked("someone"), "Waves over 5 minutes old still counted") + TEST_ASSERT_NULL(stealth_ai.waved?["someone"], "Old waves weren't cleared") + qdel(block) + +/// No pass: asked again at 3 s, blown at 6 s. Walking off or running is blown at once. A pass put on in time passes. +/datum/unit_test/voidcrew_stealth_disguise_fail + +/datum/unit_test/voidcrew_stealth_disguise_fail/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + for(var/how in list("waits", "walks off", "runs", "shows a pass")) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 8, 2) + stealth_dress(person, TRUE, TRUE, FALSE) + stealth_scans(guard, 2) + TEST_ASSERT_EQUAL(stealth_ai.challenge?.resolve(), person, "[how]: a guard didn't stop someone in clothing and mask 2 tiles in front of it") + TEST_ASSERT(stealth_ai.checked_at, "[how]: the guard isn't waiting for a pass") + switch(how) + if("waits") + stealth_ai.stealth_rewind(3 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "The guard was past asking after 3 s") + TEST_ASSERT(stealth_ai.warned, "The guard didn't ask a second time after 3 s") + TEST_ASSERT_EQUAL(guard.npc_last_bark, "stealth_id_fail", "The guard asked a second time without a word") + stealth_ai.stealth_rewind(3 SECONDS) + stealth_scans(guard, 1) + if("walks off") + person.forceMove(stealth_at(block, 11, 2)) + stealth_scans(guard, 1) + if("runs") + person.toggle_move_intent() + person.forceMove(stealth_at(block, 9, 2)) + stealth_scans(guard, 1) + if("shows a pass") + stealth_dress(person, FALSE, FALSE, TRUE) + stealth_ai.stealth_rewind(2 SECONDS) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A pass put on while the guard waited didn't pass") + qdel(guard) + qdel(person) + continue + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "[how]: the guard didn't go for someone with no pass") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "[how]: the alert guard has no target") + TEST_ASSERT(stealth_ai.made[REF(person)] > world.time, "[how]: the guard doesn't remember who it saw through") + TEST_ASSERT(!stealth_ai.stealth_fooled(person), "[how]: the disguise still holds for the guard that blew it") + qdel(guard) + qdel(person) + qdel(block) + +/// What a guard sees that no guard of the den would do: a weapon in hand, a fallen guard pulled along, an off-limits room. +/datum/unit_test/voidcrew_stealth_disguise_breakers + +/datum/unit_test/voidcrew_stealth_disguise_breakers/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + // what they hold => whether it blows the whole set at 6 tiles + var/list/cases = list( + /obj/item/gun/ballistic/automatic/pistol = TRUE, + /obj/item/knife/combat = TRUE, + /obj/item/melee/baton/security = TRUE, + /obj/item/storage/toolbox/mechanical = FALSE, + /obj/item/flashlight/seclite = FALSE, + ) + for(var/item_type in cases) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 12, 2) + stealth_dress(person) + stealth_scans(guard, 2) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "[item_type]: empty-handed in the whole set wasn't one of their own") + person.put_in_hands(new item_type(person)) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), cases[item_type] ? "alert" : "unaware", "[item_type] in hand at 6 tiles left the guard [stealth_ai.stealth_state()]") + qdel(guard) + qdel(person) + // Off limits: the pass excuses it, unless the mark says nobody. + for(var/how in list("no pass", "pass", "pass, nobody allowed")) + var/obj/effect/landmark/stealth_restricted/mark = new(stealth_at(block, 12, 2)) + mark.reach = 1 + mark.allowed = how != "pass, nobody allowed" + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 12, 2) + stealth_dress(person, TRUE, TRUE, how != "no pass") + stealth_scans(guard, 2) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), how == "pass" ? "unaware" : "alert", "Off limits, [how]: the guard is [stealth_ai.stealth_state()]") + // Outside the room the same disguise is nothing to look at. + if(how == "no pass") + TEST_ASSERT_NULL(stealth_ai.group.off_limits()[stealth_at(block, 15, 2)], "A mark with a reach of 1 took in a tile 3 off") + qdel(guard) + qdel(person) + qdel(mark) + // Pulling a fallen guard (its look for bodies is held off, so this is the pulling alone). + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_ai.stealth_setup() + var/mob/living/carbon/human/npc/victim = stealth_guard(block, 12, 3) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = stealth_ai(victim) + guard_ai.stealth_setup() + victim.death() + var/mob/living/carbon/human/person = stealth_person(block, 12, 2) + stealth_dress(person) + person.start_pulling(victim) + TEST_ASSERT_EQUAL(person.pulling, victim, "The body wouldn't be pulled") + stealth_ai.next_body_scan = world.time + 1 MINUTES + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard watched one of its own being dragged off by someone in the whole set") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "The guard isn't after whoever drags the body") + qdel(guard) + qdel(victim) + qdel(person) + qdel(block) + +/// Standing over a body as it is found, and laying hands on a guard in another's sight. +/datum/unit_test/voidcrew_stealth_disguise_seen + +/datum/unit_test/voidcrew_stealth_disguise_seen/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + // A fresh body with them beside it. + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_ai.stealth_setup() + var/mob/living/carbon/human/npc/victim = stealth_guard(block, 12, 3) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = stealth_ai(victim) + guard_ai.stealth_setup() + TEST_ASSERT_EQUAL(guard_ai.group, stealth_ai.group, "The two guards aren't one group") + var/mob/living/carbon/human/person = stealth_person(block, 12, 2) + stealth_dress(person) + stealth_scans(guard, 2) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "Standing by a living guard in the whole set drew a look") + victim.death() + // Its look for fallen friends comes round again. + stealth_ai.next_body_scan = 0 + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard found a body with someone in the whole set standing over it and let them be") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "The guard isn't after whoever stood over the body") + qdel(guard) + qdel(victim) + // Hands on a guard: the one touched turns on them, and so does the one that sees it; one that doesn't see it is still fooled. + guard = stealth_guard(block, 6, 2) + stealth_ai = stealth_ai(guard) + stealth_ai.stealth_setup() + victim = stealth_guard(block, 11, 2) + guard_ai = stealth_ai(victim) + guard_ai.stealth_setup() + var/mob/living/carbon/human/npc/other = stealth_guard(block, 2, 2, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = stealth_ai(other) + friend_ai.stealth_setup() + person.forceMove(stealth_at(block, 10, 2)) + TEST_ASSERT(stealth_ai.stealth_fooled(person), "The watching guard already sees through them") + guard_ai.stealth_touched(person) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "alert", "A guard touched from behind by someone in the whole set didn't turn on them") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard watched one of its own being grabbed and did nothing") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "The watching guard isn't after the one it saw") + TEST_ASSERT_EQUAL(friend_ai.stealth_state(), "unaware", "A guard with its back to it all reacted") + // Word reaches the third guard only through a shout or a call that reaches it (decision 44, voidcrew_stealth_d44.dm): + // being wary is not word. + TEST_ASSERT(friend_ai.stealth_fooled(person), "A guard nobody has told sees through them") + friend_ai.stealth_set_wary() + TEST_ASSERT(friend_ai.stealth_fooled(person), "A wary guard nobody told knows what another guard saw") + stealth_ai.stealth_tell(friend_ai) + TEST_ASSERT(!friend_ai.stealth_fooled(person), "A guard that was told is still fooled") + qdel(block) + +/// Running in a guard's earshot is only footsteps (decision 44); a face it went alert on is known unless a mask hides it. +/datum/unit_test/voidcrew_stealth_disguise_known + +/datum/unit_test/voidcrew_stealth_disguise_known/Run() + var/datum/turf_reservation/block = stealth_block(20, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + // Running three tiles behind it. + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 6, 2, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/mob/living/carbon/human/person = stealth_person(block, 10, 2) + stealth_dress(person) + stealth_scans(guard, 1) + person.forceMove(stealth_at(block, 9, 2)) + stealth_scans(guard, 1) + TEST_ASSERT(stealth_ai.stealth_fooled(person), "Walking behind a guard in the whole set gave them away") + person.toggle_move_intent() + person.forceMove(stealth_at(block, 8, 2)) + stealth_scans(guard, 1) + TEST_ASSERT(stealth_ai.stealth_fooled(person), "Running three tiles behind a guard gave a disguise away by ear") + TEST_ASSERT(!length(stealth_ai.made), "A guard marked someone it only heard running") + qdel(guard) + qdel(person) + // A face it has gone alert on. + guard = stealth_guard(block, 6, 2) + stealth_ai = stealth_ai(guard) + person = stealth_person(block, 12, 2) + stealth_ai.stealth_go_alert(person) + stealth_ai.clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_ai.stealth_go_unaware() + stealth_ai.stealth_clear_wary() + stealth_dress(person, TRUE, FALSE, TRUE) + TEST_ASSERT(!stealth_ai.stealth_fooled(person), "A guard didn't know the bare face it had fought") + stealth_scans(guard, 1) + TEST_ASSERT(abs(stealth_notice_of(guard, person) - 0.375) < 0.001, "A known face in the fatigues was still noticed slowly") + stealth_dress(person, FALSE, TRUE, FALSE) + TEST_ASSERT(stealth_ai.stealth_fooled(person), "A mask didn't hide a face the guard knew") + // A disguise it saw through stays seen through, mask or no mask. + stealth_ai.stealth_blow(person) + TEST_ASSERT(!stealth_ai.stealth_fooled(person), "A guard that saw through a masked disguise is fooled by it again") + qdel(guard) + qdel(person) + // Someone it fought masked left no face behind: the disguise holds. + guard = stealth_guard(block, 6, 2) + stealth_ai = stealth_ai(guard) + person = stealth_person(block, 12, 2) + stealth_dress(person, FALSE, TRUE, FALSE) + stealth_ai.stealth_go_alert(person) + stealth_ai.clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_ai.stealth_go_unaware() + stealth_ai.stealth_clear_wary() + stealth_dress(person, TRUE, FALSE, TRUE) + TEST_ASSERT(stealth_ai.stealth_fooled(person), "A guard knew someone it had only ever seen masked") + qdel(block) + +/// The pass, the fatigues and the balaclava come off a guard like anyone's; the rest of its kit stays locked. The pass opens scav doors. +/datum/unit_test/voidcrew_stealth_disguise_loot + +/datum/unit_test/voidcrew_stealth_disguise_loot/Run() + var/datum/turf_reservation/block = stealth_block(5, 3) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 1, 1) + var/mob/living/carbon/human/person = stealth_person(block, 3, 1) + var/obj/item/card/id/card = guard.wear_id + TEST_ASSERT(istype(card, /obj/item/card/id/advanced/black/scav), "A scav guard wears no scav pass") + TEST_ASSERT(("scav" in card.GetAccess()), "The scav pass carries no scav access") + TEST_ASSERT_EQUAL(card.registered_name, guard.real_name, "The pass isn't in the guard's name") + var/obj/item/uniform = guard.w_uniform + TEST_ASSERT(istype(uniform, /obj/item/clothing/under/syndicate/scav), "A scav guard doesn't wear the scav fatigues") + for(var/obj/item/loot as anything in list(card, uniform)) + TEST_ASSERT(!human_npc_gear_locked(loot), "[loot] is locked gear") + TEST_ASSERT(!HAS_TRAIT(loot, TRAIT_NO_STRIP), "[loot] can't be stripped") + TEST_ASSERT(human_npc_gear_locked(guard.shoes), "The guard's boots are loot too") + var/obj/item/mask = new /obj/item/clothing/mask/balaclava/scav(guard) + TEST_ASSERT(!guard.npc_lock_item(mask), "A scav balaclava was locked to the guard") + qdel(mask) + // A door that takes scav access. + var/obj/machinery/door/airlock/door = allocate(/obj/machinery/door/airlock, stealth_at(block, 4, 0)) + door.req_one_access = list("armory", "scav") + TEST_ASSERT(door.check_access(card), "A door set to scav access refuses the scav pass") + // Taken off the guard and worn. + TEST_ASSERT(guard.dropItemToGround(card), "The pass can't be taken off the guard") + TEST_ASSERT(guard.dropItemToGround(uniform), "The fatigues can't be taken off the guard") + TEST_ASSERT(person.equip_to_slot_if_possible(uniform, ITEM_SLOT_ICLOTHING), "The looted fatigues can't be worn") + TEST_ASSERT(person.equip_to_slot_if_possible(card, ITEM_SLOT_ID), "The looted pass can't be worn") + sleep(2) + TEST_ASSERT(!QDELETED(card) && !QDELETED(uniform), "The looted pass or fatigues were deleted") + TEST_ASSERT_EQUAL(stealth_disguise_of(person), 6, "The guard's own fatigues and pass aren't clothing and ID on someone else") + qdel(block) + +/// The real AI: stopped at a distance in the fatigues and a pass, the guard walks up, reads it and goes back to its post. +/datum/unit_test/voidcrew_stealth_live/disguise_pass + +/datum/unit_test/voidcrew_stealth_live/disguise_pass/Run() + TEST_ASSERT(make_room(14, 5), "No room for the test") + var/mob/living/carbon/human/npc/guard = guard_at(1, 2) + var/mob/living/carbon/human/person = person_at(6, 2) + stealth_dress(person, TRUE, FALSE, TRUE) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + var/turf/post = at(1, 2) + var/stopped = FALSE + var/deadline = world.time + 30 SECONDS + while(world.time < deadline && !(stealth_ai.passes?[REF(person)])) + if(stealth_ai.challenge?.resolve() == person) + stopped = TRUE + sleep(2) + TEST_ASSERT(stopped, "A guard never stopped someone in the fatigues 5 tiles in front of it") + TEST_ASSERT(stealth_ai.passes?[REF(person)], "The guard never let someone with a pass go (state [stealth_ai.stealth_state()], [get_dist(guard, person)] tiles off)") + TEST_ASSERT_NULL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], "The guard took a target during the check") + TEST_ASSERT(get_dist(guard, person) <= 2, "The guard read a pass from [get_dist(guard, person)] tiles off") + deadline = world.time + 30 SECONDS + while(world.time < deadline && get_turf(guard) != post) + sleep(2) + TEST_ASSERT_EQUAL(get_turf(guard), post, "The guard didn't go back to its post after the check") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "The guard isn't calm after a good pass") + +/// The real AI: stopped with no pass, they stand there; the guard asks again and then goes for them. +/datum/unit_test/voidcrew_stealth_live/disguise_fail + +/datum/unit_test/voidcrew_stealth_live/disguise_fail/Run() + TEST_ASSERT(make_room(14, 5), "No room for the test") + var/mob/living/carbon/human/npc/guard = guard_at(1, 2) + var/mob/living/carbon/human/person = person_at(4, 2) + stealth_dress(person, TRUE, TRUE, FALSE) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + var/stopped = FALSE + var/start_time = world.time + var/deadline = world.time + 30 SECONDS + while(world.time < deadline && stealth_ai.stealth_state() != "alert") + if(stealth_ai.challenge?.resolve() == person) + stopped = TRUE + sleep(2) + TEST_ASSERT(stopped, "A guard never stopped someone in clothing and mask 3 tiles in front of it") + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "alert", "A guard never went for someone who showed no pass") + TEST_ASSERT(world.time - start_time >= 5 SECONDS, "The guard gave someone with no pass only [(world.time - start_time) / 10] s") + TEST_ASSERT_EQUAL(stealth_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], person, "The alert guard isn't after them") diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_hearing.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_hearing.dm new file mode 100644 index 00000000000..4c73780cf76 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_hearing.dm @@ -0,0 +1,829 @@ +// Stealth guards: hearing (voidcrew/modules/stealth/stealth_noise.dm and friends). Unit tests compile before +// voidcrew/_DEFINES, so values from there are written out: noise kinds "gun_quiet", "gun_pistol", "gun_smg", +// "gun_long", "impact", "blast", "glass", "thrown", "knock", "bash", "door", "thud", "voice", "scream", "shout"; +// flags LOS_ONLY 1, LOUD 2; call kinds REPORT 1, MISSING 2, ALARM 3; STEALTH_CHECKIN_TIME 30 s, +// STEALTH_RADIO_CALL_TIME 3 s, the heard mark "q_y0". +// +// Every test runs in the walled, lit room of voidcrew_stealth_live with a person on SSmobs' list of players, so +// the level is awake and guards hear. Those down to hear/cleanup never sleep: the AI is on but never gets a +// turn, so they pin what one noise does. The ones after them use real tg actions, and the last four let the +// real AI run. + +#define STEALTH_HEAR_GUARD /mob/living/carbon/human/npc/ruin/trooper/scav +#define STEALTH_HEAR_LOOKOUT /mob/living/carbon/human/npc/ruin/trooper/scav/lookout + +/datum/unit_test/voidcrew_stealth_live/hear + abstract_type = /datum/unit_test/voidcrew_stealth_live/hear + /// Stops handed out on route "a" so far + var/stops_made = 0 + /// The group's marker + var/obj/effect/landmark/stealth_group/marker + +/// The room, its group marker in the top left corner, and a player far off in the bottom right one. +/datum/unit_test/voidcrew_stealth_live/hear/proc/hear_room(width, height) + if(!make_room(width, height)) + return FALSE + marker = allocate(/obj/effect/landmark/stealth_group, at(0, height - 1)) + person_at(width - 1, 0) + return TRUE + +/// Gives the room's floor gravity, for tests where something is thrown or falls (reserved space has none). +/datum/unit_test/voidcrew_stealth_live/hear/proc/ground() + var/turf/corner = room.bottom_left_turfs[1] + var/turf/far_corner = room.top_right_turfs[1] + // A floor kept from an earlier test's room may still have it. + for(var/turf/open/spot in block(corner.x, corner.y, corner.z, far_corner.x, far_corner.y, corner.z)) + if(!spot.has_gravity()) + spot.AddElement(/datum/element/forced_gravity, 1) + +/// A sentry at (dx, dy): awake and in the group. +/datum/unit_test/voidcrew_stealth_live/hear/proc/sentry(dx, dy, facing = EAST, guard_type = STEALTH_HEAR_GUARD) + var/mob/living/carbon/human/npc/guard = allocate(guard_type, at(dx, dy)) + guard.setDir(facing) + guard.AddElement(/datum/element/forced_gravity, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + stealth_ai.stealth_setup() + return guard + +/// A guard with a stop of route "a" under it, so it walks a route (it waits there ten minutes). +/datum/unit_test/voidcrew_stealth_live/hear/proc/walker(dx, dy, facing = EAST, guard_type = STEALTH_HEAR_GUARD) + stop_at(dx, dy, ++stops_made, 10 MINUTES) + return sentry(dx, dy, facing, guard_type) + +/// Back to nothing on its mind, with every clock run out. +/datum/unit_test/voidcrew_stealth_live/hear/proc/settle(mob/living/guard) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + stealth_ai.clear_blackboard_key(BB_BASIC_MOB_CURRENT_TARGET) + stealth_ai.stealth_go_unaware() + stealth_ai.stealth_clear_wary() + stealth_ai.stealth_drop_call() + stealth_ai.stealth_rewind(2 MINUTES) + stealth_ai.glance_until = 0 + +/datum/unit_test/voidcrew_stealth_live/hear/proc/state_of(mob/living/guard) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + return stealth_ai.stealth_state() + +/datum/unit_test/voidcrew_stealth_live/hear/proc/no_targets(list/guards) + for(var/mob/living/guard as anything in guards) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = guard.ai_controller + TEST_ASSERT(!stealth_ai.blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET), "A sound gave [guard] a target") + +/// Walls and doors on the line eat reach; glass and the two ends don't. +/datum/unit_test/voidcrew_stealth_live/hear/muffle + +/datum/unit_test/voidcrew_stealth_live/hear/muffle/Run() + TEST_ASSERT(hear_room(20, 3), "No room for the test") + var/turf/west = at(0, 1) + var/turf/east = at(8, 1) + TEST_ASSERT_EQUAL(stealth_muffled_dist(west, east, 0), 8, "An open line isn't its plain distance") + var/turf/wall_spot = at(4, 1) + wall_spot.ChangeTurf(/turf/closed/wall) + TEST_ASSERT_EQUAL(stealth_muffled_dist(west, east, 0), 11, "One wall didn't cost 3 tiles") + TEST_ASSERT_EQUAL(stealth_muffled_dist(west, east, 2), 9.5, "A loud sound didn't lose half as much to a wall") + TEST_ASSERT_EQUAL(stealth_muffled_dist(west, east, 1), INFINITY, "A line-of-sight sound went through a wall") + TEST_ASSERT_EQUAL(stealth_muffled_dist(wall_spot, west, 0), 4, "A sound on a wall is muffled on its west side") + TEST_ASSERT_EQUAL(stealth_muffled_dist(wall_spot, east, 0), 4, "A sound on a wall is muffled on its east side") + var/obj/machinery/door/airlock/door = allocate(/obj/machinery/door/airlock, at(6, 1)) + TEST_ASSERT(door.density, "The airlock isn't shut") + TEST_ASSERT_EQUAL(stealth_muffled_dist(west, east, 0), 13, "A wall and a closed airlock didn't cost 5 tiles") + qdel(door) + allocate(/obj/structure/window/fulltile, at(6, 1)) + TEST_ASSERT_EQUAL(stealth_muffled_dist(west, east, 0), 11, "A window muffled a sound") + for(var/dx in list(2, 3, 5)) + var/turf/more = at(dx, 1) + more.ChangeTurf(/turf/closed/wall) + TEST_ASSERT_EQUAL(stealth_muffled_dist(west, east, 2), INFINITY, "A sound was heard through four walls") + +/// Every kind has a profile; a gun is never heard further than tg plays its own sound; tiers and suppressors. +/datum/unit_test/voidcrew_stealth_live/hear/guns + +/datum/unit_test/voidcrew_stealth_live/hear/guns/Run() + TEST_ASSERT(hear_room(5, 3), "No room for the test") + for(var/kind in list("gun_quiet", "gun_pistol", "gun_smg", "gun_long", "impact", "blast", "glass", "thrown", "knock", "bash", "door", "thud", "voice", "scream", "shout")) + var/list/profile = stealth_noise_profile(kind) + TEST_ASSERT_EQUAL(length(profile), 3, "Noise kind [kind] has no profile") + TEST_ASSERT(profile[1] > 0 && profile[2] > 0 && isnum(profile[3]), "Noise kind [kind] has a bad profile") + var/turf/here = at(1, 1) + var/list/expected = list( + /obj/item/gun/ballistic/automatic/pistol = "gun_pistol", + /obj/item/gun/ballistic/revolver = "gun_pistol", + /obj/item/gun/energy/laser = "gun_pistol", + /obj/item/gun/ballistic/automatic/c20r = "gun_smg", + /obj/item/gun/ballistic/rifle/boltaction = "gun_long", + /obj/item/gun/ballistic/shotgun = "gun_long", + /obj/item/gun/ballistic/bow/longbow = "gun_quiet", + /obj/item/gun/ballistic/automatic/pistol/suppressed = "gun_quiet", + ) + for(var/gun_type in expected) + var/obj/item/gun/gun = allocate(gun_type, here) + var/list/noise = gun.stealth_shot_noise() + TEST_ASSERT_EQUAL(noise[1], expected[gun_type], "[gun_type] is the wrong loudness") + var/obj/item/gun/ballistic/automatic/pistol/pistol = allocate(/obj/item/gun/ballistic/automatic/pistol, here) + TEST_ASSERT_EQUAL(pistol.stealth_shot_noise()[2], 8, "A pistol's reach isn't 8") + pistol.fire_sound_volume = 10 + TEST_ASSERT(pistol.stealth_shot_noise()[2] < 8, "A quiet custom gun is heard as far as a loud one") + pistol.install_suppressor(new /obj/item/suppressor(pistol)) + var/list/quiet = pistol.stealth_shot_noise() + TEST_ASSERT_EQUAL(quiet[1], "gun_quiet", "A pistol with a suppressor fitted isn't quiet") + TEST_ASSERT_EQUAL(quiet[2], 3, "A suppressed shot's reach isn't 3") + +/// tg's footstep rules: running is heard, walking and every silencer are not. +/datum/unit_test/voidcrew_stealth_live/hear/footstep_reach + +/datum/unit_test/voidcrew_stealth_live/hear/footstep_reach/Run() + TEST_ASSERT(hear_room(6, 3), "No room for the test") + var/mob/living/carbon/human/runner = person_at(1, 1, FALSE) + TEST_ASSERT_EQUAL(stealth_footstep_reach(runner), 0, "A walking step is heard") + runner.toggle_move_intent() + TEST_ASSERT_EQUAL(stealth_footstep_reach(runner), 3, "A running step barefoot on plain floor doesn't carry 3") + runner.equip_to_slot_or_del(new /obj/item/clothing/shoes/sneakers/black(runner), ITEM_SLOT_FEET) + TEST_ASSERT_EQUAL(stealth_footstep_reach(runner), 3, "A running step in shoes on plain floor doesn't carry 3") + var/turf/plating = at(3, 1) + plating.ChangeTurf(/turf/open/floor/plating) + runner.forceMove(plating) + TEST_ASSERT(stealth_footstep_reach(runner) > 3, "Plating is no louder than floor") + runner.forceMove(at(1, 1)) + ADD_TRAIT(runner, TRAIT_LIGHT_STEP, TRAIT_SOURCE_UNIT_TESTS) + TEST_ASSERT_EQUAL(stealth_footstep_reach(runner), 2, "A light step doesn't carry 2") + REMOVE_TRAIT(runner, TRAIT_LIGHT_STEP, TRAIT_SOURCE_UNIT_TESTS) + ADD_TRAIT(runner, TRAIT_SILENT_FOOTSTEPS, TRAIT_SOURCE_UNIT_TESTS) + TEST_ASSERT_EQUAL(stealth_footstep_reach(runner), 0, "Silent footsteps are heard") + REMOVE_TRAIT(runner, TRAIT_SILENT_FOOTSTEPS, TRAIT_SOURCE_UNIT_TESTS) + runner.set_body_position(LYING_DOWN) + TEST_ASSERT_EQUAL(stealth_footstep_reach(runner), 1, "Crawling doesn't carry 1") + runner.set_body_position(STANDING_UP) + var/obj/structure/closet/locker = allocate(/obj/structure/closet, at(1, 1)) + runner.forceMove(locker) + TEST_ASSERT_EQUAL(stealth_footstep_reach(runner), 0, "Someone in a locker makes footsteps") + runner.forceMove(at(1, 1)) + // The real shoes. + qdel(runner.shoes) + runner.equip_to_slot_or_del(new /obj/item/clothing/shoes/laceup/winters_loafers(runner), ITEM_SLOT_FEET) + TEST_ASSERT_NOTNULL(runner.shoes, "The loafers didn't go on") + TEST_ASSERT_EQUAL(stealth_footstep_reach(runner), 0, "Running in Winter's loafers is heard") + +/// One guard goes, then two, then everyone; somewhere else, one again. No sound gives anyone a target. +/datum/unit_test/voidcrew_stealth_live/hear/dispatch + +/datum/unit_test/voidcrew_stealth_live/hear/dispatch/Run() + TEST_ASSERT(hear_room(30, 3), "No room for the test") + var/mob/living/carbon/human/npc/first = walker(5, 1) + var/mob/living/carbon/human/npc/second = walker(7, 1) + var/mob/living/carbon/human/npc/third = walker(9, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/first_ai = first.ai_controller + var/datum/ai_controller/basic_controller/human_npc/stealth/second_ai = second.ai_controller + var/datum/ai_controller/basic_controller/human_npc/stealth/third_ai = third.ai_controller + var/datum/stealth_group/group = first_ai.group + TEST_ASSERT_EQUAL(group, marker.group, "The guards didn't join the marker's group") + TEST_ASSERT_NOTNULL(third_ai.route_id, "A guard on a stop claimed no route") + var/turf/spot = at(4, 1) + TEST_ASSERT_EQUAL(stealth_noise(spot, "knock"), 3, "Three guards within 5 tiles didn't all hear a knock") + TEST_ASSERT_EQUAL(first_ai.stealth_state(), "suspicious", "The nearest guard didn't go to look") + TEST_ASSERT(first_ai.suspicion_heard, "A guard that heard something isn't marked as having heard it") + TEST_ASSERT_EQUAL(first_ai.investigate_turf, spot, "It isn't going to where the noise was") + TEST_ASSERT(!first_ai.blackboard["stealth_wary"], "A noise alone made a guard wary") + TEST_ASSERT_EQUAL(second_ai.stealth_state(), "unaware", "A second guard went to the first noise") + TEST_ASSERT(second_ai.glance_until > world.time && third_ai.glance_until > world.time, "The others didn't glance") + TEST_ASSERT_EQUAL(second.dir, WEST, "A glancing guard didn't turn to the noise") + // The same noise at once is the same noise. + TEST_ASSERT_EQUAL(stealth_noise(spot, "knock"), 0, "The same noise in the same moment was heard twice") + group.rewind(4 SECONDS) + stealth_noise(spot, "knock") + TEST_ASSERT_EQUAL(second_ai.stealth_state(), "suspicious", "Two guards didn't go to the second noise") + TEST_ASSERT_EQUAL(third_ai.stealth_state(), "unaware", "Three guards went to the second noise") + group.rewind(4 SECONDS) + stealth_noise(spot, "knock") + for(var/mob/living/guard as anything in list(first, second, third)) + TEST_ASSERT_EQUAL(state_of(guard), "searching", "Not every guard searched at the third noise") + TEST_ASSERT(third_ai.blackboard["stealth_wary"], "A guard searching for a noise isn't wary") + // Ten tiles off it is a new spot. + for(var/mob/living/guard as anything in list(first, second, third)) + settle(guard) + group.rewind(4 SECONDS) + TEST_ASSERT_EQUAL(stealth_noise(at(14, 1), "glass"), 2, "A smash 5 and 7 tiles off wasn't heard by two") + TEST_ASSERT_EQUAL(third_ai.stealth_state(), "suspicious", "Nobody went to a noise somewhere new") + TEST_ASSERT_EQUAL(second_ai.stealth_state(), "unaware", "Two went to the first noise at a new spot") + no_targets(list(first, second, third)) + +/// The guard who never came back is missed by the ones who watched it go, once it is overdue. +/datum/unit_test/voidcrew_stealth_live/hear/missing + +/datum/unit_test/voidcrew_stealth_live/hear/missing/Run() + TEST_ASSERT(hear_room(20, 3), "No room for the test") + var/mob/living/carbon/human/npc/first = walker(5, 1) + var/mob/living/carbon/human/npc/second = walker(7, 1) + var/mob/living/carbon/human/npc/third = walker(9, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/first_ai = first.ai_controller + var/datum/stealth_group/group = first_ai.group + var/turf/spot = at(4, 1) + stealth_noise(spot, "knock") + TEST_ASSERT_EQUAL(length(group.checks), 1, "No check was opened on the guard that went") + first.death() + group.check_overdue() + TEST_ASSERT_EQUAL(state_of(second), "unaware", "A guard knew its friend was down before it was overdue") + group.rewind(31 SECONDS) + group.check_overdue() + TEST_ASSERT_EQUAL(state_of(second), "searching", "Nobody came looking for the guard that never came back") + TEST_ASSERT_EQUAL(state_of(third), "searching", "Only one guard came looking") + TEST_ASSERT(group.lure_count(spot) >= 2, "The next noise at that spot won't bring everyone") + TEST_ASSERT_EQUAL(length(group.checks), 0, "A failed check wasn't closed") + // One that comes back closes its check. + settle(second) + settle(third) + group.forget_noises() + stealth_noise(spot, "knock") + TEST_ASSERT_EQUAL(state_of(second), "suspicious", "The next guard didn't go to look") + settle(second) + group.rewind(31 SECONDS) + group.check_overdue() + TEST_ASSERT_EQUAL(state_of(third), "unaware", "A guard was missed after it came back") + no_targets(list(second, third)) + +/// Gunfire: the nearest four that aren't sentries run to it, the rest hold, everyone is wary. After two alarms, two go. +/datum/unit_test/voidcrew_stealth_live/hear/alarm + +/datum/unit_test/voidcrew_stealth_live/hear/alarm/Run() + TEST_ASSERT(hear_room(30, 5), "No room for the test") + // The sentries first: a guard made beside a stop would claim its route. + var/list/sentries = list(sentry(4, 3), sentry(6, 3)) + var/list/route_guards = list() + for(var/dx in 3 to 8) + route_guards += walker(dx, 1) + var/mob/living/any_guard = route_guards[1] + var/datum/ai_controller/basic_controller/human_npc/stealth/any_ai = any_guard.ai_controller + var/datum/stealth_group/group = any_ai.group + var/turf/spot = at(1, 1) + TEST_ASSERT_EQUAL(stealth_noise(spot, "gun_long"), 8, "Eight guards within 14 tiles didn't all hear a rifle") + var/searching = 0 + for(var/mob/living/guard as anything in route_guards) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + TEST_ASSERT(guard_ai.blackboard["stealth_wary"], "A guard that heard gunfire isn't wary") + if(guard_ai.stealth_state() == "searching") + searching++ + TEST_ASSERT_EQUAL(searching, 4, "Not exactly four guards ran to the gunfire") + TEST_ASSERT_EQUAL(state_of(route_guards[1]), "searching", "The nearest guard didn't go") + TEST_ASSERT_EQUAL(state_of(route_guards[6]), "unaware", "The furthest guard didn't hold") + for(var/mob/living/guard as anything in sentries) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A sentry left its post for gunfire") + TEST_ASSERT(guard_ai.blackboard["stealth_wary"], "A sentry that heard gunfire isn't wary") + // A second, then a third: by then they have learned it may be a draw. + for(var/round_number in 2 to 3) + for(var/mob/living/guard as anything in route_guards + sentries) + settle(guard) + group.rewind(4 SECONDS) + stealth_noise(spot, "gun_long") + searching = 0 + for(var/mob/living/guard as anything in route_guards) + if(state_of(guard) == "searching") + searching++ + TEST_ASSERT_EQUAL(searching, 2, "After two alarms in memory, not exactly two guards went to the third") + no_targets(route_guards + sentries) + +/// Their own side: a guard doesn't hear itself, a friend's gunfire is a call for help, their own door is nothing, a friend's fall is heard. +/datum/unit_test/voidcrew_stealth_live/hear/allies + +/datum/unit_test/voidcrew_stealth_live/hear/allies/Run() + TEST_ASSERT(hear_room(20, 3), "No room for the test") + var/mob/living/carbon/human/npc/shooter = walker(3, 1) + var/mob/living/carbon/human/npc/friend = walker(8, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = friend.ai_controller + TEST_ASSERT_EQUAL(stealth_noise(shooter, "voice", null, shooter), 0, "A guard's whistle was heard by its friend") + TEST_ASSERT_EQUAL(stealth_noise(shooter, "gun_pistol", null, shooter), 1, "A guard's gunfire wasn't heard by its friend") + TEST_ASSERT_EQUAL(state_of(shooter), "unaware", "A guard reacted to its own shot") + TEST_ASSERT_EQUAL(friend_ai.stealth_state(), "searching", "A guard didn't run to a friend's gunfire") + TEST_ASSERT_EQUAL(friend_ai.search_center, get_turf(shooter), "It isn't looking where its friend fired from") + settle(friend) + var/obj/machinery/door/airlock/door = allocate(/obj/machinery/door/airlock, at(9, 1)) + TEST_ASSERT_EQUAL(stealth_noise(door, "door"), 0, "A door with one of their own beside it was heard") + door.forceMove(at(11, 1)) + TEST_ASSERT_EQUAL(stealth_noise(door, "door"), 1, "A door with nobody beside it wasn't heard") + TEST_ASSERT(friend_ai.glance_until > world.time, "A guard didn't glance at a door") + friend_ai.group.forget_noises() + TEST_ASSERT_EQUAL(stealth_noise(at(6, 1), "thud", null, shooter), 1, "A friend's fall wasn't heard") + TEST_ASSERT_EQUAL(friend_ai.stealth_state(), "suspicious", "A guard didn't look at a friend's fall") + no_targets(list(shooter, friend)) + +/// The deaf hear nothing; with no player on the level nothing is heard at all; ten shots in a tick are one noise. +/datum/unit_test/voidcrew_stealth_live/hear/deaf_dormant + +/datum/unit_test/voidcrew_stealth_live/hear/deaf_dormant/Run() + TEST_ASSERT(hear_room(20, 3), "No room for the test") + var/mob/living/carbon/human/npc/guard = walker(5, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + var/datum/stealth_group/group = guard_ai.group + var/turf/spot = at(3, 1) + ADD_TRAIT(guard, TRAIT_DEAF, TRAIT_SOURCE_UNIT_TESTS) + TEST_ASSERT_EQUAL(stealth_noise(spot, "gun_long"), 0, "A deaf guard heard a rifle") + REMOVE_TRAIT(guard, TRAIT_DEAF, TRAIT_SOURCE_UNIT_TESTS) + // Nobody on the level. + var/list/were_listed = players.Copy() + for(var/mob/living/person as anything in were_listed) + SSmobs.clients_by_zlevel[were_listed[person]] -= person + TEST_ASSERT_EQUAL(stealth_noise(spot, "gun_long"), 0, "A guard on an empty level heard a rifle") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A noise on an empty level changed a guard") + for(var/mob/living/person as anything in were_listed) + SSmobs.clients_by_zlevel[were_listed[person]] += person + var/heard = 0 + for(var/shot in 1 to 10) + heard += stealth_noise(at(3 + (shot % 3), 1), "gun_long") + TEST_ASSERT_EQUAL(heard, 1, "Ten shots in one tick weren't one noise") + TEST_ASSERT_EQUAL(length(group.alarms), 1, "Ten shots in one tick were more than one alarm") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "searching", "A guard didn't run to gunfire") + no_targets(list(guard)) + +/// A guard that sees someone shouts; a friend in earshot runs to the shouter and doesn't shout on. A muted guard calls nobody. +/datum/unit_test/voidcrew_stealth_live/hear/shout + +/datum/unit_test/voidcrew_stealth_live/hear/shout/Run() + TEST_ASSERT(hear_room(24, 3), "No room for the test") + var/mob/living/carbon/human/npc/spotter = walker(10, 1, EAST) + var/mob/living/carbon/human/npc/friend = walker(4, 1, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/spotter_ai = spotter.ai_controller + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = friend.ai_controller + var/mob/living/carbon/human/intruder = person_at(12, 1, FALSE) + ADD_TRAIT(spotter, TRAIT_MUTE, TRAIT_SOURCE_UNIT_TESTS) + stealth_scans(spotter, 4) + TEST_ASSERT_EQUAL(spotter_ai.stealth_state(), "alert", "A guard isn't alert on someone 2 tiles in front of it") + TEST_ASSERT_EQUAL(friend_ai.stealth_state(), "unaware", "A muted guard called its friend") + REMOVE_TRAIT(spotter, TRAIT_MUTE, TRAIT_SOURCE_UNIT_TESTS) + settle(spotter) + spotter.setDir(EAST) + stealth_scans(spotter, 4) + TEST_ASSERT_EQUAL(spotter_ai.stealth_state(), "alert", "A guard isn't alert on someone 2 tiles in front of it") + TEST_ASSERT_EQUAL(friend_ai.stealth_state(), "searching", "A guard in earshot of a shout didn't come") + TEST_ASSERT_EQUAL(friend_ai.search_center, get_turf(spotter), "It ran to the intruder, not to the friend who shouted") + TEST_ASSERT(!friend_ai.blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET), "A shout gave a guard a target") + TEST_ASSERT(!friend_ai.next_shout, "A guard that came for a shout shouted on") + TEST_ASSERT_EQUAL(spotter_ai.blackboard[BB_BASIC_MOB_CURRENT_TARGET], intruder, "The guard that saw them has no target") + +/// A radio call takes three seconds, reaches the other lookout anywhere, and is stopped by a knockout, a jammer or an EMP. +/datum/unit_test/voidcrew_stealth_live/hear/radio + +/datum/unit_test/voidcrew_stealth_live/hear/radio/Run() + TEST_ASSERT(hear_room(40, 3), "No room for the test") + var/mob/living/carbon/human/npc/speaker = walker(3, 1, WEST, STEALTH_HEAR_LOOKOUT) + var/mob/living/carbon/human/npc/listener = walker(34, 1, EAST, STEALTH_HEAR_LOOKOUT) + var/mob/living/carbon/human/npc/neighbour = walker(31, 1, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/speaker_ai = speaker.ai_controller + var/datum/ai_controller/basic_controller/human_npc/stealth/listener_ai = listener.ai_controller + var/datum/stealth_group/group = speaker_ai.group + TEST_ASSERT_NOTNULL(speaker.stealth_radio_ready(), "A lookout has no working radio") + TEST_ASSERT_NULL(neighbour.stealth_radio_ready(), "A plain guard has a radio") + var/turf/spot = at(5, 1) + // The call goes out after three seconds, not before. + TEST_ASSERT(speaker_ai.stealth_start_call(3, spot), "A lookout couldn't start a call") + stealth_scans(speaker, 1) + TEST_ASSERT_EQUAL(listener_ai.stealth_state(), "unaware", "A radio call arrived at once") + speaker_ai.stealth_rewind(3.1 SECONDS) + stealth_scans(speaker, 1) + TEST_ASSERT_NULL(speaker_ai.pending_call, "A call that was made is still pending") + TEST_ASSERT_EQUAL(listener_ai.stealth_state(), "searching", "The other lookout didn't answer a radio alarm") + TEST_ASSERT_EQUAL(state_of(neighbour), "searching", "The guard beside the lookout that answered didn't come") + // Knocked out inside the three seconds. + for(var/mob/living/guard as anything in list(speaker, listener, neighbour)) + settle(guard) + group.forget_noises() + speaker_ai.stealth_start_call(3, spot) + speaker.Unconscious(4 SECONDS) + TEST_ASSERT_NULL(speaker_ai.pending_call, "A knocked-out guard kept its call") + speaker.SetUnconscious(0) + speaker.update_stat() + settle(speaker) + TEST_ASSERT_EQUAL(listener_ai.stealth_state(), "unaware", "A call from a knocked-out guard arrived") + // A jammer beside the speaker. + var/obj/item/jammer/jammer = allocate(/obj/item/jammer, get_turf(speaker)) + GLOB.active_jammers |= jammer + TEST_ASSERT_NULL(speaker.stealth_radio_ready(), "A jammed lookout's radio works") + speaker_ai.stealth_start_call(3, spot) + speaker_ai.stealth_rewind(3.1 SECONDS) + stealth_scans(speaker, 1) + GLOB.active_jammers -= jammer + TEST_ASSERT_EQUAL(listener_ai.stealth_state(), "unaware", "A jammed call arrived") + TEST_ASSERT(speaker_ai.bark_ready_at["stealth_radio_dead"], "A lookout with a dead radio didn't say so") + // The receiver's earpiece hit by an EMP. + settle(speaker) + var/obj/item/radio/earpiece = listener.ears + earpiece.emp_act(EMP_HEAVY) + TEST_ASSERT_NULL(listener.stealth_radio_ready(), "An EMPed earpiece still works") + speaker_ai.stealth_start_call(3, spot) + speaker_ai.stealth_rewind(3.1 SECONDS) + stealth_scans(speaker, 1) + TEST_ASSERT_EQUAL(listener_ai.stealth_state(), "unaware", "A lookout with a dead earpiece got the call") + TEST_ASSERT_EQUAL(state_of(neighbour), "unaware", "The call reached a guard with no radio") + no_targets(list(speaker, listener, neighbour)) + +/// A lone lookout that reports in is missed by the other lookout; a guard with no radio that goes alone is missed by nobody. +/datum/unit_test/voidcrew_stealth_live/hear/report + +/datum/unit_test/voidcrew_stealth_live/hear/report/Run() + TEST_ASSERT(hear_room(40, 3), "No room for the test") + var/mob/living/carbon/human/npc/scout = walker(3, 1, WEST, STEALTH_HEAR_LOOKOUT) + var/mob/living/carbon/human/npc/listener = walker(34, 1, EAST, STEALTH_HEAR_LOOKOUT) + var/mob/living/carbon/human/npc/loner = walker(18, 1, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/scout_ai = scout.ai_controller + var/datum/stealth_group/group = scout_ai.group + TEST_ASSERT_EQUAL(stealth_noise(at(5, 1), "knock"), 1, "Only the lookout should hear this knock") + TEST_ASSERT_NOTNULL(scout_ai.pending_call, "A lookout sent to look didn't reach for its radio") + scout_ai.stealth_rewind(3.1 SECONDS) + stealth_scans(scout, 1) + TEST_ASSERT_EQUAL(state_of(listener), "unaware", "A report moved someone") + scout.death() + group.rewind(31 SECONDS) + group.check_overdue() + TEST_ASSERT_EQUAL(state_of(listener), "searching", "A lookout that reported and never came back wasn't missed") + // No radio, nobody else in earshot: nobody knows it went. + settle(listener) + group.forget_noises() + TEST_ASSERT_EQUAL(stealth_noise(at(20, 1), "knock"), 1, "Only the plain guard should hear this knock") + TEST_ASSERT_EQUAL(state_of(loner), "suspicious", "The plain guard didn't go to look") + loner.death() + group.rewind(31 SECONDS) + group.check_overdue() + TEST_ASSERT_EQUAL(state_of(listener), "unaware", "A guard nobody saw leave was missed") + +/// The grey "?" of a heard noise: for players near with no fill of their own, never for a glance, gone when it gives up. +/datum/unit_test/voidcrew_stealth_live/hear/mark + +/datum/unit_test/voidcrew_stealth_live/hear/mark/Run() + TEST_ASSERT(hear_room(20, 3), "No room for the test") + var/mob/living/carbon/human/npc/first = walker(8, 1) + var/mob/living/carbon/human/npc/second = walker(10, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/first_ai = first.ai_controller + var/datum/ai_controller/basic_controller/human_npc/stealth/second_ai = second.ai_controller + var/mob/living/carbon/human/watcher = person_at(4, 1) + stealth_noise(at(7, 1), "knock") + TEST_ASSERT(first_ai.suspicion_heard, "The guard that went isn't marked as having heard") + TEST_ASSERT(stealth_meter_heard(first_ai.stealth_state(), first_ai.suspicion_heard), "A heard suspicion shows no mark") + TEST_ASSERT_NOTNULL(first_ai.meter, "No mark was built for a heard suspicion with nobody noticed") + TEST_ASSERT(watcher in first_ai.meter.heard_viewers(first_ai.notice_map), "A player near the guard doesn't get the heard mark") + first_ai.notice_map[REF(watcher)] = list(0.5, get_turf(watcher), world.time) + TEST_ASSERT(!(watcher in first_ai.meter.heard_viewers(first_ai.notice_map)), "A player with their own fill gets the heard mark too") + TEST_ASSERT(!second_ai.suspicion_heard, "A glance shows the heard mark") + first_ai.stealth_go_unaware() + TEST_ASSERT(!first_ai.suspicion_heard, "The heard mark outlived the suspicion") + TEST_ASSERT(!stealth_meter_heard(first_ai.stealth_state(), first_ai.suspicion_heard), "An unaware guard shows the heard mark") + +/// Deleting a guard with a call pending and a check open, then its group: nothing left behind. +/datum/unit_test/voidcrew_stealth_live/hear/cleanup + +/datum/unit_test/voidcrew_stealth_live/hear/cleanup/Run() + TEST_ASSERT(hear_room(20, 3), "No room for the test") + stop_at(5, 1, 1, 10 MINUTES) + stop_at(7, 1, 2, 10 MINUTES) + var/mob/living/carbon/human/npc/scout = new STEALTH_HEAR_LOOKOUT(at(5, 1)) + var/mob/living/carbon/human/npc/friend = new STEALTH_HEAR_GUARD(at(7, 1)) + var/datum/ai_controller/basic_controller/human_npc/stealth/scout_ai = wake(scout) + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = wake(friend) + scout_ai.stealth_setup() + friend_ai.stealth_setup() + var/datum/stealth_group/group = scout_ai.group + stealth_noise(at(4, 1), "knock") + TEST_ASSERT_NOTNULL(scout_ai.pending_call, "The lookout has no call pending") + TEST_ASSERT_EQUAL(length(group.checks), 1, "No check is open") + qdel(scout) + group.rewind(31 SECONDS) + group.check_overdue() + TEST_ASSERT_EQUAL(friend_ai.stealth_state(), "searching", "A deleted investigator wasn't missed") + qdel(friend) + QDEL_NULL(marker) + TEST_ASSERT(!(group in GLOB.stealth_groups), "A group with no marker and no guards is still registered") + TEST_ASSERT(QDELETED(group), "The group wasn't deleted") + // The explosion listener went with it. + SEND_GLOBAL_SIGNAL(COMSIG_GLOB_EXPLOSION, at(4, 1), 0, 0, 1) + +// ===== Through the real tg action ===== + +/// A real pistol shot sends a guard running; suppressed, it is unheard at 6 tiles and a curiosity at 3. +/datum/unit_test/voidcrew_stealth_live/hear/real_gunshot + +/datum/unit_test/voidcrew_stealth_live/hear/real_gunshot/Run() + TEST_ASSERT(hear_room(30, 3), "No room for the test") + var/mob/living/carbon/human/npc/guard = walker(3, 1, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + var/mob/living/carbon/human/shooter = person_at(10, 1, FALSE) + var/obj/item/gun/ballistic/automatic/pistol/pistol = allocate(/obj/item/gun/ballistic/automatic/pistol, get_turf(shooter)) + shooter.put_in_active_hand(pistol) + var/turf/far_wall = at(25, 1) + TEST_ASSERT(pistol.process_fire(far_wall, shooter), "The pistol didn't fire") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "searching", "A guard 7 tiles behind a pistol shot didn't run to it") + TEST_ASSERT(get_dist(guard_ai.search_center, shooter) <= 1, "It isn't searching where the shot came from") + TEST_ASSERT(!guard_ai.blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET), "A gunshot gave a guard a target") + // Suppressed, 6 tiles: nothing. + settle(guard) + guard_ai.group.forget_noises() + pistol.install_suppressor(new /obj/item/suppressor(pistol)) + shooter.forceMove(at(9, 1)) + // No time passes in this test: the gun's own delay between shots is cleared by hand. + pistol.reset_fire_cd() + TEST_ASSERT(pistol.process_fire(far_wall, shooter), "The suppressed pistol didn't fire") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A guard heard a suppressed shot 6 tiles off") + // 3 tiles, in the open: it turns to look. + guard_ai.group.forget_noises() + shooter.forceMove(at(6, 1)) + pistol.reset_fire_cd() + TEST_ASSERT(pistol.process_fire(far_wall, shooter), "The suppressed pistol didn't fire again") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "A guard 3 tiles from a suppressed shot didn't look") + TEST_ASSERT(guard_ai.suspicion_heard, "It isn't marked as having heard it") + TEST_ASSERT(!guard_ai.blackboard["stealth_wary"], "A suppressed shot made a guard wary") + +/// A real throw: the guard looks where the thing landed. A bottle smashes and carries further. +/datum/unit_test/voidcrew_stealth_live/hear/real_throw + +/datum/unit_test/voidcrew_stealth_live/hear/real_throw/Run() + TEST_ASSERT(hear_room(30, 7), "No room for the test") + ground() + var/mob/living/carbon/human/npc/guard = sentry(9, 5, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + var/mob/living/carbon/human/thrower = person_at(0, 2, FALSE) + var/obj/item/coin/iron/coin = allocate(/obj/item/coin/iron, get_turf(thrower)) + var/turf/landing = at(9, 2) + coin.throw_at(landing, 12, 2, thrower) + var/deadline = world.time + 10 SECONDS + while((coin.throwing || guard_ai.stealth_state() == "unaware") && world.time < deadline) + sleep(1) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "A guard 3 tiles from a thrown coin's landing didn't look (it landed [get_dist(coin, guard)] tiles off)") + TEST_ASSERT(get_dist(guard_ai.investigate_turf, get_turf(coin)) <= 1, "It isn't looking where the coin landed") + TEST_ASSERT_EQUAL(guard_ai.last_heard[1], "thrown", "It heard something other than a landing") + // A bottle, 7 tiles from the guard: only breaking glass carries that far. + settle(guard) + guard_ai.group.forget_noises() + // On a route now: a sentry wouldn't leave its post for something this far off. + guard.forceMove(at(16, 2)) + stop_at(16, 2, 1, 10 MINUTES) + stealth_assign_points() + guard_ai.route_id = "a" + guard_ai.route_index = 1 + guard_ai.home_turf = at(16, 2) + guard.setDir(EAST) + var/obj/item/reagent_containers/cup/glass/bottle/beer/bottle = allocate(/obj/item/reagent_containers/cup/glass/bottle/beer, get_turf(thrower)) + TEST_ASSERT_EQUAL(bottle.stealth_throw_kind(), "glass", "A glass bottle doesn't smash as glass") + bottle.throw_at(landing, 12, 2, thrower) + deadline = world.time + 10 SECONDS + while(guard_ai.stealth_state() == "unaware" && world.time < deadline) + sleep(1) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "A guard 7 tiles from a smashed bottle didn't look") + TEST_ASSERT_EQUAL(guard_ai.last_heard[1], "glass", "It heard something other than breaking glass") + +/// Knocking on a wall or a window, and a door that refuses: the guard on the far side looks at its own side of it. +/datum/unit_test/voidcrew_stealth_live/hear/real_knock + +/datum/unit_test/voidcrew_stealth_live/hear/real_knock/Run() + TEST_ASSERT(hear_room(20, 5), "No room for the test") + for(var/dy in 0 to 4) + var/turf/wall_spot = at(10, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + var/mob/living/carbon/human/npc/guard = sentry(13, 2, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + var/mob/living/carbon/human/knocker = person_at(9, 2, FALSE) + var/turf/closed/wall/wall = at(10, 2) + wall.attack_hand(knocker, list()) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "A guard 3 tiles behind a wall didn't hear a push on it") + TEST_ASSERT_EQUAL(guard_ai.investigate_turf, at(11, 2), "It isn't going to its own side of the wall") + // A window in the wall. + settle(guard) + guard_ai.group.forget_noises() + var/turf/pane_spot = at(10, 3) + pane_spot.ChangeTurf(/turf/open/floor/iron) + var/obj/structure/window/reinforced/fulltile/pane = allocate(/obj/structure/window/reinforced/fulltile, pane_spot) + knocker.forceMove(at(9, 3)) + knocker.set_combat_mode(FALSE) + pane.attack_hand(knocker, list()) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "A guard didn't hear a knock on a window") + TEST_ASSERT_EQUAL(guard_ai.last_heard[1], "knock", "A knock with combat mode off wasn't a knock") + TEST_ASSERT_EQUAL(guard_ai.investigate_turf?.x, pane_spot.x + 1, "It isn't going to its own side of the window") + // A door that refuses. + settle(guard) + guard_ai.group.forget_noises() + var/turf/door_spot = at(10, 1) + door_spot.ChangeTurf(/turf/open/floor/iron) + var/obj/machinery/door/airlock/door = allocate(/obj/machinery/door/airlock, door_spot) + door.animation_effects(DOOR_DENY_ANIMATION) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "A guard didn't hear a door refuse someone") + TEST_ASSERT_EQUAL(guard_ai.investigate_turf?.x, door_spot.x + 1, "It isn't going to its own side of the door") + +/// A body that drops is heard; one held when it drops is lowered without a sound. A whistle is heard; a nod is not. +/datum/unit_test/voidcrew_stealth_live/hear/real_fall_emote + +/datum/unit_test/voidcrew_stealth_live/hear/real_fall_emote/Run() + TEST_ASSERT(hear_room(20, 5), "No room for the test") + var/mob/living/carbon/human/npc/guard = sentry(10, 2, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + var/mob/living/carbon/human/holder = person_at(6, 2, FALSE) + var/mob/living/carbon/human/held = person_at(7, 2, FALSE) + ground() + holder.start_pulling(held) + holder.setGrabState(GRAB_AGGRESSIVE) + TEST_ASSERT_EQUAL(held.pulledby, holder, "The grab didn't take") + held.Knockdown(10 SECONDS) + TEST_ASSERT_EQUAL(held.body_position, LYING_DOWN, "The held one didn't go down") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A body lowered by whoever held it was heard") + var/mob/living/carbon/human/dropped = person_at(7, 3, FALSE) + dropped.Knockdown(10 SECONDS) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "A body dropping 3 tiles behind a guard wasn't heard") + TEST_ASSERT_EQUAL(guard_ai.last_heard[1], "thud", "It heard something other than a thud") + // Emotes. + settle(guard) + guard_ai.group.forget_noises() + guard.setDir(EAST) + var/mob/living/carbon/human/whistler = person_at(6, 4, FALSE) + whistler.emote("nod") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A silent emote was heard") + whistler.emote("whistle") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "suspicious", "A whistle 4 tiles off wasn't heard") + TEST_ASSERT_EQUAL(guard_ai.last_heard[1], "voice", "It heard something other than a voice") + +/// A real explosion 12 tiles off, the other side of a wall: the guard runs to it. +/datum/unit_test/voidcrew_stealth_live/hear/real_blast + +/datum/unit_test/voidcrew_stealth_live/hear/real_blast/Run() + TEST_ASSERT(hear_room(30, 5), "No room for the test") + for(var/dy in 0 to 4) + var/turf/wall_spot = at(10, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + var/mob/living/carbon/human/npc/guard = walker(16, 2, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = guard.ai_controller + explosion(at(4, 2), devastation_range = 0, heavy_impact_range = 0, light_impact_range = 1) + var/deadline = world.time + 10 SECONDS + while(guard_ai.stealth_state() != "searching" && world.time < deadline) + sleep(1) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "searching", "A guard 12 tiles from a blast behind a wall didn't run to it") + TEST_ASSERT_EQUAL(guard_ai.last_heard[1], "blast", "It heard something other than a blast") + TEST_ASSERT(!guard_ai.blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET), "A blast gave a guard a target") + +// ===== With the real AI running ===== + +/// A bottle thrown off a guard's route: it walks over, finds nothing, and goes back to its round. +/datum/unit_test/voidcrew_stealth_live/hear/live_lure + +/datum/unit_test/voidcrew_stealth_live/hear/live_lure/Run() + TEST_ASSERT(make_room(34, 9), "No room for the test") + marker = allocate(/obj/effect/landmark/stealth_group, at(0, 8)) + // The player who keeps the level awake, walled off at the far end. + for(var/dy in 0 to 8) + var/turf/wall_spot = at(24, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + person_at(30, 2) + // A wall hides the thrower from the route; the top two rows are open to throw along. + for(var/dy in 0 to 6) + var/turf/wall_spot = at(11, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + ground() + stop_at(2, 2, 1) + stop_at(8, 2, 2) + var/mob/living/carbon/human/npc/guard = guard_at(2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = wake(guard) + var/mob/living/carbon/human/thrower = person_at(16, 7, FALSE) + sleep(3 SECONDS) + TEST_ASSERT_EQUAL(guard_ai.route_id, "a", "The guard never claimed its route") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A patrolling guard with nobody in sight isn't unaware") + var/turf/landing = at(5, 7) + var/obj/item/reagent_containers/cup/glass/bottle/beer/bottle = allocate(/obj/item/reagent_containers/cup/glass/bottle/beer, get_turf(thrower)) + bottle.throw_at(landing, 14, 2, thrower) + var/start_time = world.time + var/found = FALSE + var/nearest = INFINITY + var/deadline = world.time + 25 SECONDS + while(world.time < deadline) + nearest = min(nearest, get_dist(guard, landing)) + if(nearest <= 1) + found = TRUE + break + sleep(2) + TEST_ASSERT(found, "The guard never walked to the smashed bottle: it got within [nearest] tiles, state [guard_ai.stealth_state()], heard [guard_ai.last_heard ? guard_ai.last_heard[1] : "nothing"]") + var/back = FALSE + deadline = start_time + 60 SECONDS + while(world.time < deadline) + if(guard_ai.stealth_state() == "unaware" && (get_dist(guard, at(2, 2)) <= 1 || get_dist(guard, at(8, 2)) <= 1)) + back = TRUE + break + sleep(2) + TEST_ASSERT(back, "The guard didn't go back to its round: state [guard_ai.stealth_state()], [get_dist(guard, at(2, 2))] and [get_dist(guard, at(8, 2))] tiles from its stops") + TEST_ASSERT(!guard_ai.blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET), "A smashed bottle gave a guard a target") + +/// A bottle smashes 5 tiles behind a sentry: it walks a few steps toward it (STEALTH_SENTRY_INVESTIGATE_RANGE, 4), +/// looks round, and walks back to its post and its facing. +/datum/unit_test/voidcrew_stealth_live/hear/sentry_rule + +/datum/unit_test/voidcrew_stealth_live/hear/sentry_rule/Run() + TEST_ASSERT(make_room(34, 7), "No room for the test") + marker = allocate(/obj/effect/landmark/stealth_group, at(0, 6)) + // The player who keeps the level awake, walled off at the far end. + for(var/dy in 0 to 6) + var/turf/wall_spot = at(24, dy) + wall_spot.ChangeTurf(/turf/closed/wall) + person_at(30, 3) + ground() + var/turf/post = at(14, 3) + var/mob/living/carbon/human/npc/guard = guard_at(14, 3, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = wake(guard) + var/mob/living/carbon/human/thrower = person_at(0, 3, FALSE) + sleep(3 SECONDS) + TEST_ASSERT_NULL(guard_ai.route_id, "A guard with no stop near it claimed a route") + TEST_ASSERT_EQUAL(guard_ai.home_turf, post, "The sentry's post isn't where it spawned") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A sentry with nobody in sight isn't unaware") + var/turf/landing = at(9, 3) + var/obj/item/reagent_containers/cup/glass/bottle/beer/bottle = allocate(/obj/item/reagent_containers/cup/glass/bottle/beer, get_turf(thrower)) + bottle.throw_at(landing, 14, 2, thrower) + // Out of the way before the sentry turns round: this is about the noise, not a sighting. + thrower.forceMove(at(32, 5)) + var/start_time = world.time + var/best_dist = 0 + var/deadline = world.time + 25 SECONDS + while(world.time < deadline) + best_dist = max(best_dist, get_dist(guard, post)) + if(best_dist >= 3) + break + sleep(2) + TEST_ASSERT(best_dist >= 3, "The sentry didn't leave its post for a bottle 5 tiles off: it got [best_dist] tiles away, state [guard_ai.stealth_state()], heard [guard_ai.last_heard ? guard_ai.last_heard[1] : "nothing"]") + var/back = FALSE + deadline = start_time + 60 SECONDS + while(world.time < deadline) + best_dist = max(best_dist, get_dist(guard, post)) + if(guard_ai.stealth_state() == "unaware" && get_turf(guard) == post && guard.dir == EAST) + back = TRUE + break + sleep(2) + TEST_ASSERT(best_dist <= 5, "The sentry went [best_dist] tiles from its post for a small noise") + TEST_ASSERT(back, "The sentry didn't go back to its post: state [guard_ai.stealth_state()], [get_dist(guard, post)] tiles off, facing [dir2text(guard.dir)]") + TEST_ASSERT_EQUAL(guard_ai.sentry_dir, EAST, "The sentry's post facing changed") + TEST_ASSERT(!guard_ai.blackboard_key_exists(BB_BASIC_MOB_CURRENT_TARGET), "A smashed bottle gave a sentry a target") + +/// Someone walking up behind a guard is not heard; the same person running makes it turn. +/datum/unit_test/voidcrew_stealth_live/hear/live_footsteps + +/datum/unit_test/voidcrew_stealth_live/hear/live_footsteps/Run() + TEST_ASSERT(make_room(20, 3), "No room for the test") + // The player first: a guard woken on an empty level stays asleep. + var/mob/living/carbon/human/runner = person_at(5, 1) + var/mob/living/carbon/human/npc/guard = guard_at(10, 1, EAST) + var/datum/ai_controller/basic_controller/human_npc/stealth/guard_ai = wake(guard) + sleep(2 SECONDS) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A guard noticed someone standing 5 tiles behind it") + // Walking, to one tile behind it. + for(var/step_number in 1 to 4) + runner.Move(get_step(runner, EAST), EAST) + sleep(3) + TEST_ASSERT_EQUAL(get_dist(runner, guard), 1, "The walker didn't get behind the guard") + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "A guard heard someone walk up behind it") + // Back, and now running. + runner.forceMove(at(5, 1)) + guard_ai.stealth_go_unaware() + guard_ai.stealth_clear_wary() + guard.setDir(EAST) + sleep(2 SECONDS) + TEST_ASSERT_EQUAL(guard_ai.stealth_state(), "unaware", "The guard didn't settle") + runner.toggle_move_intent() + TEST_ASSERT_EQUAL(runner.move_intent, MOVE_INTENT_RUN, "The runner isn't running") + var/heard = FALSE + for(var/step_number in 1 to 3) + runner.Move(get_step(runner, EAST), EAST) + for(var/tick in 1 to 6) + if(guard_ai.stealth_state() != "unaware") + heard = TRUE + break + sleep(1) + if(heard) + break + var/deadline = world.time + 3 SECONDS + while(!heard && world.time < deadline) + heard = guard_ai.stealth_state() != "unaware" + sleep(1) + TEST_ASSERT(heard, "A guard never heard someone run up behind it (they are [get_dist(runner, guard)] tiles off)") + TEST_ASSERT(get_dist(runner, guard) >= 2, "The runner was next to the guard before it turned") + TEST_ASSERT_EQUAL(guard.dir, WEST, "The guard didn't turn to the footsteps") + TEST_ASSERT(guard_ai.last_heard?[1] == "footsteps", "It turned for something other than footsteps") + +/// A lookout that sees someone reaches for its radio; stunned before the call goes out, the other lookout never hears of it. +/datum/unit_test/voidcrew_stealth_live/hear/live_call + +/datum/unit_test/voidcrew_stealth_live/hear/live_call/Run() + TEST_ASSERT(make_room(40, 3), "No room for the test") + marker = allocate(/obj/effect/landmark/stealth_group, at(0, 2)) + var/mob/living/carbon/human/npc/scout = allocate(STEALTH_HEAR_LOOKOUT, at(4, 1)) + scout.setDir(EAST) + scout.AddElement(/datum/element/forced_gravity, 1) + var/mob/living/carbon/human/npc/listener = allocate(STEALTH_HEAR_LOOKOUT, at(36, 1)) + listener.setDir(EAST) + listener.AddElement(/datum/element/forced_gravity, 1) + person_at(6, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/scout_ai = wake(scout) + var/datum/ai_controller/basic_controller/human_npc/stealth/listener_ai = wake(listener) + var/deadline = world.time + 15 SECONDS + while(isnull(scout_ai.pending_call) && world.time < deadline) + sleep(1) + TEST_ASSERT_EQUAL(scout_ai.stealth_state(), "alert", "A lookout isn't alert on someone 2 tiles in front of it") + TEST_ASSERT_NOTNULL(scout_ai.pending_call, "A lookout that saw someone didn't reach for its radio") + scout.Stun(8 SECONDS) + TEST_ASSERT_NULL(scout_ai.pending_call, "A stunned lookout kept its call") + var/found = FALSE + deadline = world.time + 6 SECONDS + while(world.time < deadline) + if(listener_ai.stealth_state() != "unaware") + found = TRUE + sleep(2) + TEST_ASSERT(!found, "The other lookout heard of a call that was never made") + +#undef STEALTH_HEAR_GUARD +#undef STEALTH_HEAR_LOOKOUT diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_hostage.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_hostage.dm new file mode 100644 index 00000000000..9bdb6bf2f52 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_hostage.dm @@ -0,0 +1,89 @@ +// Hostages (step 5, voidcrew/modules/stealth/stealth_hostage.dm and stealth_hostage_pose.dm). Unit tests compile +// before voidcrew/_DEFINES, so values are written out: state "alert". + +/// `holder` holds `victim` at `wanted` grab state through tg's own grab. +/datum/unit_test/proc/stealth_test_grab(mob/living/carbon/human/holder, mob/living/victim, wanted) + holder.start_pulling(victim, supress_message = TRUE) + var/tries = 0 + while(holder.pulling == victim && holder.grab_state < wanted && tries++ < 3) + victim.grippedby(holder, instant = TRUE) + TEST_ASSERT_EQUAL(holder.grab_state, wanted, "Test fixture: couldn't get the grab") + +/// Hostages: a guard alert on someone holding one of its own holds fire and stands off; demands work once each; +/// hurting the hostage ends the deal; a stranger held up is no reason to hold fire. +/datum/unit_test/voidcrew_stealth_hostage + +/datum/unit_test/voidcrew_stealth_hostage/Run() + var/datum/turf_reservation/block = stealth_block(10, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 8, 2, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/datum/ai_planning_subtree/stealth_hostage/subtree = GLOB.ai_subtrees[/datum/ai_planning_subtree/stealth_hostage] + var/at = stealth_ai.planning_subtrees.Find(subtree) + TEST_ASSERT(at, "The hostage subtree isn't in the guard's planning") + TEST_ASSERT(at < stealth_ai.planning_subtrees.Find(GLOB.ai_subtrees[/datum/ai_planning_subtree/human_npc_shoot]), "The hostage subtree comes after shooting") + var/mob/living/carbon/human/npc/friend = stealth_guard(block, 3, 2, WEST) + var/mob/living/carbon/human/holder = stealth_person(block, 2, 2) + var/obj/item/gun/ballistic/automatic/pistol/pistol = allocate(/obj/item/gun/ballistic/automatic/pistol) + pistol.can_misfire = FALSE + holder.put_in_active_hand(pistol, forced = TRUE) + holder.setDir(EAST) + stealth_test_grab(holder, friend, GRAB_NECK) + TEST_ASSERT_EQUAL(stealth_hostage_of(holder), friend, "A neck grab with a gun isn't a hostage") + stealth_ai.stealth_go_alert(holder) + TEST_ASSERT_EQUAL(subtree.SelectBehaviors(stealth_ai, 1), SUBTREE_RETURN_FINISH_PLANNING, "The guard didn't hold fire") + TEST_ASSERT_EQUAL(stealth_ai.standoff_holder?.resolve(), holder, "No standoff") + // Demands, once each. + var/obj/item/held_weapon = guard.get_active_held_item() || guard.get_inactive_held_item() + holder.say("Back off!") + TEST_ASSERT(stealth_ai.standoff_backed_off, "Told to back off, it didn't") + holder.say("Drop the gun!") + TEST_ASSERT(stealth_ai.standoff_dropped, "Told to drop it, it didn't") + if(held_weapon) + TEST_ASSERT(!(held_weapon in guard.held_items), "Told to drop it, it kept its weapon") + // Hurting the hostage ends the deal for good. + pistol.fire_gun(friend, holder, TRUE, null) + TEST_ASSERT_NULL(stealth_ai.standoff_holder, "The standoff outlived a shot into the hostage") + TEST_ASSERT(LAZYFIND(stealth_ai.no_deals, REF(holder)), "No grudge after the hostage was shot") + TEST_ASSERT(isnull(subtree.SelectBehaviors(stealth_ai, 1)), "Stood off again against someone who shot a hostage") + // A stranger held up is no reason to hold fire. + var/mob/living/carbon/human/npc/guard2 = stealth_guard(block, 8, 4, WEST) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai2 = stealth_ai(guard2) + var/mob/living/carbon/human/stranger = stealth_person(block, 3, 4) + var/mob/living/carbon/human/holder2 = stealth_person(block, 2, 4) + var/obj/item/gun/ballistic/automatic/pistol/pistol2 = allocate(/obj/item/gun/ballistic/automatic/pistol) + holder2.put_in_active_hand(pistol2, forced = TRUE) + stealth_test_grab(holder2, stranger, GRAB_NECK) + stealth_ai2.stealth_go_alert(holder2) + TEST_ASSERT(isnull(subtree.SelectBehaviors(stealth_ai2, 1)), "A guard held fire for a stranger") + qdel(block) + +/// The hold at gunpoint is drawn: the hostage is posed in front of the holder, on its feet, facing his way, and goes +/// back to tg's own grab when the gun is put away and to nothing once let go. +/datum/unit_test/voidcrew_stealth_hostage_pose + +/datum/unit_test/voidcrew_stealth_hostage_pose/Run() + var/datum/turf_reservation/block = stealth_block(9, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/holder = stealth_person(block, 4, 2) + var/mob/living/carbon/human/hostage = stealth_person(block, 5, 2) + var/obj/item/gun/ballistic/automatic/pistol/pistol = allocate(/obj/item/gun/ballistic/automatic/pistol) + holder.put_in_active_hand(pistol, forced = TRUE) + holder.setDir(EAST) + stealth_test_grab(holder, hostage, GRAB_NECK) + holder.setDir(EAST) + TEST_ASSERT_EQUAL(stealth_hostage_of(holder), hostage, "A neck grab with a gun isn't a hostage") + TEST_ASSERT_EQUAL(hostage.hostage_pose_dir, EAST, "The hostage isn't posed for the holder's facing") + TEST_ASSERT_EQUAL(hostage.dir, EAST, "The hostage doesn't face the holder's way") + TEST_ASSERT_EQUAL(hostage.body_position, STANDING_UP, "The hostage isn't held on its feet") + holder.setDir(NORTH) + TEST_ASSERT_EQUAL(hostage.hostage_pose_dir, NORTH, "The pose didn't follow the holder's turn") + // The gun put away: tg's own grab again. + holder.dropItemToGround(pistol, force = TRUE) + TEST_ASSERT_NULL(stealth_hostage_of(holder), "Still a hostage with no gun out") + TEST_ASSERT_EQUAL(hostage.hostage_pose_dir, 0, "Still posed with no gun out") + holder.put_in_active_hand(pistol, forced = TRUE) + TEST_ASSERT_EQUAL(hostage.hostage_pose_dir, holder.dir, "Not posed again when the gun came back out") + holder.stop_pulling() + TEST_ASSERT_EQUAL(hostage.hostage_pose_dir, 0, "Still posed after being let go") + qdel(block) diff --git a/voidcrew/modules/unit_tests/voidcrew_stealth_light.dm b/voidcrew/modules/unit_tests/voidcrew_stealth_light.dm new file mode 100644 index 00000000000..1bab5635a23 --- /dev/null +++ b/voidcrew/modules/unit_tests/voidcrew_stealth_light.dm @@ -0,0 +1,579 @@ +// Stealth guards: flashlights, elbow-to-elbow sight, volleys and sentry facing (owner decisions 31, 39 and 41, +// voidcrew/modules/stealth/stealth_light.dm). Values from voidcrew/_DEFINES are written out: STEALTH_LIGHT_HOLD +// 5 s, STEALTH_TORCH_FORWARD 0.5, STEALTH_STRAY_LIGHT_RANGE 5, STEALTH_NOISE_COALESCE 3 s, +// STEALTH_SENTRY_TURN_INTERVAL 8 s, STEALTH_SENTRY_GLANCE_TIME 2 s. + +/// Waits for tg's static lighting to apply what was just switched or moved (it updates on its own subsystem). +/// `target`: a lamp whose light is applied here if SSlighting hasn't got to it. A test run first in a world can find +/// SSlighting still holding the whole map's boot backlog (70,000 sources, not fired once 3 minutes in). +/datum/unit_test/proc/stealth_settle_light(atom/movable/target) + sleep(1) + for(var/i in 1 to 50) + if(!length(SSlighting.sources_queue) && !length(SSlighting.current_sources)) + stealth_land_cone(target) + return + sleep(1) + var/datum/light_source/source = target?.light + if(source?.needs_update) + source.update_corners() + source.needs_update = LIGHTING_NO_UPDATE + stealth_land_cone(target) + +/// Applies `lamp`'s queued light now, without waiting, as SSlighting would: for checks that a beam's short timers +/// would outrun. +/datum/unit_test/proc/stealth_apply_light(atom/movable/lamp) + var/datum/light_source/source = lamp?.light + if(source?.needs_update) + source.update_corners() + source.needs_update = LIGHTING_NO_UPDATE + stealth_land_cone(lamp) + +/// A guard's cone looks for its lamp's light once a tick; this looks now, so a test needn't wait the tick. +/datum/unit_test/proc/stealth_land_cone(atom/movable/lamp) + var/obj/effect/abstract/stealth_torch/torch = lamp + if(istype(torch) && torch.owner_ai) + torch.owner_ai.stealth_cone_stop() + torch.owner_ai.stealth_cone_check() + +/// The guard switches its light on in the dark and while on edge, off in the light, and can't while it is cut out. +/datum/unit_test/voidcrew_stealth_light_switch + +/datum/unit_test/voidcrew_stealth_light_switch/Run() + var/datum/turf_reservation/block = stealth_block(9, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/obj/item/flashlight/light = stealth_ai.stealth_light() + TEST_ASSERT_NOTNULL(light, "A scav guard has no flashlight on its body") + TEST_ASSERT(!stealth_ai.stealth_light_shows(), "A guard's light starts on") + var/turf/here = get_turf(guard) + stealth_ai.stealth_update_light() + TEST_ASSERT(!stealth_ai.stealth_light_shows(), "An unaware guard in the light switched its light on") + GLOB.stealth_test_dark_turfs[here] = TRUE + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A guard standing in the dark didn't switch its light on") + TEST_ASSERT(!light.light_on, "The seclite item lit its own beam as well as the pool") + // Back in the light it keeps it on a moment, then switches it off. + GLOB.stealth_test_dark_turfs[here] = FALSE + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A guard switched its light off the moment it stepped into the light") + stealth_ai.light_hold_until = 0 + stealth_ai.stealth_update_light() + TEST_ASSERT(!stealth_ai.stealth_light_shows(), "An unaware guard in the light kept its light on") + // On edge, it is on even in the light. + stealth_ai.stealth_go_suspicious(stealth_at(block, 6, 2)) + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A suspicious guard's light isn't on") + stealth_ai.stealth_go_searching(stealth_at(block, 6, 2)) + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A searching guard's light isn't on") + stealth_ai.stealth_go_unaware() + stealth_ai.light_hold_until = 0 + stealth_ai.stealth_update_light() + TEST_ASSERT(!stealth_ai.stealth_light_shows(), "A calm guard in the light kept its light on") + // An EMP cuts it out at once, and the guard can't switch it back on until it recovers. + GLOB.stealth_test_dark_turfs[here] = TRUE + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "The light didn't come on in the dark") + guard.emp_act(EMP_LIGHT) + TEST_ASSERT(!stealth_ai.stealth_light_shows(), "An EMP didn't cut the guard's light out") + // It sputters as it dies (decision 41): a flash of the beam with the light counted off, then dark again. + stealth_ai.stealth_sputter(stealth_ai.sputter_serial, TRUE) + TEST_ASSERT(stealth_ai.torch.light_on && !stealth_ai.stealth_light_shows(), "A cut-out seclite doesn't sputter") + stealth_ai.stealth_sputter(stealth_ai.sputter_serial, FALSE) + TEST_ASSERT(!stealth_ai.torch.light_on, "A sputter left the beam on") + stealth_ai.stealth_update_light() + TEST_ASSERT(!stealth_ai.stealth_light_shows(), "A guard switched an EMP'd light straight back on") + light.disabled_time = 0 + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "The light didn't come back on once the EMP wore off") + // Stunned, it has no light. + guard.Paralyze(5 SECONDS) + TEST_ASSERT(!stealth_ai.stealth_light_shows(), "A stunned guard kept its light on") + guard.SetParalyzed(0) + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "The light didn't come back once the guard was up") + // Gone from its body, it goes out at once. + light.forceMove(stealth_at(block, 4, 4)) + TEST_ASSERT_NULL(stealth_ai.stealth_light(), "A guard still counts a light that left its body") + TEST_ASSERT(!stealth_ai.stealth_light_shows(), "A guard's pool stayed on after its seclite was taken") + GLOB.stealth_test_dark_turfs[here] = FALSE + qdel(block) + +/// Decision 41: the lamp sits on the guard's tile and its beam starts half a tile ahead; a turn passes through the +/// halfway point, a turn of its own is led by the beam, a step at a walk carries the beam half a tile at a time, and +/// a searching guard sweeps it side to side. +/datum/unit_test/voidcrew_stealth_light_pool + +/datum/unit_test/voidcrew_stealth_light_pool/Run() + var/datum/turf_reservation/block = stealth_block(12, 7) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 3) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + if(guard.move_intent == MOVE_INTENT_RUN) + guard.toggle_move_intent() + for(var/dx in 0 to 11) + for(var/dy in 0 to 6) + GLOB.stealth_test_dark_turfs[stealth_at(block, dx, dy)] = TRUE + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A guard in the dark has no beam") + var/obj/effect/abstract/stealth_torch/torch = stealth_ai.torch + TEST_ASSERT_EQUAL(get_turf(torch), get_turf(guard), "The lamp isn't on the guard's tile") + TEST_ASSERT_EQUAL(torch.light_dir, EAST, "The beam doesn't point the way the guard faces") + TEST_ASSERT_EQUAL(torch.beam_x, -0.5, "The beam doesn't start half a tile ahead of a guard facing east") + TEST_ASSERT_EQUAL(torch.beam_y, 0, "A beam facing east starts off to one side") + // A turn of 90 degrees shows the beam halfway, then lands. + guard.setDir(NORTH) + TEST_ASSERT_EQUAL(torch.light_dir, NORTHEAST, "A quarter turn didn't pass the beam through the diagonal") + stealth_ai.stealth_torch_settle(stealth_ai.torch_serial) + TEST_ASSERT_EQUAL(torch.light_dir, NORTH, "The beam didn't land on the new facing") + TEST_ASSERT_EQUAL(torch.beam_y, -0.5, "The beam doesn't start half a tile ahead of a guard facing north") + TEST_ASSERT_EQUAL(torch.beam_x, 0, "A beam facing north starts off to one side") + // A turn of its own: the beam goes halfway first, while the body still faces the old way. + stealth_ai.stealth_turn_to(EAST) + TEST_ASSERT_EQUAL(guard.dir, NORTH, "A guard's own turn has no tell") + TEST_ASSERT_EQUAL(torch.light_dir, NORTHEAST, "The beam didn't lead a turn the guard makes on its own") + stealth_ai.stealth_finish_turn(EAST, stealth_ai.turn_planned_at) + TEST_ASSERT_EQUAL(guard.dir, EAST, "The guard didn't finish its turn") + TEST_ASSERT_EQUAL(torch.light_dir, EAST, "The beam didn't land when the led turn finished") + TEST_ASSERT(!stealth_ai.torch_pass, "A led turn passed through the halfway point a second time") + // A turn it drops: the beam goes back. + stealth_ai.stealth_turn_to(SOUTH) + TEST_ASSERT_EQUAL(torch.light_dir, SOUTHEAST, "The beam didn't lead the second turn") + stealth_ai.stealth_drop_turn() + TEST_ASSERT_EQUAL(torch.light_dir, EAST, "A dropped turn left the beam off to the side") + // One step at a walk: the lamp moves at once, the beam half a tile behind it until it settles. + guard.forceMove(stealth_at(block, 3, 3)) + TEST_ASSERT_EQUAL(get_turf(torch), stealth_at(block, 3, 3), "The lamp didn't follow the guard's step") + TEST_ASSERT_EQUAL(torch.beam_x, 0, "A step at a walk didn't hold the beam half a tile back") + stealth_ai.stealth_torch_settle(stealth_ai.torch_serial) + TEST_ASSERT_EQUAL(torch.beam_x, -0.5, "The beam didn't land after the step") + // Further than a step (a shove, a teleport): no half step. + guard.forceMove(stealth_at(block, 6, 3)) + TEST_ASSERT_EQUAL(get_turf(torch), stealth_at(block, 6, 3), "The lamp didn't follow the guard") + TEST_ASSERT_EQUAL(torch.beam_x, -0.5, "A jump of three tiles held the beam back") + // A walked corner (tg turns a walker, then moves it, in one tick): the beam passes the diagonal as it steps. + guard.setDir(NORTH) + guard.forceMove(stealth_at(block, 6, 4)) + TEST_ASSERT_EQUAL(torch.light_dir, NORTHEAST, "A step round a corner snapped the beam round") + stealth_ai.stealth_torch_settle(stealth_ai.torch_serial) + TEST_ASSERT_EQUAL(torch.light_dir, NORTH, "The beam didn't land after a step round a corner") + TEST_ASSERT_EQUAL(torch.beam_y, -0.5, "The beam didn't land half a tile ahead after a step round a corner") + // A diagonal step turns the walker after it moves: the beam still passes the diagonal. + guard.forceMove(stealth_at(block, 6, 3)) + guard.setDir(EAST) + TEST_ASSERT_EQUAL(torch.light_dir, NORTHEAST, "A turn just after a step snapped the beam round") + stealth_ai.stealth_torch_settle(stealth_ai.torch_serial) + TEST_ASSERT_EQUAL(torch.light_dir, EAST, "The beam didn't land after a turn just after a step") + // Searching, standing: one side, back, the other side, back. + // Its sweep runs only while its AI does (a dormant level sweeps nothing). + stealth_ai.stealth_go_searching(stealth_at(block, 8, 3)) + TEST_ASSERT(stealth_ai.stealth_scanning() || !stealth_ai.sweeping, "A guard whose AI is off sweeps its beam") + stealth_ai.set_ai_status(AI_STATUS_ON) + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.sweeping, "A searching guard with its light on doesn't sweep") + stealth_ai.torch_moved_at = 0 + stealth_ai.turned_at = 0 + var/side = stealth_ai.look_side + stealth_ai.stealth_sweep_tick() + TEST_ASSERT_EQUAL(torch.light_dir, turn(EAST, 45 * side), "The sweep's first move isn't 45 degrees to a side") + stealth_ai.stealth_sweep_tick() + TEST_ASSERT_EQUAL(torch.light_dir, EAST, "The sweep didn't come back to the middle") + stealth_ai.stealth_sweep_tick() + TEST_ASSERT_EQUAL(torch.light_dir, turn(EAST, -45 * side), "The sweep didn't go to the other side") + stealth_ai.stealth_sweep_tick() + TEST_ASSERT_EQUAL(torch.light_dir, EAST, "The sweep didn't end in the middle") + // A step interrupts it; calm again, it stops. + stealth_ai.stealth_sweep_tick() + guard.forceMove(stealth_at(block, 7, 3)) + TEST_ASSERT_EQUAL(torch.light_dir, EAST, "A step left the beam off to the side") + stealth_ai.stealth_go_unaware() + stealth_ai.stealth_sweep_tick() + TEST_ASSERT(!stealth_ai.sweeping, "A calm guard keeps sweeping") + for(var/dx in 0 to 11) + for(var/dy in 0 to 6) + GLOB.stealth_test_dark_turfs[stealth_at(block, dx, dy)] = FALSE + qdel(guard) + TEST_ASSERT(QDELETED(torch), "A deleted guard left its lamp behind") + qdel(block) + +/// Decision 41, real lighting: the beam is a wedge. It lights 1 to 4 tiles ahead and the tiles beside 2 and 3 +/// ahead; the guard's own tile, its sides, its back, 5 ahead and two tiles off the line stay dark. A wall stops it. +/// Decision 42: the cone players see shows and hides with the light, points where the beam points, and stops at a wall. +/datum/unit_test/voidcrew_stealth_light_cone + +/datum/unit_test/voidcrew_stealth_light_cone/Run() + // STEALTH_BEAM_LENGTHS: the unit tests are included before voidcrew/_DEFINES, so the number is written out + var/open_reach = 22 + var/datum/turf_reservation/block = stealth_block(12, 7) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 3) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + for(var/dx in 0 to 11) + for(var/dy in 0 to 6) + GLOB.stealth_test_dark_turfs[stealth_at(block, dx, dy)] = TRUE + guard.setDir(EAST) + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A guard in the dark has no beam") + var/obj/effect/abstract/stealth_beam/beam = stealth_ai.beam + TEST_ASSERT_NOTNULL(beam, "A lit guard shows no cone") + stealth_settle_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.holder, guard, "The cone isn't on its guard") + TEST_ASSERT(beam in guard.vis_contents, "The cone isn't drawn on its guard") + TEST_ASSERT_EQUAL(beam.shown_dir, EAST, "The cone doesn't point the way the guard faces") + TEST_ASSERT_EQUAL(beam.icon_state, "beam_[open_reach]", "An open beam's cone is cut short, or has no glow facing sideways") + TEST_ASSERT_EQUAL(PLANE_TO_TRUE(beam.plane), O_LIGHTING_VISUAL_PLANE, "The cone isn't drawn as light") + // It follows the beam through a turn, and facing away the lamp's glow is hidden by the body. It never moves ahead + // of the light on the floor: until the lamp's turn is applied, it still points the old way. + guard.setDir(NORTH) + TEST_ASSERT(stealth_ai.torch.light?.needs_update, "A turn didn't queue the lamp's light") + TEST_ASSERT_EQUAL(beam.shown_dir, EAST, "The cone turned before the light on the floor did") + stealth_apply_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.shown_dir, NORTHEAST, "The cone didn't pass through the diagonal with the beam") + stealth_ai.stealth_torch_settle(stealth_ai.torch_serial) + stealth_apply_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.shown_dir, NORTH, "The cone didn't land on the new facing") + TEST_ASSERT(findtext(beam.icon_state, "back_") == 1, "A guard facing away shows its lamp's glow through its body") + // A turn of its own: the cone leads it with the beam. + stealth_ai.stealth_turn_to(EAST) + stealth_apply_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.shown_dir, NORTHEAST, "The cone didn't lead a turn the guard makes on its own") + stealth_ai.stealth_finish_turn(EAST, stealth_ai.turn_planned_at) + stealth_apply_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.shown_dir, EAST, "The cone didn't land when the led turn finished") + // A wall two tiles ahead cuts it at the wall. + var/turf/wall = stealth_at(block, 4, 3) + wall.ChangeTurf(/turf/closed/wall) + TEST_ASSERT_EQUAL(stealth_beam_reach(get_turf(guard), EAST), 7, "The cone doesn't stop on a wall two tiles ahead") + TEST_ASSERT_EQUAL(stealth_beam_reach(stealth_at(block, 6, 3), EAST), open_reach, "The cone stops with nothing ahead") + stealth_ai.stealth_place_torch() + stealth_apply_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.icon_state, "beam_7", "The cone runs through a wall two tiles ahead") + // Off with the light at once, and gone with the guard. + stealth_ai.stealth_set_light(FALSE) + TEST_ASSERT_NULL(beam.holder, "The cone stayed on with the light off") + TEST_ASSERT(!(beam in guard.vis_contents), "The cone is still drawn with the light off") + stealth_ai.stealth_set_light(TRUE) + stealth_settle_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.holder, guard, "The cone didn't come back with the light") + qdel(guard) + TEST_ASSERT(QDELETED(beam), "The cone outlived its guard") + qdel(block) + +/// Playtest 2 (owner: "light goes through walls"): while a new aim waits on the lamp, the old cone stays on the guard. +/// Walking toward a wall or round a corner in that wait, the old cone must still stop at the wall from where it is now. +/// Backing away from a wall, it stops there too while the body glides off the old tile. +/datum/unit_test/voidcrew_stealth_light_cone_wall + +/datum/unit_test/voidcrew_stealth_light_cone_wall/Run() + var/open_reach = 22 + var/datum/turf_reservation/block = stealth_block(12, 7) + TEST_ASSERT_NOTNULL(block, "No room for the test") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 3) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + for(var/dx in 0 to 11) + for(var/dy in 0 to 6) + GLOB.stealth_test_dark_turfs[stealth_at(block, dx, dy)] = TRUE + // A wall four tiles ahead. + var/turf/wall = stealth_at(block, 6, 3) + wall.ChangeTurf(/turf/closed/wall) + guard.setDir(EAST) + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A guard in the dark has no beam") + var/obj/effect/abstract/stealth_beam/beam = stealth_ai.beam + stealth_settle_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.icon_state, "beam_15", "The cone doesn't stop on a wall four tiles ahead") + // One step on toward it, the lamp not yet applied: the old aim waits, cut at the wall from the new tile. + guard.forceMove(stealth_at(block, 3, 3)) + TEST_ASSERT(stealth_ai.torch.light?.needs_update, "A step didn't queue the lamp's light") + TEST_ASSERT_EQUAL(beam.icon_state, "beam_11", "The waiting cone runs through the wall it walked toward") + stealth_apply_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.icon_state, "beam_11", "The cone isn't cut at the wall once the light lands") + // Round a corner: a step north to a tile with a wall right beside it to the east, the cone still pointing east. + var/turf/side_wall = stealth_at(block, 4, 4) + side_wall.ChangeTurf(/turf/closed/wall) + guard.forceMove(stealth_at(block, 3, 4)) + TEST_ASSERT(stealth_ai.torch.light?.needs_update, "A step didn't queue the lamp's light") + TEST_ASSERT_EQUAL(beam.shown_dir, EAST, "Test fixture: the cone turned before the light did") + TEST_ASSERT_EQUAL(beam.icon_state, "beam_3", "The waiting cone runs through the wall beside its new tile") + stealth_apply_light(stealth_ai.torch) + // Backing away from the wall: until the body lands, the cone stops at the wall ahead of the tile it left. + guard.forceMove(stealth_at(block, 3, 3)) + stealth_apply_light(stealth_ai.torch) + stealth_ai.torch_from = null + stealth_ai.stealth_place_torch() + stealth_apply_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.icon_state, "beam_11", "Test fixture: the cone isn't cut at the wall") + guard.set_glide_size(2) + guard.forceMove(stealth_at(block, 2, 3)) + stealth_apply_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.icon_state, "beam_11", "Mid-step backing away, the cone ran past the wall ahead of the tile it left") + stealth_ai.torch_from_until = world.time + stealth_ai.stealth_cone_landed() + stealth_apply_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.icon_state, "beam_15", "Landed, the cone didn't reach the wall again") + // Nothing ahead: full length. + wall.ChangeTurf(/turf/open/floor/iron) + stealth_ai.stealth_place_torch() + stealth_apply_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(beam.icon_state, "beam_[open_reach]", "An open cone is cut short") + qdel(guard) + qdel(block) + +/datum/unit_test/voidcrew_stealth_light_beam + +/datum/unit_test/voidcrew_stealth_light_beam/Run() + var/datum/turf_reservation/block = stealth_block(12, 9) + TEST_ASSERT_NOTNULL(block, "No room for the test") + stealth_unlist(block, 12, 9) + TEST_ASSERT(stealth_tile_is_dark(stealth_at(block, 5, 4)), "Reserved test space isn't dark, so the light can't be tested") + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 4) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A guard standing in the dark didn't switch its light on") + stealth_settle_light(stealth_ai.torch) + // offsets from the guard (ahead, aside) + var/list/lit = list(list(1, 0), list(2, 0), list(3, 0), list(4, 0), list(2, 1), list(2, -1), list(3, 1), list(3, -1)) + var/list/dark = list(list(0, 0), list(-1, 0), list(0, 1), list(0, -1), list(-1, 1), list(5, 0), list(6, 0), list(3, 2), list(3, -2), list(1, 2)) + for(var/list/offset as anything in lit) + TEST_ASSERT(!stealth_tile_is_dark(stealth_at(block, 2 + offset[1], 4 + offset[2])), "The beam doesn't light [offset[1]] ahead, [offset[2]] aside") + for(var/list/offset as anything in dark) + TEST_ASSERT(stealth_tile_is_dark(stealth_at(block, 2 + offset[1], 4 + offset[2])), "The beam lights [offset[1]] ahead, [offset[2]] aside") + // The beam is what the guard's own "is my spot dark" test leaves out, wherever it lands. + TEST_ASSERT(stealth_tile_is_dark(stealth_at(block, 4, 4), no_guard_lights = TRUE), "A tile lit only by a guard's beam isn't dark without guard lights") + TEST_ASSERT(stealth_room_is_dark(stealth_at(block, 4, 4)), "A tile lit only by a guard's beam isn't dark by the room's light") + // Turned north, the wedge turns with it. + guard.setDir(NORTH) + stealth_ai.stealth_torch_settle(stealth_ai.torch_serial) + stealth_settle_light(stealth_ai.torch) + TEST_ASSERT(!stealth_tile_is_dark(stealth_at(block, 2, 6)), "The beam doesn't light 2 ahead of a guard facing north") + TEST_ASSERT(stealth_tile_is_dark(stealth_at(block, 4, 4)), "The beam still lights where the guard used to face") + qdel(guard) + stealth_settle_light() + TEST_ASSERT(stealth_tile_is_dark(stealth_at(block, 2, 6)), "The beam stayed lit after its guard was gone") + // A wall across the room two tiles ahead: lit up to it, dark past it. A lone wall tile wouldn't do: tg lights a + // tile by its corners, and the tiles beside the one behind a pillar still see the beam. + for(var/dy in 1 to 7) + var/turf/wall = stealth_at(block, 4, dy) + wall.ChangeTurf(/turf/closed/wall) + guard = stealth_guard(block, 2, 4) + stealth_ai = stealth_ai(guard) + stealth_ai.stealth_update_light() + stealth_settle_light(stealth_ai.torch) + TEST_ASSERT(!stealth_tile_is_dark(stealth_at(block, 3, 4)), "The beam doesn't light the tile before a wall") + TEST_ASSERT(stealth_tile_is_dark(stealth_at(block, 5, 4)), "The beam lights the tile behind a wall") + qdel(guard) + qdel(block) + +/// Decision 41: a lit flashlight carried behind an unaware guard that stands in the dark makes it suspicious, never +/// alert, and it turns to look. Unlit, out of the light's reach, or in a lit room, it draws nothing. +/datum/unit_test/voidcrew_stealth_stray_light + +/datum/unit_test/voidcrew_stealth_stray_light/Run() + var/datum/turf_reservation/block = stealth_block(14, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + for(var/dx in 0 to 13) + for(var/dy in 0 to 4) + GLOB.stealth_test_dark_turfs[stealth_at(block, dx, dy)] = TRUE + var/mob/living/carbon/human/person = stealth_person(block, 6, 2) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 9, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + TEST_ASSERT_EQUAL(stealth_carried_light(person), 0, "Someone with no light counts as carrying one") + // Three tiles behind it in the dark, no light: nothing. + stealth_scans(guard, 4) + var/list/entry = stealth_ai.notice_map[REF(person)] + TEST_ASSERT(isnull(entry) || entry[1] == 0, "A guard built notice on someone behind it in the dark ([entry?[1]])") + // The same with a lit flashlight in hand. + var/obj/item/flashlight/held = allocate(/obj/item/flashlight, get_turf(person)) + TEST_ASSERT(person.put_in_hands(held), "Test fixture: the flashlight can't be held") + held.attack_self(person) + TEST_ASSERT(held.light_on, "Test fixture: the flashlight didn't switch on") + TEST_ASSERT(stealth_carried_light(person) >= 3, "A lit flashlight in hand reaches [stealth_carried_light(person)] tiles") + for(var/i in 1 to 6) + stealth_scans(guard, 1) + if(stealth_ai.stealth_state() != "unaware") + break + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "A lit flashlight behind a guard in the dark made it [stealth_ai.stealth_state()]") + entry = stealth_ai.notice_map[REF(person)] + TEST_ASSERT(entry[1] <= 1, "A light behind a guard filled its notice past suspicious ([entry[1]])") + TEST_ASSERT_EQUAL(guard.dir, WEST, "The guard didn't turn to the light") + qdel(guard) + // Out of the light's reach: nothing. + person.forceMove(stealth_at(block, 1, 2)) + guard = stealth_guard(block, 9, 2) + stealth_ai = stealth_ai(guard) + stealth_scans(guard, 6) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A light 8 tiles behind a guard drew its notice") + qdel(guard) + // In a lit room a flashlight is nothing to wonder at. + person.forceMove(stealth_at(block, 6, 2)) + GLOB.stealth_test_dark_turfs[stealth_at(block, 9, 2)] = FALSE + guard = stealth_guard(block, 9, 2) + stealth_ai = stealth_ai(guard) + stealth_scans(guard, 6) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A flashlight behind a guard in a lit room drew its notice") + entry = stealth_ai.notice_map[REF(person)] + TEST_ASSERT(isnull(entry) || entry[1] == 0, "A flashlight behind a guard in a lit room built notice ([entry?[1]])") + for(var/dx in 0 to 13) + for(var/dy in 0 to 4) + GLOB.stealth_test_dark_turfs[stealth_at(block, dx, dy)] = FALSE + qdel(block) + +/// Real lighting: in a dark room the guard's pool lights what it lands on and nothing behind it. +/datum/unit_test/voidcrew_stealth_light_sight + +/datum/unit_test/voidcrew_stealth_light_sight/Run() + var/datum/turf_reservation/block = stealth_block(12, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + stealth_unlist(block, 12, 5) + var/mob/living/carbon/human/person = stealth_person(block, 5, 2) + var/turf/spot = get_turf(person) + TEST_ASSERT(stealth_tile_is_dark(spot), "Reserved test space isn't dark, so the light can't be tested") + // Without a light: 3 tiles off in the dark fills slowly (no near fill in the dark, decision 39). + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 2, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + qdel(stealth_ai.stealth_light()) + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "A guard with no light noticed someone 3 tiles off in the dark in one look") + qdel(guard) + // With one: it switches it on, the pool lands on them, and it notices them. + guard = stealth_guard(block, 2, 2) + stealth_ai = stealth_ai(guard) + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A guard standing in the dark didn't switch its light on") + stealth_settle_light(stealth_ai.torch) + TEST_ASSERT(!stealth_tile_is_dark(spot), "The guard's pool doesn't light the tile it lands on") + TEST_ASSERT(!stealth_tile_is_dark(stealth_at(block, 6, 2)), "The guard's pool doesn't light the tile past it") + TEST_ASSERT(stealth_tile_is_dark(get_turf(guard)), "The guard's pool lights its own tile") + TEST_ASSERT(stealth_tile_is_dark(stealth_at(block, 1, 2)), "The guard's pool lights the tile behind it") + TEST_ASSERT(stealth_tile_is_dark(stealth_at(block, 8, 2)), "The guard's pool lights 6 tiles ahead") + stealth_scans(guard, 1) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "suspicious", "A guard didn't notice someone its pool was on") + qdel(guard) + stealth_settle_light() + TEST_ASSERT(stealth_tile_is_dark(spot), "The pool stayed lit after its guard was gone") + qdel(block) + +/// Real lighting: a searching guard sees as far as in daylight onto the tiles its pool lights. +/datum/unit_test/voidcrew_stealth_light_body + +/datum/unit_test/voidcrew_stealth_light_body/Run() + var/datum/turf_reservation/block = stealth_block(12, 5) + TEST_ASSERT_NOTNULL(block, "No room for the test") + stealth_unlist(block, 12, 5) + allocate(/obj/effect/landmark/stealth_group, stealth_at(block, 7, 4)) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 1, 2) + var/mob/living/carbon/human/npc/friend = stealth_guard(block, 4, 2) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + var/datum/ai_controller/basic_controller/human_npc/stealth/friend_ai = stealth_ai(friend) + stealth_ai.stealth_setup() + friend_ai.stealth_setup() + qdel(friend_ai.stealth_light()) + friend.death() + var/turf/body_turf = get_turf(friend) + TEST_ASSERT(stealth_tile_is_dark(body_turf), "Reserved test space isn't dark, so the light can't be tested") + var/datum/stealth_skill/profile = stealth_ai.stealth_skill() + // Its light cut out, the body's tile is dark to it. + var/obj/item/flashlight/light = stealth_ai.stealth_light() + light.on_saboteur(null, 1 MINUTES) + stealth_ai.stealth_go_searching(get_turf(guard)) + TEST_ASSERT(!stealth_ai.stealth_light_shows(), "A guard's cut-out light shows a pool") + TEST_ASSERT_EQUAL(stealth_ai.stealth_range_onto(body_turf), profile.dark_sight_range, "A guard sees into the dark as if it were lit") + // With it on, it is lit, and it finds the body. + light.disabled_time = 0 + stealth_ai.stealth_update_light() + TEST_ASSERT(stealth_ai.stealth_light_shows(), "A searching guard's light didn't come on") + stealth_settle_light(stealth_ai.torch) + TEST_ASSERT_EQUAL(stealth_ai.stealth_range_onto(body_turf), profile.sight_range, "A guard's pool doesn't light the body it lands on") + stealth_ai.next_body_scan = 0 + stealth_ai.stealth_check_bodies() + TEST_ASSERT(REF(friend) in stealth_ai.blackboard["stealth_bodies_seen"], "A searching guard with its light on didn't find the body") + TEST_ASSERT(get_dist(stealth_ai.search_center, friend) <= 1, "The search didn't move to the body") + TEST_ASSERT(stealth_ai.search_for_body, "The search isn't marked as over a body") + qdel(block) + +/// Elbow to elbow: someone on the next tile in front is seen in the dark (an alert, decision 32); behind or side-on +/// is not; two ahead in the dark fills slowly (no near fill in the dark, decision 39). +/datum/unit_test/voidcrew_stealth_adjacent + +/datum/unit_test/voidcrew_stealth_adjacent/Run() + var/datum/turf_reservation/block = stealth_block(7, 7) + TEST_ASSERT_NOTNULL(block, "No room for the test") + for(var/dx in 0 to 6) + for(var/dy in 0 to 6) + GLOB.stealth_test_dark_turfs[stealth_at(block, dx, dy)] = TRUE + var/mob/living/carbon/human/person = stealth_person(block, 4, 3) + // offset from the guard => its state after two scans + var/list/cases = list( + list(1, 0, "alert"), + list(-1, 0, "unaware"), + list(0, 1, "unaware"), + list(2, 0, "unaware"), + ) + for(var/list/test_case as anything in cases) + person.forceMove(stealth_at(block, 3 + test_case[1], 3 + test_case[2])) + var/mob/living/carbon/human/npc/guard = stealth_guard(block, 3, 3) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = stealth_ai(guard) + stealth_scans(guard, 2) + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), test_case[3], "Offset ([test_case[1]], [test_case[2]]) in the dark: state [stealth_ai.stealth_state()]") + qdel(guard) + for(var/dx in 0 to 6) + for(var/dy in 0 to 6) + GLOB.stealth_test_dark_turfs[stealth_at(block, dx, dy)] = FALSE + qdel(block) + +/// Takes a test block's turfs off the test light list, so they read the real light. +/datum/unit_test/proc/stealth_unlist(datum/turf_reservation/block, width, height) + for(var/dx in 0 to width - 1) + for(var/dy in 0 to height - 1) + GLOB.stealth_test_dark_turfs -= stealth_at(block, dx, dy) + +/// A quick volley from one spot is one noise; the same gun 3 s later is a new one; a loud gun still alarms. +/datum/unit_test/voidcrew_stealth_live/hear/volley + +/datum/unit_test/voidcrew_stealth_live/hear/volley/Run() + TEST_ASSERT(hear_room(20, 3), "No room for the test") + var/mob/living/carbon/human/npc/first = walker(5, 1) + var/mob/living/carbon/human/npc/second = walker(7, 1) + var/datum/ai_controller/basic_controller/human_npc/stealth/first_ai = first.ai_controller + var/datum/stealth_group/group = first_ai.group + var/turf/spot = at(4, 1) + TEST_ASSERT(stealth_noise(spot, "gun_quiet") > 0, "A suppressed shot a tile off wasn't heard") + for(var/i in 1 to 2) + group.rewind(0.5 SECONDS) + TEST_ASSERT_EQUAL(stealth_noise(spot, "gun_quiet"), 0, "Shot [i + 1] of a volley counted as a new noise") + TEST_ASSERT_EQUAL(group.lure_count(spot), 1, "A volley counted as more than one lure") + TEST_ASSERT_EQUAL(state_of(second), "unaware", "A volley sent a second guard") + // A loud gun from the same spot is still an alarm. + TEST_ASSERT(stealth_noise(spot, "gun_long") > 0, "A rifle after the volley wasn't heard") + TEST_ASSERT_EQUAL(state_of(second), "searching", "A rifle shot after a quiet volley didn't send the guards running") + // The same quiet gun later is a new noise. + settle(first) + settle(second) + group.rewind(3.5 SECONDS) + TEST_ASSERT(stealth_noise(spot, "gun_quiet") > 0, "A shot 3.5 s after the volley was merged into it") + no_targets(list(first, second)) + +/// A sentry faces the way it was placed, glancing aside only now and then. +/datum/unit_test/voidcrew_stealth_live/sentry_facing + +/datum/unit_test/voidcrew_stealth_live/sentry_facing/Run() + TEST_ASSERT(make_room(14, 5), "No room for the test") + person_at(13, 4) + var/mob/living/carbon/human/npc/guard = guard_at(1, 2, SOUTH) + var/datum/ai_controller/basic_controller/human_npc/stealth/stealth_ai = wake(guard) + var/deadline = world.time + 10 SECONDS + while(!stealth_ai.stealth_ready && world.time < deadline) + sleep(1) + TEST_ASSERT(stealth_ai.stealth_ready, "The sentry never planned") + sleep(1 SECONDS) + TEST_ASSERT_NULL(stealth_ai.route_id, "A guard with no stop near it claimed a route") + TEST_ASSERT_EQUAL(stealth_ai.sentry_dir, SOUTH, "A sentry placed facing south took [dir2text(stealth_ai.sentry_dir)] as its post") + TEST_ASSERT_EQUAL(guard.dir, SOUTH, "A sentry placed facing south faces [dir2text(guard.dir)] a second later") + var/total = 0 + var/count = 0 + for(var/i in 1 to 24) + sleep(0.5 SECONDS) + total++ + if(guard.dir == SOUTH) + count++ + TEST_ASSERT_EQUAL(stealth_ai.stealth_state(), "unaware", "The sentry was disturbed during the test") + TEST_ASSERT(count >= total * 0.7, "A sentry faced its post only [count] of [total] looks over 12 s")