New ThinkNode and StatusLevel problem

Started by Gaesatae, January 31, 2015, 02:20:42 PM

Previous topic - Next topic

Gaesatae

I was trying to add a new ThinkNode and I've hit a wall, and I can't figure out how to make it work.

The idea is very similar to the vanilla "ThinkNode_SatisfyNeeds", and its objective is to create a new need like food or rest. I've created the same structure the game uses to manage food needs: a ThinkNode, a StatusLevel, a Tracker and a new Pawnclass. I also added the ThinkNode to the xml.

My problem is that I can't find a way to make the game use all this. The thinknode class works, but I don't know how to add the StatusLevel and the tracker to the colonists.

Does anyone have any experience with something like this?

Wastelander

I think the Pawn class has hard-coded Rest and Food trackers, I'm not sure it's possible to add a need at the moment (would be awesome for Tynan to provide a modding hook here!).

I managed to add something that works like a need by:
-Override the Human definition and add a thingComp to track your need, that comp should record the last tick the need was satisfied
-Add a new thought def that controls the penalties for not meeting the need, it can check the thingComp above to determine the severity of penalty
-Add a job to postSatisfyNeeds step to check your need as well, or override ThinkNode_SatisfyNeeds
-Presumably you have a worker or something to satisfy the need, when that's completed set the last tick in your thingComp to now

I haven't yet been able to get any UI for the need to display, I'm thinking either I need to add a new ITab just for my need or look at how EDB reworked the UI in his/her interface mod

Gaesatae

Thanks for your reply.

I don't want to mess too much with the pawn class, I'm worried about mod compatibility. Also, I prefer to use the game classes when possible. I'm working on the structure of my mod and I plan to expand it, so having to work around this will make my life miserable on the long run.

I think it's better for me right now to stop trying this, maybe until the next release, or until someone can point out what I'm doing wrong.

Friedmutant

I haven't done anything with the ThinkNode or SatisfyNeeds stuff, but I've looked at the Alert Siren mod's source, which does.  The code is well laid out, you might be able to solve your problem by looking at it.  Sorry I can't find the link at the moment, iirc it's by Rikiki.

Rikiki

Sorry Friedmutant but my Alert Speaker mod is more modest. :-[
It only adds thoughts and stat offsets to pawns.
ThinkNodes are used in AI so pawns will automatically perform a job. I did not touched it for now... ::)

mipen

I'm not at home so what I say probably won't be too helpful, but to add the new ThinkNode to a pawns ai, you need to write a new thinktreedef. Use the base ones as templates and add in an entry referencing your ThinkNode. And then in the pawn race Def, change the thinktreedef name to your new thinktreedef. This will unfortunately cause incompatibilities with any other mods that change the think tree, but I don't think that there are any at the moment.

On a side note, looking through the thinktreedefs, it appears there is actually an insertion hook available, so you could try playing around with those and seeing if you can get them working. I have only just noticed them so I don't know how they work, but they look pretty handy and would mean you don't have to override any vanilla defs

Gaesatae

mipen, I did all that, and it works fine if you use a simple jobgiver. The problem I have is mostly related to how can I use my own Statuslevel and status tracker, so each pawn will have his own need. The jobgiver will need to access the tracker of each pawn to decide if it creates a job. And there is my problem, the pawn won't pick up the statuslevel and I can't cast the vanilla pawn into my own pawnclass.

mipen

Hm, to do this you will need to extend the pawn class and add new instances of your status level and tracker to it. Initialise these in the constructor for your class,and make sure they have the Saveable interface so you can save them with ExposeData. In the ThinkNode, check if the pawn is an instance of your new pawn class, and if it is, then do whatever you need with the tracker and status level there. Remember to check if it is not null first. I believe I have done something similar to what you want to achieve in my Mechanical Defence mod. I have droids which are extended from the pawn class and they have an internal charge level. I use an interface to provide a handle on it with a get set function. In the think tree there are three job givers which control when the droid will go to recharge. You can take a look here if you want

Gaesatae

Thanks very much mipen! I believe I did everything you explained. I'll check your code in a couple of days, and will see where I messed up.