How do I increase the growth rate for one specific plant?

Started by StoneWolf, December 27, 2017, 06:35:40 AM

Previous topic - Next topic

StoneWolf

The mod I am currently working on is a mod which lets the pawns apply pesticide onto the crops. I would like to have one of the benefits of doing that be decreased growth time for the plant which the pesticide was applied onto but the fertility of a plant is sadly hardcoded as far as I can tell.

The fertility is decided by the light intensity, temperature and the soil fertility. It makes no sense to change the first two in this case and when I change the soil fertility all tiles of that type get increased fertility. That is because the fertility is in the def of the tile which is the same for all tiles of that type. I know that I could directly increase the growth value but that is not my preferred option for immersion reasons. Plants don't really go from 10 % grown to 20 % in the blink of an eye in the real world. How else can I increase the growth rate of the plant which the pesticide was applied onto?




[attachment deleted by admin: too old]

CannibarRechter

I'm confused by your question. What outcome do you want to achieve here? You can set the minimum soil fertility, the sensitivity to the soil fertility, and the total grow days required (as adjusted by the prior numbers)? What can you not achieve here?
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

StoneWolf

#2
Quote from: CannibarRechter on December 27, 2017, 07:20:44 AM
I'm confused by your question. What outcome do you want to achieve here? You can set the minimum soil fertility, the sensitivity to the soil fertility, and the total grow days required (as adjusted by the prior numbers)? What can you not achieve here?

I want to make the one plant that the pesticide was applied onto grow faster. Sorry if I was unclear on that point. I've since edited the question details to make it more understandable.

dburgdorf

Quote from: StoneWolf on December 27, 2017, 07:42:51 AMI want to make the one plant that the pesticide was applied onto grow faster....

This is not something I've looked at specifically, so I could be wrong, but I suspect the simple answer is, "You can't."  A lot of information in RimWorld is stored not on an individual item basis, but on a "thing" basis. While the stage of growth (e.g., "70% grown") of a particular potato plant, for example, is stored as data for that plant, the rate of growth of potato plants is stored simply as part of the generic "thing" definition for potato plants. Similarly, the fertility of a terrain tile isn't stored individually for each tile, but only as part of the "thing" definition for each type of terrain.

So you can't change the growth rate of potato plants without changing the growth rate of *all* potato plants, and you can't change the fertility of a particular rich soil tile without changing the fertility of *all* rich soil tiles.

It may not be "realistic," but having plants gain 10% (or whatever amount) of growth immediately upon application of your pesticide is probably the only way to achieve your goal, at least without a need for potentially extensive recoding of plant growth mechanics. Even that, though, could be problematic, as I'm not sure how you could prevent players from just spraying pesticide on the same plants repeatedly, in order to gain "instant" full growth.
- Rainbeau Flambe (aka Darryl Burgdorf) -
Old. Short. Grumpy. Bearded. "Yeah, I'm a dorf."



Buy me a Dr Pepper?

StoneWolf

Quote from: dburgdorf on December 27, 2017, 08:26:26 AM
Quote from: StoneWolf on December 27, 2017, 07:42:51 AMI want to make the one plant that the pesticide was applied onto grow faster....

This is not something I've looked at specifically, so I could be wrong, but I suspect the simple answer is, "You can't."  A lot of information in RimWorld is stored not on an individual item basis, but on a "thing" basis. While the stage of growth (e.g., "70% grown") of a particular potato plant, for example, is stored as data for that plant, the rate of growth of potato plants is stored simply as part of the generic "thing" definition for potato plants. Similarly, the fertility of a terrain tile isn't stored individually for each tile, but only as part of the "thing" definition for each type of terrain.

So you can't change the growth rate of potato plants without changing the growth rate of *all* potato plants, and you can't change the fertility of a particular rich soil tile without changing the fertility of *all* rich soil tiles.

