[HELP] Recipes_Surgery.xml

Started by DarknessEyes, April 15, 2016, 03:52:03 PM

Previous topic - Next topic

DarknessEyes

Those values do what?
<surgeonSurgerySuccessChanceExponent>
<roomSurgerySuccessChanceFactorExponent>
<surgerySuccessChanceFactor>
<deathOnFailedSurgeryChance>

How do you get the real success/failure chance?
De Surgeries
https://ludeon.com/forums/index.php?topic=18976.0
Adds 26 new surgeries to Rimworld.

RawCode

take all factors and account?

if you want static rolls, like fixed 50% chance, you will need custom surgery implementation, in other case you will hit nan exception.

DarknessEyes

Quote from: RawCode on April 16, 2016, 08:53:17 AM
take all factors and account?

if you want static rolls, like fixed 50% chance, you will need custom surgery implementation, in other case you will hit nan exception.

<surgeonSurgerySuccessChanceExponent> If i set this value to 2 it will increase success chance by 2% * medicine skill?
<roomSurgerySuccessChanceFactorExponent> If i set this value to 2 it will increase success chance by 2%?
De Surgeries
https://ludeon.com/forums/index.php?topic=18976.0
Adds 26 new surgeries to Rimworld.

DarknessEyes

Quote from: DarknessEyes on April 16, 2016, 11:39:24 AM
<surgeonSurgerySuccessChanceExponent> If i set this value to 2 it will increase success chance by 2% * medicine skill?
<roomSurgerySuccessChanceFactorExponent> If i set this value to 2 it will increase success chance by 2%?

No one know this?

Also the medicine/beds/medical level affect surgerySuccessChanceFactor if the above is not set?
De Surgeries
https://ludeon.com/forums/index.php?topic=18976.0
Adds 26 new surgeries to Rimworld.

RawCode

will your computer explode and evaporate 100 km around if you test it self?

DarknessEyes

Quote from: RawCode on April 17, 2016, 11:12:02 AM
will your computer explode and evaporate 100 km around if you test it self?

Kinda hard to test chances. For that i have to load a game and do the surgery at least 100 times to get a valid % result.
This X all the 4 fields.
De Surgeries
https://ludeon.com/forums/index.php?topic=18976.0
Adds 26 new surgeries to Rimworld.

Raccoon

just make the value 100 and 0 and 50 and test it 10 times each is simpler and shoud work but how you told 100x 1 is better.

Deon

I am kinda wondering about various chances in the game as well, just learning defs. Is there an easy way to display rolls in the console, to see the chance rolls and extra info? Or do I need to look into code to check it out, and there is no way to just toggle "logging" in the game itself? Sorry if the question is too simple/stupid, I am still kinda lost :).

Shabazza

Any results yet?
I'm too curious what those values mean.
Especially the first ones:

<surgeonSurgerySuccessChanceExponent>
<roomSurgerySuccessChanceFactorExponent>

DarknessEyes

Quote from: Shabazza on April 23, 2016, 05:25:07 AM
Any results yet?
I'm too curious what those values mean.
Especially the first ones:

<surgeonSurgerySuccessChanceExponent>
<roomSurgerySuccessChanceFactorExponent>

<surgeonSurgerySuccessChanceExponent> is used in default game "Remove carcinoma".
i THINK its the base % of surgery success + the bonus of medicine level, medicines used and room bonuses stack with this.

If you doesnt use this the surgeries still can fail, so i guess there is a default unknown value for this.

<roomSurgerySuccessChanceFactorExponent>
I THINK its a bonus % of surgery success based on the room (sterile floor).
De Surgeries
https://ludeon.com/forums/index.php?topic=18976.0
Adds 26 new surgeries to Rimworld.

kaptain_kavern

#10
I found this piece of code while digging in the Assembly

using System;
using System.Collections.Generic;
using UnityEngine;
using Verse;

