Multiple sowTag on one building?

Started by GrandSaintDog, December 06, 2017, 05:27:45 AM

Previous topic - Next topic

GrandSaintDog

I'm currently working on a mod that will add, among other things, a new hydroponics basin. I want to have plants that can only be grown in that specific basin, but I also want other plants to be able to be grown it. No matter how I try to add multiple sowTags on the building, it won't work. I know I can just set the fertility requirement of the plant to be the base fertility of the basin (300% in this case), but is there any other way? I feel like there must be some mods out there that could bring natural soil to 300% fertility, and that doesn't fit thematically. In my canon, these plants cannot survive without specific attention that only a basin like the one I've made can provide, but these basins can also nurture "normal" plants. I know I could also just make copies of every plant that can be grown in hydroponics and change their sowTag, but that just seems wonky.

Also, first post!

CannibarRechter

So, you can't. RM XML maps directly into values in C# objects. In the case of <building>...<sowTag>, there is  a "public BuildingProperties building" field in ThingDef, and a "sowTag" string filed attached to building. Since there is only one in the original code, the XML can do nothing more.

One thing to keep in mind with RimWorld XML is worth repeating: it maps directly over into C# objects. So if the cardinality of something is singular, you can bet that it's just singular. When something has a cardinality of >1, you will ALWAYS see a list item <li><li> set, even if the list only has 1 item.

Do you happen to know any programming languages at all? If you do, I highly recommend getting Zhentar's verision of ILSpy, and using it to decompile RimWorld. It can be very helpful to cross reference the XML with the original code occasionally, and sometimes you can get information that way more expediently than any other method.
CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects

dburgdorf

Quote from: GrandSaintDog on December 06, 2017, 05:27:45 AMI know I could also just make copies of every plant that can be grown in hydroponics and change their sowTag, but that just seems wonky.

First, and most importantly, don't make copies of the plants' XML defs. Just use patches to add your new basin to the plants' sowTags. (You might also want to use patches to add your basin to VG's plants' sowTags, too, since so many people use VG.) That way, you're not interfering with other mods that also alter the plants.

But, yeah, it may seem wonky, but I'm afraid that's really your best bet.
- Rainbeau Flambe (aka Darryl Burgdorf) -
Old. Short. Grumpy. Bearded. "Yeah, I'm a dorf."



Buy me a Dr Pepper?

GrandSaintDog

#3
Quote from: CannibarRechter on December 06, 2017, 07:16:59 AM
Do you happen to know any programming languages at all?

Not even remotely, haha. I'm a microbiology major. The closest thing I have to any form of modding experience is making a weird, barely-functional creature in Dwarf Fortress.  I'm pretty much winging it with Google as my ally here. To my rudimentary understanding of what you've said (which may as well have been hieroglyphics to my brain, honestly...) sowTag can ONLY have one value on buildings because the C# code for "building" only allows for one? Is there any way to dick with that, or is that a big no-no?

Quote from: dburgdorf on December 06, 2017, 09:29:35 AM
Just use patches to add your new basin to the plants' sowTags. (You might also want to use patches to add your basin to VG's plants' sowTags, too, since so many people use VG.)

How does one go about making said patches?

kaptain_kavern

Quote from: GrandSaintDog on December 06, 2017, 07:41:50 PM
How does one go about making said patches?

Hi there,

Welcome in here  :D

Look here for some documentation on patches: https://ludeon.com/forums/index.php?topic=32785.0

GrandSaintDog

Quote from: kaptain_kavern on December 06, 2017, 08:08:55 PM

Hi there,

Welcome in here  :D

Look here for some documentation on patches: https://ludeon.com/forums/index.php?topic=32785.0

I found that and am trying my best, but I'm not able to get anything to work.
Here's what I got:
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationAdd">
    <xpath>/ThingDefs/ThingDef[defName = "PlantCorn"]/plant/sowTags</xpath>
    <value>
                <li>GlitterHydroponic</li>
    </value>
</Operation>
</Patch>

And, of course, it isn't working at all. Can anyone point me to where I'm going wrong?

kaptain_kavern

If we are talking about B18 your xpath should be

<xpath>Defs/ThingDef[defName = "PlantCorn"]/plant/sowTags</xpath>

at least that's what i think :p


GrandSaintDog

#7
That appears to have done it! Thank you so much. Do you think I should apply it to each plant individually, or is there a quicker way? I want to make sure that plants that can't be planted in normal basins also can't be planted in my basin.

EDIT: Also if anyone has any idea how to make my plants not able to be grazed on, that'd be excellent.

kaptain_kavern

AFAIK yes, you have to make a copy of that for each plant.

The patching system is still somewhat new - introduced for A17 - and I'm not an expert at all, but I do think it's better to make all those operations in one PatchOperationSequence but I'm still in the process of learning to use this. Having all of them patched one by one like the example you used would works without problems though.

Here is an example of patch with several operations from one of my mod, maybe it could help you.

jamaicancastle

Quote from: GrandSaintDog on December 06, 2017, 08:30:54 PM
That appears to have done it! Thank you so much. Do you think I should apply it to each plant individually, or is there a quicker way? I want to make sure that plants that can't be planted in normal basins also can't be planted in my basin.

EDIT: Also if anyone has any idea how to make my plants not able to be grazed on, that'd be excellent.
I have heard conflicting reports about whether a patch can affect multiple defs. You can certainly build an xpath that will match, for instance, every instance of the sowTag "Hydroponic", then have an instruction to add a sibling node with your new tag; I just don't know if RW will actually change them all.

As for being grazed upon - if you built your plant def off of one of the vanilla ones, it should have an "ingestible" tag somewhere. Try adding <foodType>None</foodType> to that tag; that should remove the flag that tells the game your plant is edible.

CannibarRechter

> I have heard conflicting reports about whether a patch can affect multiple defs.

When I tested this, it could not.

CR All Mods and Tools Download Link
CR Total Texture Overhaul : Gives RimWorld a Natural Feel
CR Moddable: make RimWorld more moddable.
CR CompFX: display dynamic effects over RimWorld objects