Ludeon Forums

RimWorld => Bugs => Topic started by: JT on September 24, 2021, 09:41:30 PM

Title: [1.3.3117 - Ideology] No ideology roles = broken verb menu
Post by: JT on September 24, 2021, 09:41:30 PM
Circumstances:

When running an ideology with all roles removed, the right-click float "verb" menu will fail to open.

Savegame:

Not applicable.

Cause and solution:

The culprit is the RimWorld function:


// H:\RimWorld13\RimWorldWin64_Data\Managed\Assembly-CSharp.dll
// Assembly-CSharp, Version=1.3.7922.19870, Culture=neutral, PublicKeyToken=null
// Global type: <Module>
// Architecture: AnyCPU (64-bit preferred)
// Runtime: v4.0.30319
// Hash algorithm: SHA1
// RimWorld.RitualBehaviorWorker_Conversion
public override string CanStartRitualNow(TargetInfo target, Precept_Ritual ritual, Pawn selectedPawn = null, Dictionary<string, Pawn> forcedForRole = null)
{
Precept_Role precept_Role = ritual.ideo.RolesListForReading.First((Precept_Role r) => r.def == PreceptDefOf.IdeoRole_Moralist);
if (precept_Role.ChosenPawnSingle() == null)
{
return "CantStartRitualRoleNotAssigned".Translate(precept_Role.LabelCap);
}
bool flag = false;
foreach (Pawn item in target.Map.mapPawns.FreeColonistsAndPrisonersSpawned)
{
if (ValidateConvertee(item, precept_Role.ChosenPawnSingle(), throwMessages: false))
{
flag = true;
break;
}
}
if (!flag)
{
return "CantStartRitualNoConvertee".Translate(precept_Role.ChosenPawnSingle().Ideo.name);
}
return base.CanStartRitualNow(target, ritual, selectedPawn, forcedForRole);
}


If the error doesn't immediately leap out at you, the problem is that the routine is scanning for the first spiritual leader role of the pawn's ideology.  Upon finding that role, it then verifies whether that role is assigned to any colonist.

However, if you have removed every role from your ideology, the IEnumerable<>.First() function will throw an exception, because it cannot operate against an empty set.

The function should be changed to use FirstOrDefault() instead, and the following line should double-check to be sure that precept_Role is non-null.

This is a vanilla bug, but is exposed by mods, because Achtung! includes a prompt that reports when an exception is encountered while attempting to display the float menu.

jcstryker first discovered this issue: https://github.com/lilwhitemouse/RimWorld-LWM.DeepStorage/issues/110#issuecomment-926989363

Cheers!
Title: Re: [1.3.3117 - Ideology] No ideology roles = broken verb menu
Post by: JT on September 24, 2021, 11:17:26 PM
After patching this with a bugfix Harmony patch on my end (which fixes the issue!), I have discovered that the problem also exists for RitualBehaviorWorker_Speech.

Once again, I'll assert that this is definitely a vanilla bug. ;-)
Title: Re: [1.3.3117 - Ideology] No ideology roles = broken verb menu
Post by: Pheanox on October 27, 2021, 06:36:13 PM
Thanks for the bug report.  As it is impossible to remove all roles from an ideo in vanilla, the "Leader" and "Moral Guide" role are hard-coded and unable to be removed, this is definitely not a vanilla bug.  I would recommend examining what mods may be causing this behavior.