Making custom neurotrainers

Started by Oiltanker, February 03, 2016, 04:56:07 PM

Previous topic - Next topic

Oiltanker

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]

RawCode

QuoteMoreover when nurotrainer is being created it produces a lot of errors till it gets wanted skill.

please explain this part more "detailed"

Oiltanker

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]

Oiltanker

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]

Fluffy (l2032)

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.

Oiltanker

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?

Fluffy (l2032)

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).

Oiltanker

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.

Fluffy (l2032)

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.

Oiltanker

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]

Fluffy (l2032)

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?

Oiltanker

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?

Fluffy (l2032)

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.

Oiltanker

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.

Fluffy (l2032)

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?