From 19730f6e81ff1e1a714b0da8a516fc41908e4f2e Mon Sep 17 00:00:00 2001 From: Mikhail Dzianishchyts Date: Mon, 5 Feb 2024 00:18:43 +0300 Subject: [PATCH] Fix tint control logic (#23821) * Fix: Upgrade tint control logic * Follow formatting * Remove redundant 'as' * Revert "Remove redundant 'as'" This reverts commit 12bceb405331db0d4c931cb37e661ed24f844cea. * Auto-docs, refactoring --- code/__DEFINES/construction_defines.dm | 37 +++++++++++-------- code/game/area/areas.dm | 2 ++ code/game/objects/structures/window.dm | 50 +++++++++++++++++--------- 3 files changed, 57 insertions(+), 32 deletions(-) diff --git a/code/__DEFINES/construction_defines.dm b/code/__DEFINES/construction_defines.dm index 86be9100316..3264c0e9616 100644 --- a/code/__DEFINES/construction_defines.dm +++ b/code/__DEFINES/construction_defines.dm @@ -2,14 +2,14 @@ //Defines for construction states -//girder construction states +/// girder construction states #define GIRDER_NORMAL 0 #define GIRDER_REINF_STRUTS 1 #define GIRDER_REINF 2 #define GIRDER_DISPLACED 3 #define GIRDER_DISASSEMBLED 4 -//rwall construction states +/// rwall construction states #define RWALL_INTACT 0 #define RWALL_SUPPORT_LINES 1 #define RWALL_COVER 2 @@ -18,31 +18,31 @@ #define RWALL_SUPPORT_RODS 5 #define RWALL_SHEATH 6 -//window construction states +/// window construction states #define WINDOW_OUT_OF_FRAME 0 #define WINDOW_IN_FRAME 1 #define WINDOW_SCREWED_TO_FRAME 2 -//airlock assembly construction states +/// airlock assembly construction states #define AIRLOCK_ASSEMBLY_NEEDS_WIRES 0 #define AIRLOCK_ASSEMBLY_NEEDS_ELECTRONICS 1 #define AIRLOCK_ASSEMBLY_NEEDS_SCREWDRIVER 2 -//used by airlocks and airlock wires. +/// used by airlocks and airlock wires. #define AICONTROLDISABLED_OFF 0 // Silicons can control the airlock normally. #define AICONTROLDISABLED_ON 1 // Silicons cannot control the airlock, but can hack the airlock. #define AICONTROLDISABLED_BYPASS 2 // Silicons can control the airlock because they succeeded on the hack #define AICONTROLDISABLED_PERMA 3 // Wire cutting an airlock on AICONTROLDISABLED_BYPASS toggles it between AICONTROLDISABLED_BYPASS and this. -//plastic flaps construction states +/// plastic flaps construction states #define PLASTIC_FLAPS_NORMAL 0 #define PLASTIC_FLAPS_DETACHED 1 -//Mounted Frames BITMASK +/// Mounted Frames BITMASK #define MOUNTED_FRAME_SIMFLOOR (1 << 0) #define MOUNTED_FRAME_NOSPACE (1 << 1) -//ai core defines +/// ai core defines #define EMPTY_CORE 0 #define CIRCUIT_CORE 1 #define SCREWED_CORE 2 @@ -50,15 +50,21 @@ #define GLASS_CORE 4 #define AI_READY_CORE 5 -//other construction-related things +/// other construction-related things -//windows affected by nar'sie turn this color. +/// windows affected by nar'sie turn this color. #define NARSIE_WINDOW_COLOUR "#7D1919" -//let's just pretend fulltile windows being children of border windows is fine +/// let's just pretend fulltile windows being children of border windows is fine #define FULLTILE_WINDOW_DIR NORTHEAST -//Material defines, for determining how much of a given material an item contains +/// Range of a tint control button, that works only in its area. +#define TINT_CONTROL_RANGE_AREA 0 + +/// ID of a tint control button with no group specified, so it controls only windows also with no group specified ('null-like' id). +#define TINT_CONTROL_GROUP_NONE 0 + +/// Material defines, for determining how much of a given material an item contains #define MAT_METAL "metal" #define MAT_GLASS "glass" #define MAT_SILVER "silver" @@ -72,9 +78,10 @@ #define MAT_TITANIUM "titanium" #define MAT_BIOMASS "biomass" #define MAT_PLASTIC "plastic" -//The amount of materials you get from a sheet of mineral like iron/diamond/glass etc + +/// The amount of materials you get from a sheet of mineral like iron/diamond/glass etc #define MINERAL_MATERIAL_AMOUNT 2000 -//The maximum size of a stack object. +/// The maximum size of a stack object. #define MAX_STACK_SIZE 50 -//maximum amount of cable in a coil +/// maximum amount of cable in a coil #define MAXCOIL 30 diff --git a/code/game/area/areas.dm b/code/game/area/areas.dm index 032046134e8..421a369e4ac 100644 --- a/code/game/area/areas.dm +++ b/code/game/area/areas.dm @@ -20,6 +20,8 @@ var/map_name /// Is the lightswitch in this area on? Controls whether or not lights are on and off var/lightswitch = TRUE + /// Is the window tint control in this area on? Controls whether electrochromic windows and doors are tinted or not + var/window_tint = FALSE /// If TRUE, the local powernet in this area will have all its power channels switched off var/apc_starts_off = FALSE /// If TRUE, this area's local powernet will require power to properly operate machines diff --git a/code/game/objects/structures/window.dm b/code/game/objects/structures/window.dm index 499e64913e5..e074fb4fe76 100644 --- a/code/game/objects/structures/window.dm +++ b/code/game/objects/structures/window.dm @@ -523,8 +523,13 @@ icon_state = "light0" anchored = TRUE desc = "A remote control switch for polarized windows." - var/range = 7 - var/id = 0 + /// The area where the button is located. + var/area/button_area + /// Windows in this range are controlled by this button. If it equals TINT_CONTROL_RANGE_AREA, the button controls only windows at button_area. + var/range = TINT_CONTROL_RANGE_AREA + /// If equals TINT_CONTROL_GROUP_NONE, only windows with 'null-like' id are controlled by this button. Otherwise, windows with corresponding or 'null-like' id are controlled by this button. + var/id = TINT_CONTROL_GROUP_NONE + /// The button toggle state. If range equals TINT_CONTROL_RANGE_AREA and id equals TINT_CONTROL_GROUP_NONE or is same with other button, it is shared between all such buttons in its area. var/active = FALSE /obj/machinery/button/windowtint/Initialize(mapload, w_dir = null) @@ -539,6 +544,10 @@ if(WEST) pixel_x = -25 +/obj/machinery/button/windowtint/New(turf/loc, direction) + ..() + button_area = get_area(src) + /obj/machinery/button/windowtint/attack_hand(mob/user) if(..()) return TRUE @@ -562,23 +571,30 @@ /obj/machinery/button/windowtint/proc/toggle_tint() use_power(5) + if(range == TINT_CONTROL_RANGE_AREA) + button_area.window_tint = !button_area.window_tint + for(var/obj/machinery/button/windowtint/button in button_area) + if(button.range != TINT_CONTROL_RANGE_AREA || (button.id != id && button.id != TINT_CONTROL_GROUP_NONE)) + continue + button.active = button_area.window_tint + button.update_icon() + else + active = !active + update_icon() + process_controlled_windows(range != TINT_CONTROL_RANGE_AREA ? range(src, range) : button_area) - active = !active - update_icon() - - for(var/obj/structure/window/reinforced/polarized/W in range(src,range)) - if(W.id == src.id || !W.id) - W.toggle_polarization() - - for(var/obj/structure/window/full/reinforced/polarized/W in range(src, range)) - if(W.id == id || !W.id) - W.toggle_polarization() - - for(var/obj/machinery/door/D in range(src, range)) - if(!D.polarized_glass) +/obj/machinery/button/windowtint/proc/process_controlled_windows(control_area) + for(var/obj/structure/window/reinforced/polarized/window in control_area) + if(window.id == id || !window.id) + window.toggle_polarization() + for(var/obj/structure/window/full/reinforced/polarized/window in control_area) + if(window.id == id || !window.id) + window.toggle_polarization() + for(var/obj/machinery/door/door in control_area) + if(!door.polarized_glass) continue - if(D.id == id || !D.id) - D.toggle_polarization() + if(door.id == id || !door.id) + door.toggle_polarization() /obj/machinery/button/windowtint/power_change() if(!..())