[1.0] SeedsPlease!

Started by notfood, August 16, 2016, 01:39:39 AM

Previous topic - Next topic

GrumpyProgrammer

Quote from: notfood on August 21, 2016, 11:30:34 PM
About the autogeneration of market value. I can do it that way. Here are the variables, can you come with an interesting formula?
plant.harvestedThing.BaseMarketValue
plant.harvestedThing.IsIngestible (boolean)
plant.harvestYield (count of things)
plant.growDays (0 to many days)
plant.fertilityFactorGrowthRate (0 to 1)
plant.sowMinSkill (0 to 20)
plant.growOptimalGlow (0 to 1)

Those are the most relevant variables. There are some more.

I can give it a shot.

MarketValue = RoundUpToNearestHundredth(BaseMarketValue * UtilityValue) * (harvestYield / growDays) * (SeedsProduced * SeedChance * (1 + ExtraChance)) * (21 - sowMinSkill)

UtilityValue = 1 + (IsColonistIngestible * 0.1) + (IsAnimalIngestible * 0.05) + (craftingRecipesCount * 0.01) + (IsMedicinal * 0.1)

Let's look at an example: potatoes with the spreadsheet provided kindly by gillsminnow in the first comment page and the vanilla game values for growDays. I'll assume BaseMaketValue is equivelant to ProduceValue for this example and that there isn't any crafting recipe that uses potatoes beyond the three meal types (like vodka or something in a mod -- would this be programmatically possible to discover? Ask Ringworld how many crafting recipes exist with [plant] as a possible ingredient?)

First, the Utility Value: 1 + (1 * 0.1) + (1 * 0.05) + (3 * 0.01 ) + (0 * 0.1)

UtilityValue = 1.18

This means that potato seeds are actually 18% more valuable than the BaseMarketValue of potatoes themselves. Now let's use it in the MarketValue calculation:

MarketValue = RoundUp((1.5 * 1.18) * (8 / 4.90) * (1 * 0.58 * (1 + 0.1)) * (21 - 0))

MarketValue = RoundUp(38.71748)

MarketValue = 38.72

So, the final value of potato seeds is 38.72 silver per packet. It's braindead easy to grow, grows fairly quickly, is edible by both animals and people, and can be used in three types of recipes. Not a bad or unfair price for such a useful little plant, I must say.

A few cavats: you'll need to put in some kind of sane minimum value for growDays; obviously, 0 won't cut it. If it has zero grow days, then maybe something like a default of 0.01. That will balloon up the price nicely for such an insane turn around.

I'm clearly making a few assumptions here; mainly that there is a way to tell if a plant is animal ingestible vs colonist ingestible, as well as if it can be used as medicine, a crafting ingredient, and how many of those. I honestly don't know if any of that is possible to get.

As a bonus, let's do the same calculation, but for Devilstrand. I'm assuming Devilstrand has a minimum skill requirement of 10, (but I don't know if that's accurate) and its only use is to make devilstrand fiber.
 
UtilityValue = 1 + (0 * 0.1) + (0 * 0.05) + (1 * 0.01) + (0 * 0.1)

So the UtilityValue is 1.01, really close to its BaseMarketPrice.

MarketValue = RoundUp((6.4 * 1.01) * (3 / 22.5 ) * (1 * 0.55 * (1 + 0.1)) * (21 - 10))

MarketValue = 5.735722667

MarketValue = 5.74

And here we see that because Devilstrand is hard to grow, takes forever to mature, and has very limited utility it's cheap to get the seeds. The seeds are actually cheaper than the Raw Devilstrand itself! Which makes a lot of sense, considering how much of a hassle to cultivate the plant is -- most people would rather just get the damn Raw Devilstrand and let some other sucker deal with trying to grow the persnickerty plant, so the demand for seeds would be low.

Out of curiosity, what does plant.growOptimalGlow measure? How much light is needed for the plant to grow optimally?

notfood

Hmmm something is wrong with the formula, I'm getting strange results. Even if I remove the utilty factor.

The number of recipes is... not very accurate, a lot of duplicates and food has none. Wood has constant 18 recipes for example while potato has 0. There is only 1 recipe for health that's the herbal medicine because there is only 5 tipes of medicine in vanilla Rimworld.

