Adding a prerequisite to a XML patch

Started by Kilroy232, June 18, 2017, 12:55:56 PM

Previous topic - Next topic

Kilroy232

Is it possible to have a patch that has a prerequisite that you have to research before the patch is applied?

kaptain_kavern

Something I asked in the "what will make the game easier to mod"!

I totally agree it could be great but as far as I know, it's not possible with XML only for now

Kilroy232

Quote from: kaptain_kavern on June 18, 2017, 12:58:48 PM
Something I asked in the "what will make the game easier to mod"!

I totally agree it could be great but as far as I know, it's not possible with XML only for now

If its not possible through XML only and anyone knows how to achieve this through C# I would love to know so that I can use this and hopefully help others do this as well.

I need something to replace the removed <ResearchMods> and <SpecialActions> nodes

Xnope

#3
Do you mean XML patching? And do you mean that you essentially want to change the values of an object's def based on prerequisites?

If so, I think it is certainly possible with C# and can be made easier with JecsTools. JecsTools has a component called CompToggleDef that you could use to toggle a ThingWithComps's standard def to a different def if certain prerequisites are met. It would take some tweaking but after you have the C# figured out, you can use an XML patch to add the comp to whatever ThingDefs you want.

Edit 1:
You'd probably want to create a new class and either look at CompToggleDef for inspiration or inherit it and change some things. For instance, you'd want to hide any ITabs that are associated with Jec's version of the comp. Honestly I haven't really ever used Jec's CompToggleDef, so I didn't know exactly how it works, but I just looked at a bit of its source code and I think it would be better to write your own similar comp. Point is, you want the ability to despawn a thing, change its def, and respawn it with everything the same minus the def change within the same tick.

Edit 2:
Sorry, the more thought I put into this, the more I seem to switch my opinion on how this should be done. Since you're question concerned only changing a Def's value after a research prequisite is met, it wouldn't be too bad a thing to change a Thing's Def's values directly from the DefDatabase.

The only downside is that you'd have to reload the Def's default values every time a new save is loaded, then recheck if the prerequisites are still met and reapply changes, otherwise you could research something in one save, which would activate a Def's new value, then switch over to a different save and the Def would retain the changed value. You could easily do this reloading with a HugsLib OnMapLoaded() call, as long as you keep track of what Defs are changeable, which in turn could be done with a ModExtension or a comp.

Complicated solution, for sure. Anyone else have something more elegant?
My W.I.P. mods:
Carnivale: GitHub | Forum Post
XnopeCore: GitHub

jamaicancastle

Quote from: Xnope on June 18, 2017, 03:49:59 PM
Complicated solution, for sure. Anyone else have something more elegant?
Would it be possible to have a function that runs when a research project is completed that scans the map and replaces any object X with an object Y? That would make the changes persistent across save/loads, although it limits what you can do with the upgrades (they need to be strict stages, not something where you have multiple upgrades in parallel) and you would need to monkey around with traders and new pawns to make sure they used the right version (assuming whatever it is is something traders or new pawns can spawn with; if you're upgrading your turrets or generators or whatever they could just be unable to spawn in trader inventories).

Actually, with a little thought, you could use this to make upgrades in parallel (researching A upgrades thing O -> thing A and thing B -> thing AB, and likewise researching B upgrades O -> B and A -> AB) but the number of defs you need would increase with the square of the number of upgrades, so it would quickly grow out of hand.