Ludeon Forums

Ludeon Forums

  • October 07, 2022, 12:34:16 PM
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [0.171546] Medicine might not affect surgery failures at all  (Read 4507 times)

PeteTimesSix

  • Drifter
  • **
  • Posts: 53
  • I'll be back.
    • View Profile

Bold claim, I know.

First off, a disclaimer: I've been digging through the code using a mod and I realise that I'm not supposed to post bugs in modded games, so its possible the issue is somewhere in HugsLib or Harmony. However, with such a simple test-case I kind of doubt it (and considering how many A17 mods use those libraries I figure it's its still pretty important to find out if that's the case), and if I'm wrong it should take one Log.Message(GetAverageMedicalPotency(ingredients)) in the right place to find out.

I think the game uses a default value instead of the medicine potency stat when it comes to determining surgery failure rates.

Ive spent the last five hours trying to figure out what I'm missing, but my best guess as to what happens: By the time the Recipe_Surgery class gets around to checking wherever a surgery failed (in CheckSurgeryFail), the ingredients list no longer actually contains the medicine used for the surgery (since the surgeon always brings one unit of it, which is consumed when the surgery begins), and thus GetAverageMedicalPotency always returns 1f. This is somewhat hard to notice since that happens to match regular medicine and actually makes herbal medicine *better*, but it makes glitterworld medicine much worse than it should be for surgeries specifically.

I've attached the test mod I've been using, stripped down to bare essentials (requires HugsLib as I need Harmony prefix/postixes for this), and a convenient save file with a surgery about to begin can be found here. The code of the test mod is:

Code: [Select]
    /// <summary>
    /// List out ingredients right before surgery fail check (which makes use of them)
    /// </summary>
    [HarmonyPatch(typeof(Recipe_Surgery), "CheckSurgeryFail")]
    static class Test_Prefix
    {
        [HarmonyPrefix]
        private static void CheckSurgeryFail(Recipe_Surgery __instance, Pawn surgeon, Pawn patient, List<Thing> ingredients, BodyPartRecord part)
        {
            Log.Message("ingredients for surgery on "+patient);
            foreach (Thing ing in ingredients)
            {
                Log.Message(ing.LabelShort);
            }
        }
    }

    /// <summary>
    /// Print average medical potency result to log
    /// </summary>
    [HarmonyPatch(typeof(Recipe_Surgery), "GetAverageMedicalPotency")]
    static class Test2_Postfix
    {
        [HarmonyPostfix]
        private static void GetAverageMedicalPotency(Recipe_Surgery __instance, List<Thing> ingredients, ref float __result)
        {
            Log.Message("avg. medical potency result is "+__result);
        }
    }

    /// <summary>
    /// Force all glitterworld medicine to be obnoxiously good
    /// </summary>
    [HarmonyPatch(typeof(StatWorker), "GetValue")]
    [HarmonyPatch(new Type[] { typeof(Thing), typeof(bool) })]
    static class Test3_Postfix
    {
        [HarmonyPostfix]
        private static void GetValue(StatWorker __instance, Thing thing, bool applyPostProcess, ref float __result)
        {
            StatDef stat = Traverse.Create(__instance).Field("stat").GetValue<StatDef>() as StatDef;
            if(StatDefOf.MedicalPotency.Equals(stat))
            {
                if (thing is Medicine)
                {
                    if ((thing as Medicine).def == ThingDefOf.GlitterworldMedicine)
                    {
                        __result = 9999.0f;
                        Log.Message("Forced glitterworldMedicine potency to:" + __result);
                    }
                }
            }           
        }
    }



Of course I could be hilariously wrong, in which case I genuinely have no idea how the GetAverageMedicalPotency method actually gets the right ingredient list.

[attachment deleted by admin due to age]
Logged
Mods: SimpleSidearms | QOLTweaksPack
Check them out, feedback and suggestions are welcome.

Tynan

  • Developer
  • Administrator
  • Transcendent
  • *****
  • Posts: 12484
    • View Profile
    • Tynan's Blog
Re: [0.171546] Medicine might not affect surgery failures at all
« Reply #1 on: May 24, 2017, 02:46:13 PM »

