Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit b89deb3

Browse files
Deletes unneeded instances to maybe save the server from being overrun by ghost scoops and cones if such a thing is not solved by garbage collection (#22898)
* Deletes unneeded instances * Switched some instancing with colons * gave thanks * uses :: instead of : * fix * undo separate thing --------- Co-authored-by: JohnFulpWillard <[email protected]>
1 parent 60b1e40 commit b89deb3

File tree

1 file changed

+48
-58
lines changed

1 file changed

+48
-58
lines changed

code/modules/food_and_drinks/kitchen_machinery/icecream_vat.dm

Lines changed: 48 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
new /obj/item/circuitboard/machine/icecream_vat)
1313
circuit = /obj/item/circuitboard/machine/icecream_vat
1414
//Ice cream to be dispensed into cone on attackby
15-
var/selected_scoop = null
15+
var/obj/item/reagent_containers/food/snacks/ice_cream_scoop/selected_scoop_type
1616
//Cone to be dispensed with alt click
17-
var/selected_cone = null
17+
var/obj/item/reagent_containers/food/snacks/selected_cone_type
1818
//Max amount of items that can be in vat's storage
1919
var/storage_capacity = 80
2020
//If it starts empty or not
@@ -60,43 +60,44 @@
6060
data["storage"] = list()
6161

6262
//Loop through starting list for data to send to main tab
63-
for(var/item_detail in ui_list)
63+
for(var/obj/item/reagent_containers/food/snacks/item_path as anything in ui_list)
6464

6565
//Create needed list and variable for geting data for UI
6666
var/list/details = list()
67-
var/obj/item/reagent_containers/food/snacks/item = new item_detail
6867

6968
//Get information for UI
70-
details["item_name"] = item.name
71-
details["item_quantity"] = find_amount(item)
72-
details["item_type_path"] = item.type
69+
details["item_name"] = item_path::name
70+
details["item_quantity"] = find_amount(item_path)
71+
details["item_type_path"] = item_path
7372

73+
74+
var/obj/item/reagent_containers/food/snacks/initialized_item = new item_path
7475
//Get an image for the UI
75-
var/icon/item_pic = getFlatIcon(item)
76+
var/icon/item_pic = getFlatIcon(initialized_item)
7677
var/md5 = md5(fcopy_rsc(item_pic))
77-
if(!SSassets.cache["photo_[md5]_[item.name]_icon.png"])
78-
SSassets.transport.register_asset("photo_[md5]_[item.name]_icon.png", item_pic)
79-
SSassets.transport.send_assets(user, list("photo_[md5]_[item.name]_icon.png" = item_pic))
80-
details["item_image"] = SSassets.transport.get_asset_url("photo_[md5]_[item.name]_icon.png")
78+
if(!SSassets.cache["photo_[md5]_[initialized_item.name]_icon.png"])
79+
SSassets.transport.register_asset("photo_[md5]_[initialized_item.name]_icon.png", item_pic)
80+
SSassets.transport.send_assets(user, list("photo_[md5]_[initialized_item.name]_icon.png" = item_pic))
81+
details["item_image"] = SSassets.transport.get_asset_url("photo_[md5]_[initialized_item.name]_icon.png")
8182

8283
//Sort into different data lists depending on what the item is
83-
if(istype(item, /obj/item/reagent_containers/food/snacks/ice_cream_scoop))
84-
details["selected_item"] = selected_scoop
84+
if(ispath(item_path, /obj/item/reagent_containers/food/snacks/ice_cream_scoop))
85+
details["selected_item"] = selected_scoop_type
8586
data["ice_cream"] += list(details)
8687
else
87-
details["selected_item"] = selected_cone
88+
details["selected_item"] = selected_cone_type
8889
data["cones"] += list(details)
90+
qdel(initialized_item)
8991

9092
//Loop through children of /datum/info_tab/icecream_vat for data to send to info tab
91-
for(var/info_detail in subtypesof(/datum/info_tab/icecream_vat))
93+
for(var/datum/info_tab/icecream_vat/info_detail_path as anything in subtypesof(/datum/info_tab/icecream_vat))
9294

