Advertisement
Guest User

Untitled

a guest
May 18th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.57 KB | None | 0 0
  1. // This is the base type that does all the hardware stuff.
  2. // Other types expand it - tablets use a direct subtypes, and
  3. // consoles and laptops use "procssor" item that is held inside machinery piece
  4. /obj/item/modular_computer
  5. name = "Modular Microcomputer"
  6. desc = "A small portable microcomputer."
  7.  
  8. var/enabled = 0 // Whether the computer is turned on.
  9. var/screen_on = 1 // Whether the computer is active/opened/it's screen is on.
  10. var/datum/computer_file/program/active_program = null // A currently active program running on the computer.
  11. var/hardware_flag = 0 // A flag that describes this device type
  12. var/last_power_usage = 0
  13. var/last_battery_percent = 0 // Used for deciding if battery percentage has chandged
  14. var/last_world_time = "00:00"
  15. var/list/last_header_icons
  16. var/computer_emagged = 0 // Whether the computer is emagged.
  17. var/password = "test"
  18.  
  19. 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.
  20. var/base_idle_power_usage = 5 // Power usage when the computer is idle and screen is off (currently only applies to laptops)
  21.  
  22. // Modular computers can run on various devices. Each DEVICE (Laptop, Console, Tablet,..)
  23. // must have it's own DMI file. Icon states must be called exactly the same in all files, but may look differently
  24. // 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.
  25.  
  26. icon = 'icons/obj/computer.dmi'
  27. icon_state = "laptop-open"
  28. var/icon_state_unpowered = null // Icon state when the computer is turned off
  29. var/icon_state_menu = "menu" // Icon state overlay when the computer is turned on, but no program is loaded that would override the screen.
  30. var/max_hardware_size = 0 // Maximal hardware size. Currently, tablets have 1, laptops 2 and consoles 3. Limits what hardware types can be installed.
  31. var/steel_sheet_cost = 5 // Amount of steel sheets refunded when disassembling an empty frame of this computer.
  32. var/light_strength = 0
  33.  
  34. // Damage of the chassis. If the chassis takes too much damage it will break apart.
  35. var/damage = 0 // Current damage level
  36. var/broken_damage = 50 // Damage level at which the computer ceases to operate
  37. var/max_damage = 100 // Damage level at which the computer breaks apart.
  38.  
  39. // Important hardware (must be installed for computer to work)
  40. 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.
  41. var/obj/item/weapon/computer_hardware/network_card/network_card // Network Card component of this computer. Allows connection to NTNet
  42. var/obj/item/weapon/computer_hardware/hard_drive/hard_drive // Hard Drive component of this computer. Stores programs and files.
  43. var/obj/item/weapon/computer_hardware/battery_module/battery_module // An internal power source for this computer. Can be recharged.
  44. // Optional hardware (improves functionality, but is not critical for computer to work)
  45. 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.
  46. var/obj/item/weapon/computer_hardware/nano_printer/nano_printer // Nano Printer component of this computer, for your everyday paperwork needs.
  47. var/obj/item/weapon/computer_hardware/hard_drive/portable/portable_drive // Portable data storage
  48.  
  49. var/list/idle_threads = list() // Idle programs on background. They still receive process calls but can't be interacted with.
  50.  
  51.  
  52. // Eject ID card from computer, if it has ID slot with card inside.
  53. /obj/item/modular_computer/verb/eject_id()
  54. set name = "Eject ID"
  55. set category = "Object"
  56. set src in view(1)
  57.  
  58. if(usr.incapacitated() || !istype(usr, /mob/living))
  59. usr << "<span class='warning'>You can't do that.</span>"
  60. return
  61.  
  62. if(!Adjacent(usr))
  63. usr << "<span class='warning'>You can't reach it.</span>"
  64. return
  65.  
  66. proc_eject_id(usr)
  67.  
  68. // Eject ID card from computer, if it has ID slot with card inside.
  69. /obj/item/modular_computer/verb/eject_usb()
  70. set name = "Eject Portable Device"
  71. set category = "Object"
  72. set src in view(1)
  73.  
  74. if(usr.incapacitated() || !istype(usr, /mob/living))
  75. usr << "<span class='warning'>You can't do that.</span>"
  76. return
  77.  
  78. if(!Adjacent(usr))
  79. usr << "<span class='warning'>You can't reach it.</span>"
  80. return
  81.  
  82. proc_eject_usb(usr)
  83.  
  84. /obj/item/modular_computer/proc/proc_eject_id(mob/user)
  85. if(!user)
  86. user = usr
  87.  
  88. if(!card_slot)
  89. user << "\The [src] does not have an ID card slot"
  90. return
  91.  
  92. if(!card_slot.stored_card)
  93. user << "There is no card in \the [src]"
  94. return
  95.  
  96. if(active_program)
  97. active_program.event_idremoved(0)
  98.  
  99. for(var/datum/computer_file/program/P in idle_threads)
  100. P.event_idremoved(1)
  101.  
  102. card_slot.stored_card.forceMove(get_turf(src))
  103. card_slot.stored_card = null
  104. update_uis()
  105. user << "You remove the card from \the [src]"
  106.  
  107. /obj/item/modular_computer/proc/proc_eject_usb(mob/user)
  108. if(!user)
  109. user = usr
  110.  
  111. if(!portable_drive)
  112. user << "There is no portable device connected to \the [src]."
  113. return
  114.  
  115. uninstall_component(user, portable_drive)
  116. update_uis()
  117.  
  118. /obj/item/modular_computer/attack_ghost(var/mob/observer/ghost/user)
  119. if(enabled)
  120. ui_interact(user)
  121. else if(check_rights(R_ADMIN, 0, user))
  122. var/response = alert(user, "This computer is turned off. Would you like to turn it on?", "Admin Override", "Yes", "No")
  123. if(response == "Yes")
  124. turn_on(user)
  125.  
  126. /obj/item/modular_computer/emag_act(var/remaining_charges, var/mob/user)
  127. if(computer_emagged)
  128. user << "\The [src] was already emagged."
  129. return NO_EMAG_ACT
  130. else
  131. computer_emagged = 1
  132. user << "You emag \the [src]. It's screen briefly shows a \"OVERRIDE ACCEPTED: New software downloads available.\" message."
  133. return 1
  134.  
  135. /obj/item/modular_computer/examine(var/mob/user)
  136. ..()
  137. if(damage > broken_damage)
  138. user << "<span class='danger'>It is heavily damaged!</span>"
  139. else if(damage)
  140. user << "It is damaged."
  141.  
  142. /obj/item/modular_computer/New()
  143. processing_objects.Add(src)
  144. update_icon()
  145. ..()
  146.  
  147. /obj/item/modular_computer/Destroy()
  148. kill_program(1)
  149. processing_objects.Remove(src)
  150. for(var/obj/item/weapon/computer_hardware/CH in src.get_all_components())
  151. uninstall_component(null, CH)
  152. return ..()
  153.  
  154. /obj/item/modular_computer/update_icon()
  155. icon_state = icon_state_unpowered
  156.  
  157. overlays.Cut()
  158. if(!enabled)
  159. set_light(0)
  160. return
  161. set_light(light_strength)
  162. if(active_program)
  163. overlays.Add(active_program.program_icon_state ? active_program.program_icon_state : icon_state_menu)
  164. else
  165. overlays.Add(icon_state_menu)
  166.  
  167. // Used by child types if they have other power source than battery
  168. /obj/item/modular_computer/proc/check_power_override()
  169. return 0
  170.  
  171. // Operates NanoUI
  172. /obj/item/modular_computer/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = 1)
  173. if(!screen_on || !enabled)
  174. if(ui)
  175. ui.close()
  176. return 0
  177. if((!battery_module || !battery_module.battery.charge) && !check_power_override())
  178. if(ui)
  179. ui.close()
  180. return 0
  181.  
  182. // If we have an active program switch to it now.
  183. if(active_program)
  184. if(ui) // This is the main laptop screen. Since we are switching to program's UI close it for now.
  185. ui.close()
  186. active_program.ui_interact(user)
  187. return
  188.  
  189. // We are still here, that means there is no program loaded. Load the BIOS/ROM/OS/whatever you want to call it.
  190. // This screen simply lists available programs and user may select them.
  191. if(!hard_drive || !hard_drive.stored_files || !hard_drive.stored_files.len)
  192. visible_message("\The [src] beeps three times, it's screen displaying \"DISK ERROR\" warning.")
  193. return // No HDD, No HDD files list or no stored files. Something is very broken.
  194.  
  195. var/list/data = get_header_data()
  196.  
  197. var/list/programs = list()
  198. for(var/datum/computer_file/program/P in hard_drive.stored_files)
  199. var/list/program = list()
  200. program["name"] = P.filename
  201. program["desc"] = P.filedesc
  202. programs.Add(list(program))
  203.  
  204. data["programs"] = programs
  205. ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open)
  206. if (!ui)
  207. ui = new(user, src, ui_key, "laptop_mainscreen.tmpl", "NTOS Main Menu", 400, 500)
  208. ui.auto_update_layout = 1
  209. ui.set_initial_data(data)
  210. ui.open()
  211. ui.set_auto_update(1)
  212.  
  213. // On-click handling. Turns on the computer if it's off and opens the GUI.
  214. /obj/item/modular_computer/attack_self(mob/user)
  215. if(enabled)
  216. ui_interact(user)
  217. else
  218. turn_on(user)
  219.  
  220. /obj/item/modular_computer/proc/break_apart()
  221. visible_message("\The [src] breaks apart!")
  222. var/turf/newloc = get_turf(src)
  223. new /obj/item/stack/material/steel(newloc, round(steel_sheet_cost/2))
  224. for(var/obj/item/weapon/computer_hardware/H in get_all_components())
  225. uninstall_component(null, H)
  226. H.forceMove(newloc)
  227. if(prob(25))
  228. H.take_damage(rand(10,30))
  229. relay_qdel()
  230. qdel()
  231.  
  232. /obj/item/modular_computer/proc/turn_on(var/mob/user)
  233. var/issynth = issilicon(user) // Robots and AIs get different activation messages.
  234. if(damage > broken_damage)
  235. if(issynth)
  236. user << "You send an activation signal to \the [src], but it responds with an error code. It must be damaged."
  237. else
  238. user << "You press the power button, but the computer fails to boot up, displaying variety of errors before shutting down again."
  239. return
  240. 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.
  241. if(issynth)
  242. user << "You send an activation signal to \the [src], turning it on"
  243. else
  244. user << "You press the power button and start up \the [src]"
  245. enabled = 1
  246. update_icon()
  247. if(password)
  248. var/response = alert(user, "Device locked. Please select an option.", "Device Locked", "Enter password", "Attempt manual override", "Cancel")
  249. if(response == "Cancel")
  250. enabled = 0
  251. update_icon()
  252. return
  253. if(response == "Attempt manual override")
  254. var/over_response = alert(user, "Attempting a manual override will take time, and trigger the Intrusion Detection System. Confirm?", "Manual Override", "Yes", "No")
  255. if(over_response == "No")
  256. enabled = 0
  257. update_icon()
  258. return
  259. if((ntnet_global.intrusion_detection_enabled) && (network_card))
  260. ntnet_global.add_log("IDS WARNING - Manual override attempt of device [network_card.get_network_tag()] detected.")
  261. ntnet_global.intrusion_detection_alarm = 1
  262. user << "<span class='notice'> Manual override initiated. Processing...</span>"
  263. sleep(300)
  264. user << "<span class='notice'> Manual override successful. Device unlocked.</span>"
  265. ntnet_global.intrusion_detection_alarm = 0
  266. password = null
  267. if(response == "Enter password")
  268. var/pass_entered = sanitize(input(user, "Please enter the password.", "Enter Password"), 16)
  269. if(!pass_entered)
  270. enabled = 0
  271. update_icon()
  272. return
  273. if(!(pass_entered == password))
  274. user << "<span class='warning'> Incorrect password. Access Denied.</span>"
  275. enabled = 0
  276. update_icon()
  277. return
  278. user << "<span class='notice'> Password accepted. Access granted.</span>"
  279. ui_interact(user)
  280. else // Unpowered
  281. if(issynth)
  282. user << "You send an activation signal to \the [src] but it does not respond"
  283. else
  284. user << "You press the power button but \the [src] does not respond"
  285.  
  286. // Process currently calls handle_power(), may be expanded in future if more things are added.
  287. /obj/item/modular_computer/process()
  288. if(!enabled) // The computer is turned off
  289. last_power_usage = 0
  290. return 0
  291.  
  292. if(damage > broken_damage)
  293. shutdown_computer()
  294. return 0
  295.  
  296. 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.
  297. active_program.event_networkfailure(0)
  298.  
  299. for(var/datum/computer_file/program/P in idle_threads)
  300. if(P.requires_ntnet && !get_ntnet_status(P.requires_ntnet_feature))
  301. P.event_networkfailure(1)
  302.  
  303. if(active_program)
  304. if(active_program.program_state != PROGRAM_STATE_KILLED)
  305. active_program.process_tick()
  306. active_program.ntnet_status = get_ntnet_status()
  307. active_program.computer_emagged = computer_emagged
  308. else
  309. active_program = null
  310.  
  311. for(var/datum/computer_file/program/P in idle_threads)
  312. if(P.program_state != PROGRAM_STATE_KILLED)
  313. P.process_tick()
  314. P.ntnet_status = get_ntnet_status()
  315. P.computer_emagged = computer_emagged
  316. else
  317. idle_threads.Remove(P)
  318.  
  319. handle_power() // Handles all computer power interaction
  320. check_update_ui_need()
  321.  
  322. // Function used by NanoUI's to obtain data for header. All relevant entries begin with "PC_"
  323. /obj/item/modular_computer/proc/get_header_data()
  324. var/list/data = list()
  325.  
  326. if(battery_module)
  327. switch(battery_module.battery.percent())
  328. if(80 to 200) // 100 should be maximal but just in case..
  329. data["PC_batteryicon"] = "batt_100.gif"
  330. if(60 to 80)
  331. data["PC_batteryicon"] = "batt_80.gif"
  332. if(40 to 60)
  333. data["PC_batteryicon"] = "batt_60.gif"
  334. if(20 to 40)
  335. data["PC_batteryicon"] = "batt_40.gif"
  336. if(5 to 20)
  337. data["PC_batteryicon"] = "batt_20.gif"
  338. else
  339. data["PC_batteryicon"] = "batt_5.gif"
  340. data["PC_batterypercent"] = "[round(battery_module.battery.percent())] %"
  341. data["PC_showbatteryicon"] = 1
  342. else
  343. data["PC_batteryicon"] = "batt_5.gif"
  344. data["PC_batterypercent"] = "N/C"
  345. data["PC_showbatteryicon"] = battery_module ? 1 : 0
  346.  
  347. switch(get_ntnet_status())
  348. if(0)
  349. data["PC_ntneticon"] = "sig_none.gif"
  350. if(1)
  351. data["PC_ntneticon"] = "sig_low.gif"
  352. if(2)
  353. data["PC_ntneticon"] = "sig_high.gif"
  354. if(3)
  355. data["PC_ntneticon"] = "sig_lan.gif"
  356.  
  357. if(idle_threads.len)
  358. var/list/program_headers = list()
  359. for(var/datum/computer_file/program/P in idle_threads)
  360. if(!P.ui_header)
  361. continue
  362. program_headers.Add(list(list(
  363. "icon" = P.ui_header
  364. )))
  365.  
  366. data["PC_programheaders"] = program_headers
  367.  
  368. data["PC_stationtime"] = stationtime2text()
  369. data["PC_hasheader"] = 1
  370. data["PC_showexitprogram"] = active_program ? 1 : 0 // Hides "Exit Program" button on mainscreen
  371. return data
  372.  
  373. // Relays kill program request to currently active program. Use this to quit current program.
  374. /obj/item/modular_computer/proc/kill_program(var/forced = 0)
  375. if(active_program)
  376. active_program.kill_program(forced)
  377. active_program = null
  378. var/mob/user = usr
  379. if(user && istype(user))
  380. ui_interact(user) // Re-open the UI on this computer. It should show the main screen now.
  381. update_icon()
  382.  
  383. // Returns 0 for No Signal, 1 for Low Signal and 2 for Good Signal. 3 is for wired connection (always-on)
  384. /obj/item/modular_computer/proc/get_ntnet_status(var/specific_action = 0)
  385. if(network_card)
  386. return network_card.get_signal(specific_action)
  387. else
  388. return 0
  389.  
  390. /obj/item/modular_computer/proc/add_log(var/text)
  391. if(!get_ntnet_status())
  392. return 0
  393. return ntnet_global.add_log(text, network_card)
  394.  
  395. /obj/item/modular_computer/proc/shutdown_computer(var/loud = 1)
  396. kill_program(1)
  397. for(var/datum/computer_file/program/P in idle_threads)
  398. P.kill_program(1)
  399. idle_threads.Remove(P)
  400. if(loud)
  401. visible_message("\The [src] shuts down.")
  402. enabled = 0
  403. update_icon()
  404. return
  405.  
  406. // Handles user's GUI input
  407. /obj/item/modular_computer/Topic(href, href_list)
  408. if(..())
  409. return 1
  410. if( href_list["PC_exit"] )
  411. kill_program()
  412. return 1
  413. if( href_list["PC_enable_component"] )
  414. var/obj/item/weapon/computer_hardware/H = find_hardware_by_name(href_list["PC_enable_component"])
  415. if(H && istype(H) && !H.enabled)
  416. H.enabled = 1
  417. . = 1
  418. if( href_list["PC_disable_component"] )
  419. var/obj/item/weapon/computer_hardware/H = find_hardware_by_name(href_list["PC_disable_component"])
  420. if(H && istype(H) && H.enabled)
  421. H.enabled = 0
  422. . = 1
  423. if( href_list["PC_shutdown"] )
  424. shutdown_computer()
  425. return 1
  426. if( href_list["PC_minimize"] )
  427. var/mob/user = usr
  428. if(!active_program || !processor_unit)
  429. return
  430.  
  431. if(idle_threads.len >= processor_unit.max_idle_programs)
  432. user << "<span class='notice'>\The [src] displays a \"Maximal CPU load reached. Unable to minimize another program.\" error</span>"
  433. return
  434.  
  435. idle_threads.Add(active_program)
  436. active_program.program_state = PROGRAM_STATE_BACKGROUND // Should close any existing UIs
  437. nanomanager.close_uis(active_program.NM ? active_program.NM : active_program)
  438. active_program = null
  439. update_icon()
  440. if(user && istype(user))
  441. ui_interact(user) // Re-open the UI on this computer. It should show the main screen now.
  442.  
  443. if( href_list["PC_runprogram"] )
  444. var/prog = href_list["PC_runprogram"]
  445. var/datum/computer_file/program/P = null
  446. var/mob/user = usr
  447. if(hard_drive)
  448. P = hard_drive.find_file_by_name(prog)
  449.  
  450. if(!P || !istype(P)) // Program not found or it's not executable program.
  451. user << "<span class='danger'>\The [src]'s screen shows \"I/O ERROR - Unable to run program\" warning.</span>"
  452. return
  453.  
  454. P.computer = src
  455.  
  456. if(!P.is_supported_by_hardware(hardware_flag, 1, user))
  457. return
  458.  
  459. // The program is already running. Resume it.
  460. if(P in idle_threads)
  461. P.program_state = PROGRAM_STATE_ACTIVE
  462. active_program = P
  463. idle_threads.Remove(P)
  464. update_icon()
  465. return
  466.  
  467. if(P.requires_ntnet && !get_ntnet_status(P.requires_ntnet_feature)) // The program requires NTNet connection, but we are not connected to NTNet.
  468. 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>"
  469. return
  470. if(P.run_program(user))
  471. active_program = P
  472. update_icon()
  473. return 1
  474. if(.)
  475. update_uis()
  476.  
  477. // Used in following function to reduce copypaste
  478. /obj/item/modular_computer/proc/power_failure(var/malfunction = 0)
  479. if(enabled) // Shut down the computer
  480. visible_message("<span class='danger'>\The [src]'s screen flickers \"BATTERY [malfunction ? "MALFUNCTION" : "CRITICAL"]\" warning as it shuts down unexpectedly.</span>")
  481. if(active_program)
  482. active_program.event_powerfailure(0)
  483. for(var/datum/computer_file/program/PRG in idle_threads)
  484. PRG.event_powerfailure(1)
  485. shutdown_computer(0)
  486.  
  487. // Handles power-related things, such as battery interaction, recharging, shutdown when it's discharged
  488. /obj/item/modular_computer/proc/handle_power()
  489. if(!battery_module || battery_module.battery.charge <= 0) // Battery-run but battery is depleted.
  490. power_failure()
  491. return 0
  492.  
  493. var/power_usage = screen_on ? base_active_power_usage : base_idle_power_usage
  494.  
  495. for(var/obj/item/weapon/computer_hardware/H in get_all_components())
  496. if(H.enabled)
  497. power_usage += H.power_usage
  498.  
  499. if(battery_module)
  500. if(!battery_module.check_functionality())
  501. power_failure(1)
  502. return
  503. battery_module.battery.use(power_usage * CELLRATE)
  504.  
  505. last_power_usage = power_usage
  506.  
  507. /obj/item/modular_computer/attackby(var/obj/item/weapon/W as obj, var/mob/user as mob)
  508. if(istype(W, /obj/item/weapon/card/id)) // ID Card, try to insert it.
  509. var/obj/item/weapon/card/id/I = W
  510. if(!card_slot)
  511. user << "You try to insert \the [I] into \the [src], but it does not have an ID card slot installed."
  512. return
  513.  
  514. if(card_slot.stored_card)
  515. user << "You try to insert \the [I] into \the [src], but it's ID card slot is occupied."
  516. return
  517. user.drop_from_inventory(I)
  518. card_slot.stored_card = I
  519. I.forceMove(src)
  520. update_uis()
  521. user << "You insert \the [I] into \the [src]."
  522. return
  523. if(istype(W, /obj/item/weapon/paper))
  524. if(!nano_printer)
  525. return
  526. nano_printer.attackby(W, user)
  527. if(istype(W, /obj/item/weapon/computer_hardware))
  528. var/obj/item/weapon/computer_hardware/C = W
  529. if(C.hardware_size <= max_hardware_size)
  530. try_install_component(user, C)
  531. else
  532. user << "This component is too large for \the [src]."
  533. if(istype(W, /obj/item/weapon/wrench))
  534. var/list/components = get_all_components()
  535. if(components.len)
  536. user << "Remove all components from \the [src] before disassembling it."
  537. return
  538. new /obj/item/stack/material/steel( get_turf(src.loc), steel_sheet_cost )
  539. src.visible_message("\The [src] has been disassembled by [user].")
  540. relay_qdel()
  541. qdel(src)
  542. return
  543. if(istype(W, /obj/item/weapon/weldingtool))
  544. var/obj/item/weapon/weldingtool/WT = W
  545. if(!WT.isOn())
  546. user << "\The [W] is off."
  547. return
  548.  
  549. if(!damage)
  550. user << "\The [src] does not require repairs."
  551. return
  552.  
  553. user << "You begin repairing damage to \the [src]..."
  554. if(WT.remove_fuel(round(damage/75)) && do_after(usr, damage/10))
  555. damage = 0
  556. user << "You repair \the [src]."
  557. return
  558.  
  559. if(istype(W, /obj/item/weapon/screwdriver))
  560. var/list/all_components = get_all_components()
  561. if(!all_components.len)
  562. user << "This device doesn't have any components installed."
  563. return
  564. var/list/component_names = list()
  565. for(var/obj/item/weapon/computer_hardware/H in all_components)
  566. component_names.Add(H.name)
  567.  
  568. var/choice = input(usr, "Which component do you want to uninstall?", "Computer maintenance", null) as null|anything in component_names
  569.  
  570. if(!choice)
  571. return
  572.  
  573. if(!Adjacent(usr))
  574. return
  575.  
  576. var/obj/item/weapon/computer_hardware/H = find_hardware_by_name(choice)
  577.  
  578. if(!H)
  579. return
  580.  
  581. uninstall_component(user, H)
  582.  
  583. return
  584.  
  585. ..()
  586.  
  587. // Used by processor to relay qdel() to machinery type.
  588. /obj/item/modular_computer/proc/relay_qdel()
  589. return
  590.  
  591. // Attempts to install the hardware into apropriate slot.
  592. /obj/item/modular_computer/proc/try_install_component(var/mob/living/user, var/obj/item/weapon/computer_hardware/H, var/found = 0)
  593. // "USB" flash drive.
  594. if(istype(H, /obj/item/weapon/computer_hardware/hard_drive/portable))
  595. if(portable_drive)
  596. user << "This computer's portable drive slot is already occupied by \the [portable_drive]."
  597. return
  598. found = 1
  599. portable_drive = H
  600. else if(istype(H, /obj/item/weapon/computer_hardware/hard_drive))
  601. if(hard_drive)
  602. user << "This computer's hard drive slot is already occupied by \the [hard_drive]."
  603. return
  604. found = 1
  605. hard_drive = H
  606. else if(istype(H, /obj/item/weapon/computer_hardware/network_card))
  607. if(network_card)
  608. user << "This computer's network card slot is already occupied by \the [network_card]."
  609. return
  610. found = 1
  611. network_card = H
  612. else if(istype(H, /obj/item/weapon/computer_hardware/nano_printer))
  613. if(nano_printer)
  614. user << "This computer's nano printer slot is already occupied by \the [nano_printer]."
  615. return
  616. found = 1
  617. nano_printer = H
  618. else if(istype(H, /obj/item/weapon/computer_hardware/card_slot))
  619. if(card_slot)
  620. user << "This computer's card slot is already occupied by \the [card_slot]."
  621. return
  622. found = 1
  623. card_slot = H
  624. else if(istype(H, /obj/item/weapon/computer_hardware/battery_module))
  625. if(battery_module)
  626. user << "This computer's battery slot is already occupied by \the [battery_module]."
  627. return
  628. found = 1
  629. battery_module = H
  630. else if(istype(H, /obj/item/weapon/computer_hardware/processor_unit))
  631. if(processor_unit)
  632. user << "This computer's processor slot is already occupied by \the [processor_unit]."
  633. return
  634. found = 1
  635. processor_unit = H
  636. if(found)
  637. user << "You install \the [H] into \the [src]"
  638. H.holder2 = src
  639. user.drop_from_inventory(H)
  640. H.forceMove(src)
  641.  
  642. // Uninstalls component. Found and Critical vars may be passed by parent types, if they have additional hardware.
  643. /obj/item/modular_computer/proc/uninstall_component(var/mob/living/user, var/obj/item/weapon/computer_hardware/H, var/found = 0, var/critical = 0)
  644. if(portable_drive == H)
  645. portable_drive = null
  646. found = 1
  647. if(hard_drive == H)
  648. hard_drive = null
  649. found = 1
  650. critical = 1
  651. if(network_card == H)
  652. network_card = null
  653. found = 1
  654. if(nano_printer == H)
  655. nano_printer = null
  656. found = 1
  657. if(card_slot == H)
  658. card_slot = null
  659. found = 1
  660. if(battery_module == H)
  661. battery_module = null
  662. found = 1
  663. if(processor_unit == H)
  664. processor_unit = null
  665. found = 1
  666. critical = 1
  667. if(found)
  668. if(user)
  669. user << "You remove \the [H] from \the [src]."
  670. H.forceMove(get_turf(src))
  671. H.holder2 = null
  672. if(critical && enabled)
  673. if(user)
  674. 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>"
  675. shutdown_computer()
  676. update_icon()
  677.  
  678.  
  679. // Checks all hardware pieces to determine if name matches, if yes, returns the hardware piece, otherwise returns null
  680. /obj/item/modular_computer/proc/find_hardware_by_name(var/name)
  681. if(portable_drive && (portable_drive.name == name))
  682. return portable_drive
  683. if(hard_drive && (hard_drive.name == name))
  684. return hard_drive
  685. if(network_card && (network_card.name == name))
  686. return network_card
  687. if(nano_printer && (nano_printer.name == name))
  688. return nano_printer
  689. if(card_slot && (card_slot.name == name))
  690. return card_slot
  691. if(battery_module && (battery_module.name == name))
  692. return battery_module
  693. if(processor_unit && (processor_unit.name == name))
  694. return processor_unit
  695. return null
  696.  
  697. // Returns list of all components
  698. /obj/item/modular_computer/proc/get_all_components()
  699. var/list/all_components = list()
  700. if(hard_drive)
  701. all_components.Add(hard_drive)
  702. if(network_card)
  703. all_components.Add(network_card)
  704. if(portable_drive)
  705. all_components.Add(portable_drive)
  706. if(nano_printer)
  707. all_components.Add(nano_printer)
  708. if(card_slot)
  709. all_components.Add(card_slot)
  710. if(battery_module)
  711. all_components.Add(battery_module)
  712. if(processor_unit)
  713. all_components.Add(processor_unit)
  714. return all_components
  715.  
  716. /obj/item/modular_computer/proc/update_uis()
  717. if(active_program) //Should we update program ui or computer ui?
  718. nanomanager.update_uis(active_program)
  719. if(active_program.NM)
  720. nanomanager.update_uis(active_program.NM)
  721. else
  722. nanomanager.update_uis(src)
  723.  
  724. /obj/item/modular_computer/proc/check_update_ui_need()
  725. var/ui_update_needed = 0
  726. if(battery_module)
  727. var/batery_percent = battery_module.battery.percent()
  728. if(last_battery_percent != batery_percent) //Let's update UI on percent change
  729. ui_update_needed = 1
  730. last_battery_percent = batery_percent
  731.  
  732. if(stationtime2text() != last_world_time)
  733. last_world_time = stationtime2text()
  734. ui_update_needed = 1
  735.  
  736. if(idle_threads.len)
  737. var/list/current_header_icons = list()
  738. for(var/datum/computer_file/program/P in idle_threads)
  739. if(!P.ui_header)
  740. continue
  741. current_header_icons[P.type] = P.ui_header
  742. if(!last_header_icons)
  743. last_header_icons = current_header_icons
  744.  
  745. else if(!listequal(last_header_icons, current_header_icons))
  746. last_header_icons = current_header_icons
  747. ui_update_needed = 1
  748. else
  749. for(var/x in last_header_icons|current_header_icons)
  750. if(last_header_icons[x]!=current_header_icons[x])
  751. last_header_icons = current_header_icons
  752. ui_update_needed = 1
  753. break
  754.  
  755. if(ui_update_needed)
  756. update_uis()
  757.  
  758. /obj/item/modular_computer/proc/take_damage(var/amount, var/component_probability, var/damage_casing = 1, var/randomize = 1)
  759. if(randomize)
  760. // 75%-125%, rand() works with integers, apparently.
  761. amount *= (rand(75, 125) / 100.0)
  762. amount = round(amount)
  763. if(damage_casing)
  764. damage += amount
  765. damage = between(0, damage, max_damage)
  766.  
  767. if(component_probability)
  768. for(var/obj/item/weapon/computer_hardware/H in get_all_components())
  769. if(prob(component_probability))
  770. H.take_damage(round(amount / 2))
  771.  
  772. if(damage >= max_damage)
  773. break_apart()
  774.  
  775. // Stronger explosions cause serious damage to internal components
  776. // Minor explosions are mostly mitigitated by casing.
  777. /obj/item/modular_computer/ex_act(var/severity)
  778. take_damage(rand(100,200) / severity, 30 / severity)
  779.  
  780. // EMPs are similar to explosions, but don't cause physical damage to the casing. Instead they screw up the components
  781. /obj/item/modular_computer/emp_act(var/severity)
  782. take_damage(rand(100,200) / severity, 50 / severity, 0)
  783.  
  784. // "Stun" weapons can cause minor damage to components (short-circuits?)
  785. // "Burn" damage is equally strong against internal components and exterior casing
  786. // "Brute" damage mostly damages the casing.
  787. /obj/item/modular_computer/bullet_act(var/obj/item/projectile/Proj)
  788. switch(Proj.damage_type)
  789. if(BRUTE)
  790. take_damage(Proj.damage, Proj.damage / 2)
  791. if(HALLOSS)
  792. take_damage(Proj.damage, Proj.damage / 3, 0)
  793. if(BURN)
  794. take_damage(Proj.damage, Proj.damage / 1.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement