From 803f865b71ce328380d53e915992604d25b86b9c Mon Sep 17 00:00:00 2001 From: Pantocyclus <98746573+Pantocyclus@users.noreply.github.com> Date: Wed, 23 Feb 2022 01:12:52 +0800 Subject: [PATCH 1/2] Fixed bug when CONSUME ORGANS presents non-capped spleen use When spleen usage is not capped to the spleen limit (e.g. CONSUME SIM ORGANS 10 10 0 NOMEAT), it could previously end up with 10/10/15 spleen usage due to a bug where the diet attempts to "fill" the spleen cleansed by Sliders or Pickle Juices (even though the spleen usage was 0 and nothing was cleansed) This fix adds a buffer to the spleen so that if any cleansers are consumed, there would actually be spleen to be cleansed. Any buffered spleen use is then removed from the end of the diet so that we do not consume past the user-defined limit after cleansing. --- RELEASE/scripts/CONSUME.ash | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/RELEASE/scripts/CONSUME.ash b/RELEASE/scripts/CONSUME.ash index e0a5e52..ff154e6 100644 --- a/RELEASE/scripts/CONSUME.ash +++ b/RELEASE/scripts/CONSUME.ash @@ -817,6 +817,12 @@ void handle_organ_expanders(Diet d, OrganSpace space, OrganSpace max, boolean ni Diet get_diet(OrganSpace space, OrganSpace max, boolean nightcap) { evaluate_consumables_if_needed(); + + //Some foods and booze clear spleen, so this acts as a buffer + //If space.spleen is too low, we might waste those cleanses + //Also fixes a bug where spleen is filled up past the intended limit (test: CONSUME SIM ORGANS 10 10 0 NOMEAT) + int spleen_buffer = spleen_limit() - space.spleen; + if (spleen_buffer > 0) space.spleen = spleen_limit(); Diet d; d.nightcap = nightcap; @@ -853,6 +859,14 @@ Diet get_diet(OrganSpace space, OrganSpace max, boolean nightcap) if(space.fullness > 0) break; } + //Fill spleen again if stomache cleared spleen + //This ensures that if the booze also clears spleen, that wouldn't be wasted + if(space.spleen > 0) + { + fill_spleen(d, space, max); + if(space.spleen > 0) + break; + } if(space.inebriety > 0) { fill_liver(d, space, max); @@ -949,6 +963,22 @@ Diet get_diet(OrganSpace space, OrganSpace max, boolean nightcap) d.insert_action(ode, 0); } + // go through spleen actions from the end and remove usage of our spleen buffer + if (spleen_buffer > 0) + { + for(int i = d.actions.count() - 1; i >= 0; --i) + { + if(d.actions[i].organ == ORGAN_SPLEEN && d.actions[i].space <= spleen_buffer) + { + spleen_buffer -= d.actions[i].space; + d.remove_action(i); + } + if (spleen_buffer <= 0) { + break; + } + } + } + // go through your spleen actions from the end and replace with // sweet synthesis as appropriate if(have_skill($skill[Sweet Synthesis]) && BASE_MEAT > 0) From c3f5f9ff83ccfe8b4ffa8df7a249a59e8d8939e8 Mon Sep 17 00:00:00 2001 From: Pantocyclus <98746573+Pantocyclus@users.noreply.github.com> Date: Thu, 24 Feb 2022 23:38:37 +0800 Subject: [PATCH 2/2] Fixed infinite loop in removing excess spleen buffer usage --- RELEASE/scripts/CONSUME.ash | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/RELEASE/scripts/CONSUME.ash b/RELEASE/scripts/CONSUME.ash index ff154e6..056b457 100644 --- a/RELEASE/scripts/CONSUME.ash +++ b/RELEASE/scripts/CONSUME.ash @@ -968,14 +968,28 @@ Diet get_diet(OrganSpace space, OrganSpace max, boolean nightcap) { for(int i = d.actions.count() - 1; i >= 0; --i) { - if(d.actions[i].organ == ORGAN_SPLEEN && d.actions[i].space <= spleen_buffer) + if(d.actions[i].organ == ORGAN_SPLEEN) { - spleen_buffer -= d.actions[i].space; - d.remove_action(i); - } - if (spleen_buffer <= 0) { - break; - } + if (d.actions[i].space <= spleen_buffer) + { + spleen_buffer -= d.actions[i].space; + d.remove_action(i); + } + else + { + int spaceToFill = d.actions[i].space - spleen_buffer; + spleen_buffer = 0; + d.remove_action(i); + while(spaceToFill > 0) + { + Consumable filler = d.best_spleen(spaceToFill); + spaceToFill -= filler.space; + d.insert_action(filler.to_action(d), i); + ++i; + } + } + } + if (spleen_buffer <= 0) break; } }