Joy toils

Started by skullywag, April 23, 2015, 02:33:56 PM

Previous topic - Next topic

skullywag

Anyone have any info on these?

Im stuck trying to just extend the JobDriver_WatchBuilding so my pawns only stand in 1 spot near the building (interaction cell if possible) but ive never got to grips with toils, the joy ones are even more alien to me.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Rikiki

Mmh, I just updated the mechanoid terraformer mod.
You may have a look at the JobDriver_ScoutStrangeArtifact for example: it tells a pawn to go near the terraformer and wait for a few seconds.

What do you want to do exactly?

1000101

#2
I've been monkeying around with the toils, jobs, work, etc to do a few things.  One of the basic goals while I worked on figuring it out was simply duplicating mining.  This then morphed into a rough rock wall->finished stoneblocks wall "Smooth Wall" designator.

The JobDriver where the toils are created:using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using RimWorld;
using UnityEngine;
using Verse;
using Verse.AI;
using Verse.Sound;

using CommunityCoreLibrary;

namespace cmm
{
public class JobDriver_SmoothWall : JobDriver
{
private const int TicksPerStrike = 100;
private const int DamagePerStrike = 80;
private int minerTicks;
private int nextMinerStrike;
private Thing mineable;

protected override IEnumerable<Toil> MakeNewToils()
{
// Just on the off-chance the rock is on fire...
this.FailOnBurningImmobile( TargetIndex.A );
// Reserve the target
yield return Toils_Reserve.Reserve( TargetIndex.A );
// Go to the target
Toil toilGoto = Toils_Goto.GotoCell( TargetIndex.A, PathMode.Touch );
// Fail going to the target if it becomes unreachable
ToilFailConditions.FailOn< Toil >( toilGoto, ( Func< bool > )(() =>
{
if( Reachability.CanReach( pawn, (TargetInfo)TargetLocA, PathMode.Touch, Danger.None ) )
return false;
return true;
}));
yield return toilGoto;
// Now the work toil itself
Toil toilWork = new Toil
{
// Continue until done
defaultCompleteMode = ToilCompleteMode.Never,
// When the job starts...
initAction = new Action(() =>
{
// Get the rock resource
mineable = MineUtility.MineableInCell( TargetA.Cell );
// Get this miners speed based on stat
nextMinerStrike = (int)( (double)TicksPerStrike / (double)pawn.GetStatValue( StatDefOf.MiningSpeed, true ) );
minerTicks = 0;
} ),
// The work tick
tickAction = new Action(() =>
{
minerTicks += 1;
if( minerTicks < nextMinerStrike ) return;
// Reset counter, damage rock
minerTicks = 0;
mineable.HitPoints -= DamagePerStrike;
} )
};
// When should we stop?
toilWork.endConditions.Add( ( Func< JobCondition > )(() =>
{
// Go until the rock is fully damaged
if( mineable.HitPoints > 0 ) return JobCondition.Ongoing;
return JobCondition.Succeeded;
} ) );
// Do something when done
toilWork.AddFinishAction( new Action(() =>
{
// Clear the designation at this cell
Common.RemoveDesignationOfAt( DesignationDefs.SmoothWall, TargetA.Cell );
// Better have associated stone blocks...
string blocksDef = "Blocks" + mineable.def.defName;
ThingDef stoneBlocks = DefDatabase<ThingDef>.GetNamed( blocksDef, true );
// Replace the rock with a stone wall
GenSpawn.Spawn( ThingMaker.MakeThing( ThingDefs.WallStone, stoneBlocks ), TargetA.Cell ).SetFaction( Faction.OfColony );
} ) );
// Some fun sounds while working
ToilEffects.WithSustainer( toilWork, ( Func< SoundDef > )(() =>
{
return SoundDefs.Recipe_Sculpt;
} ) );
// Some fun effects while working
ToilEffects.WithEffect( toilWork, "Mine", TargetIndex.A );
yield return toilWork;
// And we're done.
yield break;
}
}
}


Note:  My designator code for this does all the sanity checks.  By the time the above code is executed, everything should be in a valid state.  eg, I filter to make sure that only mineables that have an assocated stoneblock def are valid (so no steel, plasteel, etc), etc.

Use and abuse.  It took me about a week figure out the basics of how it worked, I'm sure you will be faster as you have a lot more experience with RimWorld modding than I do.  Actually, I know this because I've decompiled some of your mods to see how you did things.  I mean, I did nothing, nothing of the sort.  :D :D :D

Edit:  As to toils specific to the joy system, I am yet to delve deeply but it's on the list as I have plans of my own to extend the available options.
(2*b)||!(2*b) - That is the question.
There are 10 kinds of people in this world - those that understand binary and those that don't.

Powered By