From dc40dfca81914d14624ce149a47b3d87c5137898 Mon Sep 17 00:00:00 2001 From: Artur <24881678+Arturlang@users.noreply.github.com> Date: Fri, 30 Jul 2021 01:24:43 +0300 Subject: [PATCH] goddamn stupid runtimes --- code/__DEFINES/dcs/signals.dm | 2 + code/controllers/subsystem/sun.dm | 2 - code/game/machinery/_machinery.dm | 5 +- code/game/machinery/lightswitch.dm | 49 ++++++++++------ code/modules/power/solar.dm | 90 ++++++++++++++++-------------- 5 files changed, 85 insertions(+), 63 deletions(-) diff --git a/code/__DEFINES/dcs/signals.dm b/code/__DEFINES/dcs/signals.dm index 986023e3ff..3ab70126e3 100644 --- a/code/__DEFINES/dcs/signals.dm +++ b/code/__DEFINES/dcs/signals.dm @@ -408,6 +408,8 @@ #define COMSIG_MACHINERY_POWER_LOST "machinery_power_lost" ///from base power_change() when power is restored #define COMSIG_MACHINERY_POWER_RESTORED "machinery_power_restored" +///from /obj/machinery/obj_break(damage_flag): (damage_flag) +#define COMSIG_MACHINERY_BROKEN "machinery_broken" // /obj/item signals #define COMSIG_ITEM_ATTACK "item_attack" //from base of obj/item/attack(): (/mob/living/target, /mob/living/user) diff --git a/code/controllers/subsystem/sun.dm b/code/controllers/subsystem/sun.dm index 746b1be7a9..dba9adac98 100644 --- a/code/controllers/subsystem/sun.dm +++ b/code/controllers/subsystem/sun.dm @@ -59,5 +59,3 @@ SUBSYSTEM_DEF(sun) /datum/controller/subsystem/sun/proc/complete_movement() SEND_SIGNAL(src, COMSIG_SUN_MOVED, primary_sun, suns) - -#undef OCCLUSION_DISTANCE diff --git a/code/game/machinery/_machinery.dm b/code/game/machinery/_machinery.dm index 4f61577eca..5b96efc83d 100644 --- a/code/game/machinery/_machinery.dm +++ b/code/game/machinery/_machinery.dm @@ -394,8 +394,11 @@ Class Procs: M.icon_state = "box_1" /obj/machinery/obj_break(damage_flag) - if(!(flags_1 & NODECONSTRUCT_1)) + . = ..() + if(!(stat & BROKEN) && !(flags_1 & NODECONSTRUCT_1)) stat |= BROKEN + SEND_SIGNAL(src, COMSIG_MACHINERY_BROKEN, damage_flag) + update_appearance() return TRUE /obj/machinery/contents_explosion(severity, target) diff --git a/code/game/machinery/lightswitch.dm b/code/game/machinery/lightswitch.dm index 0b55f80c39..a4d0878f77 100644 --- a/code/game/machinery/lightswitch.dm +++ b/code/game/machinery/lightswitch.dm @@ -1,29 +1,47 @@ -// the light switch -// can have multiple per area -// can also operate on non-loc area through "otherarea" var +/// The light switch. Can have multiple per area. /obj/machinery/light_switch name = "light switch" icon = 'icons/obj/power.dmi' icon_state = "light1" base_icon_state = "light" - plane = ABOVE_WALL_PLANE desc = "Make dark." - var/on = TRUE var/area/area = null var/otherarea = null +/obj/machinery/light_switch/directional/north + dir = SOUTH + pixel_y = 26 + +/obj/machinery/light_switch/directional/south + dir = NORTH + pixel_y = -26 + +/obj/machinery/light_switch/directional/east + dir = WEST + pixel_x = 26 + +/obj/machinery/light_switch/directional/west + dir = EAST + pixel_x = -26 + /obj/machinery/light_switch/Initialize() . = ..() - area = get_area(src) - + if(istext(area)) + area = text2path(area) + if(ispath(area)) + area = GLOB.areas_by_type[area] if(otherarea) area = locate(text2path("/area/[otherarea]")) + if(!area) + area = get_area(src) if(!name) name = "light switch ([area.name])" + update_appearance() - on = area.lightswitch - update_icon() +/obj/machinery/light_switch/update_appearance(updates=ALL) + . = ..() + luminosity = (stat & NOPOWER) ? 0 : 1 /obj/machinery/light_switch/update_icon_state() if(stat & NOPOWER) @@ -39,18 +57,15 @@ /obj/machinery/light_switch/examine(mob/user) . = ..() - . += "It is [on? "on" : "off"]." - + . += "It is [area.lightswitch ? "on" : "off"]." /obj/machinery/light_switch/interact(mob/user) . = ..() - on = !on - area.lightswitch = on - area.update_icon() + area.lightswitch = !area.lightswitch + area.update_appearance() for(var/obj/machinery/light_switch/L in area) - L.on = on - L.update_icon() + L.update_appearance() area.power_change() @@ -62,7 +77,7 @@ else stat |= NOPOWER - update_icon() + update_appearance() /obj/machinery/light_switch/emp_act(severity) . = ..() diff --git a/code/modules/power/solar.dm b/code/modules/power/solar.dm index 9cc289b06d..907c4e7d65 100644 --- a/code/modules/power/solar.dm +++ b/code/modules/power/solar.dm @@ -63,7 +63,7 @@ assembly = S assembly.glass_type.on_solar_construction(src) obj_integrity = max_integrity - update_icon() + update_appearance() /obj/machinery/power/solar/crowbar_act(mob/user, obj/item/I) playsound(src.loc, 'sound/machines/click.ogg', 50, TRUE) @@ -86,11 +86,10 @@ /obj/machinery/power/solar/obj_break(damage_flag) - if(!(stat & BROKEN) && !(flags_1 & NODECONSTRUCT_1)) + . = ..() + if(.) playsound(loc, 'sound/effects/glassbr3.ogg', 100, TRUE) - stat |= BROKEN unset_control() - update_icon() /obj/machinery/power/solar/deconstruct(disassembled = TRUE) if(!(flags_1 & NODECONSTRUCT_1)) @@ -99,7 +98,7 @@ assembly.forceMove(loc) assembly.give_glass(stat & BROKEN) else - playsound(src, "shatter", 70, 1) + playsound(src, "shatter", 70, TRUE) var/shard = assembly?.glass_type ? assembly.glass_type.shard_type : /obj/item/shard new shard(loc) new shard(loc) @@ -110,16 +109,15 @@ var/matrix/turner = matrix() turner.Turn(azimuth_current) panel.transform = turner - if(stat & BROKEN) - panel.icon_state = "solar_panel-b" - else - panel.icon_state = "solar_panel" + panel.icon_state = "solar_panel[(stat & BROKEN) ? "-b" : null]" /obj/machinery/power/solar/proc/queue_turn(azimuth) needs_to_turn = TRUE azimuth_target = azimuth /obj/machinery/power/solar/proc/queue_update_solar_exposure() + SIGNAL_HANDLER + needs_to_update_solar_exposure = TRUE //updating right away would be wasteful if we're also turning later /obj/machinery/power/solar/proc/update_turn() @@ -127,7 +125,7 @@ if(azimuth_current != azimuth_target) azimuth_current = azimuth_target occlusion_setup() - update_icon() + update_appearance() needs_to_update_solar_exposure = TRUE ///trace towards sun to see if we're in shadow @@ -173,7 +171,7 @@ control.gen += sgen //Bit of a hack but this whole type is a hack -/obj/machinery/power/solar/fake/Initialize(turf/loc, obj/item/solar_assembly/S) +/obj/machinery/power/solar/fake/Initialize(mapload, obj/item/solar_assembly/S) . = ..() UnregisterSignal(SSsun, COMSIG_SUN_MOVED) @@ -199,6 +197,16 @@ var/static/list/allowed_sheets = typecacheof(list(/obj/item/stack/sheet/glass, /obj/item/stack/sheet/rglass, /obj/item/stack/sheet/plasmaglass, /obj/item/stack/sheet/plasmarglass, /obj/item/stack/sheet/titaniumglass, /obj/item/stack/sheet/plastitaniumglass)) + var/random_offset = 6 //amount in pixels an unanchored assembly may be offset by + +/obj/item/solar_assembly/Initialize(mapload) + . = ..() + if(!anchored && !pixel_x && !pixel_y) + randomise_offset(random_offset) + +/obj/item/solar_assembly/proc/randomise_offset(amount) + pixel_x = rand(-amount, amount) + pixel_y = rand(-amount, amount) // Give back the glass type we were supplied with /obj/item/solar_assembly/proc/give_glass(device_broken) @@ -212,20 +220,21 @@ glass_type.forceMove(Tsec) glass_type = null +/obj/item/solar_assembly/set_anchored(anchorvalue) + . = ..() + if(isnull(.)) + return + randomise_offset(anchored ? 0 : random_offset) /obj/item/solar_assembly/attackby(obj/item/W, mob/user, params) if(W.tool_behaviour == TOOL_WRENCH && isturf(loc)) if(isinspace()) to_chat(user, "You can't secure [src] here.") return - anchored = !anchored - if(anchored) - user.visible_message("[user] wrenches the solar assembly into place.", "You wrench the solar assembly into place.") - W.play_tool_sound(src, 75) - else - user.visible_message("[user] unwrenches the solar assembly from its place.", "You unwrench the solar assembly from its place.") - W.play_tool_sound(src, 75) - return 1 + set_anchored(!anchored) + user.visible_message("[user] [anchored ? null : "un"]wrenches the solar assembly into place.", "You [anchored ? null : "un"]wrench the solar assembly into place.") + W.play_tool_sound(src, 75) + return TRUE if(is_type_in_typecache(W, allowed_sheets)) if(!anchored) @@ -249,16 +258,16 @@ if(istype(W, /obj/item/electronics/tracker)) if(!user.temporarilyRemoveItemFromInventory(W)) return - tracker = 1 + tracker = TRUE qdel(W) user.visible_message("[user] inserts the electronics into the solar assembly.", "You insert the electronics into the solar assembly.") return 1 else if(W.tool_behaviour == TOOL_CROWBAR) new /obj/item/electronics/tracker(src.loc) - tracker = 0 + tracker = FALSE user.visible_message("[user] takes out the electronics from the solar assembly.", "You take out the electronics from the solar assembly.") - return 1 + return TRUE return ..() // @@ -322,11 +331,12 @@ if(stat & NOPOWER) . += mutable_appearance(icon, "[icon_keyboard]_off") return + . += mutable_appearance(icon, icon_keyboard) if(stat & BROKEN) . += mutable_appearance(icon, "[icon_state]_broken") - else - . += mutable_appearance(icon, icon_screen) + return + . += mutable_appearance(icon, icon_screen) /obj/machinery/power/solar_control/ui_interact(mob/user, datum/tgui/ui) ui = SStgui.try_update_ui(user, src, ui) @@ -347,7 +357,8 @@ return data /obj/machinery/power/solar_control/ui_act(action, params) - if(..()) + . = ..() + if(.) return if(action == "azimuth") var/adjust = text2num(params["adjust"]) @@ -381,10 +392,10 @@ return TRUE return FALSE -/obj/machinery/power/solar_control/attackby(obj/item/I, mob/user, params) +/obj/machinery/power/solar_control/attackby(obj/item/I, mob/living/user, params) if(I.tool_behaviour == TOOL_SCREWDRIVER) - if(I.use_tool(src, user, 20, volume = 50)) - if(src.stat & BROKEN) + if(I.use_tool(src, user, 20, volume=50)) + if (src.stat & BROKEN) to_chat(user, "The broken glass falls out.") var/obj/structure/frame/computer/A = new /obj/structure/frame/computer( src.loc ) new /obj/item/shard( src.loc ) @@ -394,7 +405,7 @@ A.circuit = M A.state = 3 A.icon_state = "3" - A.anchored = TRUE + A.set_anchored(TRUE) qdel(src) else to_chat(user, "You disconnect the monitor.") @@ -405,7 +416,7 @@ A.circuit = M A.state = 4 A.icon_state = "4" - A.anchored = TRUE + A.set_anchored(TRUE) qdel(src) else if(user.a_intent != INTENT_HARM && !(I.item_flags & NOBLUDGEON)) attack_hand(user) @@ -423,10 +434,9 @@ playsound(src.loc, 'sound/items/welder.ogg', 100, TRUE) /obj/machinery/power/solar_control/obj_break(damage_flag) - if(!(stat & BROKEN) && !(flags_1 & NODECONSTRUCT_1)) + . = ..() + if(.) playsound(loc, 'sound/effects/glassbr3.ogg', 100, TRUE) - stat |= BROKEN - update_icon() /obj/machinery/power/solar_control/process() lastgen = gen @@ -437,6 +447,8 @@ ///Ran every time the sun updates. /obj/machinery/power/solar_control/proc/timed_track() + SIGNAL_HANDLER + if(track == SOLAR_TRACK_TIMED) azimuth_target += azimuth_rate set_panels(azimuth_target) @@ -453,20 +465,12 @@ for(var/obj/machinery/power/solar/S in connected_panels) S.queue_turn(azimuth) -/obj/machinery/power/solar_control/power_change() - ..() - update_icon() - // // MISC // /obj/item/paper/guides/jobs/engi/solars - info = {" -# Welcome! -At greencorps we love the environment, and space. With this package you are able to help mother nature and produce energy without any usage of fossil fuel or plasma! Singularity energy is dangerous while solar energy is safe, which is why it's better. Now here is how you setup your own solar array. -You can make a solar panel by wrenching the solar assembly onto a cable node. Adding a glass panel, reinforced or regular glass will do, will finish the construction of your solar panel. It is that easy!
Now after setting up 19 more of these solar panels you will want to create a solar tracker to keep track of our mother nature's gift, the sun. These are the same steps as before except you insert the tracker equipment circuit into the assembly before performing the final step of adding the glass. You now have a tracker! Now the last step is to add a computer to calculate the sun's movements and to send commands to the solar panels to change direction with the sun. Setting up the solar computer is the same as setting up any computer, so you should have no trouble in doing that. You do need to put a wire node under the computer, and the wire needs to be connected to the tracker. -Congratulations, you should have a working solar array. If you are having trouble, here are some tips. Make sure all solar equipment are on a cable node, even the computer. You can always deconstruct your creations if you make a mistake.
That's all to it, be safe, be green! -"} + name = "paper- 'Going green! Setup your own solar array instructions.'" + info = "
At greencorps we love the environment, and space. With this package you are able to help mother nature and produce energy without any usage of fossil fuel or plasma! Singularity energy is dangerous while solar energy is safe, which is why it's better. Now here is how you setup your own solar array.
You can make a solar panel by wrenching the solar assembly onto a cable node. Adding a glass panel, reinforced or regular glass will do, will finish the construction of your solar panel. It is that easy!
Now after setting up 19 more of these solar panels you will want to create a solar tracker to keep track of our mother nature's gift, the sun. These are the same steps as before except you insert the tracker equipment circuit into the assembly before performing the final step of adding the glass. You now have a tracker! Now the last step is to add a computer to calculate the sun's movements and to send commands to the solar panels to change direction with the sun. Setting up the solar computer is the same as setting up any computer, so you should have no trouble in doing that. You do need to put a wire node under the computer, and the wire needs to be connected to the tracker.
Congratulations, you should have a working solar array. If you are having trouble, here are some tips. Make sure all solar equipment are on a cable node, even the computer. You can always deconstruct your creations if you make a mistake.
That's all to it, be safe, be green!
" #undef SOLAR_GEN_RATE