RimWorld

RimWorld

44 ratings
Faith Framework
   
Award
Favorite
Favorited
Unfavorite
Mod, 1.5, 1.6
File Size
Posted
Updated
1.088 MB
10 Jul, 2024 @ 11:54am
29 Jun @ 7:25pm
20 Change Notes ( view )

Subscribe to download
Faith Framework

In 3 collections by emitbreaker
MIM WH40k Compatibility List
374 items
MIM WH40k Mod Collection
47 items
MIM WH40k Mod Collection 1.6 Migration Completed
31 items
Description
Summary
This mod is a framework for Faith and Corruption for my own mod sets. Hence, if you are not a modder, you don't really need to take care about this mod unless any other mod requires it.

For Modders
This mod provides highly customize-able code sets for Faith and Corruption mechanism. It is something similar to Psycast from the Royalty but uses completely independent resources and code sets.

I will update detailed specification on this page later on but so far this mod contains a code set for;

4. New code sets for abilities
5. Mod Extension to manage configurations and customization of Hediffs and abilities.
6. New code sets for Belief, which is kind of center pole of Faith and Corruption.
7. New code sets for Hediff givers to give proper hediffs for Faithful and Corrupted.

Hediff_Belief
Core component of overall mechanism. Any Hediff that has class of MIM40kFactions.Faith.Hediff_Belief is considered as an independent belief that has its own sub parameters.

It is kind of Hediff_Level, but unlike psycast, it has it's own cachedLevelExperience. Currently, only books can increase this, and when the value reaches to 1f, hediff_belief gets 1 level and the cache reset to 0f.

As per current design only supports only 1 StatDef of EMWH_Faith / EMWH_Corruption / EMWH_BeliefGain and 1 RecordDef of EMWH_KillsFaith, EMWH_KillsHeretic, EMWH_Faith, EMWH_Corruption, EMWH_TimeAsFaithful, EMWH_TimeAsCorrupted each, it has a code to remove any existing belief.

PostAdd
When it is added, there are two initiation process - one is giving the first level message with one ability, and the other is configuring initial allegiance. Initial allegiance is controlled by FaithExtension that is supporting several codes to manage their variables.

If FaithExtension.startsAsCorrupted is true, currentCorruption (resource for corrupted ability, default -1f) set as 0 - otherwise, currentFaith set as 0.

Tick
During Hediff Tick, it runs several calculations based on configurable HashIntervalTick by FaithExtension.

At first, once per FaithExtension.changeFaithorCorroptionLongTime (default 60,000) tick, it will check RecordDef EMWH_Faith and EMWH_Corruption. If EMWH_Faith > EMWH_Corruption but currentCorruption > currentFaith, the code will switch value of currentCorruption and currentFaith, then set currentCorruption to -1f, and then reset level of Hediff_Belief to 1 (and vice versa afterwards).

By doing this, I assume that we can make sort of event of sudden conversion or corruption.

Secondly, it runs RechargeFaith() - which contains three parts

1. gaining currentFaith by meditation. Same logic as Royalty meditation, hence user needs to enable Royalty DLC to use this function. This recharges currentFaith by current value of StatDef EMWH_BeliefGain + StatDef MeditationFocusStrength of the object. Upper limits equal to faithValueMax (is equal to value of StatDef EMWH_Faith).

2. Pausing natural recharge while reading a book.

3. Natural recharge: currentFaith + FaithIncreasePerDay (same amount and logic as Royalty Psyfocus) / FaithExtension.natualRechargeDivider (default 400f) * beliefGainMultiplier (equal to value of StatDef EMWH_BeliefGain)

Third one is ChangeLevelbyExp(), quite straightforward as it is named.

Last one is to calculate RecordDef EMWH_Faith from RecordDef EMWH_TimeAsFaithful. It has cached value for previously calculated RecordDef EMWH_Faith, and add value to EMWH_Faith only for the gaps (current - cached).

Conversion rate can be managed by FaithExtension.timetoFaithCount (int). Default is 60000 (or 1 in game-day) and changing this value will boost / reduce speed and amount of RecordDef EMWH_Faith. However, smaller value call this method more often, so I recommend 30,000 (twice per in game day) as minimum.

Notify_KilledPawn

Not so much important but this section calculate RecordDef of EMWH_KillsFaith, EMWH_KillsHeretic. There are two flags in FaithExtension called isRadical and isPuritan. If isPuritan is true, killing pawn's without Hediff_Belief considered as kill heretics. If isRadical is true, it consideres ans kill faithful. If both false, it won't be counted. If both true, you'll get an error.

