How to link a thought to a workgiver or jobdriver?

Started by Lord Fappington, January 25, 2015, 05:57:14 PM

Previous topic - Next topic

Lord Fappington

As the title says. 

I'm trying to trigger a thought when a workgivers conditions are met, or better yet when a job driver is complete.

Igabod

Quote from: Lord Fappington on January 25, 2015, 05:57:14 PM
As the title says. 

I'm trying to trigger a thought when a workgivers conditions are met, or better yet when a job driver is complete.

Do you mean like the one for green thumb that triggers a positive mood thought after the pawn completes a planting task? I don't know enough about the C# side of modding to help you more than suggest you look at green thumb for help. I know it's not possible in just XML unfortunately.

Lord Fappington

Quote from: Igabod on January 25, 2015, 08:53:40 PM

Do you mean like the one for green thumb that triggers a positive mood thought after the pawn completes a planting task? I don't know enough about the C# side of modding to help you more than suggest you look at green thumb for help. I know it's not possible in just XML unfortunately.

Igabod, you read my mind.  Unfortunately when I try to decompile the core assembly for the jobdrivers related to sowing/planting I get an error; therefore, I can't see how Tynan did it :(

FridayBiology

Yes another god damn youtuber.
 https://www.youtube.com/user/FridayBiology

Igabod

Quote from: Lord Fappington on January 25, 2015, 08:57:34 PM
Quote from: Igabod on January 25, 2015, 08:53:40 PM

Do you mean like the one for green thumb that triggers a positive mood thought after the pawn completes a planting task? I don't know enough about the C# side of modding to help you more than suggest you look at green thumb for help. I know it's not possible in just XML unfortunately.

Igabod, you read my mind.  Unfortunately when I try to decompile the core assembly for the jobdrivers related to sowing/planting I get an error; therefore, I can't see how Tynan did it :(

ah, sorry, I have no experience with decompiling code. I've done a lot of compiling in the ancient past but never any need to decompile cause I always had the source code.

Lord Fappington

Quote from: Feirfec on January 25, 2015, 09:08:10 PM
wait "green thumb" doesn't just give +2 growing?

If they sow plants it gives a moodlet that increases their mood.  +1 per plant up to 20 stack.

Kolljak

after seeing your mod i can think of the many reasons as to why you want this :D i know its similar to the Depressive and Sanguine only triggered by an event such as sowing .... there is someone who has a mod i think its in one of the food mods Where a person is happy for eating a certain food and it uses the same code as that only wired to eating a specific item. could you not rework that to your needs.

Lord Fappington

Quote from: Kolljak on January 26, 2015, 12:07:03 AM
after seeing your mod i can think of the many reasons as to why you want this :D i know its similar to the Depressive and Sanguine only triggered by an event such as sowing .... there is someone who has a mod i think its in one of the food mods Where a person is happy for eating a certain food and it uses the same code as that only wired to eating a specific item. could you not rework that to your needs.

Unfortunately no, I can't tie easily into the eating system for triggering moods.  If I am wrong, I'd love for someone to correct me, and show me how ;)

My source code is freely available with my mod, so anyone is welcome to tinker with it to help :)

AAR_Dev

GreenThumb

public static class ThoughtDefOf
{
public static ThoughtDef GreenThumbHappy;
public static ThoughtDef WasImprisoned;
public static ThoughtDef NewColonyOptimism;
public static ThoughtDef SleptOutside;
public static ThoughtDef SleptOnGround;
public static ThoughtDef SleptInCold;
public static ThoughtDef SleptInHeat;
public static ThoughtDef AteWithoutTable;
public static ThoughtDef Catharsis;
public static ThoughtDef AbrasiveTalk;
public static ThoughtDef SocialTalk;
public static ThoughtDef MePrisonerOrganHarvested;
public static ThoughtDef KnowPrisonerOrganHarvested;
public static ThoughtDef KnowPrisonerExecuted;
public static ThoughtDef KnowPrisonerSold;
public static ThoughtDef BattleWounded;
public static ThoughtDef WitnessedDeathStranger;
public static ThoughtDef WitnessedDeathStrangerBloodlust;
public static ThoughtDef WitnessedDeathAlly;
public static ThoughtDef KilledHumanoidBloodlust;
public static ThoughtDef ButcheredHumanoidCorpse;
public static ThoughtDef ObservedLayingRottingCorpse;
public static ThoughtDef ObservedLayingCorpse;
public static void RebindDefs()
{
DefOfHelper.BindDefsFor<ThoughtDef>(typeof(ThoughtDefOf));
}
}


By the way, anyone know a way around the DebuggerHidden?

// RimWorld.JobDriver_PlantSow
[DebuggerHidden]
protected override IEnumerable<Toil> MakeNewToils()
{
JobDriver_PlantSow.<MakeNewToils>c__Iterator3E <MakeNewToils>c__Iterator3E = new JobDriver_PlantSow.<MakeNewToils>c__Iterator3E();
<MakeNewToils>c__Iterator3E.<>f__this = this;
JobDriver_PlantSow.<MakeNewToils>c__Iterator3E expr_0E = <MakeNewToils>c__Iterator3E;
expr_0E.$PC = -2;
return expr_0E;
}


Setup

// Verse.AI.JobDriver
private void SetupToils()
{
try
{
this.toils.Clear();
foreach (Toil current in this.MakeNewToils())
{
if (current.defaultCompleteMode == ToilCompleteMode.Undefined)
{
Log.Error("Toil has undefined complete mode.");
current.defaultCompleteMode = ToilCompleteMode.Instant;
}
current.actor = this.pawn;
this.toils.Add(current);
}
}
catch (Exception ex)
{
Log.Error(string.Concat(new object[]
{
"JobDriver.SetupToils threw exception. Pawn=",
this.pawn,
", Job=",
this.CurJob,
", Exception=",
ex.ToString()
}));
this.EndJobWith(JobCondition.Errored);
}
}



Lord Fappington

don't know a way around debugger hidden, hence my current dillema :(

Rikiki

Have you look at this?

Adding the thought is just putting that line of code after a toil is finished:
colonist.psychology.thoughts.TryGainThought(new Thought(ThoughtDef.Named("MyThoughtDefName")));

Easy to say but I still had no time to play with it... ;D

Lord Fappington

Quote from: Rikiki on January 27, 2015, 03:53:09 AM
Have you look at this?

Adding the thought is just putting that line of code after a toil is finished:


colonist.psychology.thoughts.TryGainThought(new Thought(ThoughtDef.Named("MyThoughtDefName")));

Easy to say but I still had no time to play with it... ;D

I'm not seeing a colonist class to call

Rikiki

?!? ???
Sorry but I don't understand.
The colonist is a Pawn object, generally the toil's actor.

public class Toil : JobEndable
{
public Pawn actor;

skullywag

im assuming thats your pawn so whatever youve got for pawn in your code change it to that.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Lord Fappington

Quote from: Rikiki on January 28, 2015, 03:03:28 AM
?!? ???
Sorry but I don't understand.
The colonist is a Pawn object, generally the toil's actor.

public class Toil : JobEndable
{
public Pawn actor;


Thanks for the tips; I tried what you typed but I didn't find the TryGainThought... maybe its because in my toil I don't explicitedly define an actor (see attached)?

I also tried

return new Thought(ThoughtDef.Named("MouthToSouth"));


but it threw the error "Invalid token 'return' in class, struct or interface member (note I put the above code outside of the toil.  When tried inside the toil it said I couldn't convert a thought into a Verse.AI toil.

[attachment deleted due to age]