diff --git a/code/modules/modular_computers/computers/item/computer.dm b/code/modules/modular_computers/computers/item/computer.dm index 6fe91c9575b..0de25b903ab 100644 --- a/code/modules/modular_computers/computers/item/computer.dm +++ b/code/modules/modular_computers/computers/item/computer.dm @@ -42,7 +42,7 @@ ///The program currently active on the tablet. var/datum/computer_file/program/active_program ///Idle programs on background. They still receive process calls but can't be interacted with. - var/list/idle_threads = list() + var/list/datum/computer_file/program/idle_threads = list() /// Amount of programs that can be ran at once var/max_idle_programs = 2 @@ -72,12 +72,10 @@ /// The built-in light's color, editable by players. var/comp_light_color = "#FFFFFF" - ///The last recorded amount of power used. - var/last_power_usage = 0 ///Power usage when the computer is open (screen is active) and can be interacted with. - var/base_active_power_usage = 75 - ///Power usage when the computer is idle and screen is off (currently only applies to laptops) - var/base_idle_power_usage = 5 + var/base_active_power_usage = 15 // SKYRAT EDIT CHANGE - Original: 125 + ///Power usage when the computer is idle and screen is off. + var/base_idle_power_usage = 2 // SKYRAT EDIT CHANGE - Original: 5 // Modular computers can run on various devices. Each DEVICE (Laptop, Console & Tablet) // must have it's own DMI file. Icon states must be called exactly the same in all files, but may look differently @@ -369,6 +367,9 @@ /obj/item/modular_computer/add_context(atom/source, list/context, obj/item/held_item, mob/living/user) . = ..() + if(held_item?.tool_behaviour == TOOL_SCREWDRIVER && internal_cell) + context[SCREENTIP_CONTEXT_RMB] = "Remove Cell" + . = CONTEXTUAL_SCREENTIP_SET if(held_item?.tool_behaviour == TOOL_WRENCH) context[SCREENTIP_CONTEXT_RMB] = "Deconstruct" . = CONTEXTUAL_SCREENTIP_SET @@ -440,7 +441,7 @@ to_chat(user, span_warning("You press the power button, but the computer fails to boot up, displaying variety of errors before shutting down again.")) return FALSE - if(use_power()) // use_power() checks if the PC is powered + if(use_power()) // checks if the PC is powered if(issynth) to_chat(user, span_notice("You send an activation signal to \the [src], turning it on.")) else @@ -462,7 +463,6 @@ // Process currently calls handle_power(), may be expanded in future if more things are added. /obj/item/modular_computer/process(seconds_per_tick) if(!enabled) // The computer is turned off - last_power_usage = 0 return if(atom_integrity <= integrity_failure * max_integrity) @@ -736,7 +736,7 @@ return if(istype(attacking_item, /obj/item/stock_parts/cell)) - if(ismachinery(loc)) + if(ismachinery(physical)) return if(internal_cell) to_chat(user, span_warning("You try to connect \the [attacking_item] to \the [src], but its connectors are occupied.")) @@ -800,6 +800,16 @@ return ..() +/obj/item/modular_computer/screwdriver_act_secondary(mob/living/user, obj/item/tool) + . = ..() + if(internal_cell) + user.balloon_alert(user, "cell removed") + internal_cell.forceMove(drop_location()) + internal_cell = null + return TOOL_ACT_TOOLTYPE_SUCCESS + else + user.balloon_alert(user, "no cell!") + /obj/item/modular_computer/wrench_act_secondary(mob/living/user, obj/item/tool) . = ..() tool.play_tool_sound(src, user, 20, volume=20) diff --git a/code/modules/modular_computers/computers/item/computer_power.dm b/code/modules/modular_computers/computers/item/computer_power.dm index 6b6230ed0d4..0c3672352d0 100644 --- a/code/modules/modular_computers/computers/item/computer_power.dm +++ b/code/modules/modular_computers/computers/item/computer_power.dm @@ -1,9 +1,13 @@ +///The multiplier given to the base overtime charge drain value if its flashlight is on. +#define FLASHLIGHT_DRAIN_MULTIPLIER 1.25 + // Tries to draw power from charger or, if no operational charger is present, from power cell. /obj/item/modular_computer/proc/use_power(amount = 0) if(check_power_override()) return TRUE - if(ismachinery(loc)) - var/obj/machinery/machine_holder = loc + + if(ismachinery(physical)) + var/obj/machinery/machine_holder = physical if(machine_holder.powered()) machine_holder.use_power(amount) return TRUE @@ -27,20 +31,30 @@ return if(active_program) active_program.event_powerfailure() + if(light_on) + set_light_on(FALSE) for(var/datum/computer_file/program/programs as anything in idle_threads) programs.event_powerfailure() shutdown_computer(loud = FALSE) -// Handles power-related things, such as battery interaction, recharging, shutdown when it's discharged +///Takes the charge necessary from the Computer, shutting it off if it's unable to provide it. +///Charge depends on whether the PC is on, and what programs are running/idle on it. /obj/item/modular_computer/proc/handle_power(seconds_per_tick) var/power_usage = screen_on ? base_active_power_usage : base_idle_power_usage + if(light_on) + base_active_power_usage *= FLASHLIGHT_DRAIN_MULTIPLIER + if(active_program) + power_usage += active_program.power_cell_use + for(var/datum/computer_file/program/open_programs as anything in idle_threads) + if(!open_programs.power_cell_use) + continue + if(open_programs in idle_threads) + power_usage += (open_programs.power_cell_use / 2) - if(use_power(power_usage)) - last_power_usage = power_usage + if(use_power(power_usage * seconds_per_tick)) return TRUE - else - power_failure() - return FALSE + power_failure() + return FALSE ///Used by subtypes for special cases for power usage, returns TRUE if it should stop the use_power chain. /obj/item/modular_computer/proc/check_power_override() @@ -49,3 +63,5 @@ //Integrated (Silicon) tablets don't drain power, because the tablet is required to state laws, so it being disabled WILL cause problems. /obj/item/modular_computer/pda/silicon/check_power_override() return TRUE + +#undef FLASHLIGHT_DRAIN_MULTIPLIER diff --git a/code/modules/modular_computers/computers/item/computer_ui.dm b/code/modules/modular_computers/computers/item/computer_ui.dm index d5dcf98c623..1b87a014f18 100644 --- a/code/modules/modular_computers/computers/item/computer_ui.dm +++ b/code/modules/modular_computers/computers/item/computer_ui.dm @@ -44,7 +44,7 @@ // Operates TGUI /obj/item/modular_computer/ui_interact(mob/user, datum/tgui/ui) - if(!enabled || !user.can_read(src, READING_CHECK_LITERACY) || !use_power()) + if(!enabled || !user.can_read(src, READING_CHECK_LITERACY)) if(ui) ui.close() return diff --git a/code/modules/modular_computers/computers/machinery/modular_computer.dm b/code/modules/modular_computers/computers/machinery/modular_computer.dm index 293cdd9c5f7..c54d3295fe3 100644 --- a/code/modules/modular_computers/computers/machinery/modular_computer.dm +++ b/code/modules/modular_computers/computers/machinery/modular_computer.dm @@ -13,8 +13,6 @@ var/internal_cell = null ///A flag that describes this device type var/hardware_flag = PROGRAM_CONSOLE - ///Power usage during last tick - var/last_power_usage = 0 /// Amount of programs that can be ran at once var/max_idle_programs = 4 @@ -72,7 +70,7 @@ set_light(cpu?.enabled ? light_strength : 0) /obj/machinery/modular_computer/update_icon_state() - if(!cpu || !cpu.enabled || !cpu.use_power() || (machine_stat & NOPOWER)) + if(!cpu || !cpu.enabled || (machine_stat & NOPOWER)) icon_state = icon_state_unpowered else icon_state = icon_state_powered @@ -83,7 +81,7 @@ if(!cpu) return . - if(cpu.enabled && cpu.use_power()) + if(cpu.enabled) . += cpu.active_program?.program_icon_state || screen_icon_state_menu else if(!(machine_stat & NOPOWER)) . += screen_icon_screensaver diff --git a/code/modules/modular_computers/file_system/program.dm b/code/modules/modular_computers/file_system/program.dm index 1f36713380d..6f693b5bf99 100644 --- a/code/modules/modular_computers/file_system/program.dm +++ b/code/modules/modular_computers/file_system/program.dm @@ -1,8 +1,14 @@ +///The default amount a program should take in cell use. +#define PROGRAM_BASIC_CELL_USE 15 + // /program/ files are executable programs that do things. /datum/computer_file/program filetype = "PRG" /// File name. FILE NAME MUST BE UNIQUE IF YOU WANT THE PROGRAM TO BE DOWNLOADABLE FROM NTNET! filename = "UnknownProgram" + + ///How much power running this program costs. + var/power_cell_use = PROGRAM_BASIC_CELL_USE /// List of required accesses to *run* the program. Any match will do. var/list/required_access = list() /// List of required access to download or file host the program. Any match will do. @@ -211,3 +217,5 @@ computer.update_tablet_open_uis(usr) computer.update_appearance(UPDATE_ICON) return TRUE + +#undef PROGRAM_BASIC_CELL_USE