Kill count also converted to RecordDef EMWH_Faith / EMWH_Corruption. You can control # of kills per 1 Faith / Corruption by FaithExtension.KilltoFaithCount or KilltoCorruptionCount. Default is 10.

Hediff_FaithfulorCorrupted
This is a supplementary class to Belief, to let players easily know what kind of allegiance (either Faithful or Corrupted) their selected pawn has.

By FaithExtension.targetBelieftoGetLevel, you can define which belief is source of these sub hediff. Then, it will automatically get severity from target Hediff_Belief and gives buff / debuff per stage. So you have to give same amount of Hediff Stage to any HediffDef that is using this class.

HediffGivers
There are two hediff givers but in a context level they works same way - HediffGiver_WhenCorrupted / HediffGiver_WhenFaithful.

They will call currentFaith / currentCorruption from Hediff_Belief, and if the pawn is Faithful, gives hediffs under HediffGiver_WhenFaithful and vise versa.

Code Set for Books
WIP

Reference
There is a separated mod that basically uses all functions of the framework as a working sample.

MIM WH40k Adeptus Ministorum

Recent update
See above history tab for the details. It seems like I don't have any more letters remain on this description.

To Dos
  1. Conversion ritual for ideology - but it may takes time as it took lots of time for me when I coded similar one in my ideology library.
  2. Conversion ritual for Anomaly - maybe starts from the feasibility check
  3. (Maybe?) Biotech Gene integration - but it sounds ridiculous to me as I believe agnosticism in my RL.

Credits
Thanks for Ty to give us great game of Rimworld!

I, emitbreaker, did all the coding and design of this mod.

Preview artworks come from generative AI of Playground[playground.com].

You can use this framework and its code under CC BY-NC-ND 4.0[creativecommons.org]. Any secondary creation for your own add-on is fully allowed.

Buy me a coffee if you wish[buymeacoffee.com]
Popular Discussions View All (1)
12
27 Jul, 2024 @ 10:21am
PINNED: Error Logs here please
emitbreaker
31 Comments
emitbreaker  [author] 14 Apr @ 7:27am 
@Luke Fixed. It was XML issue at Adeptus Ministorum mod's end. Now those logic works properly. Please update Adeptus Ministorum mod.
emitbreaker  [author] 14 Apr @ 6:54am 
@Luke That's really odd... let me check it once again.
Luke 14 Apr @ 6:03am 
I'm wondering if something odd is going on on my end.
All my pawns are the same faith, and all have the imperial creed and faithful hediffs.
I have existence of heretic set to horrible.
They have a mood buff of +2 for unified faith, a debuff of -4 for surrounded by heretics, and a debuff of -4 for having a leader of a different faith (even though that leader is the same ideoligion)

Is there a way to disable the existence of heretic ideoligion precept if I can't figure out what's going on?

Even with existence of heretic set to neutral my leader still gets the -2 debuff (though somehow none of the others have it) and all pawns have surrounded by heretics (0)
emitbreaker  [author] 13 Apr @ 12:04pm 
@Luke Sorry it took longer than expected to refactor and update some functionality. Now your pawns will find proper heretics with less performance issue. Please update this mod.
Luke 13 Apr @ 6:43am 
Just saw your post, sorry I didn't refresh. I had typed out that comment right away but forgot to hit post until I came back hah. Thanks for the quick fix!
Luke 13 Apr @ 6:42am 
Specifically there's things like when I make one of them the ideoligious leader, the rest get a debuff marked with the ideoligion symbol and says that they don't like having a heretic as their leader. Including the leader pawn themself.
emitbreaker  [author] 13 Apr @ 4:42am 
@Luke Ah, it seems like I forgot to care about if the belief is neither Puritan nor Radical. Just read through my code and if both marked as false, pawns will consider each other as Corrupted even if they are both faithful to same belief. Hotfix will be deployed soon - once after finishing test at my end.
emitbreaker  [author] 13 Apr @ 4:30am 
@Luke Let me check it
Luke 13 Apr @ 4:29am 
Having an issue where my pawns think all of my other colony pawns are heretics even if they have imperial creed, faith etc. Am I missing something or reading things wrong?
emitbreaker  [author] 14 Aug, 2024 @ 8:36am 
@慕柯 Took a while but fixed...