float utility = 1f;
if (plant.plant.harvestedThingDef.ingestible != null) {
if (plant.plant.harvestedThingDef.ingestible.HumanEdible) {
utility += 0.1f;
}
if (plant.plant.harvestedThingDef.ingestible.nutrition > 0f){
utility += 0.05f;
}
}

/*var recipes = (
from recipe in DefDatabase<RecipeDef>.AllDefs
where recipe.IsIngredient(plant.plant.harvestedThingDef)
select recipe
);

int recipeCount = recipes.Count ();

utility += recipeCount * 0.01f;

var medicinalRecipes = (
from recipe in recipes
where recipe.defName == ""
select recipe
);

int medicinalRecipesCount = medicinalRecipes.Count ();

if (medicinalRecipesCount > 0) {
utility += 0.1f;
}*/

float marketValue = plant.plant.harvestedThingDef.BaseMarketValue * utility;

if (plant.plant.growDays > 0) {
marketValue *= plant.plant.harvestYield / plant.plant.growDays;
}
marketValue *= seed.seedFactor * seed.baseChance * (1 + seed.extraChance) * (21 - plant.plant.sowMinSkill);

BaseMarketValue = Mathf.Round(marketValue);

Log.Message ("> " + plant + " has " + BaseMarketValue + " seed value for " + utility + " utility");


  PlantPotato has 133 seed value for 1.15 utility
  PlantCorn has 132 seed value for 1.15 utility
  PlantRice has 106 seed value for 1.15 utility
  PlantHaygrass has 107 seed value for 1.05 utility
  PlantStrawberry has 55 seed value for 1.15 utility
  PlantCotton has 66 seed value for 1 utility
  PlantDevilstrand has 6 seed value for 1 utility
  PlantHealroot has 15 seed value for 1 utility
  PlantHops has 82 seed value for 1.05 utility
  PlantTreeOak has 46 seed value for 1 utility
  PlantTreePoplar has 55 seed value for 1 utility
  PlantTreePine has 62 seed value for 1 utility
  PlantTreeBirch has 62 seed value for 1 utility
  PlantTreeTeak has 61 seed value for 1 utility
  PlantTreeCecropia has 94 seed value for 1 utility
  PlantPotato has 133 seed value for 1.15 utility
  PlantCorn has 132 seed value for 1.15 utility
  PlantRice has 106 seed value for 1.15 utility
  PlantHaygrass has 107 seed value for 1.05 utility
  PlantStrawberry has 55 seed value for 1.15 utility
  PlantCotton has 66 seed value for 1 utility
  PlantDevilstrand has 6 seed value for 1 utility
  PlantHealroot has 15 seed value for 1 utility
  PlantHops has 82 seed value for 1.05 utility
  PlantTreeOak has 46 seed value for 1 utility
  PlantTreePoplar has 55 seed value for 1 utility
  PlantTreePine has 62 seed value for 1 utility
  PlantTreeBirch has 62 seed value for 1 utility
  PlantTreeTeak has 61 seed value for 1 utility
  PlantTreeCecropia has 94 seed value for 1 utility
  PlantPotato has 133 seed value for 1.15 utility
  PlantCorn has 132 seed value for 1.15 utility
  PlantRice has 106 seed value for 1.15 utility
  PlantHaygrass has 107 seed value for 1.05 utility
  PlantStrawberry has 55 seed value for 1.15 utility
  PlantCotton has 66 seed value for 1 utility
  PlantDevilstrand has 6 seed value for 1 utility
  PlantHealroot has 15 seed value for 1 utility
  PlantHops has 82 seed value for 1.05 utility
  PlantTreeOak has 46 seed value for 1 utility
  PlantTreePoplar has 55 seed value for 1 utility
  PlantTreePine has 62 seed value for 1 utility
  PlantTreeBirch has 62 seed value for 1 utility
  PlantTreeTeak has 61 seed value for 1 utility
  PlantTreeCecropia has 94 seed value for 1 utility

GrumpyProgrammer

Quote from: notfood on September 05, 2016, 10:53:59 AM
Hmmm something is wrong with the formula, I'm getting strange results. Even if I remove the utilty factor.

The thing to do here would be the verify each part of the formula separately to see where the calculation goes wonky (ideally with an automated unit test). Eliminating the utility function is a good first step and you've already broken up the calculation into steps in your code, so you should be able to just check each stage of the calculation to make sure it's correct. The calculation should give 32.81 as the value for potato seeds without the utility function if you're using the revised values listed here: https://embed.gyazo.com/5064e1ea35887515a60a932b29b76ac5.png.

