first attempt. partial copy and stuff.

This commit is contained in:
Shadowlight213
2016-07-30 13:45:46 -07:00
parent d31cd79aa6
commit 6a5c7d7068
45 changed files with 5108 additions and 2 deletions
@@ -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()