-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathmodular_computer.dm
190 lines (163 loc) · 7.32 KB
/
modular_computer.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// 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."
icon = 'icons/obj/modular_console.dmi'
icon_state = "console"
use_power = IDLE_POWER_USE
idle_power_usage = 5
density = TRUE
///A flag that describes this device type
var/hardware_flag = PROGRAM_CONSOLE
/// Power usage during last tick
var/last_power_usage = 0
// 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 state when the computer is turned off.
var/icon_state_unpowered = "console-off"
///Icon state when the computer is turned on.
var/icon_state_powered = "console"
///Icon state overlay when the computer is turned on, but no program is loaded that would override the screen.
var/screen_icon_state_menu = "menu"
///Icon state overlay when the computer is powered, but not 'switched on'.
var/screen_icon_screensaver = "standby"
var/overlay_skin = null
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)
// Stuff for presets
var/list/starting_components = list()
var/list/starting_files = list()
var/datum/computer_file/program/initial_program
// Interaction Sounds
var/sound/startup_sound = 'sound/machines/computers/computer_start.ogg'
var/sound/shutdown_sound = 'sound/machines/computers/computer_end.ogg'
var/list/interact_sounds = list('sound/machines/computers/keypress1.ogg', 'sound/machines/computers/keypress2.ogg', 'sound/machines/computers/keypress3.ogg', 'sound/machines/computers/keypress4.ogg', 'sound/machines/computers/keystroke1.ogg', 'sound/machines/computers/keystroke2.ogg', 'sound/machines/computers/keystroke3.ogg', 'sound/machines/computers/keystroke4.ogg')
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/Initialize(mapload)
. = ..()
cpu = new(src)
cpu.physical = src
cpu.screen_on = TRUE
update_appearance()
/obj/machinery/modular_computer/Destroy()
QDEL_NULL(cpu)
return ..()
/obj/machinery/modular_computer/examine(mob/user)
. = ..()
. += get_modular_computer_parts_examine(user)
if(cpu && !(cpu.resistance_flags & INDESTRUCTIBLE))
if(cpu.resistance_flags & ON_FIRE)
. += span_warning("The CPU is on fire!")
var/healthpercent = (cpu.get_integrity()/cpu.max_integrity) * 100
switch(healthpercent)
if(50 to 99)
. += "The CPU looks slightly damaged."
if(25 to 50)
. += "The CPU appears heavily damaged."
if(0 to 25)
. += span_warning("The CPU is falling apart!")
/obj/machinery/modular_computer/attack_ghost(mob/dead/observer/user)
. = ..()
if(.)
return
if(cpu)
cpu.attack_ghost(user)
/obj/machinery/modular_computer/emag_act(mob/user, obj/item/card/emag/emag_card)
if(!cpu)
to_chat(user, "<span class='warning'>You'd need to turn the [src] on first.</span>")
return FALSE
return (cpu.emag_act(user, emag_card))
/obj/machinery/modular_computer/update_appearance(updates)
. = ..()
set_light(cpu?.enabled ? light_strength : 0)
/obj/machinery/modular_computer/update_icon_state()
if(!cpu || !cpu.enabled || (stat & NOPOWER))
icon_state = icon_state_unpowered
else
icon_state = icon_state_powered
return ..()
/obj/machinery/modular_computer/update_overlays()
. = ..()
if(!cpu)
return .
if(cpu.enabled)
. += cpu.active_program?.program_icon_state || screen_icon_state_menu
else if(!(stat & NOPOWER))
. += screen_icon_screensaver
if(cpu.get_integrity() <= cpu.integrity_failure)
. += "bsod"
. += "broken"
return .
/// Eats the "source" arg because update_icon actually expects args now.
/obj/machinery/modular_computer/proc/relay_icon_update(datum/source, updates, updated)
SIGNAL_HANDLER
return update_icon(updates)
/obj/machinery/modular_computer/AltClick(mob/user)
if(cpu)
cpu.AltClick(user)
//ATTACK HAND IGNORING PARENT RETURN VALUE
// On-click handling. Turns on the computer if it's off and opens the GUI.
/obj/machinery/modular_computer/interact(mob/user)
if(cpu)
return cpu.interact(user) // CPU is an item, that's why we route attack_hand to attack_self
else
return ..()
// Process currently calls handle_power(), may be expanded in future if more things are added.
/obj/machinery/modular_computer/process(delta_time)
if(cpu)
// Keep names in sync.
cpu.name = name
cpu.process(delta_time)
// Used in following function to reduce copypaste
/obj/machinery/modular_computer/proc/power_failure(malfunction = 0)
var/obj/item/computer_hardware/battery/battery_module = cpu.all_components[MC_CELL]
if(cpu && cpu.enabled) // Shut down the computer
visible_message(span_danger("\The [src]'s screen flickers [battery_module ? "\"BATTERY [malfunction ? "MALFUNCTION" : "CRITICAL"]\"" : "\"EXTERNAL POWER LOSS\""] warning as it shuts down unexpectedly."))
if(cpu)
cpu.shutdown_computer(0)
stat |= NOPOWER
update_appearance(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_appearance(UPDATE_ICON) //modPCs should be changed to use powered() instead.
return
. = ..()
/obj/machinery/modular_computer/screwdriver_act(mob/user, obj/item/tool)
if(cpu)
return cpu.screwdriver_act(user, tool)
/obj/machinery/modular_computer/attackby(obj/item/W as obj, mob/user)
if(!user.combat_mode && cpu && !(flags_1 & NODECONSTRUCT_1))
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)
switch(severity)
if(EXPLODE_DEVASTATE)
SSexplosions.high_mov_atom += cpu
if(EXPLODE_HEAVY)
SSexplosions.med_mov_atom += cpu
if(EXPLODE_LIGHT)
SSexplosions.low_mov_atom += cpu
..()
// 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(. & EMP_PROTECT_CONTENTS)
return
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/projectile/Proj)
if(cpu)
cpu.bullet_act(Proj)