-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathoven.dm
249 lines (211 loc) · 7 KB
/
oven.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#define OVEN_SMOKE_STATE_NONE 0
#define OVEN_SMOKE_STATE_GOOD 1
#define OVEN_SMOKE_STATE_NEUTRAL 2
#define OVEN_SMOKE_STATE_BAD 3
#define OVEN_LID_Y_OFFSET -15
#define OVEN_TRAY_Y_OFFSET -16
#define OVEN_TRAY_X_OFFSET -2
/obj/machinery/oven
name = "oven"
desc = "Why do they call it oven when you of in the cold food of out hot eat the food?"
icon = 'icons/obj/machines/kitchenmachines.dmi'
icon_state = "oven_off"
density = TRUE
use_power = IDLE_POWER_USE
idle_power_usage = 5
//layer = BELOW_OBJ_LAYER
circuit = /obj/item/circuitboard/machine/oven
resistance_flags = FIRE_PROOF
///The tray inside of this oven, if there is one.
var/obj/item/plate/oven_tray/used_tray
///Whether or not the oven is open.
var/open = FALSE
///Looping sound for the oven
var/datum/looping_sound/oven/oven_loop
///Current state of smoke coming from the oven
var/smoke_state = OVEN_SMOKE_STATE_NONE
var/current_overlay
/obj/machinery/oven/Initialize(mapload)
. = ..()
oven_loop = new(list(src), FALSE)
if(mapload)
add_tray_to_oven(new /obj/item/plate/oven_tray(src)) //Start with a tray if it's a default one
/obj/machinery/oven/Destroy()
QDEL_NULL(oven_loop)
QDEL_NULL(particles)
. = ..()
/obj/machinery/oven/update_icon_state()
. = ..()
if(panel_open)
icon_state = "oven_o"
return ..()
if(!open && used_tray?.contents.len)
icon_state = "oven_on"
else
icon_state = "oven_off"
/obj/machinery/oven/update_overlays()
. = ..()
var/mutable_appearance/door_overlay
if(open)
door_overlay = mutable_appearance(icon, "oven_lid_open")
door_overlay.pixel_y = OVEN_LID_Y_OFFSET
else
door_overlay = mutable_appearance(icon, "oven_lid_closed")
. += door_overlay
/obj/machinery/oven/process(delta_time)
..()
if(!used_tray) //Are we actually working?
set_smoke_state(OVEN_SMOKE_STATE_NONE)
return
///We take the worst smoke state, so if something is burning we always know.
var/worst_cooked_food_state = 0
for(var/obj/item/baked_item in used_tray.contents)
var/signal_result = SEND_SIGNAL(baked_item, COMSIG_ITEM_BAKED, src, delta_time)
if(signal_result & COMPONENT_HANDLED_BAKING) //This means something responded to us baking!
if(signal_result & COMPONENT_BAKING_GOOD_RESULT && worst_cooked_food_state < OVEN_SMOKE_STATE_GOOD)
worst_cooked_food_state = OVEN_SMOKE_STATE_GOOD
else if(signal_result & COMPONENT_BAKING_BAD_RESULT && worst_cooked_food_state < OVEN_SMOKE_STATE_NEUTRAL)
worst_cooked_food_state = OVEN_SMOKE_STATE_NEUTRAL
continue
worst_cooked_food_state = OVEN_SMOKE_STATE_BAD
baked_item.fire_act(1000) //Hot hot hot!
if(prob(10))
visible_message(span_danger("You smell a burnt smell coming from [src]!"))
set_smoke_state(worst_cooked_food_state)
update_appearance(UPDATE_ICON)
/obj/machinery/oven/attackby(obj/item/I, mob/user, params)
if(open && !used_tray && istype(I, /obj/item/plate/oven_tray))
if(user.transferItemToLoc(I, src))
to_chat(user, span_notice("You put [I] in [src]."))
add_tray_to_oven(I)
else
return ..()
///Adds a tray to the oven, making sure the shit can get baked.
/obj/machinery/oven/proc/add_tray_to_oven(obj/item/plate/oven_tray)
used_tray = oven_tray
if(!open)
oven_tray.vis_flags |= VIS_HIDE
vis_contents += oven_tray
oven_tray.pixel_y = OVEN_TRAY_Y_OFFSET
oven_tray.pixel_x = OVEN_TRAY_X_OFFSET
RegisterSignal(used_tray, COMSIG_MOVABLE_MOVED, PROC_REF(ItemMoved))
update_baking_audio()
update_appearance(UPDATE_ICON)
///Called when the tray is moved out of the oven in some way
/obj/machinery/oven/proc/ItemMoved(obj/item/oven_tray, atom/OldLoc, Dir, Forced)
tray_removed_from_oven(oven_tray)
/obj/machinery/oven/proc/tray_removed_from_oven(obj/item/oven_tray)
vis_contents -= oven_tray
used_tray = null
UnregisterSignal(oven_tray, COMSIG_MOVABLE_MOVED)
update_baking_audio()
/obj/machinery/oven/attack_hand(mob/user, modifiers)
. = ..()
if(panel_open)
to_chat(user, span_notice("The door won't budge with the access panel open!"))
return TRUE
if(!anchored)
to_chat(user, span_notice("The door won't budge with the [src] unsecured!"))
return TRUE
open = !open
if(open)
playsound(src, 'sound/machines/oven/oven_open.ogg', 75, TRUE)
set_smoke_state(OVEN_SMOKE_STATE_NONE)
to_chat(user, span_notice("You open [src]."))
end_processing()
if(used_tray)
used_tray.vis_flags &= ~VIS_HIDE
else
playsound(src, 'sound/machines/oven/oven_close.ogg', 75, TRUE)
to_chat(user, span_notice("You close [src]."))
if(used_tray)
begin_processing()
used_tray.vis_flags |= VIS_HIDE
update_appearance(UPDATE_ICON)
update_baking_audio()
return TRUE
/obj/machinery/oven/attack_robot(mob/user)
. = ..()
if(panel_open)
to_chat(user, span_notice("The door won't budge with the access panel open!"))
return TRUE
if(!anchored)
to_chat(user, span_notice("The door won't budge with the [src] unsecured!"))
return TRUE
open = !open
if(open)
playsound(src, 'sound/machines/oven/oven_open.ogg', 75, TRUE)
set_smoke_state(OVEN_SMOKE_STATE_NONE)
to_chat(user, span_notice("You open [src]."))
end_processing()
if(used_tray)
used_tray.vis_flags &= ~VIS_HIDE
else
playsound(src, 'sound/machines/oven/oven_close.ogg', 75, TRUE)
to_chat(user, span_notice("You close [src]."))
if(used_tray)
begin_processing()
used_tray.vis_flags |= VIS_HIDE
update_appearance(UPDATE_ICON)
update_baking_audio()
return TRUE
/obj/machinery/oven/proc/update_baking_audio()
if(!open && used_tray?.contents.len)
oven_loop.start()
else
oven_loop.stop()
///Updates the smoke state to something else, setting particles if relevant
/obj/machinery/oven/proc/set_smoke_state(new_state)
if(new_state == smoke_state)
return
smoke_state = new_state
QDEL_NULL(particles)
switch(smoke_state)
if(OVEN_SMOKE_STATE_BAD)
particles = new /particles/smoke()
if(OVEN_SMOKE_STATE_NEUTRAL)
particles = new /particles/smoke/steam()
if(OVEN_SMOKE_STATE_GOOD)
particles = new /particles/smoke/steam/mild
/obj/machinery/oven/screwdriver_act(mob/living/user, obj/item/I)
. = ..()
if(open)
to_chat(user,span_notice("The access panel won't budge with the oven open!"))
return TRUE
if(used_tray)
to_chat(user,span_notice("The access panel won't budge with a tray inside!"))
return TRUE
panel_open = !panel_open
update_appearance(UPDATE_ICON)
return TRUE
/obj/machinery/oven/crowbar_act(mob/living/user, obj/item/I)
. = ..()
if(flags_1 & NODECONSTRUCT_1)
return
if(default_deconstruction_crowbar(I))
return
/obj/machinery/oven/wrench_act(mob/living/user, obj/item/I)
..()
if(!panel_open)
return
default_unfasten_wrench(user, I, 2 SECONDS)
return TRUE
/obj/item/plate/oven_tray
name = "oven tray"
desc = "Time to bake cookies!"
icon_state = "oven_tray"
max_items = 6
/particles/smoke/steam/mild
spawning = 1
velocity = list(0, 0.3, 0)
friction = 0.25
/particles/smoke/steam
icon_state = list("steam_1" = 1, "steam_2" = 1, "steam_3" = 2)
fade = 1.5 SECONDS
#undef OVEN_SMOKE_STATE_NONE
#undef OVEN_SMOKE_STATE_GOOD
#undef OVEN_SMOKE_STATE_NEUTRAL
#undef OVEN_SMOKE_STATE_BAD
#undef OVEN_LID_Y_OFFSET
#undef OVEN_TRAY_Y_OFFSET
#undef OVEN_TRAY_X_OFFSET