How do traders choose where or what to trade?

The place to discuss scripting and game modifications for X4: Foundations.

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

Post Reply
Sp0ngeB0b
Posts: 22
Joined: Sun, 18. Feb 24, 10:43
x4

How do traders choose where or what to trade?

Post by Sp0ngeB0b » Thu, 25. Apr 24, 17:55

Hello coding geniuses.
I am hoping to get some insight into how the trader ai works, specifically with station managers.

I am relatively new to coding but what I have gleaned so far from trade.find.commander:
1.) The AI will asses trade values of wares by calculating the relative prices* of wares in allowed sectors.
2.) Available stations in sellspaces and buyspaces are iterated over to find and accept a buy offer and sell offer respectively. Available spaces are ordered by distance (jump gate distance I think).

AI will attempt to search for trades in this order:
1.) Will try to sell off all of the wares currently in cargo. Will not trade anything else until cargo is empty. The ai will not sell the cargo elsewhere if the station has a need for it.
2.) Will try to sell.
3.) Will try to buy.
Note: If a resource shortage is detected in station then step 2 is skipped

When selling:
- 50% of the time, the wares are sorted from lowest to highest relative price, otherwise it's random. This will generally result in selling wares we have the most of first.
- While iterating, as long as the relative price of the potential buyer is at or above the relative price of our station then we have our buyer.

When buying:
- Wares are sorted buy urgency using a priority table**.
- While iterating, as long as the relative price of the potential seller is at or below the relative price of our station then we have our seller.
- The non-player factions will purchase at any price? lines: 631, 632, 633, 640, 648

When a ware becomes critical:
All other items are removed from the warebasket available to the trader.

Does anyone know where to find the functions: <generate_shortage_reports>, <find_sell_offer>, and <find_buy_offer>?
lines 630 - 654 confuse me: Why is there a custom minimum volume step used only when there is no faction restriction? What is the default calculation for this within <find_sell_offer>?

*Relative prices: It is a value between -1 and 1. -1: Ware price is the lowest in available spaces for that ware; 0: Ware price is the average price for that ware; 1: Ware price is the highest in available spaces for that ware-
**Priority table: "Build table with priorities, making primary resources more "urgent" than secondaries or ammo offers, higher $trade.stocklevel means higher demand" --> priority considers ware type, and amount of ware needed.

User avatar
euclid
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 13304
Joined: Sun, 15. Feb 04, 20:12
x4

Re: How do traders choose where or what to trade?

Post by euclid » Sun, 28. Apr 24, 13:13

Sp0ngeB0b wrote:
Thu, 25. Apr 24, 17:55
...................
Does anyone know where to find the functions: <generate_shortage_reports>, <find_sell_offer>, and <find_buy_offer>?
...................
They are all defined in common.xsd which is located in libraries, if that is what you ask. ;-)

Cheers Euclid
"In any special doctrine of nature there can be only as much proper science as there is mathematics therein.”
- Immanuel Kant (1724-1804), Metaphysical Foundations of the Science of Nature, 4:470, 1786

Sp0ngeB0b
Posts: 22
Joined: Sun, 18. Feb 24, 10:43
x4

Re: How do traders choose where or what to trade?

Post by Sp0ngeB0b » Mon, 29. Apr 24, 11:53

Yes it is.
Thank you

Post Reply

Return to “X4: Foundations - Scripts and Modding”