9395
//Create needed list and variable for geting data for UI
9496
var/list/details = list()
95-
var/datum/info_tab/icecream_vat/item = new info_detail
9697

9798
//Get info from children
98-
details["section_title"] = item.section
99-
details["section_text"] = item.section_text
99+
details["section_title"] = info_detail_path::section
100+
details["section_text"] = info_detail_path::section_text
100101

101102
//Add info to data
102103
data["info_tab"] += list(details)
@@ -150,26 +151,24 @@
150151
. = ..()
151152

152153
//Selected cones
153-
if(selected_cone == null)
154+
if(selected_cone_type == null)
154155
. += span_notice("You can <b>Alt Click</b> to dispense a cone once one is selected.")
155156
else
156-
var/obj/item/reagent_containers/food/snacks/examine_cone = new selected_cone
157-
. += span_notice("<b>Alt Click</b> to dispense [examine_cone.name].")
157+
. += span_notice("<b>Alt Click</b> to dispense [selected_cone_type::name].")
158158

159159
//Selected scoops
160-
if(selected_scoop == null)
160+
if(selected_scoop_type == null)
161161
. += span_notice("No ice cream scoop currently selected.")
162162
else
163-
var/obj/item/reagent_containers/food/snacks/examine_scoop = new selected_scoop
164-
. += span_notice("[examine_scoop.name] is currently selected.")
163+
. += span_notice("[selected_scoop_type::name] is currently selected.")
165164

166165
//Scooping cone instruction
167166
. += span_notice("<b>Right Click</b> to add a scoop to a cone.")
168167

169168
//For dispensing selected cone
170169
/obj/machinery/icecream_vat/AltClick(mob/living/carbon/user)
171-
if(selected_cone != null)
172-
dispense_item(selected_cone)
170+
if(selected_cone_type != null)
171+
dispense_item(selected_cone_type)
173172
else
174173
user.balloon_alert(user, "None selected!")
175174

@@ -222,60 +221,51 @@
222221

223222
return amount
224223

225-
/obj/machinery/icecream_vat/proc/dispense_item(received_item, mob/user = usr)
226-
227-
//Make a variable for checking the type of the selected item
228-
var/obj/item/reagent_containers/food/snacks/ui_item = new received_item
229-
224+
/obj/machinery/icecream_vat/proc/dispense_item(obj/item/reagent_containers/food/snacks/received_item_type, mob/user = usr)
230225
//If the vat has some of the desired item, dispense it
231-
if(find_amount(ui_item) > 0)
226+
if(find_amount(received_item_type) > 0)
232227
//Select the last(most recent) of desired item
233-
var/obj/item/reagent_containers/food/snacks/dispensed_item = LAZYACCESS(contents, last_index(ui_item))
228+
var/obj/item/reagent_containers/food/snacks/dispensed_item = LAZYACCESS(contents, last_index(received_item_type))
234229
//Drop it on the floor and then move it into the user's hands
235230
dispensed_item.forceMove(loc)
236231
user.put_in_hands(dispensed_item)
237-
user.visible_message(span_notice("[user] dispenses [ui_item.name] from [src]."), span_notice("You dispense [ui_item.name] from [src]."))
232+
user.visible_message(span_notice("[user] dispenses [received_item_type::name] from [src]."), span_notice("You dispense [received_item_type::name] from [src]."))
238233
playsound(src, dispense_sound, 25, TRUE, extrarange = -3)
239234
else
240235
//For Alt click and because UI buttons are slow to disable themselves
241236
user.balloon_alert(user, "All out!")
242237

