Bomb (and traps) detector (#17959)

* sdfa

* sdf

* Apply suggestions from code review

Co-authored-by: Matt Atlas <mattiathebest2000@hotmail.it>

* sfda

---------

Co-authored-by: Matt Atlas <mattiathebest2000@hotmail.it>
This commit is contained in:
Fluffy
2024-01-11 11:52:24 +00:00
committed by GitHub
co-authored by Matt Atlas
parent 91735219f5
commit 2f1b2973ba
8 changed files with 154 additions and 1 deletions
+1
View File
@@ -1034,6 +1034,7 @@
#include "code\game\objects\items\devices\magnetic_lock.dm"
#include "code\game\objects\items\devices\megaphone.dm"
#include "code\game\objects\items\devices\memorywiper.dm"
#include "code\game\objects\items\devices\minedetector.dm"
#include "code\game\objects\items\devices\modkit.dm"
#include "code\game\objects\items\devices\multitool.dm"
#include "code\game\objects\items\devices\oxycandle.dm"
@@ -0,0 +1,102 @@
/obj/item/device/mine_detector
name = "mine detector"
desc = "A device capable of detecting mines and traps in a range."
///The types that are detected by this device
var/list/detectable_types = list(/obj/item/landmine, /obj/item/trap)
///The range in which the detection happens
var/detection_range = 4
///The angle from the center in which the detection happens
var/detection_angle = 30
///The last time this was activated, to avoid spamming it. In `world.time`
var/last_use = null
///How much to wait before allowing a new scan
var/delay_between_scans = 3 SECONDS
///If this detector is able to perform scans automatically, instead of having to trigger them manually
var/can_scan_automatically = FALSE
///The timer ID for the automatic rescans
var/timer_id = null
/obj/item/device/mine_detector/attack_self(mob/user)
. = ..()
//Apply the delay and check it is passed, so a new scan can be done
if((last_use + delay_between_scans) > world.time)
return
last_use = world.time
if(!can_scan_automatically)
perform_scan(user)
else
//If there's no timer, start a new one, otherwise stop the callbacks (aka stop the automatic scanning)
if(!timer_id)
to_chat(user, SPAN_NOTICE("You power on the automatic mine detection system, which shows a loading screen with a progress bar."))
timer_id = addtimer(CALLBACK(src, PROC_REF(perform_scan), user), delay_between_scans, TIMER_UNIQUE|TIMER_STOPPABLE)
else
to_chat(user, SPAN_NOTICE("You power off the automatic mine detection system."))
deltimer(timer_id)
timer_id = null
/obj/item/device/mine_detector/proc/perform_scan(mob/user)
var/list/turfs_scanned = get_turfs_in_cone(get_turf(src), dir2angle(user.dir), detection_range, detection_angle)
//This will contain the distance of the closest detected object
var/minimum_distance_detected = null
var/obj/effect/overlay/teleport_pulse/scanned = new() //This goes in nullspace because we want to project the image to the user only
//Search across the content of the turfs we got in the cone
for(var/turf/turf as anything in turfs_scanned)
//Show the effect on every turf that was scanned, to the user
user.client.images += image(scanned, turf)
for(var/item in turf.contents)
//If it's a type we can detect
if(is_type_in_list(item, detectable_types))
//Set it as the minimum distance mine if it's either not set, or closer than the previous detection
var/distance = get_dist(src, item)
if(isnull(minimum_distance_detected) || (distance < minimum_distance_detected))
minimum_distance_detected = distance
//Select the appropriate sound to play based on the distance, but only if something was detected
if(!isnull(minimum_distance_detected))
var/sound = null
//Pick the audio based on the distance
if(minimum_distance_detected < 2)
sound = 'sound/items/devices/minedetector/minedetector_close.ogg'
else if(minimum_distance_detected <= (detection_range / 2))
sound = 'sound/items/devices/minedetector/minedetector_medium.ogg'
else
sound = 'sound/items/devices/minedetector/minedetector_far.ogg'
//Play it
playsound(src, sound, 75, FALSE)
//Reregister the next callback timer if we're running automatic scans
if(can_scan_automatically && timer_id)
timer_id = addtimer(CALLBACK(src, PROC_REF(perform_scan), user), delay_between_scans, TIMER_UNIQUE|TIMER_STOPPABLE)
/*#############
Subtypes
#############*/
/obj/item/device/mine_detector/advanced
name = "advanced mine detector"
desc = "A device capable of detecting mines and traps in a range. This one is more advanced, featuring automatic scanning as well as a broader detection angle."
detection_angle = 45
can_scan_automatically = TRUE
@@ -232,3 +232,4 @@
new /obj/item/clothing/shoes/sneakers/brown(src)
new /obj/item/clothing/head/bomb_hood/security(src)
new /obj/item/wirecutters/bomb(src)
new /obj/item/device/mine_detector(src)
@@ -0,0 +1,43 @@
################################
# Example Changelog File
#
# Note: This file, and files beginning with ".", and files that don't end in ".yml" will not be read. If you change this file, you will look really dumb.
#
# Your changelog will be merged with a master changelog. (New stuff added only, and only on the date entry for the day it was merged.)
# When it is, any changes listed below will disappear.
#
# Valid Prefixes:
# bugfix
# wip (For works in progress)
# tweak
# soundadd
# sounddel
# rscadd (general adding of nice things)
# rscdel (general deleting of nice things)
# imageadd
# imagedel
# maptweak
# spellcheck (typo fixes)
# experiment
# balance
# admin
# backend
# security
# refactor
#################################
# Your name.
author: FluffyGhost
# Optional: Remove this file after generating master changelog. Useful for PR changelogs that won't get used again.
delete-after: True
# Any changes you've made. See valid prefix list above.
# INDENT WITH TWO SPACES. NOT TABS. SPACES.
# SCREW THIS UP AND IT WON'T WORK.
# Also, all entries are changed into a single [] after a master changelog generation. Just remove the brackets when you add new entries.
# Please surround your changes in double quotes ("), as certain characters otherwise screws up compiling. The quotes will not show up in the changelog.
changes:
- rscadd: "Added a mine detector, it is able to beep with different sounds depending on the distance of the closest mine or trap, scans in a cone up to a range for them."
- rscadd: "Added the mine detector to the security closet."
- soundadd: "Added sounds for the mine detector."
+7 -1
View File
@@ -75,4 +75,10 @@ ATTRIBUTIONS SECTION END
ATTRIBUTIONS SECTION START
sound/items/typewriter.ogg - "Typewriter Sound Effect" licensed under CC0, by No Copyright Creator Sounds. Obtained and edited from https://www.youtube.com/watch?v=HYvJtImzoNI&ab_channel=NoCopyrightCreator-Sounds
sound/items/camerabulb.ogg - "Vintage Camera Flash Bulb Pops Sound Design" licensed under CC0, by Adilbek Sounds. Obainted and edited from https://freesound.org/people/adilbek_sounds/sounds/595044/
ATTRIBUTIONS SECTION END
ATTRIBUTIONS SECTION END
ATTRIBUTIONS SECTION START
/sound/items/devices/minedetector/minedetector_close.ogg - Part of "Detector", licensed under CC0. Obtained from https://freesound.org/people/fennelliott/sounds/426404/
/sound/items/devices/minedetector/minedetector_medium.ogg - Part of "Detector", licensed under CC0. Obtained from https://freesound.org/people/fennelliott/sounds/426404/
/sound/items/devices/minedetector/minedetector_far.ogg - Part of "Detector", licensed under CC0. Obtained from https://freesound.org/people/fennelliott/sounds/426404/
ATTRIBUTIONS SECTION END