mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-01-03 22:12:38 +00:00
- As usual, fixes various issues through the code, but likely creates more as this is still WIP project. - Most importantly, NTNet software downloader program now exists and more or less works. - Your device's connectivity has effect on how quickly you can download. Right now, things with wired connection (consoles) download at 0,5GQ/s, mobile devices on station where signal is good at 0,1GQ/s and mobile devices off station where signal is bad are limited to 0,025GQ/s. This is all controlled by three defines.
160 lines
7.0 KiB
Plaintext
160 lines
7.0 KiB
Plaintext
// 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/keyboard_icon_state_menu = "keyboard1" // Keyboard's icon state overlay when the computer is turned on and no program is loaded
|
||
var/nokeyboard = 0 // Set to 1 to disable keyboard icons for this subtype.
|
||
|
||
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)
|
||
|
||
// Important hardware (must be installed for computer to work)
|
||
var/datum/computer_hardware/network_card/network_card // Network Card component of this computer. Allows connection to NTNet
|
||
var/datum/computer_hardware/hard_drive/hard_drive // Hard Drive component of this computer. Stores programs and files.
|
||
var/obj/item/weapon/cell/battery = null // Battery component of this computer. Powers the computer. <20>ll computers can have batteries.
|
||
// Optional hardware (improves functionality, but is not critical for computer to work)
|
||
var/datum/computer_hardware/tesla_link/tesla_link // Tesla Link component of this computer. Allows remote charging from nearest APC.
|
||
var/datum/computer_hardware/card_slot/card_slot // ID Card slot component of this computer. Mostly for HoP modification console that needs ID slot for modification.
|
||
var/datum/computer_hardware/nano_printer/nano_printer // Nano Printer component of this computer, for your everyday paperwork needs.
|
||
|
||
var/obj/item/modular_computer/processor/cpu = null // CPU that handles most logic while this type only handles power and other specific things.
|
||
|
||
/obj/machinery/modular_computer/update_icon()
|
||
icon_state = icon_state_unpowered
|
||
overlays.Cut()
|
||
|
||
if(!cpu || !cpu.enabled)
|
||
return
|
||
if(cpu.active_program)
|
||
overlays.Add(cpu.active_program.program_icon_state ? cpu.active_program.program_icon_state : screen_icon_state_menu)
|
||
if(!nokeyboard)
|
||
overlays.Add(cpu.active_program.keyboard_icon_state ? cpu.active_program.keyboard_icon_state : keyboard_icon_state_menu)
|
||
else
|
||
overlays.Add(screen_icon_state_menu)
|
||
if(!nokeyboard)
|
||
overlays.Add(keyboard_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()
|
||
|
||
/obj/machinery/modular_computer/New()
|
||
..()
|
||
cpu = new(src)
|
||
|
||
// Installs programs necessary for computer function.
|
||
// TODO: Implement program for downloading of other programs, and replace hardcoded program addition here
|
||
/obj/machinery/modular_computer/proc/install_default_programs()
|
||
if(cpu && cpu.hard_drive)
|
||
cpu.install_default_programs()
|
||
|
||
// 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(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()
|
||
if(cpu && cpu.enabled) // Shut down the computer
|
||
visible_message("<span class='danger'>\The [src]'s screen flickers [battery ? "\"BATTERY CRITICAL\"" : "\"EXTERNAL POWER LOSS\""] warning as it shuts down unexpectedly.</span>")
|
||
if(cpu)
|
||
cpu.kill_program(1)
|
||
cpu.enabled = 0
|
||
battery_powered = 0
|
||
update_icon()
|
||
stat |= NOPOWER
|
||
|
||
// Called by cpu item's process() automatically, handles our power interaction.
|
||
/obj/machinery/modular_computer/proc/handle_power()
|
||
if(cpu.battery && cpu.battery.charge <= 0) // Battery-run but battery is depleted.
|
||
power_failure()
|
||
return 0
|
||
else if(!cpu.battery && (!powered() || !tesla_link || !tesla_link.enabled)) // Not battery run, but lacking APC connection.
|
||
power_failure()
|
||
return 0
|
||
else if(stat & NOPOWER)
|
||
stat &= ~NOPOWER
|
||
|
||
if(cpu.battery && cpu.battery.charge)
|
||
battery_powered = 1
|
||
else
|
||
battery_powered = 0
|
||
|
||
var/power_usage = cpu.screen_on ? base_active_power_usage : base_idle_power_usage
|
||
if(cpu.network_card && cpu.network_card.enabled)
|
||
power_usage += cpu.network_card.power_usage
|
||
|
||
if(cpu.hard_drive && cpu.hard_drive.enabled)
|
||
power_usage += cpu.hard_drive.power_usage
|
||
|
||
if(cpu.nano_printer && cpu.nano_printer.enabled)
|
||
power_usage += cpu.nano_printer.power_usage
|
||
|
||
if(cpu.card_slot && cpu.card_slot.enabled)
|
||
power_usage += cpu.card_slot.power_usage
|
||
|
||
// Wireless APC connection exists.
|
||
if(tesla_link && tesla_link.enabled)
|
||
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 && cpu.battery.charge < cpu.battery.maxcharge)
|
||
use_power = 2
|
||
|
||
if(cpu.battery && powered() && (use_power == 2)) // Battery charging itself
|
||
cpu.battery.give(100 * CELLRATE)
|
||
else if(cpu.battery && !powered()) // Unpowered, but battery covers the usage.
|
||
cpu.battery.use(idle_power_usage * CELLRATE)
|
||
|
||
else // No wireless connection run only on battery.
|
||
use_power = 0
|
||
if (cpu.battery)
|
||
cpu.battery.use(power_usage * CELLRATE)
|
||
cpu.last_power_usage = power_usage
|
||
|
||
// Modular computers can have battery in them, we handle power in previous proc, so prevent this from messing it up for us.
|
||
/obj/machinery/modular_computer/power_change()
|
||
if(battery_powered)
|
||
return
|
||
else
|
||
..()
|
||
|
||
/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 ..()
|