JobGivers and animal taming

Started by Sam_, September 22, 2015, 10:11:58 AM

Previous topic - Next topic

Sam_

Hey guys,

I'm trying to make animals or at least tameable pawns that can do similar jobs to colonists, such as Grow, Build, Firefight and so on. I'm trying to avoid looking at any code and just using xmls (because I'm lazy), and I have found in SubTrees_Misc.xml you are able to define specific behaviours:


<ThinkTreeDef>
    <defName>InsertHookTest</defName>
    <insertTag>Humanlike_PostBroken</insertTag>
    <insertPriority>100</insertPriority>
    <thinkRoot Class="JobGiver_Berserk" />
</ThinkTreeDef>


Which just makes all humans go crazy, or do whatever I replace JobGiver_Berserk with. I have also created a custom think tree which has the additional section:



<li Class="ThinkNode_ConditionalHasFaction">
     <subNodes>
         <li Class="ThinkNode_ConditionalTrainableCompleted">
             <trainable>Grow</trainable>
             <subNodes>
                  <li Class="JobGiver_Berserk" />
             </subNodes>
         </li>
     </subNodes>
</li>


Which makes the pet attack everything when they are trained to "grow". What I'm having trouble doing is finding the JobGiver_ for specific jobs like Growing or Firefighting. In the Humanlike think tree the closest reference I could see was JobGiver_Work, which I assume contains the necessary code for choosing a job like the above and performing it.

Is there a specific JobGiver for each aforementioned task? if so, how do I reference them?
Is there a way without creating custom DLLs to break down the JobGiver_Work (or whichever is relevant) into each Job?
And lastly, if I have to create a custom DLL, where do I look to find the vanilla JobGivers?

Thanks for the help


Fluffy (l2032)

I'm afraid you'll have to do a custom dll.

Use ILSpy (or other tools) to decompile the source code, then look for the JobGiver_x and JobDriver_x classes. I'ld recommend also joining the modder slack for further questions;
https://ludeon.com/forums/index.php?topic=14501.0 The auto-invite tool appears to be broken, but post there asking for an invite and an admin will likely send you one.

The wiki will be some help on the basics of using a decompiler, but specific info is sadly outdated.

Sam_

After looking over the source I can see now that most colonist jobs are designed using a more dynamic way in JobGivers_Work. I have been trying to copy the JobGiver_Haul.cs to do specific colonist jobs and my attempt at getting them to harvest does not work:


public class JobGiver_GTGrow : ThinkNode_JobGiver
    {
        protected override Job TryGiveTerminalJob(Pawn pawn)
        {
            Predicate<Thing> validator = (Thing t) => HaulAIUtility.PawnCanAutomaticallyHaulFast(pawn, t);
            Thing thing = GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForGroup(ThingRequestGroup.CultivatedPlant), PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator, null);
            if (thing != null)
            {
                WorkGiver_GrowerHarvest workGiver_GrowerHarvest = new WorkGiver_GrowerHarvest();
                return workGiver_GrowerHarvest.JobOnCell(pawn, thing.InteractionCell);
            }
            return null;
        }
    }


The animal just wanders. I'm unsure if this code just isn't working or if it is related to something else, such as not having Manipulation skill, which I would assume can't be the case if they have a "Human" body. The only changes here, from the Haul JobGiver is the parameter "ThingRequest.ForGroup(ThingRequestGroup.CultivatedPlant)" and calling the WorkGiver directly in the statement. I'm typically a c++ programmer, and I mostly spend my time testing console applications rather than libraries, so I'm not sure how to debug this. If anyone can see an issue with this snippet I'd love to see a solution.


BBream

#3
I recommend to use JobDriver rather than WorkGiver.
I think thing.InteractionCell is wrong. This is for building_production.


WorkGiver_GrowerHarvest workGiver_GrowerHarvest = new WorkGiver_GrowerHarvest();
return workGiver_GrowerHarvest.JobOnCell(pawn, thing.InteractionCell);
=>
return new Job(JobDefOf.Harvest, thing.cell);


And you can output string in debug console by using Log class. It has Log.Message, Log.Warning, Log.Error.
- Log.Message method output white string and it would not make open console so if you want to see this message then you should open console window.
- Log.Warning method output yellow string and it might not open console.
- Log.Error method output red string and it would open automatically console.

You can open debug tool in Menu > Option tab.[/code]