Plant that produces wood and food when harvested

Started by Igabod, November 04, 2014, 12:34:04 AM

Previous topic - Next topic

Igabod

I'm wanting to make a plant that when harvested produces both wood and an edible fruit. I'm having difficulty figuring out how to make the <harvestedThingDef> include Wood as well as the new tree fruit food item. I could use some advice on this. The item names and everything will be changed later, I'm just working on getting a generic item working before I do all the work to pick a specific plant and then do the textures for it.

Fruit food definition:

  <ThingDef ParentName="ResourceBase">
    <defName>TreeFruitFood</defName>
    <label>NewFruitThing</label>
    <description>Food grows on trees? Who knew?</description>
    <graphicPathSingle>TreeFruitFood</graphicPathSingle>
    <soundInteract>Food_Drop</soundInteract>
    <soundDrop>Food_Drop</soundDrop>
    <baseMarketValue>4</baseMarketValue>
    <statBases>
      <Flammability>1.0</Flammability>
    </statBases>
    <food>
      <quality>Raw</quality>
      <nutrition>30</nutrition>
      <eatenDirectThought>AteRawFood</eatenDirectThought>
      <eatEffect>EatVegetarian</eatEffect>
      <soundEat>RawVegetable_Eat</soundEat>
    </food>
    <storeCategories>
      <li>PlantFoodRaw</li>
    </storeCategories>
  </ThingDef>
 
  </Thingdefs>


and the plant def


  <ThingDef ParentName="TreeBase">
    <defName>PlantFruitTree</defName>
    <label>fruit tree</label>
    <description>There seems to be some sort of fruit growing in this tree!</description>
    <graphicPathFolderRandom>Things/Plant/TreeFruitTree</graphicPathFolderRandom>
    <selectable>true</selectable>
    <statBases>
      <Beauty>15</Beauty>
    </statBases>
    <plant>
      <growthPer20kTicks>0.03</growthPer20kTicks>
      <harvestWork>900</harvestWork>
      <harvestDestroys>true</harvestDestroys>
      <harvestedThingDef>WoodLog</harvestedThingDef>
    <harvestYieldRange>
        <min>15</min>
        <max>40</max>
      </harvestYieldRange>
  <harvestedThingDef>TreeFruitFood</harvestedThingDef>
  <harvestYieldRange>
<min>1</min>
<max>5</max>
      <harvestTag>Wood</harvestTag>
  <harvestTag>Fruit</harvestTag>
      <harvestMinGrowth>0.50</harvestMinGrowth>
      <sowableGround>true</sowableGround>
      <sowWork>1200</sowWork>
      <sowRequireOpenPassageAdjacent>true</sowRequireOpenPassageAdjacent>
      <seedShootRadius>20</seedShootRadius>
      <wildClusterSizeRange>
        <min>15</min>
        <max>30</max>
      </wildClusterSizeRange>
      <wildClusterRadius>15</wildClusterRadius>
  </plant>
  </ThingDef>


Obviously the latter def is flawed. Could I maybe separate the WoodLog with a comma and add the TreeFruitFood item in after that before closing the harvestedThingDef thing? and how do I go about setting a different min/max yield for the wood than for the fruit? I've been banging my head figuratively on my imaginary desk trying to get this working. Any help on this would be so much appreciated. Thanks.

Also, looking at the preview of this, it seems that the code tags changed my formatting. I don't leave my work looking that sloppy.

Rikiki

Seems that you cannot spawn 2 kind of products as the harvestedThingDef is not a list.
You could however override the Plant.YieldNow function and add an additional custom harvestedThingDef.

skullywag

Yep dll only for now unless Tynan changes this to be a list as Rikiki stated.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Igabod

ok thanks for the input. I guess for now I'll have to make them not yield wood. I can make the plant not get removed from the map when it is harvested by changing the <harvestDestroys>true</harvestDestroys> to false I assume. But the question is, will the plant regrow the fruit again or just stay there and be useless from then on?

Rikiki

Given what I saw with ILSpy, the plant will regrow. Its growth will however be set to 0.08 (hard coded).

You may want to set killedLeavings to "wood" so when you "cut" the plant, it will spawn wood (not proportional to growth...).
"Choping" will still get you the fruits.
I think this mechanic would not be the best as cutting the tree will always give the same amount of wood.

So basically, orchard is not yet well handled and specific dll would be the best! ;)

Igabod

#5
Quote from: Rikiki on November 04, 2014, 07:11:52 AM
Given what I saw with ILSpy, the plant will regrow. Its growth will however be set to 0.08 (hard coded).

