From 1a507d23edc7d12bfee30a4db3fe4661af20add4 Mon Sep 17 00:00:00 2001 From: Watermelon914 <37270891+Watermelon914@users.noreply.github.com> Date: Thu, 30 Sep 2021 19:09:42 +0100 Subject: [PATCH] Refactors how circuit size is calculated. Fixed module circuit size not taking up capacity equal to the amount of circuit components inside of it. (#61554) Co-authored-by: Watermelon914 <3052169-Watermelon914@users.noreply.gitlab.com> --- code/datums/components/shell.dm | 7 ++++--- .../modules/wiremod/components/abstract/module.dm | 10 ++++++++++ code/modules/wiremod/components/utility/getter.dm | 2 ++ code/modules/wiremod/components/utility/setter.dm | 2 ++ code/modules/wiremod/core/component.dm | 15 +++++++++++++-- code/modules/wiremod/core/integrated_circuit.dm | 5 +++++ 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/code/datums/components/shell.dm b/code/datums/components/shell.dm index 33a72babf07..9f519bcc259 100644 --- a/code/datums/components/shell.dm +++ b/code/datums/components/shell.dm @@ -51,6 +51,7 @@ if(ispath(circuit_component)) circuit_component = new circuit_component() circuit_component.removable = FALSE + circuit_component.set_circuit_size(0) RegisterSignal(circuit_component, COMSIG_CIRCUIT_COMPONENT_SAVE, .proc/save_component) unremovable_circuit_components += circuit_component @@ -178,7 +179,7 @@ source.balloon_alert(attacker, "there is already a circuitboard inside!") return - if(length(logic_board.attached_components) - length(unremovable_circuit_components) > capacity) + if(logic_board.current_size > capacity) source.balloon_alert(attacker, "this is too large to fit into [parent]!") return @@ -251,8 +252,8 @@ source.balloon_alert(user, "it's locked!") return COMPONENT_CANCEL_ADD_COMPONENT - if(length(attached_circuit.attached_components) - length(unremovable_circuit_components) >= capacity) - source.balloon_alert(user, "it's at maximum capacity!") + if(attached_circuit.current_size + added_comp.circuit_size > capacity) + source.balloon_alert(user, "it won't fit!") return COMPONENT_CANCEL_ADD_COMPONENT /** diff --git a/code/modules/wiremod/components/abstract/module.dm b/code/modules/wiremod/components/abstract/module.dm index 91b9db308ac..257028bd696 100644 --- a/code/modules/wiremod/components/abstract/module.dm +++ b/code/modules/wiremod/components/abstract/module.dm @@ -46,6 +46,16 @@ return ..() +/obj/item/integrated_circuit/module/add_component(obj/item/circuit_component/to_add, mob/living/user) + . = ..() + if(attached_module) + attached_module.circuit_size += to_add.circuit_size + +/obj/item/integrated_circuit/module/remove_component(obj/item/circuit_component/to_remove) + if(attached_module) + attached_module.circuit_size -= to_remove.circuit_size + return ..() + /obj/item/integrated_circuit/module/Destroy() attached_module = null return ..() diff --git a/code/modules/wiremod/components/utility/getter.dm b/code/modules/wiremod/components/utility/getter.dm index 9c1b1cdc896..399a2969164 100644 --- a/code/modules/wiremod/components/utility/getter.dm +++ b/code/modules/wiremod/components/utility/getter.dm @@ -15,6 +15,8 @@ var/datum/circuit_variable/current_variable + circuit_size = 0 + /obj/item/circuit_component/getter/populate_options() variable_name = add_option_port("Variable", null) diff --git a/code/modules/wiremod/components/utility/setter.dm b/code/modules/wiremod/components/utility/setter.dm index 0edf8554d05..b5026c1207b 100644 --- a/code/modules/wiremod/components/utility/setter.dm +++ b/code/modules/wiremod/components/utility/setter.dm @@ -19,6 +19,8 @@ var/current_type + circuit_size = 0 + /obj/item/circuit_component/setter/populate_options() variable_name = add_option_port("Variable", null) diff --git a/code/modules/wiremod/core/component.dm b/code/modules/wiremod/core/component.dm index d2c8fef5f7a..8368f6ae4f3 100644 --- a/code/modules/wiremod/core/component.dm +++ b/code/modules/wiremod/core/component.dm @@ -45,12 +45,15 @@ /// The power usage whenever this component receives an input var/power_usage_per_input = 1 - // Whether the component is removable or not. Only affects user UI + /// Whether the component is removable or not. Only affects user UI var/removable = TRUE - // Defines which shells support this component. Only used as an informational guide, does not restrict placing these components in circuits. + /// Defines which shells support this component. Only used as an informational guide, does not restrict placing these components in circuits. var/required_shells = null + /// Determines the amount of space this circuit occupies in an integrated circuit. + var/circuit_size = 1 + /// The UI buttons of this circuit component. An assoc list that has this format: "button_icon" = "action_name" var/ui_buttons = null @@ -216,6 +219,14 @@ trigger_output.set_output(COMPONENT_SIGNAL) return TRUE +/obj/item/circuit_component/proc/set_circuit_size(new_size) + if(parent) + parent.current_size -= circuit_size + + circuit_size = new_size + + if(parent) + parent.current_size += circuit_size /** * Called whether this circuit component should receive an input. diff --git a/code/modules/wiremod/core/integrated_circuit.dm b/code/modules/wiremod/core/integrated_circuit.dm index ffc74054dfc..6ec768cc735 100644 --- a/code/modules/wiremod/core/integrated_circuit.dm +++ b/code/modules/wiremod/core/integrated_circuit.dm @@ -69,6 +69,9 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit) /// The Y position of the screen. Used for adding components. var/screen_y = 0 + /// The current size of the circuit. + var/current_size = 0 + /obj/item/integrated_circuit/Initialize(mapload) . = ..() @@ -224,6 +227,7 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit) to_add.rel_y = rand(COMPONENT_MIN_RANDOM_POS, COMPONENT_MAX_RANDOM_POS) - screen_y to_add.parent = src attached_components += to_add + current_size += to_add.circuit_size RegisterSignal(to_add, COMSIG_MOVABLE_MOVED, .proc/component_move_handler) SStgui.update_uis(src) @@ -255,6 +259,7 @@ GLOBAL_LIST_EMPTY_TYPED(integrated_circuits, /obj/item/integrated_circuit) to_remove.unregister_shell(shell) UnregisterSignal(to_remove, COMSIG_MOVABLE_MOVED) + current_size -= to_remove.circuit_size attached_components -= to_remove to_remove.disconnect() to_remove.parent = null