]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix egg cooking and make microwave code a little less bad (#35459)
authorslarticodefast <161409025+slarticodefast@users.noreply.github.com>
Thu, 27 Feb 2025 12:39:06 +0000 (13:39 +0100)
committerGitHub <noreply@github.com>
Thu, 27 Feb 2025 12:39:06 +0000 (23:39 +1100)
Content.Server/Kitchen/Components/ActivelyMicrowavedComponent.cs
Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs
Resources/Prototypes/Entities/Objects/Consumable/Food/egg.yml
Resources/Prototypes/Recipes/Construction/Graphs/food/egg.yml
Resources/Prototypes/Recipes/Cooking/meal_recipes.yml

index 54a7edd745497f6f1713654e1f968c6a56bd32be..c7fca5a47e57e973240850d460dad081e823ba9c 100644 (file)
@@ -1,5 +1,3 @@
-using Content.Shared.Kitchen;
-
 namespace Content.Server.Kitchen.Components;
 
 /// <summary>
@@ -8,4 +6,9 @@ namespace Content.Server.Kitchen.Components;
 [RegisterComponent]
 public sealed partial class ActivelyMicrowavedComponent : Component
 {
+    /// <summary>
+    /// The microwave this entity is actively being microwaved by.
+    /// </summary>
+    [DataField]
+    public EntityUid? Microwave;
 }
index 1ac02ac88258a83ccd9949403d6b71c5c1adee98..7f0778cbdd939d67599b00a6979f6d8e4103545b 100644 (file)
@@ -14,6 +14,7 @@ using Content.Shared.Body.Components;
 using Content.Shared.Body.Part;
 using Content.Shared.Chemistry.Components.SolutionManager;
 using Content.Shared.Chemistry.EntitySystems;
+using Content.Shared.Chemistry.Reaction;
 using Content.Shared.Construction.EntitySystems;
 using Content.Shared.Database;
 using Content.Shared.Destructible;
@@ -101,6 +102,7 @@ namespace Content.Server.Kitchen.EntitySystems
             SubscribeLocalEvent<ActiveMicrowaveComponent, EntRemovedFromContainerMessage>(OnActiveMicrowaveRemove);
 
             SubscribeLocalEvent<ActivelyMicrowavedComponent, OnConstructionTemperatureEvent>(OnConstructionTemp);
+            SubscribeLocalEvent<ActivelyMicrowavedComponent, SolutionRelayEvent<ReactionAttemptEvent>>(OnReactionAttempt);
 
             SubscribeLocalEvent<FoodRecipeProviderComponent, GetSecretRecipesEvent>(OnGetSecretRecipes);
         }
@@ -126,7 +128,8 @@ namespace Content.Server.Kitchen.EntitySystems
 
         private void OnActiveMicrowaveInsert(Entity<ActiveMicrowaveComponent> ent, ref EntInsertedIntoContainerMessage args)
         {
-            AddComp<ActivelyMicrowavedComponent>(args.Entity);
+            var microwavedComp = AddComp<ActivelyMicrowavedComponent>(args.Entity);
+            microwavedComp.Microwave = ent.Owner;
         }
 
         private void OnActiveMicrowaveRemove(Entity<ActiveMicrowaveComponent> ent, ref EntRemovedFromContainerMessage args)
@@ -134,10 +137,33 @@ namespace Content.Server.Kitchen.EntitySystems
             EntityManager.RemoveComponentDeferred<ActivelyMicrowavedComponent>(args.Entity);
         }
 
+        // Stop items from transforming through constructiongraphs while being microwaved.
+        // They might be reserved for a microwave recipe.
         private void OnConstructionTemp(Entity<ActivelyMicrowavedComponent> ent, ref OnConstructionTemperatureEvent args)
         {
             args.Result = HandleResult.False;
-            return;
+        }
+
+        // Stop reagents from reacting if they are currently reserved for a microwave recipe.
+        // For example Egg would cook into EggCooked, causing it to not being removed once we are done microwaving.
+        private void OnReactionAttempt(Entity<ActivelyMicrowavedComponent> ent, ref SolutionRelayEvent<ReactionAttemptEvent> args)
+        {
+            if (!TryComp<ActiveMicrowaveComponent>(ent.Comp.Microwave, out var activeMicrowaveComp))
+                return;
+
+            if (activeMicrowaveComp.PortionedRecipe.Item1 == null) // no recipe selected
+                return;
+
+            var recipeReagents = activeMicrowaveComp.PortionedRecipe.Item1.IngredientsReagents.Keys;
+
+            foreach (var reagent in recipeReagents)
+            {
+                if (args.Event.Reaction.Reactants.ContainsKey(reagent))
+                {
+                    args.Event.Cancelled = true;
+                    return;
+                }
+            }
         }
 
         /// <summary>