You may want to set killedLeavings to "wood" so when you "cut" the plant, it will spawn wood (not proportional to growth...).
"Choping" will still get you the fruits.
I think this mechanic would not be the best as cutting the tree will always give the same amount of wood.

So basically, orchard is not yet well handled and specific dll would be the best! ;)

Hmmm that's a good idea, I think I can work with that. There are a couple examples of trees that produce food stuff but aren't very good for wood production. I can see how a pistachio tree or something like that could give you a small amount of usable wood if you cut it down. I will have to look at some pictures of some plants now and see if there is one I can do well enough. I appreciate the help. Wish I had the programming skills to do a .dll but I'll make do with xml mods.

[edit to add] I wonder if there is a way to make the tree use a different texture when it is ready to harvest? I think maybe the wild berry bushes do this but I may be mistaken.

Rikiki

You can adjust the size with visualSizeRange. There is not a different texture when at full growth but you can make several textures and use them with graphicPathFolderRandom for more variety. :)
I believe you have to name them MyPlantNameA, MyPlantNameB... Not sure however, you will have to test!

Igabod

Quote from: Rikiki on November 04, 2014, 11:21:32 AM
You can adjust the size with visualSizeRange. There is not a different texture when at full growth but you can make several textures and use them with graphicPathFolderRandom for more variety. :)
I believe you have to name them MyPlantNameA, MyPlantNameB... Not sure however, you will have to test!

Yeah I've been playing around with making new plants for a little while now. You don't have to have the name include an A or B at the end if you are just going with one texture. I haven't tried using random names for the multi-texture things I've done yet. I just went with the crowd and named them with A and B and C etc. I don't think the file name matters at all when you are using a multi-texture thing though. It just takes any images that happen to be in the folder that is specified in the file path. At least I'm assuming that's the case cause that would be the easiest way to do it.

Rikiki

You're right! I merged graphicPathMulti and graphicPathFolderRandom... :-[

Igabod

#9
Ok I've got it all working, but to harvest the fruit you have to Cut the plant rather than Harvest or Chop it. How do I change it so you have to Harvest?

[edit to add] Nevermind, got it working. Just had to change HarvestTag to Standard. Dunno why I had it set different.

Rikiki

The harvest tag "Wood" means you can "chop" this plant (like a tree). :)

Igabod

Quote from: Rikiki on November 04, 2014, 03:36:35 PM
The harvest tag "Wood" means you can "chop" this plant (like a tree). :)

Thanks. :) That is useful to know.

skullywag

im just gonna put this here as ive just hit it in my purple ivy mod, its nothing to do with this but im annoyed and want to vent.

you cannot set a plant to be non cuttable....boooooo. that is all.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Igabod

Quote from: skullywag on November 04, 2014, 06:40:06 PM
im just gonna put this here as ive just hit it in my purple ivy mod, its nothing to do with this but im annoyed and want to vent.

you cannot set a plant to be non cuttable....boooooo. that is all.

will it still be destroyed if you set it to not be destroyed upon harvest? This sounds like something Tynan should put a work-around in the next alpha for if it can't be done already. Though maybe you can set it up sorta like the mythical Hydra. Cut the plant and it spawns 2 more plants. That way you make the plant even more of a threat and solidify the need for fire to kill it.

skullywag

Quote from: Igabod on November 04, 2014, 07:55:04 PM
Quote from: skullywag on November 04, 2014, 06:40:06 PM
im just gonna put this here as ive just hit it in my purple ivy mod, its nothing to do with this but im annoyed and want to vent.

you cannot set a plant to be non cuttable....boooooo. that is all.

will it still be destroyed if you set it to not be destroyed upon harvest? This sounds like something Tynan should put a work-around in the next alpha for if it can't be done already. Though maybe you can set it up sorta like the mythical Hydra. Cut the plant and it spawns 2 more plants. That way you make the plant even more of a threat and solidify the need for fire to kill it.

Cant cuz when you kill it with fire it sprouts some more...

heres the actual check in code for the designation to "cutplants":


public override AcceptanceReport CanDesignateAt(IntVec3 sq)
{
if (!sq.InBounds())
{
return false;
}
if (sq.Fogged())
{
return false;
}
Plant plant = sq.GetPlant();
if (plant == null)
{
return false;
}
if (Find.DesignationManager.DesignationOn(plant, DesignationDefOf.CutPlant) != null)
{
return false;
}
return true;
}


nothing we can do....
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?