mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-11 16:14:08 +01:00
first attempt. partial copy and stuff.
This commit is contained in:
@@ -0,0 +1,780 @@
|
||||
// This is the base type that does all the hardware stuff.
|
||||
// Other types expand it - tablets use a direct subtypes, and
|
||||
// consoles and laptops use "procssor" item that is held inside machinery piece
|
||||
/obj/item/modular_computer
|
||||
name = "Modular Microcomputer"
|
||||
desc = "A small portable microcomputer."
|
||||
|
||||
var/enabled = 0 // Whether the computer is turned on.
|
||||
var/screen_on = 1 // Whether the computer is active/opened/it's screen is on.
|
||||
var/datum/computer_file/program/active_program = null // A currently active program running on the computer.
|
||||
var/hardware_flag = 0 // A flag that describes this device type
|
||||
var/last_power_usage = 0
|
||||
var/last_battery_percent = 0 // Used for deciding if battery percentage has chandged
|
||||
var/last_world_time = "00:00"
|
||||
var/list/last_header_icons
|
||||
var/computer_emagged = 0 // Whether the computer is emagged.
|
||||
|
||||
var/base_active_power_usage = 50 // Power usage when the computer is open (screen is active) and can be interacted with. Remember hardware can use power too.
|
||||
var/base_idle_power_usage = 5 // Power usage when the computer is idle and screen is off (currently only applies to laptops)
|
||||
|
||||
// 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
|
||||
// If you create a program which is limited to Laptops and Consoles you don't have to add it's icon_state overlay for Tablets too, for example.
|
||||
|
||||
icon = 'icons/obj/computer.dmi'
|
||||
icon_state = "laptop-open"
|
||||
var/icon_state_unpowered = null // Icon state when the computer is turned off
|
||||
var/icon_state_menu = "menu" // Icon state overlay when the computer is turned on, but no program is loaded that would override the screen.
|
||||
var/max_hardware_size = 0 // Maximal hardware size. Currently, tablets have 1, laptops 2 and consoles 3. Limits what hardware types can be installed.
|
||||
var/steel_sheet_cost = 5 // Amount of steel sheets refunded when disassembling an empty frame of this computer.
|
||||
var/light_strength = 0
|
||||
|
||||
// Damage of the chassis. If the chassis takes too much damage it will break apart.
|
||||
var/damage = 0 // Current damage level
|
||||
var/broken_damage = 50 // Damage level at which the computer ceases to operate
|
||||
var/max_damage = 100 // Damage level at which the computer breaks apart.
|
||||
|
||||
// Important hardware (must be installed for computer to work)
|
||||
var/obj/item/weapon/computer_hardware/processor_unit/processor_unit // CPU. Without it the computer won't run. Better CPUs can run more programs at once.
|
||||
var/obj/item/weapon/computer_hardware/network_card/network_card // Network Card component of this computer. Allows connection to NTNet
|
||||
var/obj/item/weapon/computer_hardware/hard_drive/hard_drive // Hard Drive component of this computer. Stores programs and files.
|
||||
var/obj/item/weapon/computer_hardware/battery_module/battery_module // An internal power source for this computer. Can be recharged.
|
||||
// Optional hardware (improves functionality, but is not critical for computer to work)
|
||||
var/obj/item/weapon/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/obj/item/weapon/computer_hardware/nano_printer/nano_printer // Nano Printer component of this computer, for your everyday paperwork needs.
|
||||
var/obj/item/weapon/computer_hardware/hard_drive/portable/portable_drive // Portable data storage
|
||||
|
||||
var/list/idle_threads = list() // Idle programs on background. They still receive process calls but can't be interacted with.
|
||||
|
||||
|
||||
// Eject ID card from computer, if it has ID slot with card inside.
|
||||
/obj/item/modular_computer/verb/eject_id()
|
||||
set name = "Eject ID"
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(usr.incapacitated() || !istype(usr, /mob/living))
|
||||
usr << "<span class='warning'>You can't do that.</span>"
|
||||
return
|
||||
|
||||
if(!Adjacent(usr))
|
||||
usr << "<span class='warning'>You can't reach it.</span>"
|
||||
return
|
||||
|
||||
proc_eject_id(usr)
|
||||
|
||||
// Eject ID card from computer, if it has ID slot with card inside.
|
||||
/obj/item/modular_computer/verb/eject_usb()
|
||||
set name = "Eject Portable Device"
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(usr.incapacitated() || !istype(usr, /mob/living))
|
||||
usr << "<span class='warning'>You can't do that.</span>"
|
||||
return
|
||||
|
||||
if(!Adjacent(usr))
|
||||
usr << "<span class='warning'>You can't reach it.</span>"
|
||||
return
|
||||
|
||||
proc_eject_usb(usr)
|
||||
|
||||
/obj/item/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
|
||||
|
||||
if(active_program)
|
||||
active_program.event_idremoved(0)
|
||||
|
||||
for(var/datum/computer_file/program/P in idle_threads)
|
||||
P.event_idremoved(1)
|
||||
|
||||
card_slot.stored_card.forceMove(get_turf(src))
|
||||
card_slot.stored_card = null
|
||||
update_uis()
|
||||
user << "You remove the card from \the [src]"
|
||||
|
||||
/obj/item/modular_computer/proc/proc_eject_usb(mob/user)
|
||||
if(!user)
|
||||
user = usr
|
||||
|
||||
if(!portable_drive)
|
||||
user << "There is no portable device connected to \the [src]."
|
||||
return
|
||||
|
||||
uninstall_component(user, portable_drive)
|
||||
update_uis()
|
||||
|
||||
/obj/item/modular_computer/attack_ghost(mob/dead/observer/user)
|
||||
if(enabled)
|
||||
ui_interact(user)
|
||||
else if(check_rights_for(user.client, R_ADMIN))
|
||||
var/response = alert(user, "This computer is turned off. Would you like to turn it on?", "Admin Override", "Yes", "No")
|
||||
if(response == "Yes")
|
||||
turn_on(user)
|
||||
|
||||
/obj/item/modular_computer/emag_act(remaining_charges, mob/user)
|
||||
if(computer_emagged)
|
||||
user << "\The [src] was already emagged."
|
||||
return 0
|
||||
else
|
||||
computer_emagged = 1
|
||||
user << "You emag \the [src]. It's screen briefly shows a \"OVERRIDE ACCEPTED: New software downloads available.\" message."
|
||||
return 1
|
||||
|
||||
/obj/item/modular_computer/examine(mob/user)
|
||||
..()
|
||||
if(damage > broken_damage)
|
||||
user << "<span class='danger'>It is heavily damaged!</span>"
|
||||
else if(damage)
|
||||
user << "It is damaged."
|
||||
|
||||
/obj/item/modular_computer/New()
|
||||
processing_objects.Add(src)
|
||||
update_icon()
|
||||
..()
|
||||
|
||||
/obj/item/modular_computer/Destroy()
|
||||
kill_program(1)
|
||||
processing_objects.Remove(src)
|
||||
for(var/obj/item/weapon/computer_hardware/CH in src.get_all_components())
|
||||
uninstall_component(null, CH)
|
||||
qdel(CH)
|
||||
return ..()
|
||||
|
||||
/obj/item/modular_computer/update_icon()
|
||||
icon_state = icon_state_unpowered
|
||||
|
||||
overlays.Cut()
|
||||
if(!enabled)
|
||||
//set_light(0)
|
||||
return
|
||||
//set_light(light_strength)
|
||||
if(active_program)
|
||||
overlays.Add(active_program.program_icon_state ? active_program.program_icon_state : icon_state_menu)
|
||||
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", datum/tgui/ui = null, force_open = 1, datum/tgui/master_ui = null, datum/ui_state/state = default_state)
|
||||
if(!screen_on || !enabled)
|
||||
if(ui)
|
||||
ui.close()
|
||||
return 0
|
||||
if((!battery_module || !battery_module.battery.charge) && !check_power_override())
|
||||
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
|
||||
if(P in idle_threads)
|
||||
program["running"] = 1
|
||||
programs.Add(list(program))
|
||||
|
||||
data["programs"] = programs
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if (!ui)
|
||||
// ui = new(user, src, ui_key, "laptop_mainscreen", "NTOS Main Menu", 400, 500)
|
||||
ui = new(user, src, ui_key, "vr_sleeper", "VR Sleeper", 475, 340, master_ui, state)
|
||||
ui.auto_update_layout = 1
|
||||
ui.set_initial_data(data)
|
||||
ui.open()
|
||||
ui.set_auto_update(1)
|
||||
|
||||
// On-click handling. Turns on the computer if it's off and opens the GUI.
|
||||
/obj/item/modular_computer/attack_self(mob/user)
|
||||
if(enabled)
|
||||
ui_interact(user)
|
||||
else
|
||||
turn_on(user)
|
||||
|
||||
/obj/item/modular_computer/proc/break_apart()
|
||||
visible_message("\The [src] breaks apart!")
|
||||
var/turf/newloc = get_turf(src)
|
||||
new /obj/item/stack/material/steel(newloc, round(steel_sheet_cost/2))
|
||||
for(var/obj/item/weapon/computer_hardware/H in get_all_components())
|
||||
uninstall_component(null, H)
|
||||
H.forceMove(newloc)
|
||||
if(prob(25))
|
||||
H.take_damage(rand(10,30))
|
||||
relay_qdel()
|
||||
qdel()
|
||||
|
||||
/obj/item/modular_computer/proc/turn_on(mob/user)
|
||||
var/issynth = issilicon(user) // Robots and AIs get different activation messages.
|
||||
if(damage > broken_damage)
|
||||
if(issynth)
|
||||
user << "You send an activation signal to \the [src], but it responds with an error code. It must be damaged."
|
||||
else
|
||||
user << "You press the power button, but the computer fails to boot up, displaying variety of errors before shutting down again."
|
||||
return
|
||||
if(processor_unit && ((battery_module && battery_module.battery.charge && battery_module.check_functionality()) || check_power_override())) // Battery-run and charged or non-battery but powered by APC.
|
||||
if(issynth)
|
||||
user << "You send an activation signal to \the [src], turning it on"
|
||||
else
|
||||
user << "You press the power button and start up \the [src]"
|
||||
enabled = 1
|
||||
update_icon()
|
||||
ui_interact(user)
|
||||
else // Unpowered
|
||||
if(issynth)
|
||||
user << "You send an activation signal to \the [src] but it does not respond"
|
||||
else
|
||||
user << "You press the power button but \the [src] does not respond"
|
||||
|
||||
// Process currently calls handle_power(), may be expanded in future if more things are added.
|
||||
/obj/item/modular_computer/process()
|
||||
if(!enabled) // The computer is turned off
|
||||
last_power_usage = 0
|
||||
return 0
|
||||
|
||||
if(damage > broken_damage)
|
||||
shutdown_computer()
|
||||
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.
|
||||
active_program.event_networkfailure(0)
|
||||
|
||||
for(var/datum/computer_file/program/P in idle_threads)
|
||||
if(P.requires_ntnet && !get_ntnet_status(P.requires_ntnet_feature))
|
||||
P.event_networkfailure(1)
|
||||
|
||||
if(active_program)
|
||||
if(active_program.program_state != PROGRAM_STATE_KILLED)
|
||||
active_program.process_tick()
|
||||
active_program.ntnet_status = get_ntnet_status()
|
||||
active_program.computer_emagged = computer_emagged
|
||||
else
|
||||
active_program = null
|
||||
|
||||
for(var/datum/computer_file/program/P in idle_threads)
|
||||
if(P.program_state != PROGRAM_STATE_KILLED)
|
||||
P.process_tick()
|
||||
P.ntnet_status = get_ntnet_status()
|
||||
P.computer_emagged = computer_emagged
|
||||
else
|
||||
idle_threads.Remove(P)
|
||||
|
||||
handle_power() // Handles all computer power interaction
|
||||
check_update_ui_need()
|
||||
|
||||
// Function used by NanoUI's to obtain data for header. All relevant entries begin with "PC_"
|
||||
/obj/item/modular_computer/proc/get_header_data()
|
||||
var/list/data = list()
|
||||
|
||||
if(battery_module)
|
||||
switch(battery_module.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_module.battery.percent())] %"
|
||||
data["PC_showbatteryicon"] = 1
|
||||
else
|
||||
data["PC_batteryicon"] = "batt_5.gif"
|
||||
data["PC_batterypercent"] = "N/C"
|
||||
data["PC_showbatteryicon"] = battery_module ? 1 : 0
|
||||
|
||||
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(idle_threads.len)
|
||||
var/list/program_headers = list()
|
||||
for(var/datum/computer_file/program/P in idle_threads)
|
||||
if(!P.ui_header)
|
||||
continue
|
||||
program_headers.Add(list(list(
|
||||
"icon" = P.ui_header
|
||||
)))
|
||||
|
||||
data["PC_programheaders"] = program_headers
|
||||
|
||||
data["PC_stationtime"] = stationtime2text()
|
||||
data["PC_hasheader"] = 1
|
||||
data["PC_showexitprogram"] = active_program ? 1 : 0 // Hides "Exit Program" button on mainscreen
|
||||
return data
|
||||
|
||||
// Relays kill program request to currently active program. Use this to quit current program.
|
||||
/obj/item/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.
|
||||
update_icon()
|
||||
|
||||
// Returns 0 for No Signal, 1 for Low Signal and 2 for Good Signal. 3 is for wired connection (always-on)
|
||||
/obj/item/modular_computer/proc/get_ntnet_status(var/specific_action = 0)
|
||||
if(network_card)
|
||||
return network_card.get_signal(specific_action)
|
||||
else
|
||||
return 0
|
||||
|
||||
/obj/item/modular_computer/proc/add_log(var/text)
|
||||
if(!get_ntnet_status())
|
||||
return 0
|
||||
return ntnet_global.add_log(text, network_card)
|
||||
|
||||
/obj/item/modular_computer/proc/shutdown_computer(var/loud = 1)
|
||||
kill_program(1)
|
||||
for(var/datum/computer_file/program/P in idle_threads)
|
||||
P.kill_program(1)
|
||||
idle_threads.Remove(P)
|
||||
if(loud)
|
||||
visible_message("\The [src] shuts down.")
|
||||
enabled = 0
|
||||
update_icon()
|
||||
return
|
||||
|
||||
// Handles user's GUI input
|
||||
/obj/item/modular_computer/Topic(href, href_list)
|
||||
if(..())
|
||||
return 1
|
||||
if( href_list["PC_exit"] )
|
||||
kill_program()
|
||||
return 1
|
||||
if( href_list["PC_enable_component"] )
|
||||
var/obj/item/weapon/computer_hardware/H = find_hardware_by_name(href_list["PC_enable_component"])
|
||||
if(H && istype(H) && !H.enabled)
|
||||
H.enabled = 1
|
||||
. = 1
|
||||
if( href_list["PC_disable_component"] )
|
||||
var/obj/item/weapon/computer_hardware/H = find_hardware_by_name(href_list["PC_disable_component"])
|
||||
if(H && istype(H) && H.enabled)
|
||||
H.enabled = 0
|
||||
. = 1
|
||||
if( href_list["PC_shutdown"] )
|
||||
shutdown_computer()
|
||||
return 1
|
||||
if( href_list["PC_minimize"] )
|
||||
var/mob/user = usr
|
||||
if(!active_program || !processor_unit)
|
||||
return
|
||||
|
||||
idle_threads.Add(active_program)
|
||||
active_program.program_state = PROGRAM_STATE_BACKGROUND // Should close any existing UIs
|
||||
nanomanager.close_uis(active_program.NM ? active_program.NM : active_program)
|
||||
active_program = null
|
||||
update_icon()
|
||||
if(user && istype(user))
|
||||
ui_interact(user) // Re-open the UI on this computer. It should show the main screen now.
|
||||
|
||||
if( href_list["PC_killprogram"] )
|
||||
var/prog = href_list["PC_killprogram"]
|
||||
var/datum/computer_file/program/P = null
|
||||
var/mob/user = usr
|
||||
if(hard_drive)
|
||||
P = hard_drive.find_file_by_name(prog)
|
||||
|
||||
if(!istype(P) || P.program_state == PROGRAM_STATE_KILLED)
|
||||
return
|
||||
|
||||
P.kill_program(1)
|
||||
update_uis()
|
||||
user << "<span class='notice'>Program [P.filename].[P.filetype] with PID [rand(100,999)] has been killed.</span>"
|
||||
|
||||
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(!P || !istype(P)) // Program not found or it's not executable program.
|
||||
user << "<span class='danger'>\The [src]'s screen shows \"I/O ERROR - Unable to run program\" warning.</span>"
|
||||
return
|
||||
|
||||
P.computer = src
|
||||
|
||||
if(!P.is_supported_by_hardware(hardware_flag, 1, user))
|
||||
return
|
||||
|
||||
// The program is already running. Resume it.
|
||||
if(P in idle_threads)
|
||||
P.program_state = PROGRAM_STATE_ACTIVE
|
||||
active_program = P
|
||||
idle_threads.Remove(P)
|
||||
update_icon()
|
||||
return
|
||||
|
||||
if(idle_threads.len >= processor_unit.max_idle_programs+1)
|
||||
user << "<span class='notice'>\The [src] displays a \"Maximal CPU load reached. Unable to run another program.\" error</span>"
|
||||
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 << "<span class='danger'>\The [src]'s screen shows \"NETWORK ERROR - Unable to connect to NTNet. Please retry. If problem persists contact your system administrator.\" warning.</span>"
|
||||
return
|
||||
|
||||
if(P.run_program(user))
|
||||
active_program = P
|
||||
update_icon()
|
||||
return 1
|
||||
if(.)
|
||||
update_uis()
|
||||
|
||||
// Used in following function to reduce copypaste
|
||||
/obj/item/modular_computer/proc/power_failure(var/malfunction = 0)
|
||||
if(enabled) // Shut down the computer
|
||||
visible_message("<span class='danger'>\The [src]'s screen flickers \"BATTERY [malfunction ? "MALFUNCTION" : "CRITICAL"]\" warning as it shuts down unexpectedly.</span>")
|
||||
if(active_program)
|
||||
active_program.event_powerfailure(0)
|
||||
for(var/datum/computer_file/program/PRG in idle_threads)
|
||||
PRG.event_powerfailure(1)
|
||||
shutdown_computer(0)
|
||||
|
||||
// Handles power-related things, such as battery interaction, recharging, shutdown when it's discharged
|
||||
/obj/item/modular_computer/proc/handle_power()
|
||||
if(!battery_module || battery_module.battery.charge <= 0) // Battery-run but battery is depleted.
|
||||
power_failure()
|
||||
return 0
|
||||
|
||||
var/power_usage = screen_on ? base_active_power_usage : base_idle_power_usage
|
||||
|
||||
for(var/obj/item/weapon/computer_hardware/H in get_all_components())
|
||||
if(H.enabled)
|
||||
power_usage += H.power_usage
|
||||
|
||||
if(battery_module)
|
||||
if(!battery_module.check_functionality())
|
||||
power_failure(1)
|
||||
return
|
||||
battery_module.battery.use(power_usage * CELLRATE)
|
||||
|
||||
last_power_usage = power_usage
|
||||
|
||||
/obj/item/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)
|
||||
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)
|
||||
user << "You try to insert \the [I] into \the [src], but it's ID card slot is occupied."
|
||||
return
|
||||
user.drop_from_inventory(I)
|
||||
card_slot.stored_card = I
|
||||
I.forceMove(src)
|
||||
update_uis()
|
||||
user << "You insert \the [I] into \the [src]."
|
||||
return
|
||||
if(istype(W, /obj/item/weapon/paper))
|
||||
if(!nano_printer)
|
||||
return
|
||||
nano_printer.attackby(W, user)
|
||||
if(istype(W, /obj/item/weapon/computer_hardware))
|
||||
var/obj/item/weapon/computer_hardware/C = W
|
||||
if(C.hardware_size <= max_hardware_size)
|
||||
try_install_component(user, C)
|
||||
else
|
||||
user << "This component is too large for \the [src]."
|
||||
if(istype(W, /obj/item/weapon/wrench))
|
||||
var/list/components = get_all_components()
|
||||
if(components.len)
|
||||
user << "Remove all components from \the [src] before disassembling it."
|
||||
return
|
||||
new /obj/item/stack/material/steel( get_turf(src.loc), steel_sheet_cost )
|
||||
src.visible_message("\The [src] has been disassembled by [user].")
|
||||
relay_qdel()
|
||||
qdel(src)
|
||||
return
|
||||
if(istype(W, /obj/item/weapon/weldingtool))
|
||||
var/obj/item/weapon/weldingtool/WT = W
|
||||
if(!WT.isOn())
|
||||
user << "\The [W] is off."
|
||||
return
|
||||
|
||||
if(!damage)
|
||||
user << "\The [src] does not require repairs."
|
||||
return
|
||||
|
||||
user << "You begin repairing damage to \the [src]..."
|
||||
if(WT.remove_fuel(round(damage/75)) && do_after(usr, damage/10))
|
||||
damage = 0
|
||||
user << "You repair \the [src]."
|
||||
return
|
||||
|
||||
if(istype(W, /obj/item/weapon/screwdriver))
|
||||
var/list/all_components = get_all_components()
|
||||
if(!all_components.len)
|
||||
user << "This device doesn't have any components installed."
|
||||
return
|
||||
var/list/component_names = list()
|
||||
for(var/obj/item/weapon/computer_hardware/H in all_components)
|
||||
component_names.Add(H.name)
|
||||
|
||||
var/choice = input(usr, "Which component do you want to uninstall?", "Computer maintenance", null) as null|anything in component_names
|
||||
|
||||
if(!choice)
|
||||
return
|
||||
|
||||
if(!Adjacent(usr))
|
||||
return
|
||||
|
||||
var/obj/item/weapon/computer_hardware/H = find_hardware_by_name(choice)
|
||||
|
||||
if(!H)
|
||||
return
|
||||
|
||||
uninstall_component(user, H)
|
||||
|
||||
return
|
||||
|
||||
..()
|
||||
|
||||
// Used by processor to relay qdel() to machinery type.
|
||||
/obj/item/modular_computer/proc/relay_qdel()
|
||||
return
|
||||
|
||||
// Attempts to install the hardware into apropriate slot.
|
||||
/obj/item/modular_computer/proc/try_install_component(var/mob/living/user, var/obj/item/weapon/computer_hardware/H, var/found = 0)
|
||||
// "USB" flash drive.
|
||||
if(istype(H, /obj/item/weapon/computer_hardware/hard_drive/portable))
|
||||
if(portable_drive)
|
||||
user << "This computer's portable drive slot is already occupied by \the [portable_drive]."
|
||||
return
|
||||
found = 1
|
||||
portable_drive = H
|
||||
else if(istype(H, /obj/item/weapon/computer_hardware/hard_drive))
|
||||
if(hard_drive)
|
||||
user << "This computer's hard drive slot is already occupied by \the [hard_drive]."
|
||||
return
|
||||
found = 1
|
||||
hard_drive = H
|
||||
else if(istype(H, /obj/item/weapon/computer_hardware/network_card))
|
||||
if(network_card)
|
||||
user << "This computer's network card slot is already occupied by \the [network_card]."
|
||||
return
|
||||
found = 1
|
||||
network_card = H
|
||||
else if(istype(H, /obj/item/weapon/computer_hardware/nano_printer))
|
||||
if(nano_printer)
|
||||
user << "This computer's nano printer slot is already occupied by \the [nano_printer]."
|
||||
return
|
||||
found = 1
|
||||
nano_printer = H
|
||||
else if(istype(H, /obj/item/weapon/computer_hardware/card_slot))
|
||||
if(card_slot)
|
||||
user << "This computer's card slot is already occupied by \the [card_slot]."
|
||||
return
|
||||
found = 1
|
||||
card_slot = H
|
||||
else if(istype(H, /obj/item/weapon/computer_hardware/battery_module))
|
||||
if(battery_module)
|
||||
user << "This computer's battery slot is already occupied by \the [battery_module]."
|
||||
return
|
||||
found = 1
|
||||
battery_module = H
|
||||
else if(istype(H, /obj/item/weapon/computer_hardware/processor_unit))
|
||||
if(processor_unit)
|
||||
user << "This computer's processor slot is already occupied by \the [processor_unit]."
|
||||
return
|
||||
found = 1
|
||||
processor_unit = H
|
||||
if(found)
|
||||
user << "You install \the [H] into \the [src]"
|
||||
H.holder2 = src
|
||||
user.drop_from_inventory(H)
|
||||
H.forceMove(src)
|
||||
|
||||
// Uninstalls component. Found and Critical vars may be passed by parent types, if they have additional hardware.
|
||||
/obj/item/modular_computer/proc/uninstall_component(var/mob/living/user, var/obj/item/weapon/computer_hardware/H, var/found = 0, var/critical = 0)
|
||||
if(portable_drive == H)
|
||||
portable_drive = null
|
||||
found = 1
|
||||
if(hard_drive == H)
|
||||
hard_drive = null
|
||||
found = 1
|
||||
critical = 1
|
||||
if(network_card == H)
|
||||
network_card = null
|
||||
found = 1
|
||||
if(nano_printer == H)
|
||||
nano_printer = null
|
||||
found = 1
|
||||
if(card_slot == H)
|
||||
card_slot = null
|
||||
found = 1
|
||||
if(battery_module == H)
|
||||
battery_module = null
|
||||
found = 1
|
||||
if(processor_unit == H)
|
||||
processor_unit = null
|
||||
found = 1
|
||||
critical = 1
|
||||
if(found)
|
||||
if(user)
|
||||
user << "You remove \the [H] from \the [src]."
|
||||
H.forceMove(get_turf(src))
|
||||
H.holder2 = null
|
||||
if(critical && enabled)
|
||||
if(user)
|
||||
user << "<span class='danger'>\The [src]'s screen freezes for few seconds and then displays an \"HARDWARE ERROR: Critical component disconnected. Please verify component connection and reboot the device. If the problem persists contact technical support for assistance.\" warning.</span>"
|
||||
shutdown_computer()
|
||||
update_icon()
|
||||
|
||||
|
||||
// Checks all hardware pieces to determine if name matches, if yes, returns the hardware piece, otherwise returns null
|
||||
/obj/item/modular_computer/proc/find_hardware_by_name(var/name)
|
||||
if(portable_drive && (portable_drive.name == name))
|
||||
return portable_drive
|
||||
if(hard_drive && (hard_drive.name == name))
|
||||
return hard_drive
|
||||
if(network_card && (network_card.name == name))
|
||||
return network_card
|
||||
if(nano_printer && (nano_printer.name == name))
|
||||
return nano_printer
|
||||
if(card_slot && (card_slot.name == name))
|
||||
return card_slot
|
||||
if(battery_module && (battery_module.name == name))
|
||||
return battery_module
|
||||
if(processor_unit && (processor_unit.name == name))
|
||||
return processor_unit
|
||||
return null
|
||||
|
||||
// Returns list of all components
|
||||
/obj/item/modular_computer/proc/get_all_components()
|
||||
var/list/all_components = list()
|
||||
if(hard_drive)
|
||||
all_components.Add(hard_drive)
|
||||
if(network_card)
|
||||
all_components.Add(network_card)
|
||||
if(portable_drive)
|
||||
all_components.Add(portable_drive)
|
||||
if(nano_printer)
|
||||
all_components.Add(nano_printer)
|
||||
if(card_slot)
|
||||
all_components.Add(card_slot)
|
||||
if(battery_module)
|
||||
all_components.Add(battery_module)
|
||||
if(processor_unit)
|
||||
all_components.Add(processor_unit)
|
||||
return all_components
|
||||
|
||||
/obj/item/modular_computer/proc/update_uis()
|
||||
if(active_program) //Should we update program ui or computer ui?
|
||||
nanomanager.update_uis(active_program)
|
||||
if(active_program.NM)
|
||||
nanomanager.update_uis(active_program.NM)
|
||||
else
|
||||
nanomanager.update_uis(src)
|
||||
|
||||
/obj/item/modular_computer/proc/check_update_ui_need()
|
||||
var/ui_update_needed = 0
|
||||
if(battery_module)
|
||||
var/batery_percent = battery_module.battery.percent()
|
||||
if(last_battery_percent != batery_percent) //Let's update UI on percent change
|
||||
ui_update_needed = 1
|
||||
last_battery_percent = batery_percent
|
||||
|
||||
if(stationtime2text() != last_world_time)
|
||||
last_world_time = stationtime2text()
|
||||
ui_update_needed = 1
|
||||
|
||||
if(idle_threads.len)
|
||||
var/list/current_header_icons = list()
|
||||
for(var/datum/computer_file/program/P in idle_threads)
|
||||
if(!P.ui_header)
|
||||
continue
|
||||
current_header_icons[P.type] = P.ui_header
|
||||
if(!last_header_icons)
|
||||
last_header_icons = current_header_icons
|
||||
|
||||
else if(!listequal(last_header_icons, current_header_icons))
|
||||
last_header_icons = current_header_icons
|
||||
ui_update_needed = 1
|
||||
else
|
||||
for(var/x in last_header_icons|current_header_icons)
|
||||
if(last_header_icons[x]!=current_header_icons[x])
|
||||
last_header_icons = current_header_icons
|
||||
ui_update_needed = 1
|
||||
break
|
||||
|
||||
if(ui_update_needed)
|
||||
update_uis()
|
||||
|
||||
/obj/item/modular_computer/proc/take_damage(var/amount, var/component_probability, var/damage_casing = 1, var/randomize = 1)
|
||||
if(randomize)
|
||||
// 75%-125%, rand() works with integers, apparently.
|
||||
amount *= (rand(75, 125) / 100.0)
|
||||
amount = round(amount)
|
||||
if(damage_casing)
|
||||
damage += amount
|
||||
damage = between(0, damage, max_damage)
|
||||
|
||||
if(component_probability)
|
||||
for(var/obj/item/weapon/computer_hardware/H in get_all_components())
|
||||
if(prob(component_probability))
|
||||
H.take_damage(round(amount / 2))
|
||||
|
||||
if(damage >= max_damage)
|
||||
break_apart()
|
||||
|
||||
// Stronger explosions cause serious damage to internal components
|
||||
// Minor explosions are mostly mitigitated by casing.
|
||||
/obj/item/modular_computer/ex_act(var/severity)
|
||||
take_damage(rand(100,200) / severity, 30 / severity)
|
||||
|
||||
// EMPs are similar to explosions, but don't cause physical damage to the casing. Instead they screw up the components
|
||||
/obj/item/modular_computer/emp_act(var/severity)
|
||||
take_damage(rand(100,200) / severity, 50 / severity, 0)
|
||||
|
||||
// "Stun" weapons can cause minor damage to components (short-circuits?)
|
||||
// "Burn" damage is equally strong against internal components and exterior casing
|
||||
// "Brute" damage mostly damages the casing.
|
||||
/obj/item/modular_computer/bullet_act(var/obj/item/projectile/Proj)
|
||||
switch(Proj.damage_type)
|
||||
if(BRUTE)
|
||||
take_damage(Proj.damage, Proj.damage / 2)
|
||||
//if(HALLOSS)
|
||||
// take_damage(Proj.damage, Proj.damage / 3, 0)
|
||||
if(BURN)
|
||||
take_damage(Proj.damage, Proj.damage / 1.5)
|
||||
@@ -0,0 +1,133 @@
|
||||
// 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
|
||||
|
||||
/obj/item/modular_computer/processor/Destroy()
|
||||
. = ..()
|
||||
if(machinery_computer && (machinery_computer.cpu == src))
|
||||
machinery_computer.cpu = null
|
||||
machinery_computer = null
|
||||
|
||||
/obj/item/modular_computer/processor/nano_host()
|
||||
return machinery_computer.nano_host()
|
||||
|
||||
// Due to how processes work, we'd receive two process calls - one from machinery type and one from our own type.
|
||||
// Since we want this to be in-sync with machinery (as it's hidden type for machinery-based computers) we'll ignore
|
||||
// non-relayed process calls.
|
||||
/obj/item/modular_computer/processor/process(var/relayed = 0)
|
||||
if(relayed)
|
||||
..()
|
||||
else
|
||||
return
|
||||
|
||||
/obj/item/modular_computer/processor/examine(var/mob/user)
|
||||
if(damage > broken_damage)
|
||||
user << "<span class='danger'>It is heavily damaged!</span>"
|
||||
else if(damage)
|
||||
user << "It is damaged."
|
||||
|
||||
// Power interaction is handled by our machinery part, due to machinery having APC connection.
|
||||
/obj/item/modular_computer/processor/handle_power()
|
||||
if(machinery_computer)
|
||||
machinery_computer.handle_power()
|
||||
|
||||
/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
|
||||
hardware_flag = machinery_computer.hardware_flag
|
||||
max_hardware_size = machinery_computer.max_hardware_size
|
||||
steel_sheet_cost = machinery_computer.steel_sheet_cost
|
||||
max_damage = machinery_computer._max_damage
|
||||
broken_damage = machinery_computer._break_damage
|
||||
|
||||
/obj/item/modular_computer/processor/relay_qdel()
|
||||
qdel(machinery_computer)
|
||||
|
||||
/obj/item/modular_computer/processor/find_hardware_by_name(var/N)
|
||||
var/obj/item/weapon/computer_hardware/H = machinery_computer.find_hardware_by_name(N)
|
||||
if(H)
|
||||
return H
|
||||
else
|
||||
return ..()
|
||||
|
||||
/obj/item/modular_computer/processor/update_icon()
|
||||
if(machinery_computer)
|
||||
return machinery_computer.update_icon()
|
||||
|
||||
/obj/item/modular_computer/processor/get_header_data()
|
||||
var/list/L = ..()
|
||||
if(machinery_computer.tesla_link && machinery_computer.tesla_link.enabled && machinery_computer.powered())
|
||||
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 machinery_computer.powered()
|
||||
|
||||
// This thing is not meant to be used on it's own, get topic data from our machinery owner.
|
||||
/obj/item/modular_computer/processor/CanUseTopic(user, state)
|
||||
if(!machinery_computer)
|
||||
return 0
|
||||
return machinery_computer.CanUseTopic(user, state)
|
||||
|
||||
/obj/item/modular_computer/processor/shutdown_computer()
|
||||
if(!machinery_computer)
|
||||
return
|
||||
..()
|
||||
machinery_computer.update_icon()
|
||||
machinery_computer.use_power = 0
|
||||
return
|
||||
|
||||
// Tesla links only work on machinery types, so we'll override the default try_install_component() proc
|
||||
/obj/item/modular_computer/processor/try_install_component(var/mob/living/user, var/obj/item/weapon/computer_hardware/H, var/found = 0)
|
||||
if(istype(H, /obj/item/weapon/computer_hardware/tesla_link))
|
||||
if(machinery_computer.tesla_link)
|
||||
user << "This computer's tesla link slot is already occupied by \the [machinery_computer.tesla_link]."
|
||||
return
|
||||
var/obj/item/weapon/computer_hardware/tesla_link/L = H
|
||||
L.holder = machinery_computer
|
||||
machinery_computer.tesla_link = L
|
||||
found = 1
|
||||
..(user, H, found)
|
||||
|
||||
/obj/item/modular_computer/processor/uninstall_component(var/mob/living/user, var/obj/item/weapon/computer_hardware/H, var/found = 0, var/critical = 0)
|
||||
if(machinery_computer.tesla_link == H)
|
||||
machinery_computer.tesla_link = null
|
||||
var/obj/item/weapon/computer_hardware/tesla_link/L = H
|
||||
L.holder = null
|
||||
found = 1
|
||||
..(user, H, found, critical)
|
||||
|
||||
/obj/item/modular_computer/processor/get_all_components()
|
||||
var/list/all_components = ..()
|
||||
if(machinery_computer && machinery_computer.tesla_link)
|
||||
all_components.Add(machinery_computer.tesla_link)
|
||||
return all_components
|
||||
|
||||
// Perform adjacency checks on our machinery counterpart, rather than on ourselves.
|
||||
/obj/item/modular_computer/processor/Adjacent(var/atom/neighbor)
|
||||
if(!machinery_computer)
|
||||
return 0
|
||||
return machinery_computer.Adjacent(neighbor)
|
||||
|
||||
/obj/item/modular_computer/processor/turn_on(var/mob/user)
|
||||
// If we have a tesla link on our machinery counterpart, enable it automatically. Lets computer without a battery work.
|
||||
if(machinery_computer && machinery_computer.tesla_link)
|
||||
machinery_computer.tesla_link.enabled = 1
|
||||
..()
|
||||
@@ -0,0 +1,10 @@
|
||||
/obj/item/modular_computer/tablet
|
||||
name = "tablet computer"
|
||||
icon = 'icons/obj/modular_tablet.dmi'
|
||||
icon_state = "tablet"
|
||||
icon_state_unpowered = "tablet"
|
||||
icon_state_menu = "menu"
|
||||
hardware_flag = PROGRAM_TABLET
|
||||
max_hardware_size = 1
|
||||
w_class = 2
|
||||
light_strength = 2 // Same as PDAs
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
// Available as custom loadout item, this is literally the worst possible cheap tablet
|
||||
/obj/item/modular_computer/tablet/preset/custom_loadout/cheap/New()
|
||||
. = ..()
|
||||
desc = "A low-end tablet often seen among low ranked station personnel."
|
||||
processor_unit = new/obj/item/weapon/computer_hardware/processor_unit/small(src)
|
||||
battery_module = new/obj/item/weapon/computer_hardware/battery_module/nano(src)
|
||||
battery_module.charge_to_full()
|
||||
hard_drive = new/obj/item/weapon/computer_hardware/hard_drive/micro(src)
|
||||
network_card = new/obj/item/weapon/computer_hardware/network_card(src)
|
||||
|
||||
// Alternative version, an average one, for higher ranked positions mostly
|
||||
/obj/item/modular_computer/tablet/preset/custom_loadout/advanced/New()
|
||||
. = ..()
|
||||
processor_unit = new/obj/item/weapon/computer_hardware/processor_unit/small(src)
|
||||
battery_module = new/obj/item/weapon/computer_hardware/battery_module(src)
|
||||
battery_module.charge_to_full()
|
||||
hard_drive = new/obj/item/weapon/computer_hardware/hard_drive/small(src)
|
||||
network_card = new/obj/item/weapon/computer_hardware/network_card(src)
|
||||
nano_printer = new/obj/item/weapon/computer_hardware/nano_printer(src)
|
||||
card_slot = new/obj/item/weapon/computer_hardware/card_slot(src)
|
||||
@@ -0,0 +1,91 @@
|
||||
/obj/machinery/modular_computer/console/preset/
|
||||
// Can be changed to give devices specific hardware
|
||||
var/_has_id_slot = 0
|
||||
var/_has_printer = 0
|
||||
var/_has_battery = 0
|
||||
|
||||
/obj/machinery/modular_computer/console/preset/New()
|
||||
. = ..()
|
||||
if(!cpu)
|
||||
return
|
||||
cpu.processor_unit = new/obj/item/weapon/computer_hardware/processor_unit(cpu)
|
||||
if(_has_id_slot)
|
||||
cpu.card_slot = new/obj/item/weapon/computer_hardware/card_slot(cpu)
|
||||
if(_has_printer)
|
||||
cpu.nano_printer = new/obj/item/weapon/computer_hardware/nano_printer(cpu)
|
||||
if(_has_battery)
|
||||
cpu.battery_module = new/obj/item/weapon/computer_hardware/battery_module/super(cpu)
|
||||
install_programs()
|
||||
|
||||
// Override in child types to install preset-specific programs.
|
||||
/obj/machinery/modular_computer/console/preset/proc/install_programs()
|
||||
return
|
||||
|
||||
// ===== ENGINEERING CONSOLE =====
|
||||
/obj/machinery/modular_computer/console/preset/engineering
|
||||
console_department = "Engineering"
|
||||
desc = "A stationary computer. This one comes preloaded with engineering programs."
|
||||
|
||||
/obj/machinery/modular_computer/console/preset/engineering/install_programs()
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/power_monitor())
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/alarm_monitor())
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/atmos_control())
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/rcon_console())
|
||||
|
||||
|
||||
// ===== MEDICAL CONSOLE =====
|
||||
/obj/machinery/modular_computer/console/preset/medical
|
||||
console_department = "Medical"
|
||||
desc = "A stationary computer. This one comes preloaded with medical programs."
|
||||
|
||||
/obj/machinery/modular_computer/console/preset/medical/install_programs()
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/suit_sensors())
|
||||
|
||||
|
||||
// ===== RESEARCH CONSOLE =====
|
||||
/obj/machinery/modular_computer/console/preset/research
|
||||
console_department = "Research"
|
||||
desc = "A stationary computer. This one comes preloaded with research programs."
|
||||
|
||||
/obj/machinery/modular_computer/console/preset/research/install_programs()
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/ntnetmonitor())
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/nttransfer())
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/chatclient())
|
||||
|
||||
|
||||
// ===== COMMAND CONSOLE =====
|
||||
/obj/machinery/modular_computer/console/preset/command
|
||||
console_department = "Command"
|
||||
desc = "A stationary computer. This one comes preloaded with command programs."
|
||||
_has_id_slot = 1
|
||||
_has_printer = 1
|
||||
|
||||
/obj/machinery/modular_computer/console/preset/command/install_programs()
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/chatclient())
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/card_mod())
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/comm())
|
||||
|
||||
/obj/machinery/modular_computer/console/preset/command/main
|
||||
console_department = "Command"
|
||||
desc = "A stationary computer. This one comes preloaded with essential command programs."
|
||||
_has_id_slot = 1
|
||||
_has_printer = 1
|
||||
|
||||
// ===== SECURITY CONSOLE =====
|
||||
/obj/machinery/modular_computer/console/preset/security
|
||||
console_department = "Security"
|
||||
desc = "A stationary computer. This one comes preloaded with security programs."
|
||||
|
||||
/obj/machinery/modular_computer/console/preset/security/install_programs()
|
||||
return // No security programs exist, yet, but the preset is ready so it may be mapped in.
|
||||
|
||||
|
||||
// ===== CIVILIAN CONSOLE =====
|
||||
/obj/machinery/modular_computer/console/preset/civilian
|
||||
console_department = "Civilian"
|
||||
desc = "A stationary computer. This one comes preloaded with generic programs."
|
||||
|
||||
/obj/machinery/modular_computer/console/preset/civilian/install_programs()
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/chatclient())
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/nttransfer())
|
||||
cpu.hard_drive.store_file(new/datum/computer_file/program/newsbrowser())
|
||||
@@ -0,0 +1,196 @@
|
||||
// Global var to track modular computers
|
||||
var/list/global_modular_computers = list()
|
||||
|
||||
// Modular Computer - device that runs various programs and operates with hardware
|
||||
// DO NOT SPAWN THIS TYPE. Use /laptop/ or /console/ instead.
|
||||
/obj/machinery/modular_computer/
|
||||
name = "modular computer"
|
||||
desc = "An advanced computer."
|
||||
|
||||
var/battery_powered = 0 // Whether computer should be battery powered. It is set automatically
|
||||
use_power = 0
|
||||
var/hardware_flag = 0 // A flag that describes this device type
|
||||
var/last_power_usage = 0 // Power usage during last tick
|
||||
|
||||
// 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
|
||||
// If you create a program which is limited to Laptops and Consoles you don't have to add it's icon_state overlay for Tablets too, for example.
|
||||
|
||||
icon = null
|
||||
icon_state = null
|
||||
var/icon_state_unpowered = null // Icon state when the computer is turned off
|
||||
var/screen_icon_state_menu = "menu" // Icon state overlay when the computer is turned on, but no program is loaded that would override the screen.
|
||||
var/screen_icon_screensaver = "standby" // Icon state overlay when the computer is powered, but not 'switched on'.
|
||||
var/max_hardware_size = 0 // Maximal hardware size. Currently, tablets have 1, laptops 2 and consoles 3. Limits what hardware types can be installed.
|
||||
var/steel_sheet_cost = 10 // Amount of steel sheets refunded when disassembling an empty frame of this computer.
|
||||
var/light_strength = 0 // Light luminosity when turned on
|
||||
var/base_active_power_usage = 100 // Power usage when the computer is open (screen is active) and can be interacted with. Remember hardware can use power too.
|
||||
var/base_idle_power_usage = 10 // Power usage when the computer is idle and screen is off (currently only applies to laptops)
|
||||
|
||||
var/_max_damage = 100
|
||||
var/_break_damage = 50
|
||||
|
||||
var/obj/item/weapon/computer_hardware/tesla_link/tesla_link // Tesla Link component of this computer. Allows remote charging from nearest APC.
|
||||
|
||||
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/attack_ghost(var/mob/observer/ghost/user)
|
||||
if(cpu)
|
||||
cpu.attack_ghost(user)
|
||||
|
||||
/obj/machinery/modular_computer/emag_act(var/remaining_charges, var/mob/user)
|
||||
return cpu ? cpu.emag_act(remaining_charges, user) : NO_EMAG_ACT
|
||||
|
||||
/obj/machinery/modular_computer/update_icon()
|
||||
icon_state = icon_state_unpowered
|
||||
overlays.Cut()
|
||||
|
||||
if(!cpu || !cpu.enabled)
|
||||
if (!(stat & NOPOWER) || battery_powered)
|
||||
overlays.Add(screen_icon_screensaver)
|
||||
set_light(0)
|
||||
return
|
||||
set_light(light_strength)
|
||||
if(cpu.active_program)
|
||||
overlays.Add(cpu.active_program.program_icon_state ? cpu.active_program.program_icon_state : screen_icon_state_menu)
|
||||
else
|
||||
overlays.Add(screen_icon_state_menu)
|
||||
|
||||
// Eject ID card from computer, if it has ID slot with card inside.
|
||||
/obj/machinery/modular_computer/verb/eject_id()
|
||||
set name = "Eject ID"
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(cpu)
|
||||
cpu.eject_id()
|
||||
|
||||
// Eject ID card from computer, if it has ID slot with card inside.
|
||||
/obj/machinery/modular_computer/verb/eject_usb()
|
||||
set name = "Eject Portable Device"
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(cpu)
|
||||
cpu.eject_usb()
|
||||
|
||||
/obj/machinery/modular_computer/New()
|
||||
..()
|
||||
cpu = new(src)
|
||||
global_modular_computers.Add(src)
|
||||
|
||||
/obj/machinery/modular_computer/Destroy()
|
||||
if(cpu)
|
||||
qdel(cpu)
|
||||
cpu = null
|
||||
return ..()
|
||||
|
||||
// On-click handling. Turns on the computer if it's off and opens the GUI.
|
||||
/obj/machinery/modular_computer/attack_hand(mob/user)
|
||||
if(cpu)
|
||||
cpu.attack_self(user) // CPU is an item, that's why we route attack_hand to attack_self
|
||||
|
||||
/obj/machinery/modular_computer/examine(var/mob/user)
|
||||
. = ..()
|
||||
if(cpu)
|
||||
cpu.examine(user)
|
||||
|
||||
// Process currently calls handle_power(), may be expanded in future if more things are added.
|
||||
/obj/machinery/modular_computer/process()
|
||||
if(cpu)
|
||||
// Keep names in sync.
|
||||
cpu.name = src.name
|
||||
cpu.process(1)
|
||||
|
||||
// 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/N)
|
||||
if(tesla_link && (tesla_link.name == N))
|
||||
return tesla_link
|
||||
return null
|
||||
|
||||
// Used in following function to reduce copypaste
|
||||
/obj/machinery/modular_computer/proc/power_failure(var/malfunction = 0)
|
||||
if(cpu && cpu.enabled) // Shut down the computer
|
||||
visible_message("<span class='danger'>\The [src]'s screen flickers [cpu.battery_module ? "\"BATTERY [malfunction ? "MALFUNCTION" : "CRITICAL"]\"" : "\"EXTERNAL POWER LOSS\""] warning as it shuts down unexpectedly.</span>")
|
||||
if(cpu)
|
||||
cpu.shutdown_computer(0)
|
||||
battery_powered = 0
|
||||
stat |= NOPOWER
|
||||
update_icon()
|
||||
|
||||
// Called by cpu item's process() automatically, handles our power interaction.
|
||||
/obj/machinery/modular_computer/proc/handle_power()
|
||||
if(cpu.battery_module && cpu.battery_module.battery.charge <= 0) // Battery-run but battery is depleted.
|
||||
power_failure()
|
||||
return 0
|
||||
else if(!cpu.battery_module && (!powered() || !tesla_link || !tesla_link.enabled || !tesla_link.check_functionality())) // Not battery run, but lacking APC connection.
|
||||
power_failure()
|
||||
return 0
|
||||
else if(stat & NOPOWER)
|
||||
stat &= ~NOPOWER
|
||||
|
||||
if(cpu.battery_module && cpu.battery_module.battery.charge)
|
||||
battery_powered = 1
|
||||
else
|
||||
battery_powered = 0
|
||||
|
||||
var/power_usage = cpu.screen_on ? base_active_power_usage : base_idle_power_usage
|
||||
for(var/obj/item/weapon/computer_hardware/CH in src.cpu.get_all_components())
|
||||
if(CH.enabled)
|
||||
power_usage += CH.power_usage
|
||||
|
||||
// Wireless APC connection exists.
|
||||
if(tesla_link && tesla_link.enabled && tesla_link.check_functionality())
|
||||
idle_power_usage = power_usage
|
||||
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(cpu.battery_module && (cpu.battery_module.battery.charge < cpu.battery_module.battery.maxcharge))
|
||||
use_power = 2
|
||||
|
||||
if(cpu.battery_module && powered() && (use_power == 2)) // Battery charging itself
|
||||
cpu.battery_module.battery.give(100 * CELLRATE)
|
||||
else if(cpu.battery_module && !powered()) // Unpowered, but battery covers the usage.
|
||||
cpu.battery_module.battery.use(idle_power_usage * CELLRATE)
|
||||
|
||||
else // No wireless connection run only on battery.
|
||||
use_power = 0
|
||||
if (cpu.battery_module)
|
||||
if(!cpu.battery_module.check_functionality())
|
||||
power_failure(1)
|
||||
return
|
||||
cpu.battery_module.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()
|
||||
if(battery_powered)
|
||||
return
|
||||
..()
|
||||
|
||||
/obj/machinery/modular_computer/attackby(var/obj/item/weapon/W as obj, var/mob/user as mob)
|
||||
if(cpu)
|
||||
return cpu.attackby(W, user)
|
||||
return ..()
|
||||
|
||||
|
||||
// Stronger explosions cause serious damage to internal components
|
||||
// Minor explosions are mostly mitigitated by casing.
|
||||
/obj/machinery/modular_computer/ex_act(var/severity)
|
||||
if(cpu)
|
||||
cpu.ex_act(severity)
|
||||
|
||||
// EMPs are similar to explosions, but don't cause physical damage to the casing. Instead they screw up the components
|
||||
/obj/machinery/modular_computer/emp_act(var/severity)
|
||||
if(cpu)
|
||||
cpu.emp_act(severity)
|
||||
|
||||
// "Stun" weapons can cause minor damage to components (short-circuits?)
|
||||
// "Burn" damage is equally strong against internal components and exterior casing
|
||||
// "Brute" damage mostly damages the casing.
|
||||
/obj/machinery/modular_computer/bullet_act(var/obj/item/projectile/Proj)
|
||||
if(cpu)
|
||||
cpu.bullet_act(Proj)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/obj/machinery/modular_computer/console/
|
||||
name = "console"
|
||||
desc = "A stationary computer."
|
||||
|
||||
icon = 'icons/obj/modular_console.dmi'
|
||||
icon_state = "console"
|
||||
icon_state_unpowered = "console"
|
||||
screen_icon_state_menu = "menu"
|
||||
hardware_flag = PROGRAM_CONSOLE
|
||||
var/console_department = "" // Used in New() to set network tag according to our area.
|
||||
anchored = 1
|
||||
density = 1
|
||||
base_idle_power_usage = 100
|
||||
base_active_power_usage = 500
|
||||
max_hardware_size = 3
|
||||
steel_sheet_cost = 20
|
||||
light_strength = 4
|
||||
_max_damage = 300
|
||||
_break_damage = 150
|
||||
|
||||
/obj/machinery/modular_computer/console/buildable/New()
|
||||
..()
|
||||
// User-built consoles start as empty frames.
|
||||
qdel(tesla_link)
|
||||
qdel(cpu.network_card)
|
||||
qdel(cpu.hard_drive)
|
||||
|
||||
/obj/machinery/modular_computer/console/New()
|
||||
..()
|
||||
cpu.battery_module = null
|
||||
cpu.network_card = new/obj/item/weapon/computer_hardware/network_card/wired(src)
|
||||
tesla_link = new/obj/item/weapon/computer_hardware/tesla_link(src)
|
||||
cpu.hard_drive = new/obj/item/weapon/computer_hardware/hard_drive/super(src) // Consoles generally have better HDDs due to lower space limitations
|
||||
var/area/A = get_area(src)
|
||||
// Attempts to set this console's tag according to our area. Since some areas have stuff like "XX - YY" in their names we try to remove that too.
|
||||
if(A && console_department)
|
||||
cpu.network_card.identification_string = replacetext(replacetext(replacetext("[A.name] [console_department] Console", " ", "_"), "-", ""), "__", "_") // Replace spaces with "_"
|
||||
else if(A)
|
||||
cpu.network_card.identification_string = replacetext(replacetext(replacetext("[A.name] Console", " ", "_"), "-", ""), "__", "_")
|
||||
else if(console_department)
|
||||
cpu.network_card.identification_string = replacetext(replacetext(replacetext("[console_department] Console", " ", "_"), "-", ""), "__", "_")
|
||||
else
|
||||
cpu.network_card.identification_string = "Unknown Console"
|
||||
if(cpu)
|
||||
cpu.screen_on = 1
|
||||
update_icon()
|
||||
@@ -0,0 +1,110 @@
|
||||
// Laptop in it's item state, can be carried around.
|
||||
|
||||
/obj/item/laptop
|
||||
name = "laptop computer"
|
||||
desc = "A portable computer. It is closed."
|
||||
icon = 'icons/obj/modular_laptop.dmi'
|
||||
icon_state = "laptop-closed"
|
||||
item_state = "laptop-inhand"
|
||||
w_class = 3
|
||||
var/obj/machinery/modular_computer/laptop/stored_computer = null
|
||||
|
||||
/obj/item/laptop/verb/open_computer()
|
||||
set name = "Open Laptop"
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(usr.stat || usr.restrained() || usr.lying || !istype(usr, /mob/living))
|
||||
usr << "<span class='warning'>You can't do that.</span>"
|
||||
return
|
||||
|
||||
if(!Adjacent(usr))
|
||||
usr << "You can't reach it."
|
||||
return
|
||||
|
||||
if(!istype(loc,/turf))
|
||||
usr << "[src] is too bulky! You'll have to set it down."
|
||||
return
|
||||
|
||||
if(!stored_computer)
|
||||
if(contents.len)
|
||||
for(var/obj/O in contents)
|
||||
O.forceMove(src.loc)
|
||||
usr << "\The [src] crumbles to pieces."
|
||||
spawn(5)
|
||||
qdel(src)
|
||||
return
|
||||
|
||||
stored_computer.forceMove(src.loc)
|
||||
stored_computer.stat &= ~MAINT
|
||||
stored_computer.update_icon()
|
||||
if(stored_computer.cpu)
|
||||
stored_computer.cpu.screen_on = 1
|
||||
loc = stored_computer
|
||||
usr << "You open \the [src]."
|
||||
|
||||
|
||||
/obj/item/laptop/AltClick()
|
||||
if(Adjacent(usr))
|
||||
open_computer()
|
||||
|
||||
// The actual laptop
|
||||
/obj/machinery/modular_computer/laptop
|
||||
name = "laptop computer"
|
||||
desc = "A portable computer."
|
||||
var/obj/item/laptop/portable = null // Portable version of this computer, dropped on alt-click to allow transport. Used by laptops.
|
||||
hardware_flag = PROGRAM_LAPTOP
|
||||
icon_state_unpowered = "laptop-open" // Icon state when the computer is turned off
|
||||
icon = 'icons/obj/modular_laptop.dmi'
|
||||
icon_state = "laptop-open"
|
||||
base_idle_power_usage = 25
|
||||
base_active_power_usage = 200
|
||||
max_hardware_size = 2
|
||||
light_strength = 3
|
||||
_max_damage = 200
|
||||
_break_damage = 100
|
||||
|
||||
/obj/machinery/modular_computer/laptop/buildable/New()
|
||||
..()
|
||||
// User-built consoles start as empty frames.
|
||||
qdel(tesla_link)
|
||||
qdel(cpu.network_card)
|
||||
qdel(cpu.hard_drive)
|
||||
|
||||
// Close the computer. collapsing it into movable item that can't be used.
|
||||
/obj/machinery/modular_computer/laptop/verb/close_computer()
|
||||
set name = "Close Laptop"
|
||||
set category = "Object"
|
||||
set src in view(1)
|
||||
|
||||
if(usr.stat || usr.restrained() || usr.lying || !istype(usr, /mob/living))
|
||||
usr << "<span class='warning'>You can't do that.</span>"
|
||||
return
|
||||
|
||||
if(!Adjacent(usr))
|
||||
usr << "<span class='warning'>You can't reach it.</span>"
|
||||
return
|
||||
|
||||
close_laptop(usr)
|
||||
|
||||
/obj/machinery/modular_computer/laptop/proc/close_laptop(mob/user = null)
|
||||
if(istype(loc,/obj/item/laptop))
|
||||
return
|
||||
if(!istype(loc,/turf))
|
||||
return
|
||||
|
||||
if(!portable)
|
||||
portable=new
|
||||
portable.stored_computer = src
|
||||
|
||||
portable.forceMove(src.loc)
|
||||
src.forceMove(portable)
|
||||
stat |= MAINT
|
||||
if(user)
|
||||
user << "You close \the [src]."
|
||||
if(cpu)
|
||||
cpu.screen_on = 0
|
||||
|
||||
/obj/machinery/modular_computer/laptop/AltClick()
|
||||
if(Adjacent(usr))
|
||||
close_laptop()
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 818 B |
Reference in New Issue
Block a user