From b8d814cefed39cb29d8e891e3eace0d91de06c5a Mon Sep 17 00:00:00 2001 From: blueDev2 <89804215+blueDev2@users.noreply.github.com> Date: Tue, 12 Sep 2023 16:54:07 -0400 Subject: [PATCH] Soup recipes that make items spawn the correct number of items (#78120) ## About The Pull Request Soup recipes, that make items, spawn the correct number of items per reaction instead of just one item Soup recipes, that make and consume items, re-add unused reagents Soup recipes that produce no reagents do not delete all required ingredients ## Why It's Good For The Game Soup recipes should be correctly followed, however, there's some issues that happen with a soup recipe creates an item with no corresponding soup reagents. 1. Only 1 item is produced, no matter how many reagents or ingredients are used 2. All ingredients that are required_ingredients are deleted, this is done because the standard soup behavior would have transferred some of the reagents from any "required_ingredients into the soup. However, since no soup is made, the ingredients are wasted. 3. The reagents for the soup recipe itself are consumed to the highest multiple, even if there is insufficient required_ingredients in the pot. This PR ensure the proper number of items are spawned, the proper amount of required_reagents are used, and the proper amount of ingredients are used. Fixes #77821 ## Changelog :cl: fix: Soup recipes, that make items, spawn the correct number of items per reaction instead of just one item fix: Soup recipes, that make items, consumes the correct number of reagents instead of the largest multiple of the reagents /:cl: --------- Co-authored-by: Jacquerel --- .../food_and_drinks/recipes/soup_mixtures.dm | 60 +++++++++++++------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/code/modules/food_and_drinks/recipes/soup_mixtures.dm b/code/modules/food_and_drinks/recipes/soup_mixtures.dm index e298b0274d5d4..ad2caa84ca625 100644 --- a/code/modules/food_and_drinks/recipes/soup_mixtures.dm +++ b/code/modules/food_and_drinks/recipes/soup_mixtures.dm @@ -85,6 +85,34 @@ if(!length(required_ingredients)) return + // If a food item is supposed to be made, remove relevant ingredients from the pot, then make the item + if(!isnull(resulting_food_path)) + var/list/tracked_ingredients + LAZYINITLIST(tracked_ingredients) + var/ingredient_max_multiplier = INFINITY + var/obj/item/reagent_containers/cup/soup_pot/pot = holder.my_atom + + // Tracked ingredients are indexed by type and point to a list containing the actual items + for(var/obj/item/ingredient as anything in pot.added_ingredients) + if(is_type_in_list(ingredient, required_ingredients)) + LAZYADD(tracked_ingredients[ingredient.type],ingredient) + // Find the max number of ingredients that may be used for making the food item + for(var/list/ingredient_type as anything in tracked_ingredients) + ingredient_max_multiplier = min(ingredient_max_multiplier,LAZYLEN(tracked_ingredients[ingredient_type])) + // Create the food items, removing the relavent ingredients at the same time + for(var/i in 1 to (min(created_volume,ingredient_max_multiplier))) + for(var/list/ingredient_type as anything in tracked_ingredients) + var/ingredient = tracked_ingredients[ingredient_type][i] + LAZYREMOVE(pot.added_ingredients,ingredient) + qdel(ingredient) + var/obj/item/created = new resulting_food_path(get_turf(pot)) + created.pixel_y += 8 + // Re-add required reagents that were not used in this step + if(created_volume > ingredient_max_multiplier) + for(var/reagent_path as anything in required_reagents) + holder.add_reagent(reagent_path,(required_reagents[reagent_path])*(created_volume-ingredient_max_multiplier)) + + // This only happens if we're being instant reacted so let's just skip to what we really want if(isnull(reaction)) testing("Soup reaction of type [type] instant reacted, cleaning up.") @@ -113,7 +141,6 @@ /datum/chemical_reaction/food/soup/reaction_step(datum/reagents/holder, datum/equilibrium/reaction, delta_t, delta_ph, step_reaction_vol) if(!length(required_ingredients)) return - testing("Soup reaction step progressing with an increment volume of [step_reaction_vol] and delta_t of [delta_t].") var/obj/item/reagent_containers/cup/soup_pot/pot = holder.my_atom var/list/cached_ingredients = reaction.data["ingredients"] @@ -171,7 +198,7 @@ /** * Cleans up the ingredients and adds whatever leftover reagents to the mixture * - * * holder: The sou ppot + * * holder: The soup pot * * reaction: The reaction being cleaned up, note this CAN be null if being instant reacted * * react_vol: How much soup was produced */ @@ -180,29 +207,26 @@ reaction?.data["ingredients"] = null - for(var/obj/item/ingredient as anything in pot.added_ingredients) - // Let's not mess with indestructible items. - // Chef doesn't need more ways to delete things with cooking. - if(ingredient.resistance_flags & INDESTRUCTIBLE) - continue + // If soup is made, remove ingredients as their reagents were added to the soup + if(react_vol) + for(var/obj/item/ingredient as anything in pot.added_ingredients) + // Let's not mess with indestructible items. + // Chef doesn't need more ways to delete things with cooking. + if(ingredient.resistance_flags & INDESTRUCTIBLE) + continue - // Things that had reagents or ingredients in the soup will get deleted - else if(!isnull(ingredient.reagents) || is_type_in_list(ingredient, required_ingredients)) + // Everything else will just get fried + if(isnull(ingredient.reagents) && !is_type_in_list(ingredient, required_ingredients)) + ingredient.AddElement(/datum/element/fried_item, 30) + continue + + // Things that had reagents or ingredients in the soup will get deleted LAZYREMOVE(pot.added_ingredients, ingredient) // Send everything left behind transfer_ingredient_reagents(ingredient, holder) // Delete, it's done qdel(ingredient) - // Everything else will just get fried - else - ingredient.AddElement(/datum/element/fried_item, 30) - - // Spawning physical food results - if(resulting_food_path) - var/obj/item/created = new resulting_food_path(get_turf(pot)) - created.pixel_y += 8 - // Anything left in the ingredient list will get dumped out pot.dump_ingredients(get_turf(pot), y_offset = 8) // Blackbox log the chemical reaction used, to account for soup reaction that don't produce typical results