I've done a little bit of digging and managed to get some information on how the quantity of wares to be removed at equipment docks and trade stations is calculated.

This is preliminary information, and is subject to being completely incorrect, but I'll try to list what I know and what I'm guessing at so you can make up your own minds.

First, here's the code that deals with ware removal:

Code: Select all

```
int use = current_timestep * percentage / (100 * (BESTSTORE/BESTSTORE_SECONDARY)) / SA_GetTypeRelValue(m, s);
if (use == 0)
{
int invuse = SA_GetTypeRelValue(m, s) * (100 * (BESTSTORE/BESTSTORE_SECONDARY)) / (percentage * current_timestep);
if (!invuse || !SE_Random(invuse)) {
use = (current_timestep / 20) + 1;
}
else {
use = 0;
}
}
```

Let's take the first line:

Code: Select all

`int use = current_timestep * percentage / (100 * (BESTSTORE/BESTSTORE_SECONDARY)) / SA_GetTypeRelValue(m, s);`

current_timestep = this is a variable number, in seconds, of the length of time since the last iteration to check to see if wares should be removed. This number can be anywhere from 5 - 300 seconds if nothing interrupts the task.

percentage = 6 for 'high tech' wares (weapons / shields) and 12 for everything else

BESTSTORE = 10,000

BESTSTORE_SECONDARY = 5,000

SA_GetTypeRelValue(m, s) = returns the relvalue of the ware being checked, don't worry about the syntax. If you don't know what a relvalue is, you're probably not reading this tutorial anyway, since it's too advanced. Start out by reading my explanation of economy related matters in the X2 S/M forum.

Ok, so let's take wheat as an example, and let's assume that the current_timestep is 120 seconds. That gives us an equation of:

Code: Select all

`int use = 120 * 12 / (100 * (2)) / 6`

Now I don't know at this point how many wares get removed. I'm under the impression that use is more of a logical quantity and states whether or not wares should be removed. I don't think the code removes 'use' units since removing 1 wheat every 2 minutes would be silly. But this would require testing.

Also, let's note that wheat has a pretty small relvalue. Most wares are considerably higher. Wares that have relvalues higher than wheat are going to run into the dangerous possibility that use will end up being a number less than 1, and therefore the integer quantity will get floored to 0.

Let's move to the next part of the code, which deals with this possibility, and is the random function.

Code: Select all

```
if (use == 0)
{
int invuse = SA_GetTypeRelValue(m, s) * (100 * (BESTSTORE/BESTSTORE_SECONDARY)) / (percentage * current_timestep);
if (!invuse || !SE_Random(invuse)) {
use = (current_timestep / 20) + 1;
}
else {
use = 0;
}
}
```

If use ended up being 0, use this part of the code

invuse = blah blah... you'll see that this is simply the inverse of the equation used to find use. It is what it says it is, it's the inverse of use. So if use ended up being 0.25, invuse will be 4. (1 / 0.25 = 4)

if !invuse ..... - this line is the random function. it says, if invuse equals 4, there is a 1 / 4 (25%) chance of executing the next line. else go to the else part which sets use equal to zero.

The line that gets executed if the random function succeeds is:

use = (current_timestep / 20) + 1

This again sets use to some nonzero number. I'm not exactly sure why it isn't just set to 1, and what the timestep portion of the line does, but there you have it.

So really all that this entire second block of code says is:

'ok, use ended up being 0.30, then there's a 30% chance of having a nonzero use number'

'ok, use ended up being 0.58, then there's a 58% chance of having a nonzero use number'

you get the point.

Kind of clever actually since over large quantities of time, these random functions should balance out to produce something close to an average rate of consumption that can have considerable variation over the short term.

Now, I don't know what happens after use is determined. I don't know how many wares get removed. I don't think it's 1, but I don't know.

Many thanks to ticaki for helping me understand what little I've been able to present here.