vegapnk / RJW-Genes

Rimworld Biotech Genes related to RJW
MIT License
25 stars 28 forks source link

Gene_GenitaliaResizingGene.WasApplied is not stored across saves #34

Closed callavico closed 1 year ago

callavico commented 1 year ago

I have been hunting down an issue where my colonists whose breast sizes have changed seemingly randomly, and I'm pretty sure I've tracked it to here. I just noticed a colonist whose breasts have resized down, and I happened to look at her age and it was her birthday. That sent me looking, and I think I found the issue.

Gene_GenitaliaResizingGene has a bool WasApplied that is set when it runs, either in PostMake, PostAdd, or in the Patch_ResizingOnAdulthood that procs on birthdays. That variable makes sure the gene doesn't run more than once, and it works in a single session, but now that I'm looking at it, there's no way for it to persist between sessions. That means that every time the game is loaded, any pawn with a resizing gene will have it re-execute on their next birthday.

What I think the fix is is adding something like the following to Gene_GenitaliaResizingGene

private bool wasApplied = false;
public bool WasApplied { get => wasApplied; set => wasApplied = value; }

public override void ExposeData()
{
  base.ExposeData();
  Scribe_Values.Look(ref wasApplied, "wasApplied");
}

Scribe_Values can only persist fields, so you have to change WasApplied to be a field-backed property, then you can persist it by overriding ExposeData.

callavico commented 1 year ago

An alternative solution that might fix the presentation, if not the actual problem, is by making each Resize method not be able to resize in the opposite direction, if that makes sense. The method could randomize a size, and then do a check to make sure that the genitalia is resizing in the right direction.

That would require reworking how the SizeAdjuster methods all work, adding a boolean for like "smaller or larger" and doing a check before assiging hediff.Severity, so it might not actually be better in any real way.

vegapnk commented 1 year ago

Thanks for the report !

Yes, I think you found a very good one.

Just for completeness, after some reports #8 and #11 I changed the genes by adding a PostFix to Birthday in https://github.com/vegapnk/RJW-Genes/blob/88f588631c9fe6aa1b8c9b503d25bff243a73d3f/Source/Genes/GenitaliaSize/Patch_ResizingOnAdulthood.cs#L12-L28.

So yes, some kind of persistance would be good ... I have to check where the scribe values end up in the save files and if they look dangerous there. Otherwise there could a simple check for "Birthday = 18th Birthday"

callavico commented 1 year ago

ExposeData would put it in the gene element, so like this

<genes>
  <xenogenes />
  <endogenes>
    <li Class="RJW_Genes.Gene_BigMaleGenitalia">
        <def>rjw_genes_big_male_genitalia</def>
        <pawn>Thing_Human1557650</pawn>
        <overriddenByGene>null</overriddenByGene>
        <loadID>14386</loadID>
        <wasApplied>True</wasApplied>
    </li>
vegapnk commented 1 year ago

I like it a lot, I added it and It should be safe and sound in 1.2 !