@@ -176,33 +202,29 @@ namespace Content.Server.Kitchen.EntitySystems
             // this is spaghetti ngl
             foreach (var item in component.Storage.ContainedEntities)
             {
-                if (!TryComp<SolutionContainerManagerComponent>(item, out var solMan))
+                // use the same reagents as when we selected the recipe
+                if (!_solutionContainer.TryGetDrainableSolution(item, out var solutionEntity, out var solution))
                     continue;
 
-                // go over every solution
-                foreach (var (_, soln) in _solutionContainer.EnumerateSolutions((item, solMan)))
+                foreach (var (reagent, _) in recipe.IngredientsReagents)
                 {
-                    var solution = soln.Comp.Solution;
-                    foreach (var (reagent, _) in recipe.IngredientsReagents)
-                    {
-                        // removed everything
-                        if (!totalReagentsToRemove.ContainsKey(reagent))
-                            continue;
+                    // removed everything
+                    if (!totalReagentsToRemove.ContainsKey(reagent))
+                        continue;
 
-                        var quant = solution.GetTotalPrototypeQuantity(reagent);
+                    var quant = solution.GetTotalPrototypeQuantity(reagent);
 
-                        if (quant >= totalReagentsToRemove[reagent])
-                        {
-                            quant = totalReagentsToRemove[reagent];
-                            totalReagentsToRemove.Remove(reagent);
-                        }
-                        else
-                        {
-                            totalReagentsToRemove[reagent] -= quant;
-                        }
-
-                        _solutionContainer.RemoveReagent(soln, reagent, quant);
+                    if (quant >= totalReagentsToRemove[reagent])
+                    {
+                        quant = totalReagentsToRemove[reagent];
+                        totalReagentsToRemove.Remove(reagent);
+                    }
+                    else
+                    {
+                        totalReagentsToRemove[reagent] -= quant;
                     }
+
+                    _solutionContainer.RemoveReagent(solutionEntity.Value, reagent, quant);
                 }
             }
 
@@ -541,7 +563,8 @@ namespace Content.Server.Kitchen.EntitySystems
                     continue;
                 }
 
-                AddComp<ActivelyMicrowavedComponent>(item);
+                var microwavedComp = AddComp<ActivelyMicrowavedComponent>(item);
+                microwavedComp.Microwave = uid;
 
                 string? solidID = null;
                 int amountToAdd = 1;
@@ -560,33 +583,20 @@ namespace Content.Server.Kitchen.EntitySystems
                 }
 
                 if (solidID is null)
-                {
                     continue;
-                }
-
 
-                if (solidsDict.ContainsKey(solidID))
-                {
+                if (!solidsDict.TryAdd(solidID, amountToAdd))
                     solidsDict[solidID] += amountToAdd;
-                }
-                else
-                {
-                    solidsDict.Add(solidID, amountToAdd);
-                }
 
-                if (!TryComp<SolutionContainerManagerComponent>(item, out var solMan))
+                // only use reagents we have access to
+                // you have to break the eggs before we can use them!
+                if (!_solutionContainer.TryGetDrainableSolution(item, out var _, out var solution))
                     continue;
 
-                foreach (var (_, soln) in _solutionContainer.EnumerateSolutions((item, solMan)))
+                foreach (var (reagent, quantity) in solution.Contents)
                 {
-                    var solution = soln.Comp.Solution;
-                    foreach (var (reagent, quantity) in solution.Contents)
-                    {
-                        if (reagentDict.ContainsKey(reagent.Prototype))
-                            reagentDict[reagent.Prototype] += quantity;
-                        else
-                            reagentDict.Add(reagent.Prototype, quantity);
-                    }
+                    if (!reagentDict.TryAdd(reagent.Prototype, quantity))
+                        reagentDict[reagent.Prototype] += quantity;
                 }
             }
 
index a4593d50063c25b5a59683bd169852009025172d..7228a213666183befe3867620af5b5db8a8c9e95 100644 (file)
@@ -11,7 +11,7 @@
       - Egg
       - Meat
   - type: Food
-    trash: 
+    trash:
     - Eggshells
   - type: Sprite
     sprite: Objects/Consumable/Food/egg.rsi
   # all below are for egg cooking/exploding
   - type: AtmosExposed
   - type: Temperature
-    currentTemperature: 290
-  - type: InternalTemperature
-    # ~1mm shell and ~1cm of albumen
-    thickness: 0.011
-    area: 0.04
-    # conductivity of egg shell based on a paper from Romanoff and Romanoff (1949)
-    conductivity: 0.456
 
 # Splat
 - type: entity
   - type: Temperature
     # preserve temperature from the boiling step
     currentTemperature: 344
-  - type: Construction
-    graph: Egg
-    node: boiled
index 3c3bca2585a2a2b52f9414a3988f955d3a0fd61e..71a4a65021c6f07684de20cae4f15a0418ed5354 100644 (file)
@@ -4,12 +4,6 @@
   start: start
   graph:
   - node: start
-    edges:
-    - to: boiled
-      steps:
-      - minTemperature: 344
-  - node: boiled
-    entity: FoodEggBoiled
     edges:
     - to: explode
       completed:
@@ -18,6 +12,7 @@
           types:
             Blunt: 10
       steps:
-      # egg explodes some time after the water in it boils and increases pressure, guessing ~110C
-      - minTemperature: 383
+      # egg explodes some time after the water in it boils and increases pressure
+      # high enough so you can still microwave them for 5 seconds safely
+      - minTemperature: 473.15 # 200°C
   - node: explode
index c3a5012ac099956127f9dbd2849bcbebc43d2650..f8970a51194e66b8c5225dc7374c71bfd8e58057 100644 (file)
   result: FoodBurgerMcguffin
   time: 10
   group: Savory
+  reagents:
+    Egg: 12
   solids:
     FoodBreadBun: 1
     FoodCheeseSlice: 1
-    FoodEgg: 2
 
 - type: microwaveMealRecipe
   id: RecipeBurgerMcrib
   group: Savory
   reagents:
     TableSalt: 5
+    Egg: 12
   solids:
     FoodBreadBun: 1
     FoodMeat: 2
     FoodCheeseSlice: 2
     FoodTomato: 2
-    FoodEgg: 2
 
 - type: microwaveMealRecipe
   id: RecipeTofuBurger