[A17.1546] ThoughtMaker.MakeThought has incorrect init logic.

Started by Fluffy (l2032), May 29, 2017, 02:34:37 PM

Previous topic - Next topic

Fluffy (l2032)

Problem description;
ThoughtMaker.MakeThought( ThoughtDef, int ), applies the stage after Init() is called. This is a problem for thoughts that have the Thought_MemorySocial worker class, and have multiple stages.

(to my knowledge, this combination doesn't exist in vanilla so, for now, it's mostly a modding problem).


Specifically, ThoughtMaker has the following method;

public static Thought_Memory MakeThought(ThoughtDef def, int forcedStage)
{
Thought_Memory thought_Memory = (Thought_Memory)Activator.CreateInstance(def.ThoughtClass);
thought_Memory.def = def;
thought_Memory.Init();
thought_Memory.SetForcedStage(forcedStage);
return thought_Memory;
}
      

And Thought_MemorySocial has the following Init() method;
// RimWorld.Thought_MemorySocial
public override void Init()
{
base.Init();
this.opinionOffset = base.CurStage.baseOpinionOffset;
}


Since Init() is called before SetForcedStage(), which in turn sets CurStage, the opinionOffset will default to that of the zeroth stage, regardless of the forcedStage argument.

How to resolve;
Simply switch the Init() and SetForcedStage() lines.


ison