243-
/obj/machinery/icecream_vat/proc/select_item(received_item, mob/user = usr)
244-
245-
//Make a variable for checking the type of the selected item
246-
var/obj/item/reagent_containers/food/snacks/ui_item = new received_item
247-
238+
/obj/machinery/icecream_vat/proc/select_item(obj/item/reagent_containers/food/snacks/received_item_type, mob/user = usr)
248239
//Deselecting
249-
if(istype(ui_item, /obj/item/reagent_containers/food/snacks/ice_cream_cone))
250-
if(selected_cone == ui_item.type)
251-
user.visible_message(span_notice("[user] deselects [ui_item.name] from [src]."), span_notice("You deselect [ui_item.name] from [src]."))
252-
selected_cone = null
240+
if(ispath(received_item_type, /obj/item/reagent_containers/food/snacks/ice_cream_cone))
241+
if(selected_cone_type == received_item_type)
242+
user.visible_message(span_notice("[user] deselects [received_item_type::name] from [src]."), span_notice("You deselect [received_item_type::name] from [src]."))
243+
selected_cone_type = null
253244
playsound(src, select_sound, 25, TRUE, extrarange = -3)
254-
255245
return
256-
else if(selected_scoop == ui_item.type)
257-
user.visible_message(span_notice("[user] deselects [ui_item.name] from [src]."), span_notice("You deselect [ui_item.name] from [src]."))
258-
selected_scoop = null
259-
playsound(src, select_sound, 25, TRUE, extrarange = -3)
260246

247+
else if(selected_scoop_type == received_item_type)
248+
user.visible_message(span_notice("[user] deselects [received_item_type::name] from [src]."), span_notice("You deselect [received_item_type::name] from [src]."))
249+
selected_scoop_type = null
250+
playsound(src, select_sound, 25, TRUE, extrarange = -3)
261251
return
262252

263253
//Selecting
264-
if(find_amount(ui_item.type) > 0)
254+
if(find_amount(received_item_type) > 0)
265255
//Set item to selected based on its type
266-
if(istype(ui_item, /obj/item/reagent_containers/food/snacks/ice_cream_cone))
267-
selected_cone = ui_item.type
256+
if(ispath(received_item_type, /obj/item/reagent_containers/food/snacks/ice_cream_cone))
257+
selected_cone_type = received_item_type
268258
else
269-
selected_scoop = ui_item.type
259+
selected_scoop_type = received_item_type
270260
playsound(src, select_sound, 25, TRUE, extrarange = -3)
271-
user.visible_message(span_notice("[user] sets [src] to dispense [ui_item.name]s."), span_notice("You set [src] to dispense [ui_item.name]s."))
261+
user.visible_message(span_notice("[user] sets [src] to dispense [received_item_type::name]s."), span_notice("You set [src] to dispense [received_item_type::name]s."))
272262
//Prevent them from selecting items that the vat does not have
273263
else
274264
user.balloon_alert(user, "All out!")
275265

276266
/obj/machinery/icecream_vat/proc/last_index(obj/item/search_item)
277267

278-
var/obj/item/reagent_containers/food/snacks/item_index = null
268+
var/obj/item/reagent_containers/food/snacks/item_index
279269

280270
//Search for the same item path in storage
281271
for(var/i in 1 to LAZYLEN(contents))
@@ -342,13 +332,13 @@
342332
if(istype(target_cone, /obj/item/reagent_containers/food/snacks/ice_cream_cone))
343333
var/obj/item/reagent_containers/food/snacks/ice_cream_cone/cone = target_cone
344334
//Check if a scoop has been selected
345-
if(selected_scoop != null)
335+
if(selected_scoop_type != null)
346336
//Check if there are any of selected scoop in contents
347-
if(find_amount(selected_scoop) > 0)
337+
if(find_amount(selected_scoop_type) > 0)
348338
//Increase scooped variable
349339
cone.scoops += 1
350340
//Select last of selected scoop in contents
351-
var/obj/item/reagent_containers/food/snacks/cone_scoop = LAZYACCESS(contents, last_index(selected_scoop))
341+
var/obj/item/reagent_containers/food/snacks/cone_scoop = LAZYACCESS(contents, last_index(selected_scoop_type))
352342
//Remove scoop from contents
353343
cone_scoop.forceMove(loc)
354344
//Increase maximum volume to make room for scoop's chems

0 commit comments

Comments
 (0)