Ludeon Forums

RimWorld => Mods => Help => Topic started by: Oiltanker on February 03, 2016, 04:56:07 PM

Title: Making custom neurotrainers
Post by: Oiltanker on February 03, 2016, 04:56:07 PM
I was trying to create dll file that would allow me to create custom neurotrainers, but a far as I got is *se the code example*.

What I do is I create multiply item defs: each one represents neurotrainer in a specific skill. Thus it is 12 items that the game consider to be different from vanilla neurotrainer. And I want them to be classified by game as one item.

Is there any way to do it other differently.

[attachment deleted by admin - too old]
Title: Re: Making custom neurotrainers
Post by: RawCode on February 04, 2016, 01:53:51 AM
QuoteMoreover when nurotrainer is being created it produces a lot of errors till it gets wanted skill.

please explain this part more "detailed"
Title: Re: Making custom neurotrainers
Post by: Oiltanker on February 04, 2016, 06:04:50 AM
The problem is that when a neurotrainer is being created postmake method is called several times util neurotrainer has needed skill (just look at the source code). For more explanation see screenshots.

[attachment deleted by admin - too old]
Title: Re: Making custom neurotrainers
Post by: Oiltanker on February 04, 2016, 08:07:42 AM
Solved problem with errors, but it is still 12 different items to be defined (in order to make custom neurotrainer for each skill). Can it be 1 item instead of 12 somehow?

*I attached new code*

[attachment deleted by admin - too old]
Title: Re: Making custom neurotrainers
Post by: Fluffy (l2032) on February 05, 2016, 02:13:16 AM
Sure, you can create defs on the fly. Set up the class to work right, then create implied neurotrainers from skilldefs, happens all the time for meat, leather, various terrain patches based on stone, etc.
Title: Re: Making custom neurotrainers
Post by: Oiltanker on February 05, 2016, 02:41:10 AM
Quote from: Fluffy (l2032) on February 05, 2016, 02:13:16 AM
then create implied neurotrainers from skilldefs, happens all the time for meat, leather, various terrain patches based on stone, etc.
I don't understand that. Can you explain what you mean please?
Title: Re: Making custom neurotrainers
Post by: Fluffy (l2032) on February 05, 2016, 03:29:54 AM
defs don't necessarily need to be created from XML. If all the relevant stats (e.g. name, target, whatever) can be implied from another def, or are the same for all, you can create defs programatically.

E.g. the game generates meatDefs and corpseDefs for each raceDef automatically, the same goes for 'rocky ground', where there is a version generated for each type of rock in the game. You could do the same for neurotrainers; loop over skillDefs, and create a neurotrainer for each. I don't see why you need many different classes (but I might be wrong).
Title: Re: Making custom neurotrainers
Post by: Oiltanker on February 05, 2016, 04:56:57 AM
Thought behind all that is to make one item - Custom Neurotrainer, that would get right skill when it gets crafted. I have thought to use reflection to go up tha stack and get reference to the current recipedef instance and the change the field "skill" of a CustomNT, but that seems not to be possible.
Title: Re: Making custom neurotrainers
Post by: Fluffy (l2032) on February 05, 2016, 06:00:20 AM
what is the 'right' skill?
Why go through all the hassle when you can just generate thingDefs + recipeDefs and let the game handle the rest?

I feel you're seriously overcomplicating this whole thing.
Title: Re: Making custom neurotrainers
Post by: Oiltanker on February 05, 2016, 06:42:36 AM
The thing is that I end up with 12 different items and, for example, storage zones display this (see screenshot). And recipes that include neurotrainers as the ingridients do the same. But if it they were recognized by the game as one thing it would be a lot more convenient. But the thing is that I need to know what specific recipedef made this specific neurotrainer, so that I could set in the created neurotrainer skill atribute whose value would be stored in the recipedef.

[attachment deleted by admin - too old]
Title: Re: Making custom neurotrainers
Post by: Fluffy (l2032) on February 05, 2016, 10:14:52 AM
ok I understand what you're trying to do now. Frankly, I don't think it'll work. You can load a custom skill into the item with a comp, but you'd probably have to break open the item creation methods. And you'd still end up with separate recipes, or you'd have to break the crafting UI open as well to add an option there.

Then when you have such an item, if all NT's share the same def they'll get stacked. Which means they loose all their custom information, and now you have just one type of of NT. The same thing happens with stacks of meals - they all suddenly have the same ingredient types  when they get stacked.

So really, the only thing you gain is less entries in the thingFilter ui's, but why not just create a new neurotrainer thingcategory so users can collapse it at will?
Title: Re: Making custom neurotrainers
Post by: Oiltanker on February 05, 2016, 12:31:03 PM
Quote from: Fluffy (l2032) on February 05, 2016, 10:14:52 AM
So really, the only thing you gain is less entries in the thingFilter ui's, but why not just create a new neurotrainer thingcategory so users can collapse it at will?

That is a good idea. Can you show me an example how to do that?
Title: Re: Making custom neurotrainers
Post by: Fluffy (l2032) on February 05, 2016, 04:14:58 PM
ThingCategories can be added in xml, see Defs/ThingCategoryDefs.

Adding a neurotrainer to a category is as simple as adding the category defname in the thingCategories node on the thingDef xml.

It's a bit trickier when you're doing this in a .dll. I'd still suggest adding the category with xml (it won't change or get copied). Then what you have to do dynamically is 1) add the generated thingdef to the category's childThingDefs, and add the category to the thingDef's thingCategories. Both are public lists, should be fairly straightforward.
Title: Re: Making custom neurotrainers
Post by: Oiltanker on February 06, 2016, 07:11:16 AM
Another question: How can I specify in recipe OR case? I mean I want recipe to accept 5 items from a specific list no matter if all of them are items of one type or multiple.
Title: Re: Making custom neurotrainers
Post by: Fluffy (l2032) on February 06, 2016, 09:20:34 AM
I don't think recipes can deal with that. You could specify your inputs as a new stuff category and use that on the recipe, but then it still can't mix different things from the same stuff (e.g. I've never seen a tailor use half deer leather and half human leather). The only place I've seen mixing ingredients happening is in meal production, maybe see how it's done there?
Title: Re: Making custom neurotrainers
Post by: Oiltanker on February 06, 2016, 09:46:50 AM
I just solved it. Now my recipe can use my neurotrainers or default neurotrainers or mixture of them to craft that thing. Are you interested in looking at the example?
Title: Re: Making custom neurotrainers
Post by: Fluffy (l2032) on February 06, 2016, 10:55:46 AM
sure, always keen to learn new tricks :)
Title: Re: Making custom neurotrainers
Post by: Oiltanker on February 06, 2016, 12:31:24 PM
Here, I took an example from my mod for neurotrainers.

[attachment deleted by admin - too old]
Title: Re: Making custom neurotrainers
Post by: Fluffy (l2032) on February 06, 2016, 05:07:11 PM
ah, it's an xml tag... Funny that not more mods use that. Still, good on ya :)