This commit is contained in:
davipatury
2017-02-19 21:54:46 -03:00
parent 2733b77b58
commit bfc130dafb
70 changed files with 4434 additions and 4 deletions

View File

@@ -0,0 +1,442 @@
// 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/device/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/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_powered = null // Icon state when the computer is turned on.
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 w_class. Tablets/PDAs have 1, laptops 2, consoles 4.
var/steel_sheet_cost = 5 // Amount of steel sheets refunded when disassembling an empty frame of this computer.
var/obj_integrity = 100
var/integrity_failure = 50
var/max_integrity = 100
armor = list(melee = 0, bullet = 20, laser = 20, energy = 100, bomb = 0, bio = 100, rad = 100, fire = 0, acid = 0)
// Important hardware (must be installed for computer to work)
// Optional hardware (improves functionality, but is not critical for computer to work)
var/list/all_components // List of "connection ports" in this computer and the components with which they are plugged
var/list/idle_threads // Idle programs on background. They still receive process calls but can't be interacted with.
var/obj/physical = null // Object that represents our computer. It's used for Adjacent() and UI visibility checks.
/obj/item/device/modular_computer/New()
update_icon()
if(!physical)
physical = src
..()
processing_objects += src
all_components = list()
idle_threads = list()
/obj/item/device/modular_computer/Destroy()
kill_program(forced = TRUE)
for(var/H in all_components)
var/obj/item/weapon/computer_hardware/CH = all_components[H]
if(CH.holder == src)
CH.on_remove(src)
CH.holder = null
all_components.Remove(CH.device_type)
qdel(CH)
physical = null
processing_objects -= src
return ..()
/obj/item/device/modular_computer/proc/add_verb(var/path)
switch(path)
if(MC_CARD)
verbs += /obj/item/device/modular_computer/proc/eject_id
if(MC_SDD)
verbs += /obj/item/device/modular_computer/proc/eject_disk
if(MC_AI)
verbs += /obj/item/device/modular_computer/proc/eject_card
/obj/item/device/modular_computer/proc/remove_verb(path)
switch(path)
if(MC_CARD)
verbs -= /obj/item/device/modular_computer/proc/eject_id
if(MC_SDD)
verbs -= /obj/item/device/modular_computer/proc/eject_disk
if(MC_AI)
verbs -= /obj/item/device/modular_computer/proc/eject_card
// Eject ID card from computer, if it has ID slot with card inside.
/obj/item/device/modular_computer/proc/eject_id()
set name = "Eject ID"
set category = "Object"
set src in view(1)
if(issilicon(usr))
return
var/obj/item/weapon/computer_hardware/card_slot/card_slot = all_components[MC_CARD]
if(!usr.incapacitated())
card_slot.try_eject(null, usr)
// Eject ID card from computer, if it has ID slot with card inside.
/obj/item/device/modular_computer/proc/eject_card()
set name = "Eject Intellicard"
set category = "Object"
set src in view(1)
if(issilicon(usr))
return
var/obj/item/weapon/computer_hardware/ai_slot/ai_slot = all_components[MC_AI]
if(!usr.incapacitated())
ai_slot.try_eject(null, usr, 1)
// Eject ID card from computer, if it has ID slot with card inside.
/obj/item/device/modular_computer/proc/eject_disk()
set name = "Eject Data Disk"
set category = "Object"
set src in view(1)
if(issilicon(usr))
return
if(!usr.incapacitated())
var/obj/item/weapon/computer_hardware/hard_drive/portable/portable_drive = all_components[MC_SDD]
if(uninstall_component(portable_drive, usr))
portable_drive.verb_pickup()
/obj/item/device/modular_computer/AltClick(mob/user)
..()
if(issilicon(user))
return
if(!user.incapacitated() && Adjacent(user))
var/obj/item/weapon/computer_hardware/card_slot/card_slot = all_components[MC_CARD]
var/obj/item/weapon/computer_hardware/ai_slot/ai_slot = all_components[MC_AI]
var/obj/item/weapon/computer_hardware/hard_drive/portable/portable_drive = all_components[MC_SDD]
if(portable_drive)
if(uninstall_component(portable_drive, user))
portable_drive.verb_pickup()
else
if(card_slot && card_slot.try_eject(null, user))
return
if(ai_slot)
ai_slot.try_eject(null, user)
// Gets IDs/access levels from card slot. Would be useful when/if PDAs would become modular PCs.
/obj/item/device/modular_computer/GetAccess()
var/obj/item/weapon/computer_hardware/card_slot/card_slot = all_components[MC_CARD]
if(card_slot)
return card_slot.GetAccess()
return ..()
/obj/item/device/modular_computer/GetID()
var/obj/item/weapon/computer_hardware/card_slot/card_slot = all_components[MC_CARD]
if(card_slot)
return card_slot.GetID()
return ..()
/obj/item/device/modular_computer/attack_ai(mob/user)
return attack_self(user)
/obj/item/device/modular_computer/attack_ghost(mob/dead/observer/user)
if(enabled)
ui_interact(user)
else if(user.can_admin_interact())
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/device/modular_computer/emag_act(mob/user)
if(emagged)
to_chat(user, "<span class='warning'>\The [src] was already emagged.</span>")
return 0
else
emagged = 1
to_chat(user, "<span class='notice'>You emag \the [src]. It's screen briefly shows a \"OVERRIDE ACCEPTED: New software downloads available.\" message.</span>")
return 1
/obj/item/device/modular_computer/examine(mob/user)
..()
if(obj_integrity <= integrity_failure)
to_chat(user, "<span class='danger'>It is heavily damaged!</span>")
else if(obj_integrity < max_integrity)
to_chat(user, "<span class='warning'>It is damaged.</span>")
/obj/item/device/modular_computer/update_icon()
overlays.Cut()
if(!enabled)
icon_state = icon_state_unpowered
else
icon_state = icon_state_powered
if(active_program)
overlays += active_program.program_icon_state ? active_program.program_icon_state : icon_state_menu
else
overlays += icon_state_menu
if(obj_integrity <= integrity_failure)
overlays += "bsod"
overlays += "broken"
// On-click handling. Turns on the computer if it's off and opens the GUI.
/obj/item/device/modular_computer/attack_self(mob/user)
if(enabled)
ui_interact(user)
else
turn_on(user)
/obj/item/device/modular_computer/proc/turn_on(mob/user)
var/issynth = issilicon(user) // Robots and AIs get different activation messages.
if(obj_integrity <= integrity_failure)
if(issynth)
to_chat(user, "<span class='warning'>You send an activation signal to \the [src], but it responds with an error code. It must be damaged.</span>")
else
to_chat(user, "<span class='warning'>You press the power button, but the computer fails to boot up, displaying variety of errors before shutting down again.</span>")
return
// If we have a recharger, enable it automatically. Lets computer without a battery work.
var/obj/item/weapon/computer_hardware/recharger/recharger = all_components[MC_CHARGE]
if(recharger)
recharger.enabled = 1
if(all_components[MC_CPU] && use_power()) // use_power() checks if the PC is powered
if(issynth)
to_chat(user, "<span class='notice'>You send an activation signal to \the [src], turning it on.</span>")
else
to_chat(user, "<span class='notice'>You press the power button and start up \the [src].</span>")
enabled = 1
update_icon()
ui_interact(user)
else // Unpowered
if(issynth)
to_chat(user, "<span class='warning'>You send an activation signal to \the [src] but it does not respond.</span>")
else
to_chat(user, "<span class='warning'>You press the power button but \the [src] does not respond.</span>")
// Process currently calls handle_power(), may be expanded in future if more things are added.
/obj/item/device/modular_computer/process()
if(!enabled) // The computer is turned off
last_power_usage = 0
return 0
if(obj_integrity <= integrity_failure)
shutdown_computer()
return 0
if(active_program && active_program.requires_ntnet && !get_ntnet_status(active_program.requires_ntnet_feature))
active_program.event_networkfailure(0) // Active program requires NTNet to run but we've just lost connection. Crash.
for(var/I in idle_threads)
var/datum/computer_file/program/P = I
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()
else
active_program = null
for(var/I in idle_threads)
var/datum/computer_file/program/P = I
if(P.program_state != PROGRAM_STATE_KILLED)
P.process_tick()
P.ntnet_status = get_ntnet_status()
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/device/modular_computer/proc/get_header_data()
var/list/data = list()
var/obj/item/weapon/computer_hardware/battery/battery_module = all_components[MC_CELL]
var/obj/item/weapon/computer_hardware/recharger/recharger = all_components[MC_CHARGE]
if(battery_module && battery_module.battery)
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
if(recharger && recharger.enabled && recharger.check_functionality() && recharger.use_power(0))
data["PC_apclinkicon"] = "charging.gif"
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/I in idle_threads)
var/datum/computer_file/program/P = I
if(!P.ui_header)
continue
program_headers.Add(list(list(
"icon" = P.ui_header
)))
data["PC_programheaders"] = program_headers
data["PC_stationtime"] = worldtime2text()
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/device/modular_computer/proc/kill_program(forced = FALSE)
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/device/modular_computer/proc/get_ntnet_status(specific_action = 0)
var/obj/item/weapon/computer_hardware/network_card/network_card = all_components[MC_NET]
if(network_card)
return network_card.get_signal(specific_action)
else
return 0
/obj/item/device/modular_computer/proc/add_log(text)
if(!get_ntnet_status())
return FALSE
var/obj/item/weapon/computer_hardware/network_card/network_card = all_components[MC_NET]
return ntnet_global.add_log(text, network_card)
/obj/item/device/modular_computer/proc/shutdown_computer(loud = 1)
kill_program(forced = TRUE)
for(var/datum/computer_file/program/P in idle_threads)
P.kill_program(forced = TRUE)
idle_threads.Remove(P)
if(loud)
physical.visible_message("<span class='notice'>\The [src] shuts down.</span>")
enabled = 0
update_icon()
/obj/item/device/modular_computer/attackby(obj/item/weapon/W as obj, mob/user as mob)
// Insert items into the components
for(var/h in all_components)
var/obj/item/weapon/computer_hardware/H = all_components[h]
if(H.try_insert(W, user))
return
// Insert new hardware
if(istype(W, /obj/item/weapon/computer_hardware))
if(install_component(W, user))
return
if(istype(W, /obj/item/weapon/wrench))
if(all_components.len)
to_chat(user, "<span class='warning'>Remove all components from \the [src] before disassembling it.</span>")
return
new /obj/item/stack/sheet/metal( get_turf(src.loc), steel_sheet_cost )
physical.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())
to_chat(user, "<span class='warning'>\The [W] is off.</span>")
return
if(obj_integrity == max_integrity)
to_chat(user, "<span class='warning'>\The [src] does not require repairs.</span>")
return
to_chat(user, "<span class='notice'>You begin repairing damage to \the [src]...</span>")
var/dmg = round(max_integrity - obj_integrity)
if(WT.remove_fuel(round(dmg/75)) && do_after(usr, dmg/10))
obj_integrity = max_integrity
to_chat(user, "<span class='notice'>You repair \the [src].</span>")
return
if(istype(W, /obj/item/weapon/screwdriver))
if(!all_components.len)
to_chat(user, "<span class='warning'>This device doesn't have any components installed.</span>")
return
var/list/component_names = list()
for(var/h in all_components)
var/obj/item/weapon/computer_hardware/H = all_components[h]
component_names.Add(H.name)
var/choice = input(user, "Which component do you want to uninstall?", "Computer maintenance", null) as null|anything in component_names
if(!choice)
return
if(!Adjacent(user))
return
var/obj/item/weapon/computer_hardware/H = find_hardware_by_name(choice)
if(!H)
return
uninstall_component(H, user)
return
..()
// Used by processor to relay qdel() to machinery type.
/obj/item/device/modular_computer/proc/relay_qdel()
return
// Perform adjacency checks on our physical counterpart, if any.
/obj/item/device/modular_computer/Adjacent(atom/neighbor)
if(physical && physical != src)
return physical.Adjacent(neighbor)
return ..()

