From ef3c4e558b71eb8a63ef1050f4650d2aba88b3af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20=C3=81ngel=20Soler=20Ortiz?= Date: Wed, 9 Aug 2023 09:12:27 +0200 Subject: [PATCH] When a trader has no associated faction (such as for example orbital traders) choose a random faction to use for subcore information. Fixes #3. --- Assemblies/SubcoreInfo.dll | Bin 17408 -> 18432 bytes Source/Comps/CompSubcoreInfo.cs | 27 +++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Assemblies/SubcoreInfo.dll b/Assemblies/SubcoreInfo.dll index 01b6222a513e6178617c8e1c2bf46c91290286d5..ee4b22a31c3d2d2b1bf583baad2df52cc29e4872 100644 GIT binary patch delta 4856 zcmZ8k3v?9K8UF9Rv$Hd^uh|VOgvVw#Az||%1c5*b;UwULXo^@6i4Ve>q>z#a5}-oV z-85*yq9u-aw6;YQY*T9}tky;|P#ezC+)%ZRR&iseL`MNcft zn~LmYY2d8RRt|KTa;HnoP8- zl!!S;Drck@@_xZ;9ZNsW7N-BL`#38}GjkDVlhRjvw(}$-xXY4)#7pvd`wAj!(sCt~=Hc4+fcQXR+Si{n0k&y4$VL#`|>sFj#x z#xYj01^*G}MV2e*Dj7*!Z(oa8SA3mJ9#&H+%H{EKQYtF#D8@ZC8hNF1J$$I>ccOCv zgib7}<<$D)`AW^jtz+QEk z#C)tJjlvJBNz?Gd0%Kbcp-8p&CgUD-t_o%)v6O_lDXa9r^5Qz>mOANcxYl`f+Ny9! z;loat^#wBs4!nYLuQsE(mzg0d}Uv1q5($1K_ljYWTDM}6+9UG^EQ{_|Wxa0844<>4ygj34obQ%1-lvvvC?NF}o+mKmCnRyY zE%6Mtn?=tV(yFNx-&b=jRV&x0QfG1Lxd7A9X`wB1hLnE4TFVag5W7t|y&ZaA61Qj7 z^V^}!K_t~_rFwF8YL+22zt_}0I1bOJ*b{EK_5Oo7$u0Vr1Z-h!SZ32%;qld6U~92q zCF9fu+hzJ5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}jZ>F)pCg_56D|A8pMJxf{hQSWfeEdHO()Y3VOXxZ}LhsT9wvIi_ z>iLsg>yT&3#ZQwuz5b_pB2Nq}#&D=*hgUbnOz*?(|DU~9b0{JABOG(FKQZU+Pl#F^ zafDela00mT3(JjyyjE{$to2@KVYDXgCKlZm?qSi%8C4>>A!`-05^}PwmYj^}#+*-? zwK1C8+Ys}}F?pZT79QiEsosk#+9z8Wd zFnf}pv_NOr`gdtq%MEnqTBFNK*?6nAtlm-MPGgCI&Y4!UY(1N4O)5_Uey{vZ-pQsuS zG6dJTm0dBxYOPoqJz24f8CR8+7G7C0p|s4Zx+cqdW75J)G%GJ*S=K+VnRT&da?8aG w@rNg;Sf?lZJX_*_=HY4JT;ICIi{nI{U-9`5Q0_IQ(F8}}l diff --git a/Source/Comps/CompSubcoreInfo.cs b/Source/Comps/CompSubcoreInfo.cs index dfd04c4..83340cd 100644 --- a/Source/Comps/CompSubcoreInfo.cs +++ b/Source/Comps/CompSubcoreInfo.cs @@ -1,4 +1,5 @@ -using RimWorld; +using System.Linq; +using RimWorld; using Verse; namespace SubcoreInfo.Comps @@ -25,6 +26,15 @@ public override bool AllowStackWith(Thing other) return PawnName == otherComp.PawnName && TitleName == otherComp.TitleName && FactionName == otherComp.FactionName; } + /// + /// Checks if a random faction could be used to generate subcore information for traders. + /// + /// Faction being considered. + private static bool ValidRandomFaction(Faction faction) + { + return faction != null && !faction.IsPlayer && !faction.temporary && !faction.Hidden && faction.def.humanlikeFaction; + } + /// /// PostPostGeneratedForTrader is called after the subcore is generated for a trader. /// @@ -37,7 +47,20 @@ public override void PostPostGeneratedForTrader(TraderKindDef trader, int forTil if (!SubcoreInfoSettings.randomTraderInfo) { return; } - Copy(PawnGenerator.GeneratePawn(forFaction.RandomPawnKind(), forFaction)); + var pawnFaction = forFaction; + if (pawnFaction == null) + { + var randomFactions = Find.FactionManager.AllFactions.Where(ValidRandomFaction).ToList(); + if (!randomFactions.NullOrEmpty()) + { + pawnFaction = randomFactions.RandomElement(); + } + } + + if (pawnFaction != null) + { + Copy(PawnGenerator.GeneratePawn(pawnFaction.RandomPawnKind(), forFaction)); + } } } }