/
githubmirror
/
vgstation13
Обзор
Документация
Войти
/
githubmirror
/
vgstation13
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
Bleeding-Edge
code/modules/assembly/timer.dm
184 строки
5 KB
Inorien
fix (#38763)
25 дек 2025, 18:03
Не верифицирован
25 дек 2025, 18:03
6c32efc
Код
Авторство
О чём код?
#define VALUE_REMAINING_TIME "Remaining time" #define VALUE_DEFAULT_TIME "Default time" #define VALUE_TIMING "Timing" #define VALUE_TIMEMODE "Mode" #define TIMEMODE_REPEAT "Repeat pulse and recount" #define TIMEMODE_ONCE "Pulse once and stop" #define TICK_SPEEDUP 1 #define TICK_PITCHUP 2 #define SPEEDSUP_SECONDS 3 /obj/item/device/assembly/timer name = "timer" desc = "Used to time things. Works well with contraptions which have to count down. Tick tock." icon_state = "timer" starting_materials = list(MAT_IRON = 500, MAT_GLASS = 50) w_type = RECYK_ELECTRONIC origin_tech = Tc_MAGNETS + "=1" wires = WIRE_PULSE | WIRE_RECEIVE secured = 0 var/timing = 0 var/time = 10 var/repeat = FALSE var/default_time = 10 var/speedsup = TICK_PITCHUP accessible_values = list(\ VALUE_REMAINING_TIME = "time;"+VT_NUMBER,\ VALUE_DEFAULT_TIME = "default_time;"+VT_NUMBER,\ VALUE_TIMEMODE = "repeat;"+VT_NUMBER,\ VALUE_TIMING = "timing;"+VT_NUMBER) /obj/item/device/assembly/timer/activate() if(!..()) return 0//Cooldown check timing = !timing if(!silent) spawn() timesoundloop() message_admins("[key_name_admin(usr)] [timing ? "started" : "stopped"] a timer at [formatJumpTo(src)]") update_icon() countdown() return 0 /obj/item/device/assembly/timer/toggle_secure() secured = !secured if(!secured) timing = 0 update_icon() return secured /obj/item/device/assembly/timer/proc/timer_end() if(!secured) return 0 pulse(0) if(!holder) visible_message("[bicon(src)] *beep* *beep*", "*beep* *beep*") cooldown = 2 spawn(10) process_cooldown() return /obj/item/device/assembly/timer/proc/timesoundloop(decrement = clamp(SPEEDSUP_SECONDS-time,0,SPEEDSUP_SECONDS)*SPEEDSUP_SECONDS,freq = 1) if (QDELETED(src)) // if the timer was destroyed by an explosion while counting down and we came here from a spawn() return if(!silent && timing && time > 0) if (get_turf(src)) // in case timer is in nullspace when the spawn comes back playsound(src,decrement >= 7 && speedsup == TICK_SPEEDUP ? 'sound/items/assemblytick1.ogg' : 'sound/items/assemblytick2.ogg',100,1,frequency = freq) spawn(max(1,10 - decrement)) if(speedsup && time <= SPEEDSUP_SECONDS) decrement++ if(speedsup == TICK_PITCHUP) freq *= 1.03 else decrement = 0 freq = 1 timesoundloop(decrement,freq) /obj/item/device/assembly/timer/proc/countdown() if (QDELETED(src)) // if the timer was destroyed by an explosion while counting down and we came here from a spawn() return if(timing) if(time > 0) spawn(10) time-- countdown() else if(!repeat) timing = 0 timer_end() time = default_time if(repeat && time > 0) spawn() countdown() if (!QDELETED(src)) updateUsrDialog() /obj/item/device/assembly/timer/update_icon() overlays.len = 0 attached_overlays = list() if(timing) attached_overlays["timer_timing"] = image(icon = icon, icon_state = "timer_timing") overlays += attached_overlays["timer_timing"] if(holder) holder.update_icon() return /obj/item/device/assembly/timer/interact(mob/user as mob)//TODO: Have this use the wires if(!secured) user.show_message("<span class='warning'>The [name] is unsecured!</span>") return 0 var/second = time % 60 var/minute = (time - second) / 60 var/dat = text("<TT><B>Timing Unit</B>\n[] []:[]\n<A href='?src=\ref[];tp=-30'>-</A> <A href='?src=\ref[];tp=-1'>-</A> <A href='?src=\ref[];tp=1'>+</A> <A href='?src=\ref[];tp=30'>+</A>\n</TT>", (timing ? text("<A href='?src=\ref[];time=1'>Timing</A>", src) : text("<A href='?src=\ref[];time=1'>Not Timing</A>", src)), minute, second, src, src, src, src) dat += "<BR><BR><A href='?src=\ref[src];set_default_time=1'>After countdown, reset time to [(default_time - default_time%60)/60]:[(default_time % 60)]</A>" dat += {"<BR><BR><A href='byond://?src=\ref[src];toggle_silent=1'>Timer tick sound: O[silent ? "ff" : "n"]</A> <BR><BR><A href='byond://?src=\ref[src];toggle_speedup=1'>Timer tick speedup: [speedsup == TICK_PITCHUP ? "Speed and pitch" : speedsup ? "Speed" : "None"]</A>"} dat += "<BR><BR><A href='?src=\ref[src];toggle_mode=1'>Mode: [repeat ? TIMEMODE_REPEAT : TIMEMODE_ONCE]</A>" user << browse(HTML_SKELETON(dat), "window=timer") onclose(user, "timer") return /obj/item/device/assembly/timer/Topic(href, href_list) ..() if(usr.stat || usr.restrained() || !in_range(loc, usr) || (!usr.canmove && !usr.locked_to)) //If the user is handcuffed or out of range, or if they're unable to move, //but NOT if they're unable to move as a result of being buckled into something, they're unable to use the device. usr << browse(null, "window=timer") onclose(usr, "timer") return if(href_list["time"]) activate() if(!silent) spawn() timesoundloop() if(href_list["tp"]) var/tp = text2num(href_list["tp"]) time += tp time = min(max(round(time), 0), 600) if(href_list["toggle_mode"]) repeat = !repeat if(href_list["toggle_silent"]) silent = !silent if(href_list["toggle_speedup"]) speedsup = (speedsup + 1) % 3 if(href_list["set_default_time"]) default_time = time updateUsrDialog() /obj/item/device/assembly/timer/send_to_past(var/duration) ..() var/static/list/resettable_vars = list( "timing", "time") reset_vars_after_duration(resettable_vars, duration) #undef VALUE_REMAINING_TIME #undef VALUE_DEFAULT_TIME #undef VALUE_TIMING #undef TICK_SPEEDUP #undef TICK_PITCHUP #undef SPEEDSUP_SECONDS