View File

@@ -0,0 +1,54 @@
/obj/item/device/modular_computer/proc/can_install_component(obj/item/weapon/computer_hardware/H, mob/living/user = null)
if(!H.can_install(src, user))
return FALSE
if(H.w_class > max_hardware_size)
user << "<span class='warning'>This component is too large for \the [src]!</span>"
return FALSE
if(all_components[H.device_type])
user << "<span class='warning'>This computer's hardware slot is already occupied by \the [all_components[H.device_type]].</span>"
return FALSE
return TRUE
// Installs component.
/obj/item/device/modular_computer/proc/install_component(obj/item/weapon/computer_hardware/H, mob/living/user = null)
if(!can_install_component(H, user))
return FALSE
if(user && !user.unEquip(H))
return FALSE
H.forceMove(src)
all_components[H.device_type] = H
user << "<span class='notice'>You install \the [H] into \the [src].</span>"
H.holder = src
H.on_install(src, user)
// Uninstalls component.
/obj/item/device/modular_computer/proc/uninstall_component(obj/item/weapon/computer_hardware/H, mob/living/user = null)
if(H.holder != src) // Not our component at all.
return FALSE
all_components.Remove(H.device_type)
user << "<span class='notice'>You remove \the [H] from \the [src].</span>"
H.forceMove(get_turf(src))
H.holder = null
H.on_remove(src, user)
if(enabled && !use_power())
shutdown_computer()
update_icon()
// Checks all hardware pieces to determine if name matches, if yes, returns the hardware piece, otherwise returns null
/obj/item/device/modular_computer/proc/find_hardware_by_name(name)
for(var/i in all_components)
var/obj/O = all_components[i]
if(O.name == name)
return O
return null