namespace RimWorld
{
public abstract class Recipe_MedicalOperation : RecipeWorker
{
//
// Static Fields
//
private const float CatastrophicFailChance = 0.5f;

//
// Methods
//
protected bool CheckSurgeryFail (Pawn surgeon, Pawn patient, List<Thing> ingredients)
{
if (surgeon == null) {
Log.Error ("surgeon is null");
return false;
}
if (patient == null) {
Log.Error ("patient is null");
return false;
}
float num = 1f;
float num2 = surgeon.GetStatValue (StatDefOf.SurgerySuccessChance, true);
if (num2 < 1f) {
num2 = Mathf.Pow (num2, this.recipe.surgeonSurgerySuccessChanceExponent);
}
num *= num2;
Room room = surgeon.GetRoom ();
if (room != null) {
float num3 = room.GetStat (RoomStatDefOf.SurgerySuccessChanceFactor);
if (num3 < 1f) {
num3 = Mathf.Pow (num3, this.recipe.roomSurgerySuccessChanceFactorExponent);
}
num *= num3;
}
num *= this.GetAverageMedicalPotency (ingredients);
num *= this.recipe.surgerySuccessChanceFactor;
if (Rand.Value > num) {
if (Rand.Value < this.recipe.deathOnFailedSurgeryChance) {
int num4 = 0;
while (!patient.Dead) {
HealthUtility.GiveInjuriesOperationFailureCatastrophic (patient);
num4++;
if (num4 > 300) {
Log.Error ("Could not kill patient.");
break;
}
}
}
else if (Rand.Value < 0.5f) {
Messages.Message ("MessageMedicalOperationFailureCatastrophic".Translate (new object[] {
surgeon.LabelShort,
patient.LabelShort
}), patient, MessageSound.SeriousAlert);
HealthUtility.GiveInjuriesOperationFailureCatastrophic (patient);
}
else {
Messages.Message ("MessageMedicalOperationFailureMinor".Translate (new object[] {
surgeon.LabelShort,
patient.LabelShort
}), patient, MessageSound.Negative);
HealthUtility.GiveInjuriesOperationFailureMinor (patient);
}
if (!patient.Dead) {
this.TryGainBotchedSurgeryThought (patient, surgeon);
}
return true;
}
return false;
}

private float GetAverageMedicalPotency (List<Thing> ingredients)
{
if (ingredients.NullOrEmpty<Thing> ()) {
return 1f;
}
int num = 0;
float num2 = 0f;
for (int i = 0; i < ingredients.Count; i++) {
Medicine medicine = ingredients [i] as Medicine;
if (medicine != null) {
num += medicine.stackCount;
num2 += medicine.GetStatValue (StatDefOf.MedicalPotency, true) * (float)medicine.stackCount;
}
}
if (num == 0) {
return 1f;
}
return num2 / (float)num;
}

private void TryGainBotchedSurgeryThought (Pawn patient, Pawn surgeon)
{
if (!patient.RaceProps.Humanlike) {
return;
}
patient.needs.mood.thoughts.memories.TryGainMemoryThought (ThoughtDefOf.BotchedMySurgery, surgeon);
}
}
}


and i suspect that is where the magic happened :p

But i'm still trying to understand what that means as i just learned how to access it yesterday ;-)




Also found this in devmode ( "Show all Room Stat" options) :


and this in "Information" Tab :

kaptain_kavern

In "/Core/Defs/StatDefs/Stats_Pawns_WorkMedical.xml" :