That would be my first guess as to why the calculation is not producing expected values; you're using the original vanilla values, rather than the revised ones from that image.

Quote
The number of recipes is... not very accurate, a lot of duplicates and food has none. Wood has constant 18 recipes for example while potato has 0.

Interesting. Does vanilla not specify what goes into meals? Since every colonist edible plant can also be used in all three meal types (not counting nutrient paste), you could just add in +3 to the recipe count if a plant produces colonist edibles. It's a bit of a hack and will break for a mod which adds a plant that is edible but not cookable, but I think that's reasonably rare to ignore (and if vanilla doesn't specify what can go into a meal, then it likely assumes anything colonist edible is cookable as well, so you won't ever get that situation in the first place).

Quote
There is only 1 recipe for health that's the herbal medicine because there is only 5 tipes of medicine in vanilla Rimworld.

That's to be expected, yes? The only plant that produces medicine of any type in vanilla is the HealRoot, and it produces herbal medicine. The utility function only calculates one level deep in production chains (though I suppose you could recursively walk down the recipe list to get a count of absolutely everything that the plant and its sub-products could be used for, but that seems excessive).

laokangz2

I very like your mod, can you make a upgrade for A15? very thanks .

notfood

#34
I'm just struggling with this formula. I'll just do it manually for now.

edit... I remembered I was waiting for CCL. This mod without traders makes no sense.

nailertn

Quote from: notfood on September 13, 2016, 04:03:40 PM
I'm just struggling with this formula. I'll just do it manually for now.

edit... I remembered I was waiting for CCL. This mod without traders makes no sense.

Actually it does. You can start off your colonists with a couple of seeds and let them go from there. This mod does to crops what components do to electric devices: it puts a limit on rapid early expansion. You can't just cover the map in crops on day 1 and never worry about food again. I'm surprised it's not part of the base game yet, for some reason Tynan recognized one as a problem but not the other.

A15 has been out for almost a month and the CCL update isn't even in sight yet. Does updating this mod take a lot of work or is it just adding in manually the new crops?

Mackinz

Quote from: notfood on September 13, 2016, 04:03:40 PM
I'm just struggling with this formula. I'll just do it manually for now.

edit... I remembered I was waiting for CCL. This mod without traders makes no sense.
Did CCL allow for unique traders? Well, while a seeds-specific trader might be cool, I think allowing Bulk Goods and Exotic Goods traders to have the seeds would work just fine. Additionally, if it is possible, the seeds could also drop on a successful crop harvest.

notfood

It needs to overwrite the traders.

I'm planning to release Mod Friendly Overrides and make this mod depend on that.

Adalah217

Quote from: notfood on September 22, 2016, 05:52:53 PM
It needs to overwrite the traders.

I'm planning to release Mod Friendly Overrides and make this mod depend on that.

Does the SeedsPlease mod currently work in A15 without traders?

notfood

#39
Testing release for A15. Requires ModFriendlyOverrides for A15 instead of CCL. A16 follows...

Everything seems to work.

ModFriendlyOverrides 0.15.1.0
Seeds Please 0.15.1.0

Load MFO before SeedsPlease.


[attachment deleted by admin due to age]

notfood

#40
Beta release for A16.

ModFriendlyOverrides 0.16.1.0
Seeds Please 0.16.1.0

Load MFO before SeedsPlease.

[attachment deleted by admin due to age]

Thundercraft

I see a SeedsPlease Vegetable Garden Addon for 0.14.1 on page 2. However, I don't see a Vegetable Garden Addon for A15. Was it ever made? Is it even needed? (Was support of VG integrated into the base mod?)

notfood

It's version independant, it'll complain when you select it but it'll still run. Although it requires some balance...

Fafn1r

There's an error while loading the game (A16) saying "Found no usable data when trying to get defs from file OverrideTraders.xml".

Then I got a bunch of errors while trading - "...reference not assigned to an object" and I assumed it's because of that earlier error. Though I wasn't even trading seeds at the time.

notfood

#44
Did you put MFO before SeeedsPlease? That error comes when you haven't loaded MFO but not that list of "...reference not assigned to an object"

I tested it without MFO and no error when trader arrives or you initiate trade... Are you using any other mods?