View File

@@ -0,0 +1,52 @@
/obj/item/device/modular_computer/emp_act(severity)
if(prob(20 / severity))
take_damage(obj_integrity, BURN)
..()
/obj/item/device/modular_computer/ex_act(severity)
switch(severity)
if(1)
qdel(src)
if(2)
if(prob(25))
qdel(src)
else if(prob(50))
obj_integrity = 0
if(3)
if(prob(25))
obj_integrity = 0
/obj/item/device/modular_computer/bullet_act(obj/item/projectile/P)
take_damage(P.damage, P.damage_type)
..()
/obj/item/device/modular_computer/blob_act()
if(prob(75))
take_damage(obj_integrity, BRUTE)
/obj/item/device/modular_computer/proc/take_damage(damage_amount, damage_type = BRUTE, damage_flag = 0, sound_effect = 1)
. = ..()
var/component_probability = min(50, max(damage_amount*0.1, 1 - obj_integrity/max_integrity))
switch(damage_flag)
if("bullet")
component_probability = damage_amount * 0.5
if("laser")
component_probability = damage_amount * 0.66
if(component_probability)
for(var/I in all_components)
var/obj/item/weapon/computer_hardware/H = all_components[I]
if(prob(component_probability))
H.take_damage(round(damage_amount*0.5))
/obj/item/device/modular_computer/proc/break_apart(damage = TRUE)
physical.visible_message("\The [src] breaks apart!")
var/turf/newloc = get_turf(src)
new /obj/item/stack/sheet/metal(newloc, round(steel_sheet_cost/2))
for(var/C in all_components)
var/obj/item/weapon/computer_hardware/H = all_components[C]
uninstall_component(H)
H.forceMove(newloc)
if(damage && prob(25))
H.take_damage(rand(10, 30))
relay_qdel()
qdel(src)