<?xml version="1.0" encoding="utf-8" ?>
<Defs>

  <StatDef>
    <defName>MedicalOperationSpeed</defName>
    <label>medical operation speed</label>
    <description>Speed at which the character performs medical operations.</description>
    <category>PawnWork</category>
    <defaultBaseValue>1</defaultBaseValue>
    <toStringStyle>PercentZero</toStringStyle>
    <skillNeedFactors>
      <li Class="SkillNeed_BaseBonus">
        <skill>Medicine</skill>
        <baseFactor>0.4</baseFactor>
        <bonusFactor>0.06</bonusFactor>
      </li>
    </skillNeedFactors>
    <capacityFactors>
      <li>
        <capacity>Consciousness</capacity>
        <weight>1</weight>
      </li>
      <li>
        <capacity>Sight</capacity>
        <weight>0.7</weight>
      </li>
      <li>
        <capacity>Manipulation</capacity>
        <weight>0.9</weight>
      </li>
    </capacityFactors>
  </StatDef>

  <StatDef>
    <defName>SurgerySuccessChance</defName>
    <label>surgery success chance</label>
    <description>The likelihood that a character will succeed when attempting to perform a surgery. Failures can result in simple wasted time and medicine, or catastrophic damage to the patient.</description>
    <category>PawnWork</category>
    <defaultBaseValue>1.00</defaultBaseValue>
    <toStringStyle>PercentZero</toStringStyle>
    <skillNeedFactors>
      <li Class="SkillNeed_Direct">
        <skill>Medicine</skill>
        <factorsPerLevel>
          <li>0.05</li>
          <li>0.25</li>
          <li>0.40</li>
          <li>0.50</li>
          <li>0.60</li>
          <li>0.70</li>
          <li>0.80</li>
          <li>0.85</li>
          <li>0.90</li>
          <li>0.92</li>
          <li>0.93</li>
          <li>0.94</li>
          <li>0.95</li>
          <li>0.955</li>
          <li>0.96</li>
          <li>0.965</li>
          <li>0.97</li>
          <li>0.975</li>
          <li>0.98</li>
          <li>0.985</li>
          <li>0.99</li>
        </factorsPerLevel>
      </li>
    </skillNeedFactors>
    <capacityFactors>
      <li>
        <capacity>Consciousness</capacity>
        <weight>1</weight>
      </li>
      <li>
        <capacity>Sight</capacity>
        <weight>0.4</weight>
      </li>
      <li>
        <capacity>Manipulation</capacity>
        <weight>0.4</weight>
      </li>
    </capacityFactors>
  </StatDef>

  <StatDef>
    <defName>BaseHealingQuality</defName>
    <label>base healing quality</label>
    <description>Base quality of treatment given to patients when acting as a doctor.</description>
    <category>PawnWork</category>
    <defaultBaseValue>1</defaultBaseValue>
    <toStringStyle>PercentZero</toStringStyle>
    <skillNeedFactors>
      <li Class="SkillNeed_Direct">
        <skill>Medicine</skill>
        <factorsPerLevel>
          <li>0.10</li>
          <li>0.30</li>
          <li>0.50</li>
          <li>0.60</li>
          <li>0.70</li>
          <li>0.80</li>
          <li>0.90</li>
          <li>0.95</li>
          <li>1.00</li>
          <li>1.05</li>
          <li>1.10</li>
          <li>1.15</li>
          <li>1.20</li>
          <li>1.25</li>
          <li>1.30</li>
          <li>1.35</li>
          <li>1.40</li>
          <li>1.45</li>
          <li>1.50</li>
          <li>1.55</li>
          <li>1.60</li>
        </factorsPerLevel>
      </li>
    </skillNeedFactors>
    <capacityFactors>
      <li>
        <capacity>Sight</capacity>
        <weight>0.7</weight>
      </li>
      <li>
        <capacity>Manipulation</capacity>
        <weight>0.9</weight>
      </li>
    </capacityFactors>
  </StatDef>

  <StatDef>
    <defName>HealingSpeed</defName>
    <label>healing speed</label>
    <description>Speed at which the character heals wounds as a doctor.</description>
    <category>PawnWork</category>
    <defaultBaseValue>1</defaultBaseValue>
    <toStringStyle>PercentZero</toStringStyle>
    <skillNeedFactors>
      <li Class="SkillNeed_BaseBonus">
        <skill>Medicine</skill>
        <baseFactor>0.4</baseFactor>
        <bonusFactor>0.06</bonusFactor>
      </li>
    </skillNeedFactors>
    <capacityFactors>
      <li>
        <capacity>Consciousness</capacity>
        <weight>1</weight>
      </li>
      <li>
        <capacity>Sight</capacity>
        <weight>0.8</weight>
      </li>
      <li>
        <capacity>Manipulation</capacity>
        <weight>0.9</weight>
      </li>
    </capacityFactors>
  </StatDef>

</Defs>