[0.171546] Medicine might not affect surgery failures at all

Started by PeteTimesSix, May 24, 2017, 01:59:56 PM

Previous topic - Next topic

PeteTimesSix

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:

    /// <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]
Mods: SimpleSidearms | QOLTweaksPack
Check them out, feedback and suggestions are welcome.

Tynan

Interesting.

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

PeteTimesSix

Quote from: Tynan 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?
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.
Mods: SimpleSidearms | QOLTweaksPack
Check them out, feedback and suggestions are welcome.

Tynan

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

Modo44


BlackSmokeDMax

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

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

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

Wanderer_joins

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.

Tynan

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.
Tynan Sylvester - @TynanSylvester - Tynan's Blog

ison