View File

@@ -0,0 +1,61 @@
// Tries to draw power from charger or, if no operational charger is present, from power cell.
/obj/item/device/modular_computer/proc/use_power(amount = 0)
if(check_power_override())
return TRUE
var/obj/item/weapon/computer_hardware/recharger/recharger = all_components[MC_CHARGE]
if(recharger && recharger.check_functionality())
if(recharger.use_power(amount))
return TRUE
var/obj/item/weapon/computer_hardware/battery/battery_module = all_components[MC_CELL]
if(battery_module && battery_module.battery && battery_module.battery.charge)
var/obj/item/weapon/stock_parts/cell/cell = battery_module.battery
if(cell.use(amount * CELLRATE))
return TRUE
else // Discharge the cell anyway.
cell.use(min(amount*CELLRATE, cell.charge))
return FALSE
return FALSE
/obj/item/device/modular_computer/proc/give_power(amount)
var/obj/item/weapon/computer_hardware/battery/battery_module = all_components[MC_CELL]
if(battery_module && battery_module.battery)
return battery_module.battery.give(amount)
return 0
// Used in following function to reduce copypaste
/obj/item/device/modular_computer/proc/power_failure()
if(enabled) // Shut down the computer
if(active_program)
active_program.event_powerfailure(0)
for(var/I in idle_threads)
var/datum/computer_file/program/PRG = I
PRG.event_powerfailure(1)
shutdown_computer(0)
// Handles power-related things, such as battery interaction, recharging, shutdown when it's discharged
/obj/item/device/modular_computer/proc/handle_power()
var/obj/item/weapon/computer_hardware/recharger/recharger = all_components[MC_CHARGE]
if(recharger)
recharger.process()
var/power_usage = screen_on ? base_active_power_usage : base_idle_power_usage
for(var/obj/item/weapon/computer_hardware/H in all_components)
if(H.enabled)
power_usage += H.power_usage
if(use_power(power_usage))
last_power_usage = power_usage
return TRUE
else
power_failure()
return FALSE
// Used by child types if they have other power source than battery or recharger
/obj/item/device/modular_computer/proc/check_power_override()
return FALSE

