diff --git a/baystation12.dme b/baystation12.dme index e3a4437f1a6..c5a1822d1be 100644 --- a/baystation12.dme +++ b/baystation12.dme @@ -1381,6 +1381,7 @@ #include "code\modules\mob\new_player\sprite_accessories.dm" #include "code\modules\modular_computers\laptop_vendor.dm" #include "code\modules\modular_computers\computers\item\modular_computer.dm" +#include "code\modules\modular_computers\computers\item\processor.dm" #include "code\modules\modular_computers\computers\item\tablet.dm" #include "code\modules\modular_computers\computers\machinery\modular_computer.dm" #include "code\modules\modular_computers\computers\machinery\modular_console.dm" diff --git a/code/modules/modular_computers/computers/item/modular_computer.dm b/code/modules/modular_computers/computers/item/modular_computer.dm index b4429a00d8d..615a9dc16de 100644 --- a/code/modules/modular_computers/computers/item/modular_computer.dm +++ b/code/modules/modular_computers/computers/item/modular_computer.dm @@ -91,13 +91,17 @@ else overlays.Add(icon_state_menu) +// Used by child types if they have other power source than battery +/obj/item/modular_computer/proc/check_power_override() + return 0 + // Operates NanoUI /obj/item/modular_computer/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1) if(!open || !enabled) if(ui) ui.close() return 0 - if(!battery || !battery.charge) + if((!battery || !battery.charge) && !check_power_override()) if(ui) ui.close() return 0 @@ -127,7 +131,7 @@ data["programs"] = programs ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) if (!ui) - ui = new(user, src, ui_key, "laptop_mainscreen.tmpl", "NTOS-M Main Menu", 400, 500) + ui = new(user, src, ui_key, "laptop_mainscreen.tmpl", "NTOS Main Menu", 400, 500) ui.auto_update_layout = 1 ui.set_initial_data(data) ui.open() diff --git a/code/modules/modular_computers/computers/item/processor.dm b/code/modules/modular_computers/computers/item/processor.dm new file mode 100644 index 00000000000..243b5cee6f5 --- /dev/null +++ b/code/modules/modular_computers/computers/item/processor.dm @@ -0,0 +1,75 @@ +// Held by /obj/machinery/modular_computer to reduce amount of copy-pasted code. +/obj/item/modular_computer/processor + name = "processing unit" + desc = "You shouldn't see this. If you do, report it." + icon = null + icon_state = null + icon_state_unpowered = null + icon_state_menu = null + hardware_flag = 0 + + var/obj/machinery/modular_computer/machinery_computer = null + +// Process is handled via machinery half of this, due to power interaction. +/obj/item/modular_computer/processor/process() + return PROCESS_KILL + +/obj/item/modular_computer/processor/New(var/comp) + if(!comp || !istype(comp, /obj/machinery/modular_computer)) + CRASH("Inapropriate type passed to obj/item/modular_computer/processor/New()! Aborting.") + return + // Obtain reference to machinery computer + machinery_computer = comp + machinery_computer.cpu = src + // Now steal the computer's components and assume them as our own. The computer will send us commands, we'll do most of the work. + hard_drive = machinery_computer.hard_drive + machinery_computer.hard_drive = null + if(hard_drive) + hard_drive.holder2 = src + hard_drive.holder = null + network_card = machinery_computer.network_card + machinery_computer.network_card = null + if(network_card) + network_card.holder2 = src + network_card.holder = null + nano_printer = machinery_computer.nano_printer + machinery_computer.nano_printer = null + if(nano_printer) + nano_printer.holder = src + nano_printer.holder = null + card_slot = machinery_computer.card_slot + machinery_computer.card_slot = null + if(card_slot) + card_slot.holder2 = src + card_slot.holder = null + battery = machinery_computer.battery + machinery_computer.battery = null + hardware_flag = machinery_computer.hardware_flag + +/obj/item/modular_computer/processor/find_hardware_by_name(var/N) + var/datum/computer_hardware/H = machinery_computer.find_hardware_by_name(N) + if(H) + return H + else + return ..() + +/obj/item/modular_computer/processor/get_header_data() + var/list/L = ..() + if(machinery_computer.tesla_link && machinery_computer.tesla_link.enabled) + L["PC_apclinkicon"] = "charging.gif" + return L + +// Checks whether the machinery computer doesn't take power from APC network +/obj/item/modular_computer/processor/check_power_override() + if(!machinery_computer) + return 0 + if(!machinery_computer.tesla_link || !machinery_computer.tesla_link.enabled) + return 0 + return 1 + +// +/obj/item/modular_computer/processor/CanUseTopic(user, state) + if(!machinery_computer) + return 0 + return machinery_computer.CanUseTopic(user, state) + diff --git a/code/modules/modular_computers/computers/machinery/modular_computer.dm b/code/modules/modular_computers/computers/machinery/modular_computer.dm index 0c3435e42e7..cde7364e0fd 100644 --- a/code/modules/modular_computers/computers/machinery/modular_computer.dm +++ b/code/modules/modular_computers/computers/machinery/modular_computer.dm @@ -31,16 +31,17 @@ var/datum/computer_hardware/card_slot/card_slot // ID Card slot component of this computer. Mostly for HoP modification console that needs ID slot for modification. var/datum/computer_hardware/nano_printer/nano_printer // Nano Printer component of this computer, for your everyday paperwork needs. + var/obj/item/modular_computer/processor/cpu = null // CPU that handles most logic while this type only handles power and other specific things. /obj/machinery/modular_computer/update_icon() icon_state = icon_state_unpowered - overlays.Cut() + if(!enabled) return - if(active_program) - overlays.Add(active_program.program_icon_state ? active_program.program_icon_state : screen_icon_state_menu) - overlays.Add(active_program.keyboard_icon_state ? active_program.keyboard_icon_state : keyboard_icon_state_menu) + if(cpu && cpu.active_program) + overlays.Add(cpu.active_program.program_icon_state ? cpu.active_program.program_icon_state : screen_icon_state_menu) + overlays.Add(cpu.active_program.keyboard_icon_state ? cpu.active_program.keyboard_icon_state : keyboard_icon_state_menu) else overlays.Add(screen_icon_state_menu) overlays.Add(keyboard_icon_state_menu) @@ -51,31 +52,16 @@ set category = "Object" set src in view(1) - if(usr.stat || usr.restrained() || usr.lying || !istype(usr, /mob/living)) - usr << "You can't do that." + cpu.eject_id() + +// Called after the computer is completed (in case it is created step by step, for example via laptop fabricator) +// This allows the device to work and creates processor object that handles most logic. +// ALWAYS CALL THIS ONCE ALL OTHER VARIABLES ARE SET, NOT BEFORE. IT MAY BE ONLY CALLED ONCE. +/obj/machinery/modular_computer/proc/shift_to_cpu() + if(cpu) // We already called this. Abort. return + new/obj/item/modular_computer/processor(src) // It automatically handles everything in New() - if(!Adjacent(usr)) - usr << "You can't reach it." - return - - proc_eject_id(usr) - -/obj/machinery/modular_computer/proc/proc_eject_id(mob/user) - if(!user) - user = usr - - if(!card_slot) - user << "\The [src] does not have an ID card slot" - return - - if(!card_slot.stored_card) - user << "There is no card in \the [src]" - return - - card_slot.stored_card.forceMove(src.loc) - card_slot.stored_card = null - user << "You remove the card from \the [src]" /obj/machinery/modular_computer/New() ..() @@ -84,64 +70,41 @@ // Installs programs necessary for computer function. // TODO: Implement program for downloading of other programs, and replace hardcoded program addition here /obj/machinery/modular_computer/proc/install_default_programs() - hard_drive.store_file(new/datum/computer_file/program/computerconfig(src)) // Computer configuration utility, allows hardware control and displays more info than status bar + if(cpu && cpu.hard_drive) + cpu.hard_drive.store_file(new/datum/computer_file/program/computerconfig(src)) // Computer configuration utility, allows hardware control and displays more info than status bar - //TODO: Remove once downloading is implemented - hard_drive.store_file(new/datum/computer_file/program/alarm_monitor(src)) - hard_drive.store_file(new/datum/computer_file/program/power_monitor(src)) - hard_drive.store_file(new/datum/computer_file/program/atmos_control(src)) - hard_drive.store_file(new/datum/computer_file/program/rcon_console(src)) - hard_drive.store_file(new/datum/computer_file/program/suit_sensors(src)) + //TODO: Remove once downloading is implemented + cpu.hard_drive.store_file(new/datum/computer_file/program/alarm_monitor(src)) + cpu.hard_drive.store_file(new/datum/computer_file/program/power_monitor(src)) + cpu.hard_drive.store_file(new/datum/computer_file/program/atmos_control(src)) + cpu.hard_drive.store_file(new/datum/computer_file/program/rcon_console(src)) + cpu.hard_drive.store_file(new/datum/computer_file/program/suit_sensors(src)) + else if(hard_drive) + hard_drive.store_file(new/datum/computer_file/program/computerconfig(src)) // Computer configuration utility, allows hardware control and displays more info than status bar + + //TODO: Remove once downloading is implemented + hard_drive.store_file(new/datum/computer_file/program/alarm_monitor(src)) + hard_drive.store_file(new/datum/computer_file/program/power_monitor(src)) + hard_drive.store_file(new/datum/computer_file/program/atmos_control(src)) + hard_drive.store_file(new/datum/computer_file/program/rcon_console(src)) + hard_drive.store_file(new/datum/computer_file/program/suit_sensors(src)) // Operates NanoUI /obj/machinery/modular_computer/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1) - if(!open || !enabled) - if(ui) - ui.close() - return 0 - if(stat & (BROKEN | NOPOWER | MAINT)) - if(ui) - ui.close() - return 0 - - // If we have an active program switch to it now. - if(active_program) - if(ui) // This is the main laptop screen. Since we are switching to program's UI close it for now. - ui.close() - active_program.ui_interact(user) - return - - // We are still here, that means there is no program loaded. Load the BIOS/ROM/OS/whatever you want to call it. - // This screen simply lists available programs and user may select them. - if(!hard_drive || !hard_drive.stored_files || !hard_drive.stored_files.len) - visible_message("\The [src] beeps three times, it's screen displaying \"DISK ERROR\" warning.") - return // No HDD, No HDD files list or no stored files. Something is very broken. - - var/list/data = get_header_data() - - var/list/programs = list() - for(var/datum/computer_file/program/P in hard_drive.stored_files) - var/list/program = list() - program["name"] = P.filename - program["desc"] = P.filedesc - programs.Add(list(program)) - - data["programs"] = programs - ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) - if (!ui) - ui = new(user, src, ui_key, "laptop_mainscreen.tmpl", "NTOS Main Menu", 400, 500) - ui.auto_update_layout = 1 - ui.set_initial_data(data) - ui.open() - ui.set_auto_update(1) + if(cpu) + cpu.ui_interact(user, ui_key, ui, force_open) // On-click handling. Turns on the computer if it's off and opens the GUI. /obj/machinery/modular_computer/attack_hand(mob/user) - if(enabled) + if(!cpu) // If people started clicking us we're probably spawned for a while now. Generate the CPU datum. + shift_to_cpu() + if(!cpu) // Still no CPU? Something is very bad. Abort. + return + if(cpu.enabled) ui_interact(user) - else if((battery && battery.charge > 0) || (!battery && powered())) // Battery-run and charged or non-battery but powered by APC. + else if((cpu.battery && cpu.battery.charge > 0) || (!cpu.battery && powered())) // Battery-run and charged or non-battery but powered by APC. user << "You press the power button and start up \the [src]" - enabled = 1 + cpu.enabled = 1 update_icon() ui_interact(user) else // Unpowered @@ -149,13 +112,16 @@ // Process currently calls handle_power(), may be expanded in future if more things are added. /obj/machinery/modular_computer/process() - if(!enabled) // The computer is turned off + if(!cpu.enabled) // The computer is turned off use_power = 0 last_power_usage = 0 return 0 - if(active_program && active_program.requires_ntnet && !get_ntnet_status(active_program.requires_ntnet_feature)) // Active program requires NTNet to run but we've just lost connection. Crash. - kill_program(1) + if(!cpu) // The computer lacks CPU object + return 0 + + if(cpu.active_program && cpu.active_program.requires_ntnet && !cpu.get_ntnet_status(cpu.active_program.requires_ntnet_feature)) // Active program requires NTNet to run but we've just lost connection. Crash. + cpu.kill_program(1) visible_message("\The [src]'s screen briefly freezes and then shows \"NETWORK ERROR - NTNet connection lost. Please retry. If problem persists contact your system administrator.\" error.") battery_powered = battery ? 1 : 0 @@ -164,149 +130,71 @@ // Function used by NanoUI's to obtain data for header. All relevant entries begin with "PC_" /obj/machinery/modular_computer/proc/get_header_data() - var/list/data = list() - - if(battery) - switch(battery.percent()) - if(80 to 200) // 100 should be maximal but just in case.. - data["PC_batteryicon"] = "batt_100.gif" - if(60 to 80) - data["PC_batteryicon"] = "batt_80.gif" - if(40 to 60) - data["PC_batteryicon"] = "batt_60.gif" - if(20 to 40) - data["PC_batteryicon"] = "batt_40.gif" - if(5 to 20) - data["PC_batteryicon"] = "batt_20.gif" - else - data["PC_batteryicon"] = "batt_5.gif" - data["PC_batterypercent"] = "[round(battery.percent())] %" - data["PC_showbatteryicon"] = 1 - else // Computer without battery shouldn't work at all, but in case we implement computers without batteries in future that run solely on APC network, it's here. - data["PC_batteryicon"] = "batt_5.gif" - data["PC_batterypercent"] = "N/C" - data["PC_showbatteryicon"] = battery_powered - - switch(get_ntnet_status()) - if(0) - data["PC_ntneticon"] = "sig_none.gif" - if(1) - data["PC_ntneticon"] = "sig_low.gif" - if(2) - data["PC_ntneticon"] = "sig_high.gif" - if(3) - data["PC_ntneticon"] = "sig_lan.gif" - - if(tesla_link && tesla_link.enabled && powered()) - data["PC_apclinkicon"] = "charging.gif" - - data["PC_stationtime"] = worldtime2text() - data["PC_hasheader"] = 1 - data["PC_showexitprogram"] = active_program ? 1 : 0 // Hides "Exit Program" button on mainscreen - return data + if(cpu) + return cpu.get_header_data() + else + return list() // Relays kill program request to currently active program. Use this to quit current program. /obj/machinery/modular_computer/proc/kill_program(var/forced = 0) - if(active_program) - active_program.kill_program(forced) - active_program = null - var/mob/user = usr - if(user && istype(user)) - ui_interact(user) // Re-open the UI on this computer. It should show the main screen now. + if(cpu) + cpu.kill_program(forced) update_icon() // Returns 0 for No Signal, 1 for Low Signal and 2 for Good Signal. 3 is for wired connection (always-on) /obj/machinery/modular_computer/proc/get_ntnet_status(var/specific_action = 0) - if(network_card) - return network_card.get_signal(specific_action) - else - return 0 + if(cpu) + cpu.get_ntnet_status(specific_action) // Checks all hardware pieces to determine if name matches, if yes, returns the hardware piece, otherwise returns null -/obj/machinery/modular_computer/proc/find_hardware_by_name(var/name) - if(hard_drive && (hard_drive.name == name)) - return hard_drive - if(network_card && (network_card.name == name)) - return network_card - if(tesla_link && (tesla_link.name == name)) +/obj/machinery/modular_computer/proc/find_hardware_by_name(var/N) + if(tesla_link && (tesla_link.name == N)) return tesla_link - if(nano_printer && (nano_printer.name == name)) - return nano_printer - if(card_slot && (card_slot.name == name)) - return card_slot return null // Handles user's GUI input /obj/machinery/modular_computer/Topic(href, href_list) if(..()) return 1 - if( href_list["PC_exit"] ) - kill_program() - return - if( href_list["PC_enable_component"] ) - var/datum/computer_hardware/H = find_hardware_by_name(href_list["PC_enable_component"]) - if(H && istype(H) && !H.enabled) - H.enabled = 1 - return - if( href_list["PC_disable_component"] ) - var/datum/computer_hardware/H = find_hardware_by_name(href_list["PC_disable_component"]) - if(H && istype(H) && H.enabled) - H.enabled = 0 - return - if( href_list["PC_shutdown"] ) - kill_program(1) - visible_message("\The [src] shuts down.") - enabled = 0 - update_icon() - return - if( href_list["PC_runprogram"] ) - var/prog = href_list["PC_runprogram"] - var/datum/computer_file/program/P = null - var/mob/user = usr - if(hard_drive) - P = hard_drive.find_file_by_name(prog) + if(cpu) + return cpu.Topic(href, href_list) - if(!P || !istype(P)) // Program not found or it's not executable program. - user << "\The [src]'s screen shows \"I/O ERROR - Unable to run program\" warning." - return - - if(!P.is_supported_by_hardware(hardware_flag, 1, user)) - return - - if(P.requires_ntnet && !get_ntnet_status(P.requires_ntnet_feature)) // The program requires NTNet connection, but we are not connected to NTNet. - user << "\The [src]'s screen shows \"NETWORK ERROR - Unable to connect to NTNet. Please retry. If problem persists contact your system administrator.\" warning." - return - if(P.run_program(user)) - active_program = P - update_icon() - return // Used in following function to reduce copypaste /obj/machinery/modular_computer/proc/power_failure() - if(enabled) // Shut down the computer) - visible_message("\The [src]'s screen flickers \"BATTERY CRITICAL\" warning as it shuts down unexpectedly.") + if(cpu && cpu.enabled) // Shut down the computer + visible_message("\The [src]'s screen flickers [battery ? "\"BATTERY CRITICAL\"" : "\"EXTERNAL POWER LOSS\""] warning as it shuts down unexpectedly.") kill_program(1) enabled = 0 update_icon() stat |= NOPOWER + // Handles power-related things, such as battery interaction, recharging, shutdown when it's discharged, NOPOWER flag, etc. /obj/machinery/modular_computer/proc/handle_power() - if(battery && battery.charge <= 0) // Battery-run but battery is depleted. + if(!cpu) + return 0 + if(cpu.battery && cpu.battery.charge <= 0) // Battery-run but battery is depleted. power_failure() return 0 - else if(!battery && (!powered() || !tesla_link || !tesla_link.enabled)) // Not battery run, but lacking APC connection. + else if(!cpu.battery && (!powered() || !tesla_link || !tesla_link.enabled)) // Not battery run, but lacking APC connection. power_failure() return 0 else if(stat & NOPOWER) stat &= ~NOPOWER var/power_usage = open ? 300 : 25 // 300W when it's open and only 25W when closed (sleep mode)? Screen probably uses a lot. - if(network_card && network_card.enabled) - power_usage += network_card.power_usage + if(cpu.network_card && cpu.network_card.enabled) + power_usage += cpu.network_card.power_usage - if(hard_drive && hard_drive.enabled) - power_usage += hard_drive.power_usage + if(cpu.hard_drive && cpu.hard_drive.enabled) + power_usage += cpu.hard_drive.power_usage + + if(cpu.nano_printer && cpu.nano_printer.enabled) + power_usage += cpu.nano_printer.power_usage + + if(cpu.card_slot && cpu.card_slot.enabled) + power_usage += cpu.card_slot.power_usage // Wireless APC connection exists. if(tesla_link && tesla_link.enabled) @@ -314,19 +202,19 @@ active_power_usage = idle_power_usage + 100 // APCLink only charges at 100W rate, but covers any power usage. use_power = 1 // Battery is not fully charged. Begin slowly recharging. - if(battery && battery.charge < battery.maxcharge) + if(cpu.battery && cpu.battery.charge < cpu.battery.maxcharge) use_power = 2 - if(battery && powered() && (use_power == 2)) // Battery charging itself - battery.give(100 * CELLRATE) - else if(battery && !powered()) // Unpowered, but battery covers the usage. - battery.use(idle_power_usage * CELLRATE) + if(cpu.battery && powered() && (use_power == 2)) // Battery charging itself + cpu.battery.give(100 * CELLRATE) + else if(cpu.battery && !powered()) // Unpowered, but battery covers the usage. + cpu.battery.use(idle_power_usage * CELLRATE) else // No wireless connection run only on battery. use_power = 0 - if (battery) - battery.use(power_usage * CELLRATE) - last_power_usage = power_usage + if (cpu.battery) + cpu.battery.use(power_usage * CELLRATE) + cpu.last_power_usage = power_usage // Modular computers can have battery in them, we handle power in previous proc, so prevent this from messing it up for us. /obj/machinery/modular_computer/power_change() @@ -338,15 +226,15 @@ /obj/machinery/modular_computer/attackby(var/obj/item/weapon/W as obj, var/mob/user as mob) if(istype(W, /obj/item/weapon/card/id)) // ID Card, try to insert it. var/obj/item/weapon/card/id/I = W - if(!card_slot) + if(!cpu.card_slot) user << "You try to insert \the [I] into \the [src], but it does not have an ID card slot installed." return - if(card_slot.stored_card) + if(cpu.card_slot.stored_card) user << "You try to insert \the [I] into \the [src], but it's ID card slot is occupied." return - card_slot.stored_card = I + cpu.card_slot.stored_card = I I.forceMove(src) user << "You insert \the [I] into \the [src]." return diff --git a/code/modules/modular_computers/computers/machinery/modular_console.dm b/code/modules/modular_computers/computers/machinery/modular_console.dm index 2f24b3b0b51..171eee7a408 100644 --- a/code/modules/modular_computers/computers/machinery/modular_console.dm +++ b/code/modules/modular_computers/computers/machinery/modular_console.dm @@ -20,4 +20,5 @@ tesla_link.critical = 1 // Consoles don't usually come with cells, and this prevents people from disabling their only power source, as they wouldn't be able to enable it again. hard_drive = new/datum/computer_hardware/hard_drive/super(src) // Consoles generally have better HDDs due to lower space limitations ..() + shift_to_cpu() update_icon() \ No newline at end of file diff --git a/code/modules/modular_computers/file_system/programs/configurator.dm b/code/modules/modular_computers/file_system/programs/configurator.dm index 7d2698023ca..5d45fc1f4c6 100644 --- a/code/modules/modular_computers/file_system/programs/configurator.dm +++ b/code/modules/modular_computers/file_system/programs/configurator.dm @@ -37,19 +37,13 @@ var/list/hardware = list() if(stationary) - hardware.Add(stationary.network_card) - hardware.Add(stationary.hard_drive) - hardware.Add(stationary.tesla_link) - hardware.Add(stationary.card_slot) - hardware.Add(stationary.nano_printer) - data["disk_size"] = stationary.hard_drive.max_capacity - data["disk_used"] = stationary.hard_drive.used_capacity - data["power_usage"] = stationary.last_power_usage - data["battery_exists"] = stationary.battery ? 1 : 0 - if(stationary.battery) - data["battery_rating"] = stationary.battery.maxcharge - data["battery_percent"] = round(stationary.battery.percent()) - else if(movable) + if(stationary.cpu) + movable = stationary.cpu + hardware.Add(stationary.tesla_link) + else + return + + if(movable) hardware.Add(movable.network_card) hardware.Add(movable.hard_drive) hardware.Add(movable.card_slot) diff --git a/code/modules/modular_computers/laptop_vendor.dm b/code/modules/modular_computers/laptop_vendor.dm index d6b8d0b684a..3a6bd7698ee 100644 --- a/code/modules/modular_computers/laptop_vendor.dm +++ b/code/modules/modular_computers/laptop_vendor.dm @@ -240,6 +240,7 @@ obj/machinery/lapvend/attackby(obj/item/weapon/W as obj, mob/user as mob) if((devtype == 1) && fabricated_laptop) fabricated_laptop.forceMove(src.loc) fabricated_laptop.install_default_programs() + fabricated_laptop.shift_to_cpu() fabricated_laptop.close_laptop() fabricated_laptop = null else if((devtype == 2) && fabricated_tablet)