MinimumQuotaFinder

v1.1.4·Updated 2024-07-07

Calculates and highlights the minimum total value of scraps that you can sell to still reach the quota.

About this mod Author’s original text

MinimumQuotaFinder

Co-created by @Luesewr and @riceisacereal\

| Github

This mod calculates and highlights the minimum total value of scraps that you can sell to still reach the quota. The default key to toggle the highlighting is H, but this can be changed in the settings.

The same in essence as: ScrapCalculator, CalculateScrapForQuota\

Scrap auto-selling mods: SellMyScrap, SellFromTerminal

✨ 𝓦𝓱𝓪𝓽 𝓸𝓾𝓻 𝓶𝓸𝓭 𝓭𝓸𝓮𝓼 𝓫𝓮𝓽𝓽𝓮𝓻

  • Always finds the most optimal answer quickly (5ms to 1s depending on quota and number of items) using an optimized algorithm. (CalculateScrapForQuota does use the same algorithm, but other similar mods we've found all use a non-optimal algorithm)
  • Cool highlighting shader ✨

How the mod works

  • Press H to toggle the highlighting/recalculate
  • The keybind can be changed in the settings.
  • Calculation always assumes that you are selling when the company is buying at 100%. See this section why.
  • Starting from v1.1.0, calculation is disabled on the company moon when buying rate is = quota, we ran the knapsack solution on a threshold of (total value of scrap owned - quota) to find what we should exclude. (Thanks to this Stackoverflow answer for the idea.)

From v1.1.0 onwards, we've made an optimization where a direct target (opposite of inverse target) is used when the inverse target in larger than the quota. Previously, if you had a quota of 1k and total scrap value of 18k, the algorithm would calculate towards the inverse target 18k - 1k = 17k, with around 17k number of items calculations. Now, the algorithm approximates a direct target using a Greedy approximation to attempt to minimize the calculations needed. This way, there would only be around 1k + (the max value of a scrap - 1) number of items calculations needed. More explanation can be found in the next section.

Greedy Approximation for direct target (v1.1.0 onward)

Using an inverse target makes it so that the algorithm can get to the quota as close as possible by calculating what to exclude, using a direct target instead calculates what to include.

The problem here is that the solution algorithm finds an answer that is = quota, but when directly finding what to include with the quota as a target, if there is no combination that is exactly equal to quota, it will find a combination less than the quota. Therefore we need to set a higher target than the quota in case the best combination is quota + 1, or quota + 2, or quota + 3, then comes the question, how high do we set the direct target?

A reliable way to find a good direct target is to find any combination of scrap where the sum is bigger or equal to the quota, since we are sure that it is at least possible to reach that target with this combination. To find this combination, we use a greedy approach to get a quick combination that tries to not overshoot the quota by too much.

Computation Time Scaling

The 2 factors that determine how long it takes to calculate an answer are the value of the quota, the number of scrap, and the total value of that scrap. The algorithm goes through a table the size of (total value of scrap owned - quota) * number of scrap, so the bigger the difference between your quota and the total value of all your scrap, and the more scrap you have, the longer it takes to calculate.

Performance Impact

To prevent the game from freezing while doing large calculations, the mod makes use of coroutines. These coroutines spread out the calculations over multiple frames and limit the number of computations ran per frame for a smoother user experience.

Buying Rate Calculation

The way the buying rate is considered when selling things is by multiplying the total value of everything on the counter by the buying rate, and then getting rid of the decimals. (The result gets assigned to an integer, so 1.1 becomes 1, and 1.8 also becomes 1).

Of course, we could calculate every item's actual buying price beforehand, but the algorithm only works with integers so we have get rid of th

Install & use Install: BepInEx plugin

  1. The archive from playbuff is the mod itself — usually a BepInEx plugin (a .dll or a plugin folder once unzipped).
  2. Recommended: use a community mod manager (such as r2modman) — pick this game, import the mod, and the manager sets up BepInEx and its dependencies for you.
  3. Manual route: install the BepInEx loader in the game folder, then drop the unzipped .dll or plugin folder into BepInEx/plugins/.
  4. Launch the game — the BepInEx console logs every plugin it loads; seeing this mod in the log means it is installed.

Mods with listed dependencies need those installed too, or they will not load. Options are usually changed in-game or in the plugin's config file.

Dependencies

Install these first, or the mod will not work:

BepInEx-BepInExPackRune580-LethalCompany_InputUtils

File & checksum

Filename
MinimumQuotaFinder-1.1.4.zip
File size
167.2 KiB