View File

@@ -0,0 +1,136 @@
// Operates NanoUI
/obj/item/device/modular_computer/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
if(!enabled)
if(ui)
ui.close()
return 0
if(!use_power())
if(ui)
ui.close()
return 0
// Robots don't really need to see the screen, their wireless connection works as long as computer is on.
if(!screen_on && !issilicon(user))
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.
var/obj/item/weapon/computer_hardware/hard_drive/hard_drive = all_components[MC_HDD]
if(!hard_drive || !hard_drive.stored_files || !hard_drive.stored_files.len)
to_chat(user, "<span class='danger'>\The [src] beeps three times, it's screen displaying a \"DISK ERROR\" warning.</span>")
return // No HDD, No HDD files list or no stored files. Something is very broken.
ui = nanomanager.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
var/datum/asset/assets = get_asset_datum(/datum/asset/simple/headers)
assets.send(user)
ui = new(user, src, ui_key, "computer_main.tmpl", "NTOS Main menu", 400, 500)
ui.set_auto_update(1)
ui.open()
/obj/item/device/modular_computer/ui_data(mob/user)
var/list/data = get_header_data()
data["programs"] = list()
var/obj/item/weapon/computer_hardware/hard_drive/hard_drive = all_components[MC_HDD]
for(var/datum/computer_file/program/P in hard_drive.stored_files)
var/running = 0
if(P in idle_threads)
running = 1
data["programs"] += list(list("name" = P.filename, "desc" = P.filedesc, "running" = running))
return data
// Handles user's GUI input
/obj/item/device/modular_computer/Topic(href, list/href_list)
if(..())
return
var/obj/item/weapon/computer_hardware/hard_drive/hard_drive = all_components[MC_HDD]
switch(href_list["action"])
if("PC_exit")
kill_program()
return 1
if("PC_shutdown")
shutdown_computer()
return 1
if("PC_minimize")
var/mob/user = usr
if(!active_program || !all_components[MC_CPU])
return
idle_threads.Add(active_program)
active_program.program_state = PROGRAM_STATE_BACKGROUND // Should close any existing UIs
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("PC_killprogram")
var/prog = href_list["name"]
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(forced = TRUE)
user << "<span class='notice'>Program [P.filename].[P.filetype] with PID [rand(100,999)] has been killed.</span>"
if("PC_runprogram")
var/prog = href_list["name"]
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
var/obj/item/weapon/computer_hardware/processor_unit/PU = all_components[MC_CPU]
if(idle_threads.len > PU.max_idle_programs)
user << "<span class='danger'>\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 \"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
else
return
/obj/item/device/modular_computer/nano_host()
if(physical)
return physical
return src

