[A17] Want to add custom backstories and spawn categories? +More

Started by Xnope, May 25, 2017, 07:59:07 PM

Previous topic - Next topic

Xnope

Hey guys. I'm somewhat new to the RimWorld modding crowd, so here goes my first post that might help a few of you creators out there.

I made a core mod that you can pick up on GitHub. This mod allows for a few new things for modders:

       
  • Add custom backstories with Defs
  • Inject custom spawnCategories into existing backstories with Defs

    •       
    • This means you could create a custom backstory MyBackstory and give it a custom spawnCategory MySpawnCategory, and then inject this new spawn category into the existing backstory 'Con artist' for example, or the existing spawnCategory 'Civil', for example.
  • Adds extended functionality to factions, currently including:

    •       
    • Roaming factions: they roam about in caravans, but do not have any settlements. Similar to a hidden faction, only you can track and maintain relations with them via the Factions tab or the Comms Console.

    •       
    • Dynamically-named factions: a faction can be named dynamically based on what its leader's name is. Must have a custom RulePackDef namer that includes the string 'LNAME' to be replaced by the generated leader's name. This currently works, however more extensive work will be done on this feature later.
  • And most importantly, the Defs folder of this mod contains example .txt files that thoroughly outline how to use this mod for creating purposes. Please remember that these .txt files must be renamed to .xml files if you want to edit them directly into a usable Def.
Here are some examples of usage that are taken from my currently work-in-progress mod, Carnivale.

Creating a new backstory with a custom spawn category:

<!-- Gypsy Child-->
  <Xnope.Defs.BackstoryDef>
    <defName>XnopeBS_GypsyChild</defName>
   <slot>Childhood</slot>
   <title>Gypsy child</title>
   <titleShort>Gypsy</titleShort>
   <baseDescription>Folks used to say that gypsies are an ancient human culture often gifted with powers of foresight, and that is why they have been fortunate enough in their wanderlust to have survived the eons since their genesis on Earth. NAME was raised by HIS mother, a rare woman fabled to have descended from these great wandering folk.</baseDescription>
   
   <skillGains>
     <li><defName>Social</defName><degree>2</degree></li>
     <li><defName>Medicine</defName><degree>4</degree></li>
   </skillGains>
   
   <forcedTraits>
     <li><defName>PsychicSensitivity</defName><degree>2</degree></li>
     <li><defName>Luckiness</defName><degree>1</degree></li>
   </forcedTraits>
   
   <spawnCategories>
     <li>Carnivale</li>
     <li>Slave</li>
   </spawnCategories>
   
  </Xnope.Defs.BackstoryDef>


(Worth noting that the 'Luckiness' forced trait is a trait that my mod adds as well.)

Injecting the new spawn category into existing backstories:

  <Xnope.Defs.SpawnCategoryInjectorDef>
    <defName>SCI_Carnivale</defName>
   
    <newCategory>Carnivale</newCategory>
   <injectToBackstories>
     <li>Actor</li>
     <li>Con artist</li>
     <li>Courtesan</li>
     <li>Escaped convict</li>
     <li>Musician</li>
     <li>Medieval doctor</li>
     <li>Medieval minstrel</li>
     <li>Bodyguard</li>
     <li>Caravaneer</li>
     <!-- childhood -->
     <li>Apocalypse survivor</li>
     <li>Caravan traveler</li>
     <li>Mute</li>
     <li>Refugee</li>
     <li>Child slave</li>
     <li>Circus performer</li>
     <li>Medieval thief</li>
     <li>Sickly child</li>
   </injectToBackstories>
  </Xnope.Defs.SpawnCategoryInjectorDef>


Doing this populates my new custom spawn category so that more than just the custom backstories I've added will show up when a pawn in this category is spawned. This is great for immersion and variability, as we don't want every pawn with the 'Carnivale' spawn category to have the same childhood.

Here is an example of how to add or modify a PawnKindDef to utilise this new spawn category:

  <PawnKindDef Name="PawnKinds_Core" Abstract="True">
    <race>Human</race>
    <backstoryCategory>Carnivale</backstoryCategory>
  </PawnKindDef>


I had a problem with the vanilla code for generating pawns, and that is that the <backstoryCategory> field in PawnKindDefs was essentially ignored and never used for anything; a pawn's faction's <backstoryCategory> was always used to decide a pawn's backstory. I changed this with a Harmony patch, so now pawn generation prefers using a PawnKindDef's <backstoryCategory> over a FactionDef's, which it will only revert to if there is no <backstoryCategory> in a pawn's PawnKindDef. So, it's worth noting that only with my mod can you make PawnKindDef's <backstoryCategory> do anything meaningful.

I would very much like to write up more in-depth tutorials, but I first want to focus on getting my mod Carnivale to release. I just thought I'd share this here so that other creators out there can make use of the minor changes and additions I've made.

Cheers
My W.I.P. mods:
Carnivale: GitHub | Forum Post
XnopeCore: GitHub

WalkingProblem

Wow wow wow~

This is exactly what I was looking for... Awesome work!

I will test this out when I start work on the mod that needed this.

Awesomeness!

Xnope

Glad it reached someone! PM me if you have any questions. For the most part it hasn't changed since I've posted this, maybe a thing or two, but after I finish my mod Carnivale I plan to expand this core mod to accommodate my future mod ideas.

Cheers man!
My W.I.P. mods:
Carnivale: GitHub | Forum Post
XnopeCore: GitHub

kaptain_kavern

Oh I haven't see this post earlier ! Thank you for your work Xnope

This is looking quite interesting. I will definitively have a look at this one.

(Replied to be notified also ;) )

jjr

This looks great!!I will try it out, hope things will do fine.