SOLVED - [Mod Request] Push backstories down to <PawnKindDef> level

Started by o-o-o, January 19, 2018, 08:25:14 PM

Previous topic - Next topic

o-o-o

Preface - I am currently modding XML files only.  I aspire to move to C# coding at some point, but have been working to push my mod ideas as far as I can using XML before making the leap into coding. But I have something central to my mod idea that, as far as I can tell, requires code work.

I am working on a mod for a new faction of miners.  Basically, there are four different pawn kinds created for this faction as <PawnKindDefs>; Miners, Guards, Teamsters and Cooks.  I can currently assign a new backstory category for the faction in <FactionDef>, but that would randomly assign these backstories to each and all of these four pawn types.  What I want to do is instead "push" the backstory category down to the <PawnKindDef> level.  This would allow the Miners to have their own group of backstories, the Guards to also have their own backstories, etc. 

What this gets me is that my Miners could always be miners.  All of their backstories would have significant boosts to mining and construction, as well as some minor nerfs to other skills (like -2 to artistic or -2 to growing).  And I could force <requiredWorkTags> to make sure that they could mine and construct - if I allowed the use of vanilla child backstories it would not use any that disabled mining and/or construction.  Similarly, my Guards would be guards, focused on shooting and melee, eliminating any traits or options that would make them non-violent.  My Teamsters would be animal handlers, maybe with some minor bonus to medicine.  And my Cooks would of course have a bonus to cooking.

As far as I can tell, this can not be done in XML but requires code modification.

Fortunately, this code modification has already been done.  Unfortunately, the original modder has apparently abandoned his mod as of A17.  I tried using it in the current B18, got a bunch of errors, and quickly gave up on it.  The mod in question is called Xnopecore by Xnope and is available via the steam workshop.  He also has his code linked in github (link found in in Xnopecore steam page).  I have tried to contact him to request an update to B18, but received no response.  The code is open to the community; on github he states "I love my utilities, but feel free to copy my pasta. Credit would be a nicety, but not necessary." 

Note that the Xnopecore mod has a bunch of other tools in it for calculating triangles and areas and stuff that were to be used in a major content (unfinished?) mod by the author.  I don't really know what they do or how you would use them.  I am only interested in the backstory content of the Xnopecore mod.

Can anyone help resurrect the backstory portion of this mod, or alternatively write it up fresh?  Bonus points if you can show me how to do it solely within XML files.

LasurDragon

Check if this version works.
I just recompiled it to use latest Hugslib to avoid loading error but haven't tested it.

[attachment deleted by admin: too old]

jamaicancastle

Is this not a core functionality? I just checked on the core defs, and the core PirateBase PawnKindDef has a <backstoryCategory> tab, clear as day.

The reason I checked was I was sure I was doing just this with my alien faction, and I wasn't sure if it was core or if HAR was somehow adding that function to a vanilla def, but it does seem to be core...

o-o-o

@jamaicancastle - good question actually, not sure why I was sure that it didn't work that way, but because of that never bothered to try.  Some of the notes for Xnopecore indicated that you could list a backstory category at the PawnKindsDef level, but that it would be ignored by the program and only pulled from the faction level.  Plus if you could do it, I figured someone would have already put it in a mod by now, and I scoured a lot of XML from faction mods learning my way around without finding any pawn level backstories.

@LasurDragon - thanks for the update, want to verify first that backstories don't work at the PawnKindsDef level, but will then try the updated version.

jamaicancastle

Looking at the code, it appears that (for reasons I cannot readily explain) PawnKindDef defines a backstory category, but it isn't actually used by the pawn generator.

HAR appears to override this, but only if the pawn's race is an alien race with the appropriate flag. (Assuming I'm following the patch right, at least.)

o-o-o

Partial success, making good progress using the AlienRaces framework.  Will write up a solution when I get all the pieces together.  I can get my custom backstories introduced at the <PawnKindDef> level, so each pawnkind could have their own set of backstories.  But I can't figure out how to disable the backer backstories from still being injected. 

Does anyone know how to disable the backer backstories from a faction?  I am ok with them being in the rest of the game, just not for my custom faction.

o-o-o

Super double-plus extra thanks bigly to erdelf for his Humanoid Alien Races mod, github site, discord channel, and near-real time code updates yesterday to accommodate my requests (think I'm kidding? check mod update history against chat text in his discord help channel)
Special thanks to Xnope for his Xnopecore mod and github site, which got me into modding, taught me a lot about XML and showed that what I wanted to do was possible.

I was able to get backstories pushed down to the PawnKindDef level as desired by doing the following:
1.  Download latest version of Humanoid Alien Races 2.0 (HAR) by erdelf
2. for each pawn type with its own <PawnKindDef> add the following code:
Quote<modExtensions>
      <li Class="AlienRace.Info">
        <usePawnKindBackstories>true</usePawnKindBackstories>
        <allowHumanBios>false</allowHumanBios>
        </li>
      </modExtensions>

The <usePawnKindBackstories> is what pushed the backstory to the pawn kind level, as supported within
The <allowHumanBios>false is what turns off the special (backer?) bios, that would otherwise also get used for the pawns.  Setting this to false forces the pawns to ONLY have backstories from your new category

you will also need to set the backstory category in <PawnKindsDef> with the following line:

Quote<backstoryCategory>Miner</backstoryCategory>

This makes your pawn type only pull backstories that carry the "Miner" tag

3. Your custom backstory will then start like this: 

Quote<Defs>
   <AlienRace.BackstoryDef>
       <defName>Miner1</defName>
      <slot>Adulthood</slot><!-- choose Childhood or Adulthood -->
      <title>Miner short</title>
      <titleShort>Prospector</titleShort>
      <baseDescription>HECAP was a miner for a heart of gold.</baseDescription>
      <spawnCategories><li>Miner</li></spawnCategories> 

Note that the <spawnCategories>Miner in the last line is what gives this the "Miner" tag, and thus findable by PawnKindsDef.

I have been testing this with my faction mod and works like a charm. 
Note that when starting Rimworld, the other pawntypes in my faction that I have not yet done this process to gives some yellow level error; basically they all want the <modExtensions> thing to set their backstories or something.  When I get around to fleshing all of them out this warning on startup will go away.