View File

@@ -0,0 +1,107 @@
/obj/item/device/modular_computer/laptop
name = "laptop"
desc = "A portable laptop computer."
icon = 'icons/obj/modular_laptop.dmi'
icon_state = "laptop-closed"
icon_state_powered = "laptop"
icon_state_unpowered = "laptop-off"
icon_state_menu = "menu"
hardware_flag = PROGRAM_LAPTOP
max_hardware_size = 2
w_class = WEIGHT_CLASS_NORMAL
flags = HANDSLOW // No running around with open laptops in hands.
screen_on = 0 // Starts closed
var/start_open = 1 // unless this var is set to 1
var/icon_state_closed = "laptop-closed"
var/w_class_open = WEIGHT_CLASS_BULKY
var/slowdown_open = 1
/obj/item/device/modular_computer/laptop/New()
..()
if(start_open && !screen_on)
toggle_open()
/obj/item/device/modular_computer/laptop/update_icon()
if(screen_on)
..()
else
overlays.Cut()
icon_state = icon_state_closed
/obj/item/device/modular_computer/laptop/attack_self(mob/user)
if(!screen_on)
try_toggle_open(user)
else
return ..()
/obj/item/device/modular_computer/laptop/verb/open_computer()
set name = "Toggle Open"
set category = "Object"
set src in view(1)
try_toggle_open(usr)
/obj/item/device/modular_computer/laptop/MouseDrop(obj/over_object, src_location, over_location)
if(over_object == usr || over_object == src)
try_toggle_open(usr)
if(ishuman(usr))
if(!isturf(loc) || !Adjacent(usr))
return
if(over_object && !usr.incapacitated())
if(!usr.canUnEquip(src))
to_chat(usr, "[src] appears stuck on you!")
return
switch(over_object.name)
if("r_hand")
usr.unEquip(src)
usr.put_in_r_hand(src)
if("l_hand")
usr.unEquip(src)
usr.put_in_l_hand(src)
/obj/item/device/modular_computer/laptop/attack_hand(mob/user)
if(screen_on && isturf(loc))
return attack_self(user)
return ..()
/obj/item/device/modular_computer/laptop/proc/try_toggle_open(mob/living/user)
if(issilicon(user))
return
if(!isturf(loc) && !ismob(loc)) // No opening it in backpack.
return
if(user.incapacitated() || !Adjacent(user))
return
toggle_open(user)
/obj/item/device/modular_computer/laptop/AltClick(mob/user)
if(screen_on) // Close it.
try_toggle_open(user)
else
return ..()
/obj/item/device/modular_computer/laptop/proc/toggle_open(mob/living/user=null)
if(screen_on)
user << "<span class='notice'>You close \the [src].</span>"
slowdown = initial(slowdown)
w_class = initial(w_class)
else
user << "<span class='notice'>You open \the [src].</span>"
slowdown = slowdown_open
w_class = w_class_open
screen_on = !screen_on
update_icon()
// Laptop frame, starts empty and closed.
/obj/item/device/modular_computer/laptop/buildable
start_open = 0

View File

@@ -0,0 +1,21 @@
/obj/item/device/modular_computer/laptop/preset/New()
. = ..()
install_component(new /obj/item/weapon/computer_hardware/processor_unit/small)
install_component(new /obj/item/weapon/computer_hardware/battery(src, /obj/item/weapon/stock_parts/cell/computer))
install_component(new /obj/item/weapon/computer_hardware/hard_drive)
install_component(new /obj/item/weapon/computer_hardware/network_card)
install_programs()
/obj/item/device/modular_computer/laptop/preset/proc/install_programs()
return
/obj/item/device/modular_computer/laptop/preset/civillian
desc = "A low-end laptop often used for personal recreation."
/obj/item/device/modular_computer/laptop/preset/civillian/install_programs()
var/obj/item/weapon/computer_hardware/hard_drive/hard_drive = all_components[MC_HDD]
hard_drive.store_file(new/datum/computer_file/program/chatclient())
hard_drive.store_file(new/datum/computer_file/program/nttransfer())

