Skip to content

Commit

Permalink
Soup recipes that make items spawn the correct number of items (tgsta…
Browse files Browse the repository at this point in the history
…tion#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 tgstation#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 <[email protected]>
  • Loading branch information
blueDev2 and Jacquerel authored Sep 12, 2023
1 parent 7b34ac1 commit b8d814c
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions code/modules/food_and_drinks/recipes/soup_mixtures.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand 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"]
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
Expand Down

0 comments on commit b8d814c

Please sign in to comment.