Preliminary info on Dock / Trade Station ware consumption rates

The place to discuss scripting and game modifications for X³: Reunion.

Moderators: Scripting / Modding Moderators, Moderators for English X Forum

Post Reply
User avatar
Burianek
Posts: 2928
Joined: Mon, 29. Dec 03, 04:29
x3tc

Preliminary info on Dock / Trade Station ware consumption rates

Post by Burianek » Thu, 22. Dec 05, 22:55

Hi all,

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;
  }
} 
To those of you who don't know KC (I don't either) I'll explain what this means.

Let's take the first line:

Code: Select all

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

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
this equals 1.2, but since it's an integer, it floors the value to 1

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;
  }
} 
Let me say this in english

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.
"Nature's first green is gold" . . . stay golden.

jlehtone
Posts: 18691
Joined: Sat, 23. Apr 05, 21:42
x4

Re: Preliminary info on Dock / Trade Station ware consumption rates

Post by jlehtone » Fri, 23. Dec 05, 10:52

Burianek wrote:what little I've been able to present here.
Nuggets of gold, even when "little", are precious. :wink:
Goner Pancake Protector X
Insanity included at no extra charge.
There is no Box. I am the sand.

Post Reply

Return to “X³: Reunion - Scripts and Modding”