View File

@@ -0,0 +1,74 @@
// Held by /obj/machinery/modular_computer to reduce amount of copy-pasted code.
/obj/item/device/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/device/modular_computer/processor/Destroy()
. = ..()
if(machinery_computer && (machinery_computer.cpu == src))
machinery_computer.cpu = null
machinery_computer = null
/obj/item/device/modular_computer/processor/New(comp)
if(!comp || !istype(comp, /obj/machinery/modular_computer))
CRASH("Inapropriate type passed to obj/item/device/modular_computer/processor/New()! Aborting.")
return
// Obtain reference to machinery computer
all_components = list()
idle_threads = list()
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
obj_integrity = machinery_computer.obj_integrity
max_integrity = machinery_computer.max_integrity
integrity_failure = machinery_computer.integrity_failure
base_active_power_usage = machinery_computer.base_active_power_usage
base_idle_power_usage = machinery_computer.base_idle_power_usage
/obj/item/device/modular_computer/processor/relay_qdel()
qdel(machinery_computer)
/obj/item/device/modular_computer/processor/update_icon()
if(machinery_computer)
return machinery_computer.update_icon()
// This thing is not meant to be used on it's own, get topic data from our machinery owner.
//obj/item/device/modular_computer/processor/canUseTopic(user, state)
// if(!machinery_computer)
// return 0
// return machinery_computer.canUseTopic(user, state)
/obj/item/device/modular_computer/processor/shutdown_computer()
if(!machinery_computer)
return
..()
machinery_computer.update_icon()
return
/obj/item/device/modular_computer/processor/add_verb(path)
switch(path)
if(MC_CARD)
machinery_computer.verbs += /obj/machinery/modular_computer/proc/eject_id
if(MC_SDD)
machinery_computer.verbs += /obj/machinery/modular_computer/proc/eject_disk
if(MC_AI)
machinery_computer.verbs += /obj/machinery/modular_computer/proc/eject_card
/obj/item/device/modular_computer/processor/remove_verb(path)
switch(path)
if(MC_CARD)
machinery_computer.verbs -= /obj/machinery/modular_computer/proc/eject_id
if(MC_SDD)
machinery_computer.verbs -= /obj/machinery/modular_computer/proc/eject_disk
if(MC_AI)
machinery_computer.verbs -= /obj/machinery/modular_computer/proc/eject_card

View File

@@ -0,0 +1,12 @@
/obj/item/device/modular_computer/tablet //Its called tablet for theme of 90ies but actually its a "big smartphone" sized
name = "tablet computer"
icon = 'icons/obj/modular_tablet.dmi'
icon_state = "tablet"
icon_state_unpowered = "tablet"
icon_state_powered = "tablet"
icon_state_menu = "menu"
hardware_flag = PROGRAM_TABLET
max_hardware_size = 1
w_class = WEIGHT_CLASS_SMALL
steel_sheet_cost = 1
slot_flags = SLOT_ID | SLOT_BELT

View File

@@ -0,0 +1,29 @@
// This is literally the worst possible cheap tablet
/obj/item/device/modular_computer/tablet/preset/cheap
desc = "A low-end tablet often seen among low ranked station personnel."
/obj/item/device/modular_computer/tablet/preset/cheap/New()
. = ..()
install_component(new /obj/item/weapon/computer_hardware/processor_unit/small)
install_component(new /obj/item/weapon/computer_hardware/battery(src, /obj/item/weapon/stock_parts/cell/computer/micro))
install_component(new /obj/item/weapon/computer_hardware/hard_drive/small)
install_component(new /obj/item/weapon/computer_hardware/network_card)
// Alternative version, an average one, for higher ranked positions mostly
/obj/item/device/modular_computer/tablet/preset/advanced/New()
. = ..()
install_component(new /obj/item/weapon/computer_hardware/processor_unit/small)
install_component(new /obj/item/weapon/computer_hardware/battery(src, /obj/item/weapon/stock_parts/cell/computer))
install_component(new /obj/item/weapon/computer_hardware/hard_drive/small)
install_component(new /obj/item/weapon/computer_hardware/network_card)
install_component(new /obj/item/weapon/computer_hardware/card_slot)
install_component(new /obj/item/weapon/computer_hardware/printer/mini)
/obj/item/device/modular_computer/tablet/preset/cargo/New()
. = ..()
install_component(new /obj/item/weapon/computer_hardware/processor_unit/small)
install_component(new /obj/item/weapon/computer_hardware/battery(src, /obj/item/weapon/stock_parts/cell/computer))
install_component(new /obj/item/weapon/computer_hardware/hard_drive/small)
install_component(new /obj/item/weapon/computer_hardware/network_card)
install_component(new /obj/item/weapon/computer_hardware/printer/mini)

