/// <summary> /// enter the given sapience state /// </summary> /// <param name="stateDef">The state definition.</param> /// <param name="initialLevel">The initial level.</param> public void EnterState([NotNull] SapienceStateDef stateDef, float initialLevel) { _sapienceState?.Exit(); _sapienceState = stateDef.CreateState(); //need to refresh comps and needs for pawn here Pawn.needs?.AddOrRemoveNeedsAsAppropriate(); _sapienceState.Init(this); SapienceLevel = FormerHumanUtilities.GetQuantizedSapienceLevel(initialLevel); PawnComponentsUtility.AddAndRemoveDynamicComponents(Pawn); var sNeed = SapienceNeed; sNeed?.SetSapience(initialLevel); _sapienceState.Enter(); if (Pawn.Faction == Faction.OfPlayer) { Find.ColonistBar?.MarkColonistsDirty(); } //initialize work settings if they have it Pawn.workSettings?.EnableAndInitializeIfNotAlreadyInitialized(); //interrupts any jobs in case this changes their intelligence Pawn.jobs?.EndCurrentJob(JobCondition.InterruptForced); }
/// <summary> /// Exits the current sapience state. /// </summary> public void ExitState() { if (_sapienceState == null) { DebugLogUtils.Warning($"trying to exit sapience state in {Pawn.Name} but they aren't in one"); return; } _sapienceState.Exit(); _sapienceState = null; }
/// <summary> /// Exits the current sapience state. /// </summary> /// <param name="recalculateComps">if set to <c>true</c> dynamic components will be recalculated after exiting the state.</param> public void ExitState(bool recalculateComps = true) { if (_sapienceState == null) { DebugLogUtils.Warning($"trying to exit sapience state in {Pawn.Name} but they aren't in one"); return; } _sapienceState.Exit(); _sapienceState = null; if (recalculateComps) { PawnComponentsUtility.AddAndRemoveDynamicComponents(Pawn); } }