Interesting.

So to clarify, it's possible medicine doesn't affect surgery, but we know it does affect tending, right?
Logged
Tynan Sylvester - @TynanSylvester - Tynan's Blog

PeteTimesSix

  • Drifter
  • **
  • Posts: 53
  • I'll be back.
    • View Profile
Re: [0.171546] Medicine might not affect surgery failures at all
« Reply #2 on: May 24, 2017, 03:00:46 PM »

Interesting.

So to clarify, it's possible medicine doesn't affect surgery, but we know it does affect tending, right?
Ill admit to not checking the tending code (the mod I was working on was surgery-specific), but from a quick search through the decompiled code just now, plus a short test where a pawn tending a single injury (thus using a single medicine) only used up that medicine after finishing and applied a nice 100% white bandage despite having only a 3 in medicine skill, Ill guess yes.
Logged
Mods: SimpleSidearms | QOLTweaksPack
Check them out, feedback and suggestions are welcome.

Tynan

  • Developer
  • Administrator
  • Transcendent
  • *****
  • Posts: 12484
    • View Profile
    • Tynan's Blog
Re: [0.171546] Medicine might not affect surgery failures at all
« Reply #3 on: May 24, 2017, 03:02:35 PM »

Well darn, I wish we'd fixed this. Oh well. I guess A17 will have a medical bug :p
Logged
Tynan Sylvester - @TynanSylvester - Tynan's Blog

Modo44

  • Drifter
  • **
  • Posts: 82
  • Refugee
    • View Profile
Re: [0.171546] Medicine might not affect surgery failures at all
« Reply #4 on: May 25, 2017, 05:07:23 AM »

So much for the bugfix release lol
Logged

BlackSmokeDMax

  • Planetologist
  • ****
  • Posts: 1734
  • Don't Have To Live Like A...
    • View Profile
Re: [0.171546] Medicine might not affect surgery failures at all
« Reply #5 on: May 25, 2017, 10:13:28 AM »

LOL, pretty darn funny. Ended up going from A16 where medicine was *everything*, to A17 where it is nothing. A18 for the medical win!

Tynan, you could write a quick little "official mod", or have one of your minions do it ;)

Tynan

  • Developer
  • Administrator
  • Transcendent
  • *****
  • Posts: 12484
    • View Profile
    • Tynan's Blog
Re: [0.171546] Medicine might not affect surgery failures at all
« Reply #6 on: May 25, 2017, 02:21:27 PM »

It's likely this bug was present in A16 as well.

It only affects surgeries, not tending. Most medical interaction is tending.
Logged
Tynan Sylvester - @TynanSylvester - Tynan's Blog

Wanderer_joins

  • Colonist
  • ***
  • Posts: 409
  • Refugee
    • View Profile
Re: [0.171546] Medicine might not affect surgery failures at all
« Reply #7 on: June 02, 2017, 03:50:25 AM »

I thought it was intentional. Everyone complained surgery could be summed up to glitt meds in A16, and with glitt meds buffed to 200% in A17 could make it worse. Now it depends on your surgeon skills and room stats, so a healthy level 8-9 doctor in a sterile room should succeed.

What's confusing is the surgery requires medicine, it makes sense irl to decrease the infection chance, not to impact the surgery success chance.
Logged

Tynan

  • Developer
  • Administrator
  • Transcendent
  • *****
  • Posts: 12484
    • View Profile
    • Tynan's Blog
Re: [0.171546] Medicine might not affect surgery failures at all
« Reply #8 on: June 02, 2017, 03:54:46 AM »

Medicine should still affect surgery success chance, just not in a simple "multiply the chance" way; it needs to be a factor lerped from perhaps 70% through 130% out, with 0%-200% in.
Logged
Tynan Sylvester - @TynanSylvester - Tynan's Blog

ison

  • Developer
  • Planetologist
  • *****
  • Posts: 2434
    • View Profile
Re: [0.171546] Medicine might not affect surgery failures at all
« Reply #9 on: August 29, 2017, 07:31:44 AM »

Fixed for A18, thanks.
Logged