Here's sample code from (soon to be released) v1.1

Code: Select all

```
if(system.economy == 0) // rich industrial
{
new_stock = Math.floor((Math.random() + 0.5) * 60) - supply_mod;
system.mainStation.setMarketQuantity("luxuries", new_stock);
new_stock = Math.floor((Math.random() + 0.5) * 60) - supply_mod;
system.mainStation.setMarketQuantity("computers", new_stock);
new_stock = Math.floor((Math.random() + 0.5) * 60) - supply_mod;
system.mainStation.setMarketQuantity("machinery", new_stock);
new_stock = Math.floor((Math.random() + 0.5) * 60) - supply_mod;
system.mainStation.setMarketQuantity("alloys", new_stock);
new_price = Math.floor(system.mainStation.market.luxuries.price + (focus_mod * 4) + (Math.random() * (10 - 1 + 1) - 5));
system.mainStation.setMarketPrice("luxuries", new_price);
new_price = Math.floor(system.mainStation.market.computers.price - (focus_mod * 3) + (Math.random() * (10 - 1 + 1) - 5));
system.mainStation.setMarketPrice("computers", new_price);
new_price = Math.floor(system.mainStation.market.machinery.price - (focus_mod * 2) + (Math.random() * (10 - 1 + 1) - 5));
system.mainStation.setMarketPrice("machinery", new_price);
new_price = Math.floor(system.mainStation.market.alloys.price + focus_mod + (Math.random() * (10 - 1 + 1) - 5));
system.mainStation.setMarketPrice("alloys", new_price);
new_price = Math.floor(560 + 144 + demand_mod + ((Math.random() * (10 - 1 + 1) - 5) * 4));
system.mainStation.setMarketPrice("furs", new_price);
new_price = Math.floor(252 + 80 + demand_mod + ((Math.random() * (10 - 1 + 1) - 5) * 3));
system.mainStation.setMarketPrice("liquor_wines", new_price);
new_price = Math.floor(212 + 48 + demand_mod + ((Math.random() * (10 - 1 + 1) - 5) * 2));
system.mainStation.setMarketPrice("radioactives", new_price);
new_price = Math.floor(44 + 32 + demand_mod + (Math.random() * (10 - 1 + 1) - 5));
system.mainStation.setMarketPrice("food", new_price);
shortage_factor = Math.floor(system.mainStation.market.food.quantity / 1.5);
system.mainStation.setMarketQuantity("food", shortage_factor);
shortage_factor = Math.floor(system.mainStation.market.radioactives.quantity / 3);
system.mainStation.setMarketQuantity("radioactives", shortage_factor);
shortage_factor = Math.floor(system.mainStation.market.liquor_wines.quantity / 6);
system.mainStation.setMarketQuantity("liquor_wines", shortage_factor);
shortage_factor = Math.floor(system.mainStation.market.furs.quantity / 12);
system.mainStation.setMarketQuantity("furs", shortage_factor);
}
```

The opening line is just establishing that the following code runs in rich industrial systems only (it's the '0' that's key, not the 'rich industrial' text - appearing after the '//' means it's just reference to make the code easier to read).

After that we've got four blocks of code.

**Block 1:** establishes the

quantity of key exports for this system (supply_mod is based on productivity and set elsewhere in the code)

**Block 2:** modifies the

price of key exports based on tech level and some randomisation

**Block 3:** establishes the

price of key imports based on economy type (rich industrial in this case) and population size

**Block 4:** modifies the

quantity of key imports available for purchase based on demand priority

Armed with that knowledge, we now know where to look to if we wanted to make (for example) the changes suggested by (Old) Murgh:

Old Murgh wrote: ↑Fri Dec 31, 2021 5:40 pm
fine wine rates a bit higher than furs and rich agri would be more self-supplied with luxuries.

Well, I'm just going to tackle the first one here.

So crudely (in the case of a rich industrial) we're looking at imports and we're looking primarily at pricing. Price of key imports is established in

**block 3** of the code, so lets take a closer look.

Code: Select all

```
new_price = Math.floor(560 + 144 + demand_mod + ((Math.random() * (10 - 1 + 1) - 5) * 4));
system.mainStation.setMarketPrice("furs", new_price);
new_price = Math.floor(252 + 80 + demand_mod + ((Math.random() * (10 - 1 + 1) - 5) * 3));
system.mainStation.setMarketPrice("liquor_wines", new_price);
new_price = Math.floor(212 + 48 + demand_mod + ((Math.random() * (10 - 1 + 1) - 5) * 2));
system.mainStation.setMarketPrice("radioactives", new_price);
new_price = Math.floor(44 + 32 + demand_mod + (Math.random() * (10 - 1 + 1) - 5));
system.mainStation.setMarketPrice("food", new_price);
```

Four differnt goods with two lines each. First ther'e a line doing the calculation and then there's a line formalising the price and naming the commodity. Swapping names about shout be simple enough so let's focus on the numbers.

Code: Select all

```
new_price = Math.floor(560 + 144 + demand_mod + ((Math.random() * (10 - 1 + 1) - 5) * 4));
system.mainStation.setMarketPrice("furs", new_price);
```

'Zooming in' once more, we've just got the first two lines setting the price for furs. Whatever we change the word furs to will be the commodity that is set at this price. The more interseting stuff ig oing on in the line above.

The first number of the calculation (560) is the average price of the intended commodity according to elite in decicredits (furs at 56.0Cr).

The second number (144) is the typical ammount that this government is prepared to pay 'over the odds' for the commodity in question.

demand_mod is based on population and the rest is just adding some random variance.

So if you just swap the word 'furs' for 'liquor_wines' then instead of just getting the 144 base profit margin, traders will be getting 144 + 560 (furs) - 252 (liquor_wines) = 452 base profit margin. Why? Because we've inflated the base price as well as the profit margin but in this system only.

So, if you want base prices to remain the same (e.g. furs might be more expensive but wines are more profitable) then just swap the second numbers around (profit margins).

So, making liqour wines more profitable than furs but not more expensive (in this system type) only requires swapping two numbers:

Code: Select all

```
new_price = Math.floor(560 + 80 + demand_mod + ((Math.random() * (10 - 1 + 1) - 5) * 4));
system.mainStation.setMarketPrice("furs", new_price);
new_price = Math.floor(252 + 144 + demand_mod + ((Math.random() * (10 - 1 + 1) - 5) * 3));
system.mainStation.setMarketPrice("liquor_wines", new_price);
```

The respective base profit margins of 144 and 80 have simply been swapped and now furs is ranked second after liquor wines as the most profitable import to ship to a rich industrial.

Phew... Hopefully that wasn't so long winded as to be confusing