It may not be "realistic," but having plants gain 10% (or whatever amount) of growth immediately upon application of your pesticide is probably the only way to achieve your goal, at least without a need for potentially extensive recoding of plant growth mechanics. Even that, though, could be problematic, as I'm not sure how you could prevent players from just spraying pesticide on the same plants repeatedly, in order to gain "instant" full growth.

This may not be the answer I was hoping for, but you're right. I'll have to go for the more unrealistic route even though the avid roleplayer within me screams at the immersion-breaking aspect of it. Thanks for the quick response!

Thanks to a dictionary containing all plants on the map which has had pesticides applied to it, there is no risk of the same plant having pesticides applied to it repeatedly. I understand your worry though, it was definitely something which a C# newbie like me should have avoided, at least for my first Rimworld mod!

jamaicancastle

If Harmony is capable of patching a class attribute's getter function (which I've never tried, so I'm not sure if it will work) it should be as simple as adding a postfix to the Plant.GrowthRate getter. This normally determines the plant's adjusted growth rate due to fertility, light, and temperature, so all you'd have to do is take in the normal return value and then check if this is in your list of affected plants. If not, return the original return value unmodified; if so, return it with a 10% boost or whatever.

Alternative methods: you can get at Plant.TickLong, which is where the growth is actually applied. However, this handles all of the plant's per-tick functions, so it's kind of long-winded, and there's no straightforward way to just tack your extra growth onto the end without possibly causing problems.

StoneWolf

Quote from: jamaicancastle on December 27, 2017, 09:47:14 AM
If Harmony is capable of patching a class attribute's getter function (which I've never tried, so I'm not sure if it will work) it should be as simple as adding a postfix to the Plant.GrowthRate getter. This normally determines the plant's adjusted growth rate due to fertility, light, and temperature, so all you'd have to do is take in the normal return value and then check if this is in your list of affected plants. If not, return the original return value unmodified; if so, return it with a 10% boost or whatever.

Alternative methods: you can get at Plant.TickLong, which is where the growth is actually applied. However, this handles all of the plant's per-tick functions, so it's kind of long-winded, and there's no straightforward way to just tack your extra growth onto the end without possibly causing problems.

Hmm... You're right. I'll get to work on it and see if it is possible. Thanks!

Canute

Maybe you should look for a temp. terrain change.
After you apply pesticide, it should turn the terrain with into one with boosted soil fertility.
And after x days/hours it should turn back to the original.

StoneWolf

#8
Quote from: jamaicancastle on December 27, 2017, 09:47:14 AM
If Harmony is capable of patching a class attribute's getter function (which I've never tried, so I'm not sure if it will work) it should be as simple as adding a postfix to the Plant.GrowthRate getter. This normally determines the plant's adjusted growth rate due to fertility, light, and temperature, so all you'd have to do is take in the normal return value and then check if this is in your list of affected plants. If not, return the original return value unmodified; if so, return it with a 10% boost or whatever.

Alternative methods: you can get at Plant.TickLong, which is where the growth is actually applied. However, this handles all of the plant's per-tick functions, so it's kind of long-winded, and there's no straightforward way to just tack your extra growth onto the end without possibly causing problems.

I took your advice and managed to get it all up and running successfully! Detouring properties is, as I soon found out, supported and nowhere near as difficult as I at first feared. By detouring like this the change integrates with the rest of the vanilla code seemlessly. Seems like I won't have to give up on making this mod after all!

StoneWolf

Quote from: Canute on December 27, 2017, 10:58:28 AM
Maybe you should look for a temp. terrain change.
After you apply pesticide, it should turn the terrain with into one with boosted soil fertility.
And after x days/hours it should turn back to the original.

While it may be possible if given enough time, I do not think it would be worth the effort. I would have to create custom terrain types for all growable soils in the game which I think there are plenty of. Even if I got it all to work, the mod would be incompatible with any other mod which adds soils. Thanks for trying to help anyhow.

Canute

I just notice,
Dub's hygience mod include a water sprinkler, that increase the growth-rate of the plant's inside the work radius.
Maybe you should take a look into that.