View File

@@ -0,0 +1,160 @@
// 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."
use_power = 1
idle_power_usage = 5
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/icon_state_powered = null // Icon state when the computer is turned on.
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/obj_integrity = 300
var/integrity_failure = 150
var/max_integrity = 300
var/obj/item/device/modular_computer/processor/cpu = null // CPU that handles most logic while this type only handles power and other specific things.
/obj/machinery/modular_computer/New()
..()
cpu = new(src)
cpu.physical = src
global_modular_computers.Add(src)
/obj/machinery/modular_computer/Destroy()
if(cpu)
qdel(cpu)
cpu = null
return ..()
/obj/machinery/modular_computer/attack_ghost(mob/dead/observer/user)
if(cpu)
cpu.attack_ghost(user)
/obj/machinery/modular_computer/emag_act(mob/user)
return cpu ? cpu.emag_act(user) : 1
/obj/machinery/modular_computer/update_icon()
overlays.Cut()
icon_state = icon_state_powered
if(!cpu || !cpu.enabled)
if (!(stat & NOPOWER) && (cpu && cpu.use_power()))
overlays += screen_icon_screensaver
else
icon_state = icon_state_unpowered
set_light(0)
else
set_light(light_strength)
if(cpu.active_program)
overlays += cpu.active_program.program_icon_state ? cpu.active_program.program_icon_state : screen_icon_state_menu
else
overlays += screen_icon_state_menu
if(cpu && cpu.obj_integrity <= cpu.integrity_failure)
overlays += "bsod"
overlays += "broken"
// Eject ID card from computer, if it has ID slot with card inside.
/obj/machinery/modular_computer/proc/eject_id()
set name = "Eject ID"
set category = "Object"
if(cpu)
cpu.eject_id()
// Eject ID card from computer, if it has ID slot with card inside.
/obj/machinery/modular_computer/proc/eject_disk()
set name = "Eject Data Disk"
set category = "Object"
if(cpu)
cpu.eject_disk()
/obj/machinery/modular_computer/proc/eject_card()
set name = "Eject Intellicard"
set category = "Object"
set src in view(1)
if(cpu)
cpu.eject_card()
/obj/machinery/modular_computer/AltClick(mob/user)
if(cpu)
cpu.AltClick(user)
// 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
// 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()
// Used in following function to reduce copypaste
/obj/machinery/modular_computer/proc/power_failure(malfunction = 0)
var/obj/item/weapon/computer_hardware/battery/battery_module = cpu.all_components[MC_CELL]
if(cpu && cpu.enabled) // Shut down the computer
visible_message("<span class='danger'>\The [src]'s screen flickers [battery_module ? "\"BATTERY [malfunction ? "MALFUNCTION" : "CRITICAL"]\"" : "\"EXTERNAL POWER LOSS\""] warning as it shuts down unexpectedly.</span>")
if(cpu)
cpu.shutdown_computer(0)
stat |= NOPOWER
update_icon()
// 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(cpu && cpu.use_power()) // If MC_CPU still has a power source, PC wouldn't go offline.
stat &= ~NOPOWER
update_icon()
return
..()
update_icon()
/obj/machinery/modular_computer/attackby(obj/item/weapon/W, mob/user)
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(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(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(obj/item/projectile/Proj)
if(cpu)
